From 1a26f7551fede7122122e898fb465e5cb18b501a Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Sat, 5 Sep 2015 05:49:33 +0300 Subject: [PATCH] PartDesign: add Origin to the Body and unstrap the module from the Parts --- src/Mod/PartDesign/App/Body.cpp | 90 +++++++---- src/Mod/PartDesign/App/Body.h | 26 +++- src/Mod/PartDesign/App/DatumCS.cpp | 3 +- src/Mod/PartDesign/App/DatumLine.cpp | 3 +- src/Mod/PartDesign/App/DatumPlane.cpp | 3 +- src/Mod/PartDesign/App/DatumPoint.cpp | 3 +- src/Mod/PartDesign/App/Feature.cpp | 2 +- src/Mod/PartDesign/App/FeatureBoolean.cpp | 16 -- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 1 - src/Mod/PartDesign/Gui/Command.cpp | 48 +++--- src/Mod/PartDesign/Gui/CommandBody.cpp | 25 ++-- src/Mod/PartDesign/Gui/ReferenceSelection.cpp | 63 ++++++-- src/Mod/PartDesign/Gui/ReferenceSelection.h | 1 + .../PartDesign/Gui/TaskDatumParameters.cpp | 13 +- src/Mod/PartDesign/Gui/TaskFeaturePick.cpp | 1 + .../Gui/TaskLinearPatternParameters.cpp | 14 +- .../PartDesign/Gui/TaskMirroredParameters.cpp | 14 +- .../Gui/TaskPolarPatternParameters.cpp | 23 +-- .../Gui/TaskRevolutionParameters.cpp | 23 ++- .../Gui/TaskSketchBasedParameters.cpp | 1 - .../Gui/TaskTransformedParameters.cpp | 13 +- src/Mod/PartDesign/Gui/Utils.cpp | 17 ++- src/Mod/PartDesign/Gui/Utils.h | 1 + src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 141 +++++++++++------- src/Mod/PartDesign/Gui/ViewProviderBody.h | 10 +- src/Mod/PartDesign/Gui/ViewProviderDatum.cpp | 8 +- src/Mod/PartDesign/Gui/Workbench.cpp | 79 +++++----- 27 files changed, 378 insertions(+), 264 deletions(-) diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index b243f21b6..1b879f7cf 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -22,39 +22,39 @@ #include "PreCompiled.h" + #ifndef _PreComp_ +#include #endif +#include #include +#include +#include +#include + +#include +#include + + #include "Feature.h" -#include "Body.h" -#include "BodyPy.h" #include "FeatureSketchBased.h" #include "FeatureTransformed.h" #include "DatumPoint.h" #include "DatumLine.h" #include "DatumPlane.h" -#include -#include -#include -#include -#include - -#include +#include "Body.h" +#include "BodyPy.h" using namespace PartDesign; -namespace PartDesign { - PROPERTY_SOURCE(PartDesign::Body, Part::BodyBase) -Body::Body() -{ - Placement.StatusBits.set(3, true); - //ADD_PROPERTY(IsActive,(0)); +Body::Body() { + ADD_PROPERTY_TYPE (Origin, (0), 0, App::Prop_Hidden, "Origin linked to the body" ); } /* @@ -446,15 +446,6 @@ Base::BoundBox3d Body::getBoundBox() return result; } -PyObject *Body::getPyObject(void) -{ - if (PythonObject.is(Py::_None())){ - // ref counter is set to 1 - PythonObject = Py::Object(new BodyPy(this),true); - } - return Py::new_reference_to(PythonObject); -} - void Body::onSettingDocument() { if(connection.connected()) @@ -479,11 +470,58 @@ void Body::onChanged (const App::Property* prop) { assert ( nextSolid->isDerivedFrom ( PartDesign::Feature::getClassTypeId () ) ); static_cast(nextSolid)->BaseFeature.setValue( baseFeature ); } - } Part::BodyBase::onChanged ( prop ); } +App::Origin *Body::getOrigin () const { + App::DocumentObject *originObj = Origin.getValue (); -} /* PartDesign */ + if ( !originObj ) { + std::stringstream err; + err << "Can't find Origin for \"" << getNameInDocument () << "\""; + throw Base::Exception ( err.str().c_str () ); + + } else if (! originObj->isDerivedFrom ( App::Origin::getClassTypeId() ) ) { + std::stringstream err; + err << "Bad object \"" << originObj->getNameInDocument () << "\"(" << originObj->getTypeId().getName() + << ") linked to the Origin of \"" << getNameInDocument () << "\""; + throw Base::Exception ( err.str().c_str () ); + } else { + return static_cast ( originObj ); + } +} + +void Body::setupObject () { + // NOTE: the code shared with App::OriginGroup + App::Document *doc = getDocument (); + + std::string objName = std::string ( getNameInDocument() ).append ( "Origin" ); + + App::DocumentObject *originObj = doc->addObject ( "App::Origin", objName.c_str () ); + + assert ( originObj && originObj->isDerivedFrom ( App::Origin::getClassTypeId () ) ); + Origin.setValue ( originObj ); + + Part::BodyBase::setupObject (); +} + +void Body::unsetupObject () { + App::DocumentObject *origin = Origin.getValue (); + + if (origin && !origin->isDeleting ()) { + origin->getDocument ()->remObject (origin->getNameInDocument()); + } + + Part::BodyBase::unsetupObject (); +} + +PyObject *Body::getPyObject(void) +{ + if (PythonObject.is(Py::_None())){ + // ref counter is set to 1 + PythonObject = Py::Object(new BodyPy(this),true); + } + return Py::new_reference_to(PythonObject); +} diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index ca11c3e6b..910e1df56 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -29,6 +29,10 @@ #include +namespace App { + class Origin; +} + namespace PartDesign { @@ -50,6 +54,7 @@ public: /// recalculate the feature App::DocumentObjectExecReturn *execute(void); short mustExecute() const; + /// returns the type name of the view provider const char* getViewProviderName(void) const { return "PartDesignGui::ViewProviderBody"; @@ -59,9 +64,6 @@ public: /// Return the previous feature App::DocumentObject* getPrevFeature(App::DocumentObject *start = NULL) const; - // Return the shape of the feature preceding this feature - //const Part::TopoShape getPreviousSolid(const PartDesign::Feature* f); - /** * Add the feature into the body at the current insert point. * The insertion poin is the before next solid after the Tip feature @@ -84,6 +86,9 @@ public: /// Remove the feature from the body void removeFeature(App::DocumentObject* feature); + /// Delets all the objects linked to the model. + void removeModelFromDocument(); + /** * Checks if the given document object lays after the current insert point * (place before next solid after the Tip) @@ -112,14 +117,17 @@ public: */ static Body *findBodyOf(const App::DocumentObject* feature); - /// Delets all the objects linked to the model. - void removeModelFromDocument(); - /// Return the bounding box of the Tip Shape, taking into account datum features Base::BoundBox3d getBoundBox(); + /// Returns the origin link or throws an exception + App::Origin *getOrigin () const; + PyObject *getPyObject(void); + /// Origin linked to the property, please use getOrigin () to access it + App::PropertyLink Origin; + protected: virtual void onSettingDocument(); @@ -138,8 +146,12 @@ protected: */ App::DocumentObject *getNextSolidFeature(App::DocumentObject* start = NULL); + /// Creates the corresponding Origin object + virtual void setupObject (); + /// Removes all planes and axis if they are still linked to the document + virtual void unsetupObject (); + private: - App::DocumentObject* rememberTip; boost::signals::scoped_connection connection; }; diff --git a/src/Mod/PartDesign/App/DatumCS.cpp b/src/Mod/PartDesign/App/DatumCS.cpp index 97f8c0b2b..1d8ce7653 100644 --- a/src/Mod/PartDesign/App/DatumCS.cpp +++ b/src/Mod/PartDesign/App/DatumCS.cpp @@ -24,12 +24,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ #endif - +// TODO Cleanup headers (2015-09-04, Fat-Zer) #include "DatumCS.h" #include "DatumPoint.h" #include "DatumPlane.h" #include "DatumLine.h" -#include #include #include #include diff --git a/src/Mod/PartDesign/App/DatumLine.cpp b/src/Mod/PartDesign/App/DatumLine.cpp index e21b41b7d..6ba74a0ef 100644 --- a/src/Mod/PartDesign/App/DatumLine.cpp +++ b/src/Mod/PartDesign/App/DatumLine.cpp @@ -60,9 +60,8 @@ # include #endif +// TODO Cleanup Headers (2015-09-04, Fat-Zer) #include -#include -#include #include "DatumPoint.h" #include "DatumLine.h" #include "DatumPlane.h" diff --git a/src/Mod/PartDesign/App/DatumPlane.cpp b/src/Mod/PartDesign/App/DatumPlane.cpp index d14fdad47..aa299ef94 100644 --- a/src/Mod/PartDesign/App/DatumPlane.cpp +++ b/src/Mod/PartDesign/App/DatumPlane.cpp @@ -57,9 +57,8 @@ # include # include #endif - +// TODO Cleanup headers (2015-09-04, Fat-Zer) #include -#include #include "DatumPoint.h" #include "DatumLine.h" #include "DatumPlane.h" diff --git a/src/Mod/PartDesign/App/DatumPoint.cpp b/src/Mod/PartDesign/App/DatumPoint.cpp index 8950517c8..ac6a34cc7 100644 --- a/src/Mod/PartDesign/App/DatumPoint.cpp +++ b/src/Mod/PartDesign/App/DatumPoint.cpp @@ -57,9 +57,8 @@ # include # include #endif - +// TODO Cleanup headers (2015-09-04, Fat-Zer) #include -#include #include "DatumPoint.h" #include "DatumLine.h" #include "DatumPlane.h" diff --git a/src/Mod/PartDesign/App/Feature.cpp b/src/Mod/PartDesign/App/Feature.cpp index 8a89deaee..bdbeebe12 100644 --- a/src/Mod/PartDesign/App/Feature.cpp +++ b/src/Mod/PartDesign/App/Feature.cpp @@ -33,7 +33,7 @@ # include #endif - +// TODO Cleanup headers (2015-09-04, Fat-Zer) #include #include "App/Document.h" #include "App/OriginFeature.h" diff --git a/src/Mod/PartDesign/App/FeatureBoolean.cpp b/src/Mod/PartDesign/App/FeatureBoolean.cpp index 04debba34..129d2473d 100644 --- a/src/Mod/PartDesign/App/FeatureBoolean.cpp +++ b/src/Mod/PartDesign/App/FeatureBoolean.cpp @@ -41,7 +41,6 @@ #include #include #include -#include using namespace PartDesign; @@ -90,19 +89,6 @@ App::DocumentObjectExecReturn *Boolean::execute(void) if(!baseBody) return new App::DocumentObjectExecReturn("Cannot do boolean on feature which is not in a body"); - // TODO: share the code snippet with PartDesignGui::getPartFor() - //get the part every body should belong to - App::Part* part = NULL; - for(App::Part* p : this->getDocument()->getObjectsOfType()) { - if(p->hasObject(baseBody)) { - part = p; - break; - } - } - if(!part) - return new App::DocumentObjectExecReturn("Cannot do boolean on body which is not in a part"); - - // TODO: Why is Feature::getLocation() protected? Base::Placement place = baseBody->Placement.getValue(); Base::Rotation rot(place.getRotation()); @@ -125,8 +111,6 @@ App::DocumentObjectExecReturn *Boolean::execute(void) // Extract the body shape. Its important to get the actual feature that provides the last solid in the body // so that the placement will be right PartDesign::Body* body = static_cast(*b); - if(!part->hasObject(body)) - return new App::DocumentObjectExecReturn("Cannot do boolean on bodies of different parts"); TopoDS_Shape shape = body->Shape.getValue(); diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 698e7177e..50f084854 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -71,7 +71,6 @@ #include #include #include -#include #include #include "FeatureSketchBased.h" #include "DatumPlane.h" diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 157e49b9e..aeb1bedf6 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -339,21 +339,21 @@ void CmdPartDesignNewSketch::activated(int iMsg) // Get a valid plane from the user unsigned validPlanes = 0; - App::Part* pcActivePart = Gui::Application::Instance->activeView()->getActiveObject(PARTKEY); + App::GeoFeatureGroup* geoGroup = App::GeoFeatureGroup::getGroupOfObject ( pcActiveBody ); std::vector planes; std::vector status; // Baseplanes are preaprooved - if ( pcActivePart ) { + if ( pcActiveBody ) { try { - for ( auto plane: pcActivePart->getOrigin ()->planes() ) { + for ( auto plane: pcActiveBody->getOrigin ()->planes() ) { planes.push_back (plane); status.push_back(PartDesignGui::TaskFeaturePick::basePlane); validPlanes++; } } catch (const Base::Exception &ex) { - Base::Console().Error ("%s\n", ex.what() ); + Base::Console().Error ("%s\n", ex.what() ); } } @@ -363,24 +363,34 @@ void CmdPartDesignNewSketch::activated(int iMsg) for (auto plane: datumPlanes) { planes.push_back ( plane ); // Check whether this plane belongs to the active body - if (!pcActiveBody->hasFeature(plane)) { - if ( pcActivePart && pcActivePart->hasObject ( plane, true ) ) { - status.push_back(PartDesignGui::TaskFeaturePick::otherBody); + if ( pcActiveBody && pcActiveBody->hasFeature(plane) ) { + if ( !pcActiveBody->isAfterInsertPoint ( plane ) ) { + validPlanes++; + status.push_back(PartDesignGui::TaskFeaturePick::validFeature); } else { - status.push_back(PartDesignGui::TaskFeaturePick::otherPart); - } - - continue; - } else { - if (pcActiveBody->isAfterInsertPoint ( plane ) ) { status.push_back(PartDesignGui::TaskFeaturePick::afterTip); - continue; + } + } else { + PartDesign::Body *planeBody = PartDesign::Body::findBodyOf (plane); + if ( planeBody ) { + if ( ( geoGroup && geoGroup->hasObject ( planeBody, true ) ) || + !App::GeoFeatureGroup::getGroupOfObject (planeBody) ) { + status.push_back ( PartDesignGui::TaskFeaturePick::otherBody ); + } else { + status.push_back ( PartDesignGui::TaskFeaturePick::otherPart ); + } + } else { + if ( ( geoGroup && geoGroup->hasObject ( plane, true ) ) || + !App::GeoFeatureGroup::getGroupOfObject ( plane ) ) { + status.push_back ( PartDesignGui::TaskFeaturePick::otherPart ); + } else if (pcActiveBody) { + status.push_back ( PartDesignGui::TaskFeaturePick::notInBody ); + } else { // if we are outside a body count it as valid + validPlanes++; + status.push_back(PartDesignGui::TaskFeaturePick::validFeature); + } } } - - // All checks passed - found a valid plane - validPlanes++; - status.push_back(PartDesignGui::TaskFeaturePick::validFeature); } if (validPlanes == 0) { @@ -510,6 +520,7 @@ const unsigned validateSketches(std::vector& sketches, std::vector& status, std::vector::iterator& firstValidSketch) { + // TODO Review the function for non-part bodies (2015-09-04, Fat-Zer) PartDesign::Body* pcActiveBody = PartDesignGui::getBody(false); App::Part* pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false); @@ -1599,6 +1610,7 @@ void CmdPartDesignMultiTransform::activated(int iMsg) Gui::Selection().clearSelection(); if (prevFeature != NULL) Gui::Selection().addSelection(prevFeature->getDocument()->getName(), prevFeature->getNameInDocument()); + // TODO Review this (2015-09-05, Fat-Zer) openCommand("Convert to MultiTransform feature"); doCommand(Gui, "FreeCADGui.runCommand('PartDesign_MoveTip')"); diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index 4060a5ad2..aca4c7bca 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -157,30 +157,30 @@ void CmdPartDesignBody::activated(int iMsg) } // first check if Part is already created: - App::Part *actPart = PartDesignGui::assertActivePart (); - if (!actPart) { - return; - } - - std::string PartName = actPart->getNameInDocument(); + App::Part *actPart = PartDesignGui::getActivePart (); openCommand("Add a Body"); - std::string FeatName = getUniqueObjectName("Body"); + std::string bodyName = getUniqueObjectName("Body"); // add the Body feature itself, and make it active - doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')", FeatName.c_str()); + doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')", bodyName.c_str()); if (baseFeature) { doCommand(Doc,"App.activeDocument().%s.BaseFeature = App.activeDocument().%s", - FeatName.c_str(), baseFeature->getNameInDocument()); + bodyName.c_str(), baseFeature->getNameInDocument()); } addModule(Gui,"PartDesignGui"); // import the Gui module only once a session - doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, FeatName.c_str()); + doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", + PDBODYKEY, bodyName.c_str()); // Make the "Create sketch" prompt appear in the task panel doCommand(Gui,"Gui.Selection.clearSelection()"); - doCommand(Gui,"Gui.Selection.addSelection(App.ActiveDocument.%s)", FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addObject(App.ActiveDocument.%s)",PartName.c_str(),FeatName.c_str()); + doCommand(Gui,"Gui.Selection.addSelection(App.ActiveDocument.%s)", bodyName.c_str()); + if (actPart) { + doCommand(Doc,"App.activeDocument().%s.addObject(App.ActiveDocument.%s)", + actPart->getNameInDocument(), bodyName.c_str()); + } + updateActive(); } @@ -307,6 +307,7 @@ void CmdPartDesignMigrate::activated(int iMsg) // TODO Align visability (2015-08-17, Fat-Zer) } /* for */ + // TODO make it work without parts (2015-09-04, Fat-Zer) // add a part if there is no active yet App::Part *actPart = PartDesignGui::assertActivePart (); diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index 183e06026..ef0d11bac 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -31,6 +31,8 @@ #endif #include +#include +#include #include #include #include @@ -41,6 +43,9 @@ #include #include #include + +#include "Utils.h" + #include "ReferenceSelection.h" using namespace PartDesignGui; @@ -50,26 +55,62 @@ using namespace Gui; bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) { - PartDesign::Body* ActivePartObject = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); - App::Part* activePart = Gui::Application::Instance->activeView()->getActiveObject("Part"); + // TODO review this function (2015-09-04, Fat-Zer) + PartDesign::Body *body; + App::GeoFeatureGroup *geoGroup; + + if ( support ) { + body = PartDesign::Body::findBodyOf (support); + } else { + body = PartDesignGui::getBody (false); + } + + if ( body ) { // Search for Part of the body + geoGroup = App::GeoFeatureGroup::getGroupOfObject ( body ) ; + } else if ( support ) { // if no body search part for support + geoGroup = App::GeoFeatureGroup::getGroupOfObject ( support ) ; + } else { // fallback to active part + geoGroup = PartDesignGui::getActivePart ( ); + } // Don't allow selection in other document - if ((support != NULL) && (pDoc != support->getDocument())) + if ( support && pDoc != support->getDocument() ) { return false; + } - if (plane && (pObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()))) - // Note: It is assumed that a Part has exactly 3 App::Plane objects at the root of the feature tree - return true; + // Enable selection from origin of current part/ + if ( pObj->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()) ) { + bool fits = false; + if ( plane && pObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) ) { + fits = true; + } else if ( edge && pObj->getTypeId().isDerivedFrom(App::Line::getClassTypeId()) ) { + fits = true; + } - if (edge && (pObj->getTypeId().isDerivedFrom(App::Line::getClassTypeId()))) - return true; + if (fits) { // check that it is actually belongs to the choosen body or part + try { // here are some throwers + if (body) { + if (body->getOrigin ()->hasObject (pObj) ) { + return true; + } + } else if (geoGroup && geoGroup->isDerivedFrom ( App::OriginGroup::getClassTypeId () ) ) { + if ( static_cast(geoGroup)->getOrigin ()->hasObject (pObj) ) { + return true; + } + } + } catch (const Base::Exception) + { } + } + return false; // The Plane/Axis doesn't fits our needs + } if (pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { - // Allow selecting Part::Datum features from the active Body - if (ActivePartObject == NULL) + + if (!body) { // Allow selecting Part::Datum features from the active Body return false; - if (!allowOtherBody && !ActivePartObject->hasFeature(pObj)) + } else if (!allowOtherBody && !body->hasFeature(pObj)) { return false; + } if (plane && (pObj->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId()))) return true; diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.h b/src/Mod/PartDesign/Gui/ReferenceSelection.h index f67da450d..954303451 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.h +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.h @@ -29,6 +29,7 @@ namespace PartDesignGui { class ReferenceSelection : public Gui::SelectionFilterGate { + // TODO Replace this set of bools with bitwice enum (2015-09-04, Fat-Zer) const App::DocumentObject* support; // If set to true, allow picking edges or planes or both bool edge, plane; diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 3fc42346d..20020b02e 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -211,10 +210,10 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p updateListOfModes(eMapMode(pcDatum->MapMode.getValue())); //temporary show coordinate systems for selection - App::Part* part = getPartFor(DatumView->getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( DatumView->getObject() ); + if(body) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, true); @@ -771,10 +770,10 @@ bool TaskDatumParameters::getFlip() const TaskDatumParameters::~TaskDatumParameters() { //end temporary view mode of coordinate system - App::Part* part = getPartFor(DatumView->getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( DatumView->getObject() ); + if(body) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 21dfc329a..0ad654aac 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -48,6 +48,7 @@ using namespace PartDesignGui; +// TODO Do ve should snap here to App:Part or GeoFeatureGroup/DocumentObjectGroup ? (2015-09-04, Fat-Zer) const QString TaskFeaturePick::getFeatureStatusString(const featureStatus st) { switch (st) { diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 3303fbe6f..7adb14173 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,7 @@ #include #include #include +#include #include #include "ReferenceSelection.h" @@ -165,10 +165,10 @@ void TaskLinearPatternParameters::setupUI() updateUI(); //show the parts coordinate system axis for selection - App::Part* part = getPartFor(getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf(getObject()); + if(body) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, false); @@ -357,10 +357,10 @@ const unsigned TaskLinearPatternParameters::getOccurrences(void) const TaskLinearPatternParameters::~TaskLinearPatternParameters() { //hide the parts coordinate system axis for selection - App::Part* part = getPartFor(getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); + if(body) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index a7dcbbe70..c631e2b46 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -43,6 +42,7 @@ #include #include #include +#include #include #include "ReferenceSelection.h" @@ -140,10 +140,10 @@ void TaskMirroredParameters::setupUI() updateUI(); //show the parts coordinate system axis for selection - App::Part* part = getPartFor(getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); + if(body) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, false); @@ -267,10 +267,10 @@ void TaskMirroredParameters::apply() TaskMirroredParameters::~TaskMirroredParameters() { //hide the parts coordinate system axis for selection - App::Part* part = getPartFor(getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); + if ( body ) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp index 7dafa2726..27b17962c 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -46,6 +45,7 @@ #include #include #include +#include #include "ReferenceSelection.h" #include "TaskMultiTransformParameters.h" @@ -150,19 +150,20 @@ void TaskPolarPatternParameters::setupUI() ui->checkReverse->setEnabled(true); ui->polarAngle->setEnabled(true); ui->spinOccurrences->setEnabled(true); - + App::DocumentObject* sketch = getSketchObject(); if (!(sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId()))) sketch = 0; this->axesLinks.setCombo(*(ui->comboAxis)); this->fillAxisCombo(axesLinks, static_cast(sketch)); updateUI(); - + //show the parts coordinate system axis for selection - App::Part* part = getPartFor(getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); + + if(body) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, false); @@ -327,7 +328,7 @@ void TaskPolarPatternParameters::onFeatureDeleted(void) } void TaskPolarPatternParameters::getAxis(App::DocumentObject*& obj, std::vector& sub) const -{ +{ const App::PropertyLinkSub &lnk = axesLinks.getCurrentLink(); obj = lnk.getValue(); sub = lnk.getSubValues(); @@ -352,10 +353,10 @@ const unsigned TaskPolarPatternParameters::getOccurrences(void) const TaskPolarPatternParameters::~TaskPolarPatternParameters() { //hide the parts coordinate system axis for selection - App::Part* part = getPartFor(getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); + if ( body ) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility (); @@ -363,7 +364,7 @@ TaskPolarPatternParameters::~TaskPolarPatternParameters() Base::Console().Error ("%s\n", ex.what () ); } } - + delete ui; if (proxy) delete proxy; diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 467293c18..5b97b2509 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -129,19 +128,19 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* ui->checkBoxReversed->blockSignals(false); setFocus (); - + //show the parts coordinate system axis for selection - App::Part* part = getPartFor(vp->getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( vp->getObject () ); + if(body) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, false); } catch (const Base::Exception &ex) { Base::Console().Error ("%s\n", ex.what () ); } - } + } } void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) @@ -177,11 +176,11 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) //add part axes App::DocumentObject* obj = vp->getObject(); - App::Part* part = getPartFor(obj, false); - if (part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( obj ); + if (body) { try { - App::Origin* orig = part->getOrigin(); + App::Origin* orig = body->getOrigin(); addAxisToCombo(orig->getX(),"",tr("Base X axis")); addAxisToCombo(orig->getY(),"",tr("Base Y axis")); addAxisToCombo(orig->getZ(),"",tr("Base Z axis")); @@ -360,10 +359,10 @@ bool TaskRevolutionParameters::getReversed(void) const TaskRevolutionParameters::~TaskRevolutionParameters() { //hide the parts coordinate system axis for selection - App::Part* part = getPartFor(vp->getObject(), false); - if(part) { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( vp->getObject() ); + if ( body ) { try { - App::Origin *origin = part->getOrigin(); + App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index bd60188d2..b107536de 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index 94c73c242..c50eb2a04 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -192,11 +191,11 @@ void TaskTransformedParameters::fillAxisCombo(ComboLinks &combolinks, //add part axes App::DocumentObject* obj = getObject(); - App::Part* part = getPartFor(obj, false); + PartDesign::Body * body = PartDesign::Body::findBodyOf ( obj ); - if (part) { + if (body) { try { - App::Origin* orig = part->getOrigin(); + App::Origin* orig = body->getOrigin(); combolinks.addLink(orig->getX(),"",tr("Base X axis")); combolinks.addLink(orig->getY(),"",tr("Base Y axis")); combolinks.addLink(orig->getZ(),"",tr("Base Z axis")); @@ -228,11 +227,11 @@ void TaskTransformedParameters::fillPlanesCombo(ComboLinks &combolinks, //add part baseplanes App::DocumentObject* obj = getObject(); - App::Part* part = getPartFor(obj, false); + PartDesign::Body * body = PartDesign::Body::findBodyOf ( obj ); - if (part) { + if (body) { try { - App::Origin* orig = part->getOrigin(); + App::Origin* orig = body->getOrigin(); combolinks.addLink(orig->getXY(),"",tr("Base XY plane")); combolinks.addLink(orig->getYZ(),"",tr("Base YZ plane")); combolinks.addLink(orig->getXZ(),"",tr("Base XZ plane")); diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index ef9e68119..37972e077 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -99,6 +99,15 @@ PartDesign::Body *getBodyFor(const App::DocumentObject* obj, bool messageIfNot) return nullptr; } +App::Part* getActivePart() { + Gui::MDIView *activeView = Gui::Application::Instance->activeView(); + if ( activeView ) { + return activeView->getActiveObject (PARTKEY); + } else { + return 0; + } +} + App::Part* getPartFor(const App::DocumentObject* obj, bool messageIfNot) { if(!obj) @@ -108,7 +117,7 @@ App::Part* getPartFor(const App::DocumentObject* obj, bool messageIfNot) { if(body) obj = body; - //get the part every body should belong to + //get the part for(App::Part* p : obj->getDocument()->getObjectsOfType()) { if(p->hasObject(obj)) { return p; @@ -149,11 +158,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch) } // Get the Origin for the body - App::OriginGroup *grp = App::OriginGroup::getGroupOfObject (body); - if (!grp) { - throw Base::Exception ("Coudn't find group for body"); - } - App::Origin *origin = grp->getOrigin (); // May throw by itself + App::Origin *origin = body->getOrigin (); // May throw by itself Base::Placement plm = sketch->Placement.getValue(); Base::Vector3d pnt = plm.getPosition(); diff --git a/src/Mod/PartDesign/Gui/Utils.h b/src/Mod/PartDesign/Gui/Utils.h index dd94dff19..5666192cc 100644 --- a/src/Mod/PartDesign/Gui/Utils.h +++ b/src/Mod/PartDesign/Gui/Utils.h @@ -50,6 +50,7 @@ PartDesign::Body *getBody(bool messageIfNot); */ PartDesign::Body *getBodyFor(const App::DocumentObject*, bool messageIfNot); App::Part *getPartFor(const App::DocumentObject*, bool messageIfNot); +App::Part *getActivePart(); /// Fix sketch support after moving a free sketch into a body void fixSketchSupport(Sketcher::SketchObject* sketch); diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index 7fa1a35d6..1d5a7fd40 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -26,6 +26,7 @@ #ifndef _PreComp_ # include # include +# include #endif #include @@ -51,19 +52,18 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderBody,PartGui::ViewProviderPart) ViewProviderBody::ViewProviderBody() { - pcBodyChildren = new SoGroup(); + pcBodyChildren = new SoSeparator(); pcBodyChildren->ref(); - pcBodyTip = new SoGroup(); + pcBodyTip = new SoSeparator(); pcBodyTip->ref(); + sPixmap = "PartDesign_Body_Tree.svg"; } ViewProviderBody::~ViewProviderBody() { - pcBodyChildren->unref(); - pcBodyChildren = 0; - pcBodyTip->unref(); - pcBodyTip = 0; + pcBodyChildren->unref (); + pcBodyTip->unref (); } @@ -71,39 +71,40 @@ void ViewProviderBody::attach(App::DocumentObject *pcFeat) { // call parent attach method ViewProviderPart::attach(pcFeat); + PartDesign::Body *body = static_cast (pcFeat); + + App::DocumentObject *tip = body->Tip.getValue (); + + if (tip) { + Gui::ViewProvider *vp = Gui::Application::Instance->getViewProvider (tip); + if (vp) { + pcBodyTip->addChild ( vp->getRoot () ); + } + } - // TODO fixup the "Body" display mode (2015-08-07, Fat-Zer) - // putting all together with the switch - addDisplayMaskMode(pcBodyTip, "Body"); addDisplayMaskMode(pcBodyChildren, "Through"); + addDisplayMaskMode(pcBodyTip, "Tip"); } +// TODO on activating the body switch to the "Through" mode (2015-09-05, Fat-Zer) +// TODO differnt icon in tree if mode is Through (2015-09-05, Fat-Zer) +// TODO drag&drop (2015-09-05, Fat-Zer) + void ViewProviderBody::setDisplayMode(const char* ModeName) { - if ( strcmp("Body",ModeName)==0 ) - setDisplayMaskMode("Body"); - if ( strcmp("Main",ModeName)==0 ) - setDisplayMaskMode("Main"); if ( strcmp("Through",ModeName)==0 ) setDisplayMaskMode("Through"); - + if ( strcmp("Tip",ModeName)==0 ) + setDisplayMaskMode("Tip"); + // TODO When switching into Tip mode switch it's visability to true (2015-09-05, Fat-Zer) ViewProviderGeometryObject::setDisplayMode( ModeName ); } -std::vector ViewProviderBody::getDisplayModes(void) const -{ - // get the modes of the father - std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); - - // add your own modes - StrList.push_back("Through"); - StrList.push_back("Body"); - - return StrList; +std::vector ViewProviderBody::getDisplayModes(void) const { + return {"Through" , "Tip"}; } - bool ViewProviderBody::doubleClicked(void) { // assure the PartDesign workbench @@ -121,35 +122,35 @@ bool ViewProviderBody::doubleClicked(void) std::vector ViewProviderBody::claimChildren(void)const { - PartDesign::Body* bodyObj = static_cast(getObject()); - const std::vector &Model = bodyObj->Model.getValues(); - std::set OutSet; + PartDesign::Body* body= static_cast ( getObject () ); + const std::vector &model = body->Model.getValues (); + std::set outSet; //< set of objects not to claim (childrens of childrens) // search for objects handled (claimed) by the features - for(std::vector::const_iterator it = Model.begin();it!=Model.end();++it){ - if (*it == NULL) continue; - Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(*it); - if (vp == NULL) continue; - std::vector children = vp->claimChildren(); - for (std::vector::const_iterator ch = children.begin(); ch != children.end(); ch++) { - if ((*ch) != NULL) - OutSet.insert(*ch); - } + for( auto obj: model){ + if (!obj) { continue; } + Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj ); + if (!vp) { continue; } + + auto children = vp->claimChildren(); + std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr); } // remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct std::vector Result; - // Clame for the base feature first - if (bodyObj->BaseFeature.getValue()) { - Result.push_back (bodyObj->BaseFeature.getValue()); + if (body->Origin.getValue()) { // Clame for the Origin + Result.push_back (body->Origin.getValue()); + } + if (body->BaseFeature.getValue()) { // Clame for the base feature + Result.push_back (body->BaseFeature.getValue()); } - // return the rest as claim set of the Body - for (std::vector::const_iterator it = Model.begin();it!=Model.end();++it) { - if (OutSet.find(*it) == OutSet.end()) - Result.push_back(*it); - } + // claim for rest content not claimed by any other features + std::remove_copy_if (model.begin(), model.end(), std::back_inserter (Result), + [outSet] (App::DocumentObject* obj) { + return outSet.find (obj) != outSet.end(); + } ); return Result; } @@ -160,14 +161,21 @@ std::vector ViewProviderBody::claimChildren3D(void)const PartDesign::Body* body = static_cast(getObject()); const std::vector & features = body->Model.getValues(); + App::DocumentObject *originObj = body->Origin.getValue(); + App::DocumentObject *baseFeature = body->BaseFeature.getValue(); std::vector rv; - rv.push_back( body->BaseFeature.getValue() ); - rv.insert( rv.end(), features.begin(), features.end()); + if (body->Origin.getValue()) { // Add origin + rv.push_back (body->Origin.getValue()); + } + if ( body->BaseFeature.getValue() ) { // Add Base Feature + rv.push_back (body->BaseFeature.getValue()); + } + + std::copy (features.begin(), features.end(), std::back_inserter (rv) ); // TODO Check what will happen if BaseFature will be shared by severral bodies (2015-08-04, Fat-Zer) return rv; - } //void ViewProviderBody::updateTree() @@ -194,6 +202,7 @@ std::vector ViewProviderBody::claimChildren3D(void)const //} bool ViewProviderBody::onDelete ( const std::vector &) { + // TODO May be do it conditionally? (2015-09-05, Fat-Zer) Gui::Command::doCommand(Gui::Command::Doc, "App.getDocument(\"%s\").getObject(\"%s\").removeModelFromDocument()" ,getObject()->getDocument()->getName(), getObject()->getNameInDocument()); @@ -202,18 +211,34 @@ bool ViewProviderBody::onDelete ( const std::vector &) { void ViewProviderBody::updateData(const App::Property* prop) { - //Base::Console().Error("ViewProviderBody::updateData for %s\n", getObject()->getNameInDocument()); - //if (ActiveGuiDoc == NULL) - // // PartDesign workbench not active - // return PartGui::ViewProviderPart::updateData(prop); - //if ((/*prop->getTypeId() == App::PropertyBool::getClassTypeId() && strcmp(prop->getName(),"IsActive") == 0) ||*/ - // (prop->getTypeId() == App::PropertyLink::getClassTypeId() && strcmp(prop->getName(),"Tip") == 0) || - // (prop->getTypeId() == App::PropertyLinkList::getClassTypeId() && strcmp(prop->getName(),"Model") == 0)) - // // updateTree(); - - // Update the visual size of datums PartDesign::Body* body = static_cast(getObject()); + + if (prop == &body->Model || prop == &body->BaseFeature) { + // update sizes of origins and datums + // TODO Write this (2015-09-05, Fat-Zer) + } else if (prop == &body->Tip) { + // Adjust the internals to display + App::DocumentObject *tip = body->Tip.getValue (); + + if (tip) { + Gui::ViewProvider *vp = Gui::Application::Instance->getViewProvider (tip); + if (vp) { + SoNode *tipRoot = vp->getRoot (); + if ( pcBodyTip->findChild (tipRoot) == -1 ) { + pcBodyTip->removeAllChildren (); + pcBodyTip->addChild ( tipRoot ); + } + // Else our tip is already shown + } else { + pcBodyTip->removeAllChildren (); + } + } else { + pcBodyTip->removeAllChildren (); + } + } + + // TODO rewrite this, it's quite a hacky way of notifying (2015-09-05, Fat-Zer) std::vector features = body->Model.getValues(); for (std::vector::const_iterator f = features.begin(); f != features.end(); f++) { App::PropertyPlacement* plm = NULL; diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.h b/src/Mod/PartDesign/Gui/ViewProviderBody.h index e12817e9e..b5050b6b9 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.h +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.h @@ -26,13 +26,15 @@ #include +class SoGroup; +class SoSeparator; namespace PartDesignGui { /** ViewProvider of the Body feature * This class manage the visual apperance of the features in the - * Body feature. That mean while editing only the tip feature is - * visible. If the Body is not active it shows only the result shape (tip). + * Body feature. That mean while editing all visible features are shown. + * If the Body is not active it shows only the result shape (tip). * \author jriegel */ class PartDesignGuiExport ViewProviderBody : public PartGui::ViewProviderPart @@ -63,9 +65,9 @@ public: void updateData(const App::Property* prop); private: - /// group used to store children collected by claimChildren3D() + /// group used to store children collected by claimChildren3D() in the through (edit) mode. SoGroup *pcBodyChildren; - /// group used to show the tip element in "edit" mode + /// The tip node used to display the Body when it doesn't edited. SoGroup *pcBodyTip; /// Update the children's highlighting diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp index e635fc4e5..add048f39 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp @@ -51,7 +51,7 @@ # include #endif -#include +#include #include #include #include @@ -311,11 +311,11 @@ Base::BoundBox3d ViewProviderDatum::getRelevantExtents() if (body != NULL) bbox = body->getBoundBox(); else { - App::Part* part = getPartFor(this->getObject(),false); + App::DocumentObjectGroup* group = App::DocumentObjectGroup::getGroupOfObject(this->getObject()); std::vector objs; - if(part) - objs = part->getObjectsOfType(Part::Feature::getClassTypeId()); + if(group) + objs = group->getObjectsOfType(Part::Feature::getClassTypeId()); else objs = this->getObject()->getDocument()->getObjectsOfType(Part::Feature::getClassTypeId()); diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 6a704825f..5b2c01db4 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -28,7 +28,6 @@ # include #endif -#include #include #include #include @@ -67,36 +66,36 @@ Workbench::~Workbench() { void Workbench::_switchToDocument(const App::Document* doc) { - if (doc == NULL) return; - - PartDesign::Body* activeBody = NULL; - std::vector bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId()); - - // No tip, so build up structure or migrate - if (!doc->Tip.getValue()) - { - ;/*if (doc->countObjects() == 0){ - buildDefaultPartAndBody(doc); - activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); - assert(activeBody); - } else { - // empty document with no tip, so do migration - _doMigration(doc); - activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); - assert(activeBody); - } - */ - } - else - { - App::Part *docPart = dynamic_cast(doc->Tip.getValue()); - if (docPart) { - App::Part *viewPart = Gui::Application::Instance->activeView()->getActiveObject("Part"); - if (viewPart != docPart) - Gui::Application::Instance->activeView()->setActiveObject(docPart, "Part"); - //if (docPart->countObjectsOfType(PartDesign::Body::getClassTypeId()) < 1) - // setUpPart(docPart); -// TODO Commented out for thurther remove or rewrite (2015-08-27, Fat-Zer) +// TODO Commented out for thurther remove or rewrite (2015-09-04, Fat-Zer) +// if (doc == NULL) return; +// +// PartDesign::Body* activeBody = NULL; +// std::vector bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId()); +// +// // No tip, so build up structure or migrate +// if (!doc->Tip.getValue()) +// { +// ;/*if (doc->countObjects() == 0){ +// buildDefaultPartAndBody(doc); +// activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); +// assert(activeBody); +// } else { +// // empty document with no tip, so do migration +// _doMigration(doc); +// activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); +// assert(activeBody); +// } +// */ +// } +// else +// { +// App::Part *docPart = dynamic_cast(doc->Tip.getValue()); +// if (docPart) { +// App::Part *viewPart = Gui::Application::Instance->activeView()->getActiveObject("Part"); +// if (viewPart != docPart) +// Gui::Application::Instance->activeView()->setActiveObject(docPart, "Part"); +// //if (docPart->countObjectsOfType(PartDesign::Body::getClassTypeId()) < 1) +// // setUpPart(docPart); // PartDesign::Body *tempBody = dynamic_cast (docPart->getObjectsOfType(PartDesign::Body::getClassTypeId()).front()); // if (tempBody) { // PartDesign::Body *viewBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); @@ -109,15 +108,15 @@ void Workbench::_switchToDocument(const App::Document* doc) // if (activeBody != viewBody) // Gui::Application::Instance->activeView()->setActiveObject(activeBody, PDBODYKEY); // } - } - } - - /*if (activeBody == NULL) { - QMessageBox::critical(Gui::getMainWindow(), QObject::tr("Could not create body"), - QObject::tr("No body was found in this document, and none could be created. Please report this bug." - "We recommend you do not use this document with the PartDesign workbench until the bug has been fixed." - )); - }*/ +// } +// } +// +// /*if (activeBody == NULL) { +// QMessageBox::critical(Gui::getMainWindow(), QObject::tr("Could not create body"), +// QObject::tr("No body was found in this document, and none could be created. Please report this bug." +// "We recommend you do not use this document with the PartDesign workbench until the bug has been fixed." +// )); +// }*/ } void Workbench::slotActiveDocument(const Gui::Document& Doc)