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);
146 //==================================================================================================
147 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
148 const ModelHighAPI_Double& theOffset,
149 const bool theUseRatio,
150 const bool theReverse)
152 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
153 fillAttribute(theEdge, myedge);
155 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
156 fillAttribute(theOffset, myratio);
159 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
160 fillAttribute(theOffset, mydistance);
162 fillAttribute(theReverse, myreverse);
167 //==================================================================================================
168 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
169 const ModelHighAPI_Selection& theEdge)
171 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
173 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
175 fillAttribute(theVertex, mypoinToProject);
176 fillAttribute(theEdge, myedgeForPointProjection);
181 //==================================================================================================
182 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
183 const ModelHighAPI_Selection& theFace)
185 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
187 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
189 fillAttribute(theVertex, mypoinToProject);
190 fillAttribute(theFace, myfaceForPointProjection);
195 //==================================================================================================
196 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
197 const ModelHighAPI_Selection& theEdge2)
199 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
200 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES(),
202 fillAttribute(theEdge1, myintersectionLine1);
203 fillAttribute(theEdge2, myintersectionLine2);
208 //==================================================================================================
209 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
210 const ModelHighAPI_Selection& theFace)
212 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
213 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE(),
215 fillAttribute(theEdge, myintersectionLine);
216 fillAttribute(theFace, myintersectionPlane);
217 fillAttribute("", useOffset()); // not used by default
221 //==================================================================================================
222 void ConstructionAPI_Point::setByPlanesIntersection(const ModelHighAPI_Selection& theFace1,
223 const ModelHighAPI_Selection& theFace2,
224 const ModelHighAPI_Selection& theFace3)
226 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
227 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES(),
229 fillAttribute(theFace1, myintersectionPlane1);
230 fillAttribute(theFace2, myintersectionPlane2);
231 fillAttribute(theFace3, myintersectionPlane3);
236 //==================================================================================================
237 void ConstructionAPI_Point::setByCenterOfGravity(const ModelHighAPI_Selection& theObject)
239 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
241 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY(),
242 mygeometricalPropertyType);
243 fillAttribute(theObject, myobjectForCenterOfGravity);
246 //==================================================================================================
247 void ConstructionAPI_Point::setByCenterOfCircle(const ModelHighAPI_Selection& theObject)
249 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(),
251 fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_CIRCLE(),
252 mygeometricalPropertyType);
253 fillAttribute(theObject, myobjectForCenterOfCircle);
256 //==================================================================================================
257 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
259 FeaturePtr aBase = feature();
260 const std::string& aDocName = theDumper.name(aBase->document());
261 const std::string aMeth = creationMethod()->value();
264 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
266 if (aMeth == "" || // default is XYZ
267 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
268 theDumper << point() << ")" << std::endl;
269 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
270 const std::string anIntersectionType = intersectionType()->value();
271 if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
273 theDumper << intersectionLine1() << ", " << intersectionLine2();
275 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE())
277 theDumper << intersectionLine() << ", " << intersectionPlane();
278 if (!useOffset()->value().empty()) { // call method with defined offset
279 theDumper << ", " << offset() << ", " << reverseOffset();
282 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES())
284 theDumper << intersectionPlane1() << ", "
285 << intersectionPlane2() << ", "
286 << intersectionPlane3();
288 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
289 theDumper << edge() << ", ";
290 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
291 theDumper << distance() << ", " << false;
294 theDumper << ratio() << ", " << true;
296 theDumper << ", " << reverse()->value();
297 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
298 theDumper << poinToProject() << ", ";
299 if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
300 theDumper << edgeForPointProjection();
302 theDumper << faceForPointProjection();
304 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY()) {
305 if (geometricalPropertyType()->value() ==
306 ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY())
308 theDumper << objectForCenterOfGravity();
312 theDumper << objectForCenterOfCircle() << ", " << true;
316 theDumper << ")" << std::endl;
319 //==================================================================================================
320 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
321 const ModelHighAPI_Double& theX,
322 const ModelHighAPI_Double& theY,
323 const ModelHighAPI_Double& theZ)
325 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
326 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
329 //==================================================================================================
330 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
331 const ModelHighAPI_Selection& theEdge,
332 const ModelHighAPI_Double& theOffset,
333 const bool theUseRatio,
334 const bool theReverse)
336 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
337 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
340 //==================================================================================================
341 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
342 const ModelHighAPI_Selection& theObject1,
343 const ModelHighAPI_Selection& theObject2)
345 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
346 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
349 //==================================================================================================
350 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
351 const ModelHighAPI_Selection& theObject1,
352 const ModelHighAPI_Selection& theObject2,
353 const ModelHighAPI_Double& theDistanceValue,
354 const bool theReverse)
356 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
357 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
359 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
360 fillAttribute(theDistanceValue, anAPI->offset());
361 fillAttribute(theReverse, anAPI->reverseOffset());
366 //==================================================================================================
367 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
368 const ModelHighAPI_Selection& theObject1,
369 const ModelHighAPI_Selection& theObject2,
370 const ModelHighAPI_Selection& theObject3)
372 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
373 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2, theObject3));
376 //==================================================================================================
377 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
378 const ModelHighAPI_Selection& theObject,
379 const bool theIsCircularEdge)
381 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
382 return PointPtr(new ConstructionAPI_Point(aFeature, theObject, theIsCircularEdge));