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