Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Feature.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #include "SketchPlugin_Feature.h"
4 #include "SketchPlugin_Sketch.h"
5 #include <ModelAPI_Document.h>
6 #include <ModelAPI_Data.h>
7 #include <ModelAPI_Object.h>
8 #include <ModelAPI_AttributeRefList.h>
9 #include <ModelAPI_ResultConstruction.h>
10
11 SketchPlugin_Feature::SketchPlugin_Feature()
12 {
13   mySketch = 0;
14 }
15
16 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
17 {
18   if (!mySketch) {
19     // find sketch that references to this feature
20     const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
21     std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
22     for(; aBackRef != aBackRefs.end(); aBackRef++) {
23       std::shared_ptr<SketchPlugin_Sketch> aSketch = 
24         std::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
25       if (aSketch) {
26         mySketch = aSketch.get();
27         break;
28       }
29     }
30   }
31   return mySketch;
32 }
33
34 AISObjectPtr SketchPlugin_Feature::simpleAISObject(std::shared_ptr<ModelAPI_Result> theRes,
35                                                    AISObjectPtr thePrevious)
36 {
37   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = std::dynamic_pointer_cast<
38       ModelAPI_ResultConstruction>(theRes);
39
40   std::shared_ptr<GeomAPI_Shape> aPreview;
41   if (aConstr)
42     aPreview = aConstr->shape();
43
44   AISObjectPtr aResult = thePrevious;
45   if (!aResult)
46     aResult = AISObjectPtr(new GeomAPI_AISObject());
47   aResult->createShape(aPreview);
48   return aResult;
49 }