Salome HOME
Issue #2431 - remove application exit from unit tests
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Feature.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "SketchPlugin_Feature.h"
22 #include "SketchPlugin_Sketch.h"
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Object.h>
26 #include <ModelAPI_ResultConstruction.h>
27
28 /// It is important.
29 ///
30 /// Before writing a new method implementation in this file, please check the next rule:
31 /// exported public methods must not be implemented in this source file. They should be inline and
32 /// placed in the header file.
33 /// Because it leads to the runtime problem on the Linux OS.
34 ///
35 /// The reason is that this is an abstract interface. An interface of this class can be used in
36 /// outside libraries through casting without a link to the current library.
37
38 SketchPlugin_Feature::SketchPlugin_Feature()
39 {
40   mySketch = 0;
41 }
42
43 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
44 {
45   if (!mySketch) {
46     // find sketch that references to this feature
47     const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
48     std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
49     for(; aBackRef != aBackRefs.end(); aBackRef++) {
50       std::shared_ptr<SketchPlugin_Sketch> aSketch =
51         std::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
52       if (aSketch) {
53         mySketch = aSketch.get();
54         break;
55       }
56     }
57   }
58   return mySketch;
59 }
60