From d4ac0723063e973c50e818a65dd5de8c17b54648 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 10 Jul 2019 12:41:44 +0800 Subject: [PATCH] Gui: support in-place editing The link support means that an object can now appear in more than one places, and even inside a document different from its own. This patch adds support for in-place editing, meaning that the object can be edited at correct place regardless where it is. See [here](https://git.io/fjPIk) for more info about the relavent APIs. This patch includes two example of modifications to support in-place editing. One is the ViewProviderDragger, which simply adds the dragger node to editing root node by calling View3DInventorViewer::setupEditingRoot(dragger). The other much more complex one is ViewProviderSketch which calls setupEditingRoot(0) to transfer all its children node into editing root. ViewProviderSketch also includes various modifications to command invocation, because we can no longer assume the active document is the owner of the editing object. This patch also includes necessary modification of the 'Show' module to support in-place editing. --- src/Gui/Application.cpp | 21 + src/Gui/Application.h | 6 + src/Gui/ApplicationPy.cpp | 17 + src/Gui/Document.cpp | 232 +++++- src/Gui/Document.h | 16 +- src/Gui/View3DInventorViewer.cpp | 237 +++++- src/Gui/View3DInventorViewer.h | 23 +- src/Gui/View3DPy.cpp | 27 +- src/Gui/View3DPy.h | 3 + src/Gui/View3DViewerPy.cpp | 63 ++ src/Gui/View3DViewerPy.h | 3 + src/Gui/ViewProvider.cpp | 71 +- src/Gui/ViewProviderDragger.cpp | 53 +- src/Gui/ViewProviderDragger.h | 6 + src/Mod/Show/Containers.py | 28 +- src/Mod/Show/DepGraphTools.py | 11 +- src/Mod/Show/TempoVis.py | 127 ++- src/Mod/Sketcher/Gui/Command.cpp | 17 +- src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp | 2 +- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 750 ++++++++---------- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 185 ++--- .../Sketcher/Gui/CommandSketcherBSpline.cpp | 49 +- src/Mod/Sketcher/Gui/CommandSketcherTools.cpp | 46 +- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 20 +- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 11 +- .../Sketcher/Gui/TaskSketcherConstrains.cpp | 16 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 339 ++++---- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 6 + src/Mod/Sketcher/ProfileLib/RegularPolygon.py | 6 +- 29 files changed, 1449 insertions(+), 942 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index e0f29c99fd..2036136457 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -142,6 +142,7 @@ struct ApplicationP { ApplicationP() : activeDocument(0L), + editDocument(0L), isClosing(false), startingUp(true) { @@ -158,6 +159,7 @@ struct ApplicationP std::map documents; /// Active document Gui::Document* activeDocument; + Gui::Document* editDocument; MacroManager* macroMngr; /// List of all registered views std::list passive; @@ -863,6 +865,25 @@ Gui::Document* Application::activeDocument(void) const return d->activeDocument; } +Gui::Document* Application::editDocument(void) const +{ + return d->editDocument; +} + +Gui::MDIView* Application::editViewOfNode(SoNode *node) const +{ + return d->editDocument?d->editDocument->getViewOfNode(node):0; +} + +void Application::setEditDocument(Gui::Document *doc) { + if(!doc) + d->editDocument = 0; + for(auto &v : d->documents) + v.second->_resetEdit(); + d->editDocument = doc; + getMainWindow()->updateActions(); +} + void Application::setActiveDocument(Gui::Document* pcDocument) { if (d->activeDocument == pcDocument) diff --git a/src/Gui/Application.h b/src/Gui/Application.h index 8a6018a6e7..e3a5a74a6f 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -146,6 +146,11 @@ public: Gui::Document* activeDocument(void) const; /// Set the active document void setActiveDocument(Gui::Document* pcDocument); + /// Getter for the editing document + Gui::Document* editDocument(void) const; + Gui::MDIView* editViewOfNode(SoNode *node) const; + /// Set editing document, which will reset editing of all other document + void setEditDocument(Gui::Document* pcDocument); /** Retrieves a pointer to the Gui::Document whose App::Document has the name \a name. * If no such document exists 0 is returned. */ @@ -250,6 +255,7 @@ public: static PyObject* sActiveView (PyObject *self,PyObject *args); static PyObject* sActivateView (PyObject *self,PyObject *args); static PyObject* sGetDocument (PyObject *self,PyObject *args); + static PyObject* sEditDocument (PyObject *self,PyObject *args); static PyObject* sDoCommand (PyObject *self,PyObject *args); static PyObject* sDoCommandGui (PyObject *self,PyObject *args); diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index a2119f0e0a..2c269ed7c8 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -165,6 +165,9 @@ PyMethodDef Application::Methods[] = { {"activateView", (PyCFunction)Application::sActivateView, METH_VARARGS, "activateView(type)\n\n" "Activate a view of the given type of the active document"}, + {"editDocument", (PyCFunction)Application::sEditDocument, METH_VARARGS, + "editDocument() -> object or None\n\n" + "Return the current editing document or None if no one exists" }, {"getDocument", (PyCFunction) Application::sGetDocument, METH_VARARGS, "getDocument(string) -> object\n\n" "Get a document by its name"}, @@ -203,6 +206,20 @@ PyMethodDef Application::Methods[] = { {NULL, NULL, 0, NULL} /* Sentinel */ }; +PyObject* Gui::Application::sEditDocument(PyObject * /*self*/, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) // convert args: Python->C + return NULL; // NULL triggers exception + + Document *pcDoc = Instance->editDocument(); + if (pcDoc) { + return pcDoc->getPyObject(); + } + else { + Py_Return; + } +} + PyObject* Gui::Application::sActiveDocument(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, "")) diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index c0683149db..9d5f4da168 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -66,6 +66,7 @@ #include "Selection.h" #include "WaitCursor.h" #include "Thumbnail.h" +FC_LOG_LEVEL_INIT("Gui",true,true) using namespace Gui; @@ -80,6 +81,12 @@ struct DocumentP bool _isClosing; bool _isModified; ViewProvider* _editViewProvider; + int _editMode; + ViewProvider* _editViewProvider; + ViewProviderDocumentObject* _editViewProviderParent; + std::string _editSubname; + std::string _editSubElement; + Base::Matrix4D _editingTransform; Application* _pcAppWnd; // the doc/Document App::Document* _pcDocument; @@ -129,6 +136,8 @@ Document::Document(App::Document* pcDocument,Application * app) d->_pcAppWnd = app; d->_pcDocument = pcDocument; d->_editViewProvider = 0; + d->_editViewProviderParent = 0; + d->_editMode = 0; // Setup the connections d->connectNewObject = pcDocument->signalNewObject.connect @@ -224,43 +233,167 @@ Document::~Document() // 3D viewer handling //***************************************************************************************************** -bool Document::setEdit(Gui::ViewProvider* p, int ModNum) +bool Document::setEdit(Gui::ViewProvider* p, int ModNum, const char *subname) { - if (d->_editViewProvider) - resetEdit(); - - // is it really a ViewProvider of this document? ViewProviderDocumentObject* vp = dynamic_cast(p); - if (!vp) + if (!vp) { + FC_ERR("cannot edit non ViewProviderDocumentObject"); + return false; + } + auto obj = vp->getObject(); + if(!obj->getNameInDocument()) { + FC_ERR("cannot edit detached object"); + return false; + } + + std::string _subname; + if(!subname || !subname[0]) { + // No subname reference is given, we try to extract one from the current + // selection in order to obtain the correct transformation matrix below + auto sels = Gui::Selection().getCompleteSelection(false); + App::DocumentObject *parentObj = 0; + for(auto &sel : sels) { + if(!sel.pObject || !sel.pObject->getNameInDocument()) + continue; + if(!parentObj) + parentObj = sel.pObject; + else if(parentObj!=sel.pObject) { + FC_LOG("Cannot deduce subname for editing, more than one parent?"); + parentObj = 0; + break; + } + auto sobj = parentObj->getSubObject(sel.SubName); + if(!sobj || (sobj!=obj && sobj->getLinkedObject(true)!= obj)) { + FC_LOG("Cannot deduce subname for editing, subname mismatch"); + parentObj = 0; + break; + } + _subname = sel.SubName; + } + if(parentObj) { + FC_LOG("deduced editing reference " << parentObj->getFullName() << '.' << _subname); + subname = _subname.c_str(); + obj = parentObj; + vp = dynamic_cast( + Application::Instance->getViewProvider(obj)); + if(!vp || !vp->getDocument()) { + FC_ERR("invliad view provider for parent object"); + return false; + } + if(vp->getDocument()!=this) + return vp->getDocument()->setEdit(vp,ModNum,subname); + } + } + + if (d->_ViewProviderMap.find(obj) == d->_ViewProviderMap.end()) { + // We can actually support editing external object, by calling + // View3DInventViewer::setupEditingRoot() before exiting from + // ViewProvider::setEditViewer(), which transfer all child node of the view + // provider into an editing node inside the viewer of this document. And + // that's may actually be the case, as the subname referenced sub object + // is allowed to be in other documents. + // + // We just disabling editing external parent object here, for bug + // tracking purpose. Because, bringing an unrelated external object to + // the current view for editing will confuse user, and is certainly a + // bug. By right, the top parent object should always belong to the + // editing document, and the acutally editing sub object can be + // external. + // + // So, you can either call setEdit() with subname set to 0, which cause + // the code above to auto detect selection context, and dispatch the + // editing call to the correct document. Or, supply subname yourself, + // and make sure you get the document right. + // + FC_ERR("cannot edit object '" << obj->getNameInDocument() << "': not found in document " + << "'" << getDocument()->getName() << "'"); return false; - if (d->_ViewProviderMap.find(vp->getObject()) == d->_ViewProviderMap.end()) + d->_editingTransform = Base::Matrix4D(); + // Geo feature group now handles subname like link group. So no need of the + // following code. + // + // if(!subname || !subname[0]) { + // auto group = App::GeoFeatureGroupExtension::getGroupOfObject(obj); + // if(group) { + // auto ext = group->getExtensionByType(); + // d->_editingTransform = ext->globalGroupPlacement().toMatrix(); + // } + // } + auto sobj = obj->getSubObject(subname,0,&d->_editingTransform); + if(!sobj || !sobj->getNameInDocument()) { + FC_ERR("Invalid sub object '" << obj->getFullName() + << '.' << (subname?subname:"") << "'"); return false; + } + auto svp = vp; + if(sobj!=obj) { + svp = dynamic_cast( + Application::Instance->getViewProvider(sobj)); + if(!svp) { + FC_ERR("Cannot edit '" << sobj->getFullName() << "' without view provider"); + return false; + } + } View3DInventor *activeView = dynamic_cast(getActiveView()); // if the currently active view is not the 3d view search for it and activate it if (!activeView) { - activeView = dynamic_cast(getViewOfViewProvider(p)); - if (activeView) - getMainWindow()->setActiveWindow(activeView); + activeView = dynamic_cast(getViewOfViewProvider(vp)); + if(!activeView){ + FC_ERR("cannot edit without active view"); + return false; + } + } + getMainWindow()->setActiveWindow(activeView); + Application::Instance->setEditDocument(this); + + d->_editViewProviderParent = vp; + d->_editSubElement.clear(); + d->_editSubname.clear(); + if(subname) { + const char *element = Data::ComplexGeoData::findElementName(subname); + if(element) { + d->_editSubname = std::string(subname,element-subname); + d->_editSubElement = element; + }else + d->_editSubname = subname; } - if (activeView && activeView->getViewer()->setEditingViewProvider(p,ModNum)) { - d->_editViewProvider = p; - Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); - if (dlg) - dlg->setDocumentName(this->getDocument()->getName()); - if (d->_editViewProvider->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) - signalInEdit(*(static_cast(d->_editViewProvider))); - } - else { + d->_editMode = ModNum; + d->_editViewProvider = svp->startEditing(ModNum); + if(!d->_editViewProvider) { + d->_editViewProviderParent = 0; + FC_LOG("object '" << sobj->getFullName() << "' refuse to edit"); return false; } + activeView->getViewer()->setEditingViewProvider(d->_editViewProvider,ModNum); + Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); + if (dlg) + dlg->setDocumentName(this->getDocument()->getName()); + if (d->_editViewProvider->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) + signalInEdit(*(static_cast(d->_editViewProvider))); + App::AutoTransaction::setEnable(false); return true; } -void Document::resetEdit(void) +const Base::Matrix4D &Document::getEditingTransform() const { + return d->_editingTransform; +} + +void Document::setEditingTransform(const Base::Matrix4D &mat) { + d->_editingTransform = mat; + View3DInventor *activeView = dynamic_cast(getActiveView()); + if (activeView) + activeView->getViewer()->setEditingTransform(mat); +} + +void Document::resetEdit(void) { + Application::Instance->setEditDocument(0); +} + +void Document::_resetEdit(void) { std::list::iterator it; if (d->_editViewProvider) { @@ -270,6 +403,16 @@ void Document::resetEdit(void) activeView->getViewer()->resetEditingViewProvider(); } + d->_editViewProvider->finishEditing(); + if (d->_editViewProvider->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) + signalResetEdit(*(static_cast(d->_editViewProvider))); + d->_editViewProvider = 0; + + // The logic below is not necessary anymore, because this method is + // changed into a private one, _resetEdit(). And the exposed + // resetEdit() above calls into Application->setEditDocument(0) which + // will prevent recrusive calling. +#if 0 // Nullify the member variable before calling finishEditing(). // This is to avoid a possible stack overflow when a view provider wrongly // invokes the document's resetEdit() method. @@ -279,11 +422,21 @@ void Document::resetEdit(void) editViewProvider->finishEditing(); if (editViewProvider->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) signalResetEdit(*(static_cast(editViewProvider))); +#endif } + d->_editViewProviderParent = 0; + if(Application::Instance->editDocument() == this) + Application::Instance->setEditDocument(0); } -ViewProvider *Document::getInEdit(void) const +ViewProvider *Document::getInEdit(ViewProviderDocumentObject **parentVp, + std::string *subname, int *mode, std::string *subelement) const { + if(parentVp) *parentVp = d->_editViewProviderParent; + if(subname) *subname = d->_editSubname; + if(subelement) *subelement = d->_editSubElement; + if(mode) *mode = d->_editMode; + if (d->_editViewProvider) { // there is only one 3d view which is in edit mode View3DInventor *activeView = dynamic_cast(getActiveView()); @@ -294,6 +447,13 @@ ViewProvider *Document::getInEdit(void) const return 0; } +void Document::setInEdit(ViewProviderDocumentObject *parentVp, const char *subname) { + if (d->_editViewProvider) { + d->_editViewProviderParent = parentVp; + d->_editSubname = subname?subname:""; + } +} + void Document::setAnnotationViewProvider(const char* name, ViewProvider *pcProvider) { std::list::iterator vIt; @@ -486,6 +646,16 @@ void Document::slotDeletedObject(const App::DocumentObject& Obj) // cycling to all views of the document ViewProvider* viewProvider = getViewProvider(&Obj); + if(!viewProvider) return; + + if (d->_editViewProvider==viewProvider || d->_editViewProviderParent==viewProvider) + _resetEdit(); + else if(Application::Instance->editDocument()) { + auto editDoc = Application::Instance->editDocument(); + if(editDoc->d->_editViewProvider==viewProvider || + editDoc->d->_editViewProviderParent==viewProvider) + Application::Instance->setEditDocument(0); + } #if 0 // With this we can show child objects again if this method was called by undo viewProvider->onDelete(std::vector()); #endif @@ -504,6 +674,24 @@ void Document::slotDeletedObject(const App::DocumentObject& Obj) // removing from tree signalDeletedObject(*(static_cast(viewProvider))); } + + viewProvider->beforeDelete(); +} + +void Document::beforeDelete() { + auto editDoc = Application::Instance->editDocument(); + if(editDoc) { + auto vp = dynamic_cast(editDoc->d->_editViewProvider); + auto vpp = dynamic_cast(editDoc->d->_editViewProviderParent); + if(editDoc == this || + (vp && vp->getDocument()==this) || + (vpp && vpp->getDocument()==this)) + { + Application::Instance->setEditDocument(0); + } + } + for(auto &v : d->_ViewProviderMap) + v.second->beforeDelete(); } void Document::slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) @@ -1321,7 +1509,7 @@ bool Document::canClose () std::string name = Gui::Control().activeDialog()->getDocumentName(); if (name == this->getDocument()->getName()) { if (this->getInEdit()) - this->resetEdit(); + this->_resetEdit(); } } } diff --git a/src/Gui/Document.h b/src/Gui/Document.h index b1f7cea8f1..c51711d043 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -216,11 +216,18 @@ public: std::vector getViewProvidersOfType(const Base::Type& typeId) const; ViewProvider *getViewProviderByName(const char* name) const; /// set the ViewProvider in special edit mode - bool setEdit(Gui::ViewProvider* p, int ModNum=0); - /// reset from edit mode + bool setEdit(Gui::ViewProvider* p, int ModNum=0, const char *subname=0); + const Base::Matrix4D &getEditingTransform() const; + void setEditingTransform(const Base::Matrix4D &mat); + /// reset from edit mode, this cause all document to reset edit void resetEdit(void); + /// reset edit of this document + void _resetEdit(void); /// get the in edit ViewProvider or NULL - ViewProvider *getInEdit(void) const; + ViewProvider *getInEdit(ViewProviderDocumentObject **parentVp=0, + std::string *subname=0, int *mode=0, std::string *subElement=0) const; + /// set the in edit ViewProvider subname reference + void setInEdit(ViewProviderDocumentObject *parentVp, const char *subname); //@} /** @name methods for the UNDO REDO handling */ @@ -247,6 +254,9 @@ public: bool canClose(); bool isLastView(void); + /// called by Application before being deleted + void beforeDelete(); + virtual PyObject *getPyObject(void); protected: diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index b934de8713..151b3d73b3 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -515,6 +515,18 @@ void View3DInventorViewer::init() pcGroupOnTopPreSel->ref(); pcGroupOnTop->addChild(pcGroupOnTopPreSel); + pcClipPlane = 0; + + pcEditingRoot = new SoSeparator; + pcEditingRoot->ref(); + pcEditingRoot->setName("EditingRoot"); + pcEditingTransform = new SoTransform; + pcEditingTransform->ref(); + pcEditingTransform->setName("EditingTransform"); + restoreEditingRoot = false; + pcEditingRoot->addChild(pcEditingTransform); + pcViewProviderRoot->addChild(pcEditingRoot); + // Set our own render action which show a bounding box if // the SoFCSelection::BOX style is set // @@ -988,20 +1000,163 @@ void View3DInventorViewer::removeViewProvider(ViewProvider* pcProvider) _ViewProviderSet.erase(pcProvider); } -SbBool View3DInventorViewer::setEditingViewProvider(Gui::ViewProvider* p, int ModNum) -{ - if (this->editViewProvider) - return false; // only one view provider is editable at a time - - bool ok = p->startEditing(ModNum); - - if (ok) { - this->editViewProvider = p; - this->editViewProvider->setEditViewer(this, ModNum); - addEventCallback(SoEvent::getClassTypeId(), Gui::ViewProvider::eventCallback,this->editViewProvider); +void View3DInventorViewer::setEditingTransform(const Base::Matrix4D &mat) { + if(pcEditingTransform) { + double dMtrx[16]; + mat.getGLMatrix(dMtrx); + pcEditingTransform->setMatrix(SbMatrix( + dMtrx[0], dMtrx[1], dMtrx[2], dMtrx[3], + dMtrx[4], dMtrx[5], dMtrx[6], dMtrx[7], + dMtrx[8], dMtrx[9], dMtrx[10], dMtrx[11], + dMtrx[12],dMtrx[13],dMtrx[14], dMtrx[15])); } +} - return ok; +void View3DInventorViewer::setupEditingRoot(SoNode *node, const Base::Matrix4D *mat) { + if(!editViewProvider) + return; + resetEditingRoot(false); + if(mat) + setEditingTransform(*mat); + else + setEditingTransform(getDocument()->getEditingTransform()); + if(node) { + restoreEditingRoot = false; + pcEditingRoot->addChild(node); + return; + } + restoreEditingRoot = true; + auto root = editViewProvider->getRoot(); + for(int i=0,count=root->getNumChildren();igetChild(i); + if(node != editViewProvider->getTransformNode()) + pcEditingRoot->addChild(node); + } + coinRemoveAllChildren(root); + ViewProviderLink::updateLinks(editViewProvider); +} + +void View3DInventorViewer::resetEditingRoot(bool updateLinks) { + if(!editViewProvider || pcEditingRoot->getNumChildren()<=1) + return; + if(!restoreEditingRoot) { + pcEditingRoot->getChildren()->truncate(1); + return; + } + restoreEditingRoot = false; + auto root = editViewProvider->getRoot(); + if(root->getNumChildren()) + FC_ERR("WARNING!!! Editing view provider root node is tampered"); + root->addChild(editViewProvider->getTransformNode()); + for(int i=1,count=pcEditingRoot->getNumChildren();iaddChild(pcEditingRoot->getChild(i)); + pcEditingRoot->getChildren()->truncate(1); + if(updateLinks) + ViewProviderLink::updateLinks(editViewProvider); +} + +SoPickedPoint* View3DInventorViewer::getPointOnRay(const SbVec2s& pos, ViewProvider* vp) const +{ + SoPath *path; + if(vp == editViewProvider && pcEditingRoot->getNumChildren()>1) { + path = new SoPath(1); + path->ref(); + path->append(pcEditingRoot); + }else{ + //first get the path to this node and calculate the current transformation + SoSearchAction sa; + sa.setNode(vp->getRoot()); + sa.setSearchingAll(true); + sa.apply(getSoRenderManager()->getSceneGraph()); + path = sa.getPath(); + if (!path) + return nullptr; + path->ref(); + } + SoGetMatrixAction gm(getSoRenderManager()->getViewportRegion()); + gm.apply(path); + + SoTransform* trans = new SoTransform; + trans->setMatrix(gm.getMatrix()); + trans->ref(); + + // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated + // transformation + SoSeparator* root = new SoSeparator; + root->ref(); + root->addChild(getSoRenderManager()->getCamera()); + root->addChild(trans); + root->addChild(path->getTail()); + + //get the picked point + SoRayPickAction rp(getSoRenderManager()->getViewportRegion()); + rp.setPoint(pos); + rp.setRadius(getPickRadius()); + rp.apply(root); + root->unref(); + trans->unref(); + path->unref(); + + SoPickedPoint* pick = rp.getPickedPoint(); + return (pick ? new SoPickedPoint(*pick) : 0); +} + +SoPickedPoint* View3DInventorViewer::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir, ViewProvider* vp) const +{ + // Note: There seems to be a bug with setRay() which causes SoRayPickAction + // to fail to get intersections between the ray and a line + + SoPath *path; + if(vp == editViewProvider && pcEditingRoot->getNumChildren()>1) { + path = new SoPath(1); + path->ref(); + path->append(pcEditingRoot); + }else{ + //first get the path to this node and calculate the current setTransformation + SoSearchAction sa; + sa.setNode(vp->getRoot()); + sa.setSearchingAll(true); + sa.apply(getSoRenderManager()->getSceneGraph()); + path = sa.getPath(); + if (!path) + return nullptr; + path->ref(); + } + SoGetMatrixAction gm(getSoRenderManager()->getViewportRegion()); + gm.apply(path); + + // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated + // transformation + SoTransform* trans = new SoTransform; + trans->ref(); + trans->setMatrix(gm.getMatrix()); + + SoSeparator* root = new SoSeparator; + root->ref(); + root->addChild(getSoRenderManager()->getCamera()); + root->addChild(trans); + root->addChild(path->getTail()); + + //get the picked point + SoRayPickAction rp(getSoRenderManager()->getViewportRegion()); + rp.setRay(pos,dir); + rp.setRadius(getPickRadius()); + rp.apply(root); + root->unref(); + trans->unref(); + path->unref(); + + // returns a copy of the point + SoPickedPoint* pick = rp.getPickedPoint(); + //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows + return (pick ? new SoPickedPoint(*pick) : 0); +} + +void View3DInventorViewer::setEditingViewProvider(Gui::ViewProvider* p, int ModNum) +{ + this->editViewProvider = p; + this->editViewProvider->setEditViewer(this, ModNum); + addEventCallback(SoEvent::getClassTypeId(), Gui::ViewProvider::eventCallback,this->editViewProvider); } /// reset from edit mode @@ -1016,6 +1171,8 @@ void View3DInventorViewer::resetEditingViewProvider() if (heaction && heaction->getGrabber()) heaction->releaseGrabber(); + resetEditingRoot(); + this->editViewProvider->unsetEditViewer(this); removeEventCallback(SoEvent::getClassTypeId(), Gui::ViewProvider::eventCallback,this->editViewProvider); this->editViewProvider = 0; @@ -2368,36 +2525,48 @@ SbVec3f View3DInventorViewer::projectOnFarPlane(const SbVec2f& pt) const return pt2; } -void View3DInventorViewer::toggleClippingPlane() +void View3DInventorViewer::toggleClippingPlane(int toggle, bool beforeEditing, + bool noManip, const Base::Placement &pla) { - if (pcViewProviderRoot->getNumChildren() > 0 && - pcViewProviderRoot->getChild(0)->getTypeId() == - SoClipPlaneManip::getClassTypeId()) { - pcViewProviderRoot->removeChild(0); - } - else { + if(pcClipPlane) { + if(toggle<=0) { + pcViewProviderRoot->removeChild(pcClipPlane); + pcClipPlane->unref(); + pcClipPlane = 0; + } + return; + }else if(toggle==0) + return; + + Base::Vector3d dir; + pla.getRotation().multVec(Base::Vector3d(0,0,-1),dir); + Base::Vector3d base = pla.getPosition(); + + if(!noManip) { SoClipPlaneManip* clip = new SoClipPlaneManip; + pcClipPlane = clip; SoGetBoundingBoxAction action(this->getSoRenderManager()->getViewportRegion()); action.apply(this->getSoRenderManager()->getSceneGraph()); SbBox3f box = action.getBoundingBox(); if (!box.isEmpty()) { // adjust to overall bounding box of the scene - clip->setValue(box, SbVec3f(0.0f,0.0f,1.0f), 1.0f); + clip->setValue(box, SbVec3f(dir.x,dir.y,dir.z), 1.0f); } - - pcViewProviderRoot->insertChild(clip,0); - } + }else + pcClipPlane = new SoClipPlane; + pcClipPlane->plane.setValue( + SbPlane(SbVec3f(dir.x,dir.y,dir.z),SbVec3f(base.x,base.y,base.z))); + pcClipPlane->ref(); + if(beforeEditing) + pcViewProviderRoot->insertChild(pcClipPlane,0); + else + pcViewProviderRoot->insertChild(pcClipPlane,pcViewProviderRoot->findChild(pcEditingRoot)+1); } bool View3DInventorViewer::hasClippingPlane() const { - if (pcViewProviderRoot && pcViewProviderRoot->getNumChildren() > 0) { - return (pcViewProviderRoot->getChild(0)->getTypeId() - == SoClipPlaneManip::getClassTypeId()); - } - - return false; + return !!pcClipPlane; } /** @@ -2442,10 +2611,12 @@ SoPickedPoint* View3DInventorViewer::pickPoint(const SbVec2s& pos) const const SoPickedPoint* View3DInventorViewer::getPickedPoint(SoEventCallback* n) const { - if (selectionRoot) - return selectionRoot->getPickedPoint(n->getAction()); - else - return n->getPickedPoint(); + if (selectionRoot) { + auto ret = selectionRoot->getPickedList(n->getAction(), true); + if(ret.size()) return ret[0].pp; + return nullptr; + } + return n->getPickedPoint(); } SbBool View3DInventorViewer::pubSeekToPoint(const SbVec2s& pos) diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 13b0c2b535..2710f973ff 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -56,6 +57,7 @@ class QImage; class SoGroup; class SoPickStyle; class NaviCube; +class SoClipPlane; namespace Quarter = SIM::Coin3D::Quarter; @@ -190,11 +192,22 @@ public: /// get all view providers of given type std::vector getViewProvidersOfType(const Base::Type& typeId) const; /// set the ViewProvider in special edit mode - SbBool setEditingViewProvider(Gui::ViewProvider* p, int ModNum=0); + void setEditingViewProvider(Gui::ViewProvider* p, int ModNum); /// return whether a view provider is edited SbBool isEditingViewProvider() const; /// reset from edit mode void resetEditingViewProvider(); + void setupEditingRoot(SoNode *node=0, const Base::Matrix4D *mat=0); + void resetEditingRoot(bool updateLinks=true); + void setEditingTransform(const Base::Matrix4D &mat); + /** Helper method to get picked entities while editing. + * It's in the responsibility of the caller to delete the returned instance. + */ + SoPickedPoint* getPointOnRay(const SbVec2s& pos, ViewProvider* vp) const; + /** Helper method to get picked entities while editing. + * It's in the responsibility of the caller to delete the returned instance. + */ + SoPickedPoint* getPointOnRay(const SbVec3f& pos, const SbVec3f& dir, ViewProvider* vp) const; /// display override mode void setOverrideMode(const std::string &mode); void updateOverrideMode(const std::string &mode); @@ -280,7 +293,8 @@ public: /** Returns the far plane represented by its normal and base point. */ void getFarPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const; /** Adds or remove a manipulator to/from the scenegraph. */ - void toggleClippingPlane(); + void toggleClippingPlane(int toggle=-1, bool beforeEditing=false, + bool noManip=false, const Base::Placement &pla = Base::Placement()); /** Checks whether a clipping plane is set or not. */ bool hasClippingPlane() const; /** Project the given normalized 2d point onto the near plane */ @@ -424,10 +438,15 @@ private: std::map objectsOnTop; std::map objectsOnTopPreSel; + SoSeparator * pcEditingRoot; + SoTransform * pcEditingTransform; + bool restoreEditingRoot; SoEventCallback* pEventCallback; NavigationStyle* navigation; SoFCUnifiedSelection* selectionRoot; + SoClipPlane *pcClipPlane; + RenderType renderType; QtGLFramebufferObject* framebuffer; QImage glImage; diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index d0292e2423..f376519dd7 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -183,7 +183,13 @@ void View3DInventorPy::init_type() add_varargs_method("getViewProvidersOfType", &View3DInventorPy::getViewProvidersOfType, "getViewProvidersOfType(name)\nreturns a list of view providers for the given type"); add_varargs_method("redraw", &View3DInventorPy::redraw, "redraw(): renders the scene on screen (useful for animations)"); add_varargs_method("setName",&View3DInventorPy::setName,"setName(str): sets a name to this viewer\nThe name sets the widget's windowTitle and appears on the viewer tab"); - + add_keyword_method("toggleClippingPlane", &View3DInventorPy::toggleClippingPlane, + "toggleClippingPlane(toggle=-1, beforeEditing=False, noManip=True, pla=App.Placement()\n" + "Toggle a golbal clipping plane\n\n" + "toggle: -1 toggle, 1 show, 0 hide\n" + "beforeEditing: whether insert the clipping node before or after editing root node\n" + "noManip: wether to create a manipulator\n" + "pla: clipping plane placement"); } View3DInventorPy::View3DInventorPy(View3DInventor *vi) @@ -2473,3 +2479,22 @@ Py::Object View3DInventorPy::setName(const Py::Tuple& args) throw Py::RuntimeError("Unknown C++ exception"); } } + +Py::Object View3DInventorPy::toggleClippingPlane(const Py::Tuple& args, const Py::Dict& kwds) +{ + static char* keywords[] = {"toggle", "beforeEditing", "noManip", "pla", NULL}; + int toggle = -1; + PyObject *beforeEditing = Py_False; + PyObject *noManip = Py_True; + PyObject *pyPla = Py_None; + if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "|iOOO!", keywords, + &toggle, &beforeEditing, &noManip, &Base::PlacementPy::Type,&pyPla)) + throw Py::Exception(); + + Base::Placement pla; + if(pyPla!=Py_None) + pla = *static_cast(pyPla)->getPlacementPtr(); + _view->getViewer()->toggleClippingPlane(toggle,PyObject_IsTrue(beforeEditing), + PyObject_IsTrue(noManip),pla); + return Py::None(); +} diff --git a/src/Gui/View3DPy.h b/src/Gui/View3DPy.h index 67198e7643..f249fef890 100644 --- a/src/Gui/View3DPy.h +++ b/src/Gui/View3DPy.h @@ -130,6 +130,9 @@ public: Py::Object getViewProvidersOfType(const Py::Tuple&); Py::Object redraw(const Py::Tuple&); Py::Object setName(const Py::Tuple&); + Py::Object toggleClippingPlane(const Py::Tuple& args, const Py::Dict &); + + View3DInventor* getView3DIventorPtr() {return _view;} private: static void eventCallback(void * ud, SoEventCallback * n); diff --git a/src/Gui/View3DViewerPy.cpp b/src/Gui/View3DViewerPy.cpp index 4917233844..5ca2fc6bb3 100644 --- a/src/Gui/View3DViewerPy.cpp +++ b/src/Gui/View3DViewerPy.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include using namespace Gui; @@ -75,6 +76,14 @@ void View3DInventorViewerPy::init_type() "getPickRadius(): returns radius of confusion in pixels for picking objects on screen (selection)."); add_varargs_method("setPickRadius", &View3DInventorViewerPy::setPickRadius, "setPickRadius(new_radius): sets radius of confusion in pixels for picking objects on screen (selection)."); + add_varargs_method("setupEditingRoot", &View3DInventorViewerPy::setupEditingRoot, + "setupEditingRoot(matrix=None): setup the editing ViewProvider's root node.\n" + "All child coin nodes of the current editing ViewProvider will be transferred to\n" + "an internal editing node of this viewer, with a new transformation node specified\n" + "by 'matrix'. All ViewProviderLink to the editing ViewProvider will be temperary\n" + "hidden. Call resetEditingRoot() to restore everything back to normal"); + add_varargs_method("resetEditingRoot", &View3DInventorViewerPy::resetEditingRoot, + "resetEditingRoot(updateLinks=True): restore the editing ViewProvider's root node"); add_varargs_method("setBackgroundColor", &View3DInventorViewerPy::setBackgroundColor, "setBackgroundColor(r,g,b): sets the background color of the current viewer."); add_varargs_method("setRedirectToSceneGraph", &View3DInventorViewerPy::setRedirectToSceneGraph, @@ -365,6 +374,60 @@ Py::Object View3DInventorViewerPy::setPickRadius(const Py::Tuple& args) } } +Py::Object View3DInventorViewerPy::setupEditingRoot(const Py::Tuple& args) +{ + PyObject *pynode = Py_None; + PyObject *pymat = Py_None; + if (!PyArg_ParseTuple(args.ptr(), "|OO!", &pynode,&Base::MatrixPy::Type,&pymat)) { + throw Py::Exception(); + } + + Base::Matrix4D *mat = 0; + if(pymat != Py_None) + mat = static_cast(pymat)->getMatrixPtr(); + + try { + SoNode *node = 0; + if(pynode!=Py_None) { + void* ptr = 0; + Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", pynode, &ptr, 0); + node = reinterpret_cast(ptr); + } + _viewer->setupEditingRoot(node,mat); + return Py::None(); + } + catch (const Base::Exception& e) { + throw Py::Exception(Base::BaseExceptionFreeCADError,e.what()); + } + catch (const std::exception& e) { + throw Py::RuntimeError(e.what()); + } + catch(...) { + throw Py::RuntimeError("Unknown C++ exception"); + } +} + +Py::Object View3DInventorViewerPy::resetEditingRoot(const Py::Tuple& args) +{ + PyObject *updateLinks = Py_True; + if (!PyArg_ParseTuple(args.ptr(), "|O", &updateLinks)) { + throw Py::Exception(); + } + try { + _viewer->resetEditingRoot(PyObject_IsTrue(updateLinks)); + return Py::None(); + } + catch (const Base::Exception& e) { + throw Py::Exception(Base::BaseExceptionFreeCADError,e.what()); + } + catch (const std::exception& e) { + throw Py::RuntimeError(e.what()); + } + catch(...) { + throw Py::RuntimeError("Unknown C++ exception"); + } +} + Py::Object View3DInventorViewerPy::setBackgroundColor(const Py::Tuple& args) { float r,g,b = 0.0; diff --git a/src/Gui/View3DViewerPy.h b/src/Gui/View3DViewerPy.h index 87389e1ef1..abafe787cf 100644 --- a/src/Gui/View3DViewerPy.h +++ b/src/Gui/View3DViewerPy.h @@ -65,6 +65,9 @@ public: Py::Object getPickRadius(const Py::Tuple& args); Py::Object setPickRadius(const Py::Tuple& args); + Py::Object setupEditingRoot(const Py::Tuple &args); + Py::Object resetEditingRoot(const Py::Tuple &args); + Py::Object setBackgroundColor(const Py::Tuple& args); Py::Object setRedirectToSceneGraph(const Py::Tuple& args); Py::Object isRedirectedToSceneGraph(const Py::Tuple& args); diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index 27ad38ffd1..47fe0dca54 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -58,6 +58,7 @@ #include "SoFCDB.h" #include "ViewProviderExtension.h" #include "SoFCUnifiedSelection.h" +#include "ViewProviderLink.h" #include "ViewParams.h" #include @@ -588,79 +589,15 @@ bool ViewProvider::checkRecursion(SoNode* node) SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const { - //first get the path to this node and calculate the current transformation - SoSearchAction sa; - sa.setNode(pcRoot); - sa.setSearchingAll(true); - sa.apply(viewer->getSoRenderManager()->getSceneGraph()); - if (!sa.getPath()) - return nullptr; - SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion()); - gm.apply(sa.getPath()); - - SoTransform* trans = new SoTransform; - trans->setMatrix(gm.getMatrix()); - trans->ref(); - - // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated - // transformation - SoSeparator* root = new SoSeparator; - root->ref(); - root->addChild(viewer->getSoRenderManager()->getCamera()); - root->addChild(trans); - root->addChild(pcRoot); - - //get the picked point - SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); - rp.setPoint(pos); - rp.setRadius(viewer->getPickRadius()); - rp.apply(root); - root->unref(); - trans->unref(); - - SoPickedPoint* pick = rp.getPickedPoint(); - return (pick ? new SoPickedPoint(*pick) : 0); + return viewer->getPointOnRay(pos,const_cast(this)); } SoPickedPoint* ViewProvider::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir, const View3DInventorViewer* viewer) const { - // Note: There seems to be a bug with setRay() which causes SoRayPickAction - // to fail to get intersections between the ray and a line - - //first get the path to this node and calculate the current setTransformation - SoSearchAction sa; - sa.setNode(pcRoot); - sa.setSearchingAll(true); - sa.apply(viewer->getSoRenderManager()->getSceneGraph()); - SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion()); - gm.apply(sa.getPath()); - - // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated - // transformation - SoTransform* trans = new SoTransform; - trans->ref(); - trans->setMatrix(gm.getMatrix()); - - SoSeparator* root = new SoSeparator; - root->ref(); - root->addChild(viewer->getSoRenderManager()->getCamera()); - root->addChild(trans); - root->addChild(pcRoot); - - //get the picked point - SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion()); - rp.setRay(pos,dir); - rp.setRadius(viewer->getPickRadius()); - rp.apply(root); - root->unref(); - trans->unref(); - - // returns a copy of the point - SoPickedPoint* pick = rp.getPickedPoint(); - //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows - return (pick ? new SoPickedPoint(*pick) : 0); + return viewer->getPointOnRay(pos,dir,const_cast(this)); } + std::vector ViewProvider::getModelPoints(const SoPickedPoint* pp) const { // the default implementation just returns the picked point from the visual representation diff --git a/src/Gui/ViewProviderDragger.cpp b/src/Gui/ViewProviderDragger.cpp index 5541c884a7..48f75a161a 100644 --- a/src/Gui/ViewProviderDragger.cpp +++ b/src/Gui/ViewProviderDragger.cpp @@ -109,10 +109,46 @@ void ViewProviderDragger::setupContextMenu(QMenu* menu, QObject* receiver, const act->setData(QVariant((int)ViewProvider::Transform)); } +ViewProvider *ViewProviderDragger::startEditing(int mode) { + _linkDragger = 0; + auto ret = ViewProviderDocumentObject::startEditing(mode); + if(!ret) + return ret; + return _linkDragger?_linkDragger:ret; +} + +bool ViewProviderDragger::checkLink() { + // Trying to detect if the editing request is forwarded by a link object, + // usually by doubleClicked(). If so, we route the request back. There shall + // be no risk of infinit recursion, as ViewProviderLink handles + // ViewProvider::Transform request by itself. + ViewProviderDocumentObject *vpParent = 0; + std::string subname; + auto doc = Application::Instance->editDocument(); + if(!doc) + return false; + doc->getInEdit(&vpParent,&subname); + if(!vpParent) + return false; + auto sobj = vpParent->getObject()->getSubObject(subname.c_str()); + if(!sobj || sobj==getObject() || sobj->getLinkedObject(true)!=getObject()) + return false; + auto vp = Application::Instance->getViewProvider(sobj); + if(!vp) + return false; + _linkDragger = vp->startEditing(ViewProvider::Transform); + if(_linkDragger) + return true; + return false; +} + bool ViewProviderDragger::setEdit(int ModNum) { Q_UNUSED(ModNum); + if(checkLink()) + return true; + App::DocumentObject *genericObject = this->getObject(); if (genericObject->isDerivedFrom(App::GeoFeature::getClassTypeId())) { @@ -136,7 +172,9 @@ bool ViewProviderDragger::setEdit(int ModNum) csysDragger->addStartCallback(dragStartCallback, this); csysDragger->addFinishCallback(dragFinishCallback, this); - pcRoot->insertChild(csysDragger, 0); + // dragger node is added to viewer's editing root in setEditViewer + // pcRoot->insertChild(csysDragger, 0); + csysDragger->ref(); TaskCSysDragger *task = new TaskCSysDragger(this, csysDragger); Gui::Control().showDialog(task); @@ -154,7 +192,9 @@ void ViewProviderDragger::unsetEdit(int ModNum) pcTransform->translation.disconnect(&csysDragger->translation); pcTransform->rotation.disconnect(&csysDragger->rotation); - pcRoot->removeChild(csysDragger); //should delete csysDragger + // dragger node is added to viewer's editing root in setEditViewer + // pcRoot->removeChild(csysDragger); //should delete csysDragger + csysDragger->unref(); csysDragger = nullptr; } Gui::Control().closeDialog(); @@ -172,6 +212,15 @@ void ViewProviderDragger::setEditViewer(Gui::View3DInventorViewer* viewer, int M selection->insertChild(rootPickStyle, 0); selection->selectionRole.setValue(false); csysDragger->setUpAutoScale(viewer->getSoRenderManager()->getCamera()); + + auto mat = viewer->getDocument()->getEditingTransform(); + auto feat = dynamic_cast(getObject()); + if(feat) { + auto matInverse = feat->Placement.getValue().toMatrix(); + matInverse.inverse(); + mat *= matInverse; + } + viewer->setupEditingRoot(csysDragger,&mat); } } diff --git a/src/Gui/ViewProviderDragger.h b/src/Gui/ViewProviderDragger.h index bd9a1bc065..3a939625d4 100644 --- a/src/Gui/ViewProviderDragger.h +++ b/src/Gui/ViewProviderDragger.h @@ -58,6 +58,8 @@ public: void setupContextMenu(QMenu*, QObject*, const char*); void updateData(const App::Property*); + virtual ViewProvider *startEditing(int ModNum=0) override; + /*! synchronize From FC placement to Coin placement*/ static void updateTransform(const Base::Placement &from, SoTransform *to); @@ -74,6 +76,10 @@ private: static void dragFinishCallback(void * data, SoDragger * d); static void updatePlacementFromDragger(ViewProviderDragger *sudoThis, SoFCCSysDragger *draggerIn); + + bool checkLink(); + + ViewProvider *_linkDragger = nullptr; }; } // namespace Gui diff --git a/src/Mod/Show/Containers.py b/src/Mod/Show/Containers.py index 6f9c819af8..c5c4917a5d 100644 --- a/src/Mod/Show/Containers.py +++ b/src/Mod/Show/Containers.py @@ -58,6 +58,8 @@ class Container(object): return container.OriginFeatures elif container.hasExtension('App::GroupExtension'): return [] + elif container.hasChildElement(): + return [] raise RuntimeError("getStaticChildren: unexpected container type!") def getDynamicChildren(self): @@ -81,6 +83,14 @@ class Container(object): return result elif container.isDerivedFrom('App::Origin'): return [] + elif container.hasChildElement(): + result = [] + for sub in container.getSubObjects(1): + sobj = container.getSubObject(sub,retType=1) + if sobj: + result.append(sobj) + return result + raise RuntimeError("getDynamicChildren: unexpected container type!") def isACS(self): @@ -92,6 +102,8 @@ class Container(object): return True #Document is a special thing... is it a CS or not is a matter of coding convenience. elif container.hasExtension('App::GeoFeatureGroupExtension'): return True + elif container.hasElement(): + return True else: return False @@ -106,6 +118,8 @@ class Container(object): return True elif container.isDerivedFrom('App::Origin'): return True + elif container.hasChildElement(): + return True else: return False @@ -120,7 +134,17 @@ class Container(object): raise TypeError("Container is not a visibility group") container = self.Object return _getMetacontainerChildren(self, Container.isAVisGroup) - + + def isChildVisible(self,obj): + container = self.Object + isElementVisible = getattr(container,'isElementVisible',None) + if not isElementVisible: + return obj.Visibility + vis = isElementVisible(obj.Name) + if vis < 0: + return obj.Visibility + return vis>0 + def hasObject(self, obj): """Returns True if the container contains specified object directly.""" return obj in self.getAllChildren() @@ -168,6 +192,8 @@ def isAContainer(obj): return True if obj.isDerivedFrom('App::Origin'): return True + if obj.hasChildElement(): + return True return False #from Part-o-magic... diff --git a/src/Mod/Show/DepGraphTools.py b/src/Mod/Show/DepGraphTools.py index 2c8afee2ea..ad1a91faa5 100644 --- a/src/Mod/Show/DepGraphTools.py +++ b/src/Mod/Show/DepGraphTools.py @@ -65,11 +65,13 @@ def getAllDependent(feat): return list_of_deps -def isContainer(obj): +def _isContainer(obj): '''isContainer(obj): returns True if obj is an object container, such as Group, Part, Body. The important characterisic of an object being a container is visibility nesting.''' + if obj.hasChildElement(): + return True if obj.hasExtension('App::OriginGroupExtension'): return True if obj.hasExtension('App::GroupExtension'): @@ -77,3 +79,10 @@ def isContainer(obj): if obj.isDerivedFrom('App::Origin'): return True return False + +def isContainer(obj): + if _isContainer(obj): + return True + linked = obj.getLinkedObject() + return linked and linked!=obj and _isContainer(linked) + diff --git a/src/Mod/Show/TempoVis.py b/src/Mod/Show/TempoVis.py index 63cdfd9433..56996b529e 100644 --- a/src/Mod/Show/TempoVis.py +++ b/src/Mod/Show/TempoVis.py @@ -44,6 +44,7 @@ class TempoVis(FrozenClass): self.data = {} # dict. key = ("Object","Property"), value = original value of the property self.data_pickstyle = {} # dict. key = "Object", value = original value of pickstyle self.data_clipplane = {} # dict. key = "Object", value = original state of plane-clipping + self.clippingDoc = None self.sketch_clipplane_on = False #True if some clipping planes are active @@ -71,20 +72,13 @@ class TempoVis(FrozenClass): # observation: all viewproviders have transform node, then a switch node. If that switch node contains something, the object has something in 3d view. try: - viewprovider = obj.ViewObject from pivy import coin - sa = coin.SoSearchAction() - sa.setType(coin.SoSwitch.getClassTypeId()) - sa.traverse(viewprovider.RootNode) - if not sa.isFound(): #shouldn't happen... - return False - n = sa.getPath().getTail().getNumChildren() - return n > 0 + return obj.ViewObject.SwitchNode.getNumChildren()>0 except Exception as err: - App.Console.PrintWarning(u"Show.TempoVis.isIn3DView error: {err}".format(err= str(err))) + App.Console.PrintWarning(u"Show.TempoVis.isIn3DObject error: {err}\n".format(err= str(err))) return True #assume. - def modifyVPProperty(self, doc_obj_or_list, prop_name, new_value): + def modifyVPProperty(self, doc_obj_or_list, prop_names, new_value): '''modifyVPProperty(self, doc_obj_or_list, prop_name, new_value): modifies prop_name property of ViewProvider of doc_obj_or_list, and remembers original value of the property. Original values will be restored upon @@ -93,33 +87,63 @@ class TempoVis(FrozenClass): if App.GuiUp: if not hasattr(doc_obj_or_list, '__iter__'): doc_obj_or_list = [doc_obj_or_list] + if not isinstance(prop_names,(list,tuple)): + prop_names = [prop_names] for doc_obj in doc_obj_or_list: if not self.is3DObject(doc_obj): continue - if not hasattr(doc_obj.ViewObject, prop_name): - App.Console.PrintWarning("TempoVis: object {obj} has no attribute {attr}. Skipped.\n" - .format(obj= doc_obj.Name, attr= prop_name)) - continue # silently ignore if object doesn't have the property... + for prop_name in prop_names: + if not hasattr(doc_obj.ViewObject, prop_name): + App.Console.PrintWarning("TempoVis: object {obj} has no attribute {attr}. Skipped.\n" + .format(obj= doc_obj.Name, attr= prop_name)) + continue # silently ignore if object doesn't have the property... - if doc_obj.Document is not self.document: #ignore objects from other documents - raise ValueError("Document object to be modified does not belong to document TempoVis was made for.") - oldval = getattr(doc_obj.ViewObject, prop_name) - setattr(doc_obj.ViewObject, prop_name, new_value) - self.restore_on_delete = True - if (doc_obj.Name,prop_name) not in self.data: - self.data[(doc_obj.Name,prop_name)] = oldval + # Because the introduction of external objects, we shall now + # accept objects from all opening documents. + # + # if doc_obj.Document is not self.document: #ignore objects from other documents + # raise ValueError("Document object to be modified does not belong to document TempoVis was made for.") + oldval = getattr(doc_obj.ViewObject, prop_name) + if new_value is not None: + setattr(doc_obj.ViewObject, prop_name, new_value) + self.restore_on_delete = True + key = (doc_obj.Name,prop_name,doc_obj.Document.Name) + self.data.setdefault(key,oldval) + + def saveBodyVisibleFeature(self,doc_obj_or_list): + if not hasattr(doc_obj_or_list, '__iter__'): + doc_obj_or_list = [doc_obj_or_list] + objs = [] + bodies = set() + for obj in doc_obj_or_list: + body = getattr(obj,'Body',None) + if not body or body in bodies: + continue + bodies.add(body) + feature = getattr(body,'VisibleFeature',None) + if feature: + objs.append(feature) + self.modifyVPProperty(objs, 'Visibility',None) def show(self, doc_obj_or_list): '''show(doc_obj_or_list): shows objects (sets their Visibility to True). doc_obj_or_list can be a document object, or a list of document objects''' - self.modifyVPProperty(doc_obj_or_list, 'Visibility', True) + self.saveBodyVisibleFeature(doc_obj_or_list) + self.modifyVPProperty(doc_obj_or_list, ('Visibility','LinkVisibility'),True) def hide(self, doc_obj_or_list): '''hide(doc_obj_or_list): hides objects (sets their Visibility to False). doc_obj_or_list can be a document object, or a list of document objects''' - self.modifyVPProperty(doc_obj_or_list, 'Visibility', False) + self.saveBodyVisibleFeature(doc_obj_or_list) + self.modifyVPProperty(doc_obj_or_list, ('Visibility',"LinkVisibility"), False) - def get_all_dependent(self, doc_obj): + def get_all_dependent(self, doc_obj, subname=None): '''get_all_dependent(doc_obj): gets all objects that depend on doc_obj. Containers of the object are excluded from the list.''' - cnt_chain = Containers.ContainerChain(doc_obj) + if subname: + cnt_chain = doc_obj.getSubObjectList(subname) + doc_obj = cnt_chain[-1].getLinkedObject() + cnt_chain = [ o for o in cnt_chain + if o==cnt_chain[-1] or isContainer(o) ] + else: + cnt_chain = Containers.ContainerChain(doc_obj) return [o for o in getAllDependent(doc_obj) if not o in cnt_chain] def hide_all_dependent(self, doc_obj): @@ -132,7 +156,7 @@ class TempoVis(FrozenClass): def restore_all_dependent(self, doc_obj): '''show_all_dependent(doc_obj): restores original visibilities of all dependent objects.''' - self.restoreVPProperty( getAllDependent(doc_obj), 'Visibility' ) + self.restoreVPProperty( getAllDependent(doc_obj), ('Visibility','LinkVisibility') ) def hide_all_dependencies(self, doc_obj): '''hide_all_dependencies(doc_obj): hides all objects that doc_obj depends on (directly and indirectly).''' @@ -169,9 +193,9 @@ class TempoVis(FrozenClass): self.viewer = Gui.ActiveDocument.ActiveView self.links_are_lost = False - for obj_name, prop_name in self.data: + for (obj_name, prop_name, doc_name), value in self.data.items(): try: - setattr(self.document.getObject(obj_name).ViewObject, prop_name, self.data[(obj_name, prop_name)]) + setattr(App.getDocument(doc_name).getObject(obj_name).ViewObject,prop_name,value) except Exception as err: App.Console.PrintWarning("TempoVis: failed to restore {obj}.{prop}. {err}\n" .format(err= err.message, @@ -188,23 +212,26 @@ class TempoVis(FrozenClass): .format(err= err.message)) self.restore_on_delete = False - def restoreVPProperty(self, object_or_list, prop_name): + def restoreVPProperty(self, object_or_list, prop_names): """restoreVPProperty(object_or_list, prop_name): restores original values of certain property for certain objects.""" if App.GuiUp: if not hasattr(object_or_list, '__iter__'): object_or_list = [object_or_list] + if not isinstance(prop_names,(tuple,list)): + prop_names = [prop_names] for doc_obj in object_or_list: if not self.is3DObject(doc_obj): continue - key = (doc_obj.Name, prop_name) - if key in self.data: - try: - setattr(doc_obj.ViewObject, prop_name, self.data[key]) - except Exception as err: - App.Console.PrintWarning("TempoVis: failed to restore {obj}.{prop}. {err}\n" - .format(err= err.message, - obj= doc_obj.Name, - prop= prop_name)) + for prop_name in prop_names: + key = (doc_obj.Name, prop_name, doc_obj.Document.Name) + if key in self.data: + try: + setattr(doc_obj.ViewObject, prop_name, self.data[key]) + except Exception as err: + App.Console.PrintWarning("TempoVis: failed to restore {obj}.{prop}. {err}\n" + .format(err= err.message, + obj= doc_obj.Name, + prop= prop_name)) def forget(self): @@ -358,8 +385,8 @@ class TempoVis(FrozenClass): for doc_obj in doc_obj_or_list: if not self.is3DObject(doc_obj): continue - if doc_obj.Document is not self.document: #ignore objects from other documents - raise ValueError("Document object to be modified does not belong to document TempoVis was made for.") + # if doc_obj.Document is not self.document: #ignore objects from other documents + # raise ValueError("Document object to be modified does not belong to document TempoVis was made for.") print("Clipping {obj}".format(obj= doc_obj.Name)) self._enableClipPlane(doc_obj, enable, placement, offset) self.restore_on_delete = True @@ -367,6 +394,7 @@ class TempoVis(FrozenClass): self.data_clipplane[doc_obj.Name] = False def restoreClipPlanes(self): + self.sketchClipPlane(None,False) for obj_name in self.data_clipplane: try: self._enableClipPlane(self.document.getObject(obj_name), self.data_clipplane[obj_name]) @@ -385,11 +413,12 @@ class TempoVis(FrozenClass): for i in range(len(chain)): cnt = chain[i] cnt_next = chain[i+1] if i+1 < len(chain) else aroundObject - for obj in Container(cnt).getVisGroupChildren(): + container = Container(cnt) + for obj in container.getVisGroupChildren(): if not TempoVis.is3DObject(obj): continue if obj is not cnt_next: - if obj.ViewObject.Visibility: + if container.isChildVisible(obj): result.append(obj) return result @@ -397,7 +426,21 @@ class TempoVis(FrozenClass): """sketchClipPlane(sketch, enable = None): Clips all objects by plane of sketch. If enable argument is omitted, calling the routine repeatedly will toggle clipping plane.""" + editDoc = self.clippingDoc + if not editDoc: + editDoc = Gui.editDocument() + if editDoc: + self.clippingDoc = editDoc + toggle = 1 if enable else -1 if enable is None else 0 + editDoc.ActiveView.toggleClippingPlane( + toggle, pla=App.Placement(editDoc.EditingTransform)) + return + elif not sketch: + return + if enable is None: enable = not self.sketch_clipplane_on self.sketch_clipplane_on = enable self.clipPlane(self.allVisibleObjects(sketch), enable, sketch.getGlobalPlacement(), 0.02) + + diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 42327c8d88..9a3d66a300 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -423,8 +423,8 @@ void CmdSketcherReorientSketch::activated(int iMsg) } 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]); + FCMD_OBJ_CMD2("Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))" + ,sketch,p.x,p.y,p.z,r[0],r[1],r[2],r[3]); doCommand(Gui,"Gui.ActiveDocument.setEdit('%s')",sketch->getNameInDocument()); } @@ -564,20 +564,19 @@ void CmdSketcherMapSketch::activated(int iMsg) } // * action - std::string featName = sketch.getNameInDocument(); if (bAttach) { App::PropertyLinkSubList support; Gui::Selection().getAsPropertyLinkSubList(support); std::string supportString = support.getPyReprString(); openCommand("Attach Sketch"); - doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",featName.c_str(),AttachEngine::getModeName(suggMapMode).c_str()); - doCommand(Gui,"App.activeDocument().%s.Support = %s",featName.c_str(),supportString.c_str()); + FCMD_OBJ_CMD2("MapMode = \"%s\"",&sketch,AttachEngine::getModeName(suggMapMode).c_str()); + FCMD_OBJ_CMD2("Support = %s",&sketch,supportString.c_str()); commitCommand(); } else { openCommand("Detach Sketch"); - doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",featName.c_str(),AttachEngine::getModeName(suggMapMode).c_str()); - doCommand(Gui,"App.activeDocument().%s.Support = None",featName.c_str()); + FCMD_OBJ_CMD2("MapMode = \"%s\"",&sketch,AttachEngine::getModeName(suggMapMode).c_str()); + FCMD_OBJ_CMD2("Support = None",&sketch); commitCommand(); } } catch (ExceptionWrongInput &e) { @@ -614,8 +613,8 @@ void CmdSketcherViewSketch::activated(int iMsg) Gui::Document *doc = getActiveGuiDocument(); SketcherGui::ViewProviderSketch* vp = dynamic_cast(doc->getInEdit()); if (vp) { - doCommand(Gui,"Gui.ActiveDocument.ActiveView.setCameraOrientation(App.ActiveDocument.%s.getGlobalPlacement().Rotation.Q)" - ,vp->getObject()->getNameInDocument()); + runCommand(Gui,"Gui.ActiveDocument.ActiveView.setCameraOrientation(" + "App.Placement(Gui.editDocument().EditingTransform).Rotation.Q)"); } } diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index 7c8ef120b4..9fed075962 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -142,7 +142,7 @@ void CmdSketcherToggleConstruction::activated(int iMsg) if (it->size() > 4 && it->substr(0,4) == "Edge") { int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; // issue the actual commands to toggle - doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),GeoId); + FCMD_OBJ_CMD2("App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getObject(),GeoId); } } // finish the transaction and update diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index b2fee3ab96..6fd72b4d80 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -152,15 +152,15 @@ void openEditDatumDialog(Sketcher::SketchObject* sketch, int ConstrNbr) if (ui_ins_datum.labelEdit->hasExpression()) ui_ins_datum.labelEdit->apply(); else - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,App.Units.Quantity('%f %s'))", - sketch->getNameInDocument(), + FCMD_OBJ_CMD2("setDatum(%i,App.Units.Quantity('%f %s'))", + sketch, ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8()); QString constraintName = ui_ins_datum.name->text().trimmed(); if (Base::Tools::toStdString(constraintName) != sketch->Constraints[ConstrNbr]->Name) { std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - sketch->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + sketch, ConstrNbr, escapedstr.c_str()); } Gui::Command::commitCommand(); @@ -394,20 +394,19 @@ void SketcherGui::makeTangentToEllipseviaNewPoint(Sketcher::SketchObject* Obj, try { // Add a point - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - Obj->getNameInDocument(), PoE.x,PoE.y); + FCMD_OBJ_CMD2("addGeometry(Part.Point(App.Vector(%f,%f,0)))", + Obj, PoE.x,PoE.y); int GeoIdPoint = Obj->getHighestCurveIndex(); // Point on first object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId1); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId1); // constrain major axis // Point on second object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId2); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId2); // constrain major axis // tangent via point - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", - Obj->getNameInDocument(), geoId1, geoId2 ,GeoIdPoint, Sketcher::start); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", + Obj, geoId1, geoId2 ,GeoIdPoint, Sketcher::start); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -459,20 +458,19 @@ void SketcherGui::makeTangentToArcOfEllipseviaNewPoint(Sketcher::SketchObject* O try { // Add a point - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - Obj->getNameInDocument(), PoE.x,PoE.y); + FCMD_OBJ_CMD2("addGeometry(Part.Point(App.Vector(%f,%f,0)))", + Obj, PoE.x,PoE.y); int GeoIdPoint = Obj->getHighestCurveIndex(); // Point on first object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId1); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId1); // constrain major axis // Point on second object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId2); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId2); // constrain major axis // tangent via point - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", - Obj->getNameInDocument(), geoId1, geoId2 ,GeoIdPoint, Sketcher::start); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", + Obj, geoId1, geoId2 ,GeoIdPoint, Sketcher::start); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -541,20 +539,19 @@ void SketcherGui::makeTangentToArcOfHyperbolaviaNewPoint(Sketcher::SketchObject* try { // Add a point - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - Obj->getNameInDocument(), PoH.x,PoH.y); + FCMD_OBJ_CMD2("addGeometry(Part.Point(App.Vector(%f,%f,0)))", + Obj, PoH.x,PoH.y); int GeoIdPoint = Obj->getHighestCurveIndex(); // Point on first object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId1); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId1); // constrain major axis // Point on second object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId2); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId2); // constrain major axis // tangent via point - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", - Obj->getNameInDocument(), geoId1, geoId2 ,GeoIdPoint, Sketcher::start); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", + Obj, geoId1, geoId2 ,GeoIdPoint, Sketcher::start); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -618,20 +615,19 @@ void SketcherGui::makeTangentToArcOfParabolaviaNewPoint(Sketcher::SketchObject* try { // Add a point - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - Obj->getNameInDocument(), PoP.x,PoP.y); + FCMD_OBJ_CMD2("addGeometry(Part.Point(App.Vector(%f,%f,0)))", + Obj, PoP.x,PoP.y); int GeoIdPoint = Obj->getHighestCurveIndex(); // Point on first object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId1); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId1); // constrain major axis // Point on second object - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,geoId2); // constrain major axis + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,geoId2); // constrain major axis // tangent via point - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", - Obj->getNameInDocument(), geoId1, geoId2 ,GeoIdPoint, Sketcher::start); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d))", + Obj, geoId1, geoId2 ,GeoIdPoint, Sketcher::start); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -727,9 +723,8 @@ void SketcherGui::doEndpointTangency(Sketcher::SketchObject* Obj, Gui::Selection // GeoId1 is the B-spline now } // end of code supports simple B-spline endpoint tangency - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d,%d)) ", - selection.getFeatName(),GeoId1,PosId1,GeoId2,PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d,%d)) ", + selection.getObject(),GeoId1,PosId1,GeoId2,PosId2); } @@ -1290,8 +1285,8 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg) openCommand("add horizontal constraint"); for (std::vector::iterator it=edgegeoids.begin(); it != edgegeoids.end(); it++) { // issue the actual commands to create the constraint - doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Horizontal',%d)) " - ,selection[0].getFeatName(),*it); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Horizontal',%d)) " + ,selection[0].getObject(),*it); } } else if (fixedpoints <= 1) { // pointgeoids @@ -1301,8 +1296,8 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg) std::vector::iterator itp; for (it=pointgeoids.begin(), itp=pointpos.begin(); it != std::prev(pointgeoids.end()) && itp != std::prev(pointpos.end()); it++,itp++) { // issue the actual commands to create the constraint - doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Horizontal',%d,%d,%d,%d)) " - ,selection[0].getFeatName(),*it,*itp,*std::next(it),*std::next(itp)); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Horizontal',%d,%d,%d,%d)) " + ,selection[0].getObject(),*it,*itp,*std::next(it),*std::next(itp)); } } else { // vertex mode, fixedpoints > 1 @@ -1362,8 +1357,8 @@ void CmdSketcherConstrainHorizontal::applyConstraint(std::vector &sel // undo command open Gui::Command::openCommand("add horizontal constraint"); // issue the actual commands to create the constraint - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Horizontal',%d)) ", - sketchgui->getObject()->getNameInDocument(),CrvId); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Horizontal',%d)) ", + sketchgui->getObject(),CrvId); // finish the transaction and update Gui::Command::commitCommand(); @@ -1536,8 +1531,8 @@ void CmdSketcherConstrainVertical::activated(int iMsg) openCommand("add vertical constraint"); for (std::vector::iterator it=edgegeoids.begin(); it != edgegeoids.end(); it++) { // issue the actual commands to create the constraint - doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Vertical',%d)) " - ,selection[0].getFeatName(),*it); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Vertical',%d)) " + ,selection[0].getObject(),*it); } } else if (fixedpoints <= 1) { // vertex mode, maximum one fixed point @@ -1547,8 +1542,8 @@ void CmdSketcherConstrainVertical::activated(int iMsg) std::vector::iterator itp; for (it=pointgeoids.begin(), itp=pointpos.begin(); it != std::prev(pointgeoids.end()) && itp != std::prev(pointpos.end()); it++,itp++) { // issue the actual commands to create the constraint - doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Vertical',%d,%d,%d,%d)) " - ,selection[0].getFeatName(),*it,*itp,*std::next(it),*std::next(itp)); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Vertical',%d,%d,%d,%d)) " + ,selection[0].getObject(),*it,*itp,*std::next(it),*std::next(itp)); } } else { // vertex mode, fixedpoints > 1 @@ -1609,8 +1604,8 @@ void CmdSketcherConstrainVertical::applyConstraint(std::vector &selSe // undo command open Gui::Command::openCommand("add vertical constraint"); // issue the actual commands to create the constraint - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Vertical',%d)) ", - sketchgui->getObject()->getNameInDocument(),CrvId); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Vertical',%d)) ", + sketchgui->getObject(),CrvId); // finish the transaction and update Gui::Command::commitCommand(); tryAutoRecompute(Obj); @@ -1757,23 +1752,21 @@ void CmdSketcherConstrainLock::activated(int iMsg) // undo command open openCommand("add fixed constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", - selection[0].getFeatName(),GeoId[0],PosId[0],pnt.x); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", - selection[0].getFeatName(),GeoId[0],PosId[0],pnt.y); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", + selection[0].getObject(),GeoId[0],PosId[0],pnt.x); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", + selection[0].getObject(),GeoId[0],PosId[0],pnt.y); lastconstraintindex+=2; if (edgeisblocked || GeoId[0] <= Sketcher::GeoEnum::RefExt || isConstructionPoint(Obj,GeoId[0]) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),lastconstraintindex-2,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),lastconstraintindex-2,"False"); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),lastconstraintindex,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),lastconstraintindex,"False"); } } else { @@ -1798,23 +1791,21 @@ void CmdSketcherConstrainLock::activated(int iMsg) // undo command open openCommand("add relative lock constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),*itg,*itp,GeoId.back(),PosId.back(),pntr.x-pnt.x); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),*itg,*itp,GeoId.back(),PosId.back(),pntr.x-pnt.x); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),*itg,*itp,GeoId.back(),PosId.back(),pntr.y-pnt.y); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),*itg,*itp,GeoId.back(),PosId.back(),pntr.y-pnt.y); lastconstraintindex+=2; if ( (refpointfixed && pointfixed) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),lastconstraintindex-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),lastconstraintindex-1,"False"); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),lastconstraintindex,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),lastconstraintindex,"False"); } } } @@ -1845,22 +1836,20 @@ void CmdSketcherConstrainLock::applyConstraint(std::vector &selSeq, i // undo command open Gui::Command::openCommand("add fixed constraint"); - Gui::Command::doCommand( - Gui::Command::Doc, "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX', %d, %d, %f)) ", - sketchgui->getObject()->getNameInDocument(), selSeq.front().GeoId, selSeq.front().PosId, pnt.x); - Gui::Command::doCommand( - Gui::Command::Doc, "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY', %d, %d, %f)) ", - sketchgui->getObject()->getNameInDocument(), selSeq.front().GeoId, selSeq.front().PosId, pnt.y); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX', %d, %d, %f)) ", + sketchgui->getObject(), selSeq.front().GeoId, selSeq.front().PosId, pnt.x); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY', %d, %d, %f)) ", + sketchgui->getObject(), selSeq.front().GeoId, selSeq.front().PosId, pnt.y); if (pointfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.setDriving(%i, %s)", - sketchgui->getObject()->getNameInDocument(), ConStr.size()-2, "False"); + FCMD_OBJ_CMD2("setDriving(%i, %s)", + sketchgui->getObject(), ConStr.size()-2, "False"); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.setDriving(%i, %s)", - sketchgui->getObject()->getNameInDocument(), ConStr.size()-1, "False"); + FCMD_OBJ_CMD2("setDriving(%i, %s)", + sketchgui->getObject(), ConStr.size()-1, "False"); } // finish the transaction and update @@ -2222,9 +2211,8 @@ public: // check if this coincidence is already enforced (even indirectly) bool constraintExists = Obj->arePointsCoincident(GeoId1,PosId1,GeoId2,PosId2); if (!constraintExists && (GeoId1 != GeoId2)) { - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", - sketchgui->getObject()->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + sketchgui->getObject(),GeoId1,PosId1,GeoId2,PosId2); Gui::Command::commitCommand(); } else { @@ -2373,9 +2361,8 @@ void CmdSketcherConstrainCoincident::activated(int iMsg) if (!constraintExists) { constraintsAdded = true; - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2); } } @@ -2415,9 +2402,8 @@ void CmdSketcherConstrainCoincident::applyConstraint(std::vector &sel // check if this coincidence is already enforced (even indirectly) bool constraintExists = Obj->arePointsCoincident(GeoId1, PosId1, GeoId2, PosId2); if (!constraintExists && (GeoId1 != GeoId2)) { - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident', %d, %d, %d, %d)) ", - sketchgui->getObject()->getNameInDocument(), GeoId1, PosId1, GeoId2, PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident', %d, %d, %d, %d)) ", + sketchgui->getObject(), GeoId1, PosId1, GeoId2, PosId2); Gui::Command::commitCommand(); } else { @@ -2519,32 +2505,29 @@ void CmdSketcherConstrainDistance::activated(int iMsg) PosId1 = Sketcher::start; openCommand("add distance from horizontal axis constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,pnt2.y); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,pnt2.y); } else if (GeoId1 == Sketcher::GeoEnum::VAxis && PosId1 == Sketcher::none) { PosId1 = Sketcher::start; openCommand("add distance from vertical axis constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,pnt2.x); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,pnt2.x); } else { Base::Vector3d pnt1 = Obj->getPoint(GeoId1,PosId1); openCommand("add point to point distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,(pnt2-pnt1).Length()); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,(pnt2-pnt1).Length()); } if (arebothpointsorsegmentsfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -2568,15 +2551,14 @@ void CmdSketcherConstrainDistance::activated(int iMsg) double ActDist = std::abs(-pnt.x*d.y+pnt.y*d.x+pnt1.x*pnt2.y-pnt2.x*pnt1.y) / d.Length(); openCommand("add point to line Distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,ActDist); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,ActDist); if (arebothpointsorsegmentsfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -2601,15 +2583,14 @@ void CmdSketcherConstrainDistance::activated(int iMsg) double ActLength = (lineSeg->getEndPoint()-lineSeg->getStartPoint()).Length(); openCommand("add length constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%f)) ", - selection[0].getFeatName(),GeoId1,ActLength); - + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Distance',%d,%f)) ", + selection[0].getObject(),GeoId1,ActLength); + if (arebothpointsorsegmentsfixed || GeoId1 <= Sketcher::GeoEnum::RefExt || isConstructionPoint(Obj,GeoId1) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -2647,32 +2628,29 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector &selSe PosId1 = Sketcher::start; openCommand("add distance from horizontal axis constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,pnt2.y); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,pnt2.y); } else if (GeoId1 == Sketcher::GeoEnum::VAxis && PosId1 == Sketcher::none) { PosId1 = Sketcher::start; openCommand("add distance from vertical axis constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,pnt2.x); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,pnt2.x); } else { Base::Vector3d pnt1 = Obj->getPoint(GeoId1,PosId1); openCommand("add point to point distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,(pnt2-pnt1).Length()); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%d,%f)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,(pnt2-pnt1).Length()); } if (arebothpointsorsegmentsfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj,ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -2695,15 +2673,14 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector &selSe double ActLength = (lineSeg->getEndPoint()-lineSeg->getStartPoint()).Length(); openCommand("add length constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%f)) ", - Obj->getNameInDocument(),GeoId1,ActLength); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Distance',%d,%f)) ", + Obj,GeoId1,ActLength); if (arebothpointsorsegmentsfixed || GeoId1 <= Sketcher::GeoEnum::RefExt || isConstructionPoint(Obj,GeoId1) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj,ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -2735,15 +2712,14 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector &selSe double ActDist = std::abs(-pnt.x*d.y+pnt.y*d.x+pnt1.x*pnt2.y-pnt2.x*pnt1.y) / d.Length(); openCommand("add point to line Distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,ActDist); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%f)) ", + Obj,GeoId1,PosId1,GeoId2,ActDist); if (arebothpointsorsegmentsfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj,ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -2910,9 +2886,8 @@ void CmdSketcherConstrainPointOnObject::activated(int iMsg) } cnt++; - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),points[iPnt].GeoId, points[iPnt].PosId, curves[iCrv].GeoId); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),points[iPnt].GeoId, points[iPnt].PosId, curves[iCrv].GeoId); } } if (cnt) { @@ -2982,9 +2957,8 @@ void CmdSketcherConstrainPointOnObject::applyConstraint(std::vector & } if (allOK) { - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - sketchgui->getObject()->getNameInDocument(), GeoIdVt, PosIdVt, GeoIdCrv); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + sketchgui->getObject(), GeoIdVt, PosIdVt, GeoIdCrv); commitCommand(); tryAutoRecompute(Obj); @@ -3117,15 +3091,14 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg) } openCommand("add point to point horizontal distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActLength); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,ActLength); if (arebothpointsorsegmentsfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -3147,16 +3120,15 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg) arebothpointsorsegmentsfixed=isPointOrSegmentFixed(Obj,GeoId1); openCommand("add fixed x-coordinate constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,ActX); - + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,ActX); + if (arebothpointsorsegmentsfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -3218,15 +3190,14 @@ void CmdSketcherConstrainDistanceX::applyConstraint(std::vector &selS } openCommand("add point to point horizontal distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,ActLength); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,ActLength); if (areBothPointsOrSegmentsFixed(Obj,GeoId1, GeoId2) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj,ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj, false); } else @@ -3365,15 +3336,14 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg) } openCommand("add point to point vertical distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActLength); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,ActLength); if (arebothpointsorsegmentsfixed || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -3395,15 +3365,14 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg) arebothpointsorsegmentsfixed=isPointOrSegmentFixed(Obj,GeoId1); openCommand("add fixed y-coordinate constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,ActY); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,ActY); if (GeoId1 <= Sketcher::GeoEnum::RefExt || isConstructionPoint(Obj,GeoId1) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -3465,15 +3434,14 @@ void CmdSketcherConstrainDistanceY::applyConstraint(std::vector &selS } openCommand("add point to point vertical distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,ActLength); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,ActLength); if (areBothPointsOrSegmentsFixed(Obj,GeoId1, GeoId2) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj,ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -3636,9 +3604,8 @@ void CmdSketcherConstrainParallel::activated(int iMsg) // undo command open openCommand("add parallel constraint"); for (int i=0; i < int(ids.size()-1); i++) { - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Parallel',%d,%d)) ", - selection[0].getFeatName(),ids[i],ids[i+1]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Parallel',%d,%d)) ", + selection[0].getObject(),ids[i],ids[i+1]); } // finish the transaction and update commitCommand(); @@ -3677,9 +3644,8 @@ void CmdSketcherConstrainParallel::applyConstraint(std::vector &selSe // undo command open openCommand("add parallel constraint"); - Gui::Command::doCommand( - Doc, "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Parallel',%d,%d)) ", - sketchgui->getObject()->getNameInDocument(), GeoId1, GeoId2); + FCMD_OBJ_CMD2(".addConstraint(Sketcher.Constraint('Parallel',%d,%d)) ", + sketchgui->getObject(), GeoId1, GeoId2); // finish the transaction and update commitCommand(); tryAutoRecompute(Obj); @@ -3840,26 +3806,22 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) try{ //add missing point-on-object constraints if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId1); }; if(! IsPointAlreadyOnCurve(GeoId2, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId2); }; if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){//FIXME: it's a good idea to add a check if the sketch is solved - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId1); }; - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,GeoId2,GeoId3,PosId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,GeoId2,GeoId3,PosId3); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); QMessageBox::warning(Gui::getMainWindow(), @@ -3908,9 +3870,8 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) } // end of code supports simple B-spline endpoint tangency openCommand("add perpendicular constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Perpendicular',%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Perpendicular',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2); commitCommand(); tryAutoRecompute(Obj); @@ -3940,9 +3901,8 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) } openCommand("add perpendicularity constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Perpendicular',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Perpendicular',%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2); commitCommand(); tryAutoRecompute(Obj); @@ -4055,21 +4015,20 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) try { // Add a point - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - Obj->getNameInDocument(), PoO.x,PoO.y); + FCMD_OBJ_CMD2("addGeometry(Part.Point(App.Vector(%f,%f,0)))", + Obj, PoO.x,PoO.y); int GeoIdPoint = Obj->getHighestCurveIndex(); // Point on first object (ellipse, arc of ellipse) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoIdPoint,Sketcher::start,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoIdPoint,Sketcher::start,GeoId1); // Point on second object - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoIdPoint,Sketcher::start,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoIdPoint,Sketcher::start,GeoId2); // add constraint: Perpendicular-via-point - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d))", - Obj->getNameInDocument(), GeoId1, GeoId2 ,GeoIdPoint, Sketcher::start); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d))", + Obj, GeoId1, GeoId2 ,GeoIdPoint, Sketcher::start); } catch (const Base::Exception& e) { @@ -4089,9 +4048,8 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) } openCommand("add perpendicular constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Perpendicular',%d,%d)) ", - selection[0].getFeatName(),GeoId1,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Perpendicular',%d,%d)) ", + selection[0].getObject(),GeoId1,GeoId2); commitCommand(); tryAutoRecompute(Obj); @@ -4232,21 +4190,20 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector & try { // Add a point - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - Obj->getNameInDocument(), PoO.x,PoO.y); + FCMD_OBJ_CMD2("addGeometry(Part.Point(App.Vector(%f,%f,0)))", + Obj, PoO.x,PoO.y); int GeoIdPoint = Obj->getHighestCurveIndex(); // Point on first object (ellipse, arc of ellipse) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,GeoId1); // Point on second object - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoIdPoint,Sketcher::start,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoIdPoint,Sketcher::start,GeoId2); // add constraint: Perpendicular-via-point - Gui::Command::doCommand( - Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d))", - Obj->getNameInDocument(), GeoId1, GeoId2 ,GeoIdPoint, Sketcher::start); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d))", + Obj, GeoId1, GeoId2 ,GeoIdPoint, Sketcher::start); commitCommand(); } @@ -4264,9 +4221,8 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector & } openCommand("add perpendicular constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Perpendicular',%d,%d)) ", - Obj->getNameInDocument(),GeoId1,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Perpendicular',%d,%d)) ", + Obj,GeoId1,GeoId2); commitCommand(); tryAutoRecompute(Obj); @@ -4305,26 +4261,22 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector & try{ //add missing point-on-object constraints if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId1); }; if(! IsPointAlreadyOnCurve(GeoId2, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId2); }; if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){//FIXME: it's a good idea to add a check if the sketch is solved - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId1); }; - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId1,GeoId2,GeoId3,PosId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PerpendicularViaPoint',%d,%d,%d,%d)) ", + Obj,GeoId1,GeoId2,GeoId3,PosId3); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); QMessageBox::warning(Gui::getMainWindow(), @@ -4459,26 +4411,22 @@ void CmdSketcherConstrainTangent::activated(int iMsg) try{ //add missing point-on-object constraints if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId1); }; if(! IsPointAlreadyOnCurve(GeoId2, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId2); }; if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){//FIXME: it's a good idea to add a check if the sketch is solved - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId1); }; - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,GeoId2,GeoId3,PosId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,GeoId2,GeoId3,PosId3); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); QMessageBox::warning(Gui::getMainWindow(), @@ -4541,9 +4489,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) } openCommand("add tangent constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2); commitCommand(); tryAutoRecompute(Obj); @@ -4730,9 +4677,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) } openCommand("add tangent constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d)) ", - selection[0].getFeatName(),GeoId1,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Tangent',%d,%d)) ", + selection[0].getObject(),GeoId1,GeoId2); commitCommand(); tryAutoRecompute(Obj); @@ -4881,9 +4827,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector &selSeq } openCommand("add tangent constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d)) ", - Obj->getNameInDocument(),GeoId1,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Tangent',%d,%d)) ", + Obj,GeoId1,GeoId2); commitCommand(); tryAutoRecompute(Obj); @@ -4940,9 +4885,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector &selSeq } // end of code supports simple B-spline endpoint tangency openCommand("add tangent constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d,%d)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2); commitCommand(); tryAutoRecompute(Obj); @@ -4960,26 +4904,22 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector &selSeq try{ //add missing point-on-object constraints if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId1); }; if(! IsPointAlreadyOnCurve(GeoId2, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId2); }; if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){//FIXME: it's a good idea to add a check if the sketch is solved - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId1); }; - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d)) ", - Obj->getNameInDocument(), GeoId1,GeoId2,GeoId3,PosId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('TangentViaPoint',%d,%d,%d,%d)) ", + Obj, GeoId1,GeoId2,GeoId3,PosId3); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); QMessageBox::warning(Gui::getMainWindow(), @@ -5126,16 +5066,15 @@ void CmdSketcherConstrainRadius::activated(int iMsg) unsigned int constrSize = 0; for (std::vector< std::pair >::iterator it = externalGeoIdRadiusMap.begin(); it != externalGeoIdRadiusMap.end(); ++it) { - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", - selection[0].getFeatName(),it->first,it->second); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + selection[0].getObject(),it->first,it->second); const std::vector &ConStr = Obj->Constraints.getValues(); constrSize=ConStr.size(); - - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),constrSize-1,"False"); + + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),constrSize-1,"False"); } const std::vector &ConStr = Obj->Constraints.getValues(); @@ -5184,16 +5123,14 @@ void CmdSketcherConstrainRadius::activated(int iMsg) if(!commandopened) openCommand("Add radius constraint"); - - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", - selection[0].getFeatName(),refGeoId,radius); + + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + selection[0].getObject(),refGeoId,radius); // Add the equality constraints for (std::vector< std::pair >::iterator it = geoIdRadiusMap.begin()+1; it != geoIdRadiusMap.end(); ++it) { - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", - selection[0].getFeatName(),refGeoId,it->first); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", + selection[0].getObject(),refGeoId,it->first); } } else { @@ -5201,16 +5138,15 @@ void CmdSketcherConstrainRadius::activated(int iMsg) if(!commandopened) openCommand("Add radius constraint"); for (std::vector< std::pair >::iterator it = geoIdRadiusMap.begin(); it != geoIdRadiusMap.end(); ++it) { - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", - selection[0].getFeatName(),it->first,it->second); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + selection[0].getObject(),it->first,it->second); if(constraintCreationMode==Reference) { const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); } @@ -5260,22 +5196,22 @@ void CmdSketcherConstrainRadius::activated(int iMsg) try { if (constrainEqual || geoIdRadiusMap.size() == 1) { - doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,App.Units.Quantity('%f %s'))", - Obj->getNameInDocument(), + FCMD_OBJ_CMD2("setDatum(%i,App.Units.Quantity('%f %s'))", + Obj, indexConstr, newRadius, (const char*)newQuant.getUnit().getString().toUtf8()); QString constraintName = ui_Datum.name->text().trimmed(); if (Base::Tools::toStdString(constraintName) != Obj->Constraints[indexConstr]->Name) { std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - Obj->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + Obj, indexConstr, escapedstr.c_str()); } } else { for (std::size_t i=0; igetNameInDocument(), + FCMD_OBJ_CMD2("setDatum(%i,App.Units.Quantity('%f %s'))", + Obj, indexConstr+i, newRadius, (const char*)newQuant.getUnit().getString().toUtf8()); } } @@ -5355,16 +5291,16 @@ void CmdSketcherConstrainRadius::applyConstraint(std::vector &selSeq, // Create the radius constraint now openCommand("Add radius constraint"); - Gui::Command::doCommand(Doc, "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", - Obj->getNameInDocument(), GeoId, radius); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + Obj, GeoId, radius); const std::vector &ConStr = Obj->Constraints.getValues(); int indexConstr = ConStr.size() - 1; bool fixed = isPointOrSegmentFixed(Obj,GeoId); if(fixed || constraintCreationMode==Reference) { - Gui::Command::doCommand(Doc, "App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(), ConStr.size()-1, "False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj, ConStr.size()-1, "False"); } // Guess some reasonable distance for placing the datum text @@ -5401,15 +5337,15 @@ void CmdSketcherConstrainRadius::applyConstraint(std::vector &selSeq, double newRadius = newQuant.getValue(); try { - doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,App.Units.Quantity('%f %s'))", - Obj->getNameInDocument(), + FCMD_OBJ_CMD2("setDatum(%i,App.Units.Quantity('%f %s'))", + Obj, indexConstr, newRadius, (const char*)newQuant.getUnit().getString().toUtf8()); QString constraintName = ui_Datum.name->text().trimmed(); if (Base::Tools::toStdString(constraintName) != Obj->Constraints[indexConstr]->Name) { std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - Obj->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + Obj, indexConstr, escapedstr.c_str()); } @@ -6158,19 +6094,16 @@ void CmdSketcherConstrainAngle::activated(int iMsg) //add missing point-on-object constraints if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId1); }; if(! IsPointAlreadyOnCurve(GeoId2, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId2); }; if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){//FIXME: it's a good idea to add a check if the sketch is solved - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId3,PosId3,GeoId1); }; //assuming point-on-curves have been solved, calculate the angle. @@ -6185,15 +6118,14 @@ void CmdSketcherConstrainAngle::activated(int iMsg) ActAngle = -ActAngle; } - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('AngleViaPoint',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,GeoId2,GeoId3,PosId3,ActAngle); - + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('AngleViaPoint',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,GeoId2,GeoId3,PosId3,ActAngle); + if (bothexternal || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -6285,15 +6217,14 @@ void CmdSketcherConstrainAngle::activated(int iMsg) } openCommand("Add angle constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActAngle); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,ActAngle); if (bothexternal || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -6316,15 +6247,14 @@ void CmdSketcherConstrainAngle::activated(int iMsg) double ActAngle = atan2(dir.y,dir.x); openCommand("Add angle constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%f)) ", - selection[0].getFeatName(),GeoId1,ActAngle); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Angle',%d,%f)) ", + selection[0].getObject(),GeoId1,ActAngle); if (GeoId1 <= Sketcher::GeoEnum::RefExt || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -6340,15 +6270,14 @@ void CmdSketcherConstrainAngle::activated(int iMsg) double angle = endangle - startangle; openCommand("Add angle constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%f)) ", - selection[0].getFeatName(),GeoId1,angle); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Angle',%d,%f)) ", + selection[0].getObject(),GeoId1,angle); if (GeoId1 <= Sketcher::GeoEnum::RefExt || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -6453,15 +6382,14 @@ void CmdSketcherConstrainAngle::applyConstraint(std::vector &selSeq, } openCommand("Add angle constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,ActAngle); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,ActAngle); if (areBothPointsOrSegmentsFixed(Obj,GeoId1, GeoId2) || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj,ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -6503,19 +6431,16 @@ void CmdSketcherConstrainAngle::applyConstraint(std::vector &selSeq, //add missing point-on-object constraints if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId1); }; if(! IsPointAlreadyOnCurve(GeoId2, GeoId3, PosId3, Obj)){ - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId2); }; if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){//FIXME: it's a good idea to add a check if the sketch is solved - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId3,PosId3,GeoId1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + Obj,GeoId3,PosId3,GeoId1); }; //assuming point-on-curves have been solved, calculate the angle. @@ -6530,15 +6455,14 @@ void CmdSketcherConstrainAngle::applyConstraint(std::vector &selSeq, ActAngle = -ActAngle; } - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('AngleViaPoint',%d,%d,%d,%d,%f)) ", - Obj->getNameInDocument(),GeoId1,GeoId2,GeoId3,PosId3,ActAngle); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('AngleViaPoint',%d,%d,%d,%d,%f)) ", + Obj,GeoId1,GeoId2,GeoId3,PosId3,ActAngle); if (bothexternal || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - Obj->getNameInDocument(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + Obj,ConStr.size()-1,"False"); finishDistanceConstraint(this, Obj,false); } else @@ -6706,8 +6630,8 @@ void CmdSketcherConstrainEqual::activated(int iMsg) // undo command open openCommand("add equality constraint"); for (int i=0; i < int(ids.size()-1); i++) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", - selection[0].getFeatName(),ids[i],ids[i+1]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", + selection[0].getObject(),ids[i],ids[i+1]); } // finish the transaction and update commitCommand(); @@ -6740,8 +6664,8 @@ void CmdSketcherConstrainEqual::applyConstraint(std::vector &selSeq, // undo command open openCommand("add equality constraint"); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", - Obj->getNameInDocument(), GeoId1, GeoId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", + Obj, GeoId1, GeoId2); // finish the transaction and update commitCommand(); tryAutoRecompute(Obj); @@ -6852,9 +6776,8 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) // undo command open openCommand("add symmetric constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,Sketcher::start,GeoId1,Sketcher::end,GeoId2,PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,Sketcher::start,GeoId1,Sketcher::end,GeoId2,PosId2); // finish the transaction and update commitCommand(); @@ -6902,9 +6825,8 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) // undo command open openCommand("add symmetric constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,GeoId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,GeoId3); // finish the transaction and update commitCommand(); @@ -6918,9 +6840,8 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) else if (isVertex(GeoId3,PosId3)) { // undo command open openCommand("add symmetric constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,GeoId3,PosId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,GeoId3,PosId3); // finish the transaction and update commitCommand(); @@ -6987,9 +6908,8 @@ void CmdSketcherConstrainSymmetric::applyConstraint(std::vector &selS // undo command open openCommand("add symmetric constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,GeoId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,GeoId3); // finish the transaction and update commitCommand(); @@ -7022,9 +6942,8 @@ void CmdSketcherConstrainSymmetric::applyConstraint(std::vector &selS // undo command open openCommand("add symmetric constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d,%d)) ", - Obj->getNameInDocument(),GeoId1,PosId1,GeoId2,PosId2,GeoId3,PosId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Symmetric',%d,%d,%d,%d,%d,%d)) ", + Obj,GeoId1,PosId1,GeoId2,PosId2,GeoId3,PosId3); // finish the transaction and update commitCommand(); @@ -7152,24 +7071,21 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg) openCommand("add Snell's law constraint"); if (! IsPointAlreadyOnCurve(GeoId2,GeoId1,PosId1,Obj)) - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2); if (! IsPointAlreadyOnCurve(GeoId3,GeoId1,PosId1,Obj)) - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId3); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId3); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('SnellsLaw',%d,%d,%d,%d,%d,%.12f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,GeoId3,n2divn1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('SnellsLaw',%d,%d,%d,%d,%d,%.12f)) ", + selection[0].getObject(),GeoId1,PosId1,GeoId2,PosId2,GeoId3,n2divn1); /*if (allexternal || constraintCreationMode==Reference) { // it is a constraint on a external line, make it non-driving const std::vector &ConStr = Obj->Constraints.getValues(); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - selection[0].getFeatName(),ConStr.size()-1,"False"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", + selection[0].getObject(),ConStr.size()-1,"False"); }*/ commitCommand(); @@ -7354,12 +7270,12 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(pointids.size()>=1) { if(!focus1) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus1',%d,%d,%d)) ", - selection[0].getFeatName(),pointids[0],Sketcher::start,ellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus1',%d,%d,%d)) ", + selection[0].getObject(),pointids[0],Sketcher::start,ellipseids[0]); } else if(!focus2) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", - selection[0].getFeatName(),pointids[0],Sketcher::start,ellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", + selection[0].getObject(),pointids[0],Sketcher::start,ellipseids[0]); focus2=true; } else @@ -7369,8 +7285,8 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(pointids.size()==2) { if(!focus2) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", - selection[0].getFeatName(),pointids[1],Sketcher::start,ellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", + selection[0].getObject(),pointids[1],Sketcher::start,ellipseids[0]); } else extra_elements=true; @@ -7379,23 +7295,23 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(lineids.size()>=1) { if(!major) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMajorDiameter',%d,%d)) ", - selection[0].getFeatName(),lineids[0],ellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMajorDiameter',%d,%d)) ", + selection[0].getObject(),lineids[0],ellipseids[0]); const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); - if(!geo->Construction) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),lineids[0]); + if(!geo->Construction) + FCMD_OBJ_CMD2("toggleConstruction(%d) ",selection[0].getObject(),lineids[0]); } else if(!minor) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", - selection[0].getFeatName(),lineids[0],ellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", + selection[0].getObject(),lineids[0],ellipseids[0]); const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); if(!geo->Construction) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),lineids[0]); + FCMD_OBJ_CMD2("toggleConstruction(%d) ",selection[0].getObject(),lineids[0]); minor=true; } @@ -7405,13 +7321,13 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(lineids.size()==2) { if(!minor){ - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", - selection[0].getFeatName(),lineids[1],ellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", + selection[0].getObject(),lineids[1],ellipseids[0]); const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[1])); if(!geo->Construction) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),lineids[1]); + FCMD_OBJ_CMD2("toggleConstruction(%d) ",selection[0].getObject(),lineids[1]); } else extra_elements=true; @@ -7513,12 +7429,12 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(pointids.size()>=1) { if(!focus1) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus1',%d,%d,%d)) ", - selection[0].getFeatName(),pointids[0],Sketcher::start,arcsofellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus1',%d,%d,%d)) ", + selection[0].getObject(),pointids[0],Sketcher::start,arcsofellipseids[0]); } else if(!focus2) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", - selection[0].getFeatName(),pointids[0],Sketcher::start,arcsofellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", + selection[0].getObject(),pointids[0],Sketcher::start,arcsofellipseids[0]); focus2=true; } else @@ -7528,8 +7444,8 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(pointids.size()==2) { if(!focus2) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", - selection[0].getFeatName(),pointids[1],Sketcher::start,arcsofellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", + selection[0].getObject(),pointids[1],Sketcher::start,arcsofellipseids[0]); } else extra_elements=true; @@ -7538,23 +7454,23 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(lineids.size()>=1) { if(!major) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMajorDiameter',%d,%d)) ", - selection[0].getFeatName(),lineids[0],arcsofellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMajorDiameter',%d,%d)) ", + selection[0].getObject(),lineids[0],arcsofellipseids[0]); const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); if(!geo->Construction) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),lineids[0]); + FCMD_OBJ_CMD2("toggleConstruction(%d) ",selection[0].getObject(),lineids[0]); } else if(!minor) { - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", - selection[0].getFeatName(),lineids[0],arcsofellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", + selection[0].getObject(),lineids[0],arcsofellipseids[0]); const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); if(!geo->Construction) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),lineids[0]); + FCMD_OBJ_CMD2("toggleConstruction(%d) ",selection[0].getObject(),lineids[0]); minor=true; } @@ -7564,13 +7480,13 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) if(lineids.size()==2) { if(!minor){ - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", - selection[0].getFeatName(),lineids[1],arcsofellipseids[0]); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", + selection[0].getObject(),lineids[1],arcsofellipseids[0]); const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[1])); if(!geo->Construction) - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),lineids[1]); + FCMD_OBJ_CMD2("toggleConstruction(%d) ",selection[0].getObject(),lineids[1]); } else extra_elements=true; @@ -7706,7 +7622,7 @@ void CmdSketcherToggleDrivingConstraint::activated(int iMsg) int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(*it); try { // issue the actual commands to toggle - doCommand(Doc,"App.ActiveDocument.%s.toggleDriving(%d) ",selection[0].getFeatName(),ConstrId); + FCMD_OBJ_CMD2("toggleDriving(%d) ",selection[0].getObject(),ConstrId); } catch(const Base::Exception&) { successful--; @@ -7787,7 +7703,7 @@ void CmdSketcherToggleActiveConstraint::activated(int iMsg) int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(*it); try { // issue the actual commands to toggle - doCommand(Doc,"App.ActiveDocument.%s.toggleActive(%d) ",selection[0].getFeatName(),ConstrId); + FCMD_OBJ_CMD2("toggleActive(%d) ",selection[0].getObject(),ConstrId); } catch(const Base::Exception&) { successful--; diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 31ad52c730..f02fba16af 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -349,8 +349,8 @@ public: try { Gui::Command::openCommand("Add sketch line"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)),%s)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addGeometry(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)),%s)", + sketchgui->getObject(), EditCurve[0].x,EditCurve[0].y,EditCurve[1].x,EditCurve[1].y, geometryCreationMode==Construction?"True":"False"); @@ -570,7 +570,7 @@ public: "geoList.append(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))\n" "geoList.append(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))\n" "geoList.append(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))\n" - "App.ActiveDocument.%s.addGeometry(geoList,%s)\n" + "%s.addGeometry(geoList,%s)\n" "conList = []\n" "conList.append(Sketcher.Constraint('Coincident',%i,2,%i,1))\n" "conList.append(Sketcher.Constraint('Coincident',%i,2,%i,1))\n" @@ -580,12 +580,12 @@ public: "conList.append(Sketcher.Constraint('Horizontal',%i))\n" "conList.append(Sketcher.Constraint('Vertical',%i))\n" "conList.append(Sketcher.Constraint('Vertical',%i))\n" - "App.ActiveDocument.%s.addConstraint(conList)\n", + "%s.addConstraint(conList)\n", EditCurve[0].x,EditCurve[0].y,EditCurve[1].x,EditCurve[1].y, // line 1 EditCurve[1].x,EditCurve[1].y,EditCurve[2].x,EditCurve[2].y, // line 2 EditCurve[2].x,EditCurve[2].y,EditCurve[3].x,EditCurve[3].y, // line 3 EditCurve[3].x,EditCurve[3].y,EditCurve[0].x,EditCurve[0].y, // line 4 - sketchgui->getObject()->getNameInDocument(), // the sketch + Gui::Command::getObjectCmd(sketchgui->getObject()).c_str(), // the sketch geometryCreationMode==Construction?"True":"False", // geometry as construction or not firstCurve,firstCurve+1, // coincident1 firstCurve+1,firstCurve+2, // coincident2 @@ -595,7 +595,7 @@ public: firstCurve+2, // horizontal2 firstCurve+1, // vertical1 firstCurve+3, // vertical2 - sketchgui->getObject()->getNameInDocument()); // the sketch + Gui::Command::getObjectCmd(sketchgui->getObject()).c_str()); // the sketch Gui::Command::commitCommand(); } @@ -1092,9 +1092,8 @@ public: try { // open the transaction Gui::Command::openCommand("Add line to sketch wire"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)),%s)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addGeometry(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)),%s)", + sketchgui->getObject(), EditCurve[0].x,EditCurve[0].y,EditCurve[1].x,EditCurve[1].y, geometryCreationMode==Construction?"True":"False"); } @@ -1114,10 +1113,9 @@ public: try { Gui::Command::openCommand("Add arc to sketch wire"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.ArcOfCircle" + FCMD_OBJ_CMD2("addGeometry(Part.ArcOfCircle" "(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%f,%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), CenterPoint.x, CenterPoint.y, std::abs(arcRadius), std::min(startAngle,endAngle), std::max(startAngle,endAngle), geometryCreationMode==Construction?"True":"False"); @@ -1147,9 +1145,8 @@ public: TransitionMode == TRANSITION_MODE_Perpendicular_R) constrType = "Perpendicular"; } - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('%s',%i,%i,%i,%i)) ", - sketchgui->getObject()->getNameInDocument(), constrType.c_str(), + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('%s',%i,%i,%i,%i)) ", + sketchgui->getObject(), constrType.c_str(), previousCurve, previousPosId, lastCurve, lastStartPosId); if(SnapMode == SNAP_MODE_45Degree && Mode != STATUS_Close) { @@ -1159,16 +1156,14 @@ public: // #3974: if in radians, the printf %f defaults to six decimals, which leads to loss of precision double arcAngle = abs(round( (endAngle - startAngle) / (M_PI/4)) * 45); // in degrees - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%i,App.Units.Quantity('%f deg'))) ", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%i,App.Units.Quantity('%f deg'))) ", + sketchgui->getObject(), lastCurve, arcAngle); } if (Mode == STATUS_Close) { // close the loop by constrain to the first curve point - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) ", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) ", + sketchgui->getObject(), lastCurve,lastEndPosId,firstCurve,firstPosId); } Gui::Command::commitCommand(); @@ -1605,11 +1600,10 @@ public: try { Gui::Command::openCommand("Add sketch arc"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.ArcOfCircle" + FCMD_OBJ_CMD2("addGeometry(Part.ArcOfCircle" "(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f)," "%f,%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), CenterPoint.x, CenterPoint.y, sqrt(rx*rx + ry*ry), startAngle, endAngle, geometryCreationMode==Construction?"True":"False"); //arcAngle > 0 ? 0 : 1); @@ -1917,11 +1911,10 @@ public: try { Gui::Command::openCommand("Add sketch arc"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.ArcOfCircle" + FCMD_OBJ_CMD2("addGeometry(Part.ArcOfCircle" "(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f)," "%f,%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), CenterPoint.x, CenterPoint.y, radius, startAngle, endAngle, geometryCreationMode==Construction?"True":"False"); @@ -2229,10 +2222,9 @@ public: try { Gui::Command::openCommand("Add sketch circle"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.Circle" + FCMD_OBJ_CMD2("addGeometry(Part.Circle" "(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), EditCurve[0].x, EditCurve[0].y, sqrt(rx*rx + ry*ry), geometryCreationMode==Construction?"True":"False"); @@ -3031,10 +3023,9 @@ private: try { Gui::Command::openCommand("Add sketch ellipse"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.Ellipse" + FCMD_OBJ_CMD2("addGeometry(Part.Ellipse" "(App.Vector(%f,%f,0),App.Vector(%f,%f,0),App.Vector(%f,%f,0)),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), periapsis.x, periapsis.y, positiveB.x, positiveB.y, centroid.x, centroid.y, @@ -3042,9 +3033,8 @@ private: currentgeoid++; - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + sketchgui->getObject(), currentgeoid); } catch (const Base::Exception& e) { @@ -3446,11 +3436,10 @@ public: try { Gui::Command::openCommand("Add sketch arc of ellipse"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.ArcOfEllipse" + FCMD_OBJ_CMD2("addGeometry(Part.ArcOfEllipse" "(Part.Ellipse(App.Vector(%f,%f,0),App.Vector(%f,%f,0),App.Vector(%f,%f,0))," "%f,%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), majAxisPoint.x, majAxisPoint.y, minAxisPoint.x, minAxisPoint.y, centerPoint.x, centerPoint.y, @@ -3459,9 +3448,8 @@ public: currentgeoid++; - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + sketchgui->getObject(), currentgeoid); } catch (const Base::Exception& e) { @@ -3827,11 +3815,10 @@ public: //Add arc of hyperbola, point and constrain point as focus2. We add focus2 for it to balance //the intrinsic focus1, in order to balance out the intrinsic invisible focus1 when AOE is //dragged by its center - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.ArcOfHyperbola" + FCMD_OBJ_CMD2("addGeometry(Part.ArcOfHyperbola" "(Part.Hyperbola(App.Vector(%f,%f,0),App.Vector(%f,%f,0),App.Vector(%f,%f,0))," "%f,%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), majAxisPoint.x, majAxisPoint.y, minAxisPoint.x, minAxisPoint.y, centerPoint.x, centerPoint.y, @@ -3840,9 +3827,8 @@ public: currentgeoid++; - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + sketchgui->getObject(), currentgeoid); } @@ -4174,11 +4160,10 @@ public: Gui::Command::openCommand("Add sketch arc of Parabola"); //Add arc of parabola - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.ArcOfParabola" + FCMD_OBJ_CMD2("addGeometry(Part.ArcOfParabola" "(Part.Parabola(App.Vector(%f,%f,0),App.Vector(%f,%f,0),App.Vector(0,0,1))," "%f,%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), focusPoint.x, focusPoint.y, axisPoint.x, axisPoint.y, startAngle, endAngle, @@ -4186,9 +4171,8 @@ public: currentgeoid++; - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + sketchgui->getObject(), currentgeoid); } @@ -4544,8 +4528,8 @@ public: Gui::Command::openCommand("Add Pole circle"); //Add pole - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),10),True)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addGeometry(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),10),True)", + sketchgui->getObject(), EditCurve[0].x,EditCurve[0].y); } @@ -4627,17 +4611,17 @@ public: guess = normalize(guess); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),10),True)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addGeometry(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),10),True)", + sketchgui->getObject(), EditCurve[EditCurve.size()-1].x,EditCurve[EditCurve.size()-1].y); if(EditCurve.size() == 2) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", - sketchgui->getObject()->getNameInDocument(), FirstPoleGeoId, guess ); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", + sketchgui->getObject(), FirstPoleGeoId, guess ); } - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", - sketchgui->getObject()->getNameInDocument(), FirstPoleGeoId, FirstPoleGeoId+ EditCurve.size()-1); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Equal',%d,%d)) ", + sketchgui->getObject(), FirstPoleGeoId, FirstPoleGeoId+ EditCurve.size()-1); } catch (const Base::Exception& e) { @@ -4699,21 +4683,19 @@ public: //Gui::Command::openCommand("Add B-spline curve"); - /*Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.BSplineCurve" + /*FCMD_OBJ_CMD2("addGeometry(Part.BSplineCurve" "(%s,%s)," "%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), controlpoints.c_str(), ConstrMethod == 0 ?"False":"True", geometryCreationMode==Construction?"True":"False"); */ // {"poles", "mults", "knots", "periodic", "degree", "weights", "CheckRational", NULL}; - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.BSplineCurve" + FCMD_OBJ_CMD2("addGeometry(Part.BSplineCurve" "(%s,None,None,%s,3,None,False)," "%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), controlpoints.c_str(), ConstrMethod == 0 ?"False":"True", geometryCreationMode==Construction?"True":"False"); @@ -4750,14 +4732,13 @@ public: << "," << Sketcher::mid << "," << currentgeoid << "," << i << "))\n"; } - cstream << "App.ActiveDocument."<< sketchgui->getObject()->getNameInDocument() << ".addConstraint(conList)\n"; + cstream << Gui::Command::getObjectCmd(sketchgui->getObject()) << ".addConstraint(conList)\n"; Gui::Command::doCommand(Gui::Command::Doc, cstream.str().c_str()); // for showing the knots on creation - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + sketchgui->getObject(), currentgeoid); } @@ -5210,10 +5191,9 @@ public: try { Gui::Command::openCommand("Add sketch circle"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.Circle" + FCMD_OBJ_CMD2("addGeometry(Part.Circle" "(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%s)", - sketchgui->getObject()->getNameInDocument(), + sketchgui->getObject(), CenterPoint.x, CenterPoint.y, radius, geometryCreationMode==Construction?"True":"False"); @@ -5479,8 +5459,8 @@ public: try { Gui::Command::openCommand("Add sketch point"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addGeometry(Part.Point(App.Vector(%f,%f,0)))", + sketchgui->getObject(), EditPoint.x,EditPoint.y); Gui::Command::commitCommand(); @@ -5764,14 +5744,13 @@ public: // create fillet at point try { Gui::Command::openCommand("Create fillet"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.fillet(%d,%d,%f)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("fillet(%d,%d,%f)", + sketchgui->getObject(), GeoId, PosId, radius); if(construction) { - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.toggleConstruction(%d) ", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("toggleConstruction(%d) ", + sketchgui->getObject(), currentgeoid+1); } @@ -5845,8 +5824,8 @@ public: // create fillet between lines try { Gui::Command::openCommand("Create fillet"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.fillet(%d,%d,App.Vector(%f,%f,0),App.Vector(%f,%f,0),%f)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("fillet(%d,%d,App.Vector(%f,%f,0),App.Vector(%f,%f,0),%f)", + sketchgui->getObject(), firstCurve, secondCurve, firstPos.x, firstPos.y, secondPos.x, secondPos.y, radius); @@ -5872,9 +5851,8 @@ public: tryAutoRecompute(static_cast(sketchgui->getObject())); if(construction) { - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.toggleConstruction(%d) ", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("toggleConstruction(%d) ", + sketchgui->getObject(), currentgeoid+1); } @@ -6041,8 +6019,8 @@ public: geom->getTypeId() == Part::GeomEllipse::getClassTypeId()) { try { Gui::Command::openCommand("Trim edge"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.trim(%d,App.Vector(%f,%f,0))", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("trim(%d,App.Vector(%f,%f,0))", + sketchgui->getObject(), GeoId, onSketchPos.x, onSketchPos.y); Gui::Command::commitCommand(); tryAutoRecompute(static_cast(sketchgui->getObject())); @@ -6353,9 +6331,8 @@ public: } else if (Mode == STATUS_SEEK_Second) { try { Gui::Command::openCommand("Extend edge"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.extend(%d, %f, %d)\n", // GeoId, increment, PointPos - sketchgui->getObject()->getNameInDocument(), BaseGeoId, Increment, + FCMD_OBJ_CMD2("extend(%d, %f, %d)\n", // GeoId, increment, PointPos + sketchgui->getObject(), BaseGeoId, Increment, ExtendFromStart ? Sketcher::start : Sketcher::end); Gui::Command::commitCommand(); @@ -6612,8 +6589,8 @@ public: (subName.size() > 4 && subName.substr(0,4) == "Face")) { try { Gui::Command::openCommand("Add external geometry"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addExternal(\"%s\",\"%s\")", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("App.ActiveDocument.%s.addExternal(\"%s\",\"%s\")", + sketchgui->getObject(), msg.pObjectName, msg.pSubName); Gui::Command::commitCommand(); @@ -6834,8 +6811,8 @@ static const char *cursor_carboncopy[]={ try { Gui::Command::openCommand("Add carbon copy"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.carbonCopy(\"%s\",%s)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("carbonCopy(\"%s\",%s)", + sketchgui->getObject(), msg.pObjectName, geometryCreationMode==Construction?"True":"False"); Gui::Command::commitCommand(); @@ -7061,7 +7038,7 @@ public: "geoList.append(Part.ArcOfCircle(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%f,%f))\n" "geoList.append(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))\n" "geoList.append(Part.LineSegment(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))\n" - "App.ActiveDocument.%s.addGeometry(geoList,%s)\n" + "%s.addGeometry(geoList,%s)\n" "conList = []\n" "conList.append(Sketcher.Constraint('Tangent',%i,1,%i,1))\n" "conList.append(Sketcher.Constraint('Tangent',%i,2,%i,1))\n" @@ -7069,8 +7046,8 @@ public: "conList.append(Sketcher.Constraint('Tangent',%i,2,%i,2))\n" "conList.append(Sketcher.Constraint('%s',%i))\n" "conList.append(Sketcher.Constraint('Equal',%i,%i))\n" - "App.ActiveDocument.%s.addConstraint(conList)\n", - StartPos.x,StartPos.y, // center of the arc1 + "%s.addConstraint(conList)\n", + StartPos.x,StartPos.y, // center of the arc1 fabs(r), // radius arc1 start,end, // start and end angle of arc1 StartPos.x+lx,StartPos.y+ly, // center of the arc2 @@ -7078,15 +7055,15 @@ public: end,start, // start and end angle of arc2 EditCurve[16].x,EditCurve[16].y,EditCurve[17].x,EditCurve[17].y, // line1 EditCurve[0].x,EditCurve[0].y,EditCurve[34].x,EditCurve[34].y, // line2 - sketchgui->getObject()->getNameInDocument(), // the sketch - geometryCreationMode==Construction?"True":"False", // geometry as construction or not + Gui::Command::getObjectCmd(sketchgui->getObject()).c_str(), // the sketch + geometryCreationMode==Construction?"True":"False", // geometry as construction or not firstCurve,firstCurve+3, // tangent1 firstCurve,firstCurve+2, // tangent2 firstCurve+2,firstCurve+1, // tangent3 firstCurve+3,firstCurve+1, // tangent4 (fabs(lx)>fabs(ly))?"Horizontal":"Vertical", firstCurve+2, // vertical or horizontal constraint firstCurve,firstCurve+1, // equal constraint - sketchgui->getObject()->getNameInDocument()); // the sketch + Gui::Command::getObjectCmd(sketchgui->getObject()).c_str()); // the sketch Gui::Command::commitCommand(); @@ -7312,8 +7289,8 @@ public: try { Gui::Command::doCommand(Gui::Command::Doc, "import ProfileLib.RegularPolygon\n" - "ProfileLib.RegularPolygon.makeRegularPolygon('%s',%i,App.Vector(%f,%f,0),App.Vector(%f,%f,0),%s)", - sketchgui->getObject()->getNameInDocument(), + "ProfileLib.RegularPolygon.makeRegularPolygon(%s,%i,App.Vector(%f,%f,0),App.Vector(%f,%f,0),%s)", + Gui::Command::getObjectCmd(sketchgui->getObject()).c_str(), Corners, StartPos.x,StartPos.y,EditCurve[0].x,EditCurve[0].y, geometryCreationMode==Construction?"True":"False"); diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index c14c335719..335bff971f 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -381,20 +381,18 @@ void CmdSketcherConvertToNURB::activated(int iMsg) int GeoId = std::atoi(SubNames[i].substr(4,4000).c_str()) - 1; - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.convertToNURBS(%d) ", - selection[0].getFeatName(),GeoId); - + FCMD_OBJ_CMD2("convertToNURBS(%d) ", + selection[0].getObject(),GeoId); + nurbsized = true; } else if (SubNames[i].size() > 12 && SubNames[i].substr(0,12) == "ExternalEdge") { int GeoId = - (std::atoi(SubNames[i].substr(12,4000).c_str()) + 2); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.convertToNURBS(%d) ", - selection[0].getFeatName(),GeoId); - + FCMD_OBJ_CMD2("convertToNURBS(%d) ", + selection[0].getObject(),GeoId); + nurbsized = true; } @@ -465,15 +463,12 @@ void CmdSketcherIncreaseDegree::activated(int iMsg) 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); - + FCMD_OBJ_CMD2("increaseBSplineDegree(%d) ", + selection[0].getObject(),GeoId); + // add new control points - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - selection[0].getFeatName(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + selection[0].getObject(), GeoId); } else { @@ -569,9 +564,8 @@ void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg) notaknot = false; try { - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.modifyBSplineKnotMultiplicity(%d,%d,%d) ", - selection[0].getFeatName(),(*it)->Second, (*it)->InternalAlignmentIndex + 1, 1); + FCMD_OBJ_CMD2("modifyBSplineKnotMultiplicity(%d,%d,%d) ", + selection[0].getObject(),(*it)->Second, (*it)->InternalAlignmentIndex + 1, 1); applied = true; @@ -629,9 +623,8 @@ void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg) if(ngfound) { try { // add internalalignment for new pole - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - selection[0].getFeatName(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + selection[0].getObject(), ngeoid); } catch (const Base::Exception& e) { @@ -730,10 +723,9 @@ void CmdSketcherDecreaseKnotMultiplicity::activated(int iMsg) notaknot = false; try { - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.modifyBSplineKnotMultiplicity(%d,%d,%d) ", - selection[0].getFeatName(),(*it)->Second, (*it)->InternalAlignmentIndex + 1, -1); - + FCMD_OBJ_CMD2("modifyBSplineKnotMultiplicity(%d,%d,%d) ", + selection[0].getObject(),(*it)->Second, (*it)->InternalAlignmentIndex + 1, -1); + applied = true; // Warning: GeoId list might have changed as the consequence of deleting pole circles and @@ -777,9 +769,8 @@ void CmdSketcherDecreaseKnotMultiplicity::activated(int iMsg) if(ngfound) { try { // add internalalignment for new pole - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - selection[0].getFeatName(), + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", + selection[0].getObject(), ngeoid); } catch (const Base::Exception& e) { diff --git a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp index 7cd2cf4ecd..9598dbbff0 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp @@ -169,16 +169,14 @@ void CmdSketcherCloseShape::activated(int iMsg) 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); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,Sketcher::end,GeoId2,Sketcher::start); } } // Close Last Edge with First Edge - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", - selection[0].getFeatName(),GeoIdLast,Sketcher::end,GeoIdFirst,Sketcher::start); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoIdLast,Sketcher::end,GeoIdFirst,Sketcher::start); // finish the transaction and update commitCommand(); @@ -259,9 +257,8 @@ void CmdSketcherConnect::activated(int iMsg) 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); + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + selection[0].getObject(),GeoId1,Sketcher::end,GeoId2,Sketcher::start); } } @@ -875,18 +872,12 @@ void CmdSketcherRestoreInternalAlignmentGeometry::activated(int iMsg) try { Gui::Command::openCommand("Exposing Internal Geometry"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.exposeInternalGeometry(%d)", - Obj->getNameInDocument(), - GeoId); + FCMD_OBJ_CMD2("exposeInternalGeometry(%d)", Obj, GeoId); int aftergeoid = Obj->getHighestCurveIndex(); if(aftergeoid == currentgeoid) { // if we did not expose anything, deleteunused - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.deleteUnusedInternalGeometry(%d)", - Obj->getNameInDocument(), - GeoId); + FCMD_OBJ_CMD2("deleteUnusedInternalGeometry(%d)", Obj, GeoId); } } catch (const Base::Exception& e) { @@ -1085,10 +1076,7 @@ void CmdSketcherSymmetry::activated(int iMsg) Gui::Command::openCommand("Create Symmetric geometry"); try{ - Gui::Command::doCommand( - Gui::Command::Doc, "App.ActiveDocument.%s.addSymmetric(%s,%d,%d)", - Obj->getNameInDocument(), geoIdList.c_str(), LastGeoId, LastPointPos - ); + FCMD_OBJ_CMD2("addSymmetric(%s,%d,%d)", Obj, geoIdList.c_str(), LastGeoId, LastPointPos); Gui::Command::commitCommand(); } @@ -1232,10 +1220,8 @@ static const char *cursor_createcopy[]={ try{ if( Op != SketcherCopy::Move) { - - Gui::Command::doCommand( - Gui::Command::Doc, "App.ActiveDocument.%s.addCopy(%s,App.Vector(%f,%f,0),%s)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addCopy(%s,App.Vector(%f,%f,0),%s)", + sketchgui->getObject(), geoIdList.c_str(), vector.x, vector.y, (Op == SketcherCopy::Clone?"True":"False")); } @@ -1758,9 +1744,8 @@ static const char *cursor_createrectangulararray[]={ Gui::Command::openCommand("Create copy of geometry"); try { - Gui::Command::doCommand( - Gui::Command::Doc, "App.ActiveDocument.%s.addRectangularArray(%s, App.Vector(%f,%f,0),%s,%d,%d,%s,%f)", - sketchgui->getObject()->getNameInDocument(), + FCMD_OBJ_CMD2("addRectangularArray(%s, App.Vector(%f,%f,0),%s,%d,%d,%s,%f)", + sketchgui->getObject(), geoIdList.c_str(), vector.x, vector.y, (Clone?"True":"False"), Cols, Rows, @@ -1981,9 +1966,7 @@ void CmdSketcherDeleteAllGeometry::activated(int iMsg) try { Gui::Command::openCommand("Delete All Geometry"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.deleteAllGeometry()", - Obj->getNameInDocument()); + FCMD_OBJ_CMD2("deleteAllGeometry()", Obj); Gui::Command::commitCommand(); } @@ -2004,7 +1987,6 @@ void CmdSketcherDeleteAllGeometry::activated(int iMsg) // do nothing return; } - } bool CmdSketcherDeleteAllGeometry::isActive(void) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index a30d1b765e..1bafb31800 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -407,8 +407,8 @@ void DrawSketchHandler::createAutoConstraints(const std::vector 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() + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Coincident',%i,%i,%i,%i)) " + ,sketchgui->getObject() ,geoId1, posId1, it->GeoId, it->PosId ); } break; @@ -421,23 +421,23 @@ void DrawSketchHandler::createAutoConstraints(const std::vector std::swap(posId1,posId2); } - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('PointOnObject',%i,%i,%i)) " - ,sketchgui->getObject()->getNameInDocument() + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('PointOnObject',%i,%i,%i)) " + ,sketchgui->getObject() ,geoId1, posId1, geoId2 ); } break; case Sketcher::Horizontal: { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Horizontal',%i)) " - ,sketchgui->getObject()->getNameInDocument() + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Horizontal',%i)) " + ,sketchgui->getObject() ,geoId1 ); } break; case Sketcher::Vertical: { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Vertical',%i)) " - ,sketchgui->getObject()->getNameInDocument() + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Vertical',%i)) " + ,sketchgui->getObject() ,geoId1 ); @@ -496,8 +496,8 @@ void DrawSketchHandler::createAutoConstraints(const std::vector } } - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%i, %i)) " - ,sketchgui->getObject()->getNameInDocument() + FCMD_OBJ_CMD2("addConstraint(Sketcher.Constraint('Tangent',%i, %i)) " + ,sketchgui->getObject() ,geoId1, it->GeoId ); } break; diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index a171c43bef..9d8541707b 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -137,6 +137,8 @@ void EditDatumDialog::exec(bool atCursor) if (atCursor) dlg.setGeometry(QCursor::pos().x() - dlg.geometry().width() / 2, QCursor::pos().y(), dlg.geometry().width(), dlg.geometry().height()); + Gui::Command::openCommand("Modify sketch constraints"); + if (dlg.exec()) { Base::Quantity newQuant = ui_ins_datum.labelEdit->value(); if (newQuant.isQuantity() || (Constr->Type == Sketcher::SnellsLaw && newQuant.isDimensionless())) { @@ -146,22 +148,21 @@ void EditDatumDialog::exec(bool atCursor) double newDatum = newQuant.getValue(); try { - Gui::Command::openCommand("Modify sketch constraints"); if (Constr->isDriving) { if (ui_ins_datum.labelEdit->hasExpression()) ui_ins_datum.labelEdit->apply(); else - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,App.Units.Quantity('%f %s'))", - sketch->getNameInDocument(), + FCMD_OBJ_CMD2("setDatum(%i,App.Units.Quantity('%f %s'))", + sketch, ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8()); } QString constraintName = ui_ins_datum.name->text().trimmed(); if (Base::Tools::toStdString(constraintName) != sketch->Constraints[ConstrNbr]->Name) { std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - sketch->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + sketch, ConstrNbr, escapedstr.c_str()); } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index c13c41d7ef..8f29e416a5 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -603,14 +603,14 @@ void ConstraintView::swapNamedOfSelectedItems() std::string tmpname = ss.str(); Gui::Command::openCommand("Swap constraint names"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - item1->sketch->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + item1->sketch, item1->ConstraintNbr, tmpname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - item2->sketch->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + item2->sketch, item2->ConstraintNbr, escapedstr1.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - item1->sketch->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + item1->sketch, item1->ConstraintNbr, escapedstr2.c_str()); Gui::Command::commitCommand(); } @@ -831,8 +831,8 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemChanged(QListWidgetIte Gui::Command::openCommand("Rename sketch constraint"); try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.renameConstraint(%d, u'%s')", - sketch->getNameInDocument(), + FCMD_OBJ_CMD2("renameConstraint(%d, u'%s')", + sketch, it->ConstraintNbr, escapedstr.c_str()); Gui::Command::commitCommand(); } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index d8b418a57d..1db7dea438 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -118,6 +118,8 @@ #include "TaskSketcherValidation.h" #include "CommandConstraints.h" +FC_LOG_LEVEL_INIT("Sketch",true,true); + // The first is used to point at a SoDatumLabel for some // constraints, and at a SoMaterial for others... #define CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL 0 @@ -280,7 +282,8 @@ PROPERTY_SOURCE(SketcherGui::ViewProviderSketch, PartGui::ViewProvider2DObject) ViewProviderSketch::ViewProviderSketch() - : edit(0), + : SelectionObserver(false), + edit(0), Mode(STATUS_NONE), visibleInformationChanged(true), combrepscalehyst(0), @@ -408,9 +411,10 @@ void ViewProviderSketch::deactivateHandler() void ViewProviderSketch::purgeHandler(void) { deactivateHandler(); + Gui::Selection().clearSelection(); // ensure that we are in sketch only selection mode - Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView(); + Gui::MDIView *mdi = Gui::Application::Instance->editDocument()->getActiveView(); Gui::View3DInventorViewer *viewer; viewer = static_cast(mdi)->getViewer(); @@ -547,13 +551,22 @@ void ViewProviderSketch::getProjectingLine(const SbVec2s& pnt, const Gui::View3D vol.projectPointToLine(SbVec2f(pX,pY), line); } +Base::Placement ViewProviderSketch::getEditingPlacement() const { + auto doc = Gui::Application::Instance->editDocument(); + if(!doc || doc->getInEdit()!=this) + return getSketchObject()->globalPlacement(); + + // TODO: won't work if there is scale. Hmm... what to do... + return Base::Placement(doc->getEditingTransform()); +} + void ViewProviderSketch::getCoordsOnSketchPlane(double &u, double &v,const SbVec3f &point, const SbVec3f &normal) { // Plane form Base::Vector3d R0(0,0,0),RN(0,0,1),RX(1,0,0),RY(0,1,0); // move to position of Sketch - Base::Placement Plz = getSketchObject()->globalPlacement(); + Base::Placement Plz = getEditingPlacement(); R0 = Plz.getPosition() ; Base::Rotation tmp(Plz.getRotation()); tmp.multVec(RN,RN); @@ -579,6 +592,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe const Gui::View3DInventorViewer *viewer) { assert(edit); + App::AutoTransaction comitter; // Calculate 3d point to the mouse position SbLine line; @@ -674,14 +688,12 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe std::stringstream ss; ss << "Vertex" << edit->PreselectPoint + 1; - if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(),ss.str().c_str()) ) { - Gui::Selection().rmvSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(), ss.str().c_str()); +#define SEL_PARAMS editDocName.c_str(),editObjName.c_str(),\ + (editSubName+ss.str()).c_str() + if (Gui::Selection().isSelected(SEL_PARAMS) ) { + Gui::Selection().rmvSelection(SEL_PARAMS); } else { - Gui::Selection().addSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,ss.str().c_str() + Gui::Selection().addSelection2(SEL_PARAMS ,pp->getPoint()[0] ,pp->getPoint()[1] ,pp->getPoint()[2]); @@ -702,15 +714,11 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe ss << "ExternalEdge" << -edit->PreselectCurve - 2; // If edge already selected move from selection - if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(),ss.str().c_str()) ) { - Gui::Selection().rmvSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(), ss.str().c_str()); + if (Gui::Selection().isSelected(SEL_PARAMS) ) { + Gui::Selection().rmvSelection(SEL_PARAMS); } else { // Add edge to the selection - Gui::Selection().addSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,ss.str().c_str() + Gui::Selection().addSelection2(SEL_PARAMS ,pp->getPoint()[0] ,pp->getPoint()[1] ,pp->getPoint()[2]); @@ -732,15 +740,11 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe } // If cross already selected move from selection - if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(),ss.str().c_str()) ) { - Gui::Selection().rmvSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(), ss.str().c_str()); + if (Gui::Selection().isSelected(SEL_PARAMS) ) { + Gui::Selection().rmvSelection(SEL_PARAMS); } else { // Add cross to the selection - Gui::Selection().addSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,ss.str().c_str() + Gui::Selection().addSelection2(SEL_PARAMS ,pp->getPoint()[0] ,pp->getPoint()[1] ,pp->getPoint()[2]); @@ -753,19 +757,17 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe return true; case STATUS_SELECT_Constraint: if (pp) { - for(std::set::iterator it = edit->PreselectConstraintSet.begin(); it != edit->PreselectConstraintSet.end(); ++it) { - std::string constraintName(Sketcher::PropertyConstraintList::getConstraintName(*it)); + auto sels = edit->PreselectConstraintSet; + for(int id : sels) { + std::stringstream ss; + ss << Sketcher::PropertyConstraintList::getConstraintName(id); // If the constraint already selected remove - if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(),constraintName.c_str()) ) { - Gui::Selection().rmvSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument(), constraintName.c_str()); + if (Gui::Selection().isSelected(SEL_PARAMS) ) { + Gui::Selection().rmvSelection(SEL_PARAMS); } else { // Add constraint to current selection - Gui::Selection().addSelection(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,constraintName.c_str() + Gui::Selection().addSelection2(SEL_PARAMS ,pp->getPoint()[0] ,pp->getPoint()[1] ,pp->getPoint()[2]); @@ -783,18 +785,17 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe Sketcher::PointPos PosId; getSketchObject()->getGeoVertexIndex(edit->DragPoint, GeoId, PosId); if (GeoId != Sketcher::Constraint::GeoUndef && PosId != Sketcher::none) { - Gui::Command::openCommand("Drag Point"); + getDocument()->openCommand("Drag Point"); try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.movePoint(%i,%i,App.Vector(%f,%f,0),%i)" - ,getObject()->getNameInDocument() - ,GeoId, PosId, x-xInit, y-yInit, 0 - ); - Gui::Command::commitCommand(); + FCMD_OBJ_CMD2("movePoint(%i,%i,App.Vector(%f,%f,0),%i)" + ,getObject() + ,GeoId, PosId, x-xInit, y-yInit, 0); + getDocument()->commitCommand(); tryAutoRecomputeIfNotSolve(getSketchObject()); } catch (const Base::Exception& e) { - Gui::Command::abortCommand(); + getDocument()->abortCommand(); Base::Console().Error("Drag point: %s\n", e.what()); } } @@ -816,18 +817,17 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()|| geo->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()|| geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - Gui::Command::openCommand("Drag Curve"); + getDocument()->openCommand("Drag Curve"); try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.movePoint(%i,%i,App.Vector(%f,%f,0),%i)" - ,getObject()->getNameInDocument() - ,edit->DragCurve, Sketcher::none, x-xInit, y-yInit, relative ? 1 : 0 - ); - Gui::Command::commitCommand(); + FCMD_OBJ_CMD2("movePoint(%i,%i,App.Vector(%f,%f,0),%i)" + ,getObject() + ,edit->DragCurve, Sketcher::none, x-xInit, y-yInit, relative ? 1 : 0); + getDocument()->commitCommand(); tryAutoRecomputeIfNotSolve(getSketchObject()); } catch (const Base::Exception& e) { - Gui::Command::abortCommand(); + getDocument()->abortCommand(); Base::Console().Error("Drag curve: %s\n", e.what()); } } @@ -840,14 +840,15 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe return true; case STATUS_SKETCH_DragConstraint: if (edit->DragConstraintSet.empty() == false) { - Gui::Command::openCommand("Drag Constraint"); - for(std::set::iterator it = edit->DragConstraintSet.begin(); - it != edit->DragConstraintSet.end(); ++it) { - moveConstraint(*it, Base::Vector2d(x, y)); + getDocument()->openCommand("Drag Constraint"); + auto idset = edit->DragConstraintSet; + for(int id : idset) { + moveConstraint(id, Base::Vector2d(x, y)); //updateColor(); } edit->PreselectConstraintSet = edit->DragConstraintSet; edit->DragConstraintSet.clear(); + getDocument()->commitCommand(); } Mode = STATUS_NONE; return true; @@ -866,8 +867,9 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe draw(true,false); Mode = STATUS_NONE; return true; - case STATUS_SKETCH_UseHandler: + case STATUS_SKETCH_UseHandler: { return edit->sketchHandler->releaseButton(Base::Vector2d(x,y)); + } case STATUS_NONE: default: return false; @@ -892,9 +894,9 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe } else if (edit->PreselectConstraintSet.empty() != true) { return true; } else { - Gui::MenuItem *geom = new Gui::MenuItem(); - geom->setCommand("Sketcher geoms"); - *geom << "Sketcher_CreatePoint" + Gui::MenuItem geom; + geom.setCommand("Sketcher geoms"); + geom << "Sketcher_CreatePoint" << "Sketcher_CreateArc" << "Sketcher_Create3PointArc" << "Sketcher_CreateCircle" @@ -912,10 +914,10 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe /*<< "Sketcher_CreateDraftLine"*/ << "Separator"; - Gui::Application::Instance->setupContextMenu("View", geom); + Gui::Application::Instance->setupContextMenu("View", &geom); //Create the Context Menu using the Main View Qt Widget QMenu contextMenu(viewer->getGLWidget()); - Gui::MenuManager::getInstance()->setupContextMenu(geom, contextMenu); + Gui::MenuManager::getInstance()->setupContextMenu(&geom, contextMenu); contextMenu.exec(QCursor::pos()); return true; @@ -925,9 +927,9 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe break; case STATUS_SELECT_Edge: { - Gui::MenuItem *geom = new Gui::MenuItem(); - geom->setCommand("Sketcher constraints"); - *geom << "Sketcher_ConstrainVertical" + Gui::MenuItem geom; + geom.setCommand("Sketcher constraints"); + geom << "Sketcher_ConstrainVertical" << "Sketcher_ConstrainHorizontal"; // Gets a selection vector @@ -964,14 +966,14 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe } if (rightClickOnSelectedLine) { - *geom << "Sketcher_ConstrainParallel" + geom << "Sketcher_ConstrainParallel" << "Sketcher_ConstrainPerpendicular"; } - Gui::Application::Instance->setupContextMenu("View", geom); + Gui::Application::Instance->setupContextMenu("View", &geom); //Create the Context Menu using the Main View Qt Widget QMenu contextMenu(viewer->getGLWidget()); - Gui::MenuManager::getInstance()->setupContextMenu(geom, contextMenu); + Gui::MenuManager::getInstance()->setupContextMenu(&geom, contextMenu); contextMenu.exec(QCursor::pos()); return true; @@ -1006,21 +1008,20 @@ void ViewProviderSketch::editDoubleClicked(void) // Find the constraint const std::vector &constrlist = getSketchObject()->Constraints.getValues(); - for(std::set::iterator it = edit->PreselectConstraintSet.begin(); - it != edit->PreselectConstraintSet.end(); ++it) { + auto sels = edit->PreselectConstraintSet; + for(int id : sels) { - Constraint *Constr = constrlist[*it]; + Constraint *Constr = constrlist[id]; // if its the right constraint if (Constr->isDimensional()) { if(!Constr->isDriving) { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", - getObject()->getNameInDocument(),*it,"True"); + FCMD_OBJ_CMD2("setDriving(%i,%s)", getObject(),id,"True"); } // Coin's SoIdleSensor causes problems on some platform while Qt seems to work properly (#0001517) - EditDatumDialog *editDatumDialog = new EditDatumDialog(this, *it); + EditDatumDialog *editDatumDialog = new EditDatumDialog(this, id); QCoreApplication::postEvent(editDatumDialog, new QEvent(QEvent::User)); edit->editDatumDialog = true; // avoid to double handle "ESC" } @@ -1178,9 +1179,9 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor return true; case STATUS_SKETCH_DragConstraint: if (edit->DragConstraintSet.empty() == false) { - for(std::set::iterator it = edit->DragConstraintSet.begin(); - it != edit->DragConstraintSet.end(); ++it) - moveConstraint(*it, Base::Vector2d(x,y)); + auto idset = edit->DragConstraintSet; + for(int id : idset) + moveConstraint(id, Base::Vector2d(x,y)); } return true; case STATUS_SKETCH_UseHandler: @@ -1414,7 +1415,7 @@ Base::Vector3d ViewProviderSketch::seekConstraintPosition(const Base::Vector3d & const SoNode *constraint) { assert(edit); - Gui::MDIView *mdi = this->getViewOfNode(edit->EditRoot); + Gui::MDIView *mdi = Gui::Application::Instance->editViewOfNode(edit->EditRoot); if (!(mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId()))) return Base::Vector3d(0, 0, 0); Gui::View3DInventorViewer *viewer = static_cast(mdi)->getViewer(); @@ -1476,8 +1477,13 @@ void ViewProviderSketch::onSelectionChanged(const Gui::SelectionChanges& msg) { // are we in edit? if (edit) { + // ignore external object + if(msg.ObjName.size() && msg.DocName.size() && msg.DocName!=getObject()->getDocument()->getName()) + return; + bool handled=false; if (Mode == STATUS_SKETCH_UseHandler) { + App::AutoTransaction committer; handled = edit->sketchHandler->onSelectionChanged(msg); } if (handled) @@ -1838,9 +1844,7 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, std::stringstream ss; ss << "Vertex" << PtIndex + 1; bool accepted = - Gui::Selection().setPreselect(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,ss.str().c_str() + Gui::Selection().setPreselect(SEL_PARAMS ,Point->getPoint()[0] ,Point->getPoint()[1] ,Point->getPoint()[2]); @@ -1861,9 +1865,7 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, else // external geometry ss << "ExternalEdge" << -GeoIndex + Sketcher::GeoEnum::RefExt + 1; // convert index start from -3 to 1 bool accepted = - Gui::Selection().setPreselect(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,ss.str().c_str() + Gui::Selection().setPreselect(SEL_PARAMS ,Point->getPoint()[0] ,Point->getPoint()[1] ,Point->getPoint()[2]); @@ -1885,9 +1887,7 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, case 2: ss << "V_Axis" ; break; } bool accepted = - Gui::Selection().setPreselect(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,ss.str().c_str() + Gui::Selection().setPreselect(SEL_PARAMS ,Point->getPoint()[0] ,Point->getPoint()[1] ,Point->getPoint()[2]); @@ -1907,12 +1907,11 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, } else if (constrIndices.empty() == false && constrIndices != edit->PreselectConstraintSet) { // if a constraint is hit bool accepted = true; for(std::set::iterator it = constrIndices.begin(); it != constrIndices.end(); ++it) { - std::string constraintName(Sketcher::PropertyConstraintList::getConstraintName(*it)); + std::stringstream ss; + ss << Sketcher::PropertyConstraintList::getConstraintName(*it); accepted &= - Gui::Selection().setPreselect(getSketchObject()->getDocument()->getName() - ,getSketchObject()->getNameInDocument() - ,constraintName.c_str() + Gui::Selection().setPreselect(SEL_PARAMS ,Point->getPoint()[0] ,Point->getPoint()[1] ,Point->getPoint()[2]); @@ -2031,9 +2030,8 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & Gui::ViewVolumeProjection proj(viewer->getSoRenderManager()->getCamera()->getViewVolume()); Sketcher::SketchObject *sketchObject = getSketchObject(); - App::Document *doc = sketchObject->getDocument(); - Base::Placement Plm = getSketchObject()->globalPlacement(); + Base::Placement Plm = getEditingPlacement(); int intGeoCount = sketchObject->getHighestCurveIndex() + 1; int extGeoCount = sketchObject->getExternalGeometryCount(); @@ -2067,7 +2065,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (polygon.Contains(Base::Vector2d(pnt0.x, pnt0.y))) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } else if ((*it)->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { @@ -2084,19 +2082,19 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (pnt1Inside) { std::stringstream ss; ss << "Vertex" << VertexId; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt2Inside) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if ((pnt1Inside && pnt2Inside) && !touchMode) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } //check if line intersects with polygon else if (touchMode) { @@ -2108,7 +2106,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (!resultList.empty()) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } @@ -2126,7 +2124,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (polygon.Contains(Base::Vector2d(pnt0.x, pnt0.y))) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } int countSegments = 12; if (touchMode) @@ -2160,7 +2158,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(),ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } } else if ((*it)->getTypeId() == Part::GeomEllipse::getClassTypeId()) { @@ -2176,7 +2174,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (polygon.Contains(Base::Vector2d(pnt0.x, pnt0.y))) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } int countSegments = 12; @@ -2211,7 +2209,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(),ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } @@ -2273,26 +2271,26 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } if (pnt0Inside) { std::stringstream ss; ss << "Vertex" << VertexId - 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt1Inside) { std::stringstream ss; ss << "Vertex" << VertexId; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (polygon.Contains(Base::Vector2d(pnt2.x, pnt2.y))) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } else if ((*it)->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { // Check if arc lies inside box selection @@ -2355,25 +2353,25 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } if (pnt0Inside) { std::stringstream ss; ss << "Vertex" << VertexId - 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt1Inside) { std::stringstream ss; ss << "Vertex" << VertexId; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (polygon.Contains(Base::Vector2d(pnt2.x, pnt2.y))) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } else if ((*it)->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { @@ -2439,24 +2437,24 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt0Inside) { std::stringstream ss; ss << "Vertex" << VertexId - 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt1Inside) { std::stringstream ss; ss << "Vertex" << VertexId; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (polygon.Contains(Base::Vector2d(pnt2.x, pnt2.y))) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } @@ -2525,24 +2523,24 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt0Inside) { std::stringstream ss; ss << "Vertex" << VertexId - 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt1Inside) { std::stringstream ss; ss << "Vertex" << VertexId; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (polygon.Contains(Base::Vector2d(pnt2.x, pnt2.y))) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } @@ -2561,13 +2559,13 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (pnt1Inside || (touchMode && pnt2Inside)) { std::stringstream ss; ss << "Vertex" << VertexId; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } if (pnt2Inside || (touchMode && pnt1Inside)) { std::stringstream ss; ss << "Vertex" << VertexId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } // This is a rather approximated approach. No it does not guarantee that the whole curve is boxed, specially @@ -2578,14 +2576,17 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if ((pnt1Inside && pnt2Inside) || (touchMode && (pnt1Inside || pnt2Inside))) { std::stringstream ss; ss << "Edge" << GeoId + 1; - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); + Gui::Selection().addSelection2(SEL_PARAMS); } } } pnt0 = proj(Plm.getPosition()); - if (polygon.Contains(Base::Vector2d(pnt0.x, pnt0.y))) - Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), "RootPoint"); + if (polygon.Contains(Base::Vector2d(pnt0.x, pnt0.y))) { + std::stringstream ss; + ss << "RootPoint"; + Gui::Selection().addSelection2(SEL_PARAMS); + } } void ViewProviderSketch::updateColor(void) @@ -2740,8 +2741,12 @@ void ViewProviderSketch::updateColor(void) else crosscolor[1] = CrossColorV; + int count = std::min(edit->constrGroup->getNumChildren(), getSketchObject()->Constraints.getSize()); + if(getSketchObject()->Constraints.hasInvalidGeometry()) + count = 0; + // colors of the constraints - for (int i=0; i < edit->constrGroup->getNumChildren(); i++) { + for (int i=0; i < count; i++) { SoSeparator *s = static_cast(edit->constrGroup->getChild(i)); // Check Constraint Type @@ -3111,7 +3116,7 @@ void ViewProviderSketch::drawConstraintIcons() SbVec3f pos0(startingpoint.x,startingpoint.y,startingpoint.z); SbVec3f pos1(endpoint.x,endpoint.y,endpoint.z); - Gui::MDIView *mdi = this->getViewOfNode(edit->EditRoot); + Gui::MDIView *mdi = Gui::Application::Instance->editViewOfNode(edit->EditRoot); if (!(mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId()))) return; Gui::View3DInventorViewer *viewer = static_cast(mdi)->getViewer(); @@ -3484,7 +3489,7 @@ void ViewProviderSketch::drawTypicalConstraintIcon(const constrIconQueueItem &i) float ViewProviderSketch::getScaleFactor() { assert(edit); - Gui::MDIView *mdi = this->getViewOfNode(edit->EditRoot); + Gui::MDIView *mdi = Gui::Application::Instance->editViewOfNode(edit->EditRoot); if (mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { Gui::View3DInventorViewer *viewer = static_cast(mdi)->getViewer(); SoCamera* camera = viewer->getSoRenderManager()->getCamera(); @@ -5322,7 +5327,7 @@ void ViewProviderSketch::rebuildConstraintsVisual(void) Base::Vector3d RN(0,0,1); // move to position of Sketch - Base::Placement Plz = getSketchObject()->globalPlacement(); + Base::Placement Plz = getEditingPlacement(); Base::Rotation tmp(Plz.getRotation()); tmp.multVec(RN,RN); Plz.setRotation(tmp); @@ -5549,13 +5554,15 @@ void ViewProviderSketch::updateData(const App::Property *prop) if(getSketchObject()->getExternalGeometryCount()+getSketchObject()->getHighestCurveIndex() + 1 == getSketchObject()->getSolvedSketch().getGeometrySize()) { - Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView(); + Gui::MDIView *mdi = Gui::Application::Instance->editDocument()->getActiveView(); if (mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) draw(false,true); signalConstraintsChanged(); - signalElementsChanged(); } + + if(prop != &getSketchObject()->Constraints) + signalElementsChanged(); } } @@ -5625,6 +5632,8 @@ bool ViewProviderSketch::setEdit(int ModNum) // clear the selection (convenience) Gui::Selection().clearSelection(); Gui::Selection().rmvPreselect(); + + this->attachSelection(); // create the container for the additional edit data assert(!edit); @@ -5635,15 +5644,25 @@ bool ViewProviderSketch::setEdit(int ModNum) createEditInventorNodes(); + auto editDoc = Gui::Application::Instance->editDocument(); + App::DocumentObject *editObj = getSketchObject(); + std::string editSubName; + ViewProviderDocumentObject *editVp = 0; + if(editDoc) { + editDoc->getInEdit(&editVp,&editSubName); + if(editVp) + editObj = editVp->getObject(); + } + //visibility automation try{ Gui::Command::addModule(Gui::Command::Gui,"Show.TempoVis"); try{ QString cmdstr = QString::fromLatin1( - "ActiveSketch = App.ActiveDocument.getObject('{sketch_name}')\n" + "ActiveSketch = App.getDocument('%1').getObject('%2')\n" "tv = Show.TempoVis(App.ActiveDocument)\n" "if ActiveSketch.ViewObject.HideDependent:\n" - " objs = tv.get_all_dependent(ActiveSketch)\n" + " objs = tv.get_all_dependent(%3, '%4')\n" " objs = filter(lambda x: not x.TypeId.startswith(\"TechDraw::\"), objs)\n" " objs = filter(lambda x: not x.TypeId.startswith(\"Drawing::\"), objs)\n" " tv.hide(objs)\n" @@ -5654,8 +5673,10 @@ bool ViewProviderSketch::setEdit(int ModNum) "tv.hide(ActiveSketch)\n" "ActiveSketch.ViewObject.TempoVis = tv\n" "del(tv)\n" - ); - cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument())); + ).arg(QString::fromLatin1(getDocument()->getDocument()->getName()), + QString::fromLatin1(getSketchObject()->getNameInDocument()), + QString::fromLatin1(Gui::Command::getObjectCmd(editObj).c_str()), + QString::fromLatin1(editSubName.c_str())); QByteArray cmdstr_bytearray = cmdstr.toLatin1(); Gui::Command::runCommand(Gui::Command::Gui, cmdstr_bytearray); } catch (Base::PyException &e){ @@ -5749,9 +5770,9 @@ bool ViewProviderSketch::setEdit(int ModNum) UpdateSolverInformation(); draw(false,true); - connectUndoDocument = Gui::Application::Instance->activeDocument() + connectUndoDocument = getDocument() ->signalUndoDocument.connect(boost::bind(&ViewProviderSketch::slotUndoDocument, this, _1)); - connectRedoDocument = Gui::Application::Instance->activeDocument() + connectRedoDocument = getDocument() ->signalRedoDocument.connect(boost::bind(&ViewProviderSketch::slotRedoDocument, this, _1)); // Enable solver initial solution update while dragging. @@ -6062,14 +6083,14 @@ void ViewProviderSketch::unsetEdit(int ModNum) //visibility autoation try{ QString cmdstr = QString::fromLatin1( - "ActiveSketch = App.ActiveDocument.getObject('{sketch_name}')\n" + "ActiveSketch = App.getDocument('%1').getObject('%2')\n" "tv = ActiveSketch.ViewObject.TempoVis\n" "if tv:\n" " tv.restore()\n" "ActiveSketch.ViewObject.TempoVis = None\n" "del(tv)\n" - ); - cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument())); + ).arg(QString::fromLatin1(getDocument()->getDocument()->getName())).arg( + QString::fromLatin1(getSketchObject()->getNameInDocument())); QByteArray cmdstr_bytearray = cmdstr.toLatin1(); Gui::Command::runCommand(Gui::Command::Gui, cmdstr_bytearray); } catch (Base::PyException &e){ @@ -6079,10 +6100,13 @@ void ViewProviderSketch::unsetEdit(int ModNum) delete edit; edit = 0; + this->detachSelection(); + App::AutoTransaction trans("Sketch recompute"); try { // and update the sketch - getSketchObject()->getDocument()->recompute(); + // getSketchObject()->getDocument()->recompute(); + Gui::Command::updateActive(); } catch (...) { } @@ -6090,9 +6114,7 @@ void ViewProviderSketch::unsetEdit(int ModNum) // clear the selection and set the new/edited sketch(convenience) Gui::Selection().clearSelection(); - std::string ObjName = getSketchObject()->getNameInDocument(); - std::string DocName = getSketchObject()->getDocument()->getName(); - Gui::Selection().addSelection(DocName.c_str(),ObjName.c_str()); + Gui::Selection().addSelection(editDocName.c_str(),editObjName.c_str(),editSubName.c_str()); connectUndoDocument.disconnect(); connectRedoDocument.disconnect(); @@ -6113,11 +6135,11 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo if (! this->TempoVis.getValue().isNone()){ try{ QString cmdstr = QString::fromLatin1( - "ActiveSketch = App.ActiveDocument.getObject('{sketch_name}')\n" + "ActiveSketch = App.getDocument('%1').getObject('%2')\n" "if ActiveSketch.ViewObject.RestoreCamera:\n" " ActiveSketch.ViewObject.TempoVis.saveCamera()\n" - ); - cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument())); + ).arg(QString::fromLatin1(getDocument()->getDocument()->getName())).arg( + QString::fromLatin1(getSketchObject()->getNameInDocument())); QByteArray cmdstr_bytearray = cmdstr.toLatin1(); Gui::Command::runCommand(Gui::Command::Gui, cmdstr_bytearray); } catch (Base::PyException &e){ @@ -6126,7 +6148,28 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo } } - Base::Placement plm = getSketchObject()->globalPlacement(); + auto editDoc = Gui::Application::Instance->editDocument(); + editDocName.clear(); + if(editDoc) { + ViewProviderDocumentObject *parent=0; + editDoc->getInEdit(&parent,&editSubName); + if(parent) { + editDocName = editDoc->getDocument()->getName(); + editObjName = parent->getObject()->getNameInDocument(); + } + } + if(editDocName.empty()) { + editDocName = getObject()->getDocument()->getName(); + editObjName = getObject()->getNameInDocument(); + editSubName.clear(); + } + const char *dot = strrchr(editSubName.c_str(),'.'); + if(!dot) + editSubName.clear(); + else + editSubName.resize(dot-editSubName.c_str()+1); + + Base::Placement plm = getEditingPlacement(); Base::Rotation tmp(plm.getRotation()); SbRotation rot((float)tmp[0],(float)tmp[1],(float)tmp[2],(float)tmp[3]); @@ -6159,6 +6202,8 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo viewer->addGraphicsItem(rubberband); rubberband->setViewer(viewer); + + viewer->setupEditingRoot(); } void ViewProviderSketch::unsetEditViewer(Gui::View3DInventorViewer* viewer) @@ -6381,8 +6426,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) for (rit = delConstraints.rbegin(); rit != delConstraints.rend(); ++rit) { try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delConstraint(%i)" - ,getObject()->getNameInDocument(), *rit); + FCMD_OBJ_CMD2("delConstraint(%i)" ,getObject(), *rit); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -6405,8 +6449,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) if (((*it)->Type == Sketcher::Coincident) && (((*it)->First == GeoId && (*it)->FirstPos == PosId) || ((*it)->Second == GeoId && (*it)->SecondPos == PosId)) ) { try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delConstraintOnPoint(%i,%i)" - ,getObject()->getNameInDocument(), GeoId, (int)PosId); + FCMD_OBJ_CMD2("delConstraintOnPoint(%i,%i)" ,getObject(), GeoId, (int)PosId); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -6419,8 +6462,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) for (rit = delInternalGeometries.rbegin(); rit != delInternalGeometries.rend(); ++rit) { try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delGeometry(%i)" - ,getObject()->getNameInDocument(), *rit); + FCMD_OBJ_CMD2("delGeometry(%i)" ,getObject(), *rit); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -6429,8 +6471,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) for (rit = delExternalGeometries.rbegin(); rit != delExternalGeometries.rend(); ++rit) { try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.delExternal(%i)" - ,getObject()->getNameInDocument(), *rit); + FCMD_OBJ_CMD2("delExternal(%i)",getObject(), *rit); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 872bd6d5c5..e785aa321c 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -246,6 +246,8 @@ public: boost::signals2::signal signalElementsChanged; protected: + Base::Placement getEditingPlacement() const; + virtual bool setEdit(int ModNum); virtual void unsetEdit(int ModNum); virtual void setEditViewer(Gui::View3DInventorViewer*, int ModNum); @@ -422,6 +424,10 @@ protected: bool visibleInformationChanged; double combrepscalehyst; + std::string editDocName; + std::string editObjName; + std::string editSubName; + // Virtual space variables bool isShownVirtualSpace; // indicates whether the present virtual space view is the Real Space or the Virtual Space (virtual space 1 or 2) diff --git a/src/Mod/Sketcher/ProfileLib/RegularPolygon.py b/src/Mod/Sketcher/ProfileLib/RegularPolygon.py index 56dcff6e89..d6b0780bea 100644 --- a/src/Mod/Sketcher/ProfileLib/RegularPolygon.py +++ b/src/Mod/Sketcher/ProfileLib/RegularPolygon.py @@ -32,21 +32,19 @@ App = FreeCAD Gui = FreeCADGui def makeRegularPolygon( - sketchName, + sketch, sides, centerPoint=App.Vector(0,0,0), firstCornerPoint=App.Vector(-20.00,34.64,0), construction=False): - if not sketchName: + if not sketch: App.Console.PrintError("No sketch specified in 'makeRegularPolygon'") return if sides < 3: App.Console.PrintError("Number of sides must be at least 3 in 'makeRegularPolygon'") return - sketch = App.ActiveDocument.getObject(sketchName) - diffVec = firstCornerPoint - centerPoint diffVec.z = 0 angular_diff = 2*math.pi/sides