Salome HOME
Update copyrights
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Factory.cpp
1 // Copyright (C) 2014-2019  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
18 //
19
20 #include "SketcherPrs_Factory.h"
21
22 #include "SketcherPrs_Coincident.h"
23 #include "SketcherPrs_Collinear.h"
24 #include "SketcherPrs_Parallel.h"
25 #include "SketcherPrs_Perpendicular.h"
26 #include "SketcherPrs_Rigid.h"
27 #include "SketcherPrs_HVDirection.h"
28 #include "SketcherPrs_Equal.h"
29 #include "SketcherPrs_Tangent.h"
30 #include "SketcherPrs_Radius.h"
31 #include "SketcherPrs_LengthDimension.h"
32 #include "SketcherPrs_Middle.h"
33 #include "SketcherPrs_Mirror.h"
34 #include "SketcherPrs_Transformation.h"
35 #include "SketcherPrs_Angle.h"
36
37 // Macros for constraint presentation definition
38 #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \
39 AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
40                                        SketchPlugin_Sketch* theSketcher, \
41                                        AISObjectPtr thePrevious) \
42 { \
43   std::shared_ptr<GeomAPI_AISObject> anAISObj; \
44   if (CLASS::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) { \
45     if (thePrevious.get()) \
46       anAISObj = thePrevious; \
47     else { \
48       anAISObj = AISObjectPtr(new GeomAPI_AISObject()); \
49       Handle(CLASS) aPrs = new CLASS(theConstraint, theSketcher); \
50       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \
51     } \
52   } \
53   return anAISObj; \
54 }
55
56
57 CONSTRAINT_PRS_IMPL(collinearConstraint, SketcherPrs_Collinear);
58 CONSTRAINT_PRS_IMPL(parallelConstraint, SketcherPrs_Parallel);
59 CONSTRAINT_PRS_IMPL(perpendicularConstraint, SketcherPrs_Perpendicular);
60 CONSTRAINT_PRS_IMPL(rigidConstraint, SketcherPrs_Rigid);
61 CONSTRAINT_PRS_IMPL(equalConstraint, SketcherPrs_Equal);
62 CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent);
63 CONSTRAINT_PRS_IMPL(middleConstraint, SketcherPrs_Middle);
64 CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror);
65 CONSTRAINT_PRS_IMPL(coincidentConstraint, SketcherPrs_Coincident);
66
67
68
69 #define CONSTRAINT2_PRS_IMPL(NAME, CLASS) \
70 AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
71                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane, \
72                                        AISObjectPtr thePrevious) \
73 { \
74   std::shared_ptr<GeomAPI_AISObject> anAISObj; \
75   if (CLASS::IsReadyToDisplay(theConstraint, thePlane)) { \
76     if (thePrevious.get()) \
77       anAISObj = thePrevious; \
78     else { \
79       anAISObj = AISObjectPtr(new GeomAPI_AISObject()); \
80       Handle(CLASS) aPrs = new CLASS(theConstraint, thePlane); \
81       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \
82     } \
83   } \
84   return anAISObj; \
85 }
86
87
88 CONSTRAINT2_PRS_IMPL(angleConstraint, SketcherPrs_Angle);
89 CONSTRAINT2_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
90 CONSTRAINT2_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
91
92 // Non-standard constraints definition
93 AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint,
94   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
95 {
96   std::shared_ptr<GeomAPI_AISObject> anAISObj;
97   if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) {
98     if (thePrevious.get())
99       anAISObj = thePrevious;
100     else {
101       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
102       Handle(SketcherPrs_HVDirection) aPrs =
103         new SketcherPrs_HVDirection(theConstraint, theSketcher, true);
104       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
105     }
106   }
107   return anAISObj;
108 }
109
110 AISObjectPtr SketcherPrs_Factory::verticalConstraint(ModelAPI_Feature* theConstraint,
111   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
112 {
113   std::shared_ptr<GeomAPI_AISObject> anAISObj;
114   if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) {
115     if (thePrevious.get())
116       anAISObj = thePrevious;
117     else {
118       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
119       Handle(SketcherPrs_HVDirection) aPrs =
120         new SketcherPrs_HVDirection(theConstraint, theSketcher, false);
121       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
122     }
123   }
124   return anAISObj;
125 }
126
127 AISObjectPtr SketcherPrs_Factory::translateConstraint(ModelAPI_Feature* theConstraint,
128   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
129 {
130   std::shared_ptr<GeomAPI_AISObject> anAISObj;
131   if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint,
132     theSketcher->coordinatePlane())) {
133     if (thePrevious.get())
134       anAISObj = thePrevious;
135     else {
136       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
137       Handle(SketcherPrs_Transformation) aPrs =
138         new SketcherPrs_Transformation(theConstraint, theSketcher, true);
139       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
140     }
141   }
142   return anAISObj;
143 }
144
145 AISObjectPtr SketcherPrs_Factory::rotateConstraint(ModelAPI_Feature* theConstraint,
146   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
147 {
148   std::shared_ptr<GeomAPI_AISObject> anAISObj;
149   if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint,
150     theSketcher->coordinatePlane())) {
151     if (thePrevious.get())
152       anAISObj = thePrevious;
153     else {
154       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
155       Handle(SketcherPrs_Transformation) aPrs =
156         new SketcherPrs_Transformation(theConstraint, theSketcher, false);
157       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
158     }
159   }
160   return anAISObj;
161 }