1 // Copyright (C) 2014-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketchPlugin_Feature.h"
21 #include "SketchPlugin_Sketch.h"
22 #include <ModelAPI_Document.h>
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Object.h>
25 #include <ModelAPI_ResultConstruction.h>
29 /// Before writing a new method implementation in this file, please check the next rule:
30 /// exported public methods must not be implemented in this source file. They should be inline and
31 /// placed in the header file.
32 /// Because it leads to the runtime problem on the Linux OS.
34 /// The reason is that this is an abstract interface. An interface of this class can be used in
35 /// outside libraries through casting without a link to the current library.
37 SketchPlugin_Feature::SketchPlugin_Feature()
42 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
45 // find sketch that references to this feature
46 const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
47 std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
48 for(; aBackRef != aBackRefs.end(); aBackRef++) {
49 std::shared_ptr<SketchPlugin_Sketch> aSketch =
50 std::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
52 mySketch = aSketch.get();
60 void SketchPlugin_Feature::keepCurrentFeature()
62 FeaturePtr aCurFeature = document()->currentFeature(true);
63 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
64 std::dynamic_pointer_cast<SketchPlugin_Feature>(aCurFeature);
65 std::shared_ptr<SketchPlugin_Sketch> aSketch =
66 std::dynamic_pointer_cast<SketchPlugin_Sketch>(aCurFeature);
67 if ((!aSketchFeature || aSketchFeature->sketch() != sketch()) &&
68 (!aSketch || aSketch.get() != sketch()))
69 myCurrentFeature = aCurFeature;
72 void SketchPlugin_Feature::restoreCurrentFeature()
75 document()->setCurrentFeature(myCurrentFeature, true);
76 myCurrentFeature = FeaturePtr();