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()
60 GeomShapePtr aShape = createByXYZ();
62 /*GeomShapePtr aShape;
64 std::string aCreationMethod = string(CREATION_METHOD())->value();
65 if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
66 aShape = createByXYZ();
67 } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
68 aShape = createByDistanceOnEdge();
69 } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
70 aShape = createByProjection();
71 } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
72 aShape = createByLinesIntersection();
73 } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
74 aShape = createByLineAndPlaneIntersection();
81 std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
82 aConstr->setShape(aShape);
86 //==================================================================================================
87 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
89 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
91 bool isCustomized = theDefaultPrs.get() != NULL &&
92 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
93 //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
97 //==================================================================================================
98 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
100 return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
105 /*//==================================================================================================
106 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
109 AttributeSelectionPtr anEdgeSelection = selection(EDGE());
110 GeomShapePtr aShape = anEdgeSelection->value();
112 aShape = anEdgeSelection->context()->shape();
114 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
116 // Get distance value and percent flag.
117 double aValue = real(DISTANCE_VALUE())->value();
118 bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
121 bool anIsReverse = boolean(REVERSE())->value();
123 return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
126 //==================================================================================================
127 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
130 AttributeSelectionPtr aPointSelection = selection(POINT());
131 GeomShapePtr aPointShape = aPointSelection->value();
132 if(!aPointShape.get()) {
133 aPointShape = aPointSelection->context()->shape();
135 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
138 AttributeSelectionPtr aPlaneSelection = selection(PLANE());
139 GeomShapePtr aPlaneShape = aPlaneSelection->value();
140 if(!aPlaneShape.get()) {
141 aPlaneShape = aPlaneSelection->context()->shape();
143 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
145 return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
148 //==================================================================================================
149 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
152 AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
153 GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
154 if(!aFirstLineShape.get()) {
155 aFirstLineShape = aFirstLineSelection->context()->shape();
157 std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
160 AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
161 GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
162 if(!aSecondLineShape.get()) {
163 aSecondLineShape = aSecondLineSelection->context()->shape();
165 std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
167 return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
170 //==================================================================================================
171 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
174 AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
175 GeomShapePtr aLineShape = aLineSelection->value();
176 if(!aLineShape.get()) {
177 aLineShape = aLineSelection->context()->shape();
179 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
182 AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
183 GeomShapePtr aPlaneShape = aPlaneSelection->value();
184 if(!aPlaneShape.get()) {
185 aPlaneShape = aPlaneSelection->context()->shape();
187 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
189 return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);