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 <GeomAdaptor_Curve.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_Structure.hxx>
26 #include <Prs3d_Drawer.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_Presentation.hxx>
29 #include <Quantity_Color.hxx>
30 #include <Select3D_SensitiveCircle.hxx>
31 #include <SelectMgr_EntityOwner.hxx>
32 #include <SelectMgr_Selection.hxx>
33 #include <Standard_Type.hxx>
34 #include <StdPrs_DeflectionCurve.hxx>
35 #include <TColgp_Array1OfPnt.hxx>
38 IMPLEMENT_STANDARD_RTTIEXT(AIS_Circle,AIS_InteractiveObject)
40 //=======================================================================
41 //function : AIS_Circle
43 //=======================================================================
44 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
45 AIS_InteractiveObject(PrsMgr_TOP_AllView),
46 myComponent(aComponent),
49 myCircleIsArc(Standard_False),
50 myIsFilledCircleSens (Standard_False)
54 //=======================================================================
55 //function : AIS_Circle
57 //=======================================================================
58 AIS_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),
66 myCircleIsArc (Standard_True),
67 myIsFilledCircleSens (theIsFilledCircleSens)
71 //=======================================================================
74 //=======================================================================
75 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
76 const Handle(Prs3d_Presentation)& aPresentation,
77 const Standard_Integer /*aMode*/)
79 aPresentation->SetDisplayPriority(5);
81 if (myCircleIsArc) ComputeArc(aPresentation);
82 else ComputeCircle(aPresentation);
86 //=======================================================================
87 //function : ComputeSelection
89 //=======================================================================
91 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
92 const Standard_Integer /*aMode*/)
95 if (myCircleIsArc) ComputeArcSelection(aSelection);
96 else ComputeCircleSelection(aSelection);
100 //=======================================================================
101 //function : replaceWithNewLineAspect
103 //=======================================================================
104 void AIS_Circle::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
106 if (!myDrawer->HasLink())
108 myDrawer->SetLineAspect (theAspect);
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)
116 myDrawer->SetLineAspect (theAspect);
117 Graphic3d_MapOfAspectsToAspects aReplaceMap;
118 aReplaceMap.Bind (anAspectOld, anAspectNew);
119 replaceAspects (aReplaceMap);
123 //=======================================================================
124 //function : SetColor
126 //=======================================================================
128 void AIS_Circle::SetColor(const Quantity_Color &aCol)
130 hasOwnColor=Standard_True;
131 myDrawer->SetColor (aCol);
133 if (!myDrawer->HasOwnLineAspect())
135 Standard_Real WW = HasWidth() ? myOwnWidth :
136 myDrawer->HasLink() ?
137 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
139 replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW));
143 myDrawer->LineAspect()->SetColor(aCol);
144 SynchronizeAspects();
148 //=======================================================================
149 //function : SetWidth
151 //=======================================================================
152 void AIS_Circle::SetWidth(const Standard_Real aValue)
154 myOwnWidth = (Standard_ShortReal )aValue;
156 if (!myDrawer->HasOwnLineAspect())
158 Quantity_Color CC = Quantity_NOC_YELLOW;
159 if( HasColor() ) CC = myDrawer->Color();
160 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
161 replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
165 myDrawer->LineAspect()->SetWidth(aValue);
166 SynchronizeAspects();
171 //=======================================================================
172 //function : UnsetColor
174 //=======================================================================
175 void AIS_Circle::UnsetColor()
177 hasOwnColor = Standard_False;
181 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
185 Quantity_Color CC = Quantity_NOC_YELLOW;
186 if( HasColor() ) CC = myDrawer->Color();
187 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
188 myDrawer->LineAspect()->SetColor(CC);
189 myDrawer->SetColor (CC);
190 SynchronizeAspects();
194 //=======================================================================
195 //function : UnsetWidth
197 //=======================================================================
198 void AIS_Circle::UnsetWidth()
202 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
206 Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.0f;
207 myDrawer->LineAspect()->SetWidth(WW);
212 //=======================================================================
213 //function : ComputeCircle
215 //=======================================================================
216 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
219 GeomAdaptor_Curve curv(myComponent);
220 Standard_Real prevdev = myDrawer->DeviationCoefficient();
221 myDrawer->SetDeviationCoefficient(1.e-5);
222 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
223 myDrawer->SetDeviationCoefficient(prevdev);
227 //=======================================================================
228 //function : ComputeArc
231 //=======================================================================
232 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
234 GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
235 Standard_Real prevdev = myDrawer->DeviationCoefficient();
236 myDrawer->SetDeviationCoefficient(1.e-5);
237 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
238 myDrawer->SetDeviationCoefficient(prevdev);
241 //=======================================================================
242 //function : ComputeCircleSelection
244 //=======================================================================
246 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
248 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
249 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
251 myIsFilledCircleSens);
252 aSelection->Add(seg);
254 //=======================================================================
255 //function : ComputeArcSelection
257 //=======================================================================
259 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
263 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
264 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
267 myIsFilledCircleSens);
268 aSelection->Add(seg);