Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into Dev_2.8.0
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.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 "ConstructionAPI_Point.h"
22
23 #include <GeomAPI_Shape.h>
24
25 #include <ModelHighAPI_Dumper.h>
26 #include <ModelHighAPI_Selection.h>
27 #include <ModelHighAPI_Tools.h>
28
29 //==================================================================================================
30 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
31 : ModelHighAPI_Interface(theFeature)
32 {
33   initialize();
34 }
35
36 //==================================================================================================
37 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
38                                              const ModelHighAPI_Double& theX,
39                                              const ModelHighAPI_Double& theY,
40                                              const ModelHighAPI_Double& theZ)
41 : ModelHighAPI_Interface(theFeature)
42 {
43   if(initialize()) {
44     setByXYZ(theX, theY, theZ);
45   }
46 }
47
48 /*//==================================================================================================
49 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
50                                              const ModelHighAPI_Selection& theEdge,
51                                              const ModelHighAPI_Double& theDistanceValue,
52                                              const bool theDistancePercent,
53                                              const bool theReverse)
54 : ModelHighAPI_Interface(theFeature)
55 {
56   if(initialize()) {
57     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
58   }
59 }*/
60
61 //==================================================================================================
62 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
63                                              const ModelHighAPI_Selection& theObject1,
64                                              const ModelHighAPI_Selection& theObject2)
65 : ModelHighAPI_Interface(theFeature)
66 {
67   if(initialize()) {
68     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
69     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
70     /*
71     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
72       // If first object is vertex and second object is face then set by projection.
73       setByProjection(theObject1, theObject2);
74     } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
75       // If both objects are edges then set by lines intersection.
76       setByLinesIntersection(theObject1, theObject2);
77     } else */if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
78       // If first object is edge and second object is face then set by line and plane intersection.
79       setByLineAndPlaneIntersection(theObject1, theObject2);
80     }
81   }
82 }
83
84 //==================================================================================================
85 ConstructionAPI_Point::~ConstructionAPI_Point()
86 {
87
88 }
89
90 //==================================================================================================
91 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
92                                      const ModelHighAPI_Double& theY,
93                                      const ModelHighAPI_Double& theZ)
94 {
95   //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
96   fillAttribute(theX, myx);
97   fillAttribute(theY, myy);
98   fillAttribute(theZ, myz);
99   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
100
101   execute(false);
102 }
103
104 /*//==================================================================================================
105 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
106                                                 const ModelHighAPI_Double& theDistanceValue,
107                                                 const bool theDistancePercent,
108                                                 const bool theReverse)
109 {
110   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
111   fillAttribute(theEdge, myedge);
112   fillAttribute(theDistanceValue, mydistanceValue);
113   fillAttribute(theDistancePercent, mydistancePercent);
114   fillAttribute(theReverse, myreverse);
115
116   execute();
117 }
118
119 //==================================================================================================
120 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
121                                             const ModelHighAPI_Selection& theFace)
122 {
123   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
124   fillAttribute(theVertex, mypoint);
125   fillAttribute(theFace, myplane);
126
127   execute();
128 }
129
130 //==================================================================================================
131 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
132                                                    const ModelHighAPI_Selection& theEdge2)
133 {
134   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
135   fillAttribute(theEdge1, myfirstLine);
136   fillAttribute(theEdge2, mysecondLine);
137
138   execute();
139 }*/
140
141 //==================================================================================================
142 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
143                                                           const ModelHighAPI_Selection& theFace)
144 {
145   fillAttribute(
146     ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
147   fillAttribute(theEdge, myintersectionLine);
148   fillAttribute(theFace, myintersectionPlane);
149   fillAttribute("", useOffset()); // not used by default
150   execute();
151 }
152
153 //==================================================================================================
154 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
155 {
156   FeaturePtr aBase = feature();
157   const std::string& aDocName = theDumper.name(aBase->document());
158   const std::string& aMeth = creationMethod()->value();
159
160   // common part
161   theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
162
163   if (aMeth == "" || // default is XYZ
164       aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
165     theDumper << x() << ", " << y() << ", " << z() << ")" << std::endl;
166   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
167     theDumper << intersectionLine() << ", " <<intersectionPlane() ;
168     if (!useOffset()->value().empty()) { // call method with defined offset
169       theDumper << ", " << offset() << ", " << reverseOffset();
170     }
171     theDumper << ")" << std::endl;
172   }
173 }
174
175 //==================================================================================================
176 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
177                   const ModelHighAPI_Double& theX,
178                   const ModelHighAPI_Double& theY,
179                   const ModelHighAPI_Double& theZ)
180 {
181   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
182   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
183 }
184
185 /*//==================================================================================================
186 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
187                   const ModelHighAPI_Selection& theEdge,
188                   const ModelHighAPI_Double& theDistanceValue,
189                   const bool theDistancePercent,
190                   const bool theReverse)
191 {
192   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
193   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
194 }*/
195
196 //==================================================================================================
197 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
198                   const ModelHighAPI_Selection& theObject1,
199                   const ModelHighAPI_Selection& theObject2)
200 {
201   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
202   return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
203 }
204
205 //==================================================================================================
206 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
207                   const ModelHighAPI_Selection& theObject1,
208                   const ModelHighAPI_Selection& theObject2,
209                   const ModelHighAPI_Double& theDistanceValue,
210                   const bool theReverse)
211 {
212   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
213   PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
214
215   fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
216   fillAttribute(theDistanceValue, anAPI->offset());
217   fillAttribute(theReverse, anAPI->reverseOffset());
218
219   return anAPI;
220 }