1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ConstructionPlugin_Point.cxx
4 // Created: 27 Mar 2014
5 // Author: Mikhail PONIKAROV
7 #include "ConstructionPlugin_Point.h"
9 #include <ModelAPI_AttributeBoolean.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeString.h>
13 #include <ModelAPI_ResultConstruction.h>
15 #include <GeomAlgoAPI_PointBuilder.h>
17 #include <GeomAPI_Edge.h>
18 #include <GeomAPI_Pnt.h>
19 #include <GeomAPI_Vertex.h>
21 //==================================================================================================
22 ConstructionPlugin_Point::ConstructionPlugin_Point()
26 //==================================================================================================
27 const std::string& ConstructionPlugin_Point::getKind()
29 static std::string MY_KIND = ConstructionPlugin_Point::ID();
33 //==================================================================================================
34 void ConstructionPlugin_Point::initAttributes()
36 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
38 data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
39 data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
40 data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
42 data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
43 data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
44 data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
45 data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
47 data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
48 data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
50 data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
51 data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
53 data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
54 data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());
57 //==================================================================================================
58 void ConstructionPlugin_Point::execute()
62 std::string aCreationMethod = string(CREATION_METHOD())->value();
63 if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
64 aShape = createByXYZ();
65 } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
66 aShape = createByDistanceOnEdge();
67 } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
68 aShape = createByProjection();
69 } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
70 aShape = createByLinesIntersection();
71 } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
72 aShape = createByLineAndPlaneIntersection();
79 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
80 aConstr->setShape(aShape);
84 //==================================================================================================
85 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
87 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
89 bool isCustomized = theDefaultPrs.get() != NULL &&
90 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
91 //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
95 //==================================================================================================
96 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
98 return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
103 //==================================================================================================
104 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
107 AttributeSelectionPtr anEdgeSelection = selection(EDGE());
108 GeomShapePtr aShape = anEdgeSelection->value();
110 aShape = anEdgeSelection->context()->shape();
112 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
114 // Get distance value and percent flag.
115 double aValue = real(DISTANCE_VALUE())->value();
116 bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
119 bool anIsReverse = boolean(REVERSE())->value();
121 return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
124 //==================================================================================================
125 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
128 AttributeSelectionPtr aPointSelection = selection(POINT());
129 GeomShapePtr aPointShape = aPointSelection->value();
130 if(!aPointShape.get()) {
131 aPointShape = aPointSelection->context()->shape();
133 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
136 AttributeSelectionPtr aPlaneSelection = selection(PLANE());
137 GeomShapePtr aPlaneShape = aPlaneSelection->value();
138 if(!aPlaneShape.get()) {
139 aPlaneShape = aPlaneSelection->context()->shape();
141 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
143 return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
146 //==================================================================================================
147 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
150 AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
151 GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
152 if(!aFirstLineShape.get()) {
153 aFirstLineShape = aFirstLineSelection->context()->shape();
155 std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
158 AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
159 GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
160 if(!aSecondLineShape.get()) {
161 aSecondLineShape = aSecondLineSelection->context()->shape();
163 std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
165 return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
168 //==================================================================================================
169 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
172 AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
173 GeomShapePtr aLineShape = aLineSelection->value();
174 if(!aLineShape.get()) {
175 aLineShape = aLineSelection->context()->shape();
177 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
180 AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
181 GeomShapePtr aPlaneShape = aPlaneSelection->value();
182 if(!aPlaneShape.get()) {
183 aPlaneShape = aPlaneSelection->context()->shape();
185 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
187 return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);