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