Salome HOME
Added isSub method for selection of external objects task in the Sketch
authormpv <mikhail.ponikarov@opencascade.com>
Wed, 29 Oct 2014 09:15:56 +0000 (12:15 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Wed, 29 Oct 2014 09:15:56 +0000 (12:15 +0300)
src/ModelAPI/ModelAPI_CompositeFeature.h
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_Object.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index 28c4d6d2a4847523a0e7ebe6da0b52d253d53382..878ca849fb5d0fe0cfe9900eeb17840ccd9b522e 100644 (file)
@@ -27,6 +27,9 @@ public:
 
   /// Returns the sub-feature unique identifier in this composite feature by zero-base index
   virtual int subFeatureId(const int theIndex) const = 0;
+
+  /// Returns true if feature or reuslt belong to this composite feature as subs
+  virtual bool isSub(ObjectPtr theObject) const = 0;
 };
 
 //! Pointer on the composite feature object
index 3dc6a3d5d956a1e6622a51cb37647b559a1f31c1..269471f84f9404277236c65c621970f087295e49 100644 (file)
@@ -51,7 +51,7 @@ class ModelAPI_Feature : public ModelAPI_Object
   }
 
   /// Returns document this feature belongs to
-  virtual boost::shared_ptr<ModelAPI_Document> document()
+  virtual boost::shared_ptr<ModelAPI_Document> document() const
   {
     return ModelAPI_Object::document();
   }
index f6e3c6c3228d6b34867361e7ab06a8060b3c06d5..7ac6696f5ad5b0433b2d662bd2c5917f6858372f 100644 (file)
@@ -46,7 +46,7 @@ class ModelAPI_Object
   }
 
   /// Returns document this feature belongs to
-  virtual boost::shared_ptr<ModelAPI_Document> document()
+  virtual boost::shared_ptr<ModelAPI_Document> document() const
   {
     return myDoc;
   }
index a66bd9ffb1b6a3040a79c005147862739e5db233..5429b2b605668573097dbc9bd76ff09713971433 100644 (file)
@@ -131,6 +131,25 @@ int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
   return subFeature(theIndex)->data()->featureId();
 }
 
+bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const
+{
+  // check is this feature of result
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+  if (!aFeature) {
+    ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (aRes)
+      aFeature = document()->feature(aRes);
+  }
+  if (aFeature) {
+    list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
+    for(list<ObjectPtr>::iterator aSubIt = aSubs.begin(); aSubIt != aSubs.end(); aSubIt++) {
+      if (*aSubIt == aFeature)
+        return true;
+    }
+  }
+  return false;
+}
+
 boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
 {
   boost::shared_ptr<GeomDataAPI_Point> aC = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
index 79b478f7cb1df43f693d667e37760ffb293de962..23147d97f612f11077809ff5b8b773ad7d7f2690 100644 (file)
@@ -126,6 +126,9 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPr
   /// Returns the sub-feature unique identifier in this composite feature by zero-base index
   SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
 
+  /// Returns true if feature or reuslt belong to this composite feature as subs
+  SKETCHPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
+
   /// Construction result is allways recomuted on the fly
   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}