diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index a48fac413..0804a5a99 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -31,6 +31,7 @@ #include "Document.h" #include "DocumentObject.h" #include "DocumentObjectPy.h" +#include "DocumentObjectGroup.h" #include "PropertyLinks.h" #define new DEBUG_CLIENTBLOCK using namespace App; @@ -158,6 +159,11 @@ std::vector DocumentObject::getInList(void) const return std::vector(); } +DocumentObjectGroup* DocumentObject::getGroup() const +{ + return DocumentObjectGroup::getGroupOfObject(this); +} + void DocumentObject::onLostLinkToObject(DocumentObject*) { diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index 079c361c8..8d8ad091f 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -36,6 +36,7 @@ namespace App { class Document; +class DocumentObjectGroup; class DocumentObjectPy; enum ObjectStatus { @@ -122,6 +123,8 @@ public: std::vector getOutList(void) const; /// get all objects link to this object std::vector getInList(void) const; + /// get group if object is part of a group, otherwise 0 is returned + DocumentObjectGroup* getGroup() const; public: diff --git a/src/App/DocumentObjectGroup.cpp b/src/App/DocumentObjectGroup.cpp index d6781d6be..6fb6ebbf9 100644 --- a/src/App/DocumentObjectGroup.cpp +++ b/src/App/DocumentObjectGroup.cpp @@ -103,7 +103,7 @@ DocumentObject *DocumentObjectGroup::getObject(const char *Name) const return 0; } -bool DocumentObjectGroup::hasObject(DocumentObject* obj) const +bool DocumentObjectGroup::hasObject(const DocumentObject* obj) const { const std::vector& grp = Group.getValues(); for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { @@ -114,7 +114,7 @@ bool DocumentObjectGroup::hasObject(DocumentObject* obj) const return false; } -bool DocumentObjectGroup::isChildOf(DocumentObjectGroup* group) const +bool DocumentObjectGroup::isChildOf(const DocumentObjectGroup* group) const { const std::vector& grp = group->Group.getValues(); for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { @@ -158,7 +158,7 @@ int DocumentObjectGroup::countObjectsOfType(const Base::Type& typeId) const return type; } -DocumentObjectGroup* DocumentObjectGroup::getGroupOfObject(DocumentObject* obj) +DocumentObjectGroup* DocumentObjectGroup::getGroupOfObject(const DocumentObject* obj) { const Document* doc = obj->getDocument(); std::vector grps = doc->getObjectsOfType(DocumentObjectGroup::getClassTypeId()); diff --git a/src/App/DocumentObjectGroup.h b/src/App/DocumentObjectGroup.h index a7a4537df..49330ed0a 100644 --- a/src/App/DocumentObjectGroup.h +++ b/src/App/DocumentObjectGroup.h @@ -65,12 +65,12 @@ public: /** * Checks whether the object \a obj is part of this group. */ - bool hasObject(DocumentObject* obj) const; + bool hasObject(const DocumentObject* obj) const; /** * Checks whether this group object is a child (or sub-child) * of the given group object. */ - bool isChildOf(DocumentObjectGroup*) const; + bool isChildOf(const DocumentObjectGroup*) const; /** Returns a list of all objects this group does have. */ std::vector getObjects() const; @@ -83,7 +83,7 @@ public: /** Returns the object group of the document which the given object \a obj is part of. * In case this object is not part of a group 0 is returned. */ - static DocumentObjectGroup* getGroupOfObject(DocumentObject* obj); + static DocumentObjectGroup* getGroupOfObject(const DocumentObject* obj); //@} /// returns the type name of the ViewProvider diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 2a21b7f88..9934f963f 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,16 @@ void validateSketches(std::vector& sketches, const bool su while (s != sketches.end()) { // Check whether this sketch is already being used by another feature - if ((*s)->getInList().size() != 0) { + std::vector ref = (*s)->getInList(); + std::vector::iterator r = ref.begin(); + while (r != ref.end()) { + if ((*r)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) { + r = ref.erase(r); + continue; + } + ++r; + } + if (!ref.empty()) { // TODO: Display some information message that this sketch was removed? s = sketches.erase(s); continue; @@ -205,6 +215,13 @@ void CmdPartDesignPad::activated(int iMsg) doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pad\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str()); + App::DocumentObjectGroup* grp = sketch->getGroup(); + if (grp) { + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),sketch->getNameInDocument()); + } updateActive(); if (isActiveObjectValid()) { doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); @@ -276,6 +293,13 @@ void CmdPartDesignPocket::activated(int iMsg) doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pocket\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str()); + App::DocumentObjectGroup* grp = sketch->getGroup(); + if (grp) { + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),sketch->getNameInDocument()); + } updateActive(); if (isActiveObjectValid()) { doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); @@ -346,6 +370,13 @@ void CmdPartDesignRevolution::activated(int iMsg) PartDesign::Revolution* pcRevolution = static_cast(getDocument()->getObject(FeatName.c_str())); if (pcRevolution && pcRevolution->suggestReversed()) doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str()); + App::DocumentObjectGroup* grp = sketch->getGroup(); + if (grp) { + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),sketch->getNameInDocument()); + } updateActive(); if (isActiveObjectValid()) { doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); @@ -419,6 +450,13 @@ void CmdPartDesignGroove::activated(int iMsg) PartDesign::Groove* pcGroove = static_cast(getDocument()->getObject(FeatName.c_str())); if (pcGroove && pcGroove->suggestReversed()) doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str()); + App::DocumentObjectGroup* grp = sketch->getGroup(); + if (grp) { + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),sketch->getNameInDocument()); + } updateActive(); if (isActiveObjectValid()) { doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 4a5b3954e..9665f6a89 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -32,6 +32,7 @@ # include #endif +#include #include #include #include @@ -117,6 +118,11 @@ void CmdSketcherNewSketch::activated(int iMsg) doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support //doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str()); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); + App::DocumentObjectGroup* grp = part->getGroup(); + if (grp) { + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" + ,grp->getNameInDocument(),FeatName.c_str()); + } } else { // ask user for orientation