Mod/Fem/Gui/Command.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QMessageBox>
00027 #endif
00028
00029 #include <App/Application.h>
00030 #include <App/Document.h>
00031 #include <App/DocumentObject.h>
00032 #include <Gui/Application.h>
00033 #include <Gui/Command.h>
00034 #include <Gui/MainWindow.h>
00035 #include <Gui/FileDialog.h>
00036 #include <Gui/Selection.h>
00037 #include <Gui/Document.h>
00038
00039 #include <Mod/Fem/App/FemMeshObject.h>
00040
00041
00042 using namespace std;
00043
00044 DEF_STD_CMD_A(CmdFemCreateFromShape);
00045
00046 CmdFemCreateFromShape::CmdFemCreateFromShape()
00047 : Command("Fem_CreateFromShape")
00048 {
00049 sAppModule = "Fem";
00050 sGroup = QT_TR_NOOP("Fem");
00051 sMenuText = QT_TR_NOOP("Create FEM mesh");
00052 sToolTipText = QT_TR_NOOP("Create FEM mesh from shape");
00053 sWhatsThis = sToolTipText;
00054 sStatusTip = sToolTipText;
00055 sPixmap = "Fem_FemMesh";
00056 }
00057
00058 void CmdFemCreateFromShape::activated(int iMsg)
00059 {
00060 Base::Type type = Base::Type::fromName("Part::Feature");
00061 std::vector<App::DocumentObject*> obj = Gui::Selection().getObjectsOfType(type);
00062
00063 openCommand("Create FEM");
00064 doCommand(Doc, "import Fem");
00065 for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
00066 App::Document* doc = (*it)->getDocument();
00067 QString name = QString::fromAscii((*it)->getNameInDocument());
00068 QString cmd = QString::fromAscii(
00069 "__fem__=Fem.FemMesh()\n"
00070 "__fem__.setShape(FreeCAD.getDocument(\"%1\").%2.Shape)\n"
00071 "h1=Fem.StdMeshers_MaxLength(0,__fem__)\n"
00072 "h1.setLength(1.0)\n"
00073 "h2=Fem.StdMeshers_LocalLength(1,__fem__)\n"
00074 "h2.setLength(1.0)\n"
00075 "h3=Fem.StdMeshers_QuadranglePreference(2,__fem__)\n"
00076 "h4=Fem.StdMeshers_Quadrangle_2D(3,__fem__)\n"
00077 "h5=Fem.StdMeshers_MaxElementArea(4,__fem__)\n"
00078 "h5.setMaxArea(1.0)\n"
00079 "h6=Fem.StdMeshers_Regular_1D(5,__fem__)\n"
00080 "__fem__.addHypothesis(h1)\n"
00081 "__fem__.addHypothesis(h2)\n"
00082 "__fem__.addHypothesis(h3)\n"
00083 "__fem__.addHypothesis(h4)\n"
00084 "__fem__.addHypothesis(h5)\n"
00085 "__fem__.addHypothesis(h6)\n"
00086 "__fem__.compute()\n"
00087 "FreeCAD.getDocument(\"%1\").addObject"
00088 "(\"Fem::FemMeshObject\",\"%2\").FemMesh=__fem__\n"
00089 "del __fem__,h1,h2,h3,h4,h5,h6\n"
00090 )
00091 .arg(QString::fromAscii(doc->getName()))
00092 .arg(name);
00093 doCommand(Doc, "%s", (const char*)cmd.toAscii());
00094 }
00095 commitCommand();
00096 }
00097
00098 bool CmdFemCreateFromShape::isActive(void)
00099 {
00100 Base::Type type = Base::Type::fromName("Part::Feature");
00101 return Gui::Selection().countObjectsOfType(type) > 0;
00102 }
00103
00104
00105 void CreateFemCommands(void)
00106 {
00107 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00108 rcCmdMgr.addCommand(new CmdFemCreateFromShape());
00109 }