void CmdFemConstraintPressure::activated(int iMsg) { Fem::FemAnalysis *Analysis; if(getConstraintPrerequisits(&Analysis)) return; std::string FeatName = getUniqueObjectName("FemConstraintPressure"); openCommand("Make FEM constraint pressure on face"); doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintPressure\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Pressure = 0.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]", Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); updateActive(); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); }
void DefineNodesCallback(void * ud, SoEventCallback * n) { Fem::FemAnalysis *Analysis; if(getConstraintPrerequisits(&Analysis)) return; // show the wait cursor because this could take quite some time Gui::WaitCursor wc; // When this callback function is invoked we must in either case leave the edit mode Gui::View3DInventorViewer* view = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData()); view->setEditing(false); view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineNodesCallback,ud); n->setHandled(); SbBool clip_inner; std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner); if (clPoly.size() < 3) return; if (clPoly.front() != clPoly.back()) clPoly.push_back(clPoly.front()); SoCamera* cam = view->getCamera(); SbViewVolume vv = cam->getViewVolume(); Gui::ViewVolumeProjection proj(vv); Base::Polygon2D polygon; for (std::vector<SbVec2f>::const_iterator it = clPoly.begin(); it != clPoly.end(); ++it) polygon.Add(Base::Vector2D((*it)[0],(*it)[1])); std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Fem::FemMeshObject::getClassTypeId()); if(docObj.size() !=1) return; const SMESHDS_Mesh* data = const_cast<SMESH_Mesh*>(dynamic_cast<Fem::FemMeshObject*>(docObj[0])->FemMesh.getValue().getSMesh())->GetMeshDS(); SMDS_NodeIteratorPtr aNodeIter = data->nodesIterator(); Base::Vector3f pt2d; std::set<int> IntSet; for (int i=0;aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); Base::Vector3f vec(aNode->X(),aNode->Y(),aNode->Z()); pt2d = proj(vec); if (polygon.Contains(Base::Vector2D(pt2d.x, pt2d.y)) == true) IntSet.insert(aNode->GetID()); } std::stringstream set; set << "["; for(std::set<int>::const_iterator it=IntSet.begin();it!=IntSet.end();++it) if(it==IntSet.begin()) set << *it ; else set << "," << *it ; set << "]"; Gui::Command::openCommand("Place robot"); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject('Fem::FemSetNodesObject','NodeSet')"); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.ActiveObject.Nodes = %s",set.str().c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().NodeSet]",Analysis->getNameInDocument(),Analysis->getNameInDocument()); ////Gui::Command::updateActive(); Gui::Command::commitCommand(); //std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); //if (!views.empty()) { // Gui::Application::Instance->activeDocument()->openCommand("Cut"); // for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) { // ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it); // if (that->getEditingMode() > -1) { // that->finishEditing(); // that->cutMesh(clPoly, *view, clip_inner); // } // } // Gui::Application::Instance->activeDocument()->commitCommand(); // view->render(); //} }
void CmdFemConstraintPulley::activated(int iMsg) { Fem::FemAnalysis *Analysis; if(getConstraintPrerequisits(&Analysis)) return; std::string FeatName = getUniqueObjectName("FemConstraintPulley"); openCommand("Make FEM constraint for pulley"); doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintPulley\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Diameter = 300.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.OtherDiameter = 100.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.CenterDistance = 500.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Force = 100.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.TensionForce = 100.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); updateActive(); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); }
void CmdFemCreateSolver::activated(int iMsg) { #ifndef FCWithNetgen QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Your FreeCAD is build without NETGEN support. Meshing will not work....")); return; #endif Fem::FemAnalysis *Analysis; if(getConstraintPrerequisits(&Analysis)) return; std::string FeatName = getUniqueObjectName("Solver"); openCommand("Create solver for FEM or CFD analysis"); doCommand(Doc,"App.activeDocument().addObject(\"Fem::FemSolverObject\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); updateActive(); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); }