From 4ad9ee9dbdacf4b14e844eb76c7189fac3c65d9a Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 25 Mar 2015 17:59:51 +0300 Subject: [PATCH] Union of validator and filter functionalities. External edges correction --- .../ModuleBase_WidgetMultiSelector.cpp | 54 ++++++++-------- .../ModuleBase_WidgetMultiSelector.h | 14 ++-- .../ModuleBase_WidgetShapeSelector.cpp | 48 +++++++------- .../ModuleBase_WidgetShapeSelector.h | 12 ++-- src/ModuleBase/ModuleBase_WidgetValidated.cpp | 4 +- src/ModuleBase/ModuleBase_WidgetValidated.h | 12 +++- .../PartSet_WidgetConstraintShapeSelector.cpp | 9 ++- .../PartSet_WidgetConstraintShapeSelector.h | 16 ++--- src/PartSet/PartSet_WidgetShapeSelector.cpp | 64 +++++++++++++++++-- src/PartSet/PartSet_WidgetShapeSelector.h | 24 ++++++- src/PartSet/PartSet_WidgetSketchLabel.cpp | 22 ++++--- src/PartSet/PartSet_WidgetSketchLabel.h | 10 ++- src/SketchPlugin/plugin-Sketch.xml | 2 +- 13 files changed, 184 insertions(+), 107 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index ff8bafdea..8b53074f9 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -159,7 +158,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValue() } //******************************************************************** -void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup) +void ModuleBase_WidgetMultiSelector::storeAttributeValue() { DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelectionListAttr = @@ -167,23 +166,32 @@ void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup) if (aSelectionListAttr.get() == NULL) return; - if (isBackup) { - mySelectionType = aSelectionListAttr->selectionType(); - mySelection.clear(); - for (int i = 0; i < aSelectionListAttr->size(); i++) { - AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); - mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value())); - } + mySelectionType = aSelectionListAttr->selectionType(); + mySelection.clear(); + int aSize = aSelectionListAttr->size(); + for (int i = 0; i < aSelectionListAttr->size(); i++) { + AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); + mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value())); } - else { - aSelectionListAttr->clear(); - // Store shapes type - aSelectionListAttr->setSelectionType(mySelectionType); +} - // Store selection in the attribute - foreach (GeomSelection aSelec, mySelection) { - aSelectionListAttr->append(aSelec.first, aSelec.second); - } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) +{ + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(aData->attribute(attributeID())); + if (aSelectionListAttr.get() == NULL) + return; + aSelectionListAttr->clear(); + + // Store shapes type + aSelectionListAttr->setSelectionType(mySelectionType); + + // Store selection in the attribute + int aSize = mySelection.size(); + foreach (GeomSelection aSelec, mySelection) { + aSelectionListAttr->append(aSelec.first, aSelec.second); } } @@ -311,20 +319,8 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection() QIntList aList; aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType)); myWorkshop->activateSubShapesSelection(aList); - - // it is necessary to filter the selected edges to be non-degenerated - // it is not possible to build naming name for such edges - if (aNewType == "Edges") { - myEdgesTypeFilter = new ModuleBase_FilterNoDegeneratedEdge(); - aViewer->addSelectionFilter(myEdgesTypeFilter); - } - else { - aViewer->removeSelectionFilter(myEdgesTypeFilter); - } - } else { myWorkshop->deactivateSubShapesSelection(); - aViewer->removeSelectionFilter(myEdgesTypeFilter); } activateFilters(myWorkshop, myIsActive); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index ce904a981..49ae66b6b 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -102,9 +101,13 @@ protected slots: /// 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 isBackup a boolean flag, if true, store values from the attribute - /// to backup, otherwise set the backed up values to the attribute - virtual void backupAttributeValue(const bool isBackup); + virtual void storeAttributeValue(); + + /// 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 + virtual void restoreAttributeValue(const bool theValid); /// Set current shape type for selection void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType); @@ -134,9 +137,6 @@ protected slots: /// An action for pop-up menu in a list control QAction* myCopyAction; - /// A filter for the Edges type, which avoid the generated edges selection - Handle(ModuleBase_FilterNoDegeneratedEdge) myEdgesTypeFilter; - /// backup parameters of the model attribute. The class processes three types of attribute: /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter /// values are reserved in the backup diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 7fc402614..b981a9064 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -370,37 +370,33 @@ void ModuleBase_WidgetShapeSelector::activateCustom() } //******************************************************************** -void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup) +void ModuleBase_WidgetShapeSelector::storeAttributeValue() { DataPtr aData = myFeature->data(); AttributePtr anAttribute = myFeature->attribute(attributeID()); - if (isBackup) { - myObject = GeomValidators_Tools::getObject(anAttribute); - myShape = getShape(); - myRefAttribute = NULL; - myIsObject = false; - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - myIsObject = aRefAttr->isObject(); - myRefAttribute = aRefAttr->attr(); - } - myExternalObject = NULL; + myObject = GeomValidators_Tools::getObject(anAttribute); + myShape = getShape(); + myRefAttribute = NULL; + myIsObject = false; + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) { + myIsObject = aRefAttr->isObject(); + myRefAttribute = aRefAttr->attr(); } - else { - storeAttributeValues(myObject, myShape); - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - if (!myIsObject) - aRefAttr->setAttr(myRefAttribute); - } - if (myExternalObject.get()) { - DocumentPtr aDoc = myExternalObject->document(); - FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject); - if (aFeature.get() != NULL) { - aDoc->removeFeature(aFeature); - } - } +} + +//******************************************************************** +void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid) +{ + DataPtr aData = myFeature->data(); + AttributePtr anAttribute = myFeature->attribute(attributeID()); + + storeAttributeValues(myObject, myShape); + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) { + if (!myIsObject) + aRefAttr->setAttr(myRefAttribute); } } diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 34c4c0212..ea5ef10a7 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -109,9 +109,13 @@ Q_OBJECT /// 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 isBackup a boolean flag, if true, store values from the attribute - /// to backup, otherwise set the backed up values to the attribute - virtual void backupAttributeValue(const bool isBackup); + virtual void storeAttributeValue(); + + /// 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 + virtual void restoreAttributeValue(const bool theValid); /// Computes and updates name of selected object in the widget void updateSelectionName(); @@ -164,8 +168,6 @@ Q_OBJECT AttributePtr myRefAttribute; /// A boolean value whether refAttr uses reference of object bool myIsObject; - /// An external object - ObjectPtr myExternalObject; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 506eeca2a..2dd78afc6 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -42,7 +42,7 @@ bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue) bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner) { // stores the current values of the widget attribute - backupAttributeValue(true); + storeAttributeValue(); // saves the owner value to the widget attribute setSelection(theOwner); @@ -51,7 +51,7 @@ bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& the bool aValid = isValidAttribute(); // restores the current values of the widget attribute - backupAttributeValue(false); + restoreAttributeValue(aValid); return aValid; } diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index eea1bca0f..31e7b81ac 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -54,14 +54,20 @@ 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 isBackup a boolean flag, if true, store values from the attribute - /// to backup, otherwise set the backed up values to the attribute - virtual void backupAttributeValue(const bool isBackup) = 0; + virtual void storeAttributeValue() = 0; + + /// 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 + virtual void restoreAttributeValue(const bool theValid) = 0; /// Fills the attribute with the value of the selected owner /// \param theOwner a selected owner virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner) = 0; + virtual void removePresentations() {}; + /// Checks the current attibute in all attribute validators // \return true if all validators return that the attribute is valid bool isValidAttribute() const; diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp index f54e0fbc3..ca6f8837a 100644 --- a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp @@ -21,11 +21,10 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSe std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aFeature); if ((!aSPFeature) && (!theShape->isNull())) { - ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), - aSelectedObject, mySketch); - if (aObj) { - aSelectedObject = aObj; - myExternalObject = aObj; + createExternal(theSelectedObject, theShape); + + if (myExternalObject) { + aSelectedObject = myExternalObject; } else return false; } diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.h b/src/PartSet/PartSet_WidgetConstraintShapeSelector.h index ea8bbaa9e..c20eee6f3 100644 --- a/src/PartSet/PartSet_WidgetConstraintShapeSelector.h +++ b/src/PartSet/PartSet_WidgetConstraintShapeSelector.h @@ -10,17 +10,17 @@ #include "PartSet.h" -#include +#include #include /** * \ingroup Modules -* Customosation of ModuleBase_WidgetShapeSelector in order to provide +* Customosation of PartSet_WidgetShapeSelector in order to provide * working with constraints. */ -class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public ModuleBase_WidgetShapeSelector +class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public PartSet_WidgetShapeSelector { Q_OBJECT public: @@ -31,16 +31,16 @@ Q_OBJECT /// \param theParentId is Id of a parent of the current attribute PartSet_WidgetConstraintShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {} + : PartSet_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {} virtual ~PartSet_WidgetConstraintShapeSelector() {} /// Set sketcher /// \param theSketch a sketcher object - void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } + //void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } /// Retrurns installed sketcher - CompositeFeaturePtr sketch() const { return mySketch; } + //CompositeFeaturePtr sketch() const { return mySketch; } protected: /// Store the values to the model attribute of the widget. It casts this attribute to @@ -49,9 +49,9 @@ protected: /// \param theShape a selected shape, which is used in the selection attribute virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape); -private: +//private: /// Pointer to a sketch - CompositeFeaturePtr mySketch; + //CompositeFeaturePtr mySketch; }; #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index a7ada4a64..5c68a1015 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -13,6 +13,11 @@ #include #include +#include +#include +#include +#include + bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) { ObjectPtr aSelectedObject = theSelectedObject; @@ -25,13 +30,10 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje std::dynamic_pointer_cast(aSelectedFeature); if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) { // Processing of external (non-sketch) object - ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(aShape->impl(), - aSelectedObject, mySketch); - if (aObj) { - PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this; - aSelectedObject = aObj; - myExternalObject = aObj; - } else + createExternal(theSelectedObject, theShape); + if (myExternalObject) + aSelectedObject = myExternalObject; + else return false; } else { // Processing of sketch object @@ -74,3 +76,51 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, aShape); } +//******************************************************************** +void PartSet_WidgetShapeSelector::storeAttributeValue() +{ + /// this is a temporary code, will be removed when master is merged to this branch + /*XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + aWorkshop->displayer()->enableUpdateViewer(false); + */ + ModuleBase_WidgetShapeSelector::storeAttributeValue(); +} + +//******************************************************************** +void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid) +{ + ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid); + //if (!theValid) + removeExternal(); + /* + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + aWorkshop->displayer()->enableUpdateViewer(false);//->erase(myExternalObject); + aWorkshop->displayer()->enableUpdateViewer(true);*/ +} + +//******************************************************************** +void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject, + GeomShapePtr theShape) +{ + ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), + theSelectedObject, mySketch); + if (aObj != myExternalObject) { + removeExternal(); + myExternalObject = aObj; + } +} + +//******************************************************************** +void PartSet_WidgetShapeSelector::removeExternal() +{ + if (myExternalObject.get()) { + DocumentPtr aDoc = myExternalObject->document(); + FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject); + if (aFeature.get() != NULL) { + aDoc->removeFeature(aFeature); + } + myExternalObject = NULL; + } +} diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index f7d075b48..c342e0701 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -49,9 +49,31 @@ protected: /// \param theShape a selected shape, which is used in the selection attribute virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape); -private: + /// 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 + virtual void storeAttributeValue(); + + /// 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); + + // Removes the external presentation from the model + /// \param theSelectedObject an object + /// \param theShape a selected shape, which is used in the selection attribute + void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape); + + // Removes the external presentation from the model + void removeExternal(); + +protected: /// Pointer to a sketch CompositeFeaturePtr mySketch; + + /// An external object + ObjectPtr myExternalObject; }; #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 9f41c9453..e70a8a097 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -150,18 +150,20 @@ void PartSet_WidgetSketchLabel::enableFocusProcessing() myLabel->installEventFilter(this); } -void PartSet_WidgetSketchLabel::backupAttributeValue(const bool isBackup) +void PartSet_WidgetSketchLabel::storeAttributeValue() +{ +} + +void PartSet_WidgetSketchLabel::restoreAttributeValue(const bool theValid) { // it is not necessary to save the previous plane value because the plane is chosen once - if (!isBackup) { - DataPtr aData = feature()->data(); - AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr) { - ResultPtr anEmptyResult; - GeomShapePtr anEmptyShape; - aSelAttr->setValue(anEmptyResult, anEmptyShape); - } + DataPtr aData = feature()->data(); + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr) { + ResultPtr anEmptyResult; + GeomShapePtr anEmptyShape; + aSelAttr->setValue(anEmptyResult, anEmptyShape); } } diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 3e277c68d..a0a069f78 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -82,9 +82,13 @@ 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 isBackup a boolean flag, if true, store values from the attribute - /// to backup, otherwise set the backed up values to the attribute - virtual void backupAttributeValue(const bool isBackup); + virtual void storeAttributeValue(); + + /// 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 + virtual void restoreAttributeValue(const bool theValid); /// Fills the attribute with the value of the selected owner /// \param theOwner a selected owner diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 673816d77..f1bc36d9b 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -67,7 +67,7 @@ shape_types="edge vertex"> - + -- 2.30.2