Salome HOME
ModuleBase_WidgetShapeSelector correction to process AttrRefAtt like MultiSelector...
authornds <nds@opencascade.com>
Thu, 21 Jan 2016 10:22:07 +0000 (13:22 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:25 +0000 (17:04 +0300)
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/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h

index c8250969a14b0a3c665aaae4741d34b71ae4aca5..1144a30a3f91af6f75c318cc04417b8e048dd697 100755 (executable)
@@ -241,44 +241,6 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue()
   }
 }
 
-//********************************************************************
-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);
-      ObjectPtr anObject;
-      GeomShapePtr aShape;
-      getGeomSelection(thePrs, anObject, aShape);
-      setObject(anObject, aShape);
-    }
-  }
-  else {
-    //ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
-
-    ObjectPtr anObject;
-    GeomShapePtr aShape;
-    getGeomSelection(thePrs, anObject, aShape);
-    setObject(anObject, aShape);
-  }
-  return true;
-}
-
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
 {
@@ -354,9 +316,14 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
     aRefListAttr->append(theSelectedObject);
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
-    //AttributeRefAttrListPtr aRefAttrListAttr =
-    //             std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
-    //aRefAttrListAttr->clear();
+    AttributeRefAttrListPtr aRefAttrListAttr =
+                 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+
+    AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
+    if (anAttribute.get())
+      aRefAttrListAttr->append(anAttribute);
+    else
+      aRefAttrListAttr->append(theSelectedObject);
   }
 }
 
index 54ff6ddcf44298aecc9c530e5b787e70dee7f35e..7156e051789862a0df0d16e916005aa0ccc65be2 100755 (executable)
@@ -116,10 +116,6 @@ 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 c5be67919c214a1eca31ed60a5e52eb68b83ad39..0f0b2c15a8eda3efe5a491fa3fa50df0ec93a98b 100755 (executable)
@@ -150,6 +150,17 @@ bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPr
   return aValid;
 }
 
+//********************************************************************
+bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+  ObjectPtr anObject;
+  GeomShapePtr aShape;
+  getGeomSelection(thePrs, anObject, aShape);
+
+  setObject(anObject, aShape);
+  return true;
+}
+
 //********************************************************************
 void ModuleBase_WidgetSelector::deactivate()
 {
index 8a282c3625b3e80f49a8ac0a3159c837d2907af3..150a0ce349d07410f8403d447a8fb27c9372e547 100755 (executable)
@@ -51,6 +51,10 @@ Q_OBJECT
   /// \return a boolean value
   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
 
+  /// Fills the attribute with the value of the selected owner
+  /// \param thePrs a selected owner
+  virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
index e062d4f096e28ba2bb3a098a36247f265790c10c..1047536e988e1abc372d0a6544e7bddc9f6b986b 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_Filter.h>
+#include <ModuleBase_IModule.h>
 
 #include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
@@ -120,9 +121,15 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
     }
   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
     AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    ObjectPtr aObject = aRefAttr->object();
-    if (!(aObject && aObject->isSame(theSelectedObject))) {
-      aRefAttr->setObject(theSelectedObject);
+
+    AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
+    if (anAttribute.get())
+      aRefAttr->setAttr(anAttribute);
+    else {
+      ObjectPtr aObject = aRefAttr->object();
+      if (!(aObject && aObject->isSame(theSelectedObject))) {
+        aRefAttr->setObject(theSelectedObject);
+      }
     }
   } else if (aType == ModelAPI_AttributeSelection::typeId()) {
     AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
@@ -274,14 +281,3 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
       aRefAttr->setAttr(myRefAttribute);
   }
 }
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
-  ObjectPtr anObject;
-  GeomShapePtr aShape;
-  getGeomSelection(thePrs, anObject, aShape);
-
-  setObject(anObject, aShape);
-  return true;
-}
index a750c80331fd29e6c23b69dda819d730e97d51eb..2c8a10363e630fcade439ae6b895a0545e62459f 100644 (file)
@@ -104,10 +104,6 @@ Q_OBJECT
   /// \return a list of shapes
   virtual QIntList getShapeTypes() const;
 
-  /// Fills the attribute with the value of the selected owner
-  /// \param thePrs a selected owner
-  virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-
   /// Store the values to the model attribute of the widget. It casts this attribute to
   /// the specific type and set the given values
   /// \param theSelectedObject an object
index e7502e84df8cb3fb85b3652b6cfbd88cd075f6dc..3dd75c7b721a12ae31be51315e8c22f1ef0b26f5 100755 (executable)
@@ -1046,9 +1046,23 @@ GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
 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());
+  AttributePtr anAttribute;
+  GeomShapePtr aGeomShape = theGeomShape;
+  if (!aGeomShape.get()) {
+    // processing shape of result, e.g. sketch circle center is selected, this is a result
+    // the geom shape is empty, the shape of result should be used
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (aResult.get()) {
+      aGeomShape = aResult->shape();
+    }
+  }
+
+  if (aGeomShape.get()) {
+    TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
+    return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, 
+                                                 mySketchMgr->activeSketch());
+  }
+  return anAttribute;
 }
 
 //******************************************************
index 0bbeb05e8480d3ddffc8532ae826a2ee2c458f9d..79e32272de5969a21d1928a9c6d9f32a57aec02b 100755 (executable)
@@ -53,28 +53,6 @@ bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_Viewer
   return aValid;
 }
 
-//********************************************************************
-void PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
-{
-  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
-  // Do check using of external feature
-  std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
-          std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-  // Processing of sketch object
-  if (aSPFeature.get() != NULL) {
-    GeomShapePtr aShape = theShape;
-    if (!aShape.get()) {
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
-      if (aResult.get()) {
-        aShape = aResult->shape();
-      }
-    }
-    setPointAttribute(theSelectedObject, aShape);
-  }
-  else
-    ModuleBase_WidgetShapeSelector::setObject(theSelectedObject, theShape);
-}
-
 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
                                                    ObjectPtr& theObject,
                                                    GeomShapePtr& theShape)
@@ -118,39 +96,3 @@ void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
 }
 
-//********************************************************************
-void PartSet_WidgetShapeSelector::setPointAttribute(ObjectPtr theSelectedObject, GeomShapePtr theShape)
-{
-  DataPtr aData = myFeature->data();
-  AttributePtr aAttr = aData->attribute(attributeID());
-  AttributeRefAttrPtr aRefAttr = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
-  if (aRefAttr) {
-    // it is possible that the point feature is selected. It should be used itself
-    // instead of searching an attribute for the shape
-    bool aShapeIsResult = false;
-    /*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
-    if (aResult.get() != NULL) {
-      GeomShapePtr aShapePtr = aResult->shape();
-      // it is important to call isEqual of the shape of result.
-      // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
-      // GeomAPI_Shape. It is important to use the realization of the isEqual method from
-      // GeomAPI_Vertex class
-      aShapeIsResult = aShapePtr.get() != NULL && aShapePtr->isEqual(theShape);
-    }*/
-
-    AttributePtr aPntAttr;
-    if (!aShapeIsResult) {
-      TopoDS_Shape aTDSShape = theShape->impl<TopoDS_Shape>();
-      aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theSelectedObject, aTDSShape, mySketch);
-    }
-    // this is an alternative, whether the attribute should be set or object in the attribute
-    // the first check is the attribute because the object already exist
-    // the object is set only if there is no selected attribute
-    // test case is - preselection for distance operation, which contains two points selected on lines
-    if (aPntAttr)
-      aRefAttr->setAttr(aPntAttr);
-    else
-      aRefAttr->setObject(theSelectedObject);
-  }
-}
index 4d2da507bd74dd91395d3a166c056b7900048693..f6b836e2ed742886c98d322724546d97fcadd2c9 100644 (file)
@@ -48,13 +48,6 @@ protected:
   /// \return a boolean value
   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
 
-  /// Store the values to the model attribute of the widget. It casts this attribute to
-  /// the specific type and set the given values
-  /// \param theSelectedObject an object
-  /// \param theShape a selected shape, which is used in the selection attribute
-  /// \return true if it is succeed
-  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-
   /// Return an object and geom shape by the viewer presentation
   /// \param thePrs a selection
   /// \param theObject an output object
@@ -76,12 +69,6 @@ protected:
   /// \param theValid a boolean flag, if restore happens for valid parameters
   void restoreAttributeValue(const bool theValid);
 
-  /// Found the sketch point attribute by the shape and set it in the feature attribute
-  /// otherwise set the selected object
-  /// \param theSelectedObject an object
-  /// \param theShape a selected shape, which is used in the selection attribute
-  void setPointAttribute(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-
 protected:
   /// A reference to external objects manager
   PartSet_ExternalObjectsMgr* myExternalObjectMgr;