From 47b8d0384ebe05b12f944fcfad97c4686149668a Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 31 Oct 2014 13:03:44 +0300 Subject: [PATCH] Issue #192: store shape type for selection list attribute --- src/Model/Model_AttributeSelectionList.cpp | 11 ++++++++ src/Model/Model_AttributeSelectionList.h | 6 ++++ .../ModelAPI_AttributeSelectionList.h | 4 +++ .../ModuleBase_WidgetMultiSelector.cpp | 28 +++++++++++++++++-- .../ModuleBase_WidgetMultiSelector.h | 2 +- 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index a95510118..e1cb750aa 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -34,6 +34,16 @@ int Model_AttributeSelectionList::size() return mySize->Get(); } +int Model_AttributeSelectionList::selectionType() +{ + return (int) mySelectionType->Get(); +} + +void Model_AttributeSelectionList::setSelectionType(int theType) +{ + mySelectionType->Set((double) theType); +} + boost::shared_ptr Model_AttributeSelectionList::value(const int theIndex) { @@ -58,6 +68,7 @@ Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; if (!myIsInitialized) { mySize = TDataStd_Integer::Set(theLabel, 0); + mySelectionType = TDataStd_Real::Set(theLabel, 0); } else { // recollect mySubs int aNum = mySize->Get(); TDF_ChildIterator aSubIter(theLabel); diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index 103b213f1..f10d6d97f 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -9,6 +9,7 @@ #include "Model_AttributeSelection.h" #include #include +#include #include /**\class Model_AttributeSelectionList @@ -20,6 +21,7 @@ class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList { Handle(TDataStd_Integer) mySize; ///< Contains size of this list + Handle(TDataStd_Real) mySelectionType; ///< Contains current index, TODO: make it integer, not real std::vector > mySubs; /// the selection attributes public: /// Adds the new reference to the end of the list @@ -29,6 +31,10 @@ public: /// Returns the number ofselection attributes in the list MODEL_EXPORT virtual int size(); + MODEL_EXPORT virtual int selectionType(); + + MODEL_EXPORT virtual void setSelectionType(int); + /// Returns the attribute selection by the index (zero based) MODEL_EXPORT virtual boost::shared_ptr value(const int theIndex); diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index 6dc13dd3a..aef9046ae 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -24,6 +24,10 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute /// Returns the number ofselection attributes in the list virtual int size() = 0; + virtual int selectionType() = 0; + + virtual void setSelectionType(int) = 0; + /// Returns the attribute selection by the index (zero based) virtual boost::shared_ptr value(const int theIndex) = 0; diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index ed40ee204..ab89d70ef 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -45,8 +45,8 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myTypeCombo = new QComboBox(myMainWidget); // There is no sence to paramerize list of types while we can not parametrize selection mode QString aTypesStr("Vertices Edges Faces Solids"); - myShapeTypes = aTypesStr.split(' '); - myTypeCombo->addItems(myShapeTypes); + QStringList aShapeTypes = aTypesStr.split(' '); + myTypeCombo->addItems(aShapeTypes); aMainLay->addWidget(myTypeCombo, 0, 1); QLabel* aListLabel = new QLabel(tr("Selected objects:"), myMainWidget); @@ -81,6 +81,11 @@ bool ModuleBase_WidgetMultiSelector::storeValue() const if (aSelectionListAttr && (mySelection.size() > 0)) { aSelectionListAttr->clear(); + // Store shapes type + TopAbs_ShapeEnum aCurrentType = + ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText()); + aSelectionListAttr->setSelectionType((int) aCurrentType); + // Store selection in the attribute foreach (GeomSelection aSelec, mySelection) { aSelectionListAttr->append(aSelec.first, aSelec.second); } @@ -102,6 +107,10 @@ bool ModuleBase_WidgetMultiSelector::restoreValue() if (aSelectionListAttr) { mySelection.clear(); + // Restore shape type + TopAbs_ShapeEnum aShapeType = (TopAbs_ShapeEnum) aSelectionListAttr->selectionType(); + setCurrentShapeType(aShapeType); + // Restore selection in the list for (int i = 0; i < aSelectionListAttr->size(); i++) { AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value())); @@ -202,6 +211,21 @@ void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_Listcount(); ++idx) { + aShapeTypeName = myTypeCombo->currentText(); + TopAbs_ShapeEnum aRefType = ModuleBase_WidgetShapeSelector::shapeType(aShapeTypeName); + if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) { + myTypeCombo->setCurrentIndex(idx); + break; + } + } +} + //******************************************************************** void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate) { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index c141c87e9..a456a10dc 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -61,6 +61,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model protected: void filterShapes(const NCollection_List& theShapesToFilter, NCollection_List& theResult); + void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType); private: void updateSelectionList(); @@ -73,7 +74,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model ModuleBase_IWorkshop* myWorkshop; /// If true then local selector has to be activated in context - QStringList myShapeTypes; bool myUseSubShapes; bool myIsActive; -- 2.39.2