b311480e |
1 | // Created on: 1996-12-13 |
2 | // Created by: Jean-Pierre COMBE |
3 | // Copyright (c) 1996-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
b8ddfc2f |
22 | //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor. |
7fd59977 |
23 | |
24 | #define OCC218 //SAV using DsgPrs_XYZAxisPresentation to draw axes. |
b311480e |
25 | // + X/YAxis() returns AIS_Line instead of AIS_Axis |
26 | // + (-1) selection mode token into account |
27 | // (SAMTECH specific) |
7fd59977 |
28 | |
29 | #ifdef OCC218 |
30 | #include <DsgPrs_XYZAxisPresentation.hxx> |
31 | #include <AIS_Line.hxx> |
32 | #include <Geom_Line.hxx> |
33 | #endif |
34 | |
35 | #include <AIS_PlaneTrihedron.ixx> |
36 | |
37 | #include <DsgPrs_DatumPrs.hxx> |
38 | #include <SelectMgr_EntityOwner.hxx> |
39 | #include <Select3D_SensitiveSegment.hxx> |
40 | #include <Select3D_SensitivePoint.hxx> |
41 | #include <Geom_Axis1Placement.hxx> |
42 | #include <Geom_Axis2Placement.hxx> |
43 | #include <Geom_CartesianPoint.hxx> |
44 | #include <gp_Ax2.hxx> |
45 | #include <gp_Pln.hxx> |
46 | #include <gp_Pnt.hxx> |
47 | #include <gp_Vec.hxx> |
48 | #include <Prs3d_Drawer.hxx> |
49 | #include <Prs3d_LineAspect.hxx> |
50 | #include <Prs3d_DatumAspect.hxx> |
51 | #include <Graphic3d_AspectLine3d.hxx> |
52 | #include <Graphic3d_Structure.hxx> |
53 | #include <Graphic3d_MaterialAspect.hxx> |
54 | #include <Graphic3d_AspectFillArea3d.hxx> |
55 | #include <Aspect_TypeOfLine.hxx> |
56 | #include <AIS_Drawer.hxx> |
57 | #include <UnitsAPI.hxx> |
58 | #include <TColgp_Array1OfPnt.hxx> |
59 | |
60 | #include <Select3D_SensitiveFace.hxx> |
61 | |
62 | #define OCC10 |
63 | |
64 | void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer); |
65 | |
66 | //======================================================================= |
67 | //function : AIS_PlaneTrihedron |
68 | //purpose : |
69 | //======================================================================= |
70 | AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane) |
71 | :myPlane(aPlane) |
72 | { |
73 | Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect(); |
74 | //POP Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH"); |
75 | Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm"); |
76 | DA->SetAxisLength(aLength,aLength,aLength); |
77 | Quantity_NameOfColor col = Quantity_NOC_ROYALBLUE1; |
78 | DA->FirstAxisAspect()->SetColor(col); |
79 | DA->SecondAxisAspect()->SetColor(col); |
80 | DA->SetDrawFirstAndSecondAxis(Standard_True); |
81 | DA->SetDrawThirdAxis(Standard_False); |
81bba717 |
82 | myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified |
7fd59977 |
83 | myShapes[0] = Position(); |
84 | myShapes[1] = XAxis(); |
85 | myShapes[2] = YAxis(); |
86 | |
87 | #ifdef OCC218 |
88 | myXLabel = TCollection_AsciiString( "X" ); |
89 | myYLabel = TCollection_AsciiString( "Y" ); |
90 | #endif |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : Component |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | Handle(Geom_Plane) AIS_PlaneTrihedron::Component() |
99 | { |
100 | return myPlane; |
101 | } |
102 | |
103 | |
104 | //======================================================================= |
105 | //function : SetComponent |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane) |
110 | { |
111 | myPlane = aPlane; |
112 | } |
113 | |
114 | //======================================================================= |
115 | //function : XAxis |
116 | //purpose : |
117 | //======================================================================= |
118 | #ifdef OCC218 |
119 | Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const |
120 | { |
121 | Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis()); |
122 | Handle(AIS_Line) aLine = new AIS_Line (aGLine); |
123 | aLine->SetColor(Quantity_NOC_ROYALBLUE1); |
124 | return aLine; |
125 | } |
126 | #else |
127 | Handle(AIS_Axis) AIS_PlaneTrihedron::XAxis() const |
128 | { |
129 | Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().XAxis()); |
130 | Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1); |
131 | anAxis->SetTypeOfAxis(AIS_TOAX_XAxis); |
132 | return anAxis; |
133 | } |
134 | #endif |
135 | |
136 | //======================================================================= |
137 | //function : YAxis |
138 | //purpose : |
139 | //======================================================================= |
140 | #ifdef OCC218 |
141 | Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const |
142 | { |
143 | Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis()); |
144 | Handle(AIS_Line) aLine = new AIS_Line (aGLine); |
145 | aLine->SetColor(Quantity_NOC_ROYALBLUE1); |
146 | return aLine; |
147 | } |
148 | #else |
149 | Handle(AIS_Axis) AIS_PlaneTrihedron::YAxis() const |
150 | { |
151 | Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().YAxis()); |
152 | Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1); |
153 | anAxis->SetTypeOfAxis(AIS_TOAX_YAxis); |
154 | return anAxis; |
155 | } |
156 | #endif |
157 | |
158 | //======================================================================= |
159 | //function : Position |
160 | //purpose : |
161 | //======================================================================= |
162 | Handle(AIS_Point) AIS_PlaneTrihedron::Position() const |
163 | { |
164 | gp_Pnt aPnt = myPlane->Pln().Location(); |
165 | Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt); |
166 | Handle(AIS_Point) aPt = new AIS_Point (aPoint); |
167 | return aPt; |
168 | } |
169 | |
170 | #ifdef OCC10 |
171 | void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) { |
172 | myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength); |
173 | SetToUpdate(); |
174 | } |
175 | |
176 | Standard_Real AIS_PlaneTrihedron::GetLength() const { |
177 | return myDrawer->DatumAspect()->FirstAxisLength(); |
178 | } |
179 | #endif |
180 | |
181 | //======================================================================= |
182 | //function : Compute |
183 | //purpose : |
184 | //======================================================================= |
185 | void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&, |
186 | const Handle(Prs3d_Presentation)& aPresentation, |
187 | const Standard_Integer) |
188 | { |
189 | aPresentation->Clear(); |
190 | aPresentation->SetDisplayPriority(5); |
191 | #ifndef OCC218 |
192 | DsgPrs_DatumPrs::Add(aPresentation,myPlane->Position().Ax2(),myDrawer); |
193 | #else |
194 | // drawing axis in X direction |
195 | gp_Pnt first, last; |
196 | Standard_Real value = myDrawer->DatumAspect()->FirstAxisLength(); |
197 | gp_Dir xDir = myPlane->Position().Ax2().XDirection(); |
198 | |
199 | gp_Pnt orig = myPlane->Position().Ax2().Location(); |
200 | Quantity_Length xo,yo,zo,x,y,z; |
201 | orig.Coord( xo, yo, zo ); |
202 | xDir.Coord( x, y, z ); |
203 | first.SetCoord( xo, yo, zo ); |
204 | last.SetCoord( xo + x * value, yo + y * value, zo + z * value ); |
205 | |
206 | DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last ); |
207 | |
208 | // drawing axis in Y direction |
209 | value = myDrawer->DatumAspect()->SecondAxisLength(); |
210 | gp_Dir yDir = myPlane->Position().Ax2().YDirection(); |
211 | |
212 | yDir.Coord( x, y, z ); |
213 | last.SetCoord( xo + x * value, yo + y * value, zo + z * value ); |
214 | DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last ); |
215 | |
216 | #endif |
217 | aPresentation->SetInfiniteState (Standard_True); |
218 | } |
219 | |
220 | void AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation) |
221 | { |
222 | // Standard_NotImplemented::Raise("AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)"); |
223 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ; |
224 | } |
225 | |
226 | //======================================================================= |
227 | //function : ComputeSelection |
228 | //purpose : |
229 | //======================================================================= |
230 | |
231 | void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
232 | const Standard_Integer aMode) |
233 | { |
234 | Standard_Integer Prior; |
235 | Handle(SelectMgr_EntityOwner) eown; |
236 | TColgp_Array1OfPnt PP(1,4),PO(1,4); |
237 | // ExtremityPoints(PP); |
238 | ExtremityPoints(PP,myPlane,myDrawer); |
239 | switch (aMode) { |
240 | case 0: |
241 | { // triedre complet |
242 | Prior = 5; |
243 | // gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2()); |
244 | // gp_Pnt p1 = theax.Location(); |
245 | |
246 | eown = new SelectMgr_EntityOwner(this,Prior); |
247 | for (Standard_Integer i=1; i<=2;i++) |
248 | aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1))); |
249 | |
250 | break; |
251 | } |
252 | case 1: |
253 | { //origine |
254 | Prior = 8; |
255 | eown= new SelectMgr_EntityOwner(myShapes[0],Prior); |
256 | aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location())); |
257 | |
258 | break; |
259 | } |
260 | case 2: |
261 | { //axes ... priorite 7 |
262 | Prior = 7; |
263 | for (Standard_Integer i=1; i<=2;i++){ |
264 | eown= new SelectMgr_EntityOwner(myShapes[i],Prior); |
265 | aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1))); |
266 | |
267 | } |
268 | break; |
269 | } |
270 | #ifdef OCC218 |
271 | case -1: |
272 | { |
273 | Prior = 5; |
274 | aSelection->Clear(); |
275 | break; |
276 | } |
277 | #endif |
278 | } |
279 | } |
280 | |
281 | void AIS_PlaneTrihedron::SetColor(const Quantity_NameOfColor aCol) |
7fd59977 |
282 | { |
283 | SetColor(Quantity_Color(aCol)); |
284 | } |
285 | |
286 | void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol) |
7fd59977 |
287 | { |
288 | hasOwnColor=Standard_True; |
289 | myOwnColor = aCol; |
290 | myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol); |
291 | myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol); |
292 | } |
293 | |
7fd59977 |
294 | |
295 | void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&, |
296 | const Handle(Prs3d_Presentation)&) |
297 | { |
298 | } |
299 | |
300 | |
301 | //======================================================================= |
302 | //function : ExtremityPoints |
303 | //purpose : to avoid warning |
304 | //======================================================================= |
305 | //void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const |
306 | void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer ) |
307 | { |
308 | // gp_Ax2 theax(myPlane->Ax2()); |
309 | gp_Ax2 theax(myPlane->Position().Ax2()); |
310 | PP(1) = theax.Location(); |
311 | |
312 | Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength(); |
313 | gp_Vec vec = theax.XDirection(); |
314 | vec *= len; |
315 | PP(2) = PP(1).Translated(vec); |
316 | |
317 | len = myDrawer->DatumAspect()->SecondAxisLength(); |
318 | vec = theax.YDirection(); |
319 | vec *= len; |
320 | PP(3) = PP(1).Translated(vec); |
321 | |
322 | } |
323 | |
324 | //======================================================================= |
325 | //function : AcceptDisplayMode |
326 | //purpose : |
327 | //======================================================================= |
328 | Standard_Boolean AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const |
329 | {return aMode == 0;} |
330 | |