From 9e7b46311376307738fa2df75c91cc738cbd6dc9 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Wed, 3 Jul 2013 11:51:27 +0200 Subject: [PATCH] Allow geometry from other bodies in the same par as external geometry for sketches --- src/Mod/Sketcher/App/SketchObject.cpp | 4 +++- src/Mod/Sketcher/App/SketchObject.h | 3 +++ src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 13 +++++++------ src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 1a0ca7cfe..25eafc4b8 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -83,6 +83,8 @@ SketchObject::SketchObject() ADD_PROPERTY_TYPE(Constraints, (0) ,"Sketch",(App::PropertyType)(App::Prop_None),"Sketch constraints"); ADD_PROPERTY_TYPE(ExternalGeometry,(0,0),"Sketch",(App::PropertyType)(App::Prop_None),"Sketch external geometry"); + allowOtherBody = true; + for (std::vector::iterator it=ExternalGeo.begin(); it != ExternalGeo.end(); ++it) if (*it) delete *it; ExternalGeo.clear(); @@ -2713,7 +2715,7 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId) int SketchObject::addExternal(App::DocumentObject *Obj, const char* SubName) { // so far only externals to the support of the sketch and datum features - if (Support.getValue() != Obj) + if (!allowOtherBody && (Support.getValue() != Obj)) if (!Obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) && !Obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) return -1; diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 931978cf5..7224417ee 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -259,6 +259,9 @@ public: /// gets the solved sketch as a reference inline Sketch &getSolvedSketch(void) {return solvedSketch;} + // Flag to allow external geometry from other bodies than the one this sketch belongs to + bool allowOtherBody; + protected: /// get called by the container when a property has changed virtual void onChanged(const App::Property* /*prop*/); diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index fa82d573a..d9cc5bf91 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -376,10 +376,11 @@ PyObject* SketchObjectPy::addExternal(PyObject *args) return 0; // get the target object for the external link - App::DocumentObject * Obj = this->getSketchObjectPtr()->getDocument()->getObject(ObjectName); + Sketcher::SketchObject* skObj = this->getSketchObjectPtr(); + App::DocumentObject * Obj = skObj->getDocument()->getObject(ObjectName); if (!Obj) { std::stringstream str; - str << ObjectName << "does not exist in the document"; + str << ObjectName << " does not exist in the document"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); return 0; } @@ -388,21 +389,21 @@ PyObject* SketchObjectPy::addExternal(PyObject *args) if (Obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { // OK } else if (Obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { - if (this->getSketchObjectPtr()->Support.getValue() != Obj) { + if (!skObj->allowOtherBody && (skObj->Support.getValue() != Obj)) { std::stringstream str; - str << ObjectName << "is not supported by this sketch"; + str << ObjectName << " is not supported by this sketch"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); return 0; } } else if (!Obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { std::stringstream str; - str << ObjectName << "must be a Part feature or a datum feature"; + str << ObjectName << " must be a Part feature or a datum feature"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); return 0; } // add the external - if (this->getSketchObjectPtr()->addExternal(Obj,SubName) < 0) { + if (skObj->addExternal(Obj,SubName) < 0) { std::stringstream str; str << "Not able to add external shape element"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 49b1fca37..35adb3825 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4481,7 +4481,7 @@ namespace SketcherGui { pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) return true; - if (pObj != support) + if (!sketch->allowOtherBody && (pObj != support)) return false; if (!sSubName || sSubName[0] == '\0') return false;