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()
92 //==================================================================================================
93 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
94 const ModelHighAPI_Double& theY,
95 const ModelHighAPI_Double& theZ)
97 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
98 fillAttribute(theX, myx);
99 fillAttribute(theY, myy);
100 fillAttribute(theZ, myz);
101 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
106 //==================================================================================================
107 void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theEdge,
108 const ModelHighAPI_Double& theOffset,
109 const bool theUseRatio,
110 const bool theReverse)
112 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
113 fillAttribute(theEdge, myedge);
115 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_RATIO(), myoffsetType);
116 fillAttribute(theOffset, myratio);
119 fillAttribute(ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE(), myoffsetType);
120 fillAttribute(theOffset, mydistance);
122 fillAttribute(theReverse, myreverse);
127 //==================================================================================================
128 void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
129 const ModelHighAPI_Selection& theEdge)
131 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE(),
133 fillAttribute(theVertex, mypoinToProjectOnEdge);
134 fillAttribute(theEdge, myedgeForPointProjection);
139 //==================================================================================================
140 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
141 const ModelHighAPI_Selection& theFace)
143 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_FACE(),
145 fillAttribute(theVertex, mypoinToProjectOnFace);
146 fillAttribute(theFace, myfaceForPointProjection);
152 //==================================================================================================
153 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
154 const ModelHighAPI_Selection& theEdge2)
156 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
157 fillAttribute(theEdge1, myfirstLine);
158 fillAttribute(theEdge2, mysecondLine);
164 //==================================================================================================
165 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
166 const ModelHighAPI_Selection& theFace)
169 ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
170 fillAttribute(theEdge, myintersectionLine);
171 fillAttribute(theFace, myintersectionPlane);
172 fillAttribute("", useOffset()); // not used by default
176 //==================================================================================================
177 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
179 FeaturePtr aBase = feature();
180 const std::string& aDocName = theDumper.name(aBase->document());
181 const std::string& aMeth = creationMethod()->value();
184 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
186 if (aMeth == "" || // default is XYZ
187 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
188 theDumper << x() << ", " << y() << ", " << z();
189 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
190 theDumper << intersectionLine() << ", " <<intersectionPlane() ;
191 if (!useOffset()->value().empty()) { // call method with defined offset
192 theDumper << ", " << offset() << ", " << reverseOffset();
194 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
195 theDumper << edge() << ", ";
196 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
197 theDumper << distance() << ", " << false;
200 theDumper << ratio() << ", " << true;
202 theDumper << ", " << reverse()->value();
203 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE()) {
204 theDumper << mypoinToProjectOnEdge << ", " << myedgeForPointProjection;
205 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_FACE()) {
206 theDumper << mypoinToProjectOnFace << ", " << myfaceForPointProjection;
209 theDumper << ")" << std::endl;
212 //==================================================================================================
213 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
214 const ModelHighAPI_Double& theX,
215 const ModelHighAPI_Double& theY,
216 const ModelHighAPI_Double& theZ)
218 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
219 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
222 //==================================================================================================
223 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
224 const ModelHighAPI_Selection& theEdge,
225 const ModelHighAPI_Double& theOffset,
226 const bool theUseRatio,
227 const bool theReverse)
229 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
230 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
233 //==================================================================================================
234 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
235 const ModelHighAPI_Selection& theObject1,
236 const ModelHighAPI_Selection& theObject2)
238 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
239 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
242 //==================================================================================================
243 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
244 const ModelHighAPI_Selection& theObject1,
245 const ModelHighAPI_Selection& theObject2,
246 const ModelHighAPI_Double& theDistanceValue,
247 const bool theReverse)
249 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
250 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
252 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
253 fillAttribute(theDistanceValue, anAPI->offset());
254 fillAttribute(theReverse, anAPI->reverseOffset());