]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Set value for Attribute Selection
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 13 Oct 2014 13:06:52 +0000 (17:06 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 13 Oct 2014 13:06:52 +0000 (17:06 +0400)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp

index 8c344e2b3c3d8566563ec951e387ff385f518662..62659de6c59560f4468b759b0102c7c5b0d09fd6 100644 (file)
@@ -7,6 +7,9 @@
 #include "Model_Events.h"
 #include "Model_Data.h"
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <GeomAPI_Shape.h>
 
 #include <TNaming_Selector.hxx>
 #include <TNaming_NamedShape.hxx>
@@ -14,7 +17,7 @@
 
 using namespace std;
 
-void Model_AttributeSelection::setValue(const ResultBodyPtr& theContext,
+void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
 {
   const boost::shared_ptr<GeomAPI_Shape>& anOldShape = value();
@@ -25,11 +28,22 @@ void Model_AttributeSelection::setValue(const ResultBodyPtr& theContext,
   bool isOldContext = theContext == myRef.value();
   if (!isOldContext)
     myRef.setValue(theContext);
-  
+
   // perform the selection
   TNaming_Selector aSel(myRef.myRef->Label());
   TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
-  TopoDS_Shape aContext = theContext->shape()->impl<TopoDS_Shape>();
+  TopoDS_Shape aContext;
+
+  ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+  if (aBody)
+    aContext = aBody->shape()->impl<TopoDS_Shape>();
+  else {
+    ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
+    if (aConstr)
+      aContext = aConstr->shape()->impl<TopoDS_Shape>();
+    else
+      throw std::invalid_argument("a result with shape is expected");
+  }
   aSel.Select(aNewShape, aContext);
   myIsInitialized = true;
 
@@ -55,6 +69,12 @@ Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
   myIsInitialized = myRef.isInitialized();
 }
 
-ResultBodyPtr Model_AttributeSelection::context() {
-  return boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+ResultPtr Model_AttributeSelection::context() {
+  return boost::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
+}
+
+
+void Model_AttributeSelection::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+  myRef.setObject(theObject);
 }
index d8e8a54a7082f435e8ad9e7498f93dde187fcf3b..b380fef83534337571da6cc5a1222d2203de2cee 100644 (file)
@@ -20,13 +20,15 @@ class Model_AttributeSelection : public ModelAPI_AttributeSelection
 public:
   /// Defines the result and its selected sub-shape
   MODEL_EXPORT virtual void setValue(
-    const ResultBodyPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
 
   /// Returns the selected subshape
   MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> value();
 
   /// Returns the context of the selection (the whole shape owner)
-  MODEL_EXPORT virtual ResultBodyPtr context();
+  MODEL_EXPORT virtual ResultPtr context();
+
+  MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
 
 protected:
   /// Objects are created for features automatically
index 9b4970c124a01e80f7ef4187e683c8f0a8e67971..98d4af7d625254d2b76c55303a811ad808c51008 100644 (file)
@@ -6,7 +6,7 @@
 #define ModelAPI_AttributeSelection_H_
 
 #include "ModelAPI_Attribute.h"
-#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_Result.h>
 
 /**\class ModelAPI_AttributeSelection
  * \ingroup DataModel
@@ -18,13 +18,13 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
  public:
   /// Defines the result and its selected sub-shape
   virtual void setValue(
-    const ResultBodyPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
 
   /// Returns the selected subshape
   virtual boost::shared_ptr<GeomAPI_Shape> value() = 0;
 
   /// Returns the context of the selection (the whole shape owner)
-  virtual ResultBodyPtr context() = 0;
+  virtual ResultPtr context() = 0;
 
   /// Returns the type of this class of attributes
   static std::string type()
index f07c339caa60e82bd6a68645d904559758b1d4d3..84cfee206ca66ae7fa68db6fa094c59f7f6988fc 100644 (file)
@@ -129,7 +129,7 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const
     boost::shared_ptr<ModelAPI_AttributeSelection> aSelect = 
       boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aData->attribute(attributeID()));
 
-    ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(mySelectedObject);
+    ResultPtr aBody = boost::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
     if (aBody)
       aSelect->setValue(aBody, myShape);
   } else {