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(),
133 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
135 fillAttribute(theVertex, mypoinToProject);
136 fillAttribute(theEdge, myedgeForPointProjection);
141 //==================================================================================================
142 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
143 const ModelHighAPI_Selection& theFace)
145 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(),
147 fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
149 fillAttribute(theVertex, mypoinToProject);
150 fillAttribute(theFace, myfaceForPointProjection);
156 //==================================================================================================
157 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
158 const ModelHighAPI_Selection& theEdge2)
160 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
161 fillAttribute(theEdge1, myfirstLine);
162 fillAttribute(theEdge2, mysecondLine);
168 //==================================================================================================
169 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
170 const ModelHighAPI_Selection& theFace)
173 ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
174 fillAttribute(theEdge, myintersectionLine);
175 fillAttribute(theFace, myintersectionPlane);
176 fillAttribute("", useOffset()); // not used by default
180 //==================================================================================================
181 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
183 FeaturePtr aBase = feature();
184 const std::string& aDocName = theDumper.name(aBase->document());
185 const std::string& aMeth = creationMethod()->value();
188 theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
190 if (aMeth == "" || // default is XYZ
191 aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
192 theDumper << x() << ", " << y() << ", " << z();
193 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
194 theDumper << intersectionLine() << ", " <<intersectionPlane() ;
195 if (!useOffset()->value().empty()) { // call method with defined offset
196 theDumper << ", " << offset() << ", " << reverseOffset();
198 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
199 theDumper << edge() << ", ";
200 if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) {
201 theDumper << distance() << ", " << false;
204 theDumper << ratio() << ", " << true;
206 theDumper << ", " << reverse()->value();
207 } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
208 theDumper << mypoinToProject << ", ";
209 if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
210 theDumper << myedgeForPointProjection;
212 theDumper << myfaceForPointProjection;
216 theDumper << ")" << std::endl;
219 //==================================================================================================
220 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
221 const ModelHighAPI_Double& theX,
222 const ModelHighAPI_Double& theY,
223 const ModelHighAPI_Double& theZ)
225 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
226 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
229 //==================================================================================================
230 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
231 const ModelHighAPI_Selection& theEdge,
232 const ModelHighAPI_Double& theOffset,
233 const bool theUseRatio,
234 const bool theReverse)
236 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
237 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theOffset, theUseRatio, theReverse));
240 //==================================================================================================
241 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
242 const ModelHighAPI_Selection& theObject1,
243 const ModelHighAPI_Selection& theObject2)
245 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
246 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
249 //==================================================================================================
250 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
251 const ModelHighAPI_Selection& theObject1,
252 const ModelHighAPI_Selection& theObject2,
253 const ModelHighAPI_Double& theDistanceValue,
254 const bool theReverse)
256 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
257 PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
259 fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
260 fillAttribute(theDistanceValue, anAPI->offset());
261 fillAttribute(theReverse, anAPI->reverseOffset());