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