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