0029262: Visualization - AIS_InteractiveContext::Load() does not register Object...
[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
87432b82 17#include <AIS_Line.hxx>
42cf5bc1 18
19#include <AIS_GraphicTool.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 42IMPLEMENT_STANDARD_RTTIEXT(AIS_Line,AIS_InteractiveObject)
43
7fd59977 44//==================================================================
45// function: FindLimits
46// purpose:
47//==================================================================
48//unused
0797d9d3 49/*#ifdef OCCT_DEBUG
7fd59977 50static 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//=======================================================================
94AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
95myComponent (aComponent),
96myLineIsSegment(Standard_False)
97{
98 SetInfiniteState();
99}
100
101//=======================================================================
102//function : AIS_Line
103//purpose :
104//=======================================================================
105AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
106 const Handle(Geom_Point)& aEndPoint):
107myStartPoint(aStartPoint),
108myEndPoint(aEndPoint),
109myLineIsSegment(Standard_True)
110{}
111
112//=======================================================================
113//function : Compute
114//purpose :
115//=======================================================================
116void 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 127void AIS_Line::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 128{
9775fa61 129// throw Standard_NotImplemented("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 138void 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
7fd59977 155//=======================================================================
156//function : SetColor
87432b82 157//purpose :
7fd59977 158//=======================================================================
7fd59977 159void AIS_Line::SetColor(const Quantity_Color &aCol)
7fd59977 160{
161 hasOwnColor=Standard_True;
f838dac4 162 myDrawer->SetColor (aCol);
7fd59977 163
164 Standard_Real WW = HasWidth()? myOwnWidth:
6262338c 165 myDrawer->HasLink() ?
166 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
7fd59977 167
6262338c 168 if (!myDrawer->HasOwnLineAspect ())
7fd59977 169 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
170 else
171 myDrawer->LineAspect()->SetColor(aCol);
172}
173
174
175//=======================================================================
176//function : UnsetColor
177//purpose :
178//=======================================================================
179void AIS_Line::UnsetColor()
180{
181 hasOwnColor = Standard_False;
182
183 Handle(Prs3d_LineAspect) NullAsp;
184
185 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
186 else{
6262338c 187 Quantity_Color CC = Quantity_NOC_YELLOW;
f838dac4 188 if( HasColor() ) CC = myDrawer->Color();
6262338c 189 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
7fd59977 190 myDrawer->LineAspect()->SetColor(CC);
f838dac4 191 myDrawer->SetColor (CC);
7fd59977 192 }
193}
194
195//=======================================================================
196//function : SetWidth
197//purpose :
198//=======================================================================
199void AIS_Line::SetWidth(const Standard_Real aValue)
200{
201 myOwnWidth=aValue;
202
6262338c 203 if (!myDrawer->HasOwnLineAspect ()) {
204 Quantity_Color CC = Quantity_NOC_YELLOW;
f838dac4 205 if( HasColor() ) CC = myDrawer->Color();
6262338c 206 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
207 myDrawer->SetLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
7fd59977 208 } else
209 myDrawer->LineAspect()->SetWidth(aValue);
210}
211
212
213//=======================================================================
214//function : UnsetWidth
215//purpose :
216//=======================================================================
217void AIS_Line::UnsetWidth()
218{
219 Handle(Prs3d_LineAspect) NullAsp;
220
221 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
222 else{
6262338c 223 Standard_Real WW = myDrawer->HasLink() ?
224 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
7fd59977 225 myDrawer->LineAspect()->SetWidth(WW);
226 myOwnWidth = WW;
227 }
228}
229
230//=======================================================================
231//function : ComputeInfiniteLine
232//purpose :
233//=======================================================================
234void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
235{
7fd59977 236 GeomAdaptor_Curve curv(myComponent);
7fd59977 237 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 238
239 //pas de prise en compte lors du FITALL
240 aPresentation->SetInfiniteState (Standard_True);
7fd59977 241}
242
243//=======================================================================
244//function : ComputeSegmentLine
245//purpose :
246//=======================================================================
247void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
248{
7fd59977 249 gp_Pnt P1 = myStartPoint->Pnt();
250 gp_Pnt P2 = myEndPoint->Pnt();
251
252 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
253
254 Standard_Real dist = P1.Distance(P2);
255 GeomAdaptor_Curve curv(myComponent,0.,dist);
7fd59977 256 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 257}
258
259
260//=======================================================================
261//function : ComputeInfiniteLineSelection
262//purpose :
263//=======================================================================
264
265void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
266{
267
268/* // on calcule les points min max a partir desquels on cree un segment sensible...
269 GeomAdaptor_Curve curv(myComponent);
270 gp_Pnt P1,P2;
271 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
272*/
273 const gp_Dir& thedir = myComponent->Position().Direction();
274 const gp_Pnt& loc = myComponent->Position().Location();
275 const gp_XYZ& dir_xyz = thedir.XYZ();
276 const gp_XYZ& loc_xyz = loc.XYZ();
277//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
278 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
279 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
280 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
281 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
282 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
283 aSelection->Add(seg);
284}
285//=======================================================================
286//function : ComputeSegmentLineSelection
287//purpose :
288//=======================================================================
289
290void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
291{
292
293
294 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
295 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
296 myStartPoint->Pnt(),
297 myEndPoint->Pnt());
298 aSelection->Add(seg);
299}
7fd59977 300
301//=======================================================================
302//function : Compute
303//purpose : to avoid warning
304//=======================================================================
305void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
306 const Handle(Prs3d_Presentation)&)
307{
308}
309
310
311
312