]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionPlugin/ConstructionPlugin_Point.cpp
Salome HOME
Temporary commented modifications for point
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Point.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ConstructionPlugin_Point.cxx
4 // Created:     27 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "ConstructionPlugin_Point.h"
8
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>
14
15 #include <GeomAlgoAPI_PointBuilder.h>
16
17 #include <GeomAPI_Edge.h>
18 #include <GeomAPI_Pnt.h>
19 #include <GeomAPI_Vertex.h>
20
21 //==================================================================================================
22 ConstructionPlugin_Point::ConstructionPlugin_Point()
23 {
24 }
25
26 //==================================================================================================
27 const std::string& ConstructionPlugin_Point::getKind()
28 {
29   static std::string MY_KIND = ConstructionPlugin_Point::ID();
30   return MY_KIND;
31 }
32
33 //==================================================================================================
34 void ConstructionPlugin_Point::initAttributes()
35 {
36   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
37
38   data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
39   data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
40   data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
41
42 /*
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());
47
48   data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
49   data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
50
51   data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
52   data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
53
54   data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
55   data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());
56 */
57   string("creation_method")->setValue("by_xyz");
58 }
59
60 //==================================================================================================
61 void ConstructionPlugin_Point::execute()
62 {
63   GeomShapePtr aShape = createByXYZ();
64 /*  GeomShapePtr aShape;
65
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();
77   }
78   */
79   if(!aShape.get()) {
80     return;
81   }
82
83   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
84   aConstr->setShape(aShape);
85   setResult(aConstr);
86 }
87
88 //==================================================================================================
89 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
90                                                      AISObjectPtr thePrs,
91                                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
92 {
93   bool isCustomized = theDefaultPrs.get() != NULL &&
94                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
95   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
96   return true;
97 }
98
99 //==================================================================================================
100 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
101 {
102   return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
103                                           real(Y())->value(),
104                                           real(Z())->value());
105 }
106
107 //==================================================================================================
108 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
109 {
110   // Get edge.
111   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
112   GeomShapePtr aShape = anEdgeSelection->value();
113   if(!aShape.get()) {
114     aShape = anEdgeSelection->context()->shape();
115   }
116   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
117
118   // Get distance value and percent flag.
119   double aValue = real(DISTANCE_VALUE())->value();
120   bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
121
122   // Get reverse flag.
123   bool anIsReverse = boolean(REVERSE())->value();
124
125   return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
126 }
127
128 //==================================================================================================
129 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
130 {
131   // Get point.
132   AttributeSelectionPtr aPointSelection = selection(POINT());
133   GeomShapePtr aPointShape = aPointSelection->value();
134   if(!aPointShape.get()) {
135     aPointShape = aPointSelection->context()->shape();
136   }
137   std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
138
139   // Get plane.
140   AttributeSelectionPtr aPlaneSelection = selection(PLANE());
141   GeomShapePtr aPlaneShape = aPlaneSelection->value();
142   if(!aPlaneShape.get()) {
143     aPlaneShape = aPlaneSelection->context()->shape();
144   }
145   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
146
147   return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
148 }
149
150 //==================================================================================================
151 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
152 {
153   // Get first line.
154   AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
155   GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
156   if(!aFirstLineShape.get()) {
157     aFirstLineShape = aFirstLineSelection->context()->shape();
158   }
159   std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
160
161   // Get second line.
162   AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
163   GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
164   if(!aSecondLineShape.get()) {
165     aSecondLineShape = aSecondLineSelection->context()->shape();
166   }
167   std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
168
169   return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
170 }
171
172 //==================================================================================================
173 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
174 {
175   // Get line.
176   AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
177   GeomShapePtr aLineShape = aLineSelection->value();
178   if(!aLineShape.get()) {
179     aLineShape = aLineSelection->context()->shape();
180   }
181   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
182
183   // Get plane.
184   AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
185   GeomShapePtr aPlaneShape = aPlaneSelection->value();
186   if(!aPlaneShape.get()) {
187     aPlaneShape = aPlaneSelection->context()->shape();
188   }
189   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
190
191   return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);
192 }