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& theDistanceValue,
52 const bool theDistancePercent,
53 const bool theReverse)
54 : ModelHighAPI_Interface(theFeature)
57 setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, 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);
71 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
72 // If first object is vertex and second object is face then set by projection.
73 setByProjection(theObject1, theObject2);
74 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
75 // If both objects are edges then set by lines intersection.
76 setByLinesIntersection(theObject1, theObject2);
77 } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
78 // If first object is edge and second object is face then set by line and plane intersection.
79 setByLineAndPlaneIntersection(theObject1, theObject2);
84 //==================================================================================================
85 ConstructionAPI_Point::~ConstructionAPI_Point()
90 //==================================================================================================
91 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
92 const ModelHighAPI_Double& theY,
93 const ModelHighAPI_Double& theZ)
95 //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
96 fillAttribute(theX, myx);
97 fillAttribute(theY, myy);
98 fillAttribute(theZ, myz);
103 /*//==================================================================================================
104 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
105 const ModelHighAPI_Double& theDistanceValue,
106 const bool theDistancePercent,
107 const bool theReverse)
109 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
110 fillAttribute(theEdge, myedge);
111 fillAttribute(theDistanceValue, mydistanceValue);
112 fillAttribute(theDistancePercent, mydistancePercent);
113 fillAttribute(theReverse, myreverse);
118 //==================================================================================================
119 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
120 const ModelHighAPI_Selection& theFace)
122 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
123 fillAttribute(theVertex, mypoint);
124 fillAttribute(theFace, myplane);
129 //==================================================================================================
130 void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
131 const ModelHighAPI_Selection& theEdge2)
133 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
134 fillAttribute(theEdge1, myfirstLine);
135 fillAttribute(theEdge2, mysecondLine);
140 //==================================================================================================
141 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
142 const ModelHighAPI_Selection& theFace)
144 fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
145 fillAttribute(theEdge, myintersectionLine);
146 fillAttribute(theFace, myintersectionPlane);
151 //==================================================================================================
152 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
154 // TODO: all types of points
156 FeaturePtr aBase = feature();
157 const std::string& aDocName = theDumper.name(aBase->document());
159 AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Point::X());
160 AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Point::Y());
161 AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Point::Z());
162 theDumper << aBase << " = model.addPoint(" << aDocName << ", "
163 << anAttrX << ", " << anAttrY << ", " << anAttrZ << ")" << std::endl;
166 //==================================================================================================
167 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
168 const ModelHighAPI_Double& theX,
169 const ModelHighAPI_Double& theY,
170 const ModelHighAPI_Double& theZ)
172 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
173 return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
176 /*//==================================================================================================
177 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
178 const ModelHighAPI_Selection& theEdge,
179 const ModelHighAPI_Double& theDistanceValue,
180 const bool theDistancePercent,
181 const bool theReverse)
183 // TODO(spo): check that thePart is not empty
184 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
185 return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
188 //==================================================================================================
189 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
190 const ModelHighAPI_Selection& theObject1,
191 const ModelHighAPI_Selection& theObject2)
193 // TODO(spo): check that thePart is not empty
194 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
195 return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));