]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
It provides a point attribute restore selection by activation of a shape selection...
authornds <natalia.donis@opencascade.com>
Thu, 21 May 2015 10:33:10 +0000 (13:33 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 21 May 2015 10:33:10 +0000 (13:33 +0300)
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/XGUI/XGUI_Displayer.cpp

index e21d756fd7751ffb54c52b3130e7b7590f66f7e4..2dcd3662d1fa3457edf6be3d096680d4a8f34ea6 100644 (file)
@@ -122,10 +122,6 @@ Q_OBJECT
   /// \param theShape a shape
   virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
 
-  // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute
-  /// \return a shape
-  GeomShapePtr getShape() const;
-
   /// Clear attribute
   void clearAttribute();
 
@@ -136,6 +132,10 @@ Q_OBJECT
   /// \return true if it is succeed
   virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
+  /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
+  /// \return a shape
+  virtual GeomShapePtr getShape() const;
+
   /// 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
index cea864a6af9dcfe1aa1ac198b7ba02b723f7639c..a4dbf44f6f70884839b7e4e019812914989f153b 100644 (file)
 
 #include <XGUI_Workshop.h>
 
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_SelectionMgr.h>
+#include <XGUI_Selection.h>
+#include <SelectMgr_IndexedMapOfOwner.hxx>
+#include <StdSelect_BRepOwner.hxx>
+
 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          ModuleBase_IWorkshop* theWorkshop,
                                                          const Config_WidgetAPI* theData,
@@ -63,6 +70,67 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
   return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);
 }
 
+//********************************************************************
+GeomShapePtr PartSet_WidgetShapeSelector::getShape() const
+{
+  // an empty shape by default
+  GeomShapePtr aShape;
+
+  // 1. find an attribute value in attribute reference attribute value
+  DataPtr aData = myFeature->data();
+  AttributePtr aAttr = aData->attribute(attributeID());
+  AttributeRefAttrPtr aRefAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+  if (aRefAttr) {
+    if (!aRefAttr->isObject()) {
+      AttributePtr anAttribute = aRefAttr->attr();
+      if (anAttribute.get()) {
+        XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+        XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+        // 2. find visualized vertices of the attribute and if the attribute of the vertex is
+        // the same, return it
+        FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(anAttribute->owner());
+        // 2.1 get visualized results of the feature
+        const std::list<ResultPtr>& aResList = anAttributeFeature->results();
+        std::list<ResultPtr>::const_iterator anIt = aResList.begin(), aLast = aResList.end();
+        for (; anIt != aLast; anIt++) {
+          AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt);
+          if (aAISObj.get() != NULL) {
+            Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+            // 2.2 find selected owners of a visualizedd object
+            SelectMgr_IndexedMapOfOwner aSelectedOwners;  
+            aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
+            for  (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
+              Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
+              if (!anOwner.IsNull()) {
+                Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
+                if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
+                  const TopoDS_Shape& aBRepShape = aBRepOwner->Shape();
+                  if (aBRepShape.ShapeType() == TopAbs_VERTEX) {
+                    // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial
+                    // attribute, returns the shape
+                    AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature,
+                                                                                  aBRepShape, sketch());
+                    if (aPntAttr.get() != NULL && aPntAttr == anAttribute) {
+                      aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+                      aShape->setImpl(new TopoDS_Shape(aBRepShape));
+                      break;
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  if (!aShape.get())
+    aShape = ModuleBase_WidgetShapeSelector::getShape();
+  return aShape;
+}
+
 //********************************************************************
 void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
 {
index f300db7e8d011fe85db6c010bc98c848f1bdadd3..050b64e271b479860c10a54c7952c24125d1482d 100644 (file)
@@ -49,6 +49,13 @@ protected:
   /// \param theShape a selected shape, which is used in the selection attribute
   virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
+  /// Get the shape from the attribute if the attribute contain a shape
+  /// It processes the ref attr type of attributes. It obtains the referenced attribute,
+  /// results of the attribute feature. And it founds a vertes in the owners of the results
+  /// If the vertex is found, it creates a geom shape on it.
+  /// \return a shape
+  virtual GeomShapePtr getShape() const;
+
   /// 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
index 5254c1ea6d40e10be803a613fa7ae93ba2217c14..83fa8010dd1dce83aedec88d74947ef59887dbd6 100644 (file)
@@ -426,19 +426,16 @@ void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrs>& theValues,
     aContext->ClearSelected();
     //if (aSelected.size() > 0) {
     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
-    //    if (isValidSelection(aPrs)) {
-    //foreach(ObjectPtr aResult, theResults) {
-      ObjectPtr anObject = aPrs.object();
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-      if (aResult.get() && isVisible(aResult)) {
-        AISObjectPtr anObj = myResult2AISObjectMap[aResult];
-        Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAIS.IsNull()) {
-          const TopoDS_Shape& aShape = aPrs.shape();
-          if (!aShape.IsNull()) {
-            aContext->AddOrRemoveSelected(aShape, false);
-          }
-          else {
+      const TopoDS_Shape& aShape = aPrs.shape();
+      if (!aShape.IsNull()) {
+        aContext->AddOrRemoveSelected(aShape, false);
+      } else {
+        ObjectPtr anObject = aPrs.object();
+        ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+        if (aResult.get() && isVisible(aResult)) {
+          AISObjectPtr anObj = myResult2AISObjectMap[aResult];
+          Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
+          if (!anAIS.IsNull()) {
             // The methods are replaced in order to provide multi-selection, e.g. restore selection
             // by activating multi selector widget. It also gives an advantage that the multi
             // selection in OB gives multi-selection in the viewer
@@ -452,7 +449,6 @@ void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrs>& theValues,
   } else {
     aContext->UnhilightCurrents();
     aContext->ClearCurrents();
-    //foreach(ObjectPtr aResult, theResults) {
     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
       ObjectPtr anObject = aPrs.object();
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);