Salome HOME
Composite Feature implementation. Sketch now is Composite.
[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       ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a);
21       boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
22         boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj);
23       if (aSketch) {
24         std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
25             ->list();
26         std::list<ObjectPtr>::iterator aSub = aList.begin();
27         for (; aSub != aList.end(); aSub++) {
28           if ((*aSub)->data()->isEqual(data())) {
29             mySketch = aSketch.get();
30             break;
31           }
32         }
33       }
34     }
35   }
36   return mySketch;
37 }
38
39 AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
40                                                    AISObjectPtr thePrevious)
41 {
42   boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = boost::dynamic_pointer_cast<
43       ModelAPI_ResultConstruction>(theRes);
44
45   boost::shared_ptr<GeomAPI_Shape> aPreview;
46   if (aConstr)
47     aPreview = aConstr->shape();
48
49   AISObjectPtr aResult = thePrevious;
50   if (!aResult)
51     aResult = AISObjectPtr(new GeomAPI_AISObject());
52   aResult->createShape(aPreview);
53   return aResult;
54 }