Salome HOME
Issue #394 Undo-ing a Sketch element
[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 /// It is important.
12 ///
13 /// Before writing a new method implementation in this file, please check the next rule:
14 /// exported public methods must not be implemented in this source file. They should be inline and
15 /// placed in the header file.
16 /// Because it leads to the runtime problem on the Linux OS.
17 ///
18 /// The reason is that this is an abstract interface. An interface of this class can be used in
19 /// outside libraries through casting without a link to the current library.
20
21 SketchPlugin_Feature::SketchPlugin_Feature()
22 {
23   mySketch = 0;
24 }
25
26 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
27 {
28   if (!mySketch) {
29     // find sketch that references to this feature
30     const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
31     std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
32     for(; aBackRef != aBackRefs.end(); aBackRef++) {
33       std::shared_ptr<SketchPlugin_Sketch> aSketch = 
34         std::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
35       if (aSketch) {
36         mySketch = aSketch.get();
37         break;
38       }
39     }
40   }
41   return mySketch;
42 }
43