void CmdPathCompound::activated(int iMsg) { std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); if (Sel.size() > 0) { std::ostringstream cmd; cmd << "["; Path::Feature *pcPathObject; for (std::vector<Gui::SelectionSingleton::SelObj>::const_iterator it=Sel.begin();it!=Sel.end();++it) { if ((*it).pObject->getTypeId().isDerivedFrom(Path::Feature::getClassTypeId())) { pcPathObject = dynamic_cast<Path::Feature*>((*it).pObject); cmd << "FreeCAD.activeDocument()." << pcPathObject->getNameInDocument() << ","; } else { Base::Console().Error("Only Path objects must be selected before running this command\n"); return; } } cmd << "]"; std::string FeatName = getUniqueObjectName("PathCompound"); openCommand("Create Path Compound"); doCommand(Doc,"FreeCAD.activeDocument().addObject('Path::FeatureCompound','%s')",FeatName.c_str()); doCommand(Doc,"FreeCAD.activeDocument().%s.Group = %s",FeatName.c_str(),cmd.str().c_str()); commitCommand(); updateActive(); } else { Base::Console().Error("At least one Path object must be selected\n"); return; } }
void CmdPartRefineShape::activated(int iMsg) { Gui::WaitCursor wc; Base::Type partid = Base::Type::fromName("Part::Feature"); std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType(partid); openCommand("Refine shape"); for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) { try { doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape=" "App.ActiveDocument.%s.Shape.removeSplitter()\n" "App.ActiveDocument.ActiveObject.Label=" "App.ActiveDocument.%s.Label\n" "Gui.ActiveDocument.%s.hide()\n", (*it)->getNameInDocument(), (*it)->getNameInDocument(), (*it)->getNameInDocument(), (*it)->getNameInDocument()); copyVisual("ActiveObject", "ShapeColor", (*it)->getNameInDocument()); copyVisual("ActiveObject", "LineColor", (*it)->getNameInDocument()); copyVisual("ActiveObject", "PointColor", (*it)->getNameInDocument()); } catch (const Base::Exception& e) { Base::Console().Warning("%s: %s\n", (*it)->Label.getValue(), e.what()); } } commitCommand(); updateActive(); }
void CmdRaytracingNewPovrayProject::activated(int iMsg) { const char* ppReturn=0; Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn); if (ppReturn) { std::string str(ppReturn); if (str.find("PerspectiveCamera") == std::string::npos) { int ret = QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdRaytracingWriteView","No perspective camera"), qApp->translate("CmdRaytracingWriteView","The current view camera is not perspective" " and thus the result of the povray image later might look different to" " what you expect.\nDo you want to continue?"), QMessageBox::Yes|QMessageBox::No); if (ret != QMessageBox::Yes) return; } } std::string FeatName = getUniqueObjectName("PovProject"); openCommand("Raytracing create project"); doCommand(Doc,"import Raytracing,RaytracingGui"); doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayProject','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Template = App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov'",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",FeatName.c_str()); commitCommand(); }
void CmdPointsExport::activated(int iMsg) { QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QString::null, QString(), QObject::tr("Ascii Points (*.asc);;All Files (*.*)")); if ( fn.isEmpty() ) return; if (! fn.isEmpty() ) { QFileInfo fi; fi.setFile(fn); openCommand("Export Points"); std::vector<App::DocumentObject*> points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); doCommand(Doc,"f = App.ActiveDocument.addObject(\"Points::Export\",\"%s\")", (const char*)fi.baseName().toAscii()); doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii()); doCommand(Doc,"l=list()"); for ( std::vector<App::DocumentObject*>::const_iterator it = points.begin(); it != points.end(); ++it ) { doCommand(Doc,"l.append(App.ActiveDocument.getObject(\"%s\"))",(*it)->getNameInDocument()); } doCommand(Doc,"f.Sources = l"); commitCommand(); updateActive(); } }
bool Vim::parse(QString command) { bool result; qDebug() << "Parsing " << command; if (!command.startsWith(":")) { emit prefixMissing(command); result = false; } else { const QString & realCommand = QString(command).remove(0, 1).trimmed(); if (realCommand.startsWith("open ") || realCommand.startsWith("o ")) { emit openCommand(realCommand.section(' ', 1).trimmed()); result = true; } else if (realCommand.startsWith("tab ") || realCommand.startsWith("t ")) { emit openInNewTabCommand(realCommand.section(' ', 1).trimmed()); result = true; } else if (realCommand == "quit" || realCommand == "q") { emit closeTabCommand(); result = true; } else { emit parsingFailed(command); result = false; } } return result; }
void CmdRaytracingExportProject::activated(int iMsg) { unsigned int n = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (n != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one Povray project object.")); return; } QStringList filter; filter << QObject::tr("Povray(*.pov)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); openCommand("Raytracing export project"); doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); std::string fname = (const char*)fn.toUtf8(); doCommand(Doc,"OutFile = open(unicode('%s','utf-8'),'w')",fname.c_str()); doCommand(Doc,"OutFile.write(PageFile.read())"); doCommand(Doc,"del OutFile,PageFile"); commitCommand(); } }
void CmdPartDesignDuplicateSelection::activated(int iMsg) { Q_UNUSED(iMsg); PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */false); std::vector<App::DocumentObject*> beforeFeatures = getDocument()->getObjects(); openCommand("Duplicate a PartDesign object"); doCommand(Doc,"FreeCADGui.runCommand('Std_DuplicateSelection')"); if (pcActiveBody) { // Find the features that were added std::vector<App::DocumentObject*> afterFeatures = getDocument()->getObjects(); std::vector<App::DocumentObject*> newFeatures; std::sort(beforeFeatures.begin(), beforeFeatures.end()); std::sort(afterFeatures.begin(), afterFeatures.end()); std::set_difference(afterFeatures.begin(), afterFeatures.end(), beforeFeatures.begin(), beforeFeatures.end(), std::back_inserter(newFeatures)); for (auto feature : newFeatures) { if (PartDesign::Body::isAllowed(feature)) { doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)", pcActiveBody->getNameInDocument(), feature->getNameInDocument()); doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", feature->getNameInDocument()); } } // Adjust visibility of features doCommand(Gui,"Gui.activeDocument().show(\"%s\")", newFeatures.back()->getNameInDocument()); } updateActive(); }
void CmdPartCut::activated(int iMsg) { unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId()); if (n != 2) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select two shapes please.")); return; } std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); std::string FeatName = getUniqueObjectName("Cut"); std::string BaseName = Sel[0].FeatName; std::string ToolName = Sel[1].FeatName; openCommand("Part Cut"); doCommand(Doc,"App.activeDocument().addObject(\"Part::Cut\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str()); doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),ToolName.c_str()); doCommand(Gui,"Gui.activeDocument().hide('%s')",BaseName.c_str()); doCommand(Gui,"Gui.activeDocument().hide('%s')",ToolName.c_str()); copyVisual(FeatName.c_str(), "ShapeColor", BaseName.c_str()); copyVisual(FeatName.c_str(), "DisplayMode", BaseName.c_str()); updateActive(); commitCommand(); }
void CmdPartExport::activated(int iMsg) { QStringList filter; filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)"); filter << QObject::tr("STEP (*.stp *.step)"); filter << QObject::tr("IGES (*.igs *.iges)"); filter << QObject::tr("BREP (*.brp *.brep)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { App::Document* pDoc = getDocument(); if (!pDoc) return; // no document openCommand("Import Part"); QString ext = QFileInfo(fn).suffix().toLower(); if (ext == QLatin1String("step") || ext == QLatin1String("stp") || ext == QLatin1String("iges") || ext == QLatin1String("igs")) { Gui::Application::Instance->exportTo((const char*)fn.toUtf8(),pDoc->getName(),"ImportGui"); } else { Gui::Application::Instance->exportTo((const char*)fn.toUtf8(),pDoc->getName(),"Part"); } commitCommand(); } }
void CmdPartImport::activated(int iMsg) { QStringList filter; filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)"); filter << QObject::tr("STEP (*.stp *.step)"); filter << QObject::tr("IGES (*.igs *.iges)"); filter << QObject::tr("BREP (*.brp *.brep)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { Gui::WaitCursor wc; App::Document* pDoc = getDocument(); if (!pDoc) return; // no document openCommand("Import Part"); QString ext = QFileInfo(fn).suffix().toLower(); if (ext == QLatin1String("step") || ext == QLatin1String("stp") || ext == QLatin1String("iges") || ext == QLatin1String("igs")) { doCommand(Doc, "import ImportGui"); doCommand(Doc, "ImportGui.insert(\"%s\",\"%s\")", (const char*)fn.toUtf8(), pDoc->getName()); } else { doCommand(Doc, "import Part"); doCommand(Doc, "Part.insert(\"%s\",\"%s\")", (const char*)fn.toUtf8(), pDoc->getName()); } commitCommand(); } }
void CmdPartFuse::activated(int iMsg) { unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId()); if (n < 2) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select two shapes or more, please.")); return; } std::string FeatName = getUniqueObjectName("Fusion"); std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); std::stringstream str; std::vector<std::string> tempSelNames; str << "App.activeDocument()." << FeatName << ".Shapes = ["; for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){ str << "App.activeDocument()." << it->FeatName << ","; tempSelNames.push_back(it->FeatName); } str << "]"; openCommand("Fusion"); doCommand(Doc,"App.activeDocument().addObject(\"Part::MultiFuse\",\"%s\")",FeatName.c_str()); runCommand(Doc,str.str().c_str()); for (std::vector<std::string>::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it) doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str()); copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); copyVisual(FeatName.c_str(), "DisplayMode", tempSelNames.front().c_str()); updateActive(); commitCommand(); }
void CmdPartImport::activated(int iMsg) { QStringList filter; filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)"); filter << QObject::tr("STEP (*.stp *.step)"); filter << QObject::tr("IGES (*.igs *.iges)"); filter << QObject::tr("BREP (*.brp *.brep)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { Gui::WaitCursor wc; App::Document* pDoc = getDocument(); if (!pDoc) return; // no document openCommand("Import Part"); QString ext = QFileInfo(fn).suffix().toLower(); if (ext == QLatin1String("step") || ext == QLatin1String("stp") || ext == QLatin1String("iges") || ext == QLatin1String("igs")) { doCommand(Doc, "import ImportGui"); doCommand(Doc, "ImportGui.insert(\"%s\",\"%s\")", (const char*)fn.toUtf8(), pDoc->getName()); } else { doCommand(Doc, "import Part"); doCommand(Doc, "Part.insert(\"%s\",\"%s\")", (const char*)fn.toUtf8(), pDoc->getName()); } commitCommand(); std::list<Gui::MDIView*> views = getActiveGuiDocument()->getMDIViewsOfType(Gui::View3DInventor::getClassTypeId()); for (std::list<Gui::MDIView*>::iterator it = views.begin(); it != views.end(); ++it) { (*it)->viewAll(); } } }
void CmdRaytracingNewPartSegment::activated(int iMsg) { std::vector<Part::Feature*> parts = Gui::Selection().getObjectsOfType<Part::Feature>(); if (parts.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select a Part object.")); return; } std::vector<App::DocumentObject*> pages = App::GetApplication().getActiveDocument() ->getObjectsOfType(Raytracing::RayProject::getClassTypeId()); std::vector<App::DocumentObject*> pages2 = App::GetApplication().getActiveDocument() ->getObjectsOfType(Raytracing::LuxProject::getClassTypeId()); pages.insert(pages.end(),pages2.begin(),pages2.end()); if (pages.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Raytracing project to insert"), QObject::tr("Create a Raytracing project to insert a view.")); return; } std::string ProjName; if (pages.size() > 1) { // priority to the elders, if there is a pov project in the selection, it is used first! pages = Gui::Selection().getObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (pages.size() != 1) { pages = Gui::Selection().getObjectsOfType(Raytracing::LuxProject::getClassTypeId()); if (pages.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Raytracing project to insert"), QObject::tr("Select a Raytracing project to insert the view.")); return; } } } ProjName = pages.front()->getNameInDocument(); const char *FeatType; if (pages.front()->getTypeId().isDerivedFrom(Raytracing::RayProject::getClassTypeId())) { FeatType = "RayFeature"; } else { FeatType = "LuxFeature"; } openCommand("Create view"); for (std::vector<Part::Feature*>::iterator it = parts.begin(); it != parts.end(); ++it) { std::string FeatName = (*it)->getNameInDocument(); FeatName += "_View"; FeatName = getUniqueObjectName(FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject('Raytracing::%s','%s')",FeatType,FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Color = Gui.activeDocument().%s.ShapeColor",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Transparency = Gui.activeDocument().%s.Transparency",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",ProjName.c_str(), FeatName.c_str()); } updateActive(); commitCommand(); }
void CmdPartDesignMoveTip::activated(int iMsg) { Q_UNUSED(iMsg); std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType( Part::Feature::getClassTypeId() ); App::DocumentObject* selFeature; PartDesign::Body* body= nullptr; if ( features.size() == 1 ) { selFeature = features.front(); if ( selFeature->getTypeId().isDerivedFrom ( PartDesign::Body::getClassTypeId() ) ) { body = static_cast<PartDesign::Body *> ( selFeature ); } else { body = PartDesignGui::getBodyFor ( selFeature, /* messageIfNot =*/ false ); } } else { selFeature = nullptr; } if (!selFeature) { QMessageBox::warning (0, QObject::tr( "Selection error" ), QObject::tr( "Select exactly one PartDesign feature or a body." ) ); return; } else if (!body) { QMessageBox::warning (0, QObject::tr( "Selection error" ), QObject::tr( "Couldn't determine a body for the selected feature '%s'.", selFeature->Label.getValue() ) ); return; } else if ( !selFeature->isDerivedFrom(PartDesign::Feature::getClassTypeId () ) && selFeature != body && body->BaseFeature.getValue() != selFeature ) { QMessageBox::warning (0, QObject::tr( "Selection error" ), QObject::tr( "Only a solid feature can be the tip of a body." ) ); return; } App::DocumentObject* oldTip = body->Tip.getValue(); if (oldTip == selFeature) { // it's not generally an error, so print only a console message Base::Console().Message ("%s is already the tip of the body", selFeature->getNameInDocument () ); return; } openCommand("Move tip to selected feature"); if (selFeature == body) { doCommand(Doc,"App.activeDocument().%s.Tip = None", body->getNameInDocument()); } else { doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",body->getNameInDocument(), selFeature->getNameInDocument()); // Adjust visibility to show only the Tip feature doCommand(Gui,"Gui.activeDocument().show(\"%s\")", selFeature->getNameInDocument()); } // TOOD: Hide all datum features after the Tip feature? But the user might have already hidden some and wants to see // others, so we would have to remember their state somehow updateActive(); }
void CmdRaytracingWriteView::activated(int iMsg) { const char* ppReturn=0; Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn); if (ppReturn) { std::string str(ppReturn); if (str.find("PerspectiveCamera") == std::string::npos) { int ret = QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdRaytracingWriteView","No perspective camera"), qApp->translate("CmdRaytracingWriteView","The current view camera is not perspective" " and thus the result of the povray image later might look different to" " what you expect.\nDo you want to continue?"), QMessageBox::Yes|QMessageBox::No); if (ret != QMessageBox::Yes) return; } } QStringList filter; filter << QObject::tr("Povray(*.pov)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;"))); if (fn.isEmpty()) return; std::string cFullName = (const char*)fn.toUtf8(); // get all objects of the active document std::vector<Part::Feature*> DocObjects = getActiveGuiDocument()->getDocument()-> getObjectsOfType<Part::Feature>(); openCommand("Write view"); doCommand(Doc,"import Raytracing,RaytracingGui"); doCommand(Doc,"OutFile = open(unicode('%s','utf-8'),'w')",cFullName.c_str()); doCommand(Doc,"OutFile.write(open(App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov').read())"); doCommand(Doc,"OutFile.write(RaytracingGui.povViewCamera())"); // go through all document objects for (std::vector<Part::Feature*>::const_iterator it=DocObjects.begin();it!=DocObjects.end();++it) { Gui::ViewProvider* vp = getActiveGuiDocument()->getViewProvider(*it); if (vp && vp->isVisible()) { App::PropertyColor *pcColor = dynamic_cast<App::PropertyColor *>(vp->getPropertyByName("ShapeColor")); App::Color col = pcColor->getValue(); doCommand(Doc,"OutFile.write(Raytracing.getPartAsPovray('%s',App.activeDocument().%s.Shape,%f,%f,%f))", (*it)->getNameInDocument(),(*it)->getNameInDocument(),col.r,col.g,col.b); } } doCommand(Doc,"OutFile.close()"); doCommand(Doc,"del OutFile"); updateActive(); commitCommand(); }
void CmdRaytracingResetCamera::activated(int iMsg) { std::vector<App::DocumentObject*> sel = getSelection().getObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (sel.size() != 1) { sel = getSelection().getObjectsOfType(Raytracing::LuxProject::getClassTypeId()); if (sel.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one Raytracing project object.")); return; } } if (sel.front()->getTypeId().isDerivedFrom(Raytracing::RayProject::getClassTypeId())) { //povray try { openCommand("Reset Raytracing Camera"); doCommand(Doc,"import RaytracingGui"); doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",sel.front()->getNameInDocument()); commitCommand(); updateActive(); } catch (...) { abortCommand(); throw; } } else if (sel.front()->getTypeId().isDerivedFrom(Raytracing::LuxProject::getClassTypeId())) { //luxrender try { openCommand("Reset Raytracing Camera"); doCommand(Doc,"import RaytracingGui"); doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",sel.front()->getNameInDocument()); commitCommand(); updateActive(); } catch (...) { abortCommand(); throw; } } }
void CmdPartBox::activated(int iMsg) { QString cmd; cmd = qApp->translate("CmdPartBox","Cube"); openCommand((const char*)cmd.toUtf8()); doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Box\",\"Box\")"); cmd = QString::fromAscii("App.ActiveDocument.ActiveObject.Label = \"%1\"") .arg(qApp->translate("CmdPartBox","Cube")); doCommand(Doc,(const char*)cmd.toUtf8()); commitCommand(); updateActive(); doCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")"); }
void CmdPartBox3::activated(int iMsg) { openCommand("Part Box Create"); doCommand(Doc,"from FreeCAD import Base"); doCommand(Doc,"import Part"); doCommand(Doc,"__fb__ = App.ActiveDocument.addObject(\"Part::Box\",\"PartBox\")"); doCommand(Doc,"__fb__.Location = Base.Vector(50.0,50.0,50.0)"); doCommand(Doc,"__fb__.Length = 100.0"); doCommand(Doc,"__fb__.Width = 100.0"); doCommand(Doc,"__fb__.Height = 100.0"); doCommand(Doc,"del __fb__"); commitCommand(); updateActive(); }
void CmdPartShapeFromMesh::activated(int iMsg) { Q_UNUSED(iMsg); double STD_OCC_TOLERANCE = 1e-6; ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Units"); int decimals = hGrp->GetInt("Decimals"); double tolerance_from_decimals = pow(10., -decimals); double minimal_tolerance = tolerance_from_decimals < STD_OCC_TOLERANCE ? STD_OCC_TOLERANCE : tolerance_from_decimals; bool ok; double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Sewing Tolerance"), QObject::tr("Enter tolerance for sewing shape:"), 0.1, minimal_tolerance, 10.0, decimals, &ok); if (!ok) return; Base::Type meshid = Base::Type::fromName("Mesh::Feature"); std::vector<App::DocumentObject*> meshes; meshes = Gui::Selection().getObjectsOfType(meshid); Gui::WaitCursor wc; std::vector<App::DocumentObject*>::iterator it; openCommand("Convert mesh"); for (it = meshes.begin(); it != meshes.end(); ++it) { App::Document* doc = (*it)->getDocument(); std::string mesh = (*it)->getNameInDocument(); std::string name = doc->getUniqueObjectName(mesh.c_str()); doCommand(Doc,"import Part"); doCommand(Doc,"FreeCAD.getDocument(\"%s\").addObject(\"Part::Feature\",\"%s\")" ,doc->getName() ,name.c_str()); doCommand(Doc,"__shape__=Part.Shape()"); doCommand(Doc,"__shape__.makeShapeFromMesh(" "FreeCAD.getDocument(\"%s\").getObject(\"%s\").Mesh.Topology,%f" ")" ,doc->getName() ,mesh.c_str() ,tol); doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Shape=__shape__" ,doc->getName() ,name.c_str()); doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").purgeTouched()" ,doc->getName() ,name.c_str()); doCommand(Doc,"del __shape__"); } commitCommand(); }
void CmdPointsTransform::activated(int iMsg) { // This is a test command to transform a point cloud directly written in C++ (not Python) Base::Placement trans; trans.setRotation(Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796)); openCommand("Transform points"); //std::vector<App::DocumentObject*> points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); //for (std::vector<App::DocumentObject*>::const_iterator it = points.begin(); it != points.end(); ++it) { // Base::Placement p = static_cast<Points::Feature*>(*it)->Placement.getValue(); // p._rot *= Base::Rotation(Base::Vector3d(0.0, 0.0, 1.0), 1.570796); // static_cast<Points::Feature*>(*it)->Placement.setValue(p); //} commitCommand(); }
void CmdPartDefeaturing::activated(int iMsg) { Q_UNUSED(iMsg); Gui::WaitCursor wc; Base::Type partid = Base::Type::fromName("Part::Feature"); std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx(0, partid); openCommand("Defeaturing"); for (std::vector<Gui::SelectionObject>::iterator it = objs.begin(); it != objs.end(); ++it) { try { std::string shape; shape.append("sh=App."); shape.append(it->getDocName()); shape.append("."); shape.append(it->getFeatName()); shape.append(".Shape\n"); std::string faces; std::vector<std::string> subnames = it->getSubNames(); for (std::vector<std::string>::iterator sub = subnames.begin(); sub != subnames.end(); ++sub) { faces.append("sh."); faces.append(*sub); faces.append(","); } doCommand(Doc,"\nsh = App.getDocument('%s').%s.Shape\n" "nsh = sh.defeaturing([%s])\n" "if not sh.isPartner(nsh):\n" "\t\tdefeat = App.ActiveDocument.addObject('Part::Feature','Defeatured').Shape = nsh\n" "\t\tGui.ActiveDocument.%s.hide()\n" "else:\n" "\t\tFreeCAD.Console.PrintError('Defeaturing failed\\n')", it->getDocName(), it->getFeatName(), faces.c_str(), it->getFeatName()); } catch (const Base::Exception& e) { Base::Console().Warning("%s: %s\n", it->getFeatName(), e.what()); } } commitCommand(); updateActive(); }
void CmdPartImportCurveNet::activated(int iMsg) { QStringList filter; filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)"); filter << QObject::tr("STEP (*.stp *.step)"); filter << QObject::tr("IGES (*.igs *.iges)"); filter << QObject::tr("BREP (*.brp *.brep)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { QFileInfo fi; fi.setFile(fn); openCommand("Part Import Curve Net"); doCommand(Doc,"f = App.activeDocument().addObject(\"Part::CurveNet\",\"%s\")", (const char*)fi.baseName().toAscii()); doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii()); commitCommand(); updateActive(); } }
void CmdRaytracingNewLuxProject::activated(int iMsg) { const char* ppReturn=0; Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn); if (ppReturn) { std::string str(ppReturn); if (str.find("PerspectiveCamera") == std::string::npos) { int ret = QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdRaytracingWriteView","No perspective camera"), qApp->translate("CmdRaytracingWriteView","The current view camera is not perspective" " and thus the result of the luxrender image later might look different to" " what you expect.\nDo you want to continue?"), QMessageBox::Yes|QMessageBox::No); if (ret != QMessageBox::Yes) return; } } std::string FeatName = getUniqueObjectName("LuxProject"); Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(getAction()); QAction* a = pcAction->actions()[iMsg]; QFileInfo tfi(a->property("Template").toString()); if (tfi.isReadable()) { try { openCommand("Create LuxRender project"); doCommand(Doc,"import Raytracing,RaytracingGui"); doCommand(Doc,"App.activeDocument().addObject('Raytracing::LuxProject','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8()); doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",FeatName.c_str()); commitCommand(); } catch (...) { abortCommand(); throw; } } else { QMessageBox::critical(Gui::getMainWindow(), qApp->translate("CmdRaytracingNewLuxProject","No template"), qApp->translate("CmdRaytracingNewLuxProject","No template available")); } }
void CmdRaytracingNewPartSegment::activated(int iMsg) { std::vector<Part::Feature*> parts = Gui::Selection().getObjectsOfType<Part::Feature>(); if (parts.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select a Part object.")); return; } std::vector<App::DocumentObject*> pages = App::GetApplication().getActiveDocument() ->getObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (pages.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Povray project to insert"), QObject::tr("Create a Povray project to insert a view.")); return; } std::string ProjName; if (pages.size() > 1) { pages = Gui::Selection().getObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (pages.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Povray project to insert"), QObject::tr("Select a Povray project to insert the view.")); return; } } ProjName = pages.front()->getNameInDocument(); openCommand("Create view"); for (std::vector<Part::Feature*>::iterator it = parts.begin(); it != parts.end(); ++it) { std::string FeatName = (*it)->getNameInDocument(); FeatName += "_View"; FeatName = getUniqueObjectName(FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayFeature','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Color = Gui.activeDocument().%s.ShapeColor",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",ProjName.c_str(), FeatName.c_str()); } updateActive(); commitCommand(); }
void CmdPartDesignPart::activated(int iMsg) { Q_UNUSED(iMsg); if ( !PartDesignGui::assureModernWorkflow( getDocument() ) ) return; openCommand("Add a part"); std::string FeatName = getUniqueObjectName("Part"); std::string PartName; PartName = getUniqueObjectName("Part"); doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')",PartName.c_str()); // TODO We really must to set label ourselfs? (2015-08-17, Fat-Zer) doCommand(Doc,"App.activeDocument().%s.Label = '%s'", PartName.c_str(), QObject::tr(PartName.c_str()).toUtf8().data()); doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, PartName.c_str()); updateActive(); }
void CmdPartSimpleCopy::activated(int iMsg) { Base::Type partid = Base::Type::fromName("Part::Feature"); std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType(partid); openCommand("Create Copy"); for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) { doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape=" "App.ActiveDocument.%s.Shape\n" "App.ActiveDocument.ActiveObject.Label=" "App.ActiveDocument.%s.Label\n", (*it)->getNameInDocument(), (*it)->getNameInDocument(), (*it)->getNameInDocument()); copyVisual("ActiveObject", "ShapeColor", (*it)->getNameInDocument()); copyVisual("ActiveObject", "LineColor", (*it)->getNameInDocument()); copyVisual("ActiveObject", "PointColor", (*it)->getNameInDocument()); } commitCommand(); updateActive(); }
void CmdPointsImport::activated(int iMsg) { QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString::null, QString(), QObject::tr("Ascii Points (*.asc);;All Files (*.*)")); if ( fn.isEmpty() ) return; if (! fn.isEmpty() ) { QFileInfo fi; fi.setFile(fn); openCommand("Points Import Create"); doCommand(Doc,"f = App.ActiveDocument.addObject(\"Points::ImportAscii\",\"%s\")", (const char*)fi.baseName().toAscii()); doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii()); commitCommand(); updateActive(); } }
void CmdPathShape::activated(int iMsg) { std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); if (Sel.size() == 1) { if (Sel[0].pObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { Part::Feature *pcPartObject = dynamic_cast<Part::Feature*>(Sel[0].pObject); std::string FeatName = getUniqueObjectName("PathShape"); openCommand("Create Path Compound"); doCommand(Doc,"FreeCAD.activeDocument().addObject('Path::FeatureShape','%s')",FeatName.c_str()); doCommand(Doc,"FreeCAD.activeDocument().%s.Shape = FreeCAD.activeDocument().%s.Shape.copy()",FeatName.c_str(),pcPartObject->getNameInDocument()); commitCommand(); updateActive(); } else { Base::Console().Error("Exactly one shape object must be selected\n"); return; } } else { Base::Console().Error("Exactly one shape object must be selected\n"); return; } }
void CmdPartShapeFromMesh::activated(int iMsg) { Q_UNUSED(iMsg); bool ok; double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Sewing Tolerance"), QObject::tr("Enter tolerance for sewing shape:"), 0.1, 0.01,10.0,2,&ok); if (!ok) return; Base::Type meshid = Base::Type::fromName("Mesh::Feature"); std::vector<App::DocumentObject*> meshes; meshes = Gui::Selection().getObjectsOfType(meshid); Gui::WaitCursor wc; std::vector<App::DocumentObject*>::iterator it; openCommand("Convert mesh"); for (it = meshes.begin(); it != meshes.end(); ++it) { App::Document* doc = (*it)->getDocument(); std::string mesh = (*it)->getNameInDocument(); std::string name = doc->getUniqueObjectName(mesh.c_str()); doCommand(Doc,"import Part"); doCommand(Doc,"FreeCAD.getDocument(\"%s\").addObject(\"Part::Feature\",\"%s\")" ,doc->getName() ,name.c_str()); doCommand(Doc,"__shape__=Part.Shape()"); doCommand(Doc,"__shape__.makeShapeFromMesh(" "FreeCAD.getDocument(\"%s\").getObject(\"%s\").Mesh.Topology,%f" ")" ,doc->getName() ,mesh.c_str() ,tol); doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Shape=__shape__" ,doc->getName() ,name.c_str()); doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").purgeTouched()" ,doc->getName() ,name.c_str()); doCommand(Doc,"del __shape__"); } commitCommand(); }
void CmdPartSimpleCopy::activated(int iMsg) { Q_UNUSED(iMsg); Base::Type partid = Base::Type::fromName("Part::Feature"); std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx(0, partid); openCommand("Create Copy"); for (std::vector<Gui::SelectionObject>::iterator it = objs.begin(); it != objs.end(); ++it) { doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape=" "App.ActiveDocument.%s.Shape\n" "App.ActiveDocument.ActiveObject.Label=" "App.ActiveDocument.%s.Label\n", it->getFeatName(), it->getFeatName(), it->getFeatName()); copyVisual("ActiveObject", "ShapeColor", it->getFeatName()); copyVisual("ActiveObject", "LineColor", it->getFeatName()); copyVisual("ActiveObject", "PointColor", it->getFeatName()); copyVisual("ActiveObject", "DiffuseColor", it->getFeatName()); } commitCommand(); updateActive(); }