PyObject* SketchObjectPy::addExternal(PyObject *args) { char *ObjectName; char *SubName; if (!PyArg_ParseTuple(args, "ss:Give an object and subelement name", &ObjectName,&SubName)) return 0; // get the target object for the external link Sketcher::SketchObject* skObj = this->getSketchObjectPtr(); App::DocumentObject * Obj = skObj->getDocument()->getObject(ObjectName); if (!Obj) { std::stringstream str; str << ObjectName << " does not exist in the document"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); return 0; } // check if this type of external geometry is allowed if (!skObj->isExternalAllowed(Obj->getDocument(), Obj)) { std::stringstream str; str << ObjectName << " is not allowed as external geometry of this sketch"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); return 0; } // add the external if (skObj->addExternal(Obj,SubName) < 0) { std::stringstream str; str << "Not able to add external shape element"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); return 0; } Py_Return; }
void CmdSketcherConnect::activated(int iMsg) { // get the selection std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(); // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select at least two edges from the sketch.")); return; } // get the needed lists and objects const std::vector<std::string> &SubNames = selection[0].getSubNames(); if (SubNames.size() < 2) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select at least two edges from the sketch.")); return; } Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject()); // undo command open openCommand("add coincident constraint"); // go through the selected subelements for (unsigned int i=0; i<(SubNames.size()-1); i++ ) { // only handle edges if (SubNames[i].size() > 4 && SubNames[i].substr(0,4) == "Edge" && SubNames[i+1].size() > 4 && SubNames[i+1].substr(0,4) == "Edge" ) { int GeoId1 = std::atoi(SubNames[i].substr(4,4000).c_str()) - 1; int GeoId2 = std::atoi(SubNames[i+1].substr(4,4000).c_str()) - 1; const Part::Geometry *geo1 = Obj->getGeometry(GeoId1); const Part::Geometry *geo2 = Obj->getGeometry(GeoId2); if ((geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() && geo1->getTypeId() != Part::GeomArcOfCircle::getClassTypeId()) || (geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId() && geo2->getTypeId() != Part::GeomArcOfCircle::getClassTypeId())) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Impossible constraint"), QObject::tr("One selected edge is not connectable")); abortCommand(); return; } Gui::Command::doCommand( Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", selection[0].getFeatName(),GeoId1,Sketcher::end,GeoId2,Sketcher::start); } } // finish the transaction and update commitCommand(); updateActive(); // clear the selection (convenience) getSelection().clearSelection(); }
void CmdSketcherIncreaseDegree::activated(int iMsg) { Q_UNUSED(iMsg); // get the selection std::vector<Gui::SelectionObject> selection; selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId()); // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { return; } // get the needed lists and objects const std::vector<std::string> &SubNames = selection[0].getSubNames(); Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject()); openCommand("Increase degree"); bool ignored=false; for (unsigned int i=0; i<SubNames.size(); i++ ) { // only handle edges if (SubNames[i].size() > 4 && SubNames[i].substr(0,4) == "Edge") { int GeoId = std::atoi(SubNames[i].substr(4,4000).c_str()) - 1; const Part::Geometry * geo = Obj->getGeometry(GeoId); if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { Gui::Command::doCommand( Doc,"App.ActiveDocument.%s.increaseBSplineDegree(%d) ", selection[0].getFeatName(),GeoId); // add new control points Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.exposeInternalGeometry(%d)", selection[0].getFeatName(), GeoId); } else { ignored=true; } } } if(ignored) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("At least one of the selected objects was not a B-Spline and was ignored.")); } commitCommand(); tryAutoRecomputeIfNotSolve(Obj); getSelection().clearSelection(); }
void CmdSketcherEditSketch::activated(int iMsg) { Gui::SelectionFilter SketchFilter("SELECT Sketcher::SketchObject COUNT 1"); if (SketchFilter.match()) { Sketcher::SketchObject *Sketch = static_cast<Sketcher::SketchObject*>(SketchFilter.Result[0][0].getObject()); openCommand("Edit Sketch"); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",Sketch->getNameInDocument()); } }
void CmdSketcherMergeSketches::activated(int iMsg) { std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId()); if (selection.size() < 2) { QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdSketcherMergeSketches", "Wrong selection"), qApp->translate("CmdSketcherMergeSketches", "Select at least two sketches, please.")); return; } App::Document* doc = App::GetApplication().getActiveDocument(); // create Sketch std::string FeatName = getUniqueObjectName("Sketch"); openCommand("Create a merge Sketch"); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); Sketcher::SketchObject* mergesketch = static_cast<Sketcher::SketchObject*>(doc->getObject(FeatName.c_str())); int baseGeometry=0; int baseConstraints=0; for (std::vector<Gui::SelectionObject>::const_iterator it=selection.begin(); it != selection.end(); ++it) { const Sketcher::SketchObject* Obj = static_cast<const Sketcher::SketchObject*>((*it).getObject()); int addedGeometries=mergesketch->addGeometry(Obj->getInternalGeometry()); int addedConstraints=mergesketch->addConstraints(Obj->Constraints.getValues()); for(int i=0; i<=(addedConstraints-baseConstraints); i++){ Sketcher::Constraint * constraint= mergesketch->Constraints.getValues()[i+baseConstraints]; if(constraint->First!=Sketcher::Constraint::GeoUndef || constraint->First==-1 || constraint->First==-2) // not x, y axes or origin constraint->First+=baseGeometry; if(constraint->Second!=Sketcher::Constraint::GeoUndef || constraint->Second==-1 || constraint->Second==-2) // not x, y axes or origin constraint->Second+=baseGeometry; if(constraint->Third!=Sketcher::Constraint::GeoUndef || constraint->Third==-1 || constraint->Third==-2) // not x, y axes or origin constraint->Third+=baseGeometry; } baseGeometry=addedGeometries+1; baseConstraints=addedConstraints+1; } doCommand(Gui,"App.activeDocument().recompute()"); }
void CmdSketcherSelectConstraints::activated(int iMsg) { // get the selection std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(); Sketcher::SketchObject* Obj = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject()); // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select elements from a single sketch.")); return; } // get the needed lists and objects const std::vector<std::string> &SubNames = selection[0].getSubNames(); const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); std::stringstream ss; getSelection().clearSelection(); // go through the selected subelements for (std::vector<std::string>::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { // only handle edges if (it->size() > 4 && it->substr(0,4) == "Edge") { int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; // push all the constraints int i=1; for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); it != vals.end(); ++it,++i) { if ( (*it)->First == GeoId || (*it)->Second == GeoId || (*it)->Third == GeoId){ ss.str(std::string()); ss << "Constraint" << i; Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); } } } } }
void TaskGrooveParameters::onAxisChanged(int num) { PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(GrooveView->getObject()); Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue()); if (pcSketch) { int maxcount = pcSketch->getAxisCount()+2; if (num == 0) pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"V_Axis")); else if (num == 1) pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"H_Axis")); else if (num >= 2 && num < maxcount) { QString buf = QString::fromUtf8("Axis%1").arg(num-2); std::string str = buf.toStdString(); pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,str)); } if (num < maxcount && ui->axis->count() > maxcount) ui->axis->setMaxCount(maxcount); } if (updateView()) pcGroove->getDocument()->recomputeFeature(pcGroove); }
void TaskGrooveParameters::onAxisChanged(int num) { PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(GrooveView->getObject()); Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue()); if (pcSketch) { App::DocumentObject *oldRefAxis = pcGroove->ReferenceAxis.getValue(); std::vector<std::string> oldSubRefAxis = pcGroove->ReferenceAxis.getSubValues(); int maxcount = pcSketch->getAxisCount()+2; if (num == 0) pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"V_Axis")); else if (num == 1) pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"H_Axis")); else if (num >= 2 && num < maxcount) { QString buf = QString::fromUtf8("Axis%1").arg(num-2); std::string str = buf.toStdString(); pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,str)); } if (num < maxcount && ui->axis->count() > maxcount) ui->axis->setMaxCount(maxcount); const std::vector<std::string> &newSubRefAxis = pcGroove->ReferenceAxis.getSubValues(); if (oldRefAxis != pcSketch || oldSubRefAxis.size() != newSubRefAxis.size() || oldSubRefAxis[0] != newSubRefAxis[0]) { bool reversed = pcGroove->suggestReversed(); if (reversed != pcGroove->Reversed.getValue()) { pcGroove->Reversed.setValue(reversed); ui->checkBoxReversed->blockSignals(true); ui->checkBoxReversed->setChecked(reversed); ui->checkBoxReversed->blockSignals(false); } } } if (updateView()) pcGroove->getDocument()->recomputeFeature(pcGroove); }
QString TaskGrooveParameters::getReferenceAxis(void) const { // get the support and Sketch PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(GrooveView->getObject()); Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue()); QString buf; if (pcSketch) { buf = QString::fromUtf8("(App.ActiveDocument.%1,[%2])"); buf = buf.arg(QString::fromUtf8(pcSketch->getNameInDocument())); if (ui->axis->currentIndex() == 0) buf = buf.arg(QString::fromUtf8("'V_Axis'")); else if (ui->axis->currentIndex() == 1) buf = buf.arg(QString::fromUtf8("'H_Axis'")); else if (ui->axis->currentIndex() >= 2) { buf = buf.arg(QString::fromUtf8("'Axis%1'")); buf = buf.arg(ui->axis->currentIndex()-2); } } else buf = QString::fromUtf8("''"); return buf; }
void DrawSketchHandler::createAutoConstraints(const std::vector<AutoConstraint> &autoConstrs, int geoId1, Sketcher::PointPos posId1) { if (!sketchgui->Autoconstraints.getValue()) return; // If Autoconstraints property is not set quit if (autoConstrs.size() > 0) { // Open the Command Gui::Command::openCommand("Add auto constraints"); // Iterate through constraints std::vector<AutoConstraint>::const_iterator it = autoConstrs.begin(); for (; it != autoConstrs.end(); ++it) { switch (it->Type) { case Sketcher::Coincident: { if (posId1 == Sketcher::none) continue; // If the auto constraint has a point create a coincident otherwise it is an edge on a point Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) " ,sketchgui->getObject()->getNameInDocument() ,geoId1, posId1, it->GeoId, it->PosId ); } break; case Sketcher::PointOnObject: { int geoId2 = it->GeoId; Sketcher::PointPos posId2 = it->PosId; if (posId1 == Sketcher::none) { // Auto constraining an edge so swap parameters std::swap(geoId1,geoId2); std::swap(posId1,posId2); } Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%i,%i,%i)) " ,sketchgui->getObject()->getNameInDocument() ,geoId1, posId1, geoId2 ); } break; case Sketcher::Horizontal: { bool start_external; bool mid_external; bool end_external; static_cast<Sketcher::SketchObject*>((sketchgui->getObject()))->isCoincidentWithExternalGeometry(geoId1, start_external, mid_external, end_external); if( !(start_external && end_external) ) { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Horizontal',%i)) " ,sketchgui->getObject()->getNameInDocument() ,geoId1 ); } } break; case Sketcher::Vertical: { bool start_external; bool mid_external; bool end_external; static_cast<Sketcher::SketchObject*>((sketchgui->getObject()))->isCoincidentWithExternalGeometry(geoId1, start_external, mid_external, end_external); if( !(start_external && end_external) ) { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Vertical',%i)) " ,sketchgui->getObject()->getNameInDocument() ,geoId1 ); } } break; case Sketcher::Tangent: { Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(sketchgui->getObject()); const Part::Geometry *geom1 = Obj->getGeometry(geoId1); const Part::Geometry *geom2 = Obj->getGeometry(it->GeoId); int geoId2 = it->GeoId; // ellipse tangency support using construction elements (lines) if( geom1 && geom2 && ( geom1->getTypeId() == Part::GeomEllipse::getClassTypeId() || geom2->getTypeId() == Part::GeomEllipse::getClassTypeId() )){ if(geom1->getTypeId() != Part::GeomEllipse::getClassTypeId()) std::swap(geoId1,geoId2); // geoId1 is the ellipse geom1 = Obj->getGeometry(geoId1); geom2 = Obj->getGeometry(geoId2); if( geom2->getTypeId() == Part::GeomEllipse::getClassTypeId() || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ) { // in all these cases an intermediate element is needed makeTangentToEllipseviaNewPoint(Obj,geom1,geom2,geoId1,geoId2); return; } } // arc of ellipse tangency support using external elements if( geom1 && geom2 && ( geom1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() )){ if(geom1->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()) std::swap(geoId1,geoId2); // geoId1 is the arc of ellipse geom1 = Obj->getGeometry(geoId1); geom2 = Obj->getGeometry(geoId2); if( geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ) { // in all these cases an intermediate element is needed makeTangentToArcOfEllipseviaNewPoint(Obj,geom1,geom2,geoId1,geoId2); return; } } Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%i, %i)) " ,sketchgui->getObject()->getNameInDocument() ,geoId1, it->GeoId ); } break; default: break; } Gui::Command::commitCommand(); //Gui::Command::updateActive(); // There is already an recompute in each command creation, this is redundant. } } }
void CmdSketcherNewSketch::activated(int iMsg) { Gui::SelectionFilter SketchFilter("SELECT Sketcher::SketchObject COUNT 1"); Gui::SelectionFilter FaceFilter ("SELECT Part::Feature SUBELEMENT Face COUNT 1"); if (SketchFilter.match()) { Sketcher::SketchObject *Sketch = static_cast<Sketcher::SketchObject*>(SketchFilter.Result[0][0].getObject()); openCommand("Edit Sketch"); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",Sketch->getNameInDocument()); } else if (FaceFilter.match()) { // get the selected object Part::Feature *part = static_cast<Part::Feature*>(FaceFilter.Result[0][0].getObject()); Base::Placement ObjectPos = part->Placement.getValue(); const std::vector<std::string> &sub = FaceFilter.Result[0][0].getSubNames(); if (sub.size() > 1){ // No assert for wrong user input! QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Several sub-elements selected"), QObject::tr("You have to select a single face as support for a sketch!")); return; } // get the selected sub shape (a Face) const Part::TopoShape &shape = part->Shape.getValue(); TopoDS_Shape sh = shape.getSubShape(sub[0].c_str()); const TopoDS_Face& face = TopoDS::Face(sh); if (face.IsNull()){ // No assert for wrong user input! QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No support face selected"), QObject::tr("You have to select a face as support for a sketch!")); return; } BRepAdaptor_Surface adapt(face); if (adapt.GetType() != GeomAbs_Plane){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No planar support"), QObject::tr("You need a planar face as support for a sketch!")); return; } std::string supportString = FaceFilter.Result[0][0].getAsPropertyLinkSubString(); // create Sketch on Face std::string FeatName = getUniqueObjectName("Sketch"); openCommand("Create a Sketch on Face"); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); doCommand(Gui,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str()); doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support //doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str()); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); } else { // ask user for orientation SketchOrientationDialog Dlg; if (Dlg.exec() != QDialog::Accepted) return; // canceled Base::Vector3d p = Dlg.Pos.getPosition(); Base::Rotation r = Dlg.Pos.getRotation(); // do the right view direction std::string camstring; switch(Dlg.DirType){ case 0: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA \\n position 0 0 87 \\n orientation 0 0 1 0 \\n nearDistance -112.88701 \\n farDistance 287.28702 \\n aspectRatio 1 \\n focalDistance 87 \\n height 143.52005 }"; break; case 1: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA \\n position 0 0 -87 \\n orientation -1 0 0 3.1415927 \\n nearDistance -112.88701 \\n farDistance 287.28702 \\n aspectRatio 1 \\n focalDistance 87 \\n height 143.52005 }"; break; case 2: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position 0 -87 0 \\n orientation -1 0 0 4.712389\\n nearDistance -112.88701\\n farDistance 287.28702\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; case 3: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position 0 87 0 \\n orientation 0 0.70710683 0.70710683 3.1415927\\n nearDistance -112.88701\\n farDistance 287.28702\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; case 4: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position 87 0 0 \\n orientation 0.57735026 0.57735026 0.57735026 2.0943952 \\n nearDistance -112.887\\n farDistance 287.28699\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; case 5: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position -87 0 0 \\n orientation -0.57735026 0.57735026 0.57735026 4.1887903 \\n nearDistance -112.887\\n farDistance 287.28699\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; } std::string FeatName = getUniqueObjectName("Sketch"); openCommand("Create a new Sketch"); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))",FeatName.c_str(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]); doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",camstring.c_str()); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); } }
void CmdSketcherReorientSketch::activated(int iMsg) { Sketcher::SketchObject* sketch = Gui::Selection().getObjectsOfType<Sketcher::SketchObject>().front(); if (sketch->Support.getValue()) { int ret = QMessageBox::question(Gui::getMainWindow(), qApp->translate("Sketcher_ReorientSketch","Sketch has support"), qApp->translate("Sketcher_ReorientSketch","Sketch with a support face cannot be reoriented.\n" "Do you want to detach it from the support?"), QMessageBox::Yes|QMessageBox::No); if (ret == QMessageBox::No) return; sketch->Support.setValue(0); } // ask user for orientation SketchOrientationDialog Dlg; if (Dlg.exec() != QDialog::Accepted) return; // canceled Base::Vector3d p = Dlg.Pos.getPosition(); Base::Rotation r = Dlg.Pos.getRotation(); // do the right view direction std::string camstring; switch(Dlg.DirType){ case 0: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA \\n " "position 0 0 87 \\n orientation 0 0 1 0 \\n nearDistance -112.88701 \\n farDistance 287.28702 \\n " "aspectRatio 1 \\n focalDistance 87 \\n height 143.52005 }"; break; case 1: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA \\n " "position 0 0 -87 \\n orientation -1 0 0 3.1415927 \\n nearDistance -112.88701 \\n farDistance 287.28702 \\n " "aspectRatio 1 \\n focalDistance 87 \\n height 143.52005 }"; break; case 2: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n " "position 0 -87 0 \\n orientation -1 0 0 4.712389\\n nearDistance -112.88701\\n farDistance 287.28702\\n " "aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; case 3: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n " "position 0 87 0 \\n orientation 0 0.70710683 0.70710683 3.1415927\\n nearDistance -112.88701\\n farDistance 287.28702\\n " "aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; case 4: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n " "position 87 0 0 \\n orientation 0.57735026 0.57735026 0.57735026 2.0943952 \\n nearDistance -112.887\\n farDistance 287.28699\\n " "aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; case 5: camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n " "position -87 0 0 \\n orientation -0.57735026 0.57735026 0.57735026 4.1887903 \\n nearDistance -112.887\\n farDistance 287.28699\\n " "aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; break; } openCommand("Reorient Sketch"); doCommand(Doc,"App.ActiveDocument.%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))" ,sketch->getNameInDocument(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]); doCommand(Gui,"Gui.ActiveDocument.setEdit('%s')",sketch->getNameInDocument()); }
void CmdSketcherDecreaseKnotMultiplicity::activated(int iMsg) { Q_UNUSED(iMsg); #if OCC_VERSION_HEX < 0x060900 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong OCE/OCC version"), QObject::tr("This version of OCE/OCC does not support knot operation. You need 6.9.0 or higher")); return; #endif // get the selection std::vector<Gui::SelectionObject> selection; selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId()); // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { return; } // get the needed lists and objects const std::vector<std::string> &SubNames = selection[0].getSubNames(); if(SubNames.size()>1) { // Check that only one object is selected, as we need only one object to get the new GeoId after multiplicity change QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("The selection comprises more than one item. Please select just one knot.")); return; } Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject()); openCommand("Decrease knot multiplicity"); bool applied = false; bool notaknot = true; boost::uuids::uuid bsplinetag; int GeoId; Sketcher::PointPos PosId; getIdsFromName(SubNames[0], Obj, GeoId, PosId); if(isSimpleVertex(Obj, GeoId, PosId)) { const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); it != vals.end(); ++it) { if((*it)->Type == Sketcher::InternalAlignment && (*it)->First == GeoId && (*it)->AlignmentType == Sketcher::BSplineKnotPoint) { bsplinetag = Obj->getGeometry((*it)->Second)->getTag(); notaknot = false; try { Gui::Command::doCommand( Doc,"App.ActiveDocument.%s.modifyBSplineKnotMultiplicity(%d,%d,%d) ", selection[0].getFeatName(),(*it)->Second, (*it)->InternalAlignmentIndex + 1, -1); applied = true; // Warning: GeoId list might have changed as the consequence of deleting pole circles and // particularly B-spline GeoID might have changed. } catch (const Base::Exception& e) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Error"), QObject::tr(getStrippedPythonExceptionString(e).c_str())); getSelection().clearSelection(); } break; // we have already found our knot. } } } if(notaknot){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("None of the selected elements is a knot of a B-spline")); } if(applied) { // find new geoid for B-spline as GeoId might have changed const std::vector< Part::Geometry * > &gvals = Obj->getInternalGeometry(); int ngeoid = 0; bool ngfound = false; for (std::vector<Part::Geometry *>::const_iterator geo = gvals.begin(); geo != gvals.end(); geo++, ngeoid++) { if ((*geo) && (*geo)->getTag() == bsplinetag) { ngfound = true; break; } } if(ngfound) { try { // add internalalignment for new pole Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.exposeInternalGeometry(%d)", selection[0].getFeatName(), ngeoid); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); getSelection().clearSelection(); } } } if(!applied) { abortCommand(); } else { commitCommand(); } tryAutoRecomputeIfNotSolve(Obj); getSelection().clearSelection(); }
void CmdSketcherMirrorSketch::activated(int iMsg) { std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId()); if (selection.size() < 1) { QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdSketcherMirrorSketch", "Wrong selection"), qApp->translate("CmdSketcherMirrorSketch", "Select one or more sketches, please.")); return; } // Ask the user which kind of mirroring he wants SketchMirrorDialog * smd = new SketchMirrorDialog(); int refgeoid=-1; Sketcher::PointPos refposid=Sketcher::none; if( smd->exec() == QDialog::Accepted ){ refgeoid=smd->RefGeoid; refposid=smd->RefPosid; delete smd; } else { delete smd; return; } App::Document* doc = App::GetApplication().getActiveDocument(); openCommand("Create a mirror Sketch for each sketch"); for (std::vector<Gui::SelectionObject>::const_iterator it=selection.begin(); it != selection.end(); ++it) { // create Sketch std::string FeatName = getUniqueObjectName("MirroredSketch"); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); Sketcher::SketchObject* mirrorsketch = static_cast<Sketcher::SketchObject*>(doc->getObject(FeatName.c_str())); const Sketcher::SketchObject* Obj = static_cast<const Sketcher::SketchObject*>((*it).getObject()); Base::Placement pl = Obj->Placement.getValue(); Base::Vector3d p = pl.getPosition(); Base::Rotation r = pl.getRotation(); doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))", FeatName.c_str(), p.x,p.y,p.z,r[0],r[1],r[2],r[3]); Sketcher::SketchObject* tempsketch = new Sketcher::SketchObject(); int addedGeometries=tempsketch->addGeometry(Obj->getInternalGeometry()); int addedConstraints=tempsketch->addConstraints(Obj->Constraints.getValues()); std::vector<int> geoIdList; for(int i=0;i<=addedGeometries;i++) geoIdList.push_back(i); tempsketch->addSymmetric(geoIdList, refgeoid, refposid); std::vector<Part::Geometry *> tempgeo = tempsketch->getInternalGeometry(); std::vector<Sketcher::Constraint *> tempconstr = tempsketch->Constraints.getValues(); std::vector<Part::Geometry *> mirrorgeo (tempgeo.begin()+addedGeometries+1,tempgeo.end()); std::vector<Sketcher::Constraint *> mirrorconstr (tempconstr.begin()+addedConstraints+1,tempconstr.end()); for(std::vector<Sketcher::Constraint *>::const_iterator itc=mirrorconstr.begin(); itc != mirrorconstr.end(); ++itc) { if((*itc)->First!=Sketcher::Constraint::GeoUndef || (*itc)->First==-1 || (*itc)->First==-2) // not x, y axes or origin (*itc)->First-=(addedGeometries+1); if((*itc)->Second!=Sketcher::Constraint::GeoUndef || (*itc)->Second==-1 || (*itc)->Second==-2) // not x, y axes or origin (*itc)->Second-=(addedGeometries+1); if((*itc)->Third!=Sketcher::Constraint::GeoUndef || (*itc)->Third==-1 || (*itc)->Third==-2) // not x, y axes or origin (*itc)->Third-=(addedGeometries+1); } mirrorsketch->addGeometry(mirrorgeo); mirrorsketch->addConstraints(mirrorconstr); delete tempsketch; } doCommand(Gui,"App.activeDocument().recompute()"); }