Salome HOME
Calculate Flyout point for distance and length
[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 #include <ModelAPI_ResultConstruction.h>
8
9 SketchPlugin_Feature::SketchPlugin_Feature()
10 {
11   mySketch = 0;
12 }
13
14 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
15 {
16   if (!mySketch) {
17     // find sketch that references to this feature
18     int aSketches = document()->size(ModelAPI_Feature::group());
19     for (int a = 0; a < aSketches && !mySketch; a++) {
20       boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::dynamic_pointer_cast<
21           SketchPlugin_Sketch>(document()->object(ModelAPI_Feature::group(), a));
22       if (aSketch) {
23         std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
24             ->list();
25         std::list<ObjectPtr>::iterator aSub = aList.begin();
26         for (; aSub != aList.end(); aSub++) {
27           if ((*aSub)->data()->isEqual(data())) {
28             mySketch = aSketch.get();
29             break;
30           }
31         }
32       }
33     }
34   }
35   return mySketch;
36 }
37
38 AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
39                                                    AISObjectPtr thePrevious)
40 {
41   boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = boost::dynamic_pointer_cast<
42       ModelAPI_ResultConstruction>(theRes);
43
44   boost::shared_ptr<GeomAPI_Shape> aPreview;
45   if (aConstr)
46     aPreview = aConstr->shape();
47
48   AISObjectPtr aResult = thePrevious;
49   if (!aResult)
50     aResult = AISObjectPtr(new GeomAPI_AISObject());
51   aResult->createShape(aPreview);
52   return aResult;
53 }