]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Extending Multi selector for ModelAPI_AttributeRefAttrList
authornds <nds@opencascade.com>
Thu, 21 Jan 2016 07:34:54 +0000 (10:34 +0300)
committernds <nds@opencascade.com>
Thu, 21 Jan 2016 07:34:54 +0000 (10:34 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h

index d80620a4895a15befa1605d1c770b1b7b465600d..56f7e2bbc1d5c7ed4314f2911a06f994735d9c9c 100755 (executable)
@@ -7,6 +7,9 @@
 #include "ModuleBase_IWorkshop.h"\r
 \r
 #include <ModelAPI_Feature.h>\r
+#include <ModelAPI_Attribute.h>\r
+\r
+#include <GeomAPI_Shape.h>\r
 \r
 #include <QString>\r
 #include <QObject>\r
@@ -237,6 +240,18 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// Default realization is empty\r
   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};\r
 \r
+  /// Finds a shape by attribute if it is possible\r
+  /// \param theAttribute an attribute\r
+  /// \return a geom shape\r
+  virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;\r
+\r
+  /// Finds an attribute by geom shape if it is possible\r
+  /// \param theObject an object of the attribute\r
+  /// \param theGeomShape a geom shape\r
+  /// \return theAttribute\r
+  virtual AttributePtr findAttribute(const ObjectPtr& theObject,\r
+                                     const GeomShapePtr& theGeomShape) = 0;\r
+\r
 signals:\r
   /// Signal which is emitted when operation is launched\r
   void operationLaunched();\r
index 00b13340261664da441ec695877efc0d5a66cfe2..28d40d2829a9c617de91772783b11aec72d49d77 100755 (executable)
@@ -20,6 +20,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeRefAttrList.h>
 
 #include <Config_WidgetAPI.h>
 
@@ -221,6 +222,7 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue()
 
   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
   std::string aType = anAttribute->attributeType();
+
   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr =
                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
@@ -232,6 +234,44 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue()
                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
     mySelectionCount = aRefListAttr->size();
   }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+    mySelectionCount = aRefAttrListAttr->size();
+  }
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+  AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
+  std::string aType = anAttribute->attributeType();
+  if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+
+    bool isDone = false;
+    if (!thePrs.shape().IsNull()) {
+      GeomShapePtr aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+      aGeomShape->setImpl(new TopoDS_Shape(thePrs.shape()));
+
+      AttributePtr anAttribute = myWorkshop->module()->findAttribute(thePrs.object(), aGeomShape);
+      if (anAttribute.get()) {
+        aRefAttrListAttr->append(anAttribute);
+        isDone = true;
+      }
+    }
+    if (!isDone)
+      ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
+  }
+  else {
+    ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
+    /*ObjectPtr anObject;
+    GeomShapePtr aShape;
+    getGeomSelection(thePrs, anObject, aShape);
+    setObject(anObject, aShape);*/
+  }
+  return true;
 }
 
 //********************************************************************
@@ -259,6 +299,14 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
     for (int i = 0; i < aCountAppened; i++)
       aRefListAttr->removeLast();
   }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+    // restore objects in the attribute. Indeed there is only one stored object
+    int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
+    for (int i = 0; i < aCountAppened; i++)
+      aRefAttrListAttr->removeLast();
+  }
 }
 
 //********************************************************************
@@ -276,6 +324,11 @@ void ModuleBase_WidgetMultiSelector::clearAttribute()
                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
     aRefListAttr->clear();
   }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+    aRefAttrListAttr->clear();
+  }
 }
 
 //********************************************************************
@@ -295,6 +348,11 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
     aRefListAttr->append(theSelectedObject);
   }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    //AttributeRefAttrListPtr aRefAttrListAttr =
+    //             std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+    //aRefAttrListAttr->clear();
+  }
 }
 
 //********************************************************************
@@ -377,19 +435,24 @@ bool ModuleBase_WidgetMultiSelector::processDelete()
   bool aDone = false;
   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
   std::string aType = anAttribute->attributeType();
+  aDone = !anAttributeIds.empty();
   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr =
                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
-    aDone = !anAttributeIds.empty();
     aSelectionListAttr->remove(anAttributeIds);
 
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
     AttributeRefListPtr aRefListAttr =
                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
-      aDone = !anAttributeIds.empty();
       aRefListAttr->remove(anAttributeIds);
   }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+    aRefAttrListAttr->remove(anAttributeIds);
+  }
+
   if (aDone) {
     // update object is necessary to flush update signal. It leads to objects references map update
     // and the operation presentation will not contain deleted items visualized as parameters of
@@ -512,6 +575,27 @@ void ModuleBase_WidgetMultiSelector::updateSelectionList()
       }
     }
   }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+    for (int i = 0; i < aRefAttrListAttr->size(); i++) {
+      AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
+      QString aName;
+      if (anAttribute.get()) {
+        std::string anAttrName = generateName(anAttribute);
+        aName = QString::fromStdString(anAttrName);
+      }
+      else {
+        ObjectPtr anObject = aRefAttrListAttr->object(i);
+        if (anObject.get()) {
+          aName = anObject->data()->name().c_str();
+        }
+      }
+      QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
+      anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
+      myListControl->addItem(anItem);
+    }
+  }
 
   // We have to call repaint because sometimes the List control is not updated
   myListControl->repaint();
@@ -618,4 +702,25 @@ void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<in
       }
     }
   }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+    for (int i = 0; i < aRefAttrListAttr->size(); i++) {
+      // filter by attribute indices only if the container is not empty otherwise return all items
+      if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
+        continue;
+      ObjectPtr anObject = aRefAttrListAttr->object(i);
+      if (!anObject.get())
+        continue;
+      TopoDS_Shape aShape;
+      AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
+      if (anAttribute.get()) {
+        GeomShapePtr aGeomShape = myWorkshop->module()->findShape(anAttribute);
+        if (aGeomShape.get()) {
+          aShape = aGeomShape->impl<TopoDS_Shape>();
+        }
+        theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
+      }
+    }
+  }
 }
index 7156e051789862a0df0d16e916005aa0ccc65be2..54ff6ddcf44298aecc9c530e5b787e70dee7f35e 100755 (executable)
@@ -116,6 +116,10 @@ protected:
   /// parameters of the current attribute
   virtual void storeAttributeValue();
 
+  /// Fills the attribute with the value of the selected owner
+  /// \param thePrs a selected owner
+  virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
   /// Clear attribute
   virtual void clearAttribute();
 
index 99edfb890e390b33024d5a85b05baefa0aa2ed43..0f0b2c15a8eda3efe5a491fa3fa50df0ec93a98b 100755 (executable)
@@ -170,3 +170,14 @@ void ModuleBase_WidgetSelector::deactivate()
   ModuleBase_ModelWidget::deactivate();
 }
 
+//********************************************************************
+std::string ModuleBase_WidgetSelector::generateName(const AttributePtr& theAttribute)
+{
+  std::string aName;
+  if (theAttribute.get() != NULL) {
+    std::stringstream aStreamName;
+    aStreamName << theAttribute->owner()->data()->name() << "/"<< theAttribute->id();
+    aName = aStreamName.str();
+  }
+  return aName;
+}
index 63404f66fd61bcb1c1da71f34ff15260e56b18ba..150a0ce349d07410f8403d447a8fb27c9372e547 100755 (executable)
@@ -13,6 +13,7 @@
 #include "ModuleBase_Definitions.h"
 
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
 #include <GeomAPI_Shape.h>
 
 class Config_WidgetAPI;
@@ -107,6 +108,10 @@ Q_OBJECT
                                 GeomShapePtr& theShape);
 
   //----------- Class members -------------
+  /// Returns a name in the next form: attribute_feature_name/attribute_id
+  /// \param theAttribute a model attribute
+  /// \return string value
+  static std::string generateName(const AttributePtr& theAttribite);
 };
 
 #endif
index 4db52fd2a7171f6e309d193870a09856fa1c26cd..a51e16be651c62dc2258c39e65d020d8bdf05cd5 100644 (file)
@@ -231,12 +231,8 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
       AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
       if (aRefAttr && aRefAttr->attr().get() != NULL) {
         //myIsObject = aRefAttr->isObject();
-        AttributePtr anAttr = aRefAttr->attr();
-        if (anAttr.get() != NULL) {
-          std::stringstream aName;
-          aName <<anAttr->owner()->data()->name()<<"/"<<anAttr->id();
-          myTextLine->setText(QString::fromStdString(aName.str()));
-        }
+        std::string anAttrName = generateName(aRefAttr->attr());
+        myTextLine->setText(QString::fromStdString(anAttrName));
       }
       else {
         myTextLine->setText(getDefaultValue().c_str());
index 35c38bc464fbdc9ab2714a7325dfd0704140ed62..e7502e84df8cb3fb85b3652b6cfbd88cd075f6dc 100755 (executable)
@@ -1030,6 +1030,27 @@ void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
   }
 }
 
+//******************************************************
+GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
+{
+  GeomShapePtr aGeomShape;
+
+  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+  if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
+    aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
+  }
+  return aGeomShape;
+}
+
+//******************************************************
+AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
+                                           const GeomShapePtr& theGeomShape)
+{
+  TopoDS_Shape aTDSShape = theGeomShape->impl<TopoDS_Shape>();
+  return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, 
+                                                      mySketchMgr->activeSketch());
+}
+
 //******************************************************
 void PartSet_Module::onBooleanOperationChange(int theOperation)
 {
index 36424180e362642a4866f70766d9be64808db8d5..392dfa04edb5b3d7d6493c589f8e4aea8a954ae2 100755 (executable)
@@ -244,6 +244,17 @@ public:
   /// Default realization is empty
   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
 
+  /// Finds a shape by attribute if it is possible
+  /// \param theAttribute an attribute
+  /// \return a geom shape
+  virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
+
+  /// Finds an attribute by geom shape if it is possible
+  /// \param theObject an object of the attribute
+  /// \param theGeomShape a geom shape
+  /// \return theAttribute
+  virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
+
 public slots:
   /// Redefines the parent method in order to customize the next case:
   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,