0028572: Modeling Algorithms - Wrong result of the mkface command
[occt.git] / src / AIS / AIS_Circle.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <AIS_Circle.hxx>
18
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>
36 #include <TopoDS.hxx>
37
38 IMPLEMENT_STANDARD_RTTIEXT(AIS_Circle,AIS_InteractiveObject)
39
40 //=======================================================================
41 //function : AIS_Circle
42 //purpose  : 
43 //=======================================================================
44 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
45 AIS_InteractiveObject(PrsMgr_TOP_AllView),
46 myComponent(aComponent),
47 myUStart(0.),
48 myUEnd(2*M_PI),
49 myCircleIsArc(Standard_False),
50 myIsFilledCircleSens (Standard_False)
51 {
52 }
53
54 //=======================================================================
55 //function : AIS_Circle
56 //purpose  : 
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),
64   myUStart (theUStart),
65   myUEnd (theUEnd),
66   myCircleIsArc (Standard_True),
67   myIsFilledCircleSens (theIsFilledCircleSens)
68 {
69 }
70
71 //=======================================================================
72 //function : Compute
73 //purpose  : 
74 //=======================================================================
75 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
76                          const Handle(Prs3d_Presentation)& aPresentation, 
77                          const Standard_Integer /*aMode*/)
78 {
79   aPresentation->SetDisplayPriority(5);
80
81   if (myCircleIsArc) ComputeArc(aPresentation);
82   else ComputeCircle(aPresentation);
83
84 }
85
86 //=======================================================================
87 //function : ComputeSelection
88 //purpose  : 
89 //=======================================================================
90
91 void 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
100 //=======================================================================
101 //function : replaceWithNewLineAspect
102 //purpose  :
103 //=======================================================================
104 void 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
123 //=======================================================================
124 //function : SetColor
125 //purpose  : 
126 //=======================================================================
127
128 void AIS_Circle::SetColor(const Quantity_Color &aCol)
129 {
130   hasOwnColor=Standard_True;
131   myDrawer->SetColor (aCol);
132
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   }
141   else
142   {
143     myDrawer->LineAspect()->SetColor(aCol);
144     SynchronizeAspects();
145   }
146 }
147
148 //=======================================================================
149 //function : SetWidth 
150 //purpose  : 
151 //=======================================================================
152 void AIS_Circle::SetWidth(const Standard_Real aValue)
153 {
154   myOwnWidth = (Standard_ShortReal )aValue;
155
156   if (!myDrawer->HasOwnLineAspect())
157   {
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));
162   }
163   else
164   {
165     myDrawer->LineAspect()->SetWidth(aValue);
166     SynchronizeAspects();
167   }
168 }
169
170
171 //=======================================================================
172 //function : UnsetColor 
173 //purpose  : 
174 //=======================================================================
175 void AIS_Circle::UnsetColor()
176 {
177   hasOwnColor = Standard_False;
178
179   if (!HasWidth())
180   {
181     replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
182   }
183   else
184   {
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();
191   }
192 }
193
194 //=======================================================================
195 //function : UnsetWidth 
196 //purpose  : 
197 //=======================================================================
198 void AIS_Circle::UnsetWidth()
199 {
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;
207    myDrawer->LineAspect()->SetWidth(WW);
208    myOwnWidth = WW;
209   }
210 }
211
212 //=======================================================================
213 //function : ComputeCircle
214 //purpose  : 
215 //=======================================================================
216 void 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);
222   StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
223   myDrawer->SetDeviationCoefficient(prevdev);
224
225 }
226
227 //=======================================================================
228 //function : ComputeArc
229
230 //purpose  : 
231 //=======================================================================
232 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
233 {
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);
239 }
240
241 //=======================================================================
242 //function : ComputeCircleSelection
243 //purpose  : 
244 //=======================================================================
245
246 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
247 {
248   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
249   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
250                                                                        myComponent->Circ(),
251                                                                        myIsFilledCircleSens);
252   aSelection->Add(seg);
253 }
254 //=======================================================================
255 //function : ComputeArcSelection
256 //purpose  : 
257 //=======================================================================
258
259 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
260 {
261
262
263   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
264   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
265                                                                        myComponent->Circ(),
266                                                                        myUStart, myUEnd,
267                                                                        myIsFilledCircleSens);
268   aSelection->Add(seg);
269 }