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