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