Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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("Construction");
19     for(int a = 0; a < aSketches && !mySketch; a++) {
20       boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::
21         dynamic_pointer_cast<SketchPlugin_Sketch>(document()->object("Construction", a));
22       if (aSketch) {
23         std::list<ObjectPtr> aList =
24           aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->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 boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Feature::simpleAISObject(
39     boost::shared_ptr<ModelAPI_Result> theRes, boost::shared_ptr<GeomAPI_AISObject> thePrevious)
40 {
41   boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = 
42     boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theRes);
43
44   boost::shared_ptr<GeomAPI_Shape> aPreview;
45   if (aConstr) aPreview = aConstr->shape();
46
47   boost::shared_ptr<GeomAPI_AISObject> aResult = thePrevious;
48   if (!aResult)
49     aResult = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
50   aResult->createShape(aPreview);
51   return aResult;
52 }