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()
113 //==================================================================================================
114 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
115 const ModelHighAPI_Double& theY,
116 const ModelHighAPI_Double& theZ)
118 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
119 fillAttribute(theX, myx);
120 fillAttribute(theY, myy);
121 fillAttribute(theZ, myz);
122 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
127 //==================================================================================================
128 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
129 const ModelHighAPI_Double& theOffset,
130 const bool theUseRatio,
131 const bool theReverse)
133 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
134 fillAttribute(theEdge, myedge);
136 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
137 fillAttribute(theOffset, myratio);
140 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
141 fillAttribute(theOffset, mydistance);
143 fillAttribute(theReverse, myreverse);
148 //==================================================================================================
149 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
150 const ModelHighAPI_Selection& theEdge)
152 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
154 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
156 fillAttribute(theVertex, mypoinToProject);
157 fillAttribute(theEdge, myedgeForPointProjection);
162 //==================================================================================================
163 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
164 const ModelHighAPI_Selection& theFace)
166 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
168 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
170 fillAttribute(theVertex, mypoinToProject);
171 fillAttribute(theFace, myfaceForPointProjection);
176 //==================================================================================================
177 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
178 const ModelHighAPI_Selection& theEdge2)
180 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
181 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES(),
183 fillAttribute(theEdge1, myintersectionLine1);
184 fillAttribute(theEdge2, myintersectionLine2);
189 //==================================================================================================
190 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
191 const ModelHighAPI_Selection& theFace)
193 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
194 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE(),
196 fillAttribute(theEdge, myintersectionLine);
197 fillAttribute(theFace, myintersectionPlane);
198 fillAttribute("", useOffset()); // not used by default
202 //==================================================================================================
203 void ConstructionAPI_Point::setByPlanesIntersection(const ModelHighAPI_Selection& theFace1,
204 const ModelHighAPI_Selection& theFace2,
205 const ModelHighAPI_Selection& theFace3)
207 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod);
208 fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES(),
210 fillAttribute(theFace1, myintersectionPlane1);
211 fillAttribute(theFace2, myintersectionPlane2);
212 fillAttribute(theFace3, myintersectionPlane3);
217 //==================================================================================================
218 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
220 FeaturePtr aBase = feature();
221 const std::string& aDocName = theDumper.name(aBase->document());
222 const std::string aMeth = creationMethod()->value();
225 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
227 if (aMeth == "" || // default is XYZ
228 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
229 theDumper << x() << ", " << y() << ", " << z();
230 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
231 const std::string anIntersectionType = intersectionType()->value();
232 if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
234 theDumper << intersectionLine1() << ", " << intersectionLine2();
236 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE())
238 theDumper << intersectionLine() << ", " << intersectionPlane();
239 if (!useOffset()->value().empty()) { // call method with defined offset
240 theDumper << ", " << offset() << ", " << reverseOffset();
243 else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES())
245 theDumper << intersectionPlane1() << ", "
246 << intersectionPlane2() << ", "
247 << intersectionPlane3();
249 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
250 theDumper << edge() << ", ";
251 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
252 theDumper << distance() << ", " << false;
255 theDumper << ratio() << ", " << true;
257 theDumper << ", " << reverse()->value();
258 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
259 theDumper << mypoinToProject << ", ";
260 if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
261 theDumper << myedgeForPointProjection;
263 theDumper << myfaceForPointProjection;
267 theDumper << ")" << std::endl;
270 //==================================================================================================
271 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
272 const ModelHighAPI_Double& theX,
273 const ModelHighAPI_Double& theY,
274 const ModelHighAPI_Double& theZ)
276 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
277 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
280 //==================================================================================================
281 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
282 const ModelHighAPI_Selection& theEdge,
283 const ModelHighAPI_Double& theOffset,
284 const bool theUseRatio,
285 const bool theReverse)
287 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
288 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
291 //==================================================================================================
292 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
293 const ModelHighAPI_Selection& theObject1,
294 const ModelHighAPI_Selection& theObject2)
296 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
297 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
300 //==================================================================================================
301 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
302 const ModelHighAPI_Selection& theObject1,
303 const ModelHighAPI_Selection& theObject2,
304 const ModelHighAPI_Double& theDistanceValue,
305 const bool theReverse)
307 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
308 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
310 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
311 fillAttribute(theDistanceValue, anAPI->offset());
312 fillAttribute(theReverse, anAPI->reverseOffset());
317 //==================================================================================================
318 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
319 const ModelHighAPI_Selection& theObject1,
320 const ModelHighAPI_Selection& theObject2,
321 const ModelHighAPI_Selection& theObject3)
323 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
324 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2, theObject3));