0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[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>
42cf5bc1 24#include <GeomAdaptor_Curve.hxx>
7fd59977 25#include <Graphic3d_AspectLine3d.hxx>
26#include <Graphic3d_Structure.hxx>
42cf5bc1 27#include <Precision.hxx>
28#include <Prs3d_Drawer.hxx>
29#include <Prs3d_LineAspect.hxx>
30#include <Prs3d_Presentation.hxx>
42cf5bc1 31#include <Quantity_Color.hxx>
32#include <Select3D_SensitiveSegment.hxx>
7fd59977 33#include <SelectMgr_EntityOwner.hxx>
f751596e 34#include <SelectMgr_Selection.hxx>
42cf5bc1 35#include <Standard_Type.hxx>
7fd59977 36#include <StdPrs_Curve.hxx>
42cf5bc1 37#include <TColgp_Array1OfPnt.hxx>
7fd59977 38#include <UnitsAPI.hxx>
cb389a77 39
92efcf78 40IMPLEMENT_STANDARD_RTTIEXT(AIS_Line,AIS_InteractiveObject)
41
7fd59977 42//=======================================================================
43//function : AIS_Line
44//purpose :
45//=======================================================================
46AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
47myComponent (aComponent),
48myLineIsSegment(Standard_False)
49{
50 SetInfiniteState();
51}
52
53//=======================================================================
54//function : AIS_Line
55//purpose :
56//=======================================================================
57AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
58 const Handle(Geom_Point)& aEndPoint):
59myStartPoint(aStartPoint),
60myEndPoint(aEndPoint),
61myLineIsSegment(Standard_True)
62{}
63
64//=======================================================================
65//function : Compute
66//purpose :
67//=======================================================================
68void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
69 const Handle(Prs3d_Presentation)& aPresentation,
70 const Standard_Integer)
71{
7fd59977 72 aPresentation->SetDisplayPriority(5);
73
74 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
75 else ComputeSegmentLine(aPresentation);
76
77}
78
7fd59977 79//=======================================================================
80//function : ComputeSelection
81//purpose :
82//=======================================================================
83
270675f5 84void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
85 const Standard_Integer theMode)
7fd59977 86{
270675f5 87 // Do not support selection modes different from 0 currently
88 if (theMode)
89 return;
90
91 if (!myLineIsSegment)
92 {
93 ComputeInfiniteLineSelection(theSelection);
94 }
95 else
96 {
97 ComputeSegmentLineSelection(theSelection);
98 }
7fd59977 99}
100
7fd59977 101//=======================================================================
226fce20 102//function : replaceWithNewLineAspect
103//purpose :
104//=======================================================================
105void AIS_Line::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
106{
107 if (!myDrawer->HasLink())
108 {
109 myDrawer->SetLineAspect (theAspect);
110 return;
111 }
112
113 const Handle(Graphic3d_Aspects)& anAspectOld = myDrawer->LineAspect()->Aspect();
114 const Handle(Graphic3d_Aspects)& anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->LineAspect()->Aspect();
115 if (anAspectNew != anAspectOld)
116 {
117 myDrawer->SetLineAspect (theAspect);
118 Graphic3d_MapOfAspectsToAspects aReplaceMap;
119 aReplaceMap.Bind (anAspectOld, anAspectNew);
120 replaceAspects (aReplaceMap);
121 }
122}
123
124//=======================================================================
7fd59977 125//function : SetColor
87432b82 126//purpose :
7fd59977 127//=======================================================================
7fd59977 128void AIS_Line::SetColor(const Quantity_Color &aCol)
7fd59977 129{
130 hasOwnColor=Standard_True;
f838dac4 131 myDrawer->SetColor (aCol);
7fd59977 132
133 Standard_Real WW = HasWidth()? myOwnWidth:
6262338c 134 myDrawer->HasLink() ?
135 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
7fd59977 136
226fce20 137 if (!myDrawer->HasOwnLineAspect())
138 {
139 replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW));
140 }
7fd59977 141 else
226fce20 142 {
143 myDrawer->LineAspect()->SetColor (aCol);
144 SynchronizeAspects();
145 }
7fd59977 146}
147
148
149//=======================================================================
150//function : UnsetColor
151//purpose :
152//=======================================================================
153void AIS_Line::UnsetColor()
154{
155 hasOwnColor = Standard_False;
156
226fce20 157 if (!HasWidth())
158 {
159 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
160 }
161 else
162 {
6262338c 163 Quantity_Color CC = Quantity_NOC_YELLOW;
f838dac4 164 if( HasColor() ) CC = myDrawer->Color();
6262338c 165 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
7fd59977 166 myDrawer->LineAspect()->SetColor(CC);
f838dac4 167 myDrawer->SetColor (CC);
226fce20 168 SynchronizeAspects();
169 }
7fd59977 170}
171
172//=======================================================================
173//function : SetWidth
174//purpose :
175//=======================================================================
176void AIS_Line::SetWidth(const Standard_Real aValue)
177{
226fce20 178 myOwnWidth = (Standard_ShortReal )aValue;
7fd59977 179
226fce20 180 if (!myDrawer->HasOwnLineAspect())
181 {
6262338c 182 Quantity_Color CC = Quantity_NOC_YELLOW;
f838dac4 183 if( HasColor() ) CC = myDrawer->Color();
6262338c 184 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
226fce20 185 replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
186 }
187 else
188 {
189 myDrawer->LineAspect()->SetWidth (aValue);
190 SynchronizeAspects();
191 }
7fd59977 192}
193
194
195//=======================================================================
196//function : UnsetWidth
197//purpose :
198//=======================================================================
199void AIS_Line::UnsetWidth()
200{
226fce20 201 if (!HasColor())
202 {
203 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
204 }
205 else
206 {
207 Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.0f;
208 myDrawer->LineAspect()->SetWidth (WW);
7fd59977 209 myOwnWidth = WW;
226fce20 210 SynchronizeAspects();
7fd59977 211 }
212}
213
214//=======================================================================
215//function : ComputeInfiniteLine
216//purpose :
217//=======================================================================
218void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
219{
7fd59977 220 GeomAdaptor_Curve curv(myComponent);
7fd59977 221 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 222
223 //pas de prise en compte lors du FITALL
224 aPresentation->SetInfiniteState (Standard_True);
7fd59977 225}
226
227//=======================================================================
228//function : ComputeSegmentLine
229//purpose :
230//=======================================================================
231void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
232{
7fd59977 233 gp_Pnt P1 = myStartPoint->Pnt();
234 gp_Pnt P2 = myEndPoint->Pnt();
235
236 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
237
238 Standard_Real dist = P1.Distance(P2);
239 GeomAdaptor_Curve curv(myComponent,0.,dist);
7fd59977 240 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 241}
242
243
244//=======================================================================
245//function : ComputeInfiniteLineSelection
246//purpose :
247//=======================================================================
248
249void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
250{
251
252/* // on calcule les points min max a partir desquels on cree un segment sensible...
253 GeomAdaptor_Curve curv(myComponent);
254 gp_Pnt P1,P2;
255 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
256*/
257 const gp_Dir& thedir = myComponent->Position().Direction();
258 const gp_Pnt& loc = myComponent->Position().Location();
259 const gp_XYZ& dir_xyz = thedir.XYZ();
260 const gp_XYZ& loc_xyz = loc.XYZ();
261//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
262 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
263 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
264 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
265 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
266 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
267 aSelection->Add(seg);
268}
269//=======================================================================
270//function : ComputeSegmentLineSelection
271//purpose :
272//=======================================================================
273
274void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
275{
276
277
278 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
279 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
280 myStartPoint->Pnt(),
281 myEndPoint->Pnt());
282 aSelection->Add(seg);
283}