From 9d9ff3badaec1d230a701582d588b1e75c0fc09c Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 16 Apr 2015 20:25:17 +0300 Subject: [PATCH] External object manager to be used in the multi selector widget --- src/PartSet/CMakeLists.txt | 8 ++- src/PartSet/PartSet_ExternalObjectsMgr.cpp | 66 +++++++++++++++++++++ src/PartSet/PartSet_ExternalObjectsMgr.h | 61 +++++++++++++++++++ src/PartSet/PartSet_Module.cpp | 9 ++- src/PartSet/PartSet_SketcherMgr.cpp | 2 +- src/PartSet/PartSet_WidgetMultiSelector.cpp | 43 ++++++++++++++ src/PartSet/PartSet_WidgetMultiSelector.h | 58 ++++++++++++++++++ src/PartSet/PartSet_WidgetShapeSelector.cpp | 53 ++++------------- src/PartSet/PartSet_WidgetShapeSelector.h | 12 +--- 9 files changed, 258 insertions(+), 54 deletions(-) create mode 100644 src/PartSet/PartSet_ExternalObjectsMgr.cpp create mode 100644 src/PartSet/PartSet_ExternalObjectsMgr.h create mode 100644 src/PartSet/PartSet_WidgetMultiSelector.cpp create mode 100644 src/PartSet/PartSet_WidgetMultiSelector.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 58d1a210c..d25419296 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -7,12 +7,14 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS PartSet.h PartSet_Constants.h + PartSet_ExternalObjectsMgr.h PartSet_Module.h PartSet_Tools.h PartSet_WidgetSketchLabel.h PartSet_Validators.h PartSet_WidgetPoint2d.h - PartSet_WidgetEditor.h + PartSet_WidgetEditor.h + PartSet_WidgetMultiSelector.h PartSet_WidgetPoint2dDistance.h PartSet_WidgetShapeSelector.h PartSet_Filters.h @@ -21,11 +23,13 @@ SET(PROJECT_HEADERS ) SET(PROJECT_SOURCES + PartSet_ExternalObjectsMgr.cpp PartSet_Module.cpp PartSet_Tools.cpp PartSet_WidgetSketchLabel.cpp PartSet_Validators.cpp - PartSet_WidgetEditor.cpp + PartSet_WidgetEditor.cpp + PartSet_WidgetMultiSelector.cpp PartSet_WidgetPoint2d.cpp PartSet_WidgetPoint2dDistance.cpp PartSet_WidgetShapeSelector.cpp diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.cpp b/src/PartSet/PartSet_ExternalObjectsMgr.cpp new file mode 100644 index 000000000..2ba5b8668 --- /dev/null +++ b/src/PartSet/PartSet_ExternalObjectsMgr.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_ExternalObjectsMgr.cpp +// Created: 15 Apr 2015 +// Author: Natalia Ermolaeva + +#include "PartSet_ExternalObjectsMgr.h" +#include "PartSet_Tools.h" + +#include + +#include + +PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue) +: myUseExternal(theDefaultValue) +{ + QString aIsExternal(theExternal.c_str()); + if (!aIsExternal.isEmpty()) { + QString aStr = aIsExternal.toUpper(); + myUseExternal = (aStr == "TRUE") || (aStr == "YES"); + } +} + +ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject, + const GeomShapePtr& theShape, + const CompositeFeaturePtr& theSketch) +{ + ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl(), + theSelectedObject, theSketch); + if (!aSelectedObject.get()) { + // Processing of external (non-sketch) object + aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), + theSelectedObject, theSketch); + if (aSelectedObject.get()) + myExternalObjects.append(aSelectedObject); + } + return aSelectedObject; +} + +//******************************************************************** +void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature) +{ + QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (anObject.get()) { + DocumentPtr aDoc = anObject->document(); + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature.get() != NULL) { + QObjectPtrList anObjects; + anObjects.append(aFeature); + // the external feature should be removed with all references, sketch feature should be ignored + std::set anIgnoredFeatures; + anIgnoredFeatures.insert(theSketch); + // the current feature should be ignored, because it can use the external feature in the + // attributes and, therefore have a references to it. So, the delete functionality tries + // to delete this feature. Test case is creation of a constraint on external point, + // use in this control after an external point, the point of the sketch. + anIgnoredFeatures.insert(theFeature); + XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures); + } + } + } + myExternalObjects.clear(); +} diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.h b/src/PartSet/PartSet_ExternalObjectsMgr.h new file mode 100644 index 000000000..6451751de --- /dev/null +++ b/src/PartSet/PartSet_ExternalObjectsMgr.h @@ -0,0 +1,61 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_ExternalObjectsMgr.h +// Created: 15 Apr 2015 +// Author: Natalia Ermolaeva + + +#ifndef PartSet_ExternalObjectsMgr_H +#define PartSet_ExternalObjectsMgr_H + +#include "PartSet.h" + +#include +#include +#include + +#include + +#include + +/** +* \ingroup Modules +* Customosation of ModuleBase_WidgetShapeSelector in order to provide +* working with sketch specific objects. +*/ +class PARTSET_EXPORT PartSet_ExternalObjectsMgr +{ + public: + /// Constructor + /// \param theExternal the external state + /// \param theDefaultValue the default value for the external object using + PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue); + + virtual ~PartSet_ExternalObjectsMgr() {} + + /// Returns the state whether the external object is used + bool useExternal() const { return myUseExternal; } + + /// Finds or create and external object + /// \param theSelectedObject an object + /// \param theShape a selected shape, which is used in the selection attribute + /// \param theSketch a current sketch + /// \return the object + ObjectPtr externalObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape, + const CompositeFeaturePtr& theSketch); + + // Removes the external presentation from the model + /// \param theSketch a current sketch + /// \param theFeature a current feature + void removeExternal(const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature); + +protected: + /// An external object + QObjectPtrList myExternalObjects; + + /// Boolean value about the neccessity of the external object use + bool myUseExternal; +}; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 33df27091..09b8ef5d5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "PartSet_SketcherMgr.h" #include "PartSet_MenuMgr.h" @@ -456,7 +457,13 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId); aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch()); aWgt = aShapeSelectorWgt; - } if (theType == WDG_DOUBLEVALUE_EDITOR) { + } if (theType == "sketch_multi_selector") { + PartSet_WidgetMultiSelector* aShapeSelectorWgt = + new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId); + aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch()); + aWgt = aShapeSelectorWgt; + } + if (theType == WDG_DOUBLEVALUE_EDITOR) { aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId); } return aWgt; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index e46d1a60c..3a9487469 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -328,7 +328,7 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE FeaturePtr aFeature = myCurrentSelection.begin().key(); std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aFeature); - if (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) { + if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) { DataPtr aData = aSPFeature->data(); AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); std::shared_ptr aFPAttr = diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp new file mode 100644 index 000000000..c59c6919e --- /dev/null +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_WidgetMultiSelector.cpp +// Created: 15 Apr 2015 +// Author: Natalia Ermolaeva + +#include "PartSet_WidgetMultiSelector.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include + +PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) +{ + myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false); +} + +PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector() +{ + delete myExternalObjectMgr; +} + +//******************************************************************** +void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid) +{ + ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid); + myExternalObjectMgr->removeExternal(sketch(), myFeature); +} diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h new file mode 100644 index 000000000..db5d40859 --- /dev/null +++ b/src/PartSet/PartSet_WidgetMultiSelector.h @@ -0,0 +1,58 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_WidgetMultiSelector.h +// Created: 15 Apr 2015 +// Author: Natalia Ermolaeva + + +#ifndef PartSet_WidgetMultiSelector_H +#define PartSet_WidgetMultiSelector_H + +#include "PartSet.h" + +#include + +#include + +class PartSet_ExternalObjectsMgr; + +/** +* \ingroup Modules +* Customosation of ModuleBase_WidgetShapeSelector in order to provide +* working with sketch specific objects. +*/ +class PARTSET_EXPORT PartSet_WidgetMultiSelector: public ModuleBase_WidgetShapeSelector +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent the parent object + /// \param theWorkshop instance of workshop interface + /// \param theData the widget configuation. The attribute of the model widget is obtained from + /// \param theParentId is Id of a parent of the current attribute + PartSet_WidgetMultiSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, const std::string& theParentId); + + virtual ~PartSet_WidgetMultiSelector(); + + /// Set sketcher + /// \param theSketch a sketcher object + void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } + + /// Retrurns installed sketcher + CompositeFeaturePtr sketch() const { return mySketch; } + +protected: + /// Creates a backup of the current values of the attribute + /// It should be realized in the specific widget because of different + /// parameters of the current attribute + /// \param theValid a boolean flag, if restore happens for valid parameters + void restoreAttributeValue(const bool theValid); + +protected: + PartSet_ExternalObjectsMgr* myExternalObjectMgr; + /// Pointer to a sketch + CompositeFeaturePtr mySketch; +}; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 5174050ff..275a65d17 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -24,13 +25,14 @@ PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) -: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId), myUseExternal(true) +: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) { - QString aIsExternal(theData->getProperty("use_external").c_str()); - if (!aIsExternal.isEmpty()) { - QString aStr = aIsExternal.toUpper(); - myUseExternal = (aStr == "TRUE") || (aStr == "YES"); - } + myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true); +} + +PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector() +{ + delete myExternalObjectMgr; } bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) @@ -46,19 +48,11 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha std::dynamic_pointer_cast(aSelectedFeature); // Do check that we can use external feature - if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myUseExternal)) + if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal())) return false; - if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myUseExternal) { - aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl(), - theSelectedObject, mySketch); - if (!aSelectedObject.get()) { - // Processing of external (non-sketch) object - aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), - theSelectedObject, mySketch); - if (aSelectedObject.get()) - myExternalObject = aSelectedObject; - } + if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) { + aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch()); } else { // Processing of sketch object DataPtr aData = myFeature->data(); @@ -104,28 +98,5 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid) { ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid); - removeExternal(); -} - -//******************************************************************** -void PartSet_WidgetShapeSelector::removeExternal() -{ - if (myExternalObject.get()) { - DocumentPtr aDoc = myExternalObject->document(); - FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject); - if (aFeature.get() != NULL) { - QObjectPtrList anObjects; - anObjects.append(aFeature); - // the external feature should be removed with all references, sketch feature should be ignored - std::set anIgnoredFeatures; - anIgnoredFeatures.insert(sketch()); - // the current feature should be ignored, because it can use the external feature in the - // attributes and, therefore have a references to it. So, the delete functionality tries - // to delete this feature. Test case is creation of a constraint on external point, - // use in this control after an external point, the point of the sketch. - anIgnoredFeatures.insert(myFeature); - XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures); - } - myExternalObject = ObjectPtr(); - } + myExternalObjectMgr->removeExternal(sketch(), myFeature); } diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index b10c8a06f..5aa7ca283 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -14,6 +14,7 @@ #include +class PartSet_ExternalObjectsMgr; /** * \ingroup Modules @@ -32,7 +33,7 @@ Q_OBJECT PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId); - virtual ~PartSet_WidgetShapeSelector() {} + virtual ~PartSet_WidgetShapeSelector(); /// Set sketcher /// \param theSketch a sketcher object @@ -54,17 +55,10 @@ protected: /// \param theValid a boolean flag, if restore happens for valid parameters void restoreAttributeValue(const bool theValid); - // Removes the external presentation from the model - void removeExternal(); - protected: + PartSet_ExternalObjectsMgr* myExternalObjectMgr; /// Pointer to a sketch CompositeFeaturePtr mySketch; - - /// An external object - ObjectPtr myExternalObject; - - bool myUseExternal; }; #endif \ No newline at end of file -- 2.39.2