From: mpv Date: Wed, 29 Oct 2014 09:15:56 +0000 (+0300) Subject: Added isSub method for selection of external objects task in the Sketch X-Git-Tag: V_0.5~66^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b5410d157f6aab17772617fcaa09c5d660d13e9;p=modules%2Fshaper.git Added isSub method for selection of external objects task in the Sketch --- diff --git a/src/ModelAPI/ModelAPI_CompositeFeature.h b/src/ModelAPI/ModelAPI_CompositeFeature.h index 28c4d6d2a..878ca849f 100644 --- a/src/ModelAPI/ModelAPI_CompositeFeature.h +++ b/src/ModelAPI/ModelAPI_CompositeFeature.h @@ -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 diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 3dc6a3d5d..269471f84 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -51,7 +51,7 @@ class ModelAPI_Feature : public ModelAPI_Object } /// Returns document this feature belongs to - virtual boost::shared_ptr document() + virtual boost::shared_ptr document() const { return ModelAPI_Object::document(); } diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index f6e3c6c32..7ac6696f5 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -46,7 +46,7 @@ class ModelAPI_Object } /// Returns document this feature belongs to - virtual boost::shared_ptr document() + virtual boost::shared_ptr document() const { return myDoc; } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index a66bd9ffb..5429b2b60 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -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(theObject); + if (!aFeature) { + ResultPtr aRes = boost::dynamic_pointer_cast(theObject); + if (aRes) + aFeature = document()->feature(aRes); + } + if (aFeature) { + list aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list(); + for(list::iterator aSubIt = aSubs.begin(); aSubIt != aSubs.end(); aSubIt++) { + if (*aSubIt == aFeature) + return true; + } + } + return false; +} + boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, const double theY) { boost::shared_ptr aC = boost::dynamic_pointer_cast( diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 79b478f7c..23147d97f 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -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;}