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