7fd59977 |
1 | // File: AIS_Line.cxx |
2 | // Created: Tue Jan 21 11:45:01 1997 |
3 | // Author: Prestataire Christiane ARMAND |
4 | // <car@chamalox.paris1.matra-dtv.fr> |
5 | // Copyright: Matra Datavision 1997 |
6 | |
7 | #define GER61351 //GG_171199 Enable to set an object RGB color |
8 | // instead a restricted object NameOfColor. |
9 | |
10 | #include <AIS_Line.ixx> |
11 | #include <Aspect_TypeOfLine.hxx> |
12 | #include <Prs3d_Drawer.hxx> |
13 | #include <Precision.hxx> |
14 | #include <Prs3d_LineAspect.hxx> |
15 | #include <Graphic3d_ArrayOfPrimitives.hxx> |
16 | #include <Graphic3d_AspectLine3d.hxx> |
17 | #include <Graphic3d_Structure.hxx> |
18 | #include <TColgp_Array1OfPnt.hxx> |
19 | #include <SelectMgr_EntityOwner.hxx> |
20 | #include <Select3D_SensitiveSegment.hxx> |
21 | #include <StdPrs_Curve.hxx> |
22 | #include <Geom_Line.hxx> |
23 | #include <GeomAdaptor_Curve.hxx> |
24 | #include <AIS_Drawer.hxx> |
25 | #include <GC_MakeSegment.hxx> |
26 | #include <Handle_Geom_Line.hxx> |
27 | #include <Quantity_Color.hxx> |
28 | #include <AIS_GraphicTool.hxx> |
29 | #include <UnitsAPI.hxx> |
30 | //================================================================== |
31 | // function: FindLimits |
32 | // purpose: |
33 | //================================================================== |
34 | //unused |
35 | /*#ifdef DEB |
36 | static void FindLimits(const Adaptor3d_Curve& aCurve, |
37 | const Standard_Real aLimit, |
38 | gp_Pnt& P1, |
39 | gp_Pnt& P2) |
40 | { |
41 | Standard_Real First = aCurve.FirstParameter(); |
42 | Standard_Real Last = aCurve.LastParameter(); |
43 | Standard_Boolean firstInf = Precision::IsNegativeInfinite(First); |
44 | Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last); |
45 | |
46 | |
47 | if (firstInf || lastInf) { |
48 | Standard_Real delta = 1; |
49 | if (firstInf && lastInf) { |
50 | do { |
51 | delta *= 2; |
52 | First = - delta; |
53 | Last = delta; |
54 | aCurve.D0(First,P1); |
55 | aCurve.D0(Last,P2); |
56 | } while (P1.Distance(P2) < aLimit); |
57 | } |
58 | else if (firstInf) { |
59 | aCurve.D0(Last,P2); |
60 | do { |
61 | delta *= 2; |
62 | First = Last - delta; |
63 | aCurve.D0(First,P1); |
64 | } while (P1.Distance(P2) < aLimit); |
65 | } |
66 | else if (lastInf) { |
67 | aCurve.D0(First,P1); |
68 | do { |
69 | delta *= 2; |
70 | Last = First + delta; |
71 | aCurve.D0(Last,P2); |
72 | } while (P1.Distance(P2) < aLimit); |
73 | } |
74 | } |
75 | } |
76 | #endif |
77 | */ |
78 | |
79 | //======================================================================= |
80 | //function : AIS_Line |
81 | //purpose : |
82 | //======================================================================= |
83 | AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent): |
84 | myComponent (aComponent), |
85 | myLineIsSegment(Standard_False) |
86 | { |
87 | SetInfiniteState(); |
88 | } |
89 | |
90 | //======================================================================= |
91 | //function : AIS_Line |
92 | //purpose : |
93 | //======================================================================= |
94 | AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint, |
95 | const Handle(Geom_Point)& aEndPoint): |
96 | myStartPoint(aStartPoint), |
97 | myEndPoint(aEndPoint), |
98 | myLineIsSegment(Standard_True) |
99 | {} |
100 | |
101 | //======================================================================= |
102 | //function : Compute |
103 | //purpose : |
104 | //======================================================================= |
105 | void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&, |
106 | const Handle(Prs3d_Presentation)& aPresentation, |
107 | const Standard_Integer) |
108 | { |
109 | aPresentation->Clear(); |
110 | |
111 | aPresentation->SetDisplayPriority(5); |
112 | |
113 | if (!myLineIsSegment) ComputeInfiniteLine(aPresentation); |
114 | else ComputeSegmentLine(aPresentation); |
115 | |
116 | } |
117 | |
118 | void AIS_Line::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation) |
119 | { |
120 | // Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)"); |
121 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ; |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : ComputeSelection |
126 | //purpose : |
127 | //======================================================================= |
128 | |
129 | void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
130 | const Standard_Integer) |
131 | { |
132 | |
133 | if (!myLineIsSegment) ComputeInfiniteLineSelection(aSelection); |
134 | else ComputeSegmentLineSelection(aSelection); |
135 | |
136 | } |
137 | |
138 | |
139 | //======================================================================= |
140 | //function : SetColor |
141 | //purpose : |
142 | //======================================================================= |
143 | |
144 | void AIS_Line::SetColor(const Quantity_NameOfColor aCol) |
145 | #ifdef GER61351 |
146 | { |
147 | SetColor(Quantity_Color(aCol)); |
148 | } |
149 | |
150 | void AIS_Line::SetColor(const Quantity_Color &aCol) |
151 | #endif |
152 | { |
153 | hasOwnColor=Standard_True; |
154 | myOwnColor=aCol; |
155 | |
156 | Standard_Real WW = HasWidth()? myOwnWidth: |
157 | AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); |
158 | |
159 | if (!myDrawer->HasLineAspect ()) |
160 | myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); |
161 | else |
162 | myDrawer->LineAspect()->SetColor(aCol); |
163 | } |
164 | |
165 | |
166 | //======================================================================= |
167 | //function : UnsetColor |
168 | //purpose : |
169 | //======================================================================= |
170 | void AIS_Line::UnsetColor() |
171 | { |
172 | hasOwnColor = Standard_False; |
173 | |
174 | Handle(Prs3d_LineAspect) NullAsp; |
175 | |
176 | if (!HasWidth()) myDrawer->SetLineAspect(NullAsp); |
177 | else{ |
178 | #ifdef GER61351 |
179 | Quantity_Color CC; |
180 | if( HasColor() ) CC = myOwnColor; |
181 | else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
182 | #else |
183 | Quantity_NameOfColor CC = |
184 | AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line); |
185 | #endif |
186 | |
187 | myDrawer->LineAspect()->SetColor(CC); |
188 | myOwnColor = CC; |
189 | } |
190 | } |
191 | |
192 | //======================================================================= |
193 | //function : SetWidth |
194 | //purpose : |
195 | //======================================================================= |
196 | void AIS_Line::SetWidth(const Standard_Real aValue) |
197 | { |
198 | myOwnWidth=aValue; |
199 | |
200 | #ifndef GER61351 |
201 | Quantity_NameOfColor CC = |
202 | HasColor()? myOwnColor : AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line); |
203 | #endif |
204 | |
205 | if (!myDrawer->HasLineAspect ()) { |
206 | #ifdef GER61351 |
207 | Quantity_Color CC; |
208 | if( HasColor() ) CC = myOwnColor; |
209 | else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
210 | #endif |
211 | myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue)); |
212 | } else |
213 | myDrawer->LineAspect()->SetWidth(aValue); |
214 | } |
215 | |
216 | |
217 | //======================================================================= |
218 | //function : UnsetWidth |
219 | //purpose : |
220 | //======================================================================= |
221 | void AIS_Line::UnsetWidth() |
222 | { |
223 | Handle(Prs3d_LineAspect) NullAsp; |
224 | |
225 | if (!HasColor()) myDrawer->SetLineAspect(NullAsp); |
226 | else{ |
227 | Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); |
228 | myDrawer->LineAspect()->SetWidth(WW); |
229 | myOwnWidth = WW; |
230 | } |
231 | } |
232 | |
233 | //======================================================================= |
234 | //function : ComputeInfiniteLine |
235 | //purpose : |
236 | //======================================================================= |
237 | void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation) |
238 | { |
239 | |
240 | GeomAdaptor_Curve curv(myComponent); |
241 | Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable(); |
242 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable(); |
243 | StdPrs_Curve::Add(aPresentation,curv,myDrawer); |
244 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable(); |
245 | |
246 | //pas de prise en compte lors du FITALL |
247 | aPresentation->SetInfiniteState (Standard_True); |
248 | |
249 | } |
250 | |
251 | //======================================================================= |
252 | //function : ComputeSegmentLine |
253 | //purpose : |
254 | //======================================================================= |
255 | void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation) |
256 | { |
257 | |
258 | gp_Pnt P1 = myStartPoint->Pnt(); |
259 | gp_Pnt P2 = myEndPoint->Pnt(); |
260 | |
261 | myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ())); |
262 | |
263 | Standard_Real dist = P1.Distance(P2); |
264 | GeomAdaptor_Curve curv(myComponent,0.,dist); |
265 | Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable(); |
266 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable(); |
267 | StdPrs_Curve::Add(aPresentation,curv,myDrawer); |
268 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable(); |
269 | |
270 | } |
271 | |
272 | |
273 | //======================================================================= |
274 | //function : ComputeInfiniteLineSelection |
275 | //purpose : |
276 | //======================================================================= |
277 | |
278 | void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection) |
279 | { |
280 | |
281 | /* // on calcule les points min max a partir desquels on cree un segment sensible... |
282 | GeomAdaptor_Curve curv(myComponent); |
283 | gp_Pnt P1,P2; |
284 | FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2); |
285 | */ |
286 | const gp_Dir& thedir = myComponent->Position().Direction(); |
287 | const gp_Pnt& loc = myComponent->Position().Location(); |
288 | const gp_XYZ& dir_xyz = thedir.XYZ(); |
289 | const gp_XYZ& loc_xyz = loc.XYZ(); |
290 | //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH"); |
291 | Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm"); |
292 | gp_Pnt P1 = loc_xyz + aLength*dir_xyz; |
293 | gp_Pnt P2 = loc_xyz - aLength*dir_xyz; |
294 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5); |
295 | Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2); |
296 | aSelection->Add(seg); |
297 | } |
298 | //======================================================================= |
299 | //function : ComputeSegmentLineSelection |
300 | //purpose : |
301 | //======================================================================= |
302 | |
303 | void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection) |
304 | { |
305 | |
306 | |
307 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5); |
308 | Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown, |
309 | myStartPoint->Pnt(), |
310 | myEndPoint->Pnt()); |
311 | aSelection->Add(seg); |
312 | } |
313 | //======================================================================= |
314 | //function : Compute |
315 | //purpose : to avoid warning |
316 | //======================================================================= |
317 | void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager2d)&, |
318 | const Handle(Graphic2d_GraphicObject)&, |
319 | const Standard_Integer) |
320 | { |
321 | } |
322 | |
323 | //======================================================================= |
324 | //function : Compute |
325 | //purpose : to avoid warning |
326 | //======================================================================= |
327 | void AIS_Line::Compute(const Handle(Prs3d_Projector)&, |
328 | const Handle(Prs3d_Presentation)&) |
329 | { |
330 | } |
331 | |
332 | |
333 | |
334 | |