Salome HOME
42c5956b85da8181c408d3b2659c72a7bf5b2830
[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     const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
19     std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
20     for(; aBackRef != aBackRefs.end(); aBackRef++) {
21       std::shared_ptr<SketchPlugin_Sketch> aSketch = 
22         std::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
23       if (aSketch) {
24         mySketch = aSketch.get();
25         break;
26       }
27     }
28   }
29   return mySketch;
30 }
31
32 AISObjectPtr SketchPlugin_Feature::simpleAISObject(std::shared_ptr<ModelAPI_Result> theRes,
33                                                    AISObjectPtr thePrevious)
34 {
35   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = std::dynamic_pointer_cast<
36       ModelAPI_ResultConstruction>(theRes);
37
38   std::shared_ptr<GeomAPI_Shape> aPreview;
39   if (aConstr)
40     aPreview = aConstr->shape();
41
42   AISObjectPtr aResult = thePrevious;
43   if (!aResult)
44     aResult = AISObjectPtr(new GeomAPI_AISObject());
45   aResult->createShape(aPreview);
46   return aResult;
47 }