0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IGESGeom / IGESGeom_ToolConicArc.cxx
CommitLineData
b311480e 1// Created by: CKY / Contract Toubro-Larsen
2// Copyright (c) 1993-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
7fd59977 6//
d5f74e42 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
973c2be1 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.
7fd59977 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
16//--------------------------------------------------------------------
7fd59977 17//--------------------------------------------------------------------
18
7fd59977 19#include <gp_Dir2d.hxx>
42cf5bc1 20#include <gp_Pnt2d.hxx>
21#include <gp_XY.hxx>
22#include <IGESData_DirChecker.hxx>
7fd59977 23#include <IGESData_Dump.hxx>
42cf5bc1 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>
7fd59977 34#include <Interface_Macros.hxx>
42cf5bc1 35#include <Interface_MSG.hxx>
36#include <Interface_ShareTool.hxx>
37#include <Message_Messenger.hxx>
7fd59977 38#include <Message_Msg.hxx>
42cf5bc1 39#include <Standard_DomainError.hxx>
7fd59977 40
42cf5bc1 41#include <stdio.h>
42// MGE 28/07/98
7fd59977 43//=======================================================================
44//function : IGESGeom_ToolConicArc
45//purpose :
46//=======================================================================
7fd59977 47IGESGeom_ToolConicArc::IGESGeom_ToolConicArc ()
48{
49}
50
51
52//=======================================================================
53//function : ReadOwnParams
54//purpose :
55//=======================================================================
56
57void 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
1d47d8d0 69 Standard_Real A, B = 0., C = 0., D = 0., E = 0., F = 0., ZT;
7fd59977 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
114void 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
138void 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
149void 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
165Standard_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
177IGESData_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
196void 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) {
91322f44 226 Sprintf(mess,"Start point does not satisfy conic equation, gap over %f",
7fd59977 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) {
91322f44 237 Sprintf(mess,"End point does not satisfy conic equation, gap over %f",
7fd59977 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);
c6541a0c
D
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) )
7fd59977 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);
c6541a0c 267 if ( !(-M_PI/2 < t1 && t1 < M_PI/2) || !(-M_PI/2 < t2 && t2 < M_PI/2) )
7fd59977 268 ach.AddFail("Parameter Error for Parabola");
269 }
270*/
271}
272
273
274//=======================================================================
275//function : OwnDump
276//purpose :
277//=======================================================================
278
279void IGESGeom_ToolConicArc::OwnDump(const Handle(IGESGeom_ConicArc)& ent,
280 const IGESData_IGESDumper& /* dumper */,
0ebe5b0a 281 Standard_OStream& S,
7fd59977 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);
0ebe5b0a 286 S << "IGESGeom_ConicArc\n";
7fd59977 287 Standard_Integer cf = ent->FormNumber();
288 if (cf == 0) cf = ent->ComputedFormNumber();
0ebe5b0a 289 if (cf == 1) S << " -- Ellipse --\n";
290 else if (cf == 2) S << " -- Hyperbola --\n";
291 else if (cf == 3) S << " -- Parabola --\n";
292 else S << " -- (Undetermined type of Conic) --\n";
293
294 S << "Conic Coefficient A : " << A << "\n"
295 << "Conic Coefficient B : " << B << "\n"
296 << "Conic Coefficient C : " << C << "\n"
297 << "Conic Coefficient D : " << D << "\n"
298 << "Conic Coefficient E : " << E << "\n"
299 << "Conic Coefficient F : " << F << "\n"
300 << "Z-Plane shift : " << ent->ZPlane() << "\n"
301 << "Start Point : ";
7fd59977 302 IGESData_DumpXYLZ(S,level, ent->StartPoint(), ent->Location(),ent->ZPlane());
0ebe5b0a 303 S << "\n"
304 << "End Point : ";
7fd59977 305 IGESData_DumpXYLZ(S,level, ent->EndPoint(), ent->Location(), ent->ZPlane());
0ebe5b0a 306 S << "\n";
307 if (level <= 4) S <<" -- Computed Definition : ask level > 4" << std::endl;
7fd59977 308 else {
309 gp_Pnt Cen; gp_Dir Ax; Standard_Real Rmin,Rmax;
310 ent->Definition (Cen,Ax,Rmin,Rmax);
0ebe5b0a 311 S << " -- Computed Definition (and Transformed if level > 5)\n";
7fd59977 312
313 if (cf != 3) {
0ebe5b0a 314 S <<" Center : "; IGESData_DumpXYZL(S,level,Cen,ent->Location());
315 S <<"\n";
7fd59977 316 }
317 S << " Main Axis : "; IGESData_DumpXYZL(S,level,Ax,ent->VectorLocation());
0ebe5b0a 318 S <<"\n";
319 if (cf == 3) S << " Focal : " << Rmin << "\n";
320 else if (Rmin == Rmax) S << " Radius (Major = Minor) : " << Rmin << "\n";
321 else S << " Major Radius : " << Rmax << " Minor Radius : " << Rmin <<"\n";
322
323 S << " Normal Axis : "; IGESData_DumpXYZL(S,level,ent->Axis(),ent->VectorLocation());
324 S << std::endl;
7fd59977 325 }
326}