1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
20 //--------------------------------------------------------------------
21 //--------------------------------------------------------------------
23 #include <IGESGeom_ToolConicArc.ixx>
24 #include <IGESData_ParamCursor.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>
34 #include <Message_Msg.hxx>
36 //=======================================================================
37 //function : IGESGeom_ToolConicArc
39 //=======================================================================
41 IGESGeom_ToolConicArc::IGESGeom_ToolConicArc ()
46 //=======================================================================
47 //function : ReadOwnParams
49 //=======================================================================
51 void IGESGeom_ToolConicArc::ReadOwnParams(const Handle(IGESGeom_ConicArc)& ent,
52 const Handle(IGESData_IGESReaderData)& /* IR */,
53 IGESData_ParamReader& PR) const
56 // Building of messages
57 //======================================
58 Message_Msg Msg83("XSTEP_83");
59 Message_Msg Msg84("XSTEP_84");
60 //======================================
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;
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
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");
80 if (!PR.ReadReal(PR.Current(), ZT)){ //szv#4:S4163:12Mar99 `st=` not needed
81 Message_Msg Msg82("XSTEP_82");
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
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);
98 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
99 ent->Init(A, B, C, D, E, F, ZT, tempStart, tempEnd);
103 //=======================================================================
104 //function : WriteOwnParams
106 //=======================================================================
108 void IGESGeom_ToolConicArc::WriteOwnParams(const Handle(IGESGeom_ConicArc)& ent,
109 IGESData_IGESWriter& IW) const
111 Standard_Real A,B,C,D,E,F;
112 ent->Equation(A,B,C,D,E,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());
127 //=======================================================================
128 //function : OwnShared
130 //=======================================================================
132 void IGESGeom_ToolConicArc::OwnShared(const Handle(IGESGeom_ConicArc)& /* ent */,
133 Interface_EntityIterator& /* iter */) const
138 //=======================================================================
141 //=======================================================================
143 void IGESGeom_ToolConicArc::OwnCopy(const Handle(IGESGeom_ConicArc)& another,
144 const Handle(IGESGeom_ConicArc)& ent,
145 Interface_CopyTool& /* TC */) const
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());
154 //=======================================================================
155 //function : OwnCorrect
157 //=======================================================================
159 Standard_Boolean IGESGeom_ToolConicArc::OwnCorrect
160 (const Handle(IGESGeom_ConicArc)& ent) const
162 return ent->OwnCorrect(); // form selon coefs. 1 Ellipse, 2 Hyper, 3 Para
166 //=======================================================================
167 //function : DirChecker
169 //=======================================================================
171 IGESData_DirChecker IGESGeom_ToolConicArc::DirChecker
172 (const Handle(IGESGeom_ConicArc)& /* ent */ ) const
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();
185 //=======================================================================
186 //function : OwnCheck
188 //=======================================================================
190 void IGESGeom_ToolConicArc::OwnCheck(const Handle(IGESGeom_ConicArc)& ent,
191 const Interface_ShareTool&,
192 Handle(Interface_Check)& ach) const
195 // Building of messages
196 //=====================================
197 //Message_Msg Msg71("XSTEP_71");
198 //=====================================
200 //char mess[80]; //szv#4:S4163:12Mar99 not needed
201 Standard_Integer cfn = ent->ComputedFormNumber();
202 Standard_Integer fn = ent->FormNumber();
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);
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) {
220 Sprintf(mess,"Start point does not satisfy conic equation, gap over %f",
221 Interface_MSG::Intervalled(eq));
222 ach.AddFail(mess,"Start point does not satisfy conic equation, gap over %f");
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) {
231 Sprintf(mess,"End point does not satisfy conic equation, gap over %f",
232 Interface_MSG::Intervalled(eq));
233 ach.AddFail(mess,"End point does not satisfy conic equation, gap over %f");
236 /* Les tests qui suivant ont-ils un sens ??
237 if (ent->FormNumber() == 2) // Hyperbola
239 Standard_Real xc = -D / (2 * A);
240 Standard_Real yc = -E / (2 * C);
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);
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) )
250 ach.AddFail("Parameter Error for Hyperbola");
252 else if (ent->FormNumber() == 3)
254 Standard_Real xc = -D / (2 * A);
255 Standard_Real yc = -E / (2 * C);
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);
261 if ( !(-M_PI/2 < t1 && t1 < M_PI/2) || !(-M_PI/2 < t2 && t2 < M_PI/2) )
262 ach.AddFail("Parameter Error for Parabola");
268 //=======================================================================
271 //=======================================================================
273 void 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
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());
298 IGESData_DumpXYLZ(S,level, ent->EndPoint(), ent->Location(), ent->ZPlane());
300 if (level <= 4) S<<" -- Computed Definition : ask level > 4" << endl;
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;
307 S<<" Center : "; IGESData_DumpXYZL(S,level,Cen,ent->Location());
310 S << " Main Axis : "; IGESData_DumpXYZL(S,level,Ax,ent->VectorLocation());
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());