void Placement::applyPlacement(const Base::Placement& p, bool incremental) { Gui::Document* document = Application::Instance->activeDocument(); if (!document) return; std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType (App::DocumentObject::getClassTypeId(), document->getDocument()->getName()); if (!sel.empty()) { // apply transformation only on view matrix not on placement property for (std::vector<App::DocumentObject*>::iterator it=sel.begin();it!=sel.end();++it) { std::map<std::string,App::Property*> props; (*it)->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_placement(this->propertyName)); if (jt != props.end()) { Base::Placement cur = static_cast<App::PropertyPlacement*>(jt->second)->getValue(); if (incremental) cur = p * cur; else cur = p; Gui::ViewProvider* vp = document->getViewProvider(*it); if (vp) vp->setTransformation(cur.toMatrix()); } } } else { Base::Console().Warning("No object selected.\n"); } }
void DlgEvaluateMeshImp::on_repairFoldsButton_clicked() { if (d->meshFeature) { const char* docName = App::GetApplication().getDocumentName(d->meshFeature->getDocument()); const char* objName = d->meshFeature->getNameInDocument(); Gui::Document* doc = Gui::Application::Instance->getDocument(docName); qApp->setOverrideCursor(Qt::WaitCursor); doc->openCommand("Remove folds"); try { Gui::Application::Instance->runCommand( true, "App.getDocument(\"%s\").getObject(\"%s\").removeFoldsOnSurface()" , docName, objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Folds"), QString::fromLatin1(e.what())); } doc->commitCommand(); doc->getDocument()->recompute(); qApp->restoreOverrideCursor(); repairFoldsButton->setEnabled(false); checkFoldsButton->setChecked(false); removeViewProvider("MeshGui::ViewProviderMeshFolds"); } }
void DlgEvaluateMeshImp::on_repairSelfIntersectionButton_clicked() { if (d->meshFeature) { const char* docName = App::GetApplication().getDocumentName(d->meshFeature->getDocument()); #if 0 const char* objName = d->meshFeature->getNameInDocument(); #endif Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand("Fix self-intersections"); #if 0 try { Gui::Application::Instance->runCommand( true, "App.getDocument(\"%s\").getObject(\"%s\").fixSelfIntersections()" , docName, objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Self-intersections"), QString::fromLatin1(e.what())); } #else Mesh::MeshObject* mesh = d->meshFeature->Mesh.startEditing(); mesh->removeSelfIntersections(d->self_intersections); d->meshFeature->Mesh.finishEditing(); #endif doc->commitCommand(); doc->getDocument()->recompute(); repairSelfIntersectionButton->setEnabled(false); checkSelfIntersectionButton->setChecked(false); removeViewProvider("MeshGui::ViewProviderMeshSelfIntersections"); } }
void DlgEvaluateMeshImp::on_repairNonmanifoldsButton_clicked() { if (d->meshFeature) { const char* docName = App::GetApplication().getDocumentName(d->meshFeature->getDocument()); const char* objName = d->meshFeature->getNameInDocument(); Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand("Remove non-manifolds"); try { Gui::Application::Instance->runCommand( true, "App.getDocument(\"%s\").getObject(\"%s\").removeNonManifolds()" , docName, objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Non-manifolds"), QString::fromLatin1(e.what())); } catch (...) { QMessageBox::warning(this, tr("Non-manifolds"), tr("Cannot remove non-manifolds")); } doc->commitCommand(); doc->getDocument()->recompute(); repairNonmanifoldsButton->setEnabled(false); checkNonmanifoldsButton->setChecked(false); removeViewProvider("MeshGui::ViewProviderMeshNonManifolds"); } }
void ShapeBuilderWidget::on_createButton_clicked() { int mode = d->bg.checkedId(); Gui::Document* doc = Gui::Application::Instance->activeDocument(); if (!doc) return; try { if (mode == 0) { createEdgeFromVertex(); } else if (mode == 1) { createFaceFromVertex(); } else if (mode == 2) { createFaceFromEdge(); } else if (mode == 3) { createShellFromFace(); } else if (mode == 4) { createSolidFromShell(); } doc->getDocument()->recompute(); Gui::Selection().clearSelection(); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); } }
void DownloadItem::open() { QFileInfo info(m_output); QString selectedFilter; QStringList fileList; fileList << info.absoluteFilePath(); SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter); // load the files with the associated modules if (!dict.isEmpty()) { Gui::Document* doc = Gui::Application::Instance->activeDocument(); if (doc) { for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) { Gui::Application::Instance->importFrom(it.key().toUtf8(), doc->getDocument()->getName(), it.value().toAscii()); } } else { for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) { Gui::Application::Instance->open(it.key().toUtf8(), it.value().toAscii()); } } } else { QUrl url = QUrl::fromLocalFile(info.absolutePath()); QDesktopServices::openUrl(url); } }
void ViewProviderPythonFeatureObserver::slotDeleteDocument(const Gui::Document& d) { App::Document* doc = d.getDocument(); std::map<const App::Document*, ObjectProxy>::iterator it = proxyMap.find(doc); if (it != proxyMap.end()) { proxyMap.erase(it); } }
void Placement::applyPlacement(const QString& data, bool incremental) { Gui::Document* document = Application::Instance->activeDocument(); if (!document) return; std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType (App::DocumentObject::getClassTypeId(), document->getDocument()->getName()); if (!sel.empty()) { document->openCommand("Placement"); for (std::vector<App::DocumentObject*>::iterator it=sel.begin();it!=sel.end();++it) { std::map<std::string,App::Property*> props; (*it)->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_placement(this->propertyName)); if (jt != props.end()) { QString cmd; if (incremental) cmd = QString::fromAscii( "App.getDocument(\"%1\").%2.Placement=%3.multiply(App.getDocument(\"%1\").%2.Placement)") .arg(QLatin1String((*it)->getDocument()->getName())) .arg(QLatin1String((*it)->getNameInDocument())) .arg(data); else { cmd = QString::fromAscii( "App.getDocument(\"%1\").%2.Placement=%3") .arg(QLatin1String((*it)->getDocument()->getName())) .arg(QLatin1String((*it)->getNameInDocument())) .arg(data); } Application::Instance->runPythonCode((const char*)cmd.toAscii()); } } document->commitCommand(); try { document->getDocument()->recompute(); } catch (...) { } } else { Base::Console().Warning("No object selected.\n"); } }
bool Command::isActiveObjectValid(void) { Gui::Document* active = Gui::Application::Instance->activeDocument(); assert(active); App::Document* document = active->getDocument(); App::DocumentObject* object = document->getActiveObject(); assert(object); return object->isValid(); }
void addFacesToSelection(Gui::View3DInventorViewer* /*viewer*/, const Gui::ViewVolumeProjection& proj, const Base::Polygon2d& polygon, const TopoDS_Shape& shape) { try { TopTools_IndexedMapOfShape M; TopExp_Explorer xp_face(shape,TopAbs_FACE); while (xp_face.More()) { M.Add(xp_face.Current()); xp_face.Next(); } App::Document* appdoc = doc->getDocument(); for (Standard_Integer k = 1; k <= M.Extent(); k++) { const TopoDS_Shape& face = M(k); TopExp_Explorer xp_vertex(face,TopAbs_VERTEX); while (xp_vertex.More()) { gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(xp_vertex.Current())); Base::Vector3d pt2d; pt2d = proj(Base::Vector3d(p.X(), p.Y(), p.Z())); if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y))) { #if 0 // TODO if (isVisibleFace(k-1, SbVec2f(pt2d.x, pt2d.y), viewer)) #endif { std::stringstream str; str << "Face" << k; Gui::Selection().addSelection(appdoc->getName(), obj->getNameInDocument(), str.str().c_str()); break; } } xp_vertex.Next(); } //GProp_GProps props; //BRepGProp::SurfaceProperties(face, props); //gp_Pnt c = props.CentreOfMass(); //Base::Vector3d pt2d; //pt2d = proj(Base::Vector3d(c.X(), c.Y(), c.Z())); //if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y))) { // if (isVisibleFace(k-1, SbVec2f(pt2d.x, pt2d.y), viewer)) { // std::stringstream str; // str << "Face" << k; // Gui::Selection().addSelection(appdoc->getName(), obj->getNameInDocument(), str.str().c_str()); // } //} } } catch (...) { } }
App::Document* Command::getDocument(const char* Name) const { if (Name) { return App::GetApplication().getDocument(Name); } else { Gui::Document * pcDoc = getGuiApplication()->activeDocument(); if (pcDoc) return pcDoc->getDocument(); else return 0l; } }
Py::Object interactiveFilletArc(const Py::Tuple& args) { Gui::Document* doc = Gui::Application::Instance->activeDocument(); if (doc) { Gui::View3DInventor* view = qobject_cast<Gui::View3DInventor*>(doc->getActiveView()); if (view) { Gui::View3DInventorViewer* viewer = view->getViewer(); SoSeparator* scene = static_cast<SoSeparator*>(viewer->getSceneGraph()); SoSeparator* node = new SoSeparator(); SoBaseColor* rgb = new SoBaseColor(); rgb->rgb.setValue(1,1,0); node->addChild(rgb); SoCoordinate3* coords = new SoCoordinate3(); node->addChild(coords); node->addChild(new SoLineSet()); scene->addChild(node); ObjectObserver* obs = new ObjectObserver(doc->getDocument()->getActiveObject(), coords); obs->attachDocument(doc->getDocument()); } } return Py::None(); }
bool LoftWidget::accept() { QString list, solid, ruled; if (d->ui.checkSolid->isChecked()) solid = QString::fromAscii("True"); else solid = QString::fromAscii("False"); if (d->ui.checkRuledSurface->isChecked()) ruled = QString::fromAscii("True"); else ruled = QString::fromAscii("False"); QTextStream str(&list); int count = d->ui.treeWidgetLoft->topLevelItemCount(); if (count < 2) { QMessageBox::critical(this, tr("Too few elements"), tr("At least two vertices, edges or wires are required.")); return false; } for (int i=0; i<count; i++) { QTreeWidgetItem* child = d->ui.treeWidgetLoft->topLevelItem(i); QString name = child->data(0, Qt::UserRole).toString(); str << "App.getDocument('" << d->document.c_str() << "')." << name << ", "; } try { QString cmd; cmd = QString::fromAscii( "App.getDocument('%4').addObject('Part::Loft','Loft')\n" "App.getDocument('%4').ActiveObject.Sections=[%1]\n" "App.getDocument('%4').ActiveObject.Solid=%2\n" "App.getDocument('%4').ActiveObject.Ruled=%3\n" ).arg(list).arg(solid).arg(ruled).arg(QString::fromAscii(d->document.c_str())); Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); if (!doc) throw Base::Exception("Document doesn't exist anymore"); doc->openCommand("Loft"); Gui::Application::Instance->runPythonCode((const char*)cmd.toAscii(), false, false); doc->commitCommand(); doc->getDocument()->recompute(); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); return false; } return true; }
bool TaskCSysDragger::accept() { lastTranslationIncrement = dragger->translationIncrement.getValue(); lastRotationIncrement = dragger->rotationIncrement.getValue(); App::DocumentObject* dObject = vpObject.getObject(); if (dObject) { Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument()); assert(document); document->commitCommand(); document->resetEdit(); document->getDocument()->recompute(); } return Gui::TaskView::TaskDialog::accept(); }
void DlgEvaluateMeshImp::on_refreshButton_clicked() { // Connect to application and active document Gui::Document* gui = Gui::Application::Instance->activeDocument(); if (gui) { App::Document* doc = gui->getDocument(); // switch to the active document if (doc && doc != this->getDocument()) { attachDocument(doc); removeViewProviders(); d->view = dynamic_cast<Gui::View3DInventor*>(gui->getActiveView()); } } refreshList(); }
void PointMarker::customEvent(QEvent* e) { Gui::Document* doc = Gui::Application::Instance->activeDocument(); App::DocumentObject* obj = doc->getDocument()->addObject (App::MeasureDistance::getClassTypeId().getName(),"Distance"); App::MeasureDistance* md = static_cast<App::MeasureDistance*>(obj); const SbVec3f& pt1 = vp->pCoords->point[0]; const SbVec3f& pt2 = vp->pCoords->point[1]; md->P1.setValue(Base::Vector3d(pt1[0],pt1[1],pt1[2])); md->P2.setValue(Base::Vector3d(pt2[0],pt2[1],pt2[2])); std::stringstream s; s.precision(3); s.setf(std::ios::fixed | std::ios::showpoint); s << "Distance: " << md->Distance.getValue(); md->Label.setValue(s.str()); }
void ViewProviderPage::onSelectionChanged(const Gui::SelectionChanges& msg) { if(!view.isNull()) { if(msg.Type == Gui::SelectionChanges::SetSelection) { view->clearSelection(); std::vector<Gui::SelectionSingleton::SelObj> objs = Gui::Selection().getSelection(msg.pDocName); for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = objs.begin(); it != objs.end(); ++it) { Gui::SelectionSingleton::SelObj selObj = *it; if(selObj.pObject == getPageObject()) continue; std::string str = msg.pSubName; // If it's a subfeature, dont select feature if (!str.empty()) { if (TechDraw::DrawUtil::getGeomTypeFromName(str) == "Face" || TechDraw::DrawUtil::getGeomTypeFromName(str) == "Edge" || TechDraw::DrawUtil::getGeomTypeFromName(str) == "Vertex") { // TODO implement me wf: don't think this is ever executed } } else { view->selectFeature(selObj.pObject, true); } } } else { bool selectState = (msg.Type == Gui::SelectionChanges::AddSelection) ? true : false; Gui::Document* doc = Gui::Application::Instance->getDocument(pcObject->getDocument()); App::DocumentObject *obj = doc->getDocument()->getObject(msg.pObjectName); if(obj) { std::string str = msg.pSubName; // If it's a subfeature, dont select feature if (!str.empty()) { if (TechDraw::DrawUtil::getGeomTypeFromName(str) == "Face" || TechDraw::DrawUtil::getGeomTypeFromName(str) == "Edge" || TechDraw::DrawUtil::getGeomTypeFromName(str) == "Vertex") { // TODO implement me } else { view->selectFeature(obj, selectState); } } } } //else (Gui::SelectionChanges::SetPreselect) } }
void PointMarker::customEvent(QEvent*) { Gui::Document* doc = Gui::Application::Instance->activeDocument(); doc->openCommand("Measure distance"); App::DocumentObject* obj = doc->getDocument()->addObject (App::MeasureDistance::getClassTypeId().getName(),"Distance"); App::MeasureDistance* md = static_cast<App::MeasureDistance*>(obj); const SbVec3f& pt1 = vp->pCoords->point[0]; const SbVec3f& pt2 = vp->pCoords->point[1]; md->P1.setValue(Base::Vector3d(pt1[0],pt1[1],pt1[2])); md->P2.setValue(Base::Vector3d(pt2[0],pt2[1],pt2[2])); QString str = QString::fromLatin1("Distance: %1") .arg(Base::Quantity(md->Distance.getValue(), Base::Unit::Length).getUserString()); md->Label.setValue(str.toUtf8().constData()); doc->commitCommand(); this->deleteLater(); }
void Placement::revertTransformation() { for (std::set<std::string>::iterator it = documents.begin(); it != documents.end(); ++it) { Gui::Document* document = Application::Instance->getDocument(it->c_str()); if (!document) continue; std::vector<App::DocumentObject*> obj = document->getDocument()-> getObjectsOfType(App::DocumentObject::getClassTypeId()); if (!obj.empty()) { for (std::vector<App::DocumentObject*>::iterator it=obj.begin();it!=obj.end();++it) { std::map<std::string,App::Property*> props; (*it)->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_placement(this->propertyName)); if (jt != props.end()) { Base::Placement cur = static_cast<App::PropertyPlacement*>(jt->second)->getValue(); Gui::ViewProvider* vp = document->getViewProvider(*it); if (vp) vp->setTransformation(cur.toMatrix()); } } } } }
void VisualInspection::accept() { onActivateItem(0); if (buttonOk->isEnabled()) { QDialog::accept(); saveSettings(); // collect all nominal geometries QStringList nominalNames; for (QTreeWidgetItemIterator it(ui->treeWidgetNominal); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) nominalNames << sel->data(0, Qt::UserRole).toString(); } double searchRadius = ui->searchRadius->value().getValue(); double thickness = ui->thickness->value().getValue(); // open a new command Gui::Document* doc = Gui::Application::Instance->activeDocument(); doc->openCommand("Visual Inspection"); // create a group Gui::Command::runCommand( Gui::Command::App, "App_activeDocument___InspectionGroup=App.ActiveDocument.addObject(\"Inspection::Group\",\"Inspection\")"); // for each actual geometry create an inspection feature for (QTreeWidgetItemIterator it(ui->treeWidgetActual); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { QString actualName = sel->data(0, Qt::UserRole).toString(); Gui::Command::doCommand(Gui::Command::App, "App_activeDocument___InspectionGroup.newObject(\"Inspection::Feature\",\"%s_Inspect\")", (const char*)actualName.toLatin1()); Gui::Command::doCommand(Gui::Command::App, "App.ActiveDocument.ActiveObject.Actual=App.ActiveDocument.%s\n" "App_activeDocument___activeObject___Nominals=list()\n" "App.ActiveDocument.ActiveObject.SearchRadius=%.3f\n" "App.ActiveDocument.ActiveObject.Thickness=%.3f\n", (const char*)actualName.toLatin1(), searchRadius, thickness); for (QStringList::Iterator it = nominalNames.begin(); it != nominalNames.end(); ++it) { Gui::Command::doCommand(Gui::Command::App, "App_activeDocument___activeObject___Nominals.append(App.ActiveDocument.%s)\n", (const char*)(*it).toLatin1()); } Gui::Command::doCommand(Gui::Command::App, "App.ActiveDocument.ActiveObject.Nominals=App_activeDocument___activeObject___Nominals\n" "del App_activeDocument___activeObject___Nominals\n"); } } Gui::Command::runCommand(Gui::Command::App, "del App_activeDocument___InspectionGroup\n"); doc->commitCommand(); doc->getDocument()->recompute(); // hide the checked features for (QTreeWidgetItemIterator it(ui->treeWidgetActual); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { Gui::Command::doCommand(Gui::Command::App , "Gui.ActiveDocument.getObject(\"%s\").Visibility=False" , (const char*)sel->data(0, Qt::UserRole).toString().toLatin1()); } } for (QTreeWidgetItemIterator it(ui->treeWidgetNominal); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { Gui::Command::doCommand(Gui::Command::App , "Gui.ActiveDocument.getObject(\"%s\").Visibility=False" , (const char*)sel->data(0, Qt::UserRole).toString().toLatin1()); } } } }
bool SweepWidget::accept() { if (d->loop.isRunning()) return false; Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1.."); Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 1"); bool matchEdge = edgeFilter.match(); bool matchPart = partFilter.match(); if (!matchEdge && !matchPart) { QMessageBox::critical(this, tr("Sweep path"), tr("Select one or more connected edges you want to sweep along.")); return false; } // get the selected object std::string selection; std::string spineObject, spineLabel; const std::vector<Gui::SelectionObject>& result = matchEdge ? edgeFilter.Result[0] : partFilter.Result[0]; selection = result.front().getAsPropertyLinkSubString(); spineObject = result.front().getFeatName(); spineLabel = result.front().getObject()->Label.getValue(); QString list, solid, frenet; if (d->ui.checkSolid->isChecked()) solid = QString::fromLatin1("True"); else solid = QString::fromLatin1("False"); if (d->ui.checkFrenet->isChecked()) frenet = QString::fromLatin1("True"); else frenet = QString::fromLatin1("False"); QTextStream str(&list); int count = d->ui.selector->selectedTreeWidget()->topLevelItemCount(); if (count < 1) { QMessageBox::critical(this, tr("Too few elements"), tr("At least one edge or wire is required.")); return false; } for (int i=0; i<count; i++) { QTreeWidgetItem* child = d->ui.selector->selectedTreeWidget()->topLevelItem(i); QString name = child->data(0, Qt::UserRole).toString(); if (name == QLatin1String(spineObject.c_str())) { QMessageBox::critical(this, tr("Wrong selection"), tr("'%1' cannot be used as profile and path.") .arg(QString::fromUtf8(spineLabel.c_str()))); return false; } str << "App.getDocument('" << d->document.c_str() << "')." << name << ", "; } try { Gui::WaitCursor wc; QString cmd; cmd = QString::fromLatin1( "App.getDocument('%5').addObject('Part::Sweep','Sweep')\n" "App.getDocument('%5').ActiveObject.Sections=[%1]\n" "App.getDocument('%5').ActiveObject.Spine=%2\n" "App.getDocument('%5').ActiveObject.Solid=%3\n" "App.getDocument('%5').ActiveObject.Frenet=%4\n" ) .arg(list) .arg(QLatin1String(selection.c_str())) .arg(solid) .arg(frenet) .arg(QString::fromLatin1(d->document.c_str())); Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); if (!doc) throw Base::Exception("Document doesn't exist anymore"); doc->openCommand("Sweep"); Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); doc->getDocument()->recompute(); App::DocumentObject* obj = doc->getDocument()->getActiveObject(); if (obj && !obj->isValid()) { std::string msg = obj->getStatusString(); doc->abortCommand(); throw Base::Exception(msg); } doc->commitCommand(); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Input error"), QString::fromLatin1(e.what())); return false; } return true; }
void Placement::slotActiveDocument(const Gui::Document& doc) { documents.insert(doc.getDocument()->getName()); }
void Workbench::slotActiveDocument(const Gui::Document& Doc) { switchToDocument(Doc.getDocument()); }
bool SweepWidget::accept() { Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1.."); Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 1"); bool matchEdge = edgeFilter.match(); bool matchPart = partFilter.match(); if (!matchEdge && !matchPart) { QMessageBox::critical(this, tr("Sweep path"), tr("Select an edge or wire you want to sweep along.")); return false; } // get the selected object std::string selection; if (matchEdge) { const std::vector<Gui::SelectionObject>& result = edgeFilter.Result[0]; selection = result.front().getAsPropertyLinkSubString(); } else { const std::vector<Gui::SelectionObject>& result = partFilter.Result[0]; selection = result.front().getAsPropertyLinkSubString(); } QString list, solid, frenet; if (d->ui.checkSolid->isChecked()) solid = QString::fromAscii("True"); else solid = QString::fromAscii("False"); if (d->ui.checkFrenet->isChecked()) frenet = QString::fromAscii("True"); else frenet = QString::fromAscii("False"); QTextStream str(&list); int count = d->ui.selector->selectedTreeWidget()->topLevelItemCount(); if (count < 1) { QMessageBox::critical(this, tr("Too few elements"), tr("At least one edge or wire is required.")); return false; } for (int i=0; i<count; i++) { QTreeWidgetItem* child = d->ui.selector->selectedTreeWidget()->topLevelItem(i); QString name = child->data(0, Qt::UserRole).toString(); str << "App.getDocument('" << d->document.c_str() << "')." << name << ", "; } try { QString cmd; cmd = QString::fromAscii( "App.getDocument('%5').addObject('Part::Sweep','Sweep')\n" "App.getDocument('%5').ActiveObject.Sections=[%1]\n" "App.getDocument('%5').ActiveObject.Spine=%2\n" "App.getDocument('%5').ActiveObject.Solid=%3\n" "App.getDocument('%5').ActiveObject.Frenet=%4\n" ) .arg(list) .arg(QLatin1String(selection.c_str())) .arg(solid) .arg(frenet) .arg(QString::fromAscii(d->document.c_str())); Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); if (!doc) throw Base::Exception("Document doesn't exist anymore"); doc->openCommand("Sweep"); Gui::Application::Instance->runPythonCode((const char*)cmd.toAscii(), false, false); doc->commitCommand(); doc->getDocument()->recompute(); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); return false; } return true; }
void DlgEvaluateMeshImp::on_repairAllTogether_clicked() { if (d->meshFeature) { Gui::WaitCursor wc; const char* docName = App::GetApplication().getDocumentName(d->meshFeature->getDocument()); const char* objName = d->meshFeature->getNameInDocument(); Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand("Repair mesh"); bool run = false; bool self = true; int max_iter=10; const MeshKernel& rMesh = d->meshFeature->Mesh.getValue().getKernel(); try { do { run = false; { MeshEvalSelfIntersection eval(rMesh); if (self && !eval.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").fixSelfIntersections()", docName, objName); run = true; } else { self = false; // once no self-intersections found do not repeat it later on } qApp->processEvents(); } { MeshEvalFoldsOnSurface s_eval(rMesh); MeshEvalFoldsOnBoundary b_eval(rMesh); MeshEvalFoldOversOnSurface f_eval(rMesh); if (!s_eval.Evaluate() || !b_eval.Evaluate() || !f_eval.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").removeFoldsOnSurface()", docName, objName); run = true; } qApp->processEvents(); } { MeshEvalOrientation eval(rMesh); if (!eval.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").harmonizeNormals()", docName, objName); run = true; } qApp->processEvents(); } { MeshEvalTopology eval(rMesh); if (!eval.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").removeNonManifolds()", docName, objName); run = true; } qApp->processEvents(); } { MeshEvalRangeFacet rf(rMesh); MeshEvalRangePoint rp(rMesh); MeshEvalCorruptedFacets cf(rMesh); MeshEvalNeighbourhood nb(rMesh); if (!rf.Evaluate() || !rp.Evaluate() || !cf.Evaluate() || !nb.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").fixIndices()", docName, objName); run = true; } } { MeshEvalDegeneratedFacets eval(rMesh); if (!eval.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").fixDegenerations()", docName, objName); run = true; } qApp->processEvents(); } { MeshEvalDuplicateFacets eval(rMesh); if (!eval.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").removeDuplicatedFacets()", docName, objName); run = true; } qApp->processEvents(); } { MeshEvalDuplicatePoints eval(rMesh); if (!eval.Evaluate()) { Gui::Application::Instance->runCommand(true, "App.getDocument(\"%s\").getObject(\"%s\").removeDuplicatedPoints()", docName, objName); run = true; } qApp->processEvents(); } } while(checkRepeatButton->isChecked() && run && (--max_iter > 0)); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Mesh repair"), QString::fromLatin1(e.what())); } catch (...) { QMessageBox::warning(this, tr("Mesh repair"), QString::fromLatin1("Unknown error occurred.")); } doc->commitCommand(); doc->getDocument()->recompute(); } }
void Placement::applyPlacement(const Base::Placement& p, bool incremental, bool data) { Gui::Document* document = Application::Instance->activeDocument(); if (!document) return; std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType (App::DocumentObject::getClassTypeId(), document->getDocument()->getName()); if (!sel.empty()) { if (data) { document->openCommand("Placement"); for (std::vector<App::DocumentObject*>::iterator it=sel.begin();it!=sel.end();++it) { std::map<std::string,App::Property*> props; (*it)->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_placement(this->propertyName)); if (jt != props.end()) { Base::Placement cur = static_cast<App::PropertyPlacement*>(jt->second)->getValue(); if (incremental) cur = p * cur; else cur = p; Base::Vector3d pos = cur.getPosition(); const Base::Rotation& rt = cur.getRotation(); QString cmd = QString::fromAscii( "App.getDocument(\"%1\").%2.Placement=" "App.Placement(" "App.Vector(%3,%4,%5)," "App.Rotation(%6,%7,%8,%9))\n") .arg(QLatin1String((*it)->getDocument()->getName())) .arg(QLatin1String((*it)->getNameInDocument())) .arg(pos.x,0,'g',6) .arg(pos.y,0,'g',6) .arg(pos.z,0,'g',6) .arg(rt[0],0,'g',6) .arg(rt[1],0,'g',6) .arg(rt[2],0,'g',6) .arg(rt[3],0,'g',6); Application::Instance->runPythonCode((const char*)cmd.toAscii()); } } document->commitCommand(); try { document->getDocument()->recompute(); } catch (...) { } } // apply transformation only on view matrix not on placement property else { for (std::vector<App::DocumentObject*>::iterator it=sel.begin();it!=sel.end();++it) { std::map<std::string,App::Property*> props; (*it)->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_placement(this->propertyName)); if (jt != props.end()) { Base::Placement cur = static_cast<App::PropertyPlacement*>(jt->second)->getValue(); if (incremental) cur = p * cur; else cur = p; Gui::ViewProvider* vp = document->getViewProvider(*it); if (vp) vp->setTransformation(cur.toMatrix()); } } } } else { Base::Console().Warning("No object selected.\n"); } }