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