]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionAPI/ConstructionAPI_Point.cpp
Salome HOME
Some improvements in GUI
[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& theOffset,
52                                              const bool theUseRatio,
53                                              const bool theReverse)
54 : ModelHighAPI_Interface(theFeature)
55 {
56   if(initialize()) {
57     setByOffsetOnEdge(theEdge, theOffset, theUseRatio, 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     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
71       // If first object is vertex and second object is face then set by projection.
72       setByProjectionOnFace(theObject1, theObject2);
73     } else if (aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::EDGE) {
74       // If first object is vertex and second object is edge then set by projection.
75       setByProjectionOnEdge(theObject1, theObject2);
76     } /* else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
77       // If both objects are edges then set by lines intersection.
78       setByLinesIntersection(theObject1, theObject2);
79     } */ else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
80       // If first object is edge and second object is face then set by line and plane intersection.
81       setByLineAndPlaneIntersection(theObject1, theObject2);
82     }
83   }
84 }
85
86 //==================================================================================================
87 ConstructionAPI_Point::~ConstructionAPI_Point()
88 {
89
90 }
91
92 //==================================================================================================
93 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
94                                      const ModelHighAPI_Double& theY,
95                                      const ModelHighAPI_Double& theZ)
96 {
97   //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
98   fillAttribute(theX, myx);
99   fillAttribute(theY, myy);
100   fillAttribute(theZ, myz);
101   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
102
103   execute(false);
104 }
105
106 //==================================================================================================
107 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
108                                               const ModelHighAPI_Double& theOffset,
109                                               const bool theUseRatio,
110                                               const bool theReverse)
111 {
112   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
113   fillAttribute(theEdge, myedge);
114   if (theUseRatio) {
115     fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
116     fillAttribute(theOffset, myratio);
117   }
118   else {
119     fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
120     fillAttribute(theOffset, mydistance);
121   }
122   fillAttribute(theReverse, myreverse);
123
124   execute();
125 }
126
127 //==================================================================================================
128 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
129                                                   const ModelHighAPI_Selection& theEdge)
130 {
131   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
132                 mycreationMethod);
133   fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
134                 myprojectionType);
135   fillAttribute(theVertex, mypoinToProject);
136   fillAttribute(theEdge, myedgeForPointProjection);
137
138   execute();
139 }
140
141 //==================================================================================================
142 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
143                                                   const ModelHighAPI_Selection& theFace)
144 {
145   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
146                 mycreationMethod);
147   fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
148                 myprojectionType);
149   fillAttribute(theVertex, mypoinToProject);
150   fillAttribute(theFace, myfaceForPointProjection);
151
152   execute();
153 }
154
155 /*
156 //==================================================================================================
157 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
158                                                    const ModelHighAPI_Selection& theEdge2)
159 {
160   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
161   fillAttribute(theEdge1, myfirstLine);
162   fillAttribute(theEdge2, mysecondLine);
163
164   execute();
165 }
166 */
167
168 //==================================================================================================
169 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
170                                                           const ModelHighAPI_Selection& theFace)
171 {
172   fillAttribute(
173     ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
174   fillAttribute(theEdge, myintersectionLine);
175   fillAttribute(theFace, myintersectionPlane);
176   fillAttribute("", useOffset()); // not used by default
177   execute();
178 }
179
180 //==================================================================================================
181 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
182 {
183   FeaturePtr aBase = feature();
184   const std::string& aDocName = theDumper.name(aBase->document());
185   const std::string& aMeth = creationMethod()->value();
186
187   // common part
188   theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
189
190   if (aMeth == "" || // default is XYZ
191       aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
192     theDumper << x() << ", " << y() << ", " << z();
193   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
194     theDumper << intersectionLine() << ", " <<intersectionPlane() ;
195     if (!useOffset()->value().empty()) { // call method with defined offset
196       theDumper << ", " << offset() << ", " << reverseOffset();
197     }
198   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
199     theDumper << edge() << ", ";
200     if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
201       theDumper << distance() << ", " << false;
202     }
203     else {
204       theDumper << ratio() << ", " << true;
205     }
206     theDumper << ", " << reverse()->value();
207   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
208     theDumper << mypoinToProject << ", ";
209     if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
210       theDumper << myedgeForPointProjection;
211     } else {
212       theDumper << myfaceForPointProjection;
213     }
214   }
215
216   theDumper << ")" << std::endl;
217 }
218
219 //==================================================================================================
220 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
221                   const ModelHighAPI_Double& theX,
222                   const ModelHighAPI_Double& theY,
223                   const ModelHighAPI_Double& theZ)
224 {
225   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
226   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
227 }
228
229 //==================================================================================================
230 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
231                   const ModelHighAPI_Selection& theEdge,
232                   const ModelHighAPI_Double& theOffset,
233                   const bool theUseRatio,
234                   const bool theReverse)
235 {
236   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
237   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
238 }
239
240 //==================================================================================================
241 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
242                   const ModelHighAPI_Selection& theObject1,
243                   const ModelHighAPI_Selection& theObject2)
244 {
245   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
246   return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
247 }
248
249 //==================================================================================================
250 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
251                   const ModelHighAPI_Selection& theObject1,
252                   const ModelHighAPI_Selection& theObject2,
253                   const ModelHighAPI_Double& theDistanceValue,
254                   const bool theReverse)
255 {
256   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
257   PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
258
259   fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
260   fillAttribute(theDistanceValue, anAPI->offset());
261   fillAttribute(theReverse, anAPI->reverseOffset());
262
263   return anAPI;
264 }