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