]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Feature.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Feature.cpp
1 #include "SketchPlugin_Feature.h"
2 #include "SketchPlugin_Sketch.h"
3 #include <ModelAPI_Document.h>
4 #include <ModelAPI_Data.h>
5 #include <ModelAPI_Object.h>
6 #include <ModelAPI_AttributeRefList.h>
7
8 SketchPlugin_Feature::SketchPlugin_Feature()
9 {
10   mySketch = 0;
11 }
12
13 void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
14 {
15   myPreview = theShape;
16 }
17
18 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Feature::getPreview() const
19 {
20   return myPreview;
21 }
22
23 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
24 {
25   if (!mySketch) {
26     // find sketch that references to this feature
27     int aSketches = document()->size("Construction");
28     for(int a = 0; a < aSketches && !mySketch; a++) {
29       boost::shared_ptr<ModelAPI_Object> anObj = 
30         boost::dynamic_pointer_cast<ModelAPI_Object>(document()->feature("Construction", a));
31       if (anObj) {
32         boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
33           boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj->featureRef());
34         if (aSketch) {
35           std::list<boost::shared_ptr<ModelAPI_Feature> > aList = 
36             aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
37           std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
38           for(; aSub != aList.end(); aSub++) {
39             if ((*aSub)->data()->isEqual(data())) {
40               mySketch = aSketch.get();
41               break;
42             }
43           }
44         }
45       }
46     }
47   }
48   return mySketch;
49 }