From 2c2d155ee9060db08adfe1bd4b0c04a451293107 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Wed, 2 Sep 2015 07:22:54 +0300 Subject: [PATCH] OriginGroup: add new abstraction layer between the Part and the GeoFeatureGroup --- src/App/Application.cpp | 10 +- src/App/CMakeLists.txt | 7 +- src/App/GeoFeatureGroup.cpp | 76 +++++++- src/App/GeoFeatureGroup.h | 22 ++- src/App/GeoFeatureGroupPy.xml | 2 +- src/App/Origin.cpp | 4 +- src/App/OriginGroup.cpp | 122 ++++++++++++ src/App/OriginGroup.h | 76 ++++++++ src/App/OriginGroupPy.xml | 19 ++ src/App/OriginGroupPyImp.cpp | 34 ++++ src/App/Part.cpp | 8 +- src/App/Part.h | 9 +- src/App/PartPy.xml | 4 +- src/Gui/Application.cpp | 8 +- src/Gui/CMakeLists.txt | 2 + src/Gui/ViewProviderGeoFeatureGroup.cpp | 32 +--- src/Gui/ViewProviderOriginGroup.cpp | 178 ++++++++++++++++++ src/Gui/ViewProviderOriginGroup.h | 62 ++++++ src/Gui/ViewProviderPart.cpp | 149 ++------------- src/Gui/ViewProviderPart.h | 27 +-- src/Mod/Assembly/App/AppAssemblyPy.cpp | 22 --- src/Mod/Assembly/App/AppAssemblyPy.cpp.orig | 77 +------- src/Mod/PartDesign/Gui/Command.cpp | 99 +++++----- src/Mod/PartDesign/Gui/CommandBody.cpp | 4 +- .../PartDesign/Gui/TaskDatumParameters.cpp | 36 ++-- src/Mod/PartDesign/Gui/TaskFeaturePick.cpp | 24 ++- .../Gui/TaskLinearPatternParameters.cpp | 53 +++--- .../PartDesign/Gui/TaskMirroredParameters.cpp | 58 +++--- .../Gui/TaskPolarPatternParameters.cpp | 53 +++--- .../Gui/TaskRevolutionParameters.cpp | 34 ++-- .../Gui/TaskTransformedParameters.cpp | 8 +- src/Mod/PartDesign/Gui/Utils.cpp | 62 +++--- src/Mod/PartDesign/Gui/Utils.h | 11 -- 33 files changed, 835 insertions(+), 557 deletions(-) create mode 100644 src/App/OriginGroup.cpp create mode 100644 src/App/OriginGroup.h create mode 100644 src/App/OriginGroupPy.xml create mode 100644 src/App/OriginGroupPyImp.cpp create mode 100644 src/Gui/ViewProviderOriginGroup.cpp create mode 100644 src/Gui/ViewProviderOriginGroup.h diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 0be12799f..57da57783 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -76,7 +76,6 @@ #include #include "GeoFeature.h" -#include "GeoFeatureGroup.h" #include "FeatureTest.h" #include "FeaturePython.h" #include "ComplexGeoData.h" @@ -95,8 +94,10 @@ #include "Annotation.h" #include "MeasureDistance.h" #include "Placement.h" -#include "OriginFeature.h" +#include "GeoFeatureGroup.h" +#include "OriginGroup.h" #include "Part.h" +#include "OriginFeature.h" #include "Origin.h" #include "MaterialObject.h" #include "Expression.h" @@ -1122,8 +1123,6 @@ void Application::initTypes(void) App ::Document ::init(); App ::DocumentObjectGroup ::init(); App ::DocumentObjectGroupPython ::init(); - App ::GeoFeatureGroup ::init(); - App ::GeoFeatureGroupPython ::init(); App ::DocumentObjectFileIncluded::init(); App ::InventorObject ::init(); App ::VRMLObject ::init(); @@ -1136,6 +1135,9 @@ void Application::initTypes(void) App ::OriginFeature ::init(); App ::Plane ::init(); App ::Line ::init(); + App ::GeoFeatureGroup ::init(); + App ::GeoFeatureGroupPython ::init(); + App ::OriginGroup ::init(); App ::Part ::init(); App ::Origin ::init(); diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index 6fdee404c..1fd9d474a 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -35,6 +35,7 @@ generate_from_xml(DocumentObjectPy) generate_from_xml(DocumentObjectGroupPy) generate_from_xml(GeoFeaturePy) generate_from_xml(GeoFeatureGroupPy) +generate_from_xml(OriginGroupPy) generate_from_xml(PartPy) generate_from_xml(ComplexGeoDataPy) @@ -49,6 +50,7 @@ SET(FreeCADApp_XML_SRCS DocumentObjectPy.xml GeoFeaturePy.xml GeoFeatureGroupPy.xml + OriginGroupPy.xml PartPy.xml DocumentPy.xml PropertyContainerPy.xml @@ -65,7 +67,6 @@ SET(Document_CPP_SRCS DocumentObjectFileIncluded.cpp DocumentObjectGroup.cpp DocumentObjectGroupPyImp.cpp - PartPyImp.cpp GeoFeaturePyImp.cpp DocumentObjectPyImp.cpp DocumentObserver.cpp @@ -77,6 +78,9 @@ SET(Document_CPP_SRCS GeoFeature.cpp GeoFeatureGroupPyImp.cpp GeoFeatureGroup.cpp + OriginGroupPyImp.cpp + OriginGroup.cpp + PartPyImp.cpp Part.cpp Origin.cpp Path.cpp @@ -108,6 +112,7 @@ SET(Document_HPP_SRCS FeatureTest.h GeoFeature.h GeoFeatureGroup.h + OriginGroup.h Part.h Origin.h Path.h diff --git a/src/App/GeoFeatureGroup.cpp b/src/App/GeoFeatureGroup.cpp index f31218cac..4cbb6bb4e 100644 --- a/src/App/GeoFeatureGroup.cpp +++ b/src/App/GeoFeatureGroup.cpp @@ -60,14 +60,84 @@ void GeoFeatureGroup::transformPlacement(const Base::Placement &transform) this->Placement.setValue(plm); } -GeoFeatureGroup* GeoFeatureGroup::getGroupOfObject(const DocumentObject* obj) +std::vector GeoFeatureGroup::getGeoSubObjects () const { + const auto & objs = Group.getValues(); + + std::set processedGroups; + std::set rvSet; + std::set curSearchSet (objs.begin(), objs.end()); + + processedGroups.insert ( this ); + + while ( !curSearchSet.empty() ) { + rvSet.insert ( curSearchSet.begin (), curSearchSet.end () ); + + std::set nextSearchSet; + for ( auto obj: curSearchSet) { + if ( isNonGeoGroup (obj) ) { + const App::DocumentObjectGroup *grp = static_cast (obj); + // Check if we havent already processed the element may happen in case of nontree structure + // Note: if the condition is false this generally indicates malformed structure + if ( processedGroups.find (grp) == processedGroups.end() ) { + processedGroups.insert ( grp ); + const auto & objs = grp->Group.getValues(); + nextSearchSet.insert (objs.begin(), objs.end()); + } + } + } + nextSearchSet.swap (curSearchSet); + } + + return std::vector ( rvSet.begin(), rvSet.end() ); +} + +bool GeoFeatureGroup::geoHasObject (const DocumentObject* obj) const { + const auto & objs = Group.getValues(); + + if (!obj) { + return false; + } + + std::set processedGroups; + std::set curSearchSet (objs.begin(), objs.end()); + + processedGroups.insert ( this ); + + while ( !curSearchSet.empty() ) { + if ( curSearchSet.find (obj) != curSearchSet.end() ) { + return true; + } + std::set nextSearchSet; + for ( auto obj: curSearchSet) { + if ( isNonGeoGroup (obj) ) { + const App::DocumentObjectGroup *grp = static_cast (obj); + if ( processedGroups.find (grp) == processedGroups.end() ) { + processedGroups.insert ( grp ); + const auto & objs = grp->Group.getValues(); + nextSearchSet.insert (objs.begin(), objs.end()); + } + } + } + nextSearchSet.swap (curSearchSet); + } + return false; +} + +GeoFeatureGroup* GeoFeatureGroup::getGroupOfObject(const DocumentObject* obj, bool indirect) { const Document* doc = obj->getDocument(); std::vector grps = doc->getObjectsOfType(GeoFeatureGroup::getClassTypeId()); for (std::vector::const_iterator it = grps.begin(); it != grps.end(); ++it) { GeoFeatureGroup* grp = (GeoFeatureGroup*)(*it); - if (grp->hasObject(obj)) - return grp; + if ( indirect ) { + if (grp->geoHasObject(obj)) { + return grp; + } + } else { + if (grp->hasObject(obj)) { + return grp; + } + } } return 0; diff --git a/src/App/GeoFeatureGroup.h b/src/App/GeoFeatureGroup.h index c25f2717b..e3aed4c60 100644 --- a/src/App/GeoFeatureGroup.h +++ b/src/App/GeoFeatureGroup.h @@ -46,8 +46,7 @@ public: /** * @brief transformPlacement applies transform to placement of this shape. * Override this function to propagate the change of placement to base - * features, for example. By the time of writing this comment, the function - * was only called by alignment task (Edit->Alignment) + * features. * @param transform (input). */ virtual void transformPlacement(const Base::Placement &transform); @@ -55,13 +54,28 @@ public: GeoFeatureGroup(void); virtual ~GeoFeatureGroup(); + /// Returns all geometrically controlled objects: all objects of this group and it's non-geo subgroups + std::vector getGeoSubObjects () const; + + /// Returns true if either the group or one of it's non-geo subgroups has the object + bool geoHasObject (const DocumentObject* obj) const; + /** Returns the geo feature group which contains this object. * In case this object is not part of any geoFeatureGroup 0 is returned. * Unlike DocumentObjectGroup::getGroupOfObject serches only for GeoFeatureGroups + * @param obj the object to search for + * @param indirect if true return if the group that so-called geoHas the object, @see geoHasObject() + * default is true */ - static GeoFeatureGroup* getGroupOfObject(const DocumentObject* obj); + static GeoFeatureGroup* getGroupOfObject(const DocumentObject* obj, bool indirect=true); - /// returns the type name of the ViewProvider + /// Returns true if the given DocumentObject is DocumentObjectGroup but not GeoFeatureGroup + static bool isNonGeoGroup(const DocumentObject* obj) { + return obj->isDerivedFrom ( App::DocumentObjectGroup::getClassTypeId () ) && + !obj->isDerivedFrom ( App::GeoFeatureGroup::getClassTypeId () ); + } + + /// Returns the type name of the ViewProvider virtual const char* getViewProviderName(void) const { return "Gui::ViewProviderGeoFeatureGroup"; } diff --git a/src/App/GeoFeatureGroupPy.xml b/src/App/GeoFeatureGroupPy.xml index e26a767d9..a5ffdccec 100644 --- a/src/App/GeoFeatureGroupPy.xml +++ b/src/App/GeoFeatureGroupPy.xml @@ -11,7 +11,7 @@ FatherNamespace="App"> - This class handles document objects in Part + This class handles placeable group of document objects diff --git a/src/App/Origin.cpp b/src/App/Origin.cpp index 859b6fc81..e27db624e 100644 --- a/src/App/Origin.cpp +++ b/src/App/Origin.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include "OriginFeature.h" #include "Origin.h" @@ -123,7 +123,7 @@ App::DocumentObjectExecReturn *Origin::execute(void) { setError (); return new App::DocumentObjectExecReturn ( ex.what () ); } - // purgeError (); + return DocumentObject::execute (); } diff --git a/src/App/OriginGroup.cpp b/src/App/OriginGroup.cpp new file mode 100644 index 000000000..f4b6b4d6a --- /dev/null +++ b/src/App/OriginGroup.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (c) Alexander Golubev (Fat-Zer) 2015 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "OriginGroup.h" + +#ifndef _PreComp_ +#endif + +#include + +#include +#include "Origin.h" + +#include "GeoFeature.h" + +using namespace App; + +PROPERTY_SOURCE(App::OriginGroup, App::GeoFeatureGroup); + +OriginGroup::OriginGroup () { + ADD_PROPERTY_TYPE ( Origin, (0), 0, App::Prop_Hidden, "Origin linked to the group" ); +} + +OriginGroup::~OriginGroup () +{ } + +App::Origin *OriginGroup::getOrigin () const { + App::DocumentObject *originObj = Origin.getValue (); + + 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 ); + } +} + +App::OriginGroup *OriginGroup::getGroupOfObject (const DocumentObject* obj, bool indirect) { + const Document* doc = obj->getDocument(); + std::vector grps = doc->getObjectsOfType ( OriginGroup::getClassTypeId() ); + for (auto grpObj: grps) { + OriginGroup* grp = static_cast (grpObj); + if ( indirect ) { + if ( grp->geoHasObject (obj) ) { + return grp; + } + } else { + if ( grp->hasObject (obj) ) { + return grp; + } + } + } + + return 0; +} + +short OriginGroup::mustExecute() const { + if (Origin.isTouched ()) { + return 1; + } else { + return GeoFeatureGroup::mustExecute(); + } +} + +App::DocumentObjectExecReturn *OriginGroup::execute() { + try { // try to find all base axis and planes in the origin + App::Origin *origin = getOrigin (); + } catch (const Base::Exception &ex) { + setError (); + return new App::DocumentObjectExecReturn ( ex.what () ); + } + + return GeoFeatureGroup::execute (); +} + +void OriginGroup::setupObject () { + 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); + + GeoFeatureGroup::setupObject (); +} + +void OriginGroup::unsetupObject () { + App::DocumentObject *origin = Origin.getValue (); + if (origin && !origin->isDeleting ()) { + origin->getDocument ()->remObject (origin->getNameInDocument()); + } + + GeoFeatureGroup::unsetupObject (); +} diff --git a/src/App/OriginGroup.h b/src/App/OriginGroup.h new file mode 100644 index 000000000..22af7ae2a --- /dev/null +++ b/src/App/OriginGroup.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (c) Alexander Golubev (Fat-Zer) 2015 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef ORIGINGROUP_H_QHTU73IF +#define ORIGINGROUP_H_QHTU73IF + +#include "GeoFeatureGroup.h" +#include "PropertyLinks.h" + +namespace App { +class Origin; + +/** + * Represents an abstact placeable group of objects with an associated Origin + */ +class OriginGroup: public App::GeoFeatureGroup +{ + PROPERTY_HEADER(App::OriginGroup); +public: + OriginGroup (); + virtual ~OriginGroup (); + + /// Returns the origin link or throws an exception + App::Origin *getOrigin () const; + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName () const { + return "Gui::ViewProviderOriginGroup"; + } + + /** + * Returns the origin group which contains this object. + * In case this object is not part of any geoFeatureGroup 0 is returned. + * @param obj the object to search for + * @param indirect if true return if the group that so-called geoHas the object, @see geoHasObject() + * default is true + */ + static OriginGroup* getGroupOfObject (const DocumentObject* obj, bool indirect=true); + + /// Returns true on changing OriginFeature set + virtual short mustExecute () const; + + /// Origin linked to the group + PropertyLink Origin; + +protected: + /// Checks integrity of the Origin + virtual App::DocumentObjectExecReturn *execute (); + /// Creates the corresponding Origin object + virtual void setupObject (); + /// Removes all planes and axis if they are still linked to the document + virtual void unsetupObject (); +}; + +} /* App */ + +#endif /* end of include guard: ORIGINGROUP_H_QHTU73IF */ diff --git a/src/App/OriginGroupPy.xml b/src/App/OriginGroupPy.xml new file mode 100644 index 000000000..f85670446 --- /dev/null +++ b/src/App/OriginGroupPy.xml @@ -0,0 +1,19 @@ + + + + + + This class handles placable group of document objects with an Origin + + + + + diff --git a/src/App/OriginGroupPyImp.cpp b/src/App/OriginGroupPyImp.cpp new file mode 100644 index 000000000..78757021b --- /dev/null +++ b/src/App/OriginGroupPyImp.cpp @@ -0,0 +1,34 @@ + +#include "PreCompiled.h" + +#include "App/OriginGroup.h" + +// inclusion of the generated files (generated out of OriginGroupPy.xml) +#include "OriginGroupPy.h" +#include "OriginGroupPy.cpp" + +using namespace App; + +// returns a string which represents the object e.g. when printed in python +std::string OriginGroupPy::representation(void) const +{ + return std::string(""); +} + + + + + + + +PyObject *OriginGroupPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int OriginGroupPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + + diff --git a/src/App/Part.cpp b/src/App/Part.cpp index 30ce568fa..67b0c0470 100644 --- a/src/App/Part.cpp +++ b/src/App/Part.cpp @@ -35,18 +35,14 @@ using namespace App; -PROPERTY_SOURCE(App::Part, App::GeoFeatureGroup) - +PROPERTY_SOURCE(App::Part, App::OriginGroup) //=========================================================================== -// Feature +// Part //=========================================================================== -const char* Part::BaseplaneTypes[3] = {"XY_Plane", "XZ_Plane", "YZ_Plane"}; -const char* Part::BaselineTypes[3] = {"X_Axis", "Y_Axis", "Z_Axis"}; - Part::Part(void) { ADD_PROPERTY(Type,("")); diff --git a/src/App/Part.h b/src/App/Part.h index cc4060e83..3827332f1 100644 --- a/src/App/Part.h +++ b/src/App/Part.h @@ -24,7 +24,7 @@ #ifndef APP_Part_H #define APP_Part_H -#include "GeoFeatureGroup.h" +#include "OriginGroup.h" #include "PropertyLinks.h" @@ -35,7 +35,7 @@ namespace App /** Base class of all geometric document objects. */ -class AppExport Part : public App::GeoFeatureGroup +class AppExport Part : public App::OriginGroup { PROPERTY_HEADER(App::Part); @@ -75,7 +75,6 @@ public: App::PropertyColor Color; //@} - /// Constructor Part(void); virtual ~Part(); @@ -85,11 +84,7 @@ public: return "Gui::ViewProviderPart"; } - virtual PyObject *getPyObject(void); - - static const char* BaseplaneTypes[3]; - static const char* BaselineTypes[3]; }; //typedef App::FeaturePythonT PartPython; diff --git a/src/App/PartPy.xml b/src/App/PartPy.xml index 3772998ef..fd1e2c957 100644 --- a/src/App/PartPy.xml +++ b/src/App/PartPy.xml @@ -1,13 +1,13 @@ diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 9e98ca9c8..36aa9f9c9 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -98,7 +98,6 @@ #include "ViewProviderPythonFeature.h" #include "ViewProviderDocumentObjectGroup.h" #include "ViewProviderGeometryObject.h" -#include "ViewProviderGeoFeatureGroup.h" #include "ViewProviderInventorObject.h" #include "ViewProviderVRMLObject.h" #include "ViewProviderAnnotation.h" @@ -106,6 +105,8 @@ #include "ViewProviderPlacement.h" #include "ViewProviderPlane.h" #include "ViewProviderLine.h" +#include "ViewProviderGeoFeatureGroup.h" +#include "ViewProviderOriginGroup.h" #include "ViewProviderPart.h" #include "ViewProviderOrigin.h" #include "ViewProviderMaterialObject.h" @@ -1533,8 +1534,6 @@ void Application::initTypes(void) Gui::ViewProviderDocumentObjectGroup ::init(); Gui::ViewProviderDocumentObjectGroupPython ::init(); Gui::ViewProviderGeometryObject ::init(); - Gui::ViewProviderGeoFeatureGroup ::init(); - Gui::ViewProviderGeoFeatureGroupPython ::init(); Gui::ViewProviderInventorObject ::init(); Gui::ViewProviderVRMLObject ::init(); Gui::ViewProviderAnnotation ::init(); @@ -1546,6 +1545,9 @@ void Application::initTypes(void) Gui::ViewProviderPlacement ::init(); Gui::ViewProviderPlane ::init(); Gui::ViewProviderLine ::init(); + Gui::ViewProviderGeoFeatureGroup ::init(); + Gui::ViewProviderGeoFeatureGroupPython ::init(); + Gui::ViewProviderOriginGroup ::init(); Gui::ViewProviderPart ::init(); Gui::ViewProviderOrigin ::init(); Gui::ViewProviderMaterialObject ::init(); diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 5df779e1a..386b664d4 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -837,6 +837,7 @@ SET(Viewprovider_CPP_SRCS ViewProviderPlane.cpp ViewProviderLine.cpp ViewProviderGeoFeatureGroup.cpp + ViewProviderOriginGroup.cpp ViewProviderPart.cpp ViewProviderOrigin.cpp ViewProviderMaterialObject.cpp @@ -859,6 +860,7 @@ SET(Viewprovider_SRCS ViewProviderPlane.h ViewProviderLine.h ViewProviderGeoFeatureGroup.h + ViewProviderOriginGroup.h ViewProviderPart.h ViewProviderOrigin.h ViewProviderMaterialObject.h diff --git a/src/Gui/ViewProviderGeoFeatureGroup.cpp b/src/Gui/ViewProviderGeoFeatureGroup.cpp index d4f1b35c0..47b6fef04 100644 --- a/src/Gui/ViewProviderGeoFeatureGroup.cpp +++ b/src/Gui/ViewProviderGeoFeatureGroup.cpp @@ -51,41 +51,13 @@ ViewProviderGeoFeatureGroup::~ViewProviderGeoFeatureGroup() } std::vector ViewProviderGeoFeatureGroup::claimChildren3D(void) const { - App::GeoFeatureGroup *geoGroup = static_cast(getObject()); - const auto & objs = geoGroup->Group.getValues(); - - std::set rvSet; - // search recursively for all non-geoGroups and claim their children either - std::set curSearchSet (objs.begin(), objs.end()); - - for ( auto objIt = curSearchSet.begin(); !curSearchSet.empty(); - curSearchSet.erase (objIt), objIt = curSearchSet.begin() ) { - // Check if we havent already processed the element may happen in case of nontree structure - // Note: this case generally indicates malformed structure - if ( rvSet.find (*objIt) != rvSet.end() ) { - continue; - } - - rvSet.insert (*objIt); - - if ( (*objIt)->isDerivedFrom ( App::DocumentObjectGroup::getClassTypeId () ) && - !(*objIt)->isDerivedFrom ( App::GeoFeatureGroup::getClassTypeId () ) ) { - - // add the non-GeoGroup's content to search - App::DocumentObjectGroup *group = static_cast (*objIt); - const auto & objs = group->Group.getValues(); - - curSearchSet.insert ( objs.begin(), objs.end() ); - } - } - - return std::vector ( rvSet.begin(), rvSet.end() ); + return static_cast(getObject())->getGeoSubObjects (); } void ViewProviderGeoFeatureGroup::attach(App::DocumentObject* pcObject) { - addDisplayMaskMode(pcGroupChildren, "Group"); Gui::ViewProviderDocumentObjectGroup::attach(pcObject); + addDisplayMaskMode(pcGroupChildren, "Group"); } void ViewProviderGeoFeatureGroup::setDisplayMode(const char* ModeName) diff --git a/src/Gui/ViewProviderOriginGroup.cpp b/src/Gui/ViewProviderOriginGroup.cpp new file mode 100644 index 000000000..b70c889c2 --- /dev/null +++ b/src/Gui/ViewProviderOriginGroup.cpp @@ -0,0 +1,178 @@ +/*************************************************************************** + * Copyright (c) Alexander Golubev (Fat-Zer) 2015 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include +#include +#include + +#include "Application.h" +#include "Document.h" +#include "View3DInventor.h" +#include "View3DInventorViewer.h" +#include "ViewProviderOrigin.h" + +#include "ViewProviderOriginGroup.h" + + +using namespace Gui; + + +PROPERTY_SOURCE(Gui::ViewProviderOriginGroup, Gui::ViewProviderGeoFeatureGroup) + +ViewProviderOriginGroup::ViewProviderOriginGroup () +{ } + +ViewProviderOriginGroup::~ViewProviderOriginGroup () { + connectChangedObjectApp.disconnect(); + connectChangedObjectGui.disconnect(); +} + +std::vector ViewProviderOriginGroup::constructChildren ( + const std::vector &children ) const +{ + App::OriginGroup *group = static_cast ( getObject() ); + App::DocumentObject *originObj = group->Origin.getValue(); + + // Origin must be first + if (originObj) { + std::vector rv; + rv.push_back (originObj); + std::copy (children.begin(), children.end(), std::back_inserter (rv)); + return rv; + } else { // Generally shouldn't happen but must be handled in case origin is lost + return children; + } +} + + +std::vector ViewProviderOriginGroup::claimChildren () const { + return constructChildren ( ViewProviderGeoFeatureGroup::claimChildren () ); +} + +std::vector ViewProviderOriginGroup::claimChildren3D () const { + return constructChildren ( ViewProviderGeoFeatureGroup::claimChildren3D () ); +} + +void ViewProviderOriginGroup::attach(App::DocumentObject *pcObject) { + ViewProviderGeoFeatureGroup::attach ( pcObject ); + + App::Document *adoc = pcObject->getDocument (); + Gui::Document *gdoc = Gui::Application::Instance->getDocument ( adoc ) ; + + assert ( adoc ); + assert ( gdoc ); + + connectChangedObjectApp = adoc->signalChangedObject.connect ( + boost::bind ( &ViewProviderOriginGroup::slotChangedObjectApp, this, _1) ); + + connectChangedObjectGui = gdoc->signalChangedObject.connect ( + boost::bind ( &ViewProviderOriginGroup::slotChangedObjectGui, this, _1) ); +} + +void ViewProviderOriginGroup::updateData ( const App::Property* prop ) { + App::OriginGroup *group = static_cast ( getObject() ); + if ( group && prop == &group->Group ) { + updateOriginSize(); + } + + ViewProviderGeoFeatureGroup::updateData ( prop ); +} + +void ViewProviderOriginGroup::slotChangedObjectApp ( const App::DocumentObject& obj) { + App::OriginGroup *group = static_cast ( getObject() ); + if ( group && group->hasObject (&obj, /*recusive=*/ true ) ) { + updateOriginSize (); + } +} + +void ViewProviderOriginGroup::slotChangedObjectGui ( const Gui::ViewProviderDocumentObject& vp) { + if ( !vp.isDerivedFrom ( Gui::ViewProviderOrigin::getClassTypeId () ) ) { + // Ignore origins to avoid infinite recursion (not likely in a well-formed focument, + // but may happen in documents designed in old versions of assembly branch ) + App::OriginGroup *group = static_cast ( getObject() ); + App::DocumentObject *obj = vp.getObject (); + + if ( group && obj && group->hasObject (obj, /*recusive=*/ true ) ) { + updateOriginSize (); + } + } +} + +void ViewProviderOriginGroup::updateOriginSize () { + App::OriginGroup* group = static_cast ( getObject() ); + + // obtain an Origin and it's ViewProvider + App::Origin* origin = 0; + Gui::ViewProviderOrigin* vpOrigin = 0; + try { + origin = group->getOrigin (); + assert (origin); + + Gui::ViewProvider *vp = Gui::Application::Instance->getViewProvider(origin); + if (!vp) { + throw Base::Exception ("No view provider linked to the Origin"); + } + assert ( vp->isDerivedFrom ( Gui::ViewProviderOrigin::getClassTypeId () ) ); + vpOrigin = static_cast ( vp ); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what() ); + return; + } + + View3DInventorViewer* viewer = static_cast(this->getActiveView())->getViewer(); + SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion()); + + // calculate the bounding box for out content + SbBox3f bbox(0,0,0, 0,0,0); + for(App::DocumentObject* obj : group->getGeoSubObjects()) { + ViewProvider *vp = Gui::Application::Instance->getViewProvider(obj); + if (!vp) { + continue; + } + + bboxAction.apply ( vp->getRoot () ); + bbox.extendBy ( bboxAction.getBoundingBox () ); + }; + + // get the bounding box values + SbVec3f max = bbox.getMax(); + SbVec3f min = bbox.getMin(); + + Base::Vector3d size; + + for (uint_fast8_t i=0; i<3; i++) { + size[i] = std::max ( fabs ( max[i] ), fabs ( min[i] ) ); + if (size[i] < 1e-7) { // TODO replace the magic values (2015-08-31, Fat-Zer) + size[i] = ViewProviderOrigin::defaultSize(); + } + } + + vpOrigin->Size.setValue ( size * 1.3 ); +} diff --git a/src/Gui/ViewProviderOriginGroup.h b/src/Gui/ViewProviderOriginGroup.h new file mode 100644 index 000000000..c381f7745 --- /dev/null +++ b/src/Gui/ViewProviderOriginGroup.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (c) Alexander Golubev (Fat-Zer) 2015 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef VIEWPROVIDERORIGINGROUP_H_JIXBOPA7 +#define VIEWPROVIDERORIGINGROUP_H_JIXBOPA7 + +#include + +#include "ViewProviderGeoFeatureGroup.h" + +namespace Gui { + +class GuiExport ViewProviderOriginGroup: public ViewProviderGeoFeatureGroup +{ + PROPERTY_HEADER(Gui::ViewProviderOriginGroup); +public: + ViewProviderOriginGroup (); + virtual ~ViewProviderOriginGroup (); + + virtual std::vector claimChildren(void)const; + virtual std::vector claimChildren3D(void)const; + + virtual void attach(App::DocumentObject *pcObject); + virtual void updateData(const App::Property* prop); + + void updateOriginSize(); + +protected: + void slotChangedObjectApp ( const App::DocumentObject& obj ); + void slotChangedObjectGui ( const Gui::ViewProviderDocumentObject& obj ); + +private: + std::vector constructChildren ( + const std::vector &children ) const; + + boost::signals::connection connectChangedObjectApp; + boost::signals::connection connectChangedObjectGui; +}; + +} /* Gui */ + + +#endif /* end of include guard: VIEWPROVIDERORIGINGROUP_H_JIXBOPA7 */ diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index d45dec885..5ffb8ba81 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -29,161 +29,55 @@ #endif #include -#include -#include #include -/// Here the FreeCAD includes sorted by Base,App,Gui...... -#include "ViewProviderPart.h" -#include "ViewProviderOrigin.h" -#include "ViewProviderPlane.h" -#include "ViewProviderLine.h" -#include "Application.h" -#include "Command.h" +#include "ActiveObjectList.h" #include "BitmapFactory.h" -#include "Document.h" -#include "Tree.h" -#include "View3DInventor.h" -#include "View3DInventorViewer.h" +#include "Command.h" + +#include "ViewProviderPart.h" -#include "Base/Console.h" -#include -#include -#include using namespace Gui; -PROPERTY_SOURCE(Gui::ViewProviderPart, Gui::ViewProviderGeoFeatureGroup) +PROPERTY_SOURCE(Gui::ViewProviderPart, Gui::ViewProviderOriginGroup) /** * Creates the view provider for an object group. */ ViewProviderPart::ViewProviderPart() -{ - ADD_PROPERTY(Workbench,("PartDesignWorkbench")); -} +{ } ViewProviderPart::~ViewProviderPart() -{ - connection.disconnect(); -} +{ } /** + * TODO * Whenever a property of the group gets changed then the same property of all * associated view providers of the objects of the object group get changed as well. */ -void ViewProviderPart::onChanged(const App::Property* prop) -{ - ViewProviderGeoFeatureGroup::onChanged(prop); +void ViewProviderPart::onChanged(const App::Property* prop) { + ViewProviderOriginGroup::onChanged(prop); } -void ViewProviderPart::attach(App::DocumentObject *pcObj) -{ - connection = pcObj->getDocument()->signalChangedObject.connect(boost::bind(&ViewProviderPart::onObjectChanged, this, _1, _2)); - ViewProviderGeoFeatureGroup::attach(pcObj); -} - -void ViewProviderPart::updateData(const App::Property* prop) -{ - ViewProviderGeoFeatureGroup::updateData(prop); -} - -void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App::Property&) -{ - Gui::Document* gdoc = Gui::Application::Instance->getDocument ( getObject()->getDocument() ); - App::Part* part = static_cast(pcObject); - if ( &obj == pcObject || ( - obj.getTypeId() != App::Origin::getClassTypeId() && - obj.getTypeId() != App::Plane::getClassTypeId() && - obj.getTypeId() != App::Line::getClassTypeId() ) ) { - - View3DInventorViewer* viewer = static_cast(this->getActiveView())->getViewer(); - SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion()); - - //calculate for everything but datums - SbBox3f bbox(1e-9, 1e-9, 1e-9, 1e-9, 1e-9, 1e-9); - for(App::DocumentObject* obj : part->getObjects()) { - if(obj->getTypeId() != App::Origin::getClassTypeId() && - obj->getTypeId() != App::Plane::getClassTypeId() && - obj->getTypeId() != App::Line::getClassTypeId() ) { - - //getting crash on deletion PartDesign::Body object. no viewprovider. - ViewProvider *viewProvider = Gui::Application::Instance->getViewProvider(obj); - if (!viewProvider) - continue; - - bboxAction.apply(viewProvider->getRoot()); - bbox.extendBy(bboxAction.getBoundingBox()); - } - }; - - //get the bounding box values - SbVec3f max = bbox.getMax(); - SbVec3f min = bbox.getMin(); - - auto origins = part->getObjectsOfType(App::Origin::getClassTypeId()); - if (origins.empty()) - return; - App::Origin* origin = dynamic_cast(origins.front()); - if(!origin) - return; - - - Base::Vector3d size; - for (uint_fast8_t i=0; i<3; i++) { - size[i] = std::max ( fabs ( max[i] ), fabs ( min[i] ) ); - if (size[i] < 1e-7) { // TODO replace it with some non-magick value (2015-08-31, Fat-Zer) - size[i] = ViewProviderOrigin::defaultSize(); - } - } - - Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(origin); - if (vp) { - assert ( vp->isDerivedFrom ( Gui::ViewProviderOrigin::getClassTypeId () ) ); - Gui::ViewProviderOrigin *vpOrigin = static_cast (vp); - vpOrigin->Size.setValue ( size * 1.3 ); - } - } -} - - bool ViewProviderPart::doubleClicked(void) { - if(Workbench.getStrValue() != "") { - // assure the given workbench - Gui::Command::assureWorkbench( Workbench.getValue() ); - } - //make the part the active one - Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, this->getObject()->getNameInDocument()); + Gui::Command::doCommand(Gui::Command::Gui, + "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", + PARTKEY, this->getObject()->getNameInDocument()); return true; } -// commented out for thurther rewrite (2015-09-01, Fat-Zer) -// bool ViewProviderPart::onDelete(const std::vector &) -// { -// if(getActiveView()->getActiveObject(PARTKEY) == getObject()) -// Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', None)", PARTKEY); -// -// return true; -// } - -void ViewProviderPart::Restore(Base::XMLReader &reader) -{ - Visibility.StatusBits.set(9); // tmp. set - ViewProviderDocumentObject::Restore(reader); - Visibility.StatusBits.reset(9); // unset -} - - /** * Returns the pixmap for the list item. */ QIcon ViewProviderPart::getIcon() const { + // TODO Make a nice icon for the part (2015-09-01, Fat-Zer) QIcon groupIcon; groupIcon.addPixmap(QApplication::style()->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); @@ -192,21 +86,6 @@ QIcon ViewProviderPart::getIcon() const return groupIcon; } -void ViewProviderPart::setUpPart(const App::Part *part) -{ - // add the origin at the root of the Part - // first check if they already exist - std::vector origins = part->getObjectsOfType(App::Origin::getClassTypeId()); - - if ( origins.empty() ) { - std::string oname = part->getDocument()->getUniqueObjectName("Origin"); - Gui::Command::doCommand(Gui::Command::Doc,"Origin = App.activeDocument().addObject('App::Origin','%s')", oname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"Origin.Label = '%s'", QObject::tr("Origin").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(Origin)", part->getNameInDocument()); - } -} - - // Python feature ----------------------------------------------------------------------- namespace Gui { diff --git a/src/Gui/ViewProviderPart.h b/src/Gui/ViewProviderPart.h index 43e59282e..d9c4020ad 100644 --- a/src/Gui/ViewProviderPart.h +++ b/src/Gui/ViewProviderPart.h @@ -25,17 +25,13 @@ #define GUI_VIEWPROVIDER_ViewProviderPart_H -#include "ViewProviderGeoFeatureGroup.h" +#include "ViewProviderOriginGroup.h" #include "ViewProviderPythonFeature.h" -#include -#include - - namespace Gui { -class GuiExport ViewProviderPart : public ViewProviderGeoFeatureGroup +class GuiExport ViewProviderPart : public ViewProviderOriginGroup { PROPERTY_HEADER(Gui::ViewProviderPart); @@ -45,29 +41,12 @@ public: /// destructor. virtual ~ViewProviderPart(); - /// Name of the workbench which created that Part - App::PropertyString Workbench; - - void attach(App::DocumentObject *pcObject); - void updateData(const App::Property*); - void Restore(Base::XMLReader &reader); QIcon getIcon(void) const; - /// returns a list of all possible modes virtual bool doubleClicked(void); - -// virtual bool onDelete(const std::vector &); - - /// helper to set up the standard content of a Part Object - static void setUpPart(const App::Part *part); protected: /// get called by the container whenever a property has been changed - void onChanged(const App::Property* prop); - void getViewProviders(std::vector&) const; - void onObjectChanged(const App::DocumentObject&, const App::Property&); - -private: - boost::signals::connection connection; + virtual void onChanged(const App::Property* prop); }; typedef ViewProviderPythonFeatureT ViewProviderPartPython; diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp b/src/Mod/Assembly/App/AppAssemblyPy.cpp index 81c696b84..2a7b171c2 100644 --- a/src/Mod/Assembly/App/AppAssemblyPy.cpp +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp @@ -79,25 +79,6 @@ // return PartDesignGui::ActivePartObject->getPyObject(); //} -void setUpPart(App::Part *part); - -static PyObject * setUpPart(PyObject *self, PyObject *args) -{ - PyObject *object=0; - if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) ) - return NULL; - - - App::Part* part = static_cast(object)->getPartPtr(); - // Should be set! - assert(part); - - PartDesignGui::setUpPart(part); - - Py_Return; -} - - /* registration table */ struct PyMethodDef Assembly_methods[] = { //{"setActiveBody" ,setActiveBody ,METH_VARARGS, @@ -106,8 +87,5 @@ struct PyMethodDef Assembly_methods[] = { //{"getActiveBody" ,getActiveBody ,METH_NOARGS, // "getActiveBody() -- Get the PartBody object in work."}, - {"setUpPart" ,setUpPart ,METH_VARARGS, - "setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."}, - {NULL, NULL} /* end of table marker */ }; diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig b/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig index 7bc0f2455..6fc5870fb 100644 --- a/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig @@ -38,54 +38,9 @@ #include #include "ViewProviderBody.h" -#include "Workbench.h" +#include "Utils.h" -namespace PartDesignGui { - -// The names of the base planes. Note: The user-visible label is different from this -const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"}; - -} - -<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp -static PyObject * setActiveBody(PyObject *self, PyObject *args) -{ - PyObject *object=0; - if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) { - PartDesign::Body* Item = static_cast(object)->getBodyPtr(); - // Should be set! - assert(Item); - - // Set old body inactive if we are activating another body in the same document - if ((PartDesignGui::ActivePartObject != NULL) && - (PartDesignGui::ActivePartObject->getDocument() == Item->getDocument())) - PartDesignGui::ActivePartObject->IsActive.setValue(false); - PartDesignGui::ActivePartObject = Item; - PartDesignGui::ActiveAppDoc = Item->getDocument(); - PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc); - PartDesignGui::ActiveVp = dynamic_cast (PartDesignGui::ActiveGuiDoc->getViewProvider(Item)); - PartDesignGui::ActiveVp->show(); - Item->IsActive.setValue(true); - } else { - // This handles the case of deactivating the workbench - PartDesignGui::ActivePartObject=0; - PartDesignGui::ActiveGuiDoc =0; - PartDesignGui::ActiveAppDoc =0; - PartDesignGui::ActiveVp =0; - } - - Py_Return; -} -static PyObject * getActiveBody(PyObject *, PyObject *) -{ - if (PartDesignGui::ActivePartObject == NULL) { - return Py::_None(); - } - - return PartDesignGui::ActivePartObject->getPyObject(); -} -======= //static PyObject * setActiveBody(PyObject *self, PyObject *args) //{ // PyObject *object=0; @@ -123,43 +78,21 @@ static PyObject * getActiveBody(PyObject *, PyObject *) // // return PartDesignGui::ActivePartObject->getPyObject(); //} ->>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp - -void setUpPart(App::Part *part); - -static PyObject * setUpPart(PyObject *self, PyObject *args) -{ - PyObject *object=0; - if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) ) - return NULL; - - - App::Part* part = static_cast(object)->getPartPtr(); - // Should be set! - assert(part); - - PartDesignGui::Workbench::setUpPart(part); - - Py_Return; -} - /* registration table */ -<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp struct PyMethodDef Assembly_methods[] = { - {"setActiveBody" ,setActiveBody ,METH_VARARGS, - "setActiveBody(BodyObject) -- Set the PartBody object in work."}, -======= -struct PyMethodDef PartDesignGui_Import_methods[] = { //{"setActiveBody" ,setActiveBody ,METH_VARARGS, // "setActiveBody(BodyObject) -- Set the PartBody object in work."}, ->>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp //{"getActiveBody" ,getActiveBody ,METH_NOARGS, // "getActiveBody() -- Get the PartBody object in work."}, +<<<<<<< f03c0f9bdef9886ee45a086b02fa7ebaa99b6825:src/Mod/Assembly/App/AppAssemblyPy.cpp {"setUpPart" ,setUpPart ,METH_VARARGS, "setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."}, {NULL, NULL} /* end of table marker */ +======= + {NULL, NULL} /* end of table marker */ +>>>>>>> OriginGroup: add new abstraction layer between the Part and the GeoFeatureGroup:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp }; diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 5e5caf4bc..157e49b9e 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -43,7 +44,7 @@ #include #include #include - + #include #include @@ -236,7 +237,7 @@ CmdPartDesignNewSketch::CmdPartDesignNewSketch() void CmdPartDesignNewSketch::activated(int iMsg) { App::Document *doc = getDocument (); - PartDesign::Body *pcActiveBody = PartDesignGui::getBody( + PartDesign::Body *pcActiveBody = PartDesignGui::getBody( /*messageIfNot = */ PartDesignGui::assureModernWorkflow ( doc ) ); // No PartDesign feature without Body past FreeCAD 0.13 @@ -307,18 +308,8 @@ void CmdPartDesignNewSketch::activated(int iMsg) } if (!pcActiveBody->hasFeature(obj)) { - // TODO check what the heck is going on here (2015-08-31, Fat-Zer) - bool isBasePlane = false; - if(obj->isDerivedFrom(App::Plane::getClassTypeId())) { - App::Plane* pfeat = static_cast(obj); - for (unsigned i = 0; i < 3; i++) { - if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) { - isBasePlane = true; - break; - } - } - } - if (!isBasePlane) { + if ( !obj->isDerivedFrom ( App::Plane::getClassTypeId() ) ) { + // TODO check here if the plane associated with right part/body (2015-09-01, Fat-Zer) QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from other body"), QObject::tr("You have to select a face or plane from the active body!")); return; @@ -346,55 +337,48 @@ void CmdPartDesignNewSketch::activated(int iMsg) } else { // Get a valid plane from the user - std::vector status; - std::vector planes = getDocument()->getObjectsOfType(App::Plane::getClassTypeId()); - std::vector planestmp = getDocument()->getObjectsOfType(PartDesign::Plane::getClassTypeId()); - planes.insert(planes.end(), planestmp.begin(), planestmp.end()); - unsigned validPlanes = 0; - std::vector::const_iterator firstValidPlane = planes.end(); App::Part* pcActivePart = Gui::Application::Instance->activeView()->getActiveObject(PARTKEY); - for (std::vector::iterator p = planes.begin(); p != planes.end(); p++) { - // Check whether this plane is a base plane - bool base = false; - if((*p)->isDerivedFrom(App::Plane::getClassTypeId())) { - App::Plane* pfeat = static_cast(*p); - for (unsigned i = 0; i < 3; i++) { - if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) { - if(pcActivePart->hasObject(pfeat, true)) - status.push_back(PartDesignGui::TaskFeaturePick::basePlane); - else - status.push_back(PartDesignGui::TaskFeaturePick::invalidShape); - if (firstValidPlane == planes.end()) - firstValidPlane = p; - validPlanes++; - base = true; - break; - } + std::vector planes; + std::vector status; + + // Baseplanes are preaprooved + if ( pcActivePart ) { + try { + for ( auto plane: pcActivePart->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() ); } - if (base) continue; + } + std::vector datumPlanes = + getDocument()->getObjectsOfType(PartDesign::Plane::getClassTypeId()); + + for (auto plane: datumPlanes) { + planes.push_back ( plane ); // Check whether this plane belongs to the active body - if (!pcActiveBody->hasFeature(*p)) { - if(pcActivePart->hasObject(*p, true)) + if (!pcActiveBody->hasFeature(plane)) { + if ( pcActivePart && pcActivePart->hasObject ( plane, true ) ) { status.push_back(PartDesignGui::TaskFeaturePick::otherBody); - else + } else { status.push_back(PartDesignGui::TaskFeaturePick::otherPart); + } continue; } else { - if (pcActiveBody->isAfterInsertPoint(*p)) { + if (pcActiveBody->isAfterInsertPoint ( plane ) ) { status.push_back(PartDesignGui::TaskFeaturePick::afterTip); continue; } } // All checks passed - found a valid plane - if (firstValidPlane == planes.end()) - firstValidPlane = p; validPlanes++; status.push_back(PartDesignGui::TaskFeaturePick::validFeature); } @@ -1409,10 +1393,11 @@ void CmdPartDesignMirrored::activated(int iMsg) Gui::Command::doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])", FeatName.c_str(), sketch->getNameInDocument()); } - else { - doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), - App::Part::BaseplaneTypes[0]); - } + // TODO Check if default mirrored plane correctly set (2015-09-01, Fat-Zer) + // else { + // doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), + // App::Part::BaseplaneTypes[0]); + // } finishTransformed(cmd, FeatName); }; @@ -1456,10 +1441,11 @@ void CmdPartDesignLinearPattern::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])", FeatName.c_str(), sketch->getNameInDocument()); } - else { - doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), - App::Part::BaselineTypes[0]); - } + // TODO Check if default direction correctly set (2015-09-01, Fat-Zer) + // else { + // doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), + // App::Part::BaselineTypes[0]); + // } doCommand(Doc,"App.activeDocument().%s.Length = 100", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); @@ -1505,10 +1491,11 @@ void CmdPartDesignPolarPattern::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])", FeatName.c_str(), sketch->getNameInDocument()); } - else { - doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), - App::Part::BaselineTypes[0]); - } + // TODO Check if default axis correctly set (2015-09-01, Fat-Zer) + // else { + // doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(), + // App::Part::BaselineTypes[0]); + // } doCommand(Doc,"App.activeDocument().%s.Angle = 360", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index 5f49cd08b..4060a5ad2 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -101,8 +101,8 @@ void CmdPartDesignPart::activated(int iMsg) // TODO We really must to set label ourselfs? (2015-08-17, Fat-Zer) doCommand(Doc,"App.activeDocument().%s.Label = '%s'", PartName.c_str(), QObject::tr(PartName.c_str()).toUtf8().data()); - PartDesignGui::setUpPart(dynamic_cast(getDocument()->getObject(PartName.c_str()))); - doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, PartName.c_str()); + doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", + PARTKEY, PartName.c_str()); updateActive(); } diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 8d01cec27..3fc42346d 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -209,17 +209,19 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p ui->listOfModes->blockSignals(false); updateUI(); updateListOfModes(eMapMode(pcDatum->MapMode.getValue())); - + //temporary show coordinate systems for selection App::Part* part = getPartFor(DatumView->getObject(), false); - if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->setTemporaryVisibility(true, true); - } - } + if(part) { + try { + App::Origin *origin = part->getOrigin(); + ViewProviderOrigin* vpOrigin; + vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin->setTemporaryVisibility(true, true); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); + } + } if (pcDatum->Support.getSize() == 0) autoNext = true; else @@ -771,14 +773,16 @@ TaskDatumParameters::~TaskDatumParameters() //end temporary view mode of coordinate system App::Part* part = getPartFor(DatumView->getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->resetTemporaryVisibility(); - } + try { + App::Origin *origin = part->getOrigin(); + ViewProviderOrigin* vpOrigin; + vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin->resetTemporaryVisibility(); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); + } } - + delete ui; } diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index a7290dcec..21dfc329a 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -89,7 +89,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, enum { axisBit=0, planeBit = 1}; - // Note generally there shouldn't be more then one origin + // NOTE: generally there shouldn't be more then one origin std::map > originVisStatus; auto statusIt = status.cbegin(); @@ -110,18 +110,24 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, } else if ( (*objIt)->isDerivedFrom ( App::Line::getClassTypeId () ) ) { originVisStatus[ origin ].set (axisBit, true); } - - Gui::ViewProviderOrigin* vpo = static_cast ( - Gui::Application::Instance->getViewProvider(*objIt) ); - if (vpo) { - vpo->setTemporaryVisibility( originVisStatus[origin][axisBit], - originVisStatus[origin][planeBit]); - } - origins.push_back(vpo); } } } + // Setup the origin's temporary visability + for ( const auto & originPair: originVisStatus ) { + const auto &origin = originPair.first; + const auto &status = originPair.second; + + Gui::ViewProviderOrigin* vpo = static_cast ( + Gui::Application::Instance->getViewProvider ( origin ) ); + if (vpo) { + vpo->setTemporaryVisibility( originVisStatus[origin][axisBit], + originVisStatus[origin][planeBit]); + origins.push_back(vpo); + } + } + // TODO may be update origin API to show only some objects (2015-08-31, Fat-Zer) groupLayout()->addWidget(proxy); diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 46269e535..3303fbe6f 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -166,12 +166,14 @@ void TaskLinearPatternParameters::setupUI() //show the parts coordinate system axis for selection App::Part* part = getPartFor(getObject(), false); - if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->setTemporaryVisibility(true, false); + if(part) { + try { + App::Origin *origin = part->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 () ); } } } @@ -223,29 +225,20 @@ void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName); exitSelectionMode(); - } else if (selectionMode == reference) { - // Note: ReferenceSelection has already checked the selection for validity + } else { + // TODO check if this works correctly (2015-09-01, Fat-Zer) exitSelectionMode(); std::vector directions; App::DocumentObject* selObj; PartDesign::LinearPattern* pcLinearPattern = static_cast(getObject()); getReferencedSelection(pcLinearPattern, msg, selObj, directions); - pcLinearPattern->Direction.setValue(selObj, directions); + // Note: ReferenceSelection has already checked the selection for validity + if ( selectionMode == reference || selObj->isDerivedFrom ( App::Line::getClassTypeId () ) ) { + pcLinearPattern->Direction.setValue(selObj, directions); - recomputeFeature(); - updateUI(); - } else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr || - strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr || - strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) { - - std::vector directions; - App::DocumentObject* selObj; - PartDesign::LinearPattern* pcLinearPattern = static_cast(getObject()); - getReferencedSelection(pcLinearPattern, msg, selObj, directions); - pcLinearPattern->Direction.setValue(selObj, directions); - - recomputeFeature(); - updateUI(); + recomputeFeature(); + updateUI(); + } } } } @@ -366,12 +359,14 @@ TaskLinearPatternParameters::~TaskLinearPatternParameters() //hide the parts coordinate system axis for selection App::Part* part = getPartFor(getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->resetTemporaryVisibility(); - } + try { + App::Origin *origin = part->getOrigin(); + ViewProviderOrigin* vpOrigin; + vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin->resetTemporaryVisibility(); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); + } } delete ui; diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index 7d4ffd891..a7dcbbe70 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -132,22 +132,23 @@ void TaskMirroredParameters::setupUI() this->planeLinks.setCombo(*(ui->comboPlane)); ui->comboPlane->setEnabled(true); - App::DocumentObject* sketch = getSketchObject(); if (!sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId())) sketch = 0; this->fillPlanesCombo(planeLinks,static_cast(sketch)); updateUI(); - + //show the parts coordinate system axis for selection App::Part* part = getPartFor(getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin.front() )); - origin->setTemporaryVisibility(true, false); + try { + App::Origin *origin = part->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 () ); } } } @@ -179,30 +180,20 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg else removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName); exitSelectionMode(); - } else if (selectionMode == reference) { - // Note: ReferenceSelection has already checked the selection for validity + } else { + // TODO checkme (2015-09-01, Fat-Zer) exitSelectionMode(); - std::vector mirrorPlanes; App::DocumentObject* selObj; PartDesign::Mirrored* pcMirrored = static_cast(getObject()); getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes); - pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes); + // Note: ReferenceSelection has already checked the selection for validity + if ( selectionMode == reference || selObj->isDerivedFrom ( App::Plane::getClassTypeId () ) ) { + pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes); - recomputeFeature(); - updateUI(); - } else if( strstr(msg.pObjectName, App::Part::BaseplaneTypes[0]) == nullptr || - strstr(msg.pObjectName, App::Part::BaseplaneTypes[1]) == nullptr || - strstr(msg.pObjectName, App::Part::BaseplaneTypes[2]) == nullptr) { - - std::vector planes; - App::DocumentObject* selObj; - PartDesign::Mirrored* pcMirrored = static_cast(getObject()); - getReferencedSelection(pcMirrored, msg, selObj, planes); - pcMirrored->MirrorPlane.setValue(selObj, planes); - - recomputeFeature(); - updateUI(); + recomputeFeature(); + updateUI(); + } } } } @@ -278,15 +269,16 @@ TaskMirroredParameters::~TaskMirroredParameters() //hide the parts coordinate system axis for selection App::Part* part = getPartFor(getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->resetTemporaryVisibility(); - } + try { + App::Origin *origin = part->getOrigin(); + ViewProviderOrigin* vpOrigin; + vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin->resetTemporaryVisibility(); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); + } } - - + delete ui; if (proxy) delete proxy; diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp index 3dfb4e652..7dafa2726 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -161,12 +161,14 @@ void TaskPolarPatternParameters::setupUI() //show the parts coordinate system axis for selection App::Part* part = getPartFor(getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->setTemporaryVisibility(true, false); - } + try { + App::Origin *origin = part->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 () ); + } } } @@ -217,29 +219,20 @@ void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges& else removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName); exitSelectionMode(); - } else if (selectionMode == reference) { - // Note: ReferenceSelection has already checked the selection for validity + } else { + // TODO checkme (2015-09-01, Fat-Zer) exitSelectionMode(); std::vector axes; App::DocumentObject* selObj; PartDesign::PolarPattern* pcPolarPattern = static_cast(getObject()); getReferencedSelection(pcPolarPattern, msg, selObj, axes); - pcPolarPattern->Axis.setValue(selObj, axes); + // Note: ReferenceSelection has already checked the selection for validity + if ( selectionMode == reference || selObj->isDerivedFrom ( App::Line::getClassTypeId () ) ) { + pcPolarPattern->Axis.setValue(selObj, axes); - recomputeFeature(); - updateUI(); - } else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr || - strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr || - strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) { - - std::vector axes; - App::DocumentObject* selObj; - PartDesign::PolarPattern* pcPolarPattern = static_cast(getObject()); - getReferencedSelection(pcPolarPattern, msg, selObj, axes); - pcPolarPattern->Axis.setValue(selObj, axes); - - recomputeFeature(); - updateUI(); + recomputeFeature(); + updateUI(); + } } } } @@ -361,12 +354,14 @@ TaskPolarPatternParameters::~TaskPolarPatternParameters() //hide the parts coordinate system axis for selection App::Part* part = getPartFor(getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0])); - origin->resetTemporaryVisibility(); - } + try { + App::Origin *origin = part->getOrigin(); + ViewProviderOrigin* vpOrigin; + vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin->resetTemporaryVisibility (); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); + } } delete ui; diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 77c6b8670..467293c18 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -133,12 +133,14 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* //show the parts coordinate system axis for selection App::Part* part = getPartFor(vp->getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->setTemporaryVisibility(true, false); - } + try { + App::Origin *origin = part->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 () ); + } } } @@ -179,9 +181,7 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) if (part) { try { - std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); - - App::Origin* orig = static_cast(origs[0]); + App::Origin* orig = part->getOrigin(); addAxisToCombo(orig->getX(),"",tr("Base X axis")); addAxisToCombo(orig->getY(),"",tr("Base Y axis")); addAxisToCombo(orig->getZ(),"",tr("Base Z axis")); @@ -362,14 +362,16 @@ TaskRevolutionParameters::~TaskRevolutionParameters() //hide the parts coordinate system axis for selection App::Part* part = getPartFor(vp->getObject(), false); if(part) { - auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(!app_origin.empty()) { - ViewProviderOrigin* origin; - origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); - origin->resetTemporaryVisibility(); - } + try { + App::Origin *origin = part->getOrigin(); + ViewProviderOrigin* vpOrigin; + vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin->resetTemporaryVisibility(); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); + } } - + delete ui; for(int i = 0 ; i < axesInList.size() ; i++ ){ diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index f34d80d77..94c73c242 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -196,9 +196,7 @@ void TaskTransformedParameters::fillAxisCombo(ComboLinks &combolinks, if (part) { try { - std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); - - App::Origin* orig = static_cast(origs[0]); + App::Origin* orig = part->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")); @@ -234,9 +232,7 @@ void TaskTransformedParameters::fillPlanesCombo(ComboLinks &combolinks, if (part) { try { - std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); - - App::Origin* orig = static_cast(origs[0]); + App::Origin* orig = part->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 30b39f177..ef9e68119 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -29,6 +29,8 @@ #endif #include +#include +#include #include #include #include @@ -132,27 +134,6 @@ static void buildDefaultPartAndBody(const App::Document* doc) Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str()); } -PartDesign::Body *setUpPart(const App::Part *part) -{ - // first do the general Part setup - Gui::ViewProviderPart::setUpPart(part); - - // check for Bodies - // std::vector bodies = part->getObjectsOfType(PartDesign::Body::getClassTypeId()); - // assert(bodies.size() == 0); - - // std::string PartName = part->getNameInDocument(); - // std::string BodyName = part->getDocument()->getUniqueObjectName("MainBody"); - - Gui::Command::addModule(Gui::Command::Doc, "PartDesign"); - // Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().addObject('PartDesign::Body','%s')", BodyName.c_str()); - // Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument()); - // Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, BodyName.c_str()); - Gui::Command::updateActive(); - - return NULL; -} - void fixSketchSupport (Sketcher::SketchObject* sketch) { @@ -163,11 +144,17 @@ void fixSketchSupport (Sketcher::SketchObject* sketch) const App::Document* doc = sketch->getDocument(); PartDesign::Body *body = getBodyFor(sketch, /*messageIfNot*/ 0); - if (!body) { throw Base::Exception ("Coudn't find body for the 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 + Base::Placement plm = sketch->Placement.getValue(); Base::Vector3d pnt = plm.getPosition(); @@ -177,17 +164,19 @@ void fixSketchSupport (Sketcher::SketchObject* sketch) rot.multVec(sketchVector, sketchVector); bool reverseSketch = (sketchVector.x + sketchVector.y + sketchVector.z) < 0.0 ; if (reverseSketch) sketchVector *= -1.0; - int index; + + App::Plane *plane =0; if (sketchVector == Base::Vector3d(0,0,1)) - index = 0; + plane = origin->getXY (); else if (sketchVector == Base::Vector3d(0,1,0)) - index = 1; + plane = origin->getXZ (); else if (sketchVector == Base::Vector3d(1,0,0)) - index = 2; + plane = origin->getYZ (); else { throw Base::Exception("Sketch plane cannot be migrated"); } + assert (plane); // Find the normal distance from origin to the sketch plane gp_Pln pln(gp_Pnt (pnt.x, pnt.y, pnt.z), gp_Dir(sketchVector.x, sketchVector.y, sketchVector.z)); @@ -197,7 +186,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch) if (fabs(offset) < Precision::Confusion()) { // One of the base planes Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])", - sketch->getNameInDocument(), App::Part::BaseplaneTypes[index]); + sketch->getNameInDocument(), plane->getNameInDocument () ); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s", sketch->getNameInDocument(), reverseSketch ? "True" : "False"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'", @@ -211,16 +200,21 @@ void fixSketchSupport (Sketcher::SketchObject* sketch) offset *= -1.0; std::string Datum = doc->getUniqueObjectName("DatumPlane"); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('PartDesign::Plane','%s')",Datum.c_str()); - QString refStr = QString::fromAscii("[(App.activeDocument().") + QString::fromAscii(App::Part::BaseplaneTypes[index]) + - QString::fromAscii(",'')]"); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s",Datum.c_str(), refStr.toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",Datum.c_str(), AttachEngine::eMapModeStrings[Attacher::mmFlatFace]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f",Datum.c_str(), offset); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('PartDesign::Plane','%s')", + Datum.c_str()); + QString refStr = QString::fromAscii("[(App.activeDocument().%1,'')]") + .arg ( QString::fromAscii ( plane->getNameInDocument () ) ); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s", + Datum.c_str(), refStr.toStdString().c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'", + Datum.c_str(), AttachEngine::eMapModeStrings[Attacher::mmFlatFace]); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f", + Datum.c_str(), offset); Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.insertFeature(App.activeDocument().%s, App.activeDocument().%s)", body->getNameInDocument(), Datum.c_str(), sketch->getNameInDocument()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])", + Gui::Command::doCommand(Gui::Command::Doc, + "App.activeDocument().%s.Support = (App.activeDocument().%s,[''])", sketch->getNameInDocument(), Datum.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s", sketch->getNameInDocument(), reverseSketch ? "True" : "False"); diff --git a/src/Mod/PartDesign/Gui/Utils.h b/src/Mod/PartDesign/Gui/Utils.h index 63a59ebbd..dd94dff19 100644 --- a/src/Mod/PartDesign/Gui/Utils.h +++ b/src/Mod/PartDesign/Gui/Utils.h @@ -51,17 +51,6 @@ PartDesign::Body *getBody(bool messageIfNot); PartDesign::Body *getBodyFor(const App::DocumentObject*, bool messageIfNot); App::Part *getPartFor(const App::DocumentObject*, bool messageIfNot); - -/** Setup a Part for PartDesign - * This methode is use to populate a Part object with all - * necesarry PartDesign and base objects to allow the use - * in PartDesign. Its called from within PartDesign as well - * as from other modules which wish to set up a Part for PartDesin - * (e.g. Assembly): - * TODO any reasons why this should return a value? (2015-08-08, Fat-Zer) - */ -PartDesign::Body *setUpPart(const App::Part *); - /// Fix sketch support after moving a free sketch into a body void fixSketchSupport(Sketcher::SketchObject* sketch);