1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "ConstructionAPI_Point.h"
22 #include <GeomAPI_Pnt.h>
23 #include <GeomAPI_Shape.h>
24 #include <GeomAPI_Vertex.h>
26 #include <ModelHighAPI_Double.h>
27 #include <ModelHighAPI_Dumper.h>
28 #include <ModelHighAPI_Selection.h>
29 #include <ModelHighAPI_Tools.h>
31 //==================================================================================================
32 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
38 //==================================================================================================
39 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
40 const ModelHighAPI_Double& theX,
41 const ModelHighAPI_Double& theY,
42 const ModelHighAPI_Double& theZ)
43 : ModelHighAPI_Interface(theFeature)
46 setByXYZ(theX, theY, theZ);
50 //==================================================================================================
51 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
52 const ModelHighAPI_Selection& theEdge,
53 const ModelHighAPI_Double& theOffset,
54 const bool theUseRatio,
55 const bool theReverse)
56 : ModelHighAPI_Interface(theFeature)
59 setByOffsetOnEdge(theEdge, theOffset, theUseRatio, theReverse);
63 //==================================================================================================
64 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
65 const ModelHighAPI_Selection& theObject1,
66 const ModelHighAPI_Selection& theObject2)
67 : ModelHighAPI_Interface(theFeature)
70 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
71 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
72 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
73 // If first object is vertex and second object is face then set by projection.
74 setByProjectionOnFace(theObject1, theObject2);
75 } else if (aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::EDGE) {
76 // If first object is vertex and second object is edge then set by projection.
77 setByProjectionOnEdge(theObject1, theObject2);
78 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
79 // If both objects are edges then set by lines intersection.
80 setByLinesIntersection(theObject1, theObject2);
81 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
82 // If first object is edge and second object is face then set by line and plane intersection.
83 setByLineAndPlaneIntersection(theObject1, theObject2);
88 //==================================================================================================
89 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
90 const ModelHighAPI_Selection& theObject1,
91 const ModelHighAPI_Selection& theObject2,
92 const ModelHighAPI_Selection& theObject3)
93 : ModelHighAPI_Interface(theFeature)
97 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
98 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
99 GeomAPI_Shape::ShapeType aType3 = getShapeType(theObject3);
100 if (aType1 == GeomAPI_Shape::FACE
101 && aType2 == GeomAPI_Shape::FACE
102 && aType3 == GeomAPI_Shape::FACE)
104 setByPlanesIntersection(theObject1, theObject2, theObject3);
109 //==================================================================================================
110 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
111 const ModelHighAPI_Selection& theObject,
112 const bool theIsCircularEdge)
113 : ModelHighAPI_Interface(theFeature)
117 if (theIsCircularEdge) {
118 setByCenterOfCircle(theObject);
119 } else if (theObject.shapeType() == "VERTEX") {
120 // This is tricky way to get vertex shape.
121 fillAttribute(theObject, mypointToProject);
122 GeomShapePtr aShape = mypointToProject->value();
124 ResultPtr aContext = mypointToProject->context();
125 if (!aContext.get()) {
126 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
129 aShape = aContext->shape();
133 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
137 GeomVertexPtr aVertex = aShape->vertex();
138 if (!aVertex.get()) {
139 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
143 GeomPointPtr aPnt = aVertex->point();
145 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
149 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
150 setByXYZ(aPnt->x(), aPnt->y(), aPnt->z());
152 setByCenterOfGravity(theObject);
157 //==================================================================================================
158 ConstructionAPI_Point::~ConstructionAPI_Point()
163 //==================================================================================================
164 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
165 const ModelHighAPI_Double& theY,
166 const ModelHighAPI_Double& theZ)
168 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
170 // TODO: Fill point attribute
171 //fillAttribute(theX, myx);
172 //fillAttribute(theY, myy);
173 //fillAttribute(theZ, myz);
175 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
176 fillAttribute(theX, theY, theZ, mypoint);
181 //==================================================================================================
182 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
183 const ModelHighAPI_Double& theOffset,
184 const bool theUseRatio,
185 const bool theReverse)
187 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
188 fillAttribute(theEdge, myedge);
190 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
191 fillAttribute(theOffset, myratio);
194 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
195 fillAttribute(theOffset, mydistance);
197 fillAttribute(theReverse, myreverse);
202 //==================================================================================================
203 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
204 const ModelHighAPI_Selection& theEdge)
206 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
208 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
210 fillAttribute(theVertex, mypointToProject);
211 fillAttribute(theEdge, myedgeForPointProjection);
216 //==================================================================================================
217 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
218 const ModelHighAPI_Selection& theFace)
220 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
222 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
224 fillAttribute(theVertex, mypointToProject);
225 fillAttribute(theFace, myfaceForPointProjection);
230 //==================================================================================================
231 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
232 const ModelHighAPI_Selection& theEdge2)
234 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
235 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES(),
237 fillAttribute(theEdge1, myintersectionLine1);
238 fillAttribute(theEdge2, myintersectionLine2);
243 //==================================================================================================
244 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
245 const ModelHighAPI_Selection& theFace)
247 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
248 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE(),
250 fillAttribute(theEdge, myintersectionLine);
251 fillAttribute(theFace, myintersectionPlane);
252 fillAttribute("", useOffset()); // not used by default
256 //==================================================================================================
257 void ConstructionAPI_Point::setByPlanesIntersection(const ModelHighAPI_Selection& theFace1,
258 const ModelHighAPI_Selection& theFace2,
259 const ModelHighAPI_Selection& theFace3)
261 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
262 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES(),
264 fillAttribute(theFace1, myintersectionPlane1);
265 fillAttribute(theFace2, myintersectionPlane2);
266 fillAttribute(theFace3, myintersectionPlane3);
271 //==================================================================================================
272 void ConstructionAPI_Point::setByCenterOfGravity(const ModelHighAPI_Selection& theObject)
274 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
276 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY(),
277 mygeometricalPropertyType);
278 fillAttribute(theObject, myobjectForCenterOfGravity);
281 //==================================================================================================
282 void ConstructionAPI_Point::setByCenterOfCircle(const ModelHighAPI_Selection& theObject)
284 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
286 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_CIRCLE(),
287 mygeometricalPropertyType);
288 fillAttribute(theObject, myobjectForCenterOfCircle);
291 //==================================================================================================
292 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
294 FeaturePtr aBase = feature();
295 const std::string& aDocName = theDumper.name(aBase->document());
296 const std::string aMeth = creationMethod()->value();
299 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
301 if (aMeth == "" || // default is XYZ
302 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
303 theDumper << point();
304 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
305 const std::string anIntersectionType = intersectionType()->value();
306 if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
308 theDumper << intersectionLine1() << ", " << intersectionLine2();
310 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE())
312 theDumper << intersectionLine() << ", " << intersectionPlane();
313 if (!useOffset()->value().empty()) { // call method with defined offset
314 theDumper << ", " << offset() << ", " << reverseOffset();
317 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES())
319 theDumper << intersectionPlane1() << ", "
320 << intersectionPlane2() << ", "
321 << intersectionPlane3();
323 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
324 theDumper << edge() << ", ";
325 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
326 theDumper << distance() << ", " << false;
329 theDumper << ratio() << ", " << true;
331 theDumper << ", " << reverse()->value();
332 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
333 theDumper << pointToProject() << ", ";
334 if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
335 theDumper << edgeForPointProjection();
337 theDumper << faceForPointProjection();
339 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY()) {
340 if (geometricalPropertyType()->value() ==
341 ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY())
343 theDumper << objectForCenterOfGravity();
347 theDumper << objectForCenterOfCircle() << ", " << true;
351 theDumper << ")" << std::endl;
354 //==================================================================================================
355 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
356 const ModelHighAPI_Double& theX,
357 const ModelHighAPI_Double& theY,
358 const ModelHighAPI_Double& theZ)
360 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
361 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
364 //==================================================================================================
365 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
366 const ModelHighAPI_Selection& theEdge,
367 const ModelHighAPI_Double& theOffset,
368 const bool theUseRatio,
369 const bool theReverse)
371 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
372 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
375 //==================================================================================================
376 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
377 const ModelHighAPI_Selection& theObject1,
378 const ModelHighAPI_Selection& theObject2)
380 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
381 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
384 //==================================================================================================
385 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
386 const ModelHighAPI_Selection& theObject1,
387 const ModelHighAPI_Selection& theObject2,
388 const ModelHighAPI_Double& theDistanceValue,
389 const bool theReverse)
391 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
392 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
394 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
395 fillAttribute(theDistanceValue, anAPI->offset());
396 fillAttribute(theReverse, anAPI->reverseOffset());
401 //==================================================================================================
402 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
403 const ModelHighAPI_Selection& theObject1,
404 const ModelHighAPI_Selection& theObject2,
405 const ModelHighAPI_Selection& theObject3)
407 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
408 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2, theObject3));
411 //==================================================================================================
412 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
413 const ModelHighAPI_Selection& theObject,
414 const bool theIsCircularEdge)
416 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
417 return PointPtr(new ConstructionAPI_Point(aFeature, theObject, theIsCircularEdge));