Salome HOME
Using AttributeSelection for Groups.
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 23 Oct 2014 11:47:52 +0000 (15:47 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 23 Oct 2014 11:47:52 +0000 (15:47 +0400)
src/FeaturesPlugin/FeaturesPlugin_Group.cpp
src/GeomAPI/GeomAPI_Shape.h
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_Selection.h

index 4a5a34bc21f8077f78054ef9108b6d7c3d63da3b..ae5d82771e3331402a607199249aedac24813317 100644 (file)
@@ -8,6 +8,8 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
 
 using namespace std;
 
@@ -18,7 +20,7 @@ FeaturesPlugin_Group::FeaturesPlugin_Group()
 void FeaturesPlugin_Group::initAttributes()
 {
   data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type());
-  data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeString::type());
+  data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::type());
 }
 
 void FeaturesPlugin_Group::execute()
index 3aa0987f7e2fbaca01552535628838c75ace50f7..96db714562f42983e3730546629d62bb049c306e 100644 (file)
@@ -31,4 +31,7 @@ class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface
 
 };
 
+//! Pointer on attribute object
+typedef boost::shared_ptr<GeomAPI_Shape> GeomShapePtr;
+
 #endif
index 98d4af7d625254d2b76c55303a811ad808c51008..08f5f6e5d85248b1f32e7f4b029bc4d79b479c56 100644 (file)
@@ -50,4 +50,7 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
   }
 };
 
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelection> AttributeSelectionPtr;
+
 #endif
index 4305471d3c655a9be795a976732b010a1557952c..6dc13dd3a6b35c9a8467b16af7efe4e010c8c8e1 100644 (file)
@@ -54,4 +54,7 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
   }
 };
 
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelectionList> AttributeSelectionListPtr;
+
 #endif
index 43bd0ea86650863887c248c69ac603b3059a73ff..72845616b89eea80aad2a15e2175a7d42a506a31 100644 (file)
@@ -47,7 +47,8 @@ class ModuleBase_ISelection
   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
 
   //! Returns list of currently selected shapes
-  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const = 0;
+  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
+    std::list<ObjectPtr>& theOwners) const = 0;
 
 };
 
index 189b659c4d2f89a281b1f8e895fb608f9d2ac8b9..563cc18780fa6d01231a8b41a78bb38d3cb47eee 100644 (file)
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeSelectionList.h>
 
 #include <Config_WidgetAPI.h>
 
 #include <QGridLayout>
 #include <QLabel>
-#include <QTextEdit>
+#include <QListWidget>
 #include <QObject>
 #include <QString>
 #include <QComboBox>
@@ -39,17 +40,20 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   myMainWidget = new QWidget(theParent);
   QGridLayout* aMainLay = new QGridLayout(myMainWidget);
   ModuleBase_Tools::adjustMargins(aMainLay);
+
   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);
+
+  myListControl = new QListWidget(myMainWidget);
   aMainLay->addWidget(myListControl, 2, 0, 2, -1);
   aMainLay->setColumnStretch(1, 1);
   myMainWidget->setLayout(aMainLay);
@@ -72,11 +76,18 @@ bool ModuleBase_WidgetMultiSelector::storeValue() const
   if(!myFeature)
     return false;
   DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-  QString aWidgetValue = myListControl->toPlainText();
-  aStringAttr->setValue(aWidgetValue.toStdString());
-  updateObject(myFeature);
-  return true;
+  AttributeSelectionListPtr aSelectionListAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  if (aSelectionListAttr && (mySelection.size() > 0)) {
+    aSelectionListAttr->clear();
+    foreach (GeomSelection aSelec, mySelection) {
+      aSelectionListAttr->append(aSelec.first, aSelec.second);
+    }
+    updateObject(myFeature);
+    return true;
+  }
+  return false;
 }
 
 bool ModuleBase_WidgetMultiSelector::restoreValue()
@@ -86,13 +97,19 @@ bool ModuleBase_WidgetMultiSelector::restoreValue()
   if(!myFeature)
     return false;
   DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-
-  bool isBlocked = myListControl->blockSignals(true);
-  myListControl->setText(QString::fromStdString(aStringAttr->value()));
-  myListControl->blockSignals(isBlocked);
-
-  return true;
+  AttributeSelectionListPtr aSelectionListAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  if (aSelectionListAttr) {
+    mySelection.clear();
+    for (int i = 0; i < aSelectionListAttr->size(); i++) {
+      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+      mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
+    }
+    updateSelectionList();
+    return true;
+  }
+  return false;
 }
 
 QWidget* ModuleBase_WidgetMultiSelector::getControl() const
@@ -121,16 +138,38 @@ bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEve
 void ModuleBase_WidgetMultiSelector::onSelectionChanged()
 {
   ModuleBase_ISelection* aSelection = myWorkshop->selection();
-  NCollection_List<TopoDS_Shape> aSelectedShapes, aFilteredShapes;
-  aSelection->selectedShapes(aSelectedShapes);
-  QString aText;
-  if (!aSelectedShapes.IsEmpty()) {
-    filterShapes(aSelectedShapes, aFilteredShapes);
-    aText = QString("Items selected: %1").arg(aFilteredShapes.Size());
+  NCollection_List<TopoDS_Shape> aSelectedShapes; //, aFilteredShapes;
+  std::list<ObjectPtr> aOwnersList;
+  aSelection->selectedShapes(aSelectedShapes, aOwnersList);
+
+  mySelection.clear();
+  std::list<ObjectPtr>::const_iterator aIt;
+  NCollection_List<TopoDS_Shape>::Iterator aShpIt(aSelectedShapes);
+  GeomShapePtr aShape;
+  for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) {
+    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+    aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+    aShape->setImpl(new TopoDS_Shape(aShpIt.Value()));
+    mySelection.append(GeomSelection(aResult, aShape));
+  }
+  updateSelectionList();
+  emit valuesChanged();
+}
+
+
+void ModuleBase_WidgetMultiSelector::updateSelectionList()
+{
+  myListControl->clear();
+  int i = 1;
+  foreach (GeomSelection aSel, mySelection) {
+    QString aName(aSel.first->data()->name().c_str());
+    aName += ":" + myTypeCombo->currentText() + QString::number(i);
+    myListControl->addItem(aName);
+    i++;
   }
-  myListControl->setText(aText);
 }
 
+
 void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
                                                   NCollection_List<TopoDS_Shape>& theResult)
 {
index bc184d5e57323fb3c08d0f289e634a232434e130..c141c87e97d77fd96dddae7147473173afc8a547 100644 (file)
 #include <ModuleBase.h>
 #include <ModuleBase_ModelWidget.h>
 
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_Result.h>
+
 #include <NCollection_List.hxx>
 #include <TopoDS_Shape.hxx>
 
 #include <QList>
 #include <QString>
 #include <QStringList>
+#include <QPair>
 
 class QWidget;
-class QTextEdit;
+class QListWidget;
 class QComboBox;
 class ModuleBase_IWorkshop;
 
@@ -59,7 +63,9 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
                     NCollection_List<TopoDS_Shape>& theResult);
 
  private:
-  QTextEdit* myListControl;
+   void updateSelectionList();
+
+  QListWidget* myListControl;
   QComboBox* myTypeCombo;
   QWidget* myMainWidget;
 
@@ -70,6 +76,9 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
   QStringList myShapeTypes;
   bool myUseSubShapes;
   bool myIsActive;
+
+  typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
+  QList<GeomSelection> mySelection;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index d68309a4f6defcdc2d0790500e3c8b8f69d5961f..47045007066d2890123230111f8352465ea8efc1 100644 (file)
@@ -194,7 +194,8 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
     boost::shared_ptr<GeomAPI_Shape> aShape;
     if (myUseSubShapes) {
       NCollection_List<TopoDS_Shape> aShapeList;
-      myWorkshop->selection()->selectedShapes(aShapeList);
+      std::list<ObjectPtr> aOwners;
+      myWorkshop->selection()->selectedShapes(aShapeList, aOwners);
       if (aShapeList.Extent() > 0) {
         aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
         aShape->setImpl(new TopoDS_Shape(aShapeList.First()));
index d39e31359aff576cb559a684bc691afbb432a15c..1b91cb3dccad3b2dc905d617c40f91ebf8b16474 100644 (file)
@@ -111,13 +111,20 @@ void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
 }
 
 //**************************************************************
-void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
+void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
+                                    std::list<ObjectPtr>& theOwners) const
 {
   theList.Clear();
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
     TopoDS_Shape aShape = aContext->SelectedShape();
-    if (!aShape.IsNull())
+    if (!aShape.IsNull()) {
       theList.Append(aShape);
+      Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
+      Handle(AIS_InteractiveObject) anObj = 
+        Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
+      ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
+      theOwners.push_back(anObject);
+    }
   }
 }
index b67adbc52e34b5da5b71e46f1ea32eadae53d7de..5f399a7ee32450f7ba0d3258a3d35b283d2c0154 100644 (file)
@@ -52,7 +52,8 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const;
 
   //! Returns list of currently selected shapes
-  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const;
+  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theShapes, 
+    std::list<ObjectPtr>& theOwners) const;
 
  private:
   XGUI_Workshop* myWorkshop;