]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Factory.cpp
Salome HOME
Fix for the issue #3116 : Create Edge, Wire all-in is missed for feature in Partset
[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 CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
67 CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle);
68 CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
69
70 // Non-standard constraints definition
71 AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint,
72   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
73 {
74   std::shared_ptr<GeomAPI_AISObject> anAISObj;
75   if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) {
76     if (thePrevious.get())
77       anAISObj = thePrevious;
78     else {
79       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
80       Handle(SketcherPrs_HVDirection) aPrs =
81         new SketcherPrs_HVDirection(theConstraint, theSketcher, true);
82       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
83     }
84   }
85   return anAISObj;
86 }
87
88 AISObjectPtr SketcherPrs_Factory::verticalConstraint(ModelAPI_Feature* theConstraint,
89   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
90 {
91   std::shared_ptr<GeomAPI_AISObject> anAISObj;
92   if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) {
93     if (thePrevious.get())
94       anAISObj = thePrevious;
95     else {
96       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
97       Handle(SketcherPrs_HVDirection) aPrs =
98         new SketcherPrs_HVDirection(theConstraint, theSketcher, false);
99       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
100     }
101   }
102   return anAISObj;
103 }
104
105 AISObjectPtr SketcherPrs_Factory::translateConstraint(ModelAPI_Feature* theConstraint,
106   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
107 {
108   std::shared_ptr<GeomAPI_AISObject> anAISObj;
109   if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint,
110     theSketcher->coordinatePlane())) {
111     if (thePrevious.get())
112       anAISObj = thePrevious;
113     else {
114       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
115       Handle(SketcherPrs_Transformation) aPrs =
116         new SketcherPrs_Transformation(theConstraint, theSketcher, true);
117       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
118     }
119   }
120   return anAISObj;
121 }
122
123 AISObjectPtr SketcherPrs_Factory::rotateConstraint(ModelAPI_Feature* theConstraint,
124   SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
125 {
126   std::shared_ptr<GeomAPI_AISObject> anAISObj;
127   if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint,
128     theSketcher->coordinatePlane())) {
129     if (thePrevious.get())
130       anAISObj = thePrevious;
131     else {
132       anAISObj = AISObjectPtr(new GeomAPI_AISObject());
133       Handle(SketcherPrs_Transformation) aPrs =
134         new SketcherPrs_Transformation(theConstraint, theSketcher, false);
135       anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
136     }
137   }
138   return anAISObj;
139 }