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_Pnt.h>
24 #include <GeomAPI_Shape.h>
25 #include <GeomAPI_Vertex.h>
27 #include <ModelHighAPI_Double.h>
28 #include <ModelHighAPI_Dumper.h>
29 #include <ModelHighAPI_Selection.h>
30 #include <ModelHighAPI_Tools.h>
32 //==================================================================================================
33 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
34 : ModelHighAPI_Interface(theFeature)
39 //==================================================================================================
40 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41 const ModelHighAPI_Double& theX,
42 const ModelHighAPI_Double& theY,
43 const ModelHighAPI_Double& theZ)
44 : ModelHighAPI_Interface(theFeature)
47 setByXYZ(theX, theY, theZ);
51 //==================================================================================================
52 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
53 const ModelHighAPI_Selection& theEdge,
54 const ModelHighAPI_Double& theOffset,
55 const bool theUseRatio,
56 const bool theReverse)
57 : ModelHighAPI_Interface(theFeature)
60 setByOffsetOnEdge(theEdge, theOffset, theUseRatio, theReverse);
64 //==================================================================================================
65 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
66 const ModelHighAPI_Selection& theObject1,
67 const ModelHighAPI_Selection& theObject2)
68 : ModelHighAPI_Interface(theFeature)
71 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
72 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
73 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
74 // If first object is vertex and second object is face then set by projection.
75 setByProjectionOnFace(theObject1, theObject2);
76 } else if (aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::EDGE) {
77 // If first object is vertex and second object is edge then set by projection.
78 setByProjectionOnEdge(theObject1, theObject2);
79 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
80 // If both objects are edges then set by lines intersection.
81 setByLinesIntersection(theObject1, theObject2);
82 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
83 // If first object is edge and second object is face then set by line and plane intersection.
84 setByLineAndPlaneIntersection(theObject1, theObject2);
89 //==================================================================================================
90 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
91 const ModelHighAPI_Selection& theObject1,
92 const ModelHighAPI_Selection& theObject2,
93 const ModelHighAPI_Selection& theObject3)
94 : ModelHighAPI_Interface(theFeature)
98 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
99 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
100 GeomAPI_Shape::ShapeType aType3 = getShapeType(theObject3);
101 if (aType1 == GeomAPI_Shape::FACE
102 && aType2 == GeomAPI_Shape::FACE
103 && aType3 == GeomAPI_Shape::FACE)
105 setByPlanesIntersection(theObject1, theObject2, theObject3);
110 //==================================================================================================
111 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
112 const ModelHighAPI_Selection& theObject,
113 const bool theIsCircularEdge)
114 : ModelHighAPI_Interface(theFeature)
118 if (theIsCircularEdge) {
119 setByCenterOfCircle(theObject);
120 } else if (theObject.shapeType() == "VERTEX") {
121 // This is tricky way to get vertex shape.
122 fillAttribute(theObject, mypointToProject);
123 GeomShapePtr aShape = mypointToProject->value();
125 ResultPtr aContext = mypointToProject->context();
126 if (!aContext.get()) {
127 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
130 aShape = aContext->shape();
134 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
138 GeomVertexPtr aVertex = aShape->vertex();
139 if (!aVertex.get()) {
140 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
144 GeomPointPtr aPnt = aVertex->point();
146 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
150 fillAttribute(ModelHighAPI_Selection(), mypointToProject);
151 setByXYZ(aPnt->x(), aPnt->y(), aPnt->z());
153 setByCenterOfGravity(theObject);
158 //==================================================================================================
159 ConstructionAPI_Point::~ConstructionAPI_Point()
164 //==================================================================================================
165 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
166 const ModelHighAPI_Double& theY,
167 const ModelHighAPI_Double& theZ)
169 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
171 // TODO: Fill point attribute
172 //fillAttribute(theX, myx);
173 //fillAttribute(theY, myy);
174 //fillAttribute(theZ, myz);
176 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
177 fillAttribute(theX, theY, theZ, mypoint);
182 //==================================================================================================
183 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
184 const ModelHighAPI_Double& theOffset,
185 const bool theUseRatio,
186 const bool theReverse)
188 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
189 fillAttribute(theEdge, myedge);
191 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
192 fillAttribute(theOffset, myratio);
195 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
196 fillAttribute(theOffset, mydistance);
198 fillAttribute(theReverse, myreverse);
203 //==================================================================================================
204 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
205 const ModelHighAPI_Selection& theEdge)
207 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
209 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
211 fillAttribute(theVertex, mypointToProject);
212 fillAttribute(theEdge, myedgeForPointProjection);
217 //==================================================================================================
218 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
219 const ModelHighAPI_Selection& theFace)
221 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
223 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
225 fillAttribute(theVertex, mypointToProject);
226 fillAttribute(theFace, myfaceForPointProjection);
231 //==================================================================================================
232 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
233 const ModelHighAPI_Selection& theEdge2)
235 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
236 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES(),
238 fillAttribute(theEdge1, myintersectionLine1);
239 fillAttribute(theEdge2, myintersectionLine2);
244 //==================================================================================================
245 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
246 const ModelHighAPI_Selection& theFace)
248 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
249 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE(),
251 fillAttribute(theEdge, myintersectionLine);
252 fillAttribute(theFace, myintersectionPlane);
253 fillAttribute("", useOffset()); // not used by default
257 //==================================================================================================
258 void ConstructionAPI_Point::setByPlanesIntersection(const ModelHighAPI_Selection& theFace1,
259 const ModelHighAPI_Selection& theFace2,
260 const ModelHighAPI_Selection& theFace3)
262 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
263 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES(),
265 fillAttribute(theFace1, myintersectionPlane1);
266 fillAttribute(theFace2, myintersectionPlane2);
267 fillAttribute(theFace3, myintersectionPlane3);
272 //==================================================================================================
273 void ConstructionAPI_Point::setByCenterOfGravity(const ModelHighAPI_Selection& theObject)
275 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
277 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY(),
278 mygeometricalPropertyType);
279 fillAttribute(theObject, myobjectForCenterOfGravity);
282 //==================================================================================================
283 void ConstructionAPI_Point::setByCenterOfCircle(const ModelHighAPI_Selection& theObject)
285 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
287 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_CIRCLE(),
288 mygeometricalPropertyType);
289 fillAttribute(theObject, myobjectForCenterOfCircle);
292 //==================================================================================================
293 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
295 FeaturePtr aBase = feature();
296 const std::string& aDocName = theDumper.name(aBase->document());
297 const std::string aMeth = creationMethod()->value();
300 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
302 if (aMeth == "" || // default is XYZ
303 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
304 theDumper << point();
305 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
306 const std::string anIntersectionType = intersectionType()->value();
307 if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
309 theDumper << intersectionLine1() << ", " << intersectionLine2();
311 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE())
313 theDumper << intersectionLine() << ", " << intersectionPlane();
314 if (!useOffset()->value().empty()) { // call method with defined offset
315 theDumper << ", " << offset() << ", " << reverseOffset();
318 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES())
320 theDumper << intersectionPlane1() << ", "
321 << intersectionPlane2() << ", "
322 << intersectionPlane3();
324 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
325 theDumper << edge() << ", ";
326 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
327 theDumper << distance() << ", " << false;
330 theDumper << ratio() << ", " << true;
332 theDumper << ", " << reverse()->value();
333 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
334 theDumper << pointToProject() << ", ";
335 if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
336 theDumper << edgeForPointProjection();
338 theDumper << faceForPointProjection();
340 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY()) {
341 if (geometricalPropertyType()->value() ==
342 ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY())
344 theDumper << objectForCenterOfGravity();
348 theDumper << objectForCenterOfCircle() << ", " << true;
352 theDumper << ")" << std::endl;
355 //==================================================================================================
356 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
357 const ModelHighAPI_Double& theX,
358 const ModelHighAPI_Double& theY,
359 const ModelHighAPI_Double& theZ)
361 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
362 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
365 //==================================================================================================
366 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
367 const ModelHighAPI_Selection& theEdge,
368 const ModelHighAPI_Double& theOffset,
369 const bool theUseRatio,
370 const bool theReverse)
372 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
373 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
376 //==================================================================================================
377 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
378 const ModelHighAPI_Selection& theObject1,
379 const ModelHighAPI_Selection& theObject2)
381 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
382 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
385 //==================================================================================================
386 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
387 const ModelHighAPI_Selection& theObject1,
388 const ModelHighAPI_Selection& theObject2,
389 const ModelHighAPI_Double& theDistanceValue,
390 const bool theReverse)
392 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
393 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
395 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
396 fillAttribute(theDistanceValue, anAPI->offset());
397 fillAttribute(theReverse, anAPI->reverseOffset());
402 //==================================================================================================
403 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
404 const ModelHighAPI_Selection& theObject1,
405 const ModelHighAPI_Selection& theObject2,
406 const ModelHighAPI_Selection& theObject3)
408 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
409 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2, theObject3));
412 //==================================================================================================
413 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
414 const ModelHighAPI_Selection& theObject,
415 const bool theIsCircularEdge)
417 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
418 return PointPtr(new ConstructionAPI_Point(aFeature, theObject, theIsCircularEdge));