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