0025853: Edges disappear or reappear when displaying new edges
[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>
30#include <AIS_Drawer.hxx>
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:
170 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
171
172 if (!myDrawer->HasLineAspect ())
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{
7fd59977 191 Quantity_Color CC;
192 if( HasColor() ) CC = myOwnColor;
193 else 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
7fd59977 207 if (!myDrawer->HasLineAspect ()) {
7fd59977 208 Quantity_Color CC;
209 if( HasColor() ) CC = myOwnColor;
210 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
7fd59977 211 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
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{
227 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
228 myDrawer->LineAspect()->SetWidth(WW);
229 myOwnWidth = WW;
230 }
231}
232
233//=======================================================================
234//function : ComputeInfiniteLine
235//purpose :
236//=======================================================================
237void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
238{
7fd59977 239 GeomAdaptor_Curve curv(myComponent);
7fd59977 240 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 241
242 //pas de prise en compte lors du FITALL
243 aPresentation->SetInfiniteState (Standard_True);
7fd59977 244}
245
246//=======================================================================
247//function : ComputeSegmentLine
248//purpose :
249//=======================================================================
250void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
251{
7fd59977 252 gp_Pnt P1 = myStartPoint->Pnt();
253 gp_Pnt P2 = myEndPoint->Pnt();
254
255 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
256
257 Standard_Real dist = P1.Distance(P2);
258 GeomAdaptor_Curve curv(myComponent,0.,dist);
7fd59977 259 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 260}
261
262
263//=======================================================================
264//function : ComputeInfiniteLineSelection
265//purpose :
266//=======================================================================
267
268void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
269{
270
271/* // on calcule les points min max a partir desquels on cree un segment sensible...
272 GeomAdaptor_Curve curv(myComponent);
273 gp_Pnt P1,P2;
274 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
275*/
276 const gp_Dir& thedir = myComponent->Position().Direction();
277 const gp_Pnt& loc = myComponent->Position().Location();
278 const gp_XYZ& dir_xyz = thedir.XYZ();
279 const gp_XYZ& loc_xyz = loc.XYZ();
280//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
281 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
282 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
283 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
284 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
285 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
286 aSelection->Add(seg);
287}
288//=======================================================================
289//function : ComputeSegmentLineSelection
290//purpose :
291//=======================================================================
292
293void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
294{
295
296
297 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
298 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
299 myStartPoint->Pnt(),
300 myEndPoint->Pnt());
301 aSelection->Add(seg);
302}
7fd59977 303
304//=======================================================================
305//function : Compute
306//purpose : to avoid warning
307//=======================================================================
308void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
309 const Handle(Prs3d_Presentation)&)
310{
311}
312
313
314
315