0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
b8ddfc2f 22//GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
7fd59977 23
24#include <AIS_Circle.ixx>
25#include <Aspect_TypeOfLine.hxx>
26#include <Prs3d_Drawer.hxx>
27#include <Prs3d_LineAspect.hxx>
7fd59977 28#include <Graphic3d_AspectLine3d.hxx>
29#include <Graphic3d_Structure.hxx>
30#include <TColgp_Array1OfPnt.hxx>
31#include <SelectMgr_EntityOwner.hxx>
32#include <Select3D_SensitiveCircle.hxx>
33#include <StdPrs_DeflectionCurve.hxx>
34#include <TopoDS.hxx>
35#include <Geom_Circle.hxx>
36#include <GeomAdaptor_Curve.hxx>
37#include <AIS_Drawer.hxx>
38#include <GC_MakeArcOfCircle.hxx>
39#include <Quantity_Color.hxx>
40#include <AIS_GraphicTool.hxx>
41
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{
81 aPresentation->Clear();
82
83 aPresentation->SetDisplayPriority(5);
84
85 if (myCircleIsArc) ComputeArc(aPresentation);
86 else ComputeCircle(aPresentation);
87
88}
89
90//=======================================================================
91//function : Compute
92//purpose :
93//=======================================================================
94
95void AIS_Circle::Compute(const Handle_Prs3d_Projector& aProjector,
96 const Handle_Geom_Transformation& aTransformation,
97 const Handle_Prs3d_Presentation& aPresentation)
98{
99// Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
100 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
101}
102
103//=======================================================================
104//function : ComputeSelection
105//purpose :
106//=======================================================================
107
108void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
109 const Standard_Integer /*aMode*/)
110{
111
112 if (myCircleIsArc) ComputeArcSelection(aSelection);
113 else ComputeCircleSelection(aSelection);
114
115}
116
117
118//=======================================================================
119//function : SetColor
120//purpose :
121//=======================================================================
122
123void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
7fd59977 124{
125 SetColor(Quantity_Color(aCol));
126}
127
128//=======================================================================
129//function : SetColor
130//purpose :
131//=======================================================================
132
133void AIS_Circle::SetColor(const Quantity_Color &aCol)
7fd59977 134{
135 hasOwnColor=Standard_True;
136 myOwnColor=aCol;
137
138 Standard_Real WW = HasWidth()? myOwnWidth:
139 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
140
141 if (!myDrawer->HasLineAspect ())
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
7fd59977 157 if (!myDrawer->HasLineAspect ()) {
7fd59977 158 Quantity_Color CC;
159 if( HasColor() ) CC = myOwnColor;
160 else 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{
b8ddfc2f 179 Quantity_Color CC;
180 if( HasColor() ) CC = myOwnColor;
181 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
7fd59977 182 myDrawer->LineAspect()->SetColor(CC);
183 myOwnColor = 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{
197 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
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}