From: sbh Date: Thu, 9 Oct 2014 17:14:49 +0000 (+0400) Subject: Selection processing in multiselector control. X-Git-Tag: V_0.5~105 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d4267cafa3b0f01f3ed6c4d98f0133a8dec6f0d9;p=modules%2Fshaper.git Selection processing in multiselector control. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.cpp b/src/FeaturesPlugin/FeaturesPlugin_Group.cpp index 3a9a07a15..4a5a34bc2 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Group.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Group.cpp @@ -18,15 +18,15 @@ FeaturesPlugin_Group::FeaturesPlugin_Group() void FeaturesPlugin_Group::initAttributes() { data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type()); - data()->addAttribute(FeaturesPlugin_Group::TYPE_ID(), ModelAPI_AttributeInteger::type()); data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeString::type()); } void FeaturesPlugin_Group::execute() { - AttributeIntegerPtr aTypeAttr = boost::dynamic_pointer_cast( - data()->attribute(FeaturesPlugin_Group::TYPE_ID())); - if (!aTypeAttr) + AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast( + data()->attribute(FeaturesPlugin_Group::NAME_ID())); + if (!aNameAttr) return; - int aType = aTypeAttr->value(); + std::string aName = aNameAttr->value(); + data()->setName(aName); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.h b/src/FeaturesPlugin/FeaturesPlugin_Group.h index 12d298704..34385caab 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Group.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Group.h @@ -18,18 +18,12 @@ class FeaturesPlugin_Group : public ModelAPI_Feature static const std::string MY_GROUP_ID("Group"); return MY_GROUP_ID; } - /// attribute name of group type + /// attribute name of group name inline static const std::string& NAME_ID() { static const std::string MY_GROUP_NAME_ID("group_name"); return MY_GROUP_NAME_ID; } - /// attribute name of group type - inline static const std::string& TYPE_ID() - { - static const std::string MY_GROUP_TYPE_ID("group_type"); - return MY_GROUP_TYPE_ID; - } /// attribute name of selected entities list inline static const std::string& LIST_ID() { diff --git a/src/FeaturesPlugin/group_widget.xml b/src/FeaturesPlugin/group_widget.xml index 7b45d68f5..5d8ad7565 100644 --- a/src/FeaturesPlugin/group_widget.xml +++ b/src/FeaturesPlugin/group_widget.xml @@ -2,14 +2,8 @@ - + tooltip="Name of the group" /> + tooltip="List of selected objects" + type_choice="Vertices Edges Faces Solids" /> \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index ffb17b5c2..8df14bdc3 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -24,8 +24,8 @@ void adjustMargins(QLayout* theLayout) { if(!theLayout) return; - theLayout->setContentsMargins(5, 5, 5, 5); - theLayout->setSpacing(5); + theLayout->setContentsMargins(2, 5, 5, 2); + theLayout->setSpacing(4); } void zeroMargins(QWidget* theWidget) diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index c7f0c609c..057c4d5d3 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -298,7 +298,7 @@ QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent) QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent) { ModuleBase_WidgetMultiSelector* aMultiselectorWgt = - new ModuleBase_WidgetMultiSelector(theParent, myWidgetApi,myParentId); + new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId); myModelWidgets.append(aMultiselectorWgt); return aMultiselectorWgt->getControl(); } diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 4ee9a4b25..189b659c4 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -6,6 +6,9 @@ */ #include +#include +#include +#include #include #include @@ -15,37 +18,52 @@ #include -#include +#include #include #include #include #include +#include +#include #include #include ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId) + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId), + myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false) { myMainWidget = new QWidget(theParent); - QVBoxLayout* aMainLay = new QVBoxLayout(myMainWidget); + QGridLayout* aMainLay = new QGridLayout(myMainWidget); ModuleBase_Tools::adjustMargins(aMainLay); - QString aTitle = QString::fromStdString(theData->widgetLabel()); - QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget); - aMainLay->addWidget(aTitleLabel); + QLabel* aTypeLabel = new QLabel(tr("Type"), myMainWidget); + aMainLay->addWidget(aTypeLabel, 0, 0); + myTypeCombo = new QComboBox(myMainWidget); + std::string aTypes = theData->getProperty("type_choice"); + myShapeTypes = QString::fromStdString(aTypes).split(' '); + myTypeCombo->addItems(myShapeTypes); + aMainLay->addWidget(myTypeCombo, 0, 1); + QLabel* aListLabel = new QLabel(tr("Selected objects:"), myMainWidget); + aMainLay->addWidget(aListLabel, 1, 0, 1, -1); myListControl = new QTextEdit(myMainWidget); myListControl->setReadOnly(true); - aMainLay->addWidget(myListControl); - myListControl->setMinimumHeight(20); + aMainLay->addWidget(myListControl, 2, 0, 2, -1); + aMainLay->setColumnStretch(1, 1); myMainWidget->setLayout(aMainLay); - connect(myListControl, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged())); + //TODO: Move into the base class + myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); + //TODO_END + connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged())); + activateSelection(true); } ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector() { + activateSelection(false); } bool ModuleBase_WidgetMultiSelector::storeValue() const @@ -63,6 +81,7 @@ bool ModuleBase_WidgetMultiSelector::storeValue() const bool ModuleBase_WidgetMultiSelector::restoreValue() { + return false; // A rare case when plugin was not loaded. if(!myFeature) return false; @@ -84,6 +103,66 @@ QWidget* ModuleBase_WidgetMultiSelector::getControl() const QList ModuleBase_WidgetMultiSelector::getControls() const { QList result; + result << myTypeCombo; result << myListControl; return result; } + +//******************************************************************** +bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent) +{ + if (theObj == myListControl) { + if (theEvent->type() == QEvent::FocusIn) + activateSelection(true); + } + return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); +} + +void ModuleBase_WidgetMultiSelector::onSelectionChanged() +{ + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + NCollection_List aSelectedShapes, aFilteredShapes; + aSelection->selectedShapes(aSelectedShapes); + QString aText; + if (!aSelectedShapes.IsEmpty()) { + filterShapes(aSelectedShapes, aFilteredShapes); + aText = QString("Items selected: %1").arg(aFilteredShapes.Size()); + } + myListControl->setText(aText); +} + +void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List& theShapesToFilter, + NCollection_List& theResult) +{ + if(myTypeCombo->count() == 0 || theShapesToFilter.IsEmpty()) + return; + TopAbs_ShapeEnum aReferenceType = + ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText()); + NCollection_List::Iterator anIter(theShapesToFilter); + for (; anIter.More(); anIter.Next()) { + TopoDS_Shape aShape = anIter.Value(); + if (aShape.IsNull() || aShape.ShapeType() != aReferenceType) + continue; + theResult.Append(aShape); + } +} + +void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate) +{ + myIsActive = toActivate; + if (myIsActive) { + connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + onSelectionTypeChanged(); + } else { + disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + myWorkshop->deactivateSubShapesSelection(); + } +} + +void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() +{ + QString aNewType = myTypeCombo->currentText(); + QIntList aList; + aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType)); + myWorkshop->activateSubShapesSelection(aList); +} diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index d631f35ef..bc184d5e5 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -11,20 +11,26 @@ #include #include +#include +#include + #include #include #include class QWidget; class QTextEdit; +class QComboBox; +class ModuleBase_IWorkshop; class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget { Q_OBJECT public: ModuleBase_WidgetMultiSelector(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId); + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId); virtual ~ModuleBase_WidgetMultiSelector(); /// Saves the internal parameters to the given feature @@ -41,11 +47,29 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model /// \return a control list virtual QList getControls() const; - //public slots: + virtual bool eventFilter(QObject* theObj, QEvent* theEvent); + + public slots: + void activateSelection(bool toActivate); + void onSelectionTypeChanged(); + void onSelectionChanged(); + + protected: + void filterShapes(const NCollection_List& theShapesToFilter, + NCollection_List& theResult); private: QTextEdit* myListControl; + QComboBox* myTypeCombo; QWidget* myMainWidget; + + //TODO: Move into the base of selectors + ModuleBase_IWorkshop* myWorkshop; + + /// If true then local selector has to be activated in context + QStringList myShapeTypes; + bool myUseSubShapes; + bool myIsActive; }; #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 7c1d0f69a..0b433e663 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -2,24 +2,29 @@ // Created: 2 June 2014 // Author: Vitaly Smetannikov -#include "ModuleBase_WidgetShapeSelector.h" -#include +#include +#include #include -#include "ModuleBase_WidgetValue.h" +#include #include -#include "ModuleBase_WidgetValueFeature.h" - +#include +#include #include -#include -#include - +#include +#include +#include +#include #include #include -#include +#include +#include #include #include #include +#include +#include #include +#include #include @@ -35,7 +40,14 @@ #include #include +#include +#include + +#include + +#include #include +#include typedef QMap ShapeTypes; static ShapeTypes MyShapeTypes; @@ -44,16 +56,21 @@ TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::shapeType(const QString& theTyp { if (MyShapeTypes.count() == 0) { MyShapeTypes["face"] = TopAbs_FACE; + MyShapeTypes["faces"] = TopAbs_FACE; MyShapeTypes["vertex"] = TopAbs_VERTEX; + MyShapeTypes["vertices"] = TopAbs_VERTEX; MyShapeTypes["wire"] = TopAbs_WIRE; MyShapeTypes["edge"] = TopAbs_EDGE; + MyShapeTypes["edges"] = TopAbs_EDGE; MyShapeTypes["shell"] = TopAbs_SHELL; MyShapeTypes["solid"] = TopAbs_SOLID; + MyShapeTypes["solids"] = TopAbs_SOLID; } QString aType = theType.toLower(); if (MyShapeTypes.contains(aType)) return MyShapeTypes[aType]; - throw std::invalid_argument("Shape type defined in XML is not implemented!"); + Events_Error::send("Shape type defined in XML is not implemented!"); + return TopAbs_SHAPE; } ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,