0025695: Visualization, AIS_InteractiveContext - define default HilightMode
[occt.git] / src / AIS / AIS_Circle.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_Circle.hxx>
19#include <AIS_GraphicTool.hxx>
7fd59977 20#include <Aspect_TypeOfLine.hxx>
42cf5bc1 21#include <GC_MakeArcOfCircle.hxx>
22#include <Geom_Circle.hxx>
23#include <Geom_Transformation.hxx>
24#include <GeomAdaptor_Curve.hxx>
7fd59977 25#include <Graphic3d_AspectLine3d.hxx>
26#include <Graphic3d_Structure.hxx>
42cf5bc1 27#include <Prs3d_Drawer.hxx>
28#include <Prs3d_LineAspect.hxx>
29#include <Prs3d_Presentation.hxx>
30#include <Prs3d_Projector.hxx>
31#include <Quantity_Color.hxx>
32#include <Select3D_SensitiveCircle.hxx>
7fd59977 33#include <SelectMgr_EntityOwner.hxx>
f751596e 34#include <SelectMgr_Selection.hxx>
42cf5bc1 35#include <Standard_Type.hxx>
7fd59977 36#include <StdPrs_DeflectionCurve.hxx>
42cf5bc1 37#include <TColgp_Array1OfPnt.hxx>
7fd59977 38#include <TopoDS.hxx>
7fd59977 39
92efcf78 40IMPLEMENT_STANDARD_RTTIEXT(AIS_Circle,AIS_InteractiveObject)
41
7fd59977 42//=======================================================================
43//function : AIS_Circle
44//purpose :
45//=======================================================================
46AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
47AIS_InteractiveObject(PrsMgr_TOP_AllView),
48myComponent(aComponent),
49myUStart(0.),
c6541a0c 50myUEnd(2*M_PI),
9e8804b6 51myCircleIsArc(Standard_False),
52myIsFilledCircleSens (Standard_False)
7fd59977 53{
54}
55
56//=======================================================================
57//function : AIS_Circle
58//purpose :
59//=======================================================================
9e8804b6 60AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& theComponent,
61 const Standard_Real theUStart,
62 const Standard_Real theUEnd,
63 const Standard_Boolean theIsFilledCircleSens)
64: AIS_InteractiveObject(PrsMgr_TOP_AllView),
65 myComponent (theComponent),
66 myUStart (theUStart),
67 myUEnd (theUEnd),
68 myCircleIsArc (Standard_True),
69 myIsFilledCircleSens (theIsFilledCircleSens)
7fd59977 70{
7fd59977 71}
72
73//=======================================================================
74//function : Compute
75//purpose :
76//=======================================================================
77void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
78 const Handle(Prs3d_Presentation)& aPresentation,
79 const Standard_Integer /*aMode*/)
80{
7fd59977 81 aPresentation->SetDisplayPriority(5);
82
83 if (myCircleIsArc) ComputeArc(aPresentation);
84 else ComputeCircle(aPresentation);
85
86}
87
88//=======================================================================
89//function : Compute
90//purpose :
91//=======================================================================
92
857ffd5e 93void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
94 const Handle(Geom_Transformation)& aTransformation,
95 const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 96{
857ffd5e 97// Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 98 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
99}
100
101//=======================================================================
102//function : ComputeSelection
103//purpose :
104//=======================================================================
105
106void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
107 const Standard_Integer /*aMode*/)
108{
109
110 if (myCircleIsArc) ComputeArcSelection(aSelection);
111 else ComputeCircleSelection(aSelection);
112
113}
114
115
116//=======================================================================
117//function : SetColor
118//purpose :
119//=======================================================================
120
121void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
7fd59977 122{
123 SetColor(Quantity_Color(aCol));
124}
125
126//=======================================================================
127//function : SetColor
128//purpose :
129//=======================================================================
130
131void AIS_Circle::SetColor(const Quantity_Color &aCol)
7fd59977 132{
133 hasOwnColor=Standard_True;
f838dac4 134 myDrawer->SetColor (aCol);
7fd59977 135
6262338c 136 Standard_Real WW = HasWidth() ? myOwnWidth :
137 myDrawer->HasLink() ?
138 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
139 1.;
7fd59977 140
6262338c 141 if (!myDrawer->HasOwnLineAspect ())
7fd59977 142 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
143 else
144 myDrawer->LineAspect()->SetColor(aCol);
145}
146
147
148
149//=======================================================================
150//function : SetWidth
151//purpose :
152//=======================================================================
153void AIS_Circle::SetWidth(const Standard_Real aValue)
154{
155 myOwnWidth=aValue;
156
6262338c 157 if (!myDrawer->HasOwnLineAspect ()) {
158 Quantity_Color CC = Quantity_NOC_YELLOW;
f838dac4 159 if( HasColor() ) CC = myDrawer->Color();
6262338c 160 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
7fd59977 161 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
162 } else
163 myDrawer->LineAspect()->SetWidth(aValue);
164}
165
166
167//=======================================================================
168//function : UnsetColor
169//purpose :
170//=======================================================================
171void AIS_Circle::UnsetColor()
172{
173 hasOwnColor = Standard_False;
174
175 Handle(Prs3d_LineAspect) NullAsp;
176
177 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
178 else{
6262338c 179 Quantity_Color CC = Quantity_NOC_YELLOW;;
f838dac4 180 if( HasColor() ) CC = myDrawer->Color();
6262338c 181 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
7fd59977 182 myDrawer->LineAspect()->SetColor(CC);
f838dac4 183 myDrawer->SetColor (CC);
b8ddfc2f 184 }
7fd59977 185}
186
187//=======================================================================
188//function : UnsetWidth
189//purpose :
190//=======================================================================
191void AIS_Circle::UnsetWidth()
192{
193 Handle(Prs3d_LineAspect) NullAsp;
194
195 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
196 else{
6262338c 197 Standard_Real WW = myDrawer->HasLink() ? AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
7fd59977 198 myDrawer->LineAspect()->SetWidth(WW);
199 myOwnWidth = WW;
200 }
201}
202
203//=======================================================================
204//function : ComputeCircle
205//purpose :
206//=======================================================================
207void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
208{
209
210 GeomAdaptor_Curve curv(myComponent);
211 Standard_Real prevdev = myDrawer->DeviationCoefficient();
212 myDrawer->SetDeviationCoefficient(1.e-5);
7fd59977 213 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
7fd59977 214 myDrawer->SetDeviationCoefficient(prevdev);
215
216}
217
218//=======================================================================
219//function : ComputeArc
220
221//purpose :
222//=======================================================================
223void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
224{
7fd59977 225 GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
226 Standard_Real prevdev = myDrawer->DeviationCoefficient();
227 myDrawer->SetDeviationCoefficient(1.e-5);
7fd59977 228 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
7fd59977 229 myDrawer->SetDeviationCoefficient(prevdev);
7fd59977 230}
231
232//=======================================================================
233//function : ComputeCircleSelection
234//purpose :
235//=======================================================================
236
237void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
238{
239 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
9e8804b6 240 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
241 myComponent,
242 myIsFilledCircleSens);
7fd59977 243 aSelection->Add(seg);
244}
245//=======================================================================
246//function : ComputeArcSelection
247//purpose :
248//=======================================================================
249
250void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
251{
252
253
254 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
9e8804b6 255 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
256 myComponent,
257 myUStart, myUEnd,
258 myIsFilledCircleSens);
7fd59977 259 aSelection->Add(seg);
260}
7fd59977 261
262//=======================================================================
263//function : Compute
264//purpose : to avoid warning
265//=======================================================================
266void AIS_Circle::Compute(const Handle(Prs3d_Projector)&,
267 const Handle(Prs3d_Presentation)&)
268{
269}