From 797d6d3a1182004ded6441b41bfcb0eecc94e740 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Tue, 1 Sep 2015 05:35:10 +0300 Subject: [PATCH] App/Origin: big refactoring - Rebase App::Origin on App::DocumentObject - Keep all control over the Origin structure inside the Origin and it's ViewProvider - Add OriginFeature class as common base for App::Plane and App::Line - Rebase App::Plane and App::Line on top of newly created class and move to the file. - Change Origin's ViewProvider API associated with temporary display - Lots of associated changes to files - Several minor fixes - Lots of new bugs --- src/App/Application.cpp | 4 +- src/App/CMakeLists.txt | 6 +- src/App/CMakeLists.txt.orig | 16 +- src/App/Document.cpp | 2 +- src/App/Line.h | 69 ------ src/App/Origin.cpp | 147 +++++++++++- src/App/Origin.h | 101 ++++++++- src/App/{Line.cpp => OriginFeature.cpp} | 59 ++--- src/App/{Plane.h => OriginFeature.h} | 56 ++--- src/App/Part.cpp | 1 - src/App/Plane.cpp | 62 ----- src/Gui/ViewProviderGeoFeatureGroup.cpp | 6 +- src/Gui/ViewProviderOrigin.cpp | 214 +++++++++++------- src/Gui/ViewProviderOrigin.h | 69 +++--- src/Gui/ViewProviderPart.cpp | 128 +++-------- src/Gui/ViewProviderPart.h | 2 +- src/Gui/ViewProviderPlane.h | 2 +- src/Mod/Part/App/Attacher.cpp | 4 +- src/Mod/Part/App/DatumFeature.cpp | 1 - src/Mod/Part/App/Part2DObject.cpp | 1 - src/Mod/PartDesign/App/Body.cpp | 8 +- src/Mod/PartDesign/App/DatumCS.cpp | 2 - src/Mod/PartDesign/App/DatumLine.cpp | 3 +- src/Mod/PartDesign/App/DatumPlane.cpp | 2 - src/Mod/PartDesign/App/DatumPoint.cpp | 2 - src/Mod/PartDesign/App/Feature.cpp | 6 +- src/Mod/PartDesign/App/FeatureDraft.cpp | 2 +- .../PartDesign/App/FeatureLinearPattern.cpp | 3 +- src/Mod/PartDesign/App/FeatureMirrored.cpp | 2 +- .../PartDesign/App/FeaturePolarPattern.cpp | 2 +- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 10 +- src/Mod/PartDesign/Gui/Command.cpp | 7 +- src/Mod/PartDesign/Gui/ReferenceSelection.cpp | 3 +- .../PartDesign/Gui/TaskDatumParameters.cpp | 20 +- src/Mod/PartDesign/Gui/TaskFeaturePick.cpp | 45 ++-- .../Gui/TaskLinearPatternParameters.cpp | 13 +- .../PartDesign/Gui/TaskMirroredParameters.cpp | 18 +- .../Gui/TaskPolarPatternParameters.cpp | 10 +- .../Gui/TaskRevolutionParameters.cpp | 37 +-- .../Gui/TaskSketchBasedParameters.cpp | 56 +---- .../Gui/TaskSketchBasedParameters.h | 3 - .../Gui/TaskTransformedParameters.cpp | 99 +++----- .../Gui/TaskTransformedParameters.h | 3 - src/Mod/Sketcher/App/SketchObject.cpp | 2 +- src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 2 +- src/Mod/Sketcher/Gui/Command.cpp | 2 +- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 2 +- 47 files changed, 641 insertions(+), 673 deletions(-) delete mode 100644 src/App/Line.h rename src/App/{Line.cpp => OriginFeature.cpp} (57%) rename src/App/{Plane.h => OriginFeature.h} (65%) delete mode 100644 src/App/Plane.cpp diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 1808fb098..0be12799f 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -95,8 +95,7 @@ #include "Annotation.h" #include "MeasureDistance.h" #include "Placement.h" -#include "Plane.h" -#include "Line.h" +#include "OriginFeature.h" #include "Part.h" #include "Origin.h" #include "MaterialObject.h" @@ -1134,6 +1133,7 @@ void Application::initTypes(void) App ::MaterialObject ::init(); App ::MaterialObjectPython ::init(); App ::Placement ::init(); + App ::OriginFeature ::init(); App ::Plane ::init(); App ::Line ::init(); App ::Part ::init(); diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index 488bd3859..6fdee404c 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -83,9 +83,8 @@ SET(Document_CPP_SRCS InventorObject.cpp MeasureDistance.cpp Placement.cpp - Plane.cpp + OriginFeature.cpp Range.cpp - Line.cpp Transactions.cpp VRMLObject.cpp MaterialObject.cpp @@ -115,9 +114,8 @@ SET(Document_HPP_SRCS InventorObject.h MeasureDistance.h Placement.h - Plane.h + OriginFeature.h Range.h - Line.h Transactions.h VRMLObject.h MaterialObject.h diff --git a/src/App/CMakeLists.txt.orig b/src/App/CMakeLists.txt.orig index b3b733ecd..fa2232533 100644 --- a/src/App/CMakeLists.txt.orig +++ b/src/App/CMakeLists.txt.orig @@ -78,16 +78,18 @@ SET(Document_CPP_SRCS GeoFeatureGroupPyImp.cpp GeoFeatureGroup.cpp Part.cpp + Origin.cpp Path.cpp InventorObject.cpp MeasureDistance.cpp Placement.cpp +<<<<<<< ae7effa304095ee3d286ea7bb545636960e262d5 Plane.cpp -<<<<<<< 328aeaab9aed22c3b94c79bd7e49404342a44cea Range.cpp -======= Line.cpp ->>>>>>> add base lines +======= + OriginFeature.cpp +>>>>>>> App/Origin: big refactoring Transactions.cpp VRMLObject.cpp MaterialObject.cpp @@ -112,16 +114,18 @@ SET(Document_HPP_SRCS GeoFeature.h GeoFeatureGroup.h Part.h + Origin.h Path.h InventorObject.h MeasureDistance.h Placement.h +<<<<<<< ae7effa304095ee3d286ea7bb545636960e262d5 Plane.h -<<<<<<< 328aeaab9aed22c3b94c79bd7e49404342a44cea Range.h -======= Line.h ->>>>>>> add base lines +======= + OriginFeature.h +>>>>>>> App/Origin: big refactoring Transactions.h VRMLObject.h MaterialObject.h diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 444f2d52f..6a08dcdc6 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2084,7 +2084,6 @@ void Document::remObject(const char* sName) pos->second->unsetupObject(); } signalDeletedObject(*(pos->second)); - // TODO Check me if it's needed (2015-09-01, Fat-Zer) pos->second->StatusBits.reset (ObjectStatus::Delete); // Unset the bit to be on the safe side if (!d->vertexMap.empty()) { @@ -2140,6 +2139,7 @@ void Document::remObject(const char* sName) /// Remove an object out of the document (internal) void Document::_remObject(DocumentObject* pcObject) { + // TODO Refactoring: share code with Document::remObject() (2015-09-01, Fat-Zer) _checkTransaction(pcObject); std::map::iterator pos = d->objectMap.find(pcObject->getNameInDocument()); diff --git a/src/App/Line.h b/src/App/Line.h deleted file mode 100644 index 8c9463d7d..000000000 --- a/src/App/Line.h +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 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 _AppLine_h_ -#define _AppLine_h_ - - -#include "GeoFeature.h" -#include "PropertyGeo.h" - - - -namespace App -{ - - -/** Line Object - * Used to define planar support for all kind of operations in the document space - */ -class AppExport Line: public App::GeoFeature -{ - PROPERTY_HEADER(App::Line); - -public: - - /// Constructor - Line(void); - virtual ~Line(); - /// additional information about the plane usage (e.g. "BaseLine-xy" in a Part) - PropertyString LineType; - - - /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { - return "Gui::ViewProviderLine"; - } - - /// Return the bounding box of the plane (this is always a fixed size) - static Base::BoundBox3d getBoundBox(); -}; - - -} //namespace App - - - -#endif diff --git a/src/App/Origin.cpp b/src/App/Origin.cpp index 6181ec543..859b6fc81 100644 --- a/src/App/Origin.cpp +++ b/src/App/Origin.cpp @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * Copyright (c) Stefan Tr�ger (stefantroeger@gmx.net) 2015 * + * Copyright (c) Alexander Golubev (Fat-Zer) 2015 * * * * This file is part of the FreeCAD CAx development system. * * * @@ -24,10 +25,14 @@ #include "PreCompiled.h" #ifndef _PreComp_ +#include #endif +#include +#include + #include -#include +#include #include "Origin.h" @@ -35,20 +40,138 @@ using namespace App; -PROPERTY_SOURCE(App::Origin, App::GeoFeatureGroup) +PROPERTY_SOURCE(App::Origin, App::DocumentObject) +const char* Origin::AxisRoles[3] = {"X_Axis", "Y_Axis", "Z_Axis"}; +const char* Origin::PlaneRoles[3] = {"XY_Plane", "XZ_Plane", "YZ_Plane"}; - -//=========================================================================== -// Feature -//=========================================================================== - -Origin::Origin(void) -{ - Placement.StatusBits.set(3, true); +Origin::Origin(void) { + ADD_PROPERTY_TYPE ( OriginFeatures, (0), 0, App::Prop_Hidden, + "Axis and baseplanes controlled by the origin" ); } + Origin::~Origin(void) -{ +{ } + +App::OriginFeature *Origin::getOriginFeature( const char *role) const { + const auto & features = OriginFeatures.getValues (); + auto featIt = std::find_if (features.begin(), features.end(), + [role] (App::DocumentObject *obj) { + return obj->isDerivedFrom ( App::OriginFeature::getClassTypeId () ) && + strcmp (static_cast(obj)->Role.getValue(), role) == 0; + } ); + if (featIt != features.end()) { + return static_cast(*featIt); + } else { + + std::stringstream err; + err << "Origin \"" << getNameInDocument () << "\" doesn't contain feature with role \"" + << role << '"'; + throw Base::Exception ( err.str().c_str () ); + } } +App::Line *Origin::getAxis( const char *role ) const { + App::OriginFeature *feat = getOriginFeature (role); + if ( feat->isDerivedFrom(App::Line::getClassTypeId () ) ) { + return static_cast (feat); + } else { + std::stringstream err; + err << "Origin \"" << getNameInDocument () << "\" contains bad Axis object for role \"" + << role << '"'; + throw Base::Exception ( err.str().c_str () ); + } +} + +App::Plane *Origin::getPlane( const char *role ) const { + App::OriginFeature *feat = getOriginFeature (role); + if ( feat->isDerivedFrom(App::Plane::getClassTypeId () ) ) { + return static_cast (feat); + } else { + std::stringstream err; + err << "Origin \"" << getNameInDocument () << "\" comtains bad Plane object for role \"" + << role << '"'; + throw Base::Exception ( err.str().c_str () ); + } +} + +bool Origin::hasObject (DocumentObject *obj) const { + const auto & features = OriginFeatures.getValues (); + return std::find (features.begin(), features.end(), obj) != features.end (); +} + +short Origin::mustExecute(void) const { + if (OriginFeatures.isTouched ()) { + return 1; + } else { + return DocumentObject::mustExecute(); + } +} + +App::DocumentObjectExecReturn *Origin::execute(void) { + try { // try to find all base axis and planes in the origin + for (const char* role: AxisRoles) { + App::Line *axis = getAxis (role); + assert(axis); + } + for (const char* role: PlaneRoles) { + App::Plane *plane = getPlane (role); + assert(plane); + } + } catch (const Base::Exception &ex) { + setError (); + return new App::DocumentObjectExecReturn ( ex.what () ); + } + // purgeError (); + return DocumentObject::execute (); +} + +void Origin::setupObject () { + const static struct { + const Base::Type type; + const char *role; + Base::Rotation rot; + } setupData [] = { + {App::Line::getClassTypeId(), "X_Axis", Base::Rotation () }, + {App::Line::getClassTypeId(), "Y_Axis", Base::Rotation ( Base::Vector3d (1,1,1), M_PI*2/3 ) }, + {App::Line::getClassTypeId(), "Z_Axis", Base::Rotation ( Base::Vector3d (1,1,1), M_PI*4/3 ) }, + {App::Plane::getClassTypeId (), "XY_Plane", Base::Rotation () }, + {App::Plane::getClassTypeId (), "XZ_Plane", Base::Rotation ( Base::Vector3d (0,1,1), M_PI ), }, + {App::Plane::getClassTypeId (), "YZ_Plane", Base::Rotation ( Base::Vector3d (1,1,1), M_PI*2/3 ) }, + }; + + App::Document *doc = getDocument (); + + std::vector links; + for (auto data: setupData) { + std::string objName = doc->getUniqueObjectName ( data.role ); + App::DocumentObject *featureObj = doc->addObject ( data.type.getName(), objName.c_str () ); + + assert ( featureObj && featureObj->isDerivedFrom ( App::OriginFeature::getClassTypeId () ) ); + + App::OriginFeature *feature = static_cast ( featureObj ); + feature->Placement.setValue ( Base::Placement ( Base::Vector3d (), data.rot ) ); + feature->Role.setValue ( data.role ); + + links.push_back (feature); + } + + OriginFeatures.setValues (links); +} + +void Origin::unsetupObject () { + const auto &objsLnk = OriginFeatures.getValues (); + // Copy to set to assert we won't call methode more then one time for each object + std::set objs (objsLnk.begin(), objsLnk.end()); + // Remove all controlled objects + for (auto obj: objs ) { + // Check that previous deletes wasn't inderectly removed one of our objects + const auto &objsLnk = OriginFeatures.getValues (); + if ( std::find(objsLnk.begin(), objsLnk.end(), obj) != objsLnk.end()) { + if ( ! obj->isDeleting () ) { + obj->getDocument ()->remObject (obj->getNameInDocument()); + } + } + } +} diff --git a/src/App/Origin.h b/src/App/Origin.h index 47039274e..451aef18a 100644 --- a/src/App/Origin.h +++ b/src/App/Origin.h @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * Copyright (c) Alexander Golubev (Fat-Zer) 2015 * * * * This file is part of the FreeCAD CAx development system. * * * @@ -24,23 +25,21 @@ #ifndef APP_Origin_H #define APP_Origin_H -#include "GeoFeatureGroup.h" +#include "GeoFeature.h" + +#include "OriginFeature.h" #include "PropertyLinks.h" - - namespace App { - /** Base class of all geometric document objects. */ -class AppExport Origin : public App::GeoFeatureGroup +class AppExport Origin : public App::DocumentObject { PROPERTY_HEADER(App::Origin); public: - /// Constructor Origin(void); virtual ~Origin(); @@ -49,11 +48,95 @@ public: virtual const char* getViewProviderName(void) const { return "Gui::ViewProviderOrigin"; } -}; -//typedef App::FeaturePythonT OriginPython; + /** @name Axis and plane access + * This functions returns casted axis and planes objects and asserts they are setted correctly + * otherwice Base::Exception is thrown. + */ + ///@{ + // returns X axis + App::Line *getX () const { + return getAxis ("X_Axis"); + } + // returns Y axis + App::Line *getY () const { + return getAxis ("Y_Axis"); + } + // returns Z axis + App::Line *getZ () const { + return getAxis ("Z_Axis"); + } + + // returns XY plane + App::Plane *getXY () const { + return getPlane ("XY_Plane"); + } + // returns XZ plane + App::Plane *getXZ () const { + return getPlane ("XZ_Plane"); + } + // returns YZ plane + App::Plane *getYZ () const { + return getPlane ("YZ_Plane"); + } + + /// Returns all axis objects to iterate on them + std::vector axes() const { + return { getX(), getY(), getZ() }; + } + + /// Returns all base planes objects to iterate on them + std::vector planes() const { + return { getXY(), getXZ(), getYZ() }; + } + + /// Returns all controled objects (both planes and axis) to iterate on them + std::vector baseObjects() const { + return { getX(), getY(), getZ(), getXY(), getXZ(), getYZ() }; + } + + /// Returns an axis by it's name + App::OriginFeature *getOriginFeature( const char* role ) const; + + /// Returns an axis by it's name + App::Line *getAxis( const char* role ) const; + + /// Returns an axis by it's name + App::Plane *getPlane( const char* role ) const; + ///@} + + /// Returns true if the given object is part of the origin + bool hasObject (DocumentObject *obj) const; + + /// Returns the default bounding box of the origin (use this if you confused what should be s ) + // TODO Delete me if not really needed (2015-09-01, Fat-Zer) + static Base::BoundBox3d defaultBoundBox(); + + /// Returns true on changing OriginFeature set + virtual short mustExecute(void) const; + + /// Axis types + static const char* AxisRoles[3]; + /// Baseplane types + static const char* PlaneRoles[3]; + + // Axis links + PropertyLinkList OriginFeatures; + +protected: + /// Checks integrity of the Origin + virtual App::DocumentObjectExecReturn *execute(void); + /// Creates all corresponding Axises and Planes objects for the origin if they not linked yet + virtual void setupObject (); + /// Removes all planes and axis if they are still linked to the document + virtual void unsetupObject (); + +private: + struct SetupData; + void setupOriginFeature (App::PropertyLink &featProp, const SetupData &data); + +}; } //namespace App - #endif // APP_Origin_H diff --git a/src/App/Line.cpp b/src/App/OriginFeature.cpp similarity index 57% rename from src/App/Line.cpp rename to src/App/OriginFeature.cpp index 84b1ee964..4a3fae531 100644 --- a/src/App/Line.cpp +++ b/src/App/OriginFeature.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * Copyright (c) 2015 Alexander Golubev (Fat-Zer) * * * * This file is part of the FreeCAD CAx development system. * * * @@ -20,43 +20,50 @@ * * ***************************************************************************/ - #include "PreCompiled.h" #ifndef _PreComp_ #endif +#include "Document.h" +#include "Origin.h" -#include "Line.h" +#include "OriginFeature.h" using namespace App; +PROPERTY_SOURCE(App::OriginFeature, App::GeoFeature) +PROPERTY_SOURCE(App::Plane, App::OriginFeature) +PROPERTY_SOURCE(App::Line, App::OriginFeature) -PROPERTY_SOURCE(App::Line, App::GeoFeature) - - -//=========================================================================== -// Feature -//=========================================================================== - -Line::Line(void) +OriginFeature::OriginFeature() { - ADD_PROPERTY(LineType,("")); + ADD_PROPERTY_TYPE ( Role, (""), 0, App::Prop_ReadOnly, "Role of the feature in the Origin" ) ; + + // Set placement to read-only Placement.StatusBits.set(3, true); - } -Line::~Line(void) -{ +OriginFeature::~OriginFeature() +{ } + +// Base::BoundBox3d OriginFeature::getBoundBox() +// { +// return Base::BoundBox3d(-10, -10, -10, 10, 10, 10); +// } + +Origin * OriginFeature::getOrigin () { + App::Document *doc = getDocument(); + auto origins = doc->getObjectsOfType ( App::Origin::getClassTypeId() ); + + auto originIt= std::find_if (origins.begin(), origins.end(), [this] (DocumentObject *origin) { + assert ( origin->isDerivedFrom ( App::Origin::getClassTypeId() ) ); + return static_cast (origin)->hasObject (this); + } ); + if (originIt == origins.end()) { + return 0; + } else { + assert ( (*originIt)->isDerivedFrom ( App::Origin::getClassTypeId() ) ); + return static_cast (*originIt); + } } - -Base::BoundBox3d Line::getBoundBox() -{ - return Base::BoundBox3d(-10, -10, -10, 10, 10, 10); -} - - - - - - diff --git a/src/App/Plane.h b/src/App/OriginFeature.h similarity index 65% rename from src/App/Plane.h rename to src/App/OriginFeature.h index f1826ce91..9858f2d50 100644 --- a/src/App/Plane.h +++ b/src/App/OriginFeature.h @@ -20,50 +20,50 @@ * * ***************************************************************************/ - - - -#ifndef _AppPlane_h_ -#define _AppPlane_h_ - +#ifndef ORIGINFEATURE_H_6ZWJPB5V +#define ORIGINFEATURE_H_6ZWJPB5V #include "GeoFeature.h" -#include "PropertyGeo.h" - - namespace App { +class Origin; /** Plane Object * Used to define planar support for all kind of operations in the document space */ -class AppExport Plane: public App::GeoFeature +class AppExport OriginFeature: public App::GeoFeature { - PROPERTY_HEADER(App::Plane); - + PROPERTY_HEADER(App::OriginFeature); public: + /// additional information about the feature usage (e.g. "BasePlane-XY" or "Axis-X" in a Origin) + PropertyString Role; - /// Constructor - Plane(void); - virtual ~Plane(); - /// additional information about the plane usage (e.g. "BasePlane-xy" in a Part) - PropertyString PlaneType; + /// Constructor + OriginFeature(void); + virtual ~OriginFeature(); - - /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { - return "Gui::ViewProviderPlane"; - } - - /// Return the bounding box of the plane (this is always a fixed size) - static Base::BoundBox3d getBoundBox(); + /// Finds the origin object this plane belongs to + App::Origin *getOrigin (); }; +class AppExport Plane: public App::OriginFeature { + PROPERTY_HEADER(App::OriginFeature); +public: + virtual const char* getViewProviderName(void) const { + return "Gui::ViewProviderPlane"; + } +}; + +class AppExport Line: public App::OriginFeature { + PROPERTY_HEADER(App::OriginFeature); +public: + virtual const char* getViewProviderName(void) const { + return "Gui::ViewProviderLine"; + } +}; } //namespace App - - -#endif +#endif /* end of include guard: ORIGINFEATURE_H_6ZWJPB5V */ diff --git a/src/App/Part.cpp b/src/App/Part.cpp index 74cf2af13..30ce568fa 100644 --- a/src/App/Part.cpp +++ b/src/App/Part.cpp @@ -27,7 +27,6 @@ #endif #include -#include #include "Part.h" #include "PartPy.h" diff --git a/src/App/Plane.cpp b/src/App/Plane.cpp deleted file mode 100644 index 14614f746..000000000 --- a/src/App/Plane.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * - * * - * 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_ -#endif - - -#include "Plane.h" - -using namespace App; - - -PROPERTY_SOURCE(App::Plane, App::GeoFeature) - - -//=========================================================================== -// Feature -//=========================================================================== - -Plane::Plane(void) -{ - ADD_PROPERTY(PlaneType,("")); - Placement.StatusBits.set(3, true); - -} - -Plane::~Plane(void) -{ -} - -Base::BoundBox3d Plane::getBoundBox() -{ - return Base::BoundBox3d(-10, -10, -10, 10, 10, 10); -} - - - - - - diff --git a/src/Gui/ViewProviderGeoFeatureGroup.cpp b/src/Gui/ViewProviderGeoFeatureGroup.cpp index 6fe2e73a4..d4f1b35c0 100644 --- a/src/Gui/ViewProviderGeoFeatureGroup.cpp +++ b/src/Gui/ViewProviderGeoFeatureGroup.cpp @@ -109,9 +109,9 @@ std::vector ViewProviderGeoFeatureGroup::getDisplayModes(void) cons void ViewProviderGeoFeatureGroup::updateData(const App::Property* prop) { - if (prop->isDerivedFrom(App::PropertyPlacement::getClassTypeId()) && - strcmp(prop->getName(), "Placement") == 0) { - setTransformation ( static_cast(prop)->getValue().toMatrix() ); + App::GeoFeatureGroup *obj = static_cast ( getObject() ); + if (prop == &obj->Placement) { + setTransformation ( obj->Placement.getValue().toMatrix() ); } else { ViewProviderDocumentObjectGroup::updateData ( prop ); } diff --git a/src/Gui/ViewProviderOrigin.cpp b/src/Gui/ViewProviderOrigin.cpp index 3fc76585b..b429c0589 100644 --- a/src/Gui/ViewProviderOrigin.cpp +++ b/src/Gui/ViewProviderOrigin.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * Copyright (c) 2015 Alexander Golubev (Fat-Zer) * * * * This file is part of the FreeCAD CAx development system. * * * @@ -26,11 +27,15 @@ #ifndef _PreComp_ # include # include +# include +# include +# include #endif + +#include #include -#include -#include +#include #include /// Here the FreeCAD includes sorted by Base,App,Gui...... @@ -46,125 +51,170 @@ #include "View3DInventorViewer.h" #include "Base/Console.h" -#include -#include -#include + +#include using namespace Gui; -PROPERTY_SOURCE(Gui::ViewProviderOrigin, Gui::ViewProviderGeoFeatureGroup) - +PROPERTY_SOURCE(Gui::ViewProviderOrigin, Gui::ViewProviderDocumentObject) /** * Creates the view provider for an object group. */ -ViewProviderOrigin::ViewProviderOrigin() - : tempVisMode(false) +ViewProviderOrigin::ViewProviderOrigin() { + ADD_PROPERTY_TYPE ( Size, (Base::Vector3d(10,10,10)), 0, App::Prop_ReadOnly, + "The displayed size of the origin" ); + sPixmap = "CoordinateSystem"; Visibility.setValue(false); + + pcGroupChildren = new SoGroup(); + pcGroupChildren->ref(); } -ViewProviderOrigin::~ViewProviderOrigin() -{ +ViewProviderOrigin::~ViewProviderOrigin() { + pcGroupChildren->unref(); + pcGroupChildren = 0; } - -bool ViewProviderOrigin::canDragObjects() const -{ - return false; +std::vector ViewProviderOrigin::claimChildren(void) const { + return static_cast( getObject() )->OriginFeatures.getValues (); } -bool ViewProviderOrigin::canDropObjects() const -{ - return false; +std::vector ViewProviderOrigin::claimChildren3D(void) const { + return claimChildren (); } - -bool ViewProviderOrigin::setEdit(int ModNum) +void ViewProviderOrigin::attach(App::DocumentObject* pcObject) { - return true; + addDisplayMaskMode(pcGroupChildren, "Base"); + Gui::ViewProviderDocumentObject::attach(pcObject); } -void ViewProviderOrigin::unsetEdit(int ModNum) +std::vector ViewProviderOrigin::getDisplayModes(void) const { - + return { "Base" }; } -QIcon ViewProviderOrigin::getIcon(void) const +void ViewProviderOrigin::setDisplayMode(const char* ModeName) { - return Gui::ViewProvider::getIcon(); + if (strcmp(ModeName, "Base") == 0) + setDisplayMaskMode("Base"); + ViewProviderDocumentObject::setDisplayMode(ModeName); } -void ViewProviderOrigin::setTemporaryVisibilityMode(bool onoff, Gui::Document* doc) -{ - tempVisDoc = doc; - - if(tempVisMode == onoff) - return; - - tempVisMode = onoff; - if(onoff && doc) { - App::Origin* origin = static_cast(pcObject); - tempVisMap.clear(); - - for(App::DocumentObject* obj : origin->getObjects()) { - Gui::ViewProvider* vp = doc->getViewProvider(obj); - if(vp) { - tempVisMap[vp] = vp->isVisible(); - vp->setVisible(false); +void ViewProviderOrigin::setTemporaryVisibility(bool axis, bool plane) { + App::Origin* origin = static_cast( getObject() ); + + bool saveState = tempVisMap.empty(); + + try { + // Remember & Set axis visability + for(App::DocumentObject* obj : origin->axes()) { + if (obj) { + Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj); + if(vp) { + if (saveState) { + tempVisMap[vp] = vp->isVisible(); + } + vp->setVisible(axis); + } } } - tempVisMap[this] = isVisible(); - setVisible(true); + + // Remember & Set plane visability + for(App::DocumentObject* obj : origin->planes()) { + if (obj) { + Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj); + if(vp) { + if (saveState) { + tempVisMap[vp] = vp->isVisible(); + } + vp->setVisible(plane); + } + } + } + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what() ); } - else if(!onoff) { - for(std::pair pair : tempVisMap) - pair.first->setVisible(pair.second); + + // Remember & Set self visability + tempVisMap[this] = isVisible(); + setVisible(true); + +} + +void ViewProviderOrigin::resetTemporaryVisibility() { + for(std::pair pair : tempVisMap) { + pair.first->setVisible(pair.second); } + tempVisMap.clear (); } -void ViewProviderOrigin::setTemporaryVisibility(App::DocumentObject* obj, bool onoff) -{ - Gui::ViewProvider* vp = tempVisDoc->getViewProvider(obj); - if(vp) { - vp->setVisible(onoff); +bool ViewProviderOrigin::isTemporaryVisibility() { + return !tempVisMap.empty(); +} + +void ViewProviderOrigin::onChanged(const App::Property* prop) { + if (prop == &Size) { + try { + Gui::Application *app = Gui::Application::Instance; + Base::Vector3d sz = Size.getValue (); + App::Origin* origin = static_cast(pcObject); + + // find planes view providers + Gui::ViewProviderPlane* vpPlaneXY, *vpPlaneXZ, *vpPlaneYZ; + vpPlaneXY = static_cast ( app->getViewProvider ( origin->getXY () ) ); + vpPlaneXZ = static_cast ( app->getViewProvider ( origin->getXZ () ) ); + vpPlaneYZ = static_cast ( app->getViewProvider ( origin->getYZ () ) ); + + // set their sizes + if (vpPlaneXY) { + vpPlaneXY->Size.setValue ( std::max ( sz.x, sz.y ) ); + } + if (vpPlaneXZ) { + vpPlaneXZ->Size.setValue ( std::max ( sz.x, sz.z ) ); + } + if (vpPlaneYZ) { + vpPlaneYZ->Size.setValue ( std::max ( sz.y, sz.z ) ); + } + + //find Lines view providers + Gui::ViewProviderLine* vpLineX, *vpLineY, *vpLineZ; + vpLineX = static_cast ( app->getViewProvider ( origin->getX () ) ); + vpLineY = static_cast ( app->getViewProvider ( origin->getY () ) ); + vpLineZ = static_cast ( app->getViewProvider ( origin->getZ () ) ); + + if (vpLineX) { + vpLineX->Size.setValue ( std::min ( vpPlaneXY->Size.getValue(), vpPlaneXZ->Size.getValue() ) ); + } + if (vpLineY) { + vpLineY->Size.setValue ( std::min ( vpPlaneXY->Size.getValue(), vpPlaneYZ->Size.getValue() ) ); + } + if (vpLineZ) { + vpLineZ->Size.setValue ( std::min ( vpPlaneXZ->Size.getValue(), vpPlaneYZ->Size.getValue() ) ); + } + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what() ); + } } + + ViewProviderDocumentObject::onChanged ( prop ); } -bool ViewProviderOrigin::isTemporaryVisibilityMode() -{ - return tempVisMode; -} +bool ViewProviderOrigin::onDelete(const std::vector &) { + App::Origin* origin = static_cast( getObject() ); -void ViewProviderOrigin::setTemporaryVisibilityAxis(bool onoff) -{ - for(App::DocumentObject* obj : static_cast(pcObject)->getObjectsOfType(App::Line::getClassTypeId())) { - - Gui::ViewProvider* vp = tempVisDoc->getViewProvider(obj); - vp->setVisible(onoff); + if ( !origin->getInList().empty() ) { + return false; } -} -void ViewProviderOrigin::setTemporaryVisibilityPlanes(bool onoff) -{ - for(App::DocumentObject* obj : static_cast(pcObject)->getObjectsOfType(App::Plane::getClassTypeId())) { - - Gui::ViewProvider* vp = tempVisDoc->getViewProvider(obj); - vp->setVisible(onoff); + for (auto obj: origin->OriginFeatures.getValues() ) { + Gui::Command::doCommand( Gui::Command::Doc, "App.getDocument(\"%s\").removeObject(\"%s\")", + obj->getDocument()->getName(), obj->getNameInDocument() ); } -} - - - -// Python feature ----------------------------------------------------------------------- - -namespace Gui { -/// @cond DOXERR -PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderOriginPython, Gui::ViewProviderOrigin) -/// @endcond - -// explicit template instantiation -template class GuiExport ViewProviderPythonFeatureT; + + return true; } diff --git a/src/Gui/ViewProviderOrigin.h b/src/Gui/ViewProviderOrigin.h index 54aeb28a4..67034099c 100644 --- a/src/Gui/ViewProviderOrigin.h +++ b/src/Gui/ViewProviderOrigin.h @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * Copyright (c) 2015 Alexander Golubev (Fat-Zer) * * * * This file is part of the FreeCAD CAx development system. * * * @@ -24,50 +25,62 @@ #ifndef GUI_VIEWPROVIDER_ViewProviderOrigin_H #define GUI_VIEWPROVIDER_ViewProviderOrigin_H +#include -#include "ViewProviderGeoFeatureGroup.h" - -#include -#include - - +#include "ViewProviderDocumentObject.h" namespace Gui { -class Document; - -class GuiExport ViewProviderOrigin : public ViewProviderGeoFeatureGroup +class Document; + +class GuiExport ViewProviderOrigin : public ViewProviderDocumentObject { PROPERTY_HEADER(Gui::ViewProviderOrigin); public: + /// Size of the origin as setted by the part. + App::PropertyVector Size; + /// constructor. ViewProviderOrigin(); /// destructor. virtual ~ViewProviderOrigin(); - - virtual bool setEdit(int ModNum); - virtual void unsetEdit(int ModNum); - virtual bool canDragObjects() const; - virtual bool canDropObjects() const; + /// @name Override methodes + ///@{ + virtual std::vector claimChildren(void) const; + virtual std::vector claimChildren3D(void) const; + + virtual SoGroup* getChildRoot(void) const {return pcGroupChildren;}; + + virtual void attach(App::DocumentObject* pcObject); + virtual std::vector getDisplayModes(void) const; + virtual void setDisplayMode(const char* ModeName); + ///@} + + /** @name Temporary visability mode + * Control the visability of origin and associated objects when needed + */ + ///@{ + /// Set temporary visability of some of origin's objects e.g. while rotating or mirroring + void setTemporaryVisibility (bool axis, bool planes); + /// Returns true if the origin in temporary visability mode + bool isTemporaryVisibility (); + /// Reset the visability + void resetTemporaryVisibility (); + ///@} + + /// Returns default size. Use this if it is not possible to determin apropriate size by other means + static double defaultSize() {return 10.;} +protected: + virtual void onChanged(const App::Property* prop); + virtual bool onDelete(const std::vector &); - virtual QIcon getIcon(void) const; - - //temporary mode to override visibility of grouped objects - void setTemporaryVisibilityMode(bool onoff, Gui::Document* doc = NULL); - bool isTemporaryVisibilityMode(); - void setTemporaryVisibilityAxis(bool onoff); - void setTemporaryVisibilityPlanes(bool onoff); - void setTemporaryVisibility(App::DocumentObject* obj, bool onoff); - private: - bool tempVisMode; - Gui::Document* tempVisDoc; - std::map tempVisMap; -}; + SoGroup *pcGroupChildren; -typedef ViewProviderPythonFeatureT ViewProviderOriginPython; + std::map tempVisMap; +}; } // namespace Gui diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index 73ea05c48..d45dec885 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -30,12 +30,12 @@ #include #include -#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" @@ -92,6 +92,7 @@ void ViewProviderPart::updateData(const App::Property* 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() && @@ -118,14 +119,9 @@ void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App } }; - if(bbox.getSize().length() < 1e-7) { - bbox = SbBox3f(10., 10., 10., 10., 10., 10.); - } - //get the bounding box values - SbVec3f size = bbox.getSize()*1.3; - SbVec3f max = bbox.getMax()*1.3; - SbVec3f min = bbox.getMin()*1.3; + SbVec3f max = bbox.getMax(); + SbVec3f min = bbox.getMin(); auto origins = part->getObjectsOfType(App::Origin::getClassTypeId()); if (origins.empty()) @@ -134,34 +130,20 @@ void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App if(!origin) return; - //get the planes and set their values - std::vector planes = origin->getObjectsOfType(App::Plane::getClassTypeId()); - for (std::vector::const_iterator p = planes.begin(); p != planes.end(); p++) { - Gui::ViewProviderPlane* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*p)); - if(vp) { - if (strcmp(App::Part::BaseplaneTypes[0], dynamic_cast(*p)->PlaneType.getValue()) == 0) - vp->Size.setValue(std::max(std::abs(std::min(min[0], min[1])),std::max(max[0], max[1]))); - else if (strcmp(App::Part::BaseplaneTypes[1], dynamic_cast(*p)->PlaneType.getValue()) == 0) - vp->Size.setValue(std::max(std::abs(std::min(min[0], min[2])),std::max(max[0], max[2]))); - else if (strcmp(App::Part::BaseplaneTypes[2], dynamic_cast(*p)->PlaneType.getValue()) == 0) - vp->Size.setValue(std::max(std::abs(std::min(min[1], min[2])),std::max(max[1], max[2]))); - } + 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(); + } } - //get the lines and set their values - std::vector lines = origin->getObjectsOfType(App::Line::getClassTypeId()); - for (std::vector::const_iterator p = lines.begin(); p != lines.end(); p++) { - - Gui::ViewProviderLine* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*p)); - if(vp) { - if (strcmp(App::Part::BaselineTypes[0], dynamic_cast(*p)->LineType.getValue()) == 0) - vp->Size.setValue(std::max(std::abs(std::min(min[0], min[1])),std::max(max[0], max[1]))); - else if (strcmp(App::Part::BaselineTypes[1], dynamic_cast(*p)->LineType.getValue()) == 0) - vp->Size.setValue(std::max(std::abs(std::min(min[0], min[2])),std::max(max[0], max[2]))); - else if (strcmp(App::Part::BaselineTypes[2], dynamic_cast(*p)->LineType.getValue()) == 0) - vp->Size.setValue(std::max(std::abs(std::min(min[1], min[2])),std::max(max[1], max[2]))); - } + 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 ); } } } @@ -180,14 +162,14 @@ bool ViewProviderPart::doubleClicked(void) return true; } - -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; -} +// 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) { @@ -212,72 +194,16 @@ QIcon ViewProviderPart::getIcon() const void ViewProviderPart::setUpPart(const App::Part *part) { - // add the standard planes at the root of the Part + // add the origin at the root of the Part // first check if they already exist - // FIXME: If the user renames them, they won't be found... - bool found = false; - std::vector planes = part->getObjectsOfType(App::Plane::getClassTypeId()); - for (std::vector::const_iterator p = planes.begin(); p != planes.end(); p++) { - for (unsigned i = 0; i < 3; i++) { - if (strcmp(App::Part::BaseplaneTypes[i], dynamic_cast(*p)->PlaneType.getValue()) == 0) { - found = true; - break; - } - } - if (found) break; - } + std::vector origins = part->getObjectsOfType(App::Origin::getClassTypeId()); - if (!found) { - // ... and put them in the 'Origin' group + 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()); - - // Add the planes ... - std::string pname = part->getDocument()->getUniqueObjectName(App::Part::BaseplaneTypes[0]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", pname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.PlaneType = '%s'", App::Part::BaseplaneTypes[0]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XY-Plane").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str()); - - pname = part->getDocument()->getUniqueObjectName(App::Part::BaseplaneTypes[1]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", pname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,1),180))"); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.PlaneType = '%s'", App::Part::BaseplaneTypes[1]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str()); - - pname = part->getDocument()->getUniqueObjectName(App::Part::BaseplaneTypes[2]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", pname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,1,1),120))"); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.PlaneType = '%s'", App::Part::BaseplaneTypes[2]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str()); - - // Add the lines ... - std::string lname = part->getDocument()->getUniqueObjectName(App::Part::BaselineTypes[0]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", lname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.LineType = '%s'", App::Part::BaselineTypes[0]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("X-Axis").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str()); - - lname = part->getDocument()->getUniqueObjectName(App::Part::BaselineTypes[1]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", lname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,0,1),90))"); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.LineType = '%s'", App::Part::BaselineTypes[1]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("Y-Axis").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str()); - - lname = part->getDocument()->getUniqueObjectName(App::Part::BaselineTypes[2]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", lname.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))"); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.LineType = '%s'", App::Part::BaselineTypes[2]); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("Z-Axis").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str()); - } - } diff --git a/src/Gui/ViewProviderPart.h b/src/Gui/ViewProviderPart.h index 3b63383cb..43e59282e 100644 --- a/src/Gui/ViewProviderPart.h +++ b/src/Gui/ViewProviderPart.h @@ -56,7 +56,7 @@ public: virtual bool doubleClicked(void); - virtual bool onDelete(const std::vector &); +// virtual bool onDelete(const std::vector &); /// helper to set up the standard content of a Part Object static void setUpPart(const App::Part *part); diff --git a/src/Gui/ViewProviderPlane.h b/src/Gui/ViewProviderPlane.h index d8251e634..024ffa10b 100644 --- a/src/Gui/ViewProviderPlane.h +++ b/src/Gui/ViewProviderPlane.h @@ -58,7 +58,7 @@ public: std::vector getDisplayModes(void) const; void setDisplayMode(const char* ModeName); - /// indicates if the ViewProvider use the new Selection model + /// indicates if the ViewProvider use the new Selection model virtual bool useNewSelectionModel(void) const {return true;} /// indicates if the ViewProvider can be selected virtual bool isSelectable(void) const ; diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index bc2833098..68cc6e846 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -54,8 +54,7 @@ #include "Attacher.h" #include -#include -#include +#include using namespace Part; using namespace Attacher; @@ -614,6 +613,7 @@ void AttachEngine::readLinks(const App::PropertyLinkSubList &references, shapes[i] = &(shape->_Shape); } } else if ( geof->isDerivedFrom(App::Plane::getClassTypeId()) ){ + // TODO Why this assert is here? (2015-08-31, Fat-Zer) assert(sub[i].length()==0);//no more support for "back"/"front" on planes. Use mapReversed instead. //obtain Z axis and origin of placement Base::Vector3d norm; diff --git a/src/Mod/Part/App/DatumFeature.cpp b/src/Mod/Part/App/DatumFeature.cpp index 1e730b613..750023779 100644 --- a/src/Mod/Part/App/DatumFeature.cpp +++ b/src/Mod/Part/App/DatumFeature.cpp @@ -55,7 +55,6 @@ # include #endif -#include #include "DatumFeature.h" #include #include diff --git a/src/Mod/Part/App/Part2DObject.cpp b/src/Mod/Part/App/Part2DObject.cpp index 16b44d62c..d59ca0007 100644 --- a/src/Mod/Part/App/Part2DObject.cpp +++ b/src/Mod/Part/App/Part2DObject.cpp @@ -46,7 +46,6 @@ #include #include -#include #include #include #include "Part2DObject.h" diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 9fb8d2eb3..b243f21b6 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -25,7 +25,6 @@ #ifndef _PreComp_ #endif -#include #include #include "Feature.h" @@ -413,6 +412,7 @@ App::DocumentObjectExecReturn *Body::execute(void) Base::BoundBox3d Body::getBoundBox() { + // TODO review the function (2015-08-31, Fat-Zer) Base::BoundBox3d result; Part::Feature* tipSolid = static_cast(Tip.getValue()); @@ -422,7 +422,8 @@ Base::BoundBox3d Body::getBoundBox() } if (!tipSolid || tipSolid->Shape.getValue().IsNull()) { - result = App::Plane::getBoundBox(); + // TODO check that all callers are correctly handle if bounding box is null (2015-08-31, Fat-Zer) + result = Base::BoundBox3d (); } else { result = tipSolid->Shape.getShape().getBoundBox(); } @@ -439,9 +440,6 @@ Base::BoundBox3d Body::getBoundBox() } else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { PartDesign::Plane* plane = static_cast(*m); result.Add(plane->getBasePoint()); - } else if ((*m)->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { - // Note: We only take into account the base planes here - result.Add(Base::Vector3d(0,0,0)); } } diff --git a/src/Mod/PartDesign/App/DatumCS.cpp b/src/Mod/PartDesign/App/DatumCS.cpp index 76db5e534..97f8c0b2b 100644 --- a/src/Mod/PartDesign/App/DatumCS.cpp +++ b/src/Mod/PartDesign/App/DatumCS.cpp @@ -29,9 +29,7 @@ #include "DatumPoint.h" #include "DatumPlane.h" #include "DatumLine.h" -#include #include -#include #include #include #include diff --git a/src/Mod/PartDesign/App/DatumLine.cpp b/src/Mod/PartDesign/App/DatumLine.cpp index 1c5b420b2..e21b41b7d 100644 --- a/src/Mod/PartDesign/App/DatumLine.cpp +++ b/src/Mod/PartDesign/App/DatumLine.cpp @@ -61,9 +61,8 @@ #endif #include -#include +#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 28d35c641..d14fdad47 100644 --- a/src/Mod/PartDesign/App/DatumPlane.cpp +++ b/src/Mod/PartDesign/App/DatumPlane.cpp @@ -59,9 +59,7 @@ #endif #include -#include #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 cbcad427d..8950517c8 100644 --- a/src/Mod/PartDesign/App/DatumPoint.cpp +++ b/src/Mod/PartDesign/App/DatumPoint.cpp @@ -59,8 +59,6 @@ #endif #include -#include -#include #include #include "DatumPoint.h" #include "DatumLine.h" diff --git a/src/Mod/PartDesign/App/Feature.cpp b/src/Mod/PartDesign/App/Feature.cpp index 80b210626..8a89deaee 100644 --- a/src/Mod/PartDesign/App/Feature.cpp +++ b/src/Mod/PartDesign/App/Feature.cpp @@ -36,8 +36,7 @@ #include #include "App/Document.h" -#include "App/Plane.h" -#include +#include "App/OriginFeature.h" #include "Body.h" #include "Feature.h" #include "Mod/Part/App/DatumFeature.h" @@ -140,8 +139,7 @@ const Part::TopoShape Feature::getBaseTopoShape() const { bool Feature::isDatum(const App::DocumentObject* feature) { - return feature->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) || - feature->getTypeId().isDerivedFrom(App::Line::getClassTypeId()) || + return feature->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()) || feature->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()); } diff --git a/src/Mod/PartDesign/App/FeatureDraft.cpp b/src/Mod/PartDesign/App/FeatureDraft.cpp index 66f585bf1..3ccbb7c49 100644 --- a/src/Mod/PartDesign/App/FeatureDraft.cpp +++ b/src/Mod/PartDesign/App/FeatureDraft.cpp @@ -47,7 +47,7 @@ # include #endif -#include +#include #include #include #include diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp index 557ad4166..4df99d133 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp @@ -36,8 +36,7 @@ #include "FeatureLinearPattern.h" #include "DatumPlane.h" #include "DatumLine.h" -#include -#include +#include #include #include #include diff --git a/src/Mod/PartDesign/App/FeatureMirrored.cpp b/src/Mod/PartDesign/App/FeatureMirrored.cpp index a599a4ecc..17e4bdf07 100644 --- a/src/Mod/PartDesign/App/FeatureMirrored.cpp +++ b/src/Mod/PartDesign/App/FeatureMirrored.cpp @@ -31,7 +31,7 @@ #endif -#include +#include #include #include "FeatureMirrored.h" #include "DatumPlane.h" diff --git a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp index c4f4980e7..fb623d9eb 100644 --- a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp +++ b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include using namespace PartDesign; diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 9da0565a0..698e7177e 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -67,11 +67,10 @@ #include #include -#include #include #include #include -#include +#include #include #include #include "FeatureSketchBased.h" @@ -1054,12 +1053,7 @@ void SketchBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std: if (pcReferenceAxis->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) { const App::Line* line = static_cast(pcReferenceAxis); base = Base::Vector3d(0,0,0); - if( strcmp(line->LineType.getValue(), App::Part::BaselineTypes[0]) == 0) - dir = Base::Vector3d(1,0,0); - else if( strcmp(line->LineType.getValue(), App::Part::BaselineTypes[1]) == 0) - dir = Base::Vector3d(0,1,0); - else if( strcmp(line->LineType.getValue(), App::Part::BaselineTypes[2]) == 0) - dir = Base::Vector3d(0,0,1); + line->Placement.getValue().multVec (Base::Vector3d (1,0,0), dir); // Check that axis is perpendicular with sketch plane! if (sketchplane.Axis().Direction().Angle(gp_Dir(dir.x, dir.y, dir.z)) < Precision::Angular()) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index c478a306e..5e5caf4bc 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include #include @@ -307,11 +307,12 @@ 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->PlaneType.getValue()) == 0) { + if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) { isBasePlane = true; break; } @@ -360,7 +361,7 @@ void CmdPartDesignNewSketch::activated(int iMsg) 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->PlaneType.getValue()) == 0) { + if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) { if(pcActivePart->hasObject(pfeat, true)) status.push_back(PartDesignGui::TaskFeaturePick::basePlane); else diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index 8de49949d..183e06026 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -30,9 +30,8 @@ # include #endif -#include +#include #include -#include #include #include #include diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 43c561c3e..8d01cec27 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -67,8 +67,7 @@ const QString makeRefString(const App::DocumentObject* obj, const std::string& s if (obj == NULL) return QObject::tr("No reference selected"); - if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) || - obj->getTypeId().isDerivedFrom(App::Line::getClassTypeId()) || + if (obj->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()) || obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) // App::Plane, Liine or Datum feature return QString::fromAscii(obj->getNameInDocument()); @@ -217,10 +216,8 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p 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->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument()); - origin->setTemporaryVisibilityAxis(true); - origin->setTemporaryVisibilityPlanes(true); + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->setTemporaryVisibility(true, true); } } if (pcDatum->Support.getSize() == 0) @@ -402,8 +399,7 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg) std::string subname = msg.pSubName; // Remove subname for planes and datum features - if (selObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) || - selObj->getTypeId().isDerivedFrom(App::Line::getClassTypeId()) || + if (selObj->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()) || selObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) subname = ""; @@ -778,8 +774,8 @@ TaskDatumParameters::~TaskDatumParameters() 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->setTemporaryVisibilityMode(false); + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->resetTemporaryVisibility(); } } diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 1351472f8..a7290dcec 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -85,32 +87,43 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, connect(ui->nobodyRadioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); connect(ui->nobodyRadioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); - auto guidoc = Gui::Application::Instance->activeDocument(); - auto origin_obj = App::GetApplication().getActiveDocument()->getObjectsOfType(); + enum { axisBit=0, planeBit = 1}; + // Note generally there shouldn't be more then one origin + std::map > originVisStatus; + + auto statusIt = status.cbegin(); + auto objIt = objects.begin(); assert(status.size() == objects.size()); - std::vector::const_iterator st = status.begin(); - for (std::vector::const_iterator o = objects.begin(); o != objects.end(); o++) { - QListWidgetItem* item = new QListWidgetItem(QString::fromAscii((*o)->getNameInDocument()) + - QString::fromAscii(" (") + getFeatureStatusString(*st) + QString::fromAscii(")")); + for (; statusIt != status.end(); ++statusIt, ++objIt) { + QListWidgetItem* item = new QListWidgetItem( + QString::fromAscii((*objIt)->getNameInDocument()) + + QString::fromAscii(" (") + getFeatureStatusString(*statusIt) + QString::fromAscii(")") ); ui->listWidget->addItem(item); //check if we need to set any origin in temporary visibility mode - for(App::Origin* obj : origin_obj) { - if(obj->hasObject(*o) && (*st != invalidShape)) { - Gui::ViewProviderOrigin* vpo = static_cast(guidoc->getViewProvider(obj)); - if(!vpo->isTemporaryVisibilityMode()) - vpo->setTemporaryVisibilityMode(true, guidoc); + if (*statusIt != invalidShape && (*objIt)->isDerivedFrom ( App::OriginFeature::getClassTypeId () )) { + App::Origin *origin = static_cast (*objIt)->getOrigin (); + if (origin) { + if ((*objIt)->isDerivedFrom ( App::Plane::getClassTypeId () )) { + originVisStatus[ origin ].set (planeBit, true); + } else if ( (*objIt)->isDerivedFrom ( App::Line::getClassTypeId () ) ) { + originVisStatus[ origin ].set (axisBit, true); + } - vpo->setTemporaryVisibility(*o, 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); - break; } } - - st++; } + // TODO may be update origin API to show only some objects (2015-08-31, Fat-Zer) + groupLayout()->addWidget(proxy); statuses = status; updateList(); @@ -119,7 +132,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, TaskFeaturePick::~TaskFeaturePick() { for(Gui::ViewProviderOrigin* vpo : origins) - vpo->setTemporaryVisibilityMode(false, NULL); + vpo->resetTemporaryVisibility(); } diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 12d80f779..46269e535 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include @@ -170,10 +170,9 @@ void TaskLinearPatternParameters::setupUI() 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->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument()); - origin->setTemporaryVisibilityAxis(true); - } + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->setTemporaryVisibility(true, false); + } } } @@ -370,8 +369,8 @@ TaskLinearPatternParameters::~TaskLinearPatternParameters() 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->setTemporaryVisibilityMode(false); + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->resetTemporaryVisibility(); } } diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index af02a53d6..7d4ffd891 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -31,7 +31,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -141,15 +142,14 @@ void TaskMirroredParameters::setupUI() //show the parts coordinate system axis for selection App::Part* part = getPartFor(getObject(), false); - if(part) { + 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->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument()); - origin->setTemporaryVisibilityAxis(true); - } - } + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin.front() )); + origin->setTemporaryVisibility(true, false); + } + } } void TaskMirroredParameters::updateUI() @@ -281,8 +281,8 @@ TaskMirroredParameters::~TaskMirroredParameters() 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->setTemporaryVisibilityMode(false); + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->resetTemporaryVisibility(); } } diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp index 639ce87c8..3dfb4e652 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -32,7 +32,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -163,9 +164,8 @@ void TaskPolarPatternParameters::setupUI() 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->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument()); - origin->setTemporaryVisibilityAxis(true); + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->setTemporaryVisibility(true, false); } } } @@ -365,7 +365,7 @@ TaskPolarPatternParameters::~TaskPolarPatternParameters() if(!app_origin.empty()) { ViewProviderOrigin* origin; origin = static_cast(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0])); - origin->setTemporaryVisibilityMode(false); + origin->resetTemporaryVisibility(); } } diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 36ccf091c..77c6b8670 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -136,15 +136,15 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* 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->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument()); - origin->setTemporaryVisibilityAxis(true); + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->setTemporaryVisibility(true, false); } } } void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) { + // TODO share the code with TaskTransformedParameters (2015-08-31, Fat-Zer) bool oldVal_blockUpdate = blockUpdate; blockUpdate = true; @@ -174,16 +174,21 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) } //add part axes - App::DocumentObject* line = 0; - line = getPartLines(App::Part::BaselineTypes[0]); - if(line) - addAxisToCombo(line,"",tr("Base X axis")); - line = getPartLines(App::Part::BaselineTypes[1]); - if(line) - addAxisToCombo(line,"",tr("Base Y axis")); - line = getPartLines(App::Part::BaselineTypes[2]); - if(line) - addAxisToCombo(line,"",tr("Base Z axis")); + App::DocumentObject* obj = vp->getObject(); + App::Part* part = getPartFor(obj, false); + + if (part) { + try { + std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); + + App::Origin* orig = static_cast(origs[0]); + addAxisToCombo(orig->getX(),"",tr("Base X axis")); + addAxisToCombo(orig->getY(),"",tr("Base Y axis")); + addAxisToCombo(orig->getZ(),"",tr("Base Z axis")); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what() ); + } + } //add "Select reference" addAxisToCombo(0,std::string(),tr("Select reference...")); @@ -360,8 +365,8 @@ TaskRevolutionParameters::~TaskRevolutionParameters() 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->setTemporaryVisibilityMode(false); + origin = static_cast(Gui::Application::Instance->getViewProvider(app_origin[0])); + origin->resetTemporaryVisibility(); } } diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index 93fec7845..bd60188d2 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -33,10 +33,9 @@ #include #include #include -#include #include #include -#include +#include #include #include #include @@ -200,59 +199,6 @@ void TaskSketchBasedParameters::recomputeFeature() } } - -App::DocumentObject* TaskSketchBasedParameters::getPartPlanes(const char* str) const { - - //TODO: Adjust to GRAPH handling when available - App::DocumentObject* obj = vp->getObject(); - App::Part* part = getPartFor(obj, false); - if(!part) - return nullptr; - - std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(origs.size()<1) - return nullptr; - - App::Origin* orig = static_cast(origs[0]); - auto planes = orig->getObjectsOfType(App::Plane::getClassTypeId()); - for(App::DocumentObject* plane : planes) { - - if( strcmp(static_cast(plane)->PlaneType.getValue(), str) == 0) - return plane; - } - - return nullptr; -} - - -App::DocumentObject* TaskSketchBasedParameters::getPartLines(const char* str) const { - - //TODO: Adjust to GRAPH handling when available - App::DocumentObject* obj = vp->getObject(); - App::Part* part = getPartFor(obj, false); - - - std::vector origs; - if(part) - origs = part->getObjectsOfType(App::Origin::getClassTypeId()); - else - origs = vp->getObject()->getDocument()->getObjectsOfType(App::Origin::getClassTypeId()); - - if(origs.size()<1) - return nullptr; - - App::Origin* orig = static_cast(origs[0]); - auto lines = orig->getObjectsOfType(App::Line::getClassTypeId()); - for(App::DocumentObject* line : lines) { - - if( strcmp(static_cast(line)->LineType.getValue(), str) == 0) - return line; - } - - return nullptr; -} - - TaskSketchBasedParameters::~TaskSketchBasedParameters() { } diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h index 35b7f6521..4fb568346 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h @@ -56,9 +56,6 @@ protected: QString getFaceReference(const QString& obj, const QString& sub) const; void recomputeFeature(); - App::DocumentObject* getPartPlanes(const char* str) const; - App::DocumentObject* getPartLines(const char* str) const; - protected Q_SLOTS: void onUpdateView(bool on); diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index 0029b83bc..f34d80d77 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -36,8 +36,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -173,51 +172,6 @@ void TaskTransformedParameters::removeItemFromListWidget(QListWidget* widget, co } } - -App::DocumentObject* TaskTransformedParameters::getPartPlanes(const char* str) const { - //TODO: Adjust to GRAPH handling when available - App::DocumentObject* obj = getObject(); - App::Part* part = getPartFor(obj, false); - - if (part) { - std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(origs.size()<1) - return nullptr; - - App::Origin* orig = static_cast(origs[0]); - auto planes = orig->getObjectsOfType(App::Plane::getClassTypeId()); - for(App::DocumentObject* plane : planes) { - if( strcmp(static_cast(plane)->PlaneType.getValue(), str) == 0) - return plane; - } - } - - return nullptr; -} - - -App::DocumentObject* TaskTransformedParameters::getPartLines(const char* str) const { - - //TODO: Adjust to GRAPH handling when available - App::DocumentObject* obj = getObject(); - App::Part* part = getPartFor(obj, false); - if (part) { - std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); - if(origs.size()<1) - return nullptr; - - App::Origin* orig = static_cast(origs[0]); - auto lines = orig->getObjectsOfType(App::Line::getClassTypeId()); - for(App::DocumentObject* line : lines) { - - if( strcmp(static_cast(line)->LineType.getValue(), str) == 0) - return line; - } - } - - return nullptr; -} - void TaskTransformedParameters::fillAxisCombo(ComboLinks &combolinks, Part::Part2DObject* sketch) { @@ -237,16 +191,21 @@ void TaskTransformedParameters::fillAxisCombo(ComboLinks &combolinks, } //add part axes - App::DocumentObject* line = 0; - line = getPartLines(App::Part::BaselineTypes[0]); - if(line) - combolinks.addLink(line,"",tr("Base X axis")); - line = getPartLines(App::Part::BaselineTypes[1]); - if(line) - combolinks.addLink(line,"",tr("Base Y axis")); - line = getPartLines(App::Part::BaselineTypes[2]); - if(line) - combolinks.addLink(line,"",tr("Base Z axis")); + App::DocumentObject* obj = getObject(); + App::Part* part = getPartFor(obj, false); + + if (part) { + try { + std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); + + App::Origin* orig = static_cast(origs[0]); + combolinks.addLink(orig->getX(),"",tr("Base X axis")); + combolinks.addLink(orig->getY(),"",tr("Base Y axis")); + combolinks.addLink(orig->getZ(),"",tr("Base Z axis")); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what() ); + } + } //add "Select reference" combolinks.addLink(0,std::string(),tr("Select reference...")); @@ -270,20 +229,24 @@ void TaskTransformedParameters::fillPlanesCombo(ComboLinks &combolinks, } //add part baseplanes - App::DocumentObject* plane = 0; - plane = getPartPlanes(App::Part::BaseplaneTypes[0]); - if(plane) - combolinks.addLink(plane,"",tr("Base XY plane")); - plane = getPartPlanes(App::Part::BaseplaneTypes[1]); - if(plane) - combolinks.addLink(plane,"",tr("Base XZ plane")); - plane = getPartPlanes(App::Part::BaseplaneTypes[2]); - if(plane) - combolinks.addLink(plane,"",tr("Base YZ plane")); + App::DocumentObject* obj = getObject(); + App::Part* part = getPartFor(obj, false); + + if (part) { + try { + std::vector origs = part->getObjectsOfType(App::Origin::getClassTypeId()); + + App::Origin* orig = static_cast(origs[0]); + combolinks.addLink(orig->getXY(),"",tr("Base XY plane")); + combolinks.addLink(orig->getYZ(),"",tr("Base YZ plane")); + combolinks.addLink(orig->getXZ(),"",tr("Base XZ plane")); + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what() ); + } + } //add "Select reference" combolinks.addLink(0,std::string(),tr("Select reference...")); - } void TaskTransformedParameters::recomputeFeature() { diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.h b/src/Mod/PartDesign/Gui/TaskTransformedParameters.h index d0e201378..4b12be27c 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.h @@ -189,9 +189,6 @@ protected: virtual void clearButtons()=0; static void removeItemFromListWidget(QListWidget* widget, const char* itemstr); - App::DocumentObject* getPartPlanes(const char* str) const; - App::DocumentObject* getPartLines(const char* str) const; - void fillAxisCombo(ComboLinks &combolinks, Part::Part2DObject *sketch); void fillPlanesCombo(ComboLinks &combolinks, Part2DObject *sketch); diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 737a54a7c..3d6dba9b6 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -64,7 +64,7 @@ #include #include -#include +#include #include #include diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 06cef9eae..f7824e7aa 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include // inclusion of the generated files (generated out of SketchObjectSFPy.xml) diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index e0a0c35de..9349d2b6a 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -33,7 +33,7 @@ #endif #include -#include +#include #include #include #include diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index d1de0af5a..6ce987be4 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include #include