diff --git a/src/Mod/Fem/App/AppFem.cpp b/src/Mod/Fem/App/AppFem.cpp index 8f8d024eb..d432b79b2 100755 --- a/src/Mod/Fem/App/AppFem.cpp +++ b/src/Mod/Fem/App/AppFem.cpp @@ -34,6 +34,7 @@ #include "FemMesh.h" #include "FemMeshProperty.h" #include "FemMeshObject.h" +#include "FemMeshShapeObject.h" #include "FemSetElementsObject.h" #include "FemSetFacesObject.h" @@ -112,6 +113,7 @@ void AppFemExport initFem() Fem::FemMesh ::init(); Fem::FemMeshObject ::init(); + Fem::FemMeshShapeObject ::init(); Fem::PropertyFemMesh ::init(); Fem::FemSetObject ::init(); diff --git a/src/Mod/Fem/App/FemMeshShapeObject.cpp b/src/Mod/Fem/App/FemMeshShapeObject.cpp index 917913115..2501ec6fa 100644 --- a/src/Mod/Fem/App/FemMeshShapeObject.cpp +++ b/src/Mod/Fem/App/FemMeshShapeObject.cpp @@ -27,37 +27,125 @@ #endif #include "FemMeshShapeObject.h" +#include "FemMesh.h" #include #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + using namespace Fem; using namespace App; -PROPERTY_SOURCE(Fem::FemMeshShapeObject, Fem::FemMeshShapeObject) +PROPERTY_SOURCE(Fem::FemMeshShapeObject, Fem::FemMeshObject) FemMeshShapeObject::FemMeshShapeObject() { - ADD_PROPERTY_TYPE(FemMesh,(), "FEM Mesh",Prop_None,"FEM Mesh object"); + ADD_PROPERTY_TYPE(Shape,(0), "Shape",Prop_None,"Shape for the analysis"); } FemMeshShapeObject::~FemMeshShapeObject() { } -short FemMeshShapeObject::mustExecute(void) const +App::DocumentObjectExecReturn *FemMeshShapeObject::execute(void) { - return 0; + Fem::FemMesh newMesh; + + Part::Feature *feat = Shape.getValue(); + + + TopoDS_Shape shape = feat->Shape.getValue(); + + newMesh.getSMesh()->ShapeToMesh(shape); + SMESH_Gen *myGen = newMesh.getGenerator(); + + int hyp=0; + SMESH_HypothesisPtr len(new StdMeshers_MaxLength(hyp++, 1, myGen)); + static_cast(len.get())->SetLength(1.0); + newMesh.addHypothesis(shape, len); + + SMESH_HypothesisPtr loc(new StdMeshers_LocalLength(hyp++, 1, myGen)); + static_cast(loc.get())->SetLength(1.0); + newMesh.addHypothesis(shape, loc); + + SMESH_HypothesisPtr area(new StdMeshers_MaxElementArea(hyp++, 1, myGen)); + static_cast(area.get())->SetMaxArea(1.0); + newMesh.addHypothesis(shape, area); + + SMESH_HypothesisPtr segm(new StdMeshers_NumberOfSegments(hyp++, 1, myGen)); + static_cast(segm.get())->SetNumberOfSegments(1); + newMesh.addHypothesis(shape, segm); + + SMESH_HypothesisPtr defl(new StdMeshers_Deflection1D(hyp++, 1, myGen)); + static_cast(defl.get())->SetDeflection(0.01); + newMesh.addHypothesis(shape, defl); + + SMESH_HypothesisPtr reg(new StdMeshers_Regular_1D(hyp++, 1, myGen)); + newMesh.addHypothesis(shape, reg); + + //SMESH_HypothesisPtr sel(new StdMeshers_StartEndLength(hyp++, 1, myGen)); + //static_cast(sel.get())->SetLength(1.0, true); + //newMesh.addHypothesis(shape, sel; + + SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++,1,myGen)); + newMesh.addHypothesis(shape, qdp); + + SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++,1,myGen)); + newMesh.addHypothesis(shape, q2d); + + // create mesh + newMesh.compute(); + + + SMESHDS_Mesh* data = const_cast(newMesh.getSMesh())->GetMeshDS(); + const SMDS_MeshInfo& info = data->GetMeshInfo(); + int numNode = info.NbNodes(); + int numTria = info.NbTriangles(); + int numQuad = info.NbQuadrangles(); + int numPoly = info.NbPolygons(); + int numVolu = info.NbVolumes(); + int numTetr = info.NbTetras(); + int numHexa = info.NbHexas(); + int numPyrd = info.NbPyramids(); + int numPris = info.NbPrisms(); + int numHedr = info.NbPolyhedrons(); + + // set the value to the object + FemMesh.setValue(newMesh); + + + return App::DocumentObject::StdReturn; } -PyObject *FemMeshShapeObject::getPyObject() -{ - if (PythonObject.is(Py::_None())){ - // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); - } - return Py::new_reference_to(PythonObject); -} +//short FemMeshShapeObject::mustExecute(void) const +//{ +// return 0; +//} + +//PyObject *FemMeshShapeObject::getPyObject() +//{ +// if (PythonObject.is(Py::_None())){ +// // ref counter is set to 1 +// PythonObject = Py::Object(new DocumentObjectPy(this),true); +// } +// return Py::new_reference_to(PythonObject); +//} void FemMeshShapeObject::onChanged(const Property* prop) { diff --git a/src/Mod/Fem/App/FemMeshShapeObject.h b/src/Mod/Fem/App/FemMeshShapeObject.h index a13a8b286..cebf282b8 100644 --- a/src/Mod/Fem/App/FemMeshShapeObject.h +++ b/src/Mod/Fem/App/FemMeshShapeObject.h @@ -42,14 +42,13 @@ public: virtual ~FemMeshShapeObject(); /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { - return "FemGui::ViewProviderFemMeshShape"; - } - virtual App::DocumentObjectExecReturn *execute(void) { - return App::DocumentObject::StdReturn; - } - virtual short mustExecute(void) const; - virtual PyObject *getPyObject(void); + //virtual const char* getViewProviderName(void) const { + // return "FemGui::ViewProviderFemMeshShape"; + //} + virtual App::DocumentObjectExecReturn *execute(void); + + //virtual short mustExecute(void) const; + //virtual PyObject *getPyObject(void); App::PropertyLink Shape; diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index 490e53f84..e51c49d38 100755 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -86,6 +87,57 @@ bool CmdFemCreateFromShape::isActive(void) return Gui::Selection().countObjectsOfType(type) > 0; } +//===================================================================================== +DEF_STD_CMD_A(CmdFemCreateAnalysis); + +CmdFemCreateAnalysis::CmdFemCreateAnalysis() + : Command("Fem_CreateAnalysis") +{ + sAppModule = "Fem"; + sGroup = QT_TR_NOOP("Fem"); + sMenuText = QT_TR_NOOP("Create a FEM analysis"); + sToolTipText = QT_TR_NOOP("Create a FEM analysis"); + sWhatsThis = sToolTipText; + sStatusTip = sToolTipText; + sPixmap = "Fem_FemMesh"; +} + +void CmdFemCreateAnalysis::activated(int iMsg) +{ + std::vector selection = getSelection().getSelectionEx(); + + if (selection.size() != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select an edge, face or body. Only one body is allowed.")); + return; + } + + if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), + QObject::tr("Fillet works only on parts")); + return; + } + + Part::Feature *base = static_cast(selection[0].getObject()); + + + openCommand("Create FEM analysis"); + doCommand(Doc,"App.activeDocument().addObject('Fem::FemMeshShapeObject','%s')","FemShape"); + doCommand(Doc,"App.activeDocument().ActiveObject.Shape = App.activeDocument().%s",base->getNameInDocument()); + updateActive(); + +} + +bool CmdFemCreateAnalysis::isActive(void) +{ + if (Gui::Control().activeDialog()) + return false; + Base::Type type = Base::Type::fromName("Part::Feature"); + return Gui::Selection().countObjectsOfType(type) > 0; +} + +//===================================================================================== + DEF_STD_CMD_A(CmdFemConstraintBearing); CmdFemConstraintBearing::CmdFemConstraintBearing() @@ -116,6 +168,8 @@ bool CmdFemConstraintBearing::isActive(void) return hasActiveDocument(); } +//===================================================================================== + DEF_STD_CMD_A(CmdFemConstraintFixed); CmdFemConstraintFixed::CmdFemConstraintFixed() @@ -146,6 +200,8 @@ bool CmdFemConstraintFixed::isActive(void) return hasActiveDocument(); } +//===================================================================================== + DEF_STD_CMD_A(CmdFemConstraintForce); CmdFemConstraintForce::CmdFemConstraintForce() @@ -177,6 +233,8 @@ bool CmdFemConstraintForce::isActive(void) return hasActiveDocument(); } +//===================================================================================== + DEF_STD_CMD_A(CmdFemConstraintGear); CmdFemConstraintGear::CmdFemConstraintGear() @@ -208,6 +266,8 @@ bool CmdFemConstraintGear::isActive(void) return hasActiveDocument(); } +//===================================================================================== + DEF_STD_CMD_A(CmdFemConstraintPulley); CmdFemConstraintPulley::CmdFemConstraintPulley() @@ -436,6 +496,7 @@ void CreateFemCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdFemCreateFromShape()); + rcCmdMgr.addCommand(new CmdFemCreateAnalysis()); rcCmdMgr.addCommand(new CmdFemCreateNodesSet()); rcCmdMgr.addCommand(new CmdFemDefineNodesSet()); rcCmdMgr.addCommand(new CmdFemConstraintBearing()); diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 763c20475..a29ba5c04 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -56,6 +56,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* fem = new Gui::ToolBarItem(root); fem->setCommand("FEM"); *fem << "Fem_CreateFromShape" + << "Fem_CreateAnalysis" << "Fem_CreateNodesSet" << "Fem_ConstraintFixed" << "Fem_ConstraintForce" @@ -73,8 +74,9 @@ Gui::MenuItem* Workbench::setupMenuBar() const root->insertItem(item, fem); fem->setCommand("&FEM"); *fem << "Fem_CreateFromShape" + << "Fem_CreateAnalysis" << "Fem_CreateNodesSet" - << "Fem_ConstraintFixed" + << "Fem_ConstraintFixed" << "Fem_ConstraintForce" << "Fem_ConstraintBearing" << "Fem_ConstraintGear"