1 // Created on: 1997-01-21
2 // Created by: Prestataire Christiane ARMAND
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_Circle.hxx>
19 #include <AIS_GraphicTool.hxx>
20 #include <Aspect_TypeOfLine.hxx>
21 #include <GC_MakeArcOfCircle.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Transformation.hxx>
24 #include <GeomAdaptor_Curve.hxx>
25 #include <Graphic3d_AspectLine3d.hxx>
26 #include <Graphic3d_Structure.hxx>
27 #include <Prs3d_Drawer.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <Quantity_Color.hxx>
31 #include <Select3D_SensitiveCircle.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
33 #include <SelectMgr_Selection.hxx>
34 #include <Standard_Type.hxx>
35 #include <StdPrs_DeflectionCurve.hxx>
36 #include <TColgp_Array1OfPnt.hxx>
39 IMPLEMENT_STANDARD_RTTIEXT(AIS_Circle,AIS_InteractiveObject)
41 //=======================================================================
42 //function : AIS_Circle
44 //=======================================================================
45 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
46 AIS_InteractiveObject(PrsMgr_TOP_AllView),
47 myComponent(aComponent),
50 myCircleIsArc(Standard_False),
51 myIsFilledCircleSens (Standard_False)
55 //=======================================================================
56 //function : AIS_Circle
58 //=======================================================================
59 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& theComponent,
60 const Standard_Real theUStart,
61 const Standard_Real theUEnd,
62 const Standard_Boolean theIsFilledCircleSens)
63 : AIS_InteractiveObject(PrsMgr_TOP_AllView),
64 myComponent (theComponent),
67 myCircleIsArc (Standard_True),
68 myIsFilledCircleSens (theIsFilledCircleSens)
72 //=======================================================================
75 //=======================================================================
76 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
77 const Handle(Prs3d_Presentation)& aPresentation,
78 const Standard_Integer /*aMode*/)
80 aPresentation->SetDisplayPriority(5);
82 if (myCircleIsArc) ComputeArc(aPresentation);
83 else ComputeCircle(aPresentation);
87 //=======================================================================
88 //function : ComputeSelection
90 //=======================================================================
92 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
93 const Standard_Integer /*aMode*/)
96 if (myCircleIsArc) ComputeArcSelection(aSelection);
97 else ComputeCircleSelection(aSelection);
101 //=======================================================================
102 //function : replaceWithNewLineAspect
104 //=======================================================================
105 void AIS_Circle::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
107 if (!myDrawer->HasLink())
109 myDrawer->SetLineAspect (theAspect);
113 const Handle(Graphic3d_AspectLine3d) anAspectOld = myDrawer->LineAspect()->Aspect();
114 const Handle(Graphic3d_AspectLine3d) anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->LineAspect()->Aspect();
115 if (anAspectNew != anAspectOld)
117 myDrawer->SetLineAspect (theAspect);
118 Graphic3d_MapOfAspectsToAspects aReplaceMap;
119 aReplaceMap.Bind (anAspectOld, anAspectNew);
120 replaceAspects (aReplaceMap);
124 //=======================================================================
125 //function : SetColor
127 //=======================================================================
129 void AIS_Circle::SetColor(const Quantity_Color &aCol)
131 hasOwnColor=Standard_True;
132 myDrawer->SetColor (aCol);
134 if (!myDrawer->HasOwnLineAspect())
136 Standard_Real WW = HasWidth() ? myOwnWidth :
137 myDrawer->HasLink() ?
138 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
140 replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW));
144 myDrawer->LineAspect()->SetColor(aCol);
145 SynchronizeAspects();
149 //=======================================================================
150 //function : SetWidth
152 //=======================================================================
153 void AIS_Circle::SetWidth(const Standard_Real aValue)
155 myOwnWidth = (Standard_ShortReal )aValue;
157 if (!myDrawer->HasOwnLineAspect())
159 Quantity_Color CC = Quantity_NOC_YELLOW;
160 if( HasColor() ) CC = myDrawer->Color();
161 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
162 replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
166 myDrawer->LineAspect()->SetWidth(aValue);
167 SynchronizeAspects();
172 //=======================================================================
173 //function : UnsetColor
175 //=======================================================================
176 void AIS_Circle::UnsetColor()
178 hasOwnColor = Standard_False;
182 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
186 Quantity_Color CC = Quantity_NOC_YELLOW;
187 if( HasColor() ) CC = myDrawer->Color();
188 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
189 myDrawer->LineAspect()->SetColor(CC);
190 myDrawer->SetColor (CC);
191 SynchronizeAspects();
195 //=======================================================================
196 //function : UnsetWidth
198 //=======================================================================
199 void AIS_Circle::UnsetWidth()
203 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
207 Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.0f;
208 myDrawer->LineAspect()->SetWidth(WW);
213 //=======================================================================
214 //function : ComputeCircle
216 //=======================================================================
217 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
220 GeomAdaptor_Curve curv(myComponent);
221 Standard_Real prevdev = myDrawer->DeviationCoefficient();
222 myDrawer->SetDeviationCoefficient(1.e-5);
223 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
224 myDrawer->SetDeviationCoefficient(prevdev);
228 //=======================================================================
229 //function : ComputeArc
232 //=======================================================================
233 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
235 GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
236 Standard_Real prevdev = myDrawer->DeviationCoefficient();
237 myDrawer->SetDeviationCoefficient(1.e-5);
238 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
239 myDrawer->SetDeviationCoefficient(prevdev);
242 //=======================================================================
243 //function : ComputeCircleSelection
245 //=======================================================================
247 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
249 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
250 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
252 myIsFilledCircleSens);
253 aSelection->Add(seg);
255 //=======================================================================
256 //function : ComputeArcSelection
258 //=======================================================================
260 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
264 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
265 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
268 myIsFilledCircleSens);
269 aSelection->Add(seg);