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());
43 data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
44 data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
45 data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
46 data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
48 data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
49 data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
51 data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
52 data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
54 data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
55 data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());
57 string("creation_method")->setValue("by_xyz");
60 //==================================================================================================
61 void ConstructionPlugin_Point::execute()
63 GeomShapePtr aShape = createByXYZ();
64 /* GeomShapePtr aShape;
66 std::string aCreationMethod = string(CREATION_METHOD())->value();
67 if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
68 aShape = createByXYZ();
69 } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
70 aShape = createByDistanceOnEdge();
71 } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
72 aShape = createByProjection();
73 } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
74 aShape = createByLinesIntersection();
75 } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
76 aShape = createByLineAndPlaneIntersection();
83 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
84 aConstr->setShape(aShape);
88 //==================================================================================================
89 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
91 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
93 bool isCustomized = theDefaultPrs.get() != NULL &&
94 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
95 //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
99 //==================================================================================================
100 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
102 return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
107 //==================================================================================================
108 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
111 AttributeSelectionPtr anEdgeSelection = selection(EDGE());
112 GeomShapePtr aShape = anEdgeSelection->value();
114 aShape = anEdgeSelection->context()->shape();
116 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
118 // Get distance value and percent flag.
119 double aValue = real(DISTANCE_VALUE())->value();
120 bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
123 bool anIsReverse = boolean(REVERSE())->value();
125 return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
128 //==================================================================================================
129 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
132 AttributeSelectionPtr aPointSelection = selection(POINT());
133 GeomShapePtr aPointShape = aPointSelection->value();
134 if(!aPointShape.get()) {
135 aPointShape = aPointSelection->context()->shape();
137 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
140 AttributeSelectionPtr aPlaneSelection = selection(PLANE());
141 GeomShapePtr aPlaneShape = aPlaneSelection->value();
142 if(!aPlaneShape.get()) {
143 aPlaneShape = aPlaneSelection->context()->shape();
145 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
147 return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
150 //==================================================================================================
151 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
154 AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
155 GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
156 if(!aFirstLineShape.get()) {
157 aFirstLineShape = aFirstLineSelection->context()->shape();
159 std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
162 AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
163 GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
164 if(!aSecondLineShape.get()) {
165 aSecondLineShape = aSecondLineSelection->context()->shape();
167 std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
169 return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
172 //==================================================================================================
173 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
176 AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
177 GeomShapePtr aLineShape = aLineSelection->value();
178 if(!aLineShape.get()) {
179 aLineShape = aLineSelection->context()->shape();
181 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
184 AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
185 GeomShapePtr aPlaneShape = aPlaneSelection->value();
186 if(!aPlaneShape.get()) {
187 aPlaneShape = aPlaneSelection->context()->shape();
189 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
191 return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);