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