1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketcherPrs_Factory.h"
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"
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) \
43 std::shared_ptr<GeomAPI_AISObject> anAISObj; \
44 if (CLASS::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) { \
45 if (thePrevious.get()) \
46 anAISObj = thePrevious; \
48 anAISObj = AISObjectPtr(new GeomAPI_AISObject()); \
49 Handle(CLASS) aPrs = new CLASS(theConstraint, theSketcher); \
50 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \
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);
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) \
74 std::shared_ptr<GeomAPI_AISObject> anAISObj; \
75 if (CLASS::IsReadyToDisplay(theConstraint, thePlane)) { \
76 if (thePrevious.get()) \
77 anAISObj = thePrevious; \
79 anAISObj = AISObjectPtr(new GeomAPI_AISObject()); \
80 Handle(CLASS) aPrs = new CLASS(theConstraint, thePlane); \
81 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \
88 CONSTRAINT2_PRS_IMPL(angleConstraint, SketcherPrs_Angle);
89 CONSTRAINT2_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
90 CONSTRAINT2_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
92 // Non-standard constraints definition
93 AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint,
94 SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
96 std::shared_ptr<GeomAPI_AISObject> anAISObj;
97 if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) {
98 if (thePrevious.get())
99 anAISObj = thePrevious;
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));
110 AISObjectPtr SketcherPrs_Factory::verticalConstraint(ModelAPI_Feature* theConstraint,
111 SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
113 std::shared_ptr<GeomAPI_AISObject> anAISObj;
114 if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, theSketcher->coordinatePlane())) {
115 if (thePrevious.get())
116 anAISObj = thePrevious;
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));
127 AISObjectPtr SketcherPrs_Factory::translateConstraint(ModelAPI_Feature* theConstraint,
128 SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
130 std::shared_ptr<GeomAPI_AISObject> anAISObj;
131 if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint,
132 theSketcher->coordinatePlane())) {
133 if (thePrevious.get())
134 anAISObj = thePrevious;
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));
145 AISObjectPtr SketcherPrs_Factory::rotateConstraint(ModelAPI_Feature* theConstraint,
146 SketchPlugin_Sketch* theSketcher, AISObjectPtr thePrevious)
148 std::shared_ptr<GeomAPI_AISObject> anAISObj;
149 if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint,
150 theSketcher->coordinatePlane())) {
151 if (thePrevious.get())
152 anAISObj = thePrevious;
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));