0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / IGESGeom / IGESGeom_ToolConicArc.cxx
1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
18
19 #include <gp_Dir2d.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <gp_XY.hxx>
22 #include <IGESData_DirChecker.hxx>
23 #include <IGESData_Dump.hxx>
24 #include <IGESData_IGESDumper.hxx>
25 #include <IGESData_IGESReaderData.hxx>
26 #include <IGESData_IGESWriter.hxx>
27 #include <IGESData_ParamCursor.hxx>
28 #include <IGESData_ParamReader.hxx>
29 #include <IGESGeom_ConicArc.hxx>
30 #include <IGESGeom_ToolConicArc.hxx>
31 #include <Interface_Check.hxx>
32 #include <Interface_CopyTool.hxx>
33 #include <Interface_EntityIterator.hxx>
34 #include <Interface_Macros.hxx>
35 #include <Interface_MSG.hxx>
36 #include <Interface_ShareTool.hxx>
37 #include <Message_Messenger.hxx>
38 #include <Message_Msg.hxx>
39 #include <Standard_DomainError.hxx>
40
41 #include <stdio.h>
42 // MGE 28/07/98
43 //=======================================================================
44 //function : IGESGeom_ToolConicArc
45 //purpose  : 
46 //=======================================================================
47 IGESGeom_ToolConicArc::IGESGeom_ToolConicArc ()
48 {
49 }
50
51
52 //=======================================================================
53 //function : ReadOwnParams
54 //purpose  : 
55 //=======================================================================
56
57 void IGESGeom_ToolConicArc::ReadOwnParams(const Handle(IGESGeom_ConicArc)& ent,
58                                           const Handle(IGESData_IGESReaderData)& /* IR */,
59                                           IGESData_ParamReader& PR) const
60 {
61   // MGE 28/07/98
62   // Building of messages
63   //======================================
64   Message_Msg Msg83("XSTEP_83");
65   Message_Msg Msg84("XSTEP_84");
66   //======================================
67
68   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
69   Standard_Real A, B = 0., C = 0., D = 0., E = 0., F = 0., ZT;
70   gp_XY tempStart, tempEnd;
71
72  /* PR.ReadReal(PR.Current(), Msg81, A); //szv#4:S4163:12Mar99 `st=` not needed
73   PR.ReadReal(PR.Current(), Msg81, B); //szv#4:S4163:12Mar99 `st=` not needed
74   PR.ReadReal(PR.Current(), Msg81, C); //szv#4:S4163:12Mar99 `st=` not needed
75   PR.ReadReal(PR.Current(), Msg81, D); //szv#4:S4163:12Mar99 `st=` not needed
76   PR.ReadReal(PR.Current(), Msg81, E); //szv#4:S4163:12Mar99 `st=` not needed
77   PR.ReadReal(PR.Current(), Msg81, F); //szv#4:S4163:12Mar99 `st=` not needed
78   */
79   if ((!PR.ReadReal(PR.Current(),A)) || (!PR.ReadReal(PR.Current(),B)) ||
80       (!PR.ReadReal(PR.Current(),C)) || (!PR.ReadReal(PR.Current(),D)) ||
81       (!PR.ReadReal(PR.Current(),E)) || (!PR.ReadReal(PR.Current(),F))){
82     Message_Msg Msg81("XSTEP_81");
83     PR.SendFail(Msg81);
84   }
85
86   if (!PR.ReadReal(PR.Current(), ZT)){ //szv#4:S4163:12Mar99 `st=` not needed
87     Message_Msg Msg82("XSTEP_82");
88     PR.SendFail(Msg82);
89   }
90   PR.ReadXY(PR.CurrentList(1, 2),Msg83, tempStart); //szv#4:S4163:12Mar99 `st=` not needed
91   PR.ReadXY(PR.CurrentList(1, 2), Msg84, tempEnd); //szv#4:S4163:12Mar99 `st=` not needed
92
93 /*
94   st = PR.ReadReal(PR.Current(), "Conic Coefficient A", A);
95   st = PR.ReadReal(PR.Current(), "Conic Coefficient B", B);
96   st = PR.ReadReal(PR.Current(), "Conic Coefficient C", C);
97   st = PR.ReadReal(PR.Current(), "Conic Coefficient D", D);
98   st = PR.ReadReal(PR.Current(), "Conic Coefficient E", E);
99   st = PR.ReadReal(PR.Current(), "Conic Coefficient F", F);
100   st = PR.ReadReal(PR.Current(), "Z-plane shift", ZT);
101   st = PR.ReadXY(PR.CurrentList(1, 2), "Starting Point Of Arc", tempStart);
102   st = PR.ReadXY(PR.CurrentList(1, 2), "End Point Of Arc", tempEnd);
103 */
104   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
105   ent->Init(A, B, C, D, E, F, ZT, tempStart, tempEnd);
106 }
107
108
109 //=======================================================================
110 //function : WriteOwnParams
111 //purpose  : 
112 //=======================================================================
113
114 void IGESGeom_ToolConicArc::WriteOwnParams(const Handle(IGESGeom_ConicArc)& ent,
115                                            IGESData_IGESWriter& IW)  const
116 {
117   Standard_Real A,B,C,D,E,F;
118   ent->Equation(A,B,C,D,E,F);
119   IW.Send(A);
120   IW.Send(B);
121   IW.Send(C);
122   IW.Send(D);
123   IW.Send(E);
124   IW.Send(F);
125   IW.Send(ent->ZPlane());
126   IW.Send(ent->StartPoint().X());
127   IW.Send(ent->StartPoint().Y());
128   IW.Send(ent->EndPoint().X());
129   IW.Send(ent->EndPoint().Y());
130 }
131
132
133 //=======================================================================
134 //function : OwnShared
135 //purpose  : 
136 //=======================================================================
137
138 void IGESGeom_ToolConicArc::OwnShared(const Handle(IGESGeom_ConicArc)& /* ent */,
139                                       Interface_EntityIterator& /* iter */) const
140 {
141 }
142
143
144 //=======================================================================
145 //function : OwnCopy
146 //purpose  : 
147 //=======================================================================
148
149 void IGESGeom_ToolConicArc::OwnCopy(const Handle(IGESGeom_ConicArc)& another,
150                                     const Handle(IGESGeom_ConicArc)& ent,
151                                     Interface_CopyTool& /* TC */) const
152 {
153   Standard_Real A,B,C,D,E,F;
154   another->Equation(A,B,C,D,E,F);
155   ent->Init(A, B, C, D, E, F, another->ZPlane(),
156             another->StartPoint().XY(), another->EndPoint().XY());
157 }
158
159
160 //=======================================================================
161 //function : OwnCorrect
162 //purpose  : 
163 //=======================================================================
164
165 Standard_Boolean IGESGeom_ToolConicArc::OwnCorrect
166   (const Handle(IGESGeom_ConicArc)& ent) const
167 {
168   return ent->OwnCorrect();    //  form selon coefs. 1 Ellipse, 2 Hyper, 3 Para
169 }
170
171
172 //=======================================================================
173 //function : DirChecker
174 //purpose  : 
175 //=======================================================================
176
177 IGESData_DirChecker IGESGeom_ToolConicArc::DirChecker
178   (const Handle(IGESGeom_ConicArc)& /* ent */ )  const
179 {
180   IGESData_DirChecker DC(104, 0, 3);
181   DC.Structure(IGESData_DefVoid);
182   DC.GraphicsIgnored();
183   DC.LineFont(IGESData_DefAny);
184 //  DC.LineWeight(IGESData_DefValue);
185   DC.Color(IGESData_DefAny);
186   DC.HierarchyStatusIgnored();
187   return DC;
188 }
189
190
191 //=======================================================================
192 //function : OwnCheck
193 //purpose  : 
194 //=======================================================================
195
196 void IGESGeom_ToolConicArc::OwnCheck(const Handle(IGESGeom_ConicArc)& ent,
197                                      const Interface_ShareTool&,
198                                      Handle(Interface_Check)& ach)  const
199 {
200   // MGE 28/07/98
201   // Building of messages
202   //=====================================
203   //Message_Msg Msg71("XSTEP_71"); 
204   //=====================================
205
206   //char mess[80]; //szv#4:S4163:12Mar99 not needed
207   Standard_Integer cfn = ent->ComputedFormNumber();
208   Standard_Integer  fn = ent->FormNumber();
209   if (cfn == 0) {}
210     // ach.AddFail("Coefficients do not define correctly a Conic");
211   else if (fn != 0 && fn != cfn) {
212     Message_Msg Msg71("XSTEP_71"); 
213     ach->SendFail(Msg71);
214   }
215   
216   //szv#4:S4163:12Mar99 not needed
217   //if (ach.HasFailed()) return;    // les tests suivant deviennent sans objet
218   //Standard_Real eps = 1.E-04;     // Tolerance des Tests ??
219   //Standard_Real A,B,C,D,E,F;
220   //ent->Equation(A,B,C,D,E,F);
221   //Standard_Real x = ent->StartPoint().X();
222   //Standard_Real y = ent->StartPoint().Y();
223   //Standard_Real eq = (A*x*x + B*x*y + C*y*y + D*x + E*y + F);
224   // These messages are transfered in the translation procedure
225 /*  if (eq < -eps || eq > eps) {
226     Sprintf(mess,"Start point does not satisfy conic equation, gap over %f",
227             Interface_MSG::Intervalled(eq));
228     ach.AddFail(mess,"Start point does not satisfy conic equation, gap over %f");
229
230   }
231 */
232   //szv#4:S4163:12Mar99 not needed
233   //x = ent->EndPoint().X();
234   //y = ent->EndPoint().Y();
235   //eq = (A*x*x + B*x*y + C*y*y + D*x + E*y + F);
236 /*  if (eq < -eps || eq > eps) {
237     Sprintf(mess,"End point does not satisfy conic equation, gap over %f",
238             Interface_MSG::Intervalled(eq));
239     ach.AddFail(mess,"End point does not satisfy conic equation, gap over %f");
240   }
241 */
242 /*   Les tests qui suivant ont-ils un sens ??
243   if (ent->FormNumber() == 2)    // Hyperbola
244     {
245       Standard_Real xc = -D / (2 * A);
246       Standard_Real yc = -E / (2 * C);
247       gp_Dir2d d0(1, 0);
248       gp_Dir2d d1(ent->StartPoint().X() - xc, ent->StartPoint().Y() - yc);
249       gp_Dir2d d2(ent->EndPoint().X()   - xc, ent->EndPoint().Y()   - yc);
250       Standard_Real t1 = d0.Angle(d1);
251       Standard_Real t2 = d0.Angle(d2);
252       t1 += (t1  >  0 ? 0 : 2*M_PI);
253       t2 += (t2  >  0 ? 0 : 2*M_PI);
254       t2 += (t1 <= t2 ? 0 : 2*M_PI);
255       if ( !(0 <= t1 && t1 <= 2*M_PI) || !(0 <= t2-t1 && t2-t1 <= 2*M_PI) )
256         ach.AddFail("Parameter Error for Hyperbola");
257     }
258   else if (ent->FormNumber() == 3)
259     {
260       Standard_Real xc = -D / (2 * A);
261       Standard_Real yc = -E / (2 * C);
262       gp_Dir2d d0(1, 0);
263       gp_Dir2d d1(ent->StartPoint().X() - xc, ent->StartPoint().Y() - yc);
264       gp_Dir2d d2(ent->EndPoint().X()   - xc, ent->EndPoint().Y()   - yc);
265       Standard_Real t1 = d0.Angle(d1);
266       Standard_Real t2 = d0.Angle(d2);
267       if ( !(-M_PI/2 < t1 && t1 < M_PI/2) || !(-M_PI/2 < t2 && t2 < M_PI/2) )
268         ach.AddFail("Parameter Error for Parabola");
269     }
270 */
271 }
272
273
274 //=======================================================================
275 //function : OwnDump
276 //purpose  : 
277 //=======================================================================
278
279 void IGESGeom_ToolConicArc::OwnDump(const Handle(IGESGeom_ConicArc)& ent,
280                                     const IGESData_IGESDumper& /* dumper */,
281                                     const Handle(Message_Messenger)& S,
282                                     const Standard_Integer level)  const
283 {
284   Standard_Real A,B,C,D,E,F;
285   ent->Equation(A,B,C,D,E,F);
286   S << "IGESGeom_ConicArc" << endl;
287   Standard_Integer cf = ent->FormNumber();
288   if (cf == 0) cf = ent->ComputedFormNumber();
289   if (cf == 1)      S << " --     Ellipse     --" << endl;
290   else if (cf == 2) S << " --    Hyperbola    --" << endl;
291   else if (cf == 3) S << " --    Parabola    --"  << endl;
292   else              S << " --    (Undetermined type of Conic)    --" << endl;
293   S << "Conic Coefficient A : " << A << endl;
294   S << "Conic Coefficient B : " << B << endl;
295   S << "Conic Coefficient C : " << C << endl;
296   S << "Conic Coefficient D : " << D << endl;
297   S << "Conic Coefficient E : " << E << endl;
298   S << "Conic Coefficient F : " << F << endl;
299   S << "Z-Plane shift : " << ent->ZPlane() << endl;
300   S << "Start Point : ";
301   IGESData_DumpXYLZ(S,level, ent->StartPoint(), ent->Location(),ent->ZPlane());
302   S << endl;
303   S << "End   Point : ";
304   IGESData_DumpXYLZ(S,level, ent->EndPoint(), ent->Location(), ent->ZPlane());
305   S << endl;
306   if (level <= 4) S<<" -- Computed Definition : ask level > 4" << endl;
307   else {
308     gp_Pnt Cen;  gp_Dir Ax;  Standard_Real Rmin,Rmax;
309     ent->Definition (Cen,Ax,Rmin,Rmax);
310     S << " -- Computed Definition (and Transformed if level > 5)" << endl;
311
312     if (cf != 3) {
313       S<<" Center        : "; IGESData_DumpXYZL(S,level,Cen,ent->Location());
314       S<<endl;
315     }
316     S << " Main Axis   : "; IGESData_DumpXYZL(S,level,Ax,ent->VectorLocation());
317     S<<endl;
318     if (cf == 3) S << " Focal : " << Rmin << endl;
319     else if (Rmin == Rmax) S << " Radius (Major = Minor) : " << Rmin << endl;
320     else S << " Major Radius : " << Rmax << "  Minor Radius : " << Rmin <<endl;
321     S<< "  Normal Axis : ";  IGESData_DumpXYZL(S,level,ent->Axis(),ent->VectorLocation());
322     S << endl;
323   }
324 }