b311480e |
1 | // Created on: 1996-12-13 |
2 | // Created by: Jean-Pierre COMBE |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
b311480e |
17 | // + X/YAxis() returns AIS_Line instead of AIS_Axis |
18 | // + (-1) selection mode token into account |
19 | // (SAMTECH specific) |
7fd59977 |
20 | |
42cf5bc1 |
21 | #include <AIS_InteractiveObject.hxx> |
7fd59977 |
22 | #include <AIS_Line.hxx> |
42cf5bc1 |
23 | #include <AIS_PlaneTrihedron.hxx> |
24 | #include <AIS_Point.hxx> |
25 | #include <Aspect_TypeOfLine.hxx> |
42cf5bc1 |
26 | #include <DsgPrs_XYZAxisPresentation.hxx> |
7fd59977 |
27 | #include <Geom_Axis1Placement.hxx> |
28 | #include <Geom_Axis2Placement.hxx> |
29 | #include <Geom_CartesianPoint.hxx> |
42cf5bc1 |
30 | #include <Geom_Line.hxx> |
31 | #include <Geom_Plane.hxx> |
7fd59977 |
32 | #include <gp_Ax2.hxx> |
33 | #include <gp_Pln.hxx> |
34 | #include <gp_Pnt.hxx> |
35 | #include <gp_Vec.hxx> |
42cf5bc1 |
36 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 |
37 | #include <Graphic3d_AspectLine3d.hxx> |
7fd59977 |
38 | #include <Graphic3d_MaterialAspect.hxx> |
42cf5bc1 |
39 | #include <Graphic3d_Structure.hxx> |
40 | #include <Prs3d_DatumAspect.hxx> |
41 | #include <Prs3d_Drawer.hxx> |
42 | #include <Prs3d_LineAspect.hxx> |
43 | #include <Prs3d_Presentation.hxx> |
42cf5bc1 |
44 | #include <Quantity_Color.hxx> |
45 | #include <Select3D_SensitivePoint.hxx> |
46 | #include <Select3D_SensitiveSegment.hxx> |
47 | #include <SelectMgr_EntityOwner.hxx> |
48 | #include <SelectMgr_Selection.hxx> |
49 | #include <Standard_Type.hxx> |
7fd59977 |
50 | #include <TColgp_Array1OfPnt.hxx> |
42cf5bc1 |
51 | #include <TCollection_AsciiString.hxx> |
52 | #include <UnitsAPI.hxx> |
7fd59977 |
53 | |
92efcf78 |
54 | IMPLEMENT_STANDARD_RTTIEXT(AIS_PlaneTrihedron,AIS_InteractiveObject) |
55 | |
7fd59977 |
56 | void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer); |
57 | |
58 | //======================================================================= |
59 | //function : AIS_PlaneTrihedron |
60 | //purpose : |
61 | //======================================================================= |
62 | AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane) |
63 | :myPlane(aPlane) |
64 | { |
65 | Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect(); |
66 | //POP Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH"); |
67 | Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm"); |
68 | DA->SetAxisLength(aLength,aLength,aLength); |
87432b82 |
69 | Quantity_Color col (Quantity_NOC_ROYALBLUE1); |
bc001a40 |
70 | DA->LineAspect(Prs3d_DP_XAxis)->SetColor(col); |
71 | DA->LineAspect(Prs3d_DP_YAxis)->SetColor(col); |
72 | DA->SetDrawDatumAxes(Prs3d_DA_XYAxis); |
81bba717 |
73 | myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified |
7fd59977 |
74 | myShapes[0] = Position(); |
75 | myShapes[1] = XAxis(); |
76 | myShapes[2] = YAxis(); |
77 | |
7fd59977 |
78 | myXLabel = TCollection_AsciiString( "X" ); |
79 | myYLabel = TCollection_AsciiString( "Y" ); |
7fd59977 |
80 | } |
81 | |
82 | //======================================================================= |
83 | //function : Component |
84 | //purpose : |
85 | //======================================================================= |
86 | |
87 | Handle(Geom_Plane) AIS_PlaneTrihedron::Component() |
88 | { |
89 | return myPlane; |
90 | } |
91 | |
92 | |
93 | //======================================================================= |
94 | //function : SetComponent |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane) |
99 | { |
100 | myPlane = aPlane; |
101 | } |
102 | |
103 | //======================================================================= |
104 | //function : XAxis |
105 | //purpose : |
106 | //======================================================================= |
7fd59977 |
107 | Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const |
108 | { |
109 | Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis()); |
110 | Handle(AIS_Line) aLine = new AIS_Line (aGLine); |
111 | aLine->SetColor(Quantity_NOC_ROYALBLUE1); |
112 | return aLine; |
113 | } |
7fd59977 |
114 | |
115 | //======================================================================= |
116 | //function : YAxis |
117 | //purpose : |
118 | //======================================================================= |
7fd59977 |
119 | Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const |
120 | { |
121 | Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis()); |
122 | Handle(AIS_Line) aLine = new AIS_Line (aGLine); |
123 | aLine->SetColor(Quantity_NOC_ROYALBLUE1); |
124 | return aLine; |
125 | } |
7fd59977 |
126 | |
127 | //======================================================================= |
128 | //function : Position |
129 | //purpose : |
130 | //======================================================================= |
131 | Handle(AIS_Point) AIS_PlaneTrihedron::Position() const |
132 | { |
133 | gp_Pnt aPnt = myPlane->Pln().Location(); |
134 | Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt); |
135 | Handle(AIS_Point) aPt = new AIS_Point (aPoint); |
136 | return aPt; |
137 | } |
138 | |
7fd59977 |
139 | void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) { |
140 | myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength); |
141 | SetToUpdate(); |
142 | } |
143 | |
144 | Standard_Real AIS_PlaneTrihedron::GetLength() const { |
bc001a40 |
145 | return myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis); |
7fd59977 |
146 | } |
7fd59977 |
147 | |
148 | //======================================================================= |
149 | //function : Compute |
150 | //purpose : |
151 | //======================================================================= |
152 | void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&, |
153 | const Handle(Prs3d_Presentation)& aPresentation, |
154 | const Standard_Integer) |
155 | { |
7fd59977 |
156 | aPresentation->SetDisplayPriority(5); |
7fd59977 |
157 | // drawing axis in X direction |
158 | gp_Pnt first, last; |
bc001a40 |
159 | Standard_Real value = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis); |
7fd59977 |
160 | gp_Dir xDir = myPlane->Position().Ax2().XDirection(); |
161 | |
162 | gp_Pnt orig = myPlane->Position().Ax2().Location(); |
ee2be2a8 |
163 | Standard_Real xo,yo,zo,x,y,z; |
7fd59977 |
164 | orig.Coord( xo, yo, zo ); |
165 | xDir.Coord( x, y, z ); |
166 | first.SetCoord( xo, yo, zo ); |
167 | last.SetCoord( xo + x * value, yo + y * value, zo + z * value ); |
168 | |
bc001a40 |
169 | DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last ); |
7fd59977 |
170 | |
171 | // drawing axis in Y direction |
bc001a40 |
172 | value = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_YAxis); |
7fd59977 |
173 | gp_Dir yDir = myPlane->Position().Ax2().YDirection(); |
174 | |
175 | yDir.Coord( x, y, z ); |
176 | last.SetCoord( xo + x * value, yo + y * value, zo + z * value ); |
bc001a40 |
177 | DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last ); |
7fd59977 |
178 | |
7fd59977 |
179 | aPresentation->SetInfiniteState (Standard_True); |
180 | } |
181 | |
7fd59977 |
182 | //======================================================================= |
183 | //function : ComputeSelection |
184 | //purpose : |
185 | //======================================================================= |
186 | |
187 | void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
188 | const Standard_Integer aMode) |
189 | { |
190 | Standard_Integer Prior; |
191 | Handle(SelectMgr_EntityOwner) eown; |
192 | TColgp_Array1OfPnt PP(1,4),PO(1,4); |
193 | // ExtremityPoints(PP); |
194 | ExtremityPoints(PP,myPlane,myDrawer); |
195 | switch (aMode) { |
196 | case 0: |
197 | { // triedre complet |
198 | Prior = 5; |
199 | // gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2()); |
200 | // gp_Pnt p1 = theax.Location(); |
201 | |
202 | eown = new SelectMgr_EntityOwner(this,Prior); |
203 | for (Standard_Integer i=1; i<=2;i++) |
204 | aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1))); |
205 | |
206 | break; |
207 | } |
208 | case 1: |
209 | { //origine |
210 | Prior = 8; |
543a9964 |
211 | const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity |
212 | eown= new SelectMgr_EntityOwner(anObj,Prior); |
7fd59977 |
213 | aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location())); |
214 | |
215 | break; |
216 | } |
217 | case 2: |
218 | { //axes ... priorite 7 |
219 | Prior = 7; |
220 | for (Standard_Integer i=1; i<=2;i++){ |
543a9964 |
221 | const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity |
222 | eown= new SelectMgr_EntityOwner(anObj,Prior); |
7fd59977 |
223 | aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1))); |
224 | |
225 | } |
226 | break; |
227 | } |
7fd59977 |
228 | case -1: |
229 | { |
230 | Prior = 5; |
231 | aSelection->Clear(); |
232 | break; |
233 | } |
7fd59977 |
234 | } |
235 | } |
236 | |
7fd59977 |
237 | void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol) |
7fd59977 |
238 | { |
239 | hasOwnColor=Standard_True; |
f838dac4 |
240 | myDrawer->SetColor (aCol); |
bc001a40 |
241 | myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis)->SetColor(aCol); |
242 | myDrawer->DatumAspect()->LineAspect(Prs3d_DP_YAxis)->SetColor(aCol); |
226fce20 |
243 | SynchronizeAspects(); |
7fd59977 |
244 | } |
245 | |
7fd59977 |
246 | //======================================================================= |
247 | //function : ExtremityPoints |
248 | //purpose : to avoid warning |
249 | //======================================================================= |
250 | //void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const |
251 | void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer ) |
252 | { |
253 | // gp_Ax2 theax(myPlane->Ax2()); |
254 | gp_Ax2 theax(myPlane->Position().Ax2()); |
255 | PP(1) = theax.Location(); |
256 | |
bc001a40 |
257 | Standard_Real len = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis); |
7fd59977 |
258 | gp_Vec vec = theax.XDirection(); |
259 | vec *= len; |
260 | PP(2) = PP(1).Translated(vec); |
261 | |
bc001a40 |
262 | len = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_YAxis); |
7fd59977 |
263 | vec = theax.YDirection(); |
264 | vec *= len; |
265 | PP(3) = PP(1).Translated(vec); |
266 | |
267 | } |
268 | |
269 | //======================================================================= |
270 | //function : AcceptDisplayMode |
271 | //purpose : |
272 | //======================================================================= |
273 | Standard_Boolean AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const |
274 | {return aMode == 0;} |
275 | |