1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "ConstructionAPI_Point.h"
23 #include <GeomAPI_Shape.h>
25 #include <ModelHighAPI_Dumper.h>
26 #include <ModelHighAPI_Selection.h>
27 #include <ModelHighAPI_Tools.h>
29 //==================================================================================================
30 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
31 : ModelHighAPI_Interface(theFeature)
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)
44 setByXYZ(theX, theY, theZ);
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)
57 setByOffsetOnEdge(theEdge, theOffset, theUseRatio, theReverse);
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)
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);
86 //==================================================================================================
87 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
88 const ModelHighAPI_Selection& theObject1,
89 const ModelHighAPI_Selection& theObject2,
90 const ModelHighAPI_Selection& theObject3)
91 : ModelHighAPI_Interface(theFeature)
95 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
96 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
97 GeomAPI_Shape::ShapeType aType3 = getShapeType(theObject3);
98 if (aType1 == GeomAPI_Shape::FACE
99 && aType2 == GeomAPI_Shape::FACE
100 && aType3 == GeomAPI_Shape::FACE)
102 setByPlanesIntersection(theObject1, theObject2, theObject3);
107 //==================================================================================================
108 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
109 const ModelHighAPI_Selection& theObject,
110 const bool theIsCircularEdge)
111 : ModelHighAPI_Interface(theFeature)
115 if (theIsCircularEdge) {
116 setByCenterOfCircle(theObject);
118 setByCenterOfGravity(theObject);
123 //==================================================================================================
124 ConstructionAPI_Point::~ConstructionAPI_Point()
129 //==================================================================================================
130 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
131 const ModelHighAPI_Double& theY,
132 const ModelHighAPI_Double& theZ)
134 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
135 fillAttribute(theX, myx);
136 fillAttribute(theY, myy);
137 fillAttribute(theZ, myz);
138 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
143 //==================================================================================================
144 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
145 const ModelHighAPI_Double& theOffset,
146 const bool theUseRatio,
147 const bool theReverse)
149 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
150 fillAttribute(theEdge, myedge);
152 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
153 fillAttribute(theOffset, myratio);
156 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
157 fillAttribute(theOffset, mydistance);
159 fillAttribute(theReverse, myreverse);
164 //==================================================================================================
165 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
166 const ModelHighAPI_Selection& theEdge)
168 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
170 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
172 fillAttribute(theVertex, mypoinToProject);
173 fillAttribute(theEdge, myedgeForPointProjection);
178 //==================================================================================================
179 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
180 const ModelHighAPI_Selection& theFace)
182 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
184 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
186 fillAttribute(theVertex, mypoinToProject);
187 fillAttribute(theFace, myfaceForPointProjection);
192 //==================================================================================================
193 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
194 const ModelHighAPI_Selection& theEdge2)
196 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
197 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES(),
199 fillAttribute(theEdge1, myintersectionLine1);
200 fillAttribute(theEdge2, myintersectionLine2);
205 //==================================================================================================
206 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
207 const ModelHighAPI_Selection& theFace)
209 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
210 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE(),
212 fillAttribute(theEdge, myintersectionLine);
213 fillAttribute(theFace, myintersectionPlane);
214 fillAttribute("", useOffset()); // not used by default
218 //==================================================================================================
219 void ConstructionAPI_Point::setByPlanesIntersection(const ModelHighAPI_Selection& theFace1,
220 const ModelHighAPI_Selection& theFace2,
221 const ModelHighAPI_Selection& theFace3)
223 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
224 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES(),
226 fillAttribute(theFace1, myintersectionPlane1);
227 fillAttribute(theFace2, myintersectionPlane2);
228 fillAttribute(theFace3, myintersectionPlane3);
233 //==================================================================================================
234 void ConstructionAPI_Point::setByCenterOfGravity(const ModelHighAPI_Selection& theObject)
236 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
238 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY(),
239 mygeometricalPropertyType);
240 fillAttribute(theObject, myobjectForCenterOfGravity);
243 //==================================================================================================
244 void ConstructionAPI_Point::setByCenterOfCircle(const ModelHighAPI_Selection& theObject)
246 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
248 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_CIRCLE(),
249 mygeometricalPropertyType);
250 fillAttribute(theObject, myobjectForCenterOfCircle);
253 //==================================================================================================
254 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
256 FeaturePtr aBase = feature();
257 const std::string& aDocName = theDumper.name(aBase->document());
258 const std::string aMeth = creationMethod()->value();
261 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
263 if (aMeth == "" || // default is XYZ
264 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
265 theDumper << x() << ", " << y() << ", " << z();
266 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
267 const std::string anIntersectionType = intersectionType()->value();
268 if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
270 theDumper << intersectionLine1() << ", " << intersectionLine2();
272 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE())
274 theDumper << intersectionLine() << ", " << intersectionPlane();
275 if (!useOffset()->value().empty()) { // call method with defined offset
276 theDumper << ", " << offset() << ", " << reverseOffset();
279 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES())
281 theDumper << intersectionPlane1() << ", "
282 << intersectionPlane2() << ", "
283 << intersectionPlane3();
285 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
286 theDumper << edge() << ", ";
287 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
288 theDumper << distance() << ", " << false;
291 theDumper << ratio() << ", " << true;
293 theDumper << ", " << reverse()->value();
294 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
295 theDumper << poinToProject() << ", ";
296 if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
297 theDumper << edgeForPointProjection();
299 theDumper << faceForPointProjection();
301 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY()) {
302 if (geometricalPropertyType()->value() ==
303 ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY())
305 theDumper << objectForCenterOfGravity();
309 theDumper << objectForCenterOfCircle() << ", " << true;
313 theDumper << ")" << std::endl;
316 //==================================================================================================
317 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
318 const ModelHighAPI_Double& theX,
319 const ModelHighAPI_Double& theY,
320 const ModelHighAPI_Double& theZ)
322 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
323 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
326 //==================================================================================================
327 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
328 const ModelHighAPI_Selection& theEdge,
329 const ModelHighAPI_Double& theOffset,
330 const bool theUseRatio,
331 const bool theReverse)
333 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
334 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
337 //==================================================================================================
338 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
339 const ModelHighAPI_Selection& theObject1,
340 const ModelHighAPI_Selection& theObject2)
342 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
343 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
346 //==================================================================================================
347 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
348 const ModelHighAPI_Selection& theObject1,
349 const ModelHighAPI_Selection& theObject2,
350 const ModelHighAPI_Double& theDistanceValue,
351 const bool theReverse)
353 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
354 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
356 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
357 fillAttribute(theDistanceValue, anAPI->offset());
358 fillAttribute(theReverse, anAPI->reverseOffset());
363 //==================================================================================================
364 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
365 const ModelHighAPI_Selection& theObject1,
366 const ModelHighAPI_Selection& theObject2,
367 const ModelHighAPI_Selection& theObject3)
369 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
370 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2, theObject3));
373 //==================================================================================================
374 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
375 const ModelHighAPI_Selection& theObject,
376 const bool theIsCircularEdge)
378 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
379 return PointPtr(new ConstructionAPI_Point(aFeature, theObject, theIsCircularEdge));