0025180: Visualization - Homogeneous transformation API in TKV3d
[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
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 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{
120 aPresentation->Clear();
121
122 aPresentation->SetDisplayPriority(5);
123
124 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
125 else ComputeSegmentLine(aPresentation);
126
127}
128
857ffd5e 129void AIS_Line::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 130{
857ffd5e 131// Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 132 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
133}
134
135//=======================================================================
136//function : ComputeSelection
137//purpose :
138//=======================================================================
139
270675f5 140void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
141 const Standard_Integer theMode)
7fd59977 142{
270675f5 143 // Do not support selection modes different from 0 currently
144 if (theMode)
145 return;
146
147 if (!myLineIsSegment)
148 {
149 ComputeInfiniteLineSelection(theSelection);
150 }
151 else
152 {
153 ComputeSegmentLineSelection(theSelection);
154 }
7fd59977 155}
156
157
158//=======================================================================
159//function : SetColor
160//purpose :
161//=======================================================================
162
163void AIS_Line::SetColor(const Quantity_NameOfColor aCol)
7fd59977 164{
165 SetColor(Quantity_Color(aCol));
166}
167
168void AIS_Line::SetColor(const Quantity_Color &aCol)
7fd59977 169{
170 hasOwnColor=Standard_True;
171 myOwnColor=aCol;
172
173 Standard_Real WW = HasWidth()? myOwnWidth:
6262338c 174 myDrawer->HasLink() ?
175 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
7fd59977 176
6262338c 177 if (!myDrawer->HasOwnLineAspect ())
7fd59977 178 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
179 else
180 myDrawer->LineAspect()->SetColor(aCol);
181}
182
183
184//=======================================================================
185//function : UnsetColor
186//purpose :
187//=======================================================================
188void AIS_Line::UnsetColor()
189{
190 hasOwnColor = Standard_False;
191
192 Handle(Prs3d_LineAspect) NullAsp;
193
194 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
195 else{
6262338c 196 Quantity_Color CC = Quantity_NOC_YELLOW;
7fd59977 197 if( HasColor() ) CC = myOwnColor;
6262338c 198 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
7fd59977 199 myDrawer->LineAspect()->SetColor(CC);
200 myOwnColor = CC;
201 }
202}
203
204//=======================================================================
205//function : SetWidth
206//purpose :
207//=======================================================================
208void AIS_Line::SetWidth(const Standard_Real aValue)
209{
210 myOwnWidth=aValue;
211
6262338c 212 if (!myDrawer->HasOwnLineAspect ()) {
213 Quantity_Color CC = Quantity_NOC_YELLOW;
7fd59977 214 if( HasColor() ) CC = myOwnColor;
6262338c 215 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
216 myDrawer->SetLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
7fd59977 217 } else
218 myDrawer->LineAspect()->SetWidth(aValue);
219}
220
221
222//=======================================================================
223//function : UnsetWidth
224//purpose :
225//=======================================================================
226void AIS_Line::UnsetWidth()
227{
228 Handle(Prs3d_LineAspect) NullAsp;
229
230 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
231 else{
6262338c 232 Standard_Real WW = myDrawer->HasLink() ?
233 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
7fd59977 234 myDrawer->LineAspect()->SetWidth(WW);
235 myOwnWidth = WW;
236 }
237}
238
239//=======================================================================
240//function : ComputeInfiniteLine
241//purpose :
242//=======================================================================
243void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
244{
7fd59977 245 GeomAdaptor_Curve curv(myComponent);
7fd59977 246 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 247
248 //pas de prise en compte lors du FITALL
249 aPresentation->SetInfiniteState (Standard_True);
7fd59977 250}
251
252//=======================================================================
253//function : ComputeSegmentLine
254//purpose :
255//=======================================================================
256void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
257{
7fd59977 258 gp_Pnt P1 = myStartPoint->Pnt();
259 gp_Pnt P2 = myEndPoint->Pnt();
260
261 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
262
263 Standard_Real dist = P1.Distance(P2);
264 GeomAdaptor_Curve curv(myComponent,0.,dist);
7fd59977 265 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 266}
267
268
269//=======================================================================
270//function : ComputeInfiniteLineSelection
271//purpose :
272//=======================================================================
273
274void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
275{
276
277/* // on calcule les points min max a partir desquels on cree un segment sensible...
278 GeomAdaptor_Curve curv(myComponent);
279 gp_Pnt P1,P2;
280 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
281*/
282 const gp_Dir& thedir = myComponent->Position().Direction();
283 const gp_Pnt& loc = myComponent->Position().Location();
284 const gp_XYZ& dir_xyz = thedir.XYZ();
285 const gp_XYZ& loc_xyz = loc.XYZ();
286//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
287 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
288 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
289 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
290 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
291 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
292 aSelection->Add(seg);
293}
294//=======================================================================
295//function : ComputeSegmentLineSelection
296//purpose :
297//=======================================================================
298
299void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
300{
301
302
303 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
304 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
305 myStartPoint->Pnt(),
306 myEndPoint->Pnt());
307 aSelection->Add(seg);
308}
7fd59977 309
310//=======================================================================
311//function : Compute
312//purpose : to avoid warning
313//=======================================================================
314void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
315 const Handle(Prs3d_Presentation)&)
316{
317}
318
319
320
321