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