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 ViewProviderDocumentObjectGroup::drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) { // Open command App::DocumentObjectGroup* grp = static_cast<App::DocumentObjectGroup*>(getObject()); App::Document* doc = grp->getDocument(); Gui::Document* gui = Gui::Application::Instance->getDocument(doc); gui->openCommand("Move object"); for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it) { // get document object const App::DocumentObject* obj = *it; const App::DocumentObjectGroup* par = App::DocumentObjectGroup::getGroupOfObject(obj); if (par) { // allow an object to be in one group only QString cmd; cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").removeObject(" "App.getDocument(\"%1\").getObject(\"%3\"))") .arg(QString::fromLatin1(doc->getName())) .arg(QString::fromLatin1(par->getNameInDocument())) .arg(QString::fromLatin1(obj->getNameInDocument())); Gui::Application::Instance->runPythonCode(cmd.toUtf8()); } // build Python command for execution QString cmd; cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").addObject(" "App.getDocument(\"%1\").getObject(\"%3\"))") .arg(QString::fromLatin1(doc->getName())) .arg(QString::fromLatin1(grp->getNameInDocument())) .arg(QString::fromLatin1(obj->getNameInDocument())); Gui::Application::Instance->runPythonCode(cmd.toUtf8()); } gui->commitCommand(); }
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 TransformStrategy::commitTransform(const Base::Matrix4D& mat) { std::set<App::DocumentObject*> objects = transformObjects(); Gui::Document* doc = Gui::Application::Instance->activeDocument(); if (doc) { doc->openCommand("Transform"); for (std::set<App::DocumentObject*>::iterator it=objects.begin();it!=objects.end();++it) { acceptDataTransform(mat, *it); } doc->commitCommand(); } }
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 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"); } }
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(); }
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; }
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 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"); } }
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()); } } } }
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(); } }