Salome HOME
816d47f832d61e8101b5b539daebd9a3353dc277
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_NormalToFace.cpp
1 // Copyright (C) 2014-2023  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "FeaturesAPI_NormalToFace.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
25
26 //=================================================================================================
27 FeaturesAPI_NormalToFace::FeaturesAPI_NormalToFace(
28                                     const std::shared_ptr<ModelAPI_Feature>& theFeature)
29   : ModelHighAPI_Interface(theFeature)
30 {
31   initialize();
32 }
33
34 //=================================================================================================
35 FeaturesAPI_NormalToFace::FeaturesAPI_NormalToFace(
36                                     const std::shared_ptr<ModelAPI_Feature>& theFeature,
37                                     const ModelHighAPI_Selection& theBaseFace,
38                                     const ModelHighAPI_Selection& theOptionalPoint)
39 :ModelHighAPI_Interface(theFeature)
40 {
41   if (initialize()) {
42     fillAttribute(theBaseFace, myfaceSelected);
43     fillAttribute(theOptionalPoint, myvertexSelected);
44     feature()->string(FeaturesPlugin_NormalToFace::VERTEX_OPTION_ID())->setValue("true");
45     execute();
46   }
47 }
48
49 //=================================================================================================
50 FeaturesAPI_NormalToFace::FeaturesAPI_NormalToFace(
51                                     const std::shared_ptr<ModelAPI_Feature>& theFeature,
52                                     const ModelHighAPI_Selection& theBaseFace)
53 :ModelHighAPI_Interface(theFeature)
54 {
55   if (initialize()) {
56     fillAttribute(theBaseFace, myfaceSelected);
57     feature()->string(FeaturesPlugin_NormalToFace::VERTEX_OPTION_ID())->setValue("");
58     execute();
59   }
60 }
61
62 //=================================================================================================
63 FeaturesAPI_NormalToFace::~FeaturesAPI_NormalToFace()
64 {
65 }
66
67 //=================================================================================================
68 void FeaturesAPI_NormalToFace::dump(ModelHighAPI_Dumper& theDumper) const
69 {
70   FeaturePtr aBase = feature();
71   const std::string& aDocName = theDumper.name(aBase->document());
72
73   AttributeSelectionPtr anAttrObject;
74     anAttrObject = aBase->selection(FeaturesPlugin_NormalToFace::FACE_SELECTED_ID());
75
76   theDumper << aBase << " = model.getNormal(" << aDocName << ", " << anAttrObject;
77
78   if (!aBase->string(FeaturesPlugin_NormalToFace::VERTEX_OPTION_ID())->value().empty()) {
79
80     AttributeSelectionPtr anAttrVertex =
81             aBase->selection(FeaturesPlugin_NormalToFace::VERTEX_SELECTED_ID());
82
83     theDumper << ", " << anAttrVertex;
84   }
85
86   theDumper << ")" << std::endl;
87 }
88
89 //==================================================================================================
90 NormalPtr getNormal(const std::shared_ptr<ModelAPI_Document>& thePart,
91                     const ModelHighAPI_Selection& theBaseFace,
92                     const ModelHighAPI_Selection& theOptionalPoint)
93 {
94
95   FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_NormalToFace::ID());
96   NormalPtr aNormalToface;
97   aNormalToface.reset(new FeaturesAPI_NormalToFace(aFeature, theBaseFace, theOptionalPoint));
98
99   return aNormalToface;
100 }
101
102 //=================================================================================================
103 NormalPtr getNormal(const std::shared_ptr<ModelAPI_Document>& thePart,
104                     const ModelHighAPI_Selection& theBaseFace)
105 {
106
107   FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_NormalToFace::ID());
108   NormalPtr aNormalToface;
109   aNormalToface.reset(new FeaturesAPI_NormalToFace(aFeature, theBaseFace));
110
111   return aNormalToface;
112 }
113