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);
136 // TODO: Fill point attribute
137 //fillAttribute(theX, myx);
138 //fillAttribute(theY, myy);
139 //fillAttribute(theZ, myz);
141 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
142 fillAttribute(theX, theY, theZ, mypoint);
147 //==================================================================================================
148 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
149 const ModelHighAPI_Double& theOffset,
150 const bool theUseRatio,
151 const bool theReverse)
153 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
154 fillAttribute(theEdge, myedge);
156 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
157 fillAttribute(theOffset, myratio);
160 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
161 fillAttribute(theOffset, mydistance);
163 fillAttribute(theReverse, myreverse);
168 //==================================================================================================
169 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
170 const ModelHighAPI_Selection& theEdge)
172 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
174 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
176 fillAttribute(theVertex, mypoinToProject);
177 fillAttribute(theEdge, myedgeForPointProjection);
182 //==================================================================================================
183 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
184 const ModelHighAPI_Selection& theFace)
186 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
188 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
190 fillAttribute(theVertex, mypoinToProject);
191 fillAttribute(theFace, myfaceForPointProjection);
196 //==================================================================================================
197 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
198 const ModelHighAPI_Selection& theEdge2)
200 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
201 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES(),
203 fillAttribute(theEdge1, myintersectionLine1);
204 fillAttribute(theEdge2, myintersectionLine2);
209 //==================================================================================================
210 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
211 const ModelHighAPI_Selection& theFace)
213 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
214 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE(),
216 fillAttribute(theEdge, myintersectionLine);
217 fillAttribute(theFace, myintersectionPlane);
218 fillAttribute("", useOffset()); // not used by default
222 //==================================================================================================
223 void ConstructionAPI_Point::setByPlanesIntersection(const ModelHighAPI_Selection& theFace1,
224 const ModelHighAPI_Selection& theFace2,
225 const ModelHighAPI_Selection& theFace3)
227 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
228 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES(),
230 fillAttribute(theFace1, myintersectionPlane1);
231 fillAttribute(theFace2, myintersectionPlane2);
232 fillAttribute(theFace3, myintersectionPlane3);
237 //==================================================================================================
238 void ConstructionAPI_Point::setByCenterOfGravity(const ModelHighAPI_Selection& theObject)
240 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
242 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY(),
243 mygeometricalPropertyType);
244 fillAttribute(theObject, myobjectForCenterOfGravity);
247 //==================================================================================================
248 void ConstructionAPI_Point::setByCenterOfCircle(const ModelHighAPI_Selection& theObject)
250 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
252 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_CIRCLE(),
253 mygeometricalPropertyType);
254 fillAttribute(theObject, myobjectForCenterOfCircle);
257 //==================================================================================================
258 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
260 FeaturePtr aBase = feature();
261 const std::string& aDocName = theDumper.name(aBase->document());
262 const std::string aMeth = creationMethod()->value();
265 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
267 if (aMeth == "" || // default is XYZ
268 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
269 theDumper << point();
270 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
271 const std::string anIntersectionType = intersectionType()->value();
272 if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
274 theDumper << intersectionLine1() << ", " << intersectionLine2();
276 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE())
278 theDumper << intersectionLine() << ", " << intersectionPlane();
279 if (!useOffset()->value().empty()) { // call method with defined offset
280 theDumper << ", " << offset() << ", " << reverseOffset();
283 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES())
285 theDumper << intersectionPlane1() << ", "
286 << intersectionPlane2() << ", "
287 << intersectionPlane3();
289 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
290 theDumper << edge() << ", ";
291 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
292 theDumper << distance() << ", " << false;
295 theDumper << ratio() << ", " << true;
297 theDumper << ", " << reverse()->value();
298 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
299 theDumper << poinToProject() << ", ";
300 if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
301 theDumper << edgeForPointProjection();
303 theDumper << faceForPointProjection();
305 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY()) {
306 if (geometricalPropertyType()->value() ==
307 ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY())
309 theDumper << objectForCenterOfGravity();
313 theDumper << objectForCenterOfCircle() << ", " << true;
317 theDumper << ")" << std::endl;
320 //==================================================================================================
321 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
322 const ModelHighAPI_Double& theX,
323 const ModelHighAPI_Double& theY,
324 const ModelHighAPI_Double& theZ)
326 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
327 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
330 //==================================================================================================
331 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
332 const ModelHighAPI_Selection& theEdge,
333 const ModelHighAPI_Double& theOffset,
334 const bool theUseRatio,
335 const bool theReverse)
337 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
338 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
341 //==================================================================================================
342 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
343 const ModelHighAPI_Selection& theObject1,
344 const ModelHighAPI_Selection& theObject2)
346 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
347 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
350 //==================================================================================================
351 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
352 const ModelHighAPI_Selection& theObject1,
353 const ModelHighAPI_Selection& theObject2,
354 const ModelHighAPI_Double& theDistanceValue,
355 const bool theReverse)
357 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
358 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
360 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
361 fillAttribute(theDistanceValue, anAPI->offset());
362 fillAttribute(theReverse, anAPI->reverseOffset());
367 //==================================================================================================
368 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
369 const ModelHighAPI_Selection& theObject1,
370 const ModelHighAPI_Selection& theObject2,
371 const ModelHighAPI_Selection& theObject3)
373 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
374 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2, theObject3));
377 //==================================================================================================
378 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
379 const ModelHighAPI_Selection& theObject,
380 const bool theIsCircularEdge)
382 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
383 return PointPtr(new ConstructionAPI_Point(aFeature, theObject, theIsCircularEdge));