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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "ConstructionAPI_Point.h"
22 #include <GeomAPI_Shape.h>
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
28 //==================================================================================================
29 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
35 //==================================================================================================
36 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37 const ModelHighAPI_Double& theX,
38 const ModelHighAPI_Double& theY,
39 const ModelHighAPI_Double& theZ)
40 : ModelHighAPI_Interface(theFeature)
43 setByXYZ(theX, theY, theZ);
47 /*//==================================================================================================
48 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49 const ModelHighAPI_Selection& theEdge,
50 const ModelHighAPI_Double& theDistanceValue,
51 const bool theDistancePercent,
52 const bool theReverse)
53 : ModelHighAPI_Interface(theFeature)
56 setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
60 //==================================================================================================
61 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62 const ModelHighAPI_Selection& theObject1,
63 const ModelHighAPI_Selection& theObject2)
64 : ModelHighAPI_Interface(theFeature)
67 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
68 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 setByProjection(theObject1, theObject2);
73 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
74 // If both objects are edges then set by lines intersection.
75 setByLinesIntersection(theObject1, theObject2);
76 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
77 // If first object is edge and second object is face then set by line and plane intersection.
78 setByLineAndPlaneIntersection(theObject1, theObject2);
83 //==================================================================================================
84 ConstructionAPI_Point::~ConstructionAPI_Point()
89 //==================================================================================================
90 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
91 const ModelHighAPI_Double& theY,
92 const ModelHighAPI_Double& theZ)
94 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
95 fillAttribute(theX, myx);
96 fillAttribute(theY, myy);
97 fillAttribute(theZ, myz);
102 /*//==================================================================================================
103 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
104 const ModelHighAPI_Double& theDistanceValue,
105 const bool theDistancePercent,
106 const bool theReverse)
108 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
109 fillAttribute(theEdge, myedge);
110 fillAttribute(theDistanceValue, mydistanceValue);
111 fillAttribute(theDistancePercent, mydistancePercent);
112 fillAttribute(theReverse, myreverse);
117 //==================================================================================================
118 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
119 const ModelHighAPI_Selection& theFace)
121 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
122 fillAttribute(theVertex, mypoint);
123 fillAttribute(theFace, myplane);
128 //==================================================================================================
129 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
130 const ModelHighAPI_Selection& theEdge2)
132 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
133 fillAttribute(theEdge1, myfirstLine);
134 fillAttribute(theEdge2, mysecondLine);
139 //==================================================================================================
140 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
141 const ModelHighAPI_Selection& theFace)
143 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
144 fillAttribute(theEdge, myintersectionLine);
145 fillAttribute(theFace, myintersectionPlane);
150 //==================================================================================================
151 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
153 // TODO: all types of points
155 FeaturePtr aBase = feature();
156 const std::string& aDocName = theDumper.name(aBase->document());
158 AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Point::X());
159 AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Point::Y());
160 AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Point::Z());
161 theDumper << aBase << " = model.addPoint(" << aDocName << ", "
162 << anAttrX << ", " << anAttrY << ", " << anAttrZ << ")" << std::endl;
165 //==================================================================================================
166 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
167 const ModelHighAPI_Double& theX,
168 const ModelHighAPI_Double& theY,
169 const ModelHighAPI_Double& theZ)
171 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
172 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
175 /*//==================================================================================================
176 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
177 const ModelHighAPI_Selection& theEdge,
178 const ModelHighAPI_Double& theDistanceValue,
179 const bool theDistancePercent,
180 const bool theReverse)
182 // TODO(spo): check that thePart is not empty
183 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
184 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
187 //==================================================================================================
188 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
189 const ModelHighAPI_Selection& theObject1,
190 const ModelHighAPI_Selection& theObject2)
192 // TODO(spo): check that thePart is not empty
193 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
194 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));