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> |
32 | #include <Geom_Transformation.hxx> |
7fd59977 |
33 | #include <gp_Ax2.hxx> |
34 | #include <gp_Pln.hxx> |
35 | #include <gp_Pnt.hxx> |
36 | #include <gp_Vec.hxx> |
42cf5bc1 |
37 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 |
38 | #include <Graphic3d_AspectLine3d.hxx> |
7fd59977 |
39 | #include <Graphic3d_MaterialAspect.hxx> |
42cf5bc1 |
40 | #include <Graphic3d_Structure.hxx> |
41 | #include <Prs3d_DatumAspect.hxx> |
42 | #include <Prs3d_Drawer.hxx> |
43 | #include <Prs3d_LineAspect.hxx> |
44 | #include <Prs3d_Presentation.hxx> |
45 | #include <Prs3d_Projector.hxx> |
46 | #include <Quantity_Color.hxx> |
47 | #include <Select3D_SensitivePoint.hxx> |
48 | #include <Select3D_SensitiveSegment.hxx> |
49 | #include <SelectMgr_EntityOwner.hxx> |
50 | #include <SelectMgr_Selection.hxx> |
51 | #include <Standard_Type.hxx> |
7fd59977 |
52 | #include <TColgp_Array1OfPnt.hxx> |
42cf5bc1 |
53 | #include <TCollection_AsciiString.hxx> |
54 | #include <UnitsAPI.hxx> |
7fd59977 |
55 | |
92efcf78 |
56 | IMPLEMENT_STANDARD_RTTIEXT(AIS_PlaneTrihedron,AIS_InteractiveObject) |
57 | |
7fd59977 |
58 | void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer); |
59 | |
60 | //======================================================================= |
61 | //function : AIS_PlaneTrihedron |
62 | //purpose : |
63 | //======================================================================= |
64 | AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane) |
65 | :myPlane(aPlane) |
66 | { |
67 | Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect(); |
68 | //POP Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH"); |
69 | Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm"); |
70 | DA->SetAxisLength(aLength,aLength,aLength); |
87432b82 |
71 | Quantity_Color col (Quantity_NOC_ROYALBLUE1); |
bc001a40 |
72 | DA->LineAspect(Prs3d_DP_XAxis)->SetColor(col); |
73 | DA->LineAspect(Prs3d_DP_YAxis)->SetColor(col); |
74 | DA->SetDrawDatumAxes(Prs3d_DA_XYAxis); |
81bba717 |
75 | myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified |
7fd59977 |
76 | myShapes[0] = Position(); |
77 | myShapes[1] = XAxis(); |
78 | myShapes[2] = YAxis(); |
79 | |
7fd59977 |
80 | myXLabel = TCollection_AsciiString( "X" ); |
81 | myYLabel = TCollection_AsciiString( "Y" ); |
7fd59977 |
82 | } |
83 | |
84 | //======================================================================= |
85 | //function : Component |
86 | //purpose : |
87 | //======================================================================= |
88 | |
89 | Handle(Geom_Plane) AIS_PlaneTrihedron::Component() |
90 | { |
91 | return myPlane; |
92 | } |
93 | |
94 | |
95 | //======================================================================= |
96 | //function : SetComponent |
97 | //purpose : |
98 | //======================================================================= |
99 | |
100 | void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane) |
101 | { |
102 | myPlane = aPlane; |
103 | } |
104 | |
105 | //======================================================================= |
106 | //function : XAxis |
107 | //purpose : |
108 | //======================================================================= |
7fd59977 |
109 | Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const |
110 | { |
111 | Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis()); |
112 | Handle(AIS_Line) aLine = new AIS_Line (aGLine); |
113 | aLine->SetColor(Quantity_NOC_ROYALBLUE1); |
114 | return aLine; |
115 | } |
7fd59977 |
116 | |
117 | //======================================================================= |
118 | //function : YAxis |
119 | //purpose : |
120 | //======================================================================= |
7fd59977 |
121 | Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const |
122 | { |
123 | Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis()); |
124 | Handle(AIS_Line) aLine = new AIS_Line (aGLine); |
125 | aLine->SetColor(Quantity_NOC_ROYALBLUE1); |
126 | return aLine; |
127 | } |
7fd59977 |
128 | |
129 | //======================================================================= |
130 | //function : Position |
131 | //purpose : |
132 | //======================================================================= |
133 | Handle(AIS_Point) AIS_PlaneTrihedron::Position() const |
134 | { |
135 | gp_Pnt aPnt = myPlane->Pln().Location(); |
136 | Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt); |
137 | Handle(AIS_Point) aPt = new AIS_Point (aPoint); |
138 | return aPt; |
139 | } |
140 | |
7fd59977 |
141 | void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) { |
142 | myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength); |
143 | SetToUpdate(); |
144 | } |
145 | |
146 | Standard_Real AIS_PlaneTrihedron::GetLength() const { |
bc001a40 |
147 | return myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis); |
7fd59977 |
148 | } |
7fd59977 |
149 | |
150 | //======================================================================= |
151 | //function : Compute |
152 | //purpose : |
153 | //======================================================================= |
154 | void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&, |
155 | const Handle(Prs3d_Presentation)& aPresentation, |
156 | const Standard_Integer) |
157 | { |
7fd59977 |
158 | aPresentation->SetDisplayPriority(5); |
7fd59977 |
159 | // drawing axis in X direction |
160 | gp_Pnt first, last; |
bc001a40 |
161 | Standard_Real value = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis); |
7fd59977 |
162 | gp_Dir xDir = myPlane->Position().Ax2().XDirection(); |
163 | |
164 | gp_Pnt orig = myPlane->Position().Ax2().Location(); |
165 | Quantity_Length xo,yo,zo,x,y,z; |
166 | orig.Coord( xo, yo, zo ); |
167 | xDir.Coord( x, y, z ); |
168 | first.SetCoord( xo, yo, zo ); |
169 | last.SetCoord( xo + x * value, yo + y * value, zo + z * value ); |
170 | |
bc001a40 |
171 | DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last ); |
7fd59977 |
172 | |
173 | // drawing axis in Y direction |
bc001a40 |
174 | value = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_YAxis); |
7fd59977 |
175 | gp_Dir yDir = myPlane->Position().Ax2().YDirection(); |
176 | |
177 | yDir.Coord( x, y, z ); |
178 | last.SetCoord( xo + x * value, yo + y * value, zo + z * value ); |
bc001a40 |
179 | DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last ); |
7fd59977 |
180 | |
7fd59977 |
181 | aPresentation->SetInfiniteState (Standard_True); |
182 | } |
183 | |
857ffd5e |
184 | void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 |
185 | { |
9775fa61 |
186 | // throw Standard_NotImplemented("AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
7fd59977 |
187 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ; |
188 | } |
189 | |
190 | //======================================================================= |
191 | //function : ComputeSelection |
192 | //purpose : |
193 | //======================================================================= |
194 | |
195 | void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
196 | const Standard_Integer aMode) |
197 | { |
198 | Standard_Integer Prior; |
199 | Handle(SelectMgr_EntityOwner) eown; |
200 | TColgp_Array1OfPnt PP(1,4),PO(1,4); |
201 | // ExtremityPoints(PP); |
202 | ExtremityPoints(PP,myPlane,myDrawer); |
203 | switch (aMode) { |
204 | case 0: |
205 | { // triedre complet |
206 | Prior = 5; |
207 | // gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2()); |
208 | // gp_Pnt p1 = theax.Location(); |
209 | |
210 | eown = new SelectMgr_EntityOwner(this,Prior); |
211 | for (Standard_Integer i=1; i<=2;i++) |
212 | aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1))); |
213 | |
214 | break; |
215 | } |
216 | case 1: |
217 | { //origine |
218 | Prior = 8; |
543a9964 |
219 | const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity |
220 | eown= new SelectMgr_EntityOwner(anObj,Prior); |
7fd59977 |
221 | aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location())); |
222 | |
223 | break; |
224 | } |
225 | case 2: |
226 | { //axes ... priorite 7 |
227 | Prior = 7; |
228 | for (Standard_Integer i=1; i<=2;i++){ |
543a9964 |
229 | const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity |
230 | eown= new SelectMgr_EntityOwner(anObj,Prior); |
7fd59977 |
231 | aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1))); |
232 | |
233 | } |
234 | break; |
235 | } |
7fd59977 |
236 | case -1: |
237 | { |
238 | Prior = 5; |
239 | aSelection->Clear(); |
240 | break; |
241 | } |
7fd59977 |
242 | } |
243 | } |
244 | |
7fd59977 |
245 | void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol) |
7fd59977 |
246 | { |
247 | hasOwnColor=Standard_True; |
f838dac4 |
248 | myDrawer->SetColor (aCol); |
bc001a40 |
249 | myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis)->SetColor(aCol); |
250 | myDrawer->DatumAspect()->LineAspect(Prs3d_DP_YAxis)->SetColor(aCol); |
7fd59977 |
251 | } |
252 | |
7fd59977 |
253 | |
254 | void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&, |
255 | const Handle(Prs3d_Presentation)&) |
256 | { |
257 | } |
258 | |
259 | |
260 | //======================================================================= |
261 | //function : ExtremityPoints |
262 | //purpose : to avoid warning |
263 | //======================================================================= |
264 | //void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const |
265 | void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer ) |
266 | { |
267 | // gp_Ax2 theax(myPlane->Ax2()); |
268 | gp_Ax2 theax(myPlane->Position().Ax2()); |
269 | PP(1) = theax.Location(); |
270 | |
bc001a40 |
271 | Standard_Real len = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis); |
7fd59977 |
272 | gp_Vec vec = theax.XDirection(); |
273 | vec *= len; |
274 | PP(2) = PP(1).Translated(vec); |
275 | |
bc001a40 |
276 | len = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_YAxis); |
7fd59977 |
277 | vec = theax.YDirection(); |
278 | vec *= len; |
279 | PP(3) = PP(1).Translated(vec); |
280 | |
281 | } |
282 | |
283 | //======================================================================= |
284 | //function : AcceptDisplayMode |
285 | //purpose : |
286 | //======================================================================= |
287 | Standard_Boolean AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const |
288 | {return aMode == 0;} |
289 | |