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