From: nds Date: Fri, 19 Jun 2015 05:46:38 +0000 (+0300) Subject: A separation of WidgetSelector class in order to unite the logic of shape/multi shape... X-Git-Tag: V_1.3.0~219 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5b0a1b660acf209c220744eb75c54652ee81efde;p=modules%2Fshaper.git A separation of WidgetSelector class in order to unite the logic of shape/multi shape selectors. The reason is preselection: to set an empty shape to the feature attribute if the selected shape is equal to the shape of result, check of selection valid state --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index c54208e12..bab934f79 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -17,7 +17,6 @@ SET(PROJECT_HEADERS ModuleBase_WidgetDoubleValue.h ModuleBase_WidgetEditor.h ModuleBase_WidgetFactory.h - ModuleBase_WidgetShapeSelector.h ModuleBase_IWorkshop.h ModuleBase_Definitions.h ModuleBase_SelectionValidator.h @@ -41,6 +40,8 @@ SET(PROJECT_HEADERS ModuleBase_PageWidget.h ModuleBase_PageGroupBox.h ModuleBase_PagedContainer.h + ModuleBase_WidgetSelector.h + ModuleBase_WidgetShapeSelector.h ModuleBase_WidgetSwitch.h ModuleBase_WidgetToolbox.h ModuleBase_WidgetValidated.h @@ -65,7 +66,6 @@ SET(PROJECT_SOURCES ModuleBase_WidgetDoubleValue.cpp ModuleBase_WidgetEditor.cpp ModuleBase_WidgetFactory.cpp - ModuleBase_WidgetShapeSelector.cpp ModuleBase_WidgetChoice.cpp ModuleBase_WidgetFileSelector.cpp ModuleBase_DoubleSpinBox.cpp @@ -80,6 +80,8 @@ SET(PROJECT_SOURCES ModuleBase_PageWidget.cpp ModuleBase_PageGroupBox.cpp ModuleBase_PagedContainer.cpp + ModuleBase_WidgetSelector.cpp + ModuleBase_WidgetShapeSelector.cpp ModuleBase_WidgetSwitch.cpp ModuleBase_WidgetToolbox.cpp ModuleBase_WidgetValidated.cpp diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index d4f209b15..c8bdba34e 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -42,8 +42,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_WidgetValidated(theParent, theData, theParentId), - myWorkshop(theWorkshop) + : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId) { QGridLayout* aMainLay = new QGridLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); @@ -54,8 +53,6 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myTypeCombo = new QComboBox(this); // There is no sence to paramerize list of types while we can not parametrize selection mode - myShapeValidator = new GeomValidators_ShapeType(); - std::string aPropertyTypes = theData->getProperty("type_choice"); QString aTypesStr = aPropertyTypes.c_str(); QStringList aShapeTypes = aTypesStr.split(' '); @@ -104,37 +101,6 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector() { - delete myShapeValidator; -} - -//TODO: nds stabilization hotfix -void ModuleBase_WidgetMultiSelector::disconnectSignals() -{ - disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); -} - -//******************************************************************** -void ModuleBase_WidgetMultiSelector::activateCustom() -{ - ModuleBase_IViewer* aViewer = myWorkshop->viewer(); - connect(myWorkshop, SIGNAL(selectionChanged()), - this, SLOT(onSelectionChanged()), - Qt::UniqueConnection); - - activateShapeSelection(true); - - // Restore selection in the viewer by the attribute selection list - myWorkshop->setSelected(getAttributeSelection()); - - activateFilters(myWorkshop, true); -} - -//******************************************************************** -void ModuleBase_WidgetMultiSelector::deactivate() -{ - disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - activateShapeSelection(false); - activateFilters(myWorkshop, false); } //******************************************************************** @@ -195,6 +161,15 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue() } } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::clearAttribute() +{ + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(aData->attribute(attributeID())); + aSelectionListAttr->clear(); +} + //******************************************************************** void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) @@ -210,14 +185,12 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, //******************************************************************** void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) { + clearAttribute(); + + // Store shape type 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 @@ -227,31 +200,6 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) } } -//******************************************************************** -bool ModuleBase_WidgetMultiSelector::acceptSubShape(const TopoDS_Shape& theShape) const -{ - bool aValid = true; - if (theShape.IsNull()) { - aValid = true; // do not check the shape type if the shape is empty - // extrusion uses a sketch object selectected in Object browser - } - else { - aValid = false; - TopAbs_ShapeEnum aShapeType = theShape.ShapeType(); - if (myTypeCombo->count() > 1) { - TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText()); - aValid = aShapeType == aType; - } - else { - for(int i = 0, aCount = myTypeCombo->count(); i < aCount && !aValid; i++) { - TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)); - aValid = aShapeType == aType; - } - } - } - return aValid; -} - //******************************************************************** bool ModuleBase_WidgetMultiSelector::setSelection(QList& theValues) { @@ -287,56 +235,30 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList& t //******************************************************************** bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { -#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS - return true; -#endif - GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); - // if there is no result(the feature is presentable only), result is false - ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); - bool aValid = aResult.get() != NULL; + bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs); if (aValid) { - // if there is no selected shape, the method returns true - if (!aShape.get()) - aValid = true; - else { - // Check that the selection corresponds to selection type - TopoDS_Shape aTopoShape = aShape->impl(); - aValid = acceptSubShape(aTopoShape); - } - } - - if (aValid) { - if (myFeature) { - // We can not select a result of our feature - const std::list& aResList = myFeature->results(); - std::list::const_iterator aIt; - bool isSkipSelf = false; - for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { - if ((*aIt) == aResult) { - isSkipSelf = true; - break; + ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); + aValid = aResult.get() != NULL; + if (aValid) { + if (myFeature) { + // We can not select a result of our feature + const std::list& aResList = myFeature->results(); + std::list::const_iterator aIt; + bool isSkipSelf = false; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { + if ((*aIt) == aResult) { + isSkipSelf = true; + break; + } } + if (isSkipSelf) + aValid = false; } - if(isSkipSelf) - aValid = false; } } - return aValid; } -//******************************************************************** -bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) -{ - // DEBUG_THE_SAME_AS_SHAPE - ObjectPtr anObject; - GeomShapePtr aShape; - getGeomSelection(thePrs, anObject, aShape); - - setObject(anObject, aShape); - return true; -} - //******************************************************************** QList ModuleBase_WidgetMultiSelector::getControls() const { @@ -349,7 +271,7 @@ QList ModuleBase_WidgetMultiSelector::getControls() const //******************************************************************** void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { - activateShapeSelection(true); + activateSelection(true); activateFilters(myWorkshop, true); QList anEmptyList; // This method will call Selection changed event which will call onSelectionChanged @@ -358,29 +280,35 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() myWorkshop->setSelected(anEmptyList); } -//******************************************************************** -void ModuleBase_WidgetMultiSelector::onSelectionChanged() +void ModuleBase_WidgetMultiSelector::updateFocus() { - QList aSelected = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls); - - DataPtr aData = myFeature->data(); - AttributeSelectionListPtr aSelectionListAttr = - std::dynamic_pointer_cast(aData->attribute(attributeID())); - aSelectionListAttr->clear(); - - setSelection(aSelected); - - emit valuesChanged(); - // the updateObject method should be called to flush the updated sigal. The workshop listens it, - // calls validators for the feature and, as a result, updates the Apply button state. - updateObject(myFeature); - // Set focus to List control in order to make possible // to use Tab key for transfer the focus to next widgets myListControl->setCurrentRow(myListControl->model()->rowCount() - 1); myListControl->setFocus(); } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::updateSelectionName() +{ +} + +//******************************************************************** +QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const +{ + QIntList aShapeTypes; + + if (myTypeCombo->count() > 1) { + aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText())); + } + else { + for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) { + aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i))); + } + } + return aShapeTypes; +} + //******************************************************************** void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType) { @@ -390,39 +318,19 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum aShapeTypeName = myTypeCombo->itemText(idx); TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName); if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) { - activateShapeSelection(false); + activateSelection(false); activateFilters(myWorkshop, false); bool isBlocked = myTypeCombo->blockSignals(true); myTypeCombo->setCurrentIndex(idx); myTypeCombo->blockSignals(isBlocked); - activateShapeSelection(true); + activateSelection(true); activateFilters(myWorkshop, true); break; } } } -void ModuleBase_WidgetMultiSelector::activateShapeSelection(const bool isActivated) -{ - ModuleBase_IViewer* aViewer = myWorkshop->viewer(); - - if (isActivated) { - QString aNewType = myTypeCombo->currentText(); - QIntList aList; - if (true /*myIsUseChoice*/) { - aList.append(ModuleBase_Tools::shapeType(aNewType)); - } - else { - for(int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) - aList.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i))); - } - myWorkshop->activateSubShapesSelection(aList); - } else { - myWorkshop->deactivateSubShapesSelection(); - } -} - QList ModuleBase_WidgetMultiSelector::getAttributeSelection() const { QList aSelected; @@ -449,16 +357,6 @@ QList ModuleBase_WidgetMultiSelector::getAttributeSelectio return aSelected; } -//******************************************************************** -void ModuleBase_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, - ObjectPtr& theObject, - GeomShapePtr& theShape) -{ - // DEBUG_THE_SAME_AS_SHAPE - theObject = myWorkshop->selection()->getResult(thePrs); - theShape = myWorkshop->selection()->getShape(thePrs); -} - //******************************************************************** void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList) { @@ -510,4 +408,3 @@ void ModuleBase_WidgetMultiSelector::onListSelection() QList aItems = myListControl->selectedItems(); myCopyAction->setEnabled(!aItems.isEmpty()); } - diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 83e37216a..b1195e3e8 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -11,7 +11,7 @@ #define MODULEBASE_WIDGETMULTISELECTOR_H_ #include -#include +#include #include #include @@ -48,7 +48,7 @@ class QAction; * - tooltip - a tooltip for the widget * - type_choice - list of expected shape types. */ -class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetValidated +class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetSelector { Q_OBJECT public: @@ -63,18 +63,12 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge const std::string& theParentId); virtual ~ModuleBase_WidgetMultiSelector(); - //TODO: nds stabilization hotfix - virtual void disconnectSignals(); - virtual bool restoreValue(); /// Returns list of widget controls /// \return a control list virtual QList getControls() const; - /// The methiod called when widget is deactivated - virtual void deactivate(); - /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValues the wrapped selection values @@ -85,17 +79,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge /// \return a boolean value virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - /// Fills the attribute with the value of the selected owner - /// \param theOwner a selected owner - virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - public slots: /// Slot is called on selection type changed void onSelectionTypeChanged(); - /// Slot is called on selection changed - virtual void onSelectionChanged(); - protected slots: /// Slot for copy command in a list pop-up menu void onCopyItem(); @@ -104,9 +91,6 @@ protected slots: void onListSelection(); protected: - /// The methiod called when widget is activated - virtual void activateCustom(); - /// Saves the internal parameters to the given feature /// \return True in success virtual bool storeValueCustom() const; @@ -116,6 +100,19 @@ protected: /// parameters of the current attribute virtual void storeAttributeValue(); + /// Clear attribute + virtual void clearAttribute(); + + // Set the focus on the last item in the list + virtual void updateFocus(); + + /// Computes and updates name of selected object in the widget + virtual void updateSelectionName(); + + /// Retunrs a list of possible shape types + /// \return a list of shapes + virtual QIntList getShapeTypes() const; + /// Append the values to the model attribute of the widget. It casts this attribute to /// the specific type and set the given values /// \param theSelectedObject an object @@ -129,46 +126,28 @@ protected: /// \param theValid a boolean flag, if restore happens for valid parameters virtual void restoreAttributeValue(const bool theValid); - /// Returns true if selected shape corresponds to requested shape types - /// \param theShape a shape - bool acceptSubShape(const TopoDS_Shape& theShape) const; - /// Set current shape type for selection void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType); - /// Start shape selection - /// \param isActivated a state whether the shape is activated or deactivated in selection - void activateShapeSelection(const bool isActivated); - /// Return the attribute values wrapped in a list of viewer presentations /// \return a list of viewer presentations, which contains an attribute result and /// a shape. If the attribute do not uses the shape, it is empty - QList getAttributeSelection() const; + virtual QList getAttributeSelection() const; /// Update selection list void updateSelectionList(AttributeSelectionListPtr); - /// Return an object and geom shape by the viewer presentation - /// \param thePrs a selection - /// \param theObject an output object - /// \param theShape a shape of the selection - virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs, - ObjectPtr& theObject, - GeomShapePtr& theShape); - /// Converts the XML defined type choice to the validator type /// For example, the "Edges" is converted to "edge" std::string validatorType(const QString& theType) const; - /// List control +protected: + /// List control QListWidget* myListControl; /// Combobox of types QComboBox* myTypeCombo; - //TODO: Move into the base of selectors - ModuleBase_IWorkshop* myWorkshop; - /// Provides correspondance between Result object and its shape typedef QPair GeomSelection; @@ -184,9 +163,6 @@ protected: /// Variable of GeomSelection QList mySelection; - /// An instance of the "type_choice" validator. It is returns on validating in customValidator() - GeomValidators_ShapeType* myShapeValidator; - //bool myIsUseChoice; }; diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp new file mode 100755 index 000000000..f15479dd5 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -0,0 +1,146 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetSelector.h +// Created: 19 June 2015 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include + +ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetValidated(theParent, theData, theParentId), + myWorkshop(theWorkshop) +{ +} + +//******************************************************************** +ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector() +{ +} + +//TODO: nds stabilization hotfix +void ModuleBase_WidgetSelector::disconnectSignals() +{ + disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); +} + +//******************************************************************** +void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape) +{ + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + theObject = aSelection->getResult(thePrs); + theShape = aSelection->getShape(thePrs); +} + +//******************************************************************** +void ModuleBase_WidgetSelector::onSelectionChanged() +{ + clearAttribute(); + + QList aSelected = myWorkshop->selection()->getSelected( + ModuleBase_ISelection::AllControls); + setSelection(aSelected); + + emit valuesChanged(); + // the updateObject method should be called to flush the updated sigal. The workshop listens it, + // calls validators for the feature and, as a result, updates the Apply button state. + updateObject(myFeature); + + updateFocus(); +} + +//******************************************************************** +bool ModuleBase_WidgetSelector::acceptSubShape(const TopoDS_Shape& theShape) const +{ + bool aValid = true; + if (theShape.IsNull()) { + aValid = true; // do not check the shape type if the shape is empty + // extrusion uses a sketch object selectected in Object browser + } + else { + aValid = false; + TopAbs_ShapeEnum aShapeType = theShape.ShapeType(); + QIntList aShapeTypes = getShapeTypes(); + + QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end(); + for (; anIt != aLast; anIt++) { + if (aShapeType == *anIt) + aValid = true; + } + } + return aValid; +} + +//******************************************************************** +void ModuleBase_WidgetSelector::activateSelection(bool toActivate) +{ + updateSelectionName(); + + if (toActivate) { + myWorkshop->activateSubShapesSelection(getShapeTypes()); + } else { + myWorkshop->deactivateSubShapesSelection(); + } +} + +//******************************************************************** +void ModuleBase_WidgetSelector::activateCustom() +{ + connect(myWorkshop, SIGNAL(selectionChanged()), this, + SLOT(onSelectionChanged()), Qt::UniqueConnection); + + activateSelection(true); + + // Restore selection in the viewer by the attribute selection list + myWorkshop->setSelected(getAttributeSelection()); + + activateFilters(myWorkshop, true); +} + +//******************************************************************** +bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); + bool aValid; + // if there is no selected shape, the method returns true + if (!aShape.get()) + aValid = true; + else { + // Check that the selection corresponds to selection type + TopoDS_Shape aTopoShape = aShape->impl(); + aValid = acceptSubShape(aTopoShape); + } + if (aValid) { + // In order to avoid selection of the same object + ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult); + aValid = aSelectedFeature != myFeature; + } + return aValid; +} + +//******************************************************************** +bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(thePrs, anObject, aShape); + + setObject(anObject, aShape); + return true; +} + +//******************************************************************** +void ModuleBase_WidgetSelector::deactivate() +{ + disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + activateSelection(false); + activateFilters(myWorkshop, false); +} diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h new file mode 100755 index 000000000..4f3dd6e4a --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -0,0 +1,115 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetSelector.h +// Created: 19 June 2015 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetSelector_H +#define ModuleBase_WidgetSelector_H + +#include "ModuleBase.h" +#include "ModuleBase_WidgetValidated.h" +#include +#include "ModuleBase_Definitions.h" + +#include +#include + +class Config_WidgetAPI; +class QWidget; +class ModuleBase_IWorkshop; + +/** +* \ingroup GUI +* Implementation of widget for selection. +* This abstract interface is designed to be used for shape/multi shape selector widgets. +*/ +class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_WidgetValidated +{ +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 + ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, const std::string& theParentId); + + virtual ~ModuleBase_WidgetSelector(); + + /// Defines if it is supposed that the widget should interact with the viewer. + virtual bool isViewerSelector() { return true; } + + /// Checks the widget validity. By default, it returns true. + /// \param theValue a selected presentation in the view + /// \return a boolean value + virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); + + /// Fills the attribute with the value of the selected owner + /// \param theOwner a selected owner + virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); + + /// The methiod called when widget is deactivated + virtual void deactivate(); + + //TODO: nds stabilization hotfix + virtual void disconnectSignals(); + +protected: + /// Activate or deactivate selection + void activateSelection(bool toActivate); + + private slots: + /// Slot which is called on selection event + void onSelectionChanged(); + + protected: + /// Set an empty value to attribute + virtual void clearAttribute() = 0; + + // Update focus after the attribute value change + virtual void updateFocus() = 0; + + /// Return the attribute values wrapped in a list of viewer presentations + /// \return a list of viewer presentations, which contains an attribute result and + /// a shape. If the attribute do not uses the shape, it is empty + virtual QList getAttributeSelection() const = 0; + + /// Retunrs a list of possible shape types + /// \return a list of shapes + virtual QIntList getShapeTypes() const = 0; + + /// Computes and updates name of selected object in the widget + virtual void updateSelectionName() = 0; + + /// Store the values to the model attribute of the widget. It casts this attribute to + /// the specific type and set the given values + /// \param theSelectedObject an object + /// \param theShape a selected shape, which is used in the selection attribute + /// \return true if it is succeed + virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0; + + /// The methiod called when widget is activated + virtual void activateCustom(); + + /// Returns true if selected shape corresponds to requested shape types + /// \param theShape a shape + bool acceptSubShape(const TopoDS_Shape& theShape) const; + + /// Return an object and geom shape by the viewer presentation + /// \param thePrs a selection + /// \param theObject an output object + /// \param theShape a shape of the selection + virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape); + + //----------- Class members ------------- +protected: + /// Reference to workshop + ModuleBase_IWorkshop* myWorkshop; +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index d24d2b65d..c455309d7 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -71,8 +71,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_WidgetValidated(theParent, theData, theParentId), - myWorkshop(theWorkshop) + : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId) { QFormLayout* aLayout = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aLayout); @@ -94,14 +93,11 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen std::string aTypes = theData->getProperty("shape_types"); myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts); - - myShapeValidator = new GeomValidators_ShapeType(); } //******************************************************************** ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector() { - delete myShapeValidator; } //******************************************************************** @@ -159,33 +155,11 @@ QList ModuleBase_WidgetShapeSelector::getAttributeSelectio return aSelected; } -//******************************************************************** -void ModuleBase_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, - ObjectPtr& theObject, - GeomShapePtr& theShape) -{ - theObject = myWorkshop->selection()->getResult(thePrs); - theShape = myWorkshop->selection()->getShape(thePrs); -} - //******************************************************************** void ModuleBase_WidgetShapeSelector::clearAttribute() { - DataPtr aData = myFeature->data(); - AttributeSelectionPtr aSelect = aData->selection(attributeID()); - if (aSelect) { - aSelect->setValue(ResultPtr(), std::shared_ptr(new GeomAPI_Shape())); - return; - } - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - aRefAttr->setObject(ObjectPtr()); - return; - } - AttributeReferencePtr aRef = aData->reference(attributeID()); - if (aRef) { - aRef->setObject(ObjectPtr()); - } + // In order to make reselection possible, set empty object and shape should be done + setObject(ObjectPtr(), std::shared_ptr(new GeomAPI_Shape())); } //******************************************************************** @@ -206,31 +180,21 @@ QList ModuleBase_WidgetShapeSelector::getControls() const return aControls; } -//******************************************************************** -void ModuleBase_WidgetShapeSelector::onSelectionChanged() +void ModuleBase_WidgetShapeSelector::updateFocus() { - // In order to make reselection possible, set empty object and shape should be done - setObject(ObjectPtr(), std::shared_ptr(new GeomAPI_Shape())); - - QList aSelected = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls); - bool aHasObject = setSelection(aSelected); - - // the updateObject method should be called to flush the updated sigal. The workshop listens it, - // calls validators for the feature and, as a result, updates the Apply button state. - updateObject(myFeature); - // the widget loses the focus only if the selected object is set - if (aHasObject) + ObjectPtr anObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID())); + if (anObject.get()) emit focusOutWidget(this); } //******************************************************************** -bool ModuleBase_WidgetShapeSelector::acceptSubShape(const TopoDS_Shape& theShape) const +QIntList ModuleBase_WidgetShapeSelector::getShapeTypes() const { - foreach (QString aType, myShapeTypes) { - if (theShape.ShapeType() == ModuleBase_Tools::shapeType(aType)) - return true; + QIntList aShapeTypes; + foreach(QString aType, myShapeTypes) { + aShapeTypes.append(ModuleBase_Tools::shapeType(aType)); } - return false; + return aShapeTypes; } //******************************************************************** @@ -284,52 +248,6 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() } } - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate) -{ - updateSelectionName(); - - if (toActivate) { - QIntList aList; - foreach (QString aType, myShapeTypes) { - aList.append(ModuleBase_Tools::shapeType(aType)); - } - myWorkshop->activateSubShapesSelection(aList); - } else { - myWorkshop->deactivateSubShapesSelection(); - } -} - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::raisePanel() const -{ - QWidget* aParent = this->parentWidget(); - QWidget* aLastPanel = 0; - while (!aParent->inherits("QDockWidget")) { - aLastPanel = aParent; - aParent = aParent->parentWidget(); - if (!aParent) - return; - } - if (aParent->inherits("QDockWidget")) { - QDockWidget* aTabWgt = (QDockWidget*) aParent; - aTabWgt->raise(); - } -} - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::activateCustom() -{ - connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - activateSelection(true); - - // Restore selection in the viewer by the attribute selection list - myWorkshop->setSelected(getAttributeSelection()); - - activateFilters(myWorkshop, true); -} - //******************************************************************** void ModuleBase_WidgetShapeSelector::storeAttributeValue() { @@ -360,44 +278,3 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid) aRefAttr->setAttr(myRefAttribute); } } - -//******************************************************************** -bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) -{ - GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); - bool aValid; - // if there is no selected shape, the method returns true - if (!aShape.get()) - aValid = true; - else { - // Check that the selection corresponds to selection type - TopoDS_Shape aTopoShape = aShape->impl(); - aValid = acceptSubShape(aTopoShape); - } - if (aValid) { - // In order to avoid selection of the same object - ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); - FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult); - aValid = aSelectedFeature != myFeature; - } - return aValid; -} - -//******************************************************************** -bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) -{ - ObjectPtr anObject; - GeomShapePtr aShape; - getGeomSelection(thePrs, anObject, aShape); - - setObject(anObject, aShape); - return true; -} - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::deactivate() -{ - activateSelection(false); - activateFilters(myWorkshop, false); - disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); -} diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index b015a0bf3..7cb2427d2 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -8,7 +8,7 @@ #define ModuleBase_WidgetShapeSelector_H #include "ModuleBase.h" -#include "ModuleBase_WidgetValidated.h" +#include "ModuleBase_WidgetSelector.h" #include "ModuleBase_ViewerFilters.h" #include @@ -55,7 +55,7 @@ class GeomValidators_ShapeType; * which corresponds to ModelAPI_ResultConstruction object type * - concealment - hide or not hide selected object after operation */ -class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated +class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector { Q_OBJECT public: @@ -66,47 +66,21 @@ Q_OBJECT /// \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 ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData, const std::string& theParentId); + const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~ModuleBase_WidgetShapeSelector(); virtual bool restoreValue(); - /// Defines if it is supposed that the widget should interact with the viewer. - virtual bool isViewerSelector() { return true; } - /// Returns list of widget controls /// \return a control list virtual QList getControls() const; - /// Checks the widget validity. By default, it returns true. - /// \param theValue a selected presentation in the view - /// \return a boolean value - virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - - /// Fills the attribute with the value of the selected owner - /// \param theOwner a selected owner - virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - - /// The methiod called when widget is deactivated - virtual void deactivate(); - -protected: - /// Activate or deactivate selection - void activateSelection(bool toActivate); - - private slots: - /// Slot which is called on selection event - void onSelectionChanged(); - protected: /// Saves the internal parameters to the given feature /// \return True in success virtual bool storeValueCustom() const; - /// The methiod called when widget is activated - virtual void activateCustom(); - /// 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 @@ -119,17 +93,17 @@ protected: virtual void restoreAttributeValue(const bool theValid); /// Computes and updates name of selected object in the widget - void updateSelectionName(); + virtual void updateSelectionName(); - /// Raise panel which contains this widget - void raisePanel() const; + /// Clear attribute + virtual void clearAttribute(); - /// Returns true if selected shape corresponds to requested shape types - /// \param theShape a shape - bool acceptSubShape(const TopoDS_Shape& theShape) const; + // Update focus after the attribute value change + virtual void updateFocus(); - /// Clear attribute - void clearAttribute(); + /// Retunrs a list of possible shape types + /// \return a list of shapes + virtual QIntList getShapeTypes() const; /// Store the values to the model attribute of the widget. It casts this attribute to /// the specific type and set the given values @@ -145,15 +119,7 @@ protected: /// Return the attribute values wrapped in a list of viewer presentations /// \return a list of viewer presentations, which contains an attribute result and /// a shape. If the attribute do not uses the shape, it is empty - QList getAttributeSelection() const; - - /// Return an object and geom shape by the viewer presentation - /// \param thePrs a selection - /// \param theObject an output object - /// \param theShape a shape of the selection - virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs, - ObjectPtr& theObject, - GeomShapePtr& theShape); + virtual QList getAttributeSelection() const; //----------- Class members ------------- protected: @@ -163,9 +129,6 @@ protected: /// Input control of the widget QLineEdit* myTextLine; - /// Reference to workshop - ModuleBase_IWorkshop* myWorkshop; - /// List of accepting shapes types QStringList myShapeTypes; @@ -180,9 +143,6 @@ protected: AttributePtr myRefAttribute; /// A boolean value whether refAttr uses reference of object bool myIsObject; - - /// An instance of the "shape_type" validator. It is returns on validating in customValidator() - GeomValidators_ShapeType* myShapeValidator; }; #endif diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp index 19e6cc379..d6c000897 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.cpp +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -41,24 +41,25 @@ PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector() delete myExternalObjectMgr; } -//******************************************************************** -void PartSet_WidgetMultiSelector::onSelectionChanged() +bool PartSet_WidgetMultiSelector::setSelection(QList& theValues) { - ModuleBase_WidgetMultiSelector::onSelectionChanged(); - // TODO(nds): unite with externalObject(), remove parameters - //myFeature->execute(); - - DataPtr aData = myFeature->data(); - AttributeSelectionListPtr aSelectionListAttr = - std::dynamic_pointer_cast(aData->attribute(attributeID())); - - QObjectPtrList aListOfAttributeObjects; - for (int i = 0; i < aSelectionListAttr->size(); i++) { - AttributeSelectionPtr anAttr = aSelectionListAttr->value(i); - aListOfAttributeObjects.append(anAttr->context()); + bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues); + if (aSucceed) { + // TODO(nds): unite with externalObject(), remove parameters + //myFeature->execute(); + + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(aData->attribute(attributeID())); + + QObjectPtrList aListOfAttributeObjects; + for (int i = 0; i < aSelectionListAttr->size(); i++) { + AttributeSelectionPtr anAttr = aSelectionListAttr->value(i); + aListOfAttributeObjects.append(anAttr->context()); + } + myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature); } - - myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature); + return aSucceed; } //******************************************************************** @@ -77,7 +78,6 @@ void PartSet_WidgetMultiSelector::storeAttributeValue() { myIsInVaildate = true; ModuleBase_WidgetMultiSelector::storeAttributeValue(); - } //******************************************************************** diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h index 5e1b4a766..20fead7d5 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.h +++ b/src/PartSet/PartSet_WidgetMultiSelector.h @@ -32,7 +32,7 @@ Q_OBJECT /// \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); + const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~PartSet_WidgetMultiSelector(); @@ -46,9 +46,10 @@ Q_OBJECT /// Retrurns installed sketcher CompositeFeaturePtr sketch() const { return mySketch; } -public slots: - /// Slot is called on selection changed - virtual void onSelectionChanged(); + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValues the wrapped selection values + virtual bool setSelection(QList& theValues); protected: /// Checks the widget validity. By default, it returns true.