Salome HOME
Refactoring: static constants are replaced by inline functions in:
[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<SketchPlugin_Sketch> aSketch = boost::
30         dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
31       if (aSketch) {
32         std::list<FeaturePtr > aList = 
33           aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
34         std::list<FeaturePtr >::iterator aSub = aList.begin();
35         for(; aSub != aList.end(); aSub++) {
36           if ((*aSub)->data()->isEqual(data())) {
37             mySketch = aSketch.get();
38             break;
39           }
40         }
41       }
42     }
43   }
44   return mySketch;
45 }
46
47 boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Feature::prepareAISShape(
48                         boost::shared_ptr<GeomAPI_AISObject> thePrevious)
49 {
50   boost::shared_ptr<GeomAPI_Shape> aPreview = preview();
51   boost::shared_ptr<GeomAPI_AISObject> aResult = thePrevious;
52   if (!aResult)
53     aResult = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
54   aResult->createShape(aPreview);
55   return aResult;
56 }