summaryrefslogtreecommitdiff
path: root/src/IGESGeom/IGESGeom_ToolConicArc.cxx
blob: 458d122192899f6efb3f42398548e66e35d7683a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//--------------------------------------------------------------------
//
//  File Name : IGESGeom_ConicArc.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------

#include <IGESGeom_ToolConicArc.ixx>
#include <IGESData_ParamCursor.hxx>
#include <gp_XY.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Dir2d.hxx>
#include <IGESData_Dump.hxx>
#include <Interface_MSG.hxx>
#include <Interface_Macros.hxx>
#include <stdio.h>

// MGE 28/07/98
#include <Message_Msg.hxx>

//=======================================================================
//function : IGESGeom_ToolConicArc
//purpose  : 
//=======================================================================

IGESGeom_ToolConicArc::IGESGeom_ToolConicArc ()
{
}


//=======================================================================
//function : ReadOwnParams
//purpose  : 
//=======================================================================

void IGESGeom_ToolConicArc::ReadOwnParams(const Handle(IGESGeom_ConicArc)& ent,
                                          const Handle(IGESData_IGESReaderData)& /* IR */,
                                          IGESData_ParamReader& PR) const
{
  // MGE 28/07/98
  // Building of messages
  //======================================
  Message_Msg Msg83("XSTEP_83");
  Message_Msg Msg84("XSTEP_84");
  //======================================

  //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
  Standard_Real A = 0.0, B = 0.0, C = 0.0, D = 0.0, E = 0.0, F = 0.0, ZT = 0.0;
  gp_XY tempStart, tempEnd;

 /* PR.ReadReal(PR.Current(), Msg81, A); //szv#4:S4163:12Mar99 `st=` not needed
  PR.ReadReal(PR.Current(), Msg81, B); //szv#4:S4163:12Mar99 `st=` not needed
  PR.ReadReal(PR.Current(), Msg81, C); //szv#4:S4163:12Mar99 `st=` not needed
  PR.ReadReal(PR.Current(), Msg81, D); //szv#4:S4163:12Mar99 `st=` not needed
  PR.ReadReal(PR.Current(), Msg81, E); //szv#4:S4163:12Mar99 `st=` not needed
  PR.ReadReal(PR.Current(), Msg81, F); //szv#4:S4163:12Mar99 `st=` not needed
  */
  if ((!PR.ReadReal(PR.Current(),A)) || (!PR.ReadReal(PR.Current(),B)) ||
      (!PR.ReadReal(PR.Current(),C)) || (!PR.ReadReal(PR.Current(),D)) ||
      (!PR.ReadReal(PR.Current(),E)) || (!PR.ReadReal(PR.Current(),F))){
    Message_Msg Msg81("XSTEP_81");
    PR.SendFail(Msg81);
  }

  if (!PR.ReadReal(PR.Current(), ZT)){ //szv#4:S4163:12Mar99 `st=` not needed
    Message_Msg Msg82("XSTEP_82");
    PR.SendFail(Msg82);
  }
  PR.ReadXY(PR.CurrentList(1, 2),Msg83, tempStart); //szv#4:S4163:12Mar99 `st=` not needed
  PR.ReadXY(PR.CurrentList(1, 2), Msg84, tempEnd); //szv#4:S4163:12Mar99 `st=` not needed

/*
  st = PR.ReadReal(PR.Current(), "Conic Coefficient A", A);
  st = PR.ReadReal(PR.Current(), "Conic Coefficient B", B);
  st = PR.ReadReal(PR.Current(), "Conic Coefficient C", C);
  st = PR.ReadReal(PR.Current(), "Conic Coefficient D", D);
  st = PR.ReadReal(PR.Current(), "Conic Coefficient E", E);
  st = PR.ReadReal(PR.Current(), "Conic Coefficient F", F);
  st = PR.ReadReal(PR.Current(), "Z-plane shift", ZT);
  st = PR.ReadXY(PR.CurrentList(1, 2), "Starting Point Of Arc", tempStart);
  st = PR.ReadXY(PR.CurrentList(1, 2), "End Point Of Arc", tempEnd);
*/
  DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
  ent->Init(A, B, C, D, E, F, ZT, tempStart, tempEnd);
}


//=======================================================================
//function : WriteOwnParams
//purpose  : 
//=======================================================================

void IGESGeom_ToolConicArc::WriteOwnParams(const Handle(IGESGeom_ConicArc)& ent,
                                           IGESData_IGESWriter& IW)  const
{
  Standard_Real A,B,C,D,E,F;
  ent->Equation(A,B,C,D,E,F);
  IW.Send(A);
  IW.Send(B);
  IW.Send(C);
  IW.Send(D);
  IW.Send(E);
  IW.Send(F);
  IW.Send(ent->ZPlane());
  IW.Send(ent->StartPoint().X());
  IW.Send(ent->StartPoint().Y());
  IW.Send(ent->EndPoint().X());
  IW.Send(ent->EndPoint().Y());
}


//=======================================================================
//function : OwnShared
//purpose  : 
//=======================================================================

void IGESGeom_ToolConicArc::OwnShared(const Handle(IGESGeom_ConicArc)& /* ent */,
                                      Interface_EntityIterator& /* iter */) const
{
}


//=======================================================================
//function : OwnCopy
//purpose  : 
//=======================================================================

void IGESGeom_ToolConicArc::OwnCopy(const Handle(IGESGeom_ConicArc)& another,
                                    const Handle(IGESGeom_ConicArc)& ent,
                                    Interface_CopyTool& /* TC */) const
{
  Standard_Real A,B,C,D,E,F;
  another->Equation(A,B,C,D,E,F);
  ent->Init(A, B, C, D, E, F, another->ZPlane(),
	    another->StartPoint().XY(), another->EndPoint().XY());
}


//=======================================================================
//function : OwnCorrect
//purpose  : 
//=======================================================================

Standard_Boolean IGESGeom_ToolConicArc::OwnCorrect
  (const Handle(IGESGeom_ConicArc)& ent) const
{
  return ent->OwnCorrect();    //  form selon coefs. 1 Ellipse, 2 Hyper, 3 Para
}


//=======================================================================
//function : DirChecker
//purpose  : 
//=======================================================================

IGESData_DirChecker IGESGeom_ToolConicArc::DirChecker
  (const Handle(IGESGeom_ConicArc)& /* ent */ )  const
{
  IGESData_DirChecker DC(104, 0, 3);
  DC.Structure(IGESData_DefVoid);
  DC.GraphicsIgnored();
  DC.LineFont(IGESData_DefAny);
//  DC.LineWeight(IGESData_DefValue);
  DC.Color(IGESData_DefAny);
  DC.HierarchyStatusIgnored();
  return DC;
}


//=======================================================================
//function : OwnCheck
//purpose  : 
//=======================================================================

void IGESGeom_ToolConicArc::OwnCheck(const Handle(IGESGeom_ConicArc)& ent,
                                     const Interface_ShareTool&,
                                     Handle(Interface_Check)& ach)  const
{
  // MGE 28/07/98
  // Building of messages
  //=====================================
  //Message_Msg Msg71("XSTEP_71"); 
  //=====================================

  //char mess[80]; //szv#4:S4163:12Mar99 not needed
  Standard_Integer cfn = ent->ComputedFormNumber();
  Standard_Integer  fn = ent->FormNumber();
  if (cfn == 0) {}
    // ach.AddFail("Coefficients do not define correctly a Conic");
  else if (fn != 0 && fn != cfn) {
    Message_Msg Msg71("XSTEP_71"); 
    ach->SendFail(Msg71);
  }
  
  //szv#4:S4163:12Mar99 not needed
  //if (ach.HasFailed()) return;    // les tests suivant deviennent sans objet
  //Standard_Real eps = 1.E-04;     // Tolerance des Tests ??
  //Standard_Real A,B,C,D,E,F;
  //ent->Equation(A,B,C,D,E,F);
  //Standard_Real x = ent->StartPoint().X();
  //Standard_Real y = ent->StartPoint().Y();
  //Standard_Real eq = (A*x*x + B*x*y + C*y*y + D*x + E*y + F);
  // These messages are transfered in the translation procedure
/*  if (eq < -eps || eq > eps) {
    sprintf(mess,"Start point does not satisfy conic equation, gap over %f",
	    Interface_MSG::Intervalled(eq));
    ach.AddFail(mess,"Start point does not satisfy conic equation, gap over %f");

  }
*/
  //szv#4:S4163:12Mar99 not needed
  //x = ent->EndPoint().X();
  //y = ent->EndPoint().Y();
  //eq = (A*x*x + B*x*y + C*y*y + D*x + E*y + F);
/*  if (eq < -eps || eq > eps) {
    sprintf(mess,"End point does not satisfy conic equation, gap over %f",
	    Interface_MSG::Intervalled(eq));
    ach.AddFail(mess,"End point does not satisfy conic equation, gap over %f");
  }
*/
/*   Les tests qui suivant ont-ils un sens ??
  if (ent->FormNumber() == 2)    // Hyperbola
    {
      Standard_Real xc = -D / (2 * A);
      Standard_Real yc = -E / (2 * C);
      gp_Dir2d d0(1, 0);
      gp_Dir2d d1(ent->StartPoint().X() - xc, ent->StartPoint().Y() - yc);
      gp_Dir2d d2(ent->EndPoint().X()   - xc, ent->EndPoint().Y()   - yc);
      Standard_Real t1 = d0.Angle(d1);
      Standard_Real t2 = d0.Angle(d2);
      t1 += (t1  >  0 ? 0 : 2*PI);
      t2 += (t2  >  0 ? 0 : 2*PI);
      t2 += (t1 <= t2 ? 0 : 2*PI);
      if ( !(0 <= t1 && t1 <= 2*PI) || !(0 <= t2-t1 && t2-t1 <= 2*PI) )
	ach.AddFail("Parameter Error for Hyperbola");
    }
  else if (ent->FormNumber() == 3)
    {
      Standard_Real xc = -D / (2 * A);
      Standard_Real yc = -E / (2 * C);
      gp_Dir2d d0(1, 0);
      gp_Dir2d d1(ent->StartPoint().X() - xc, ent->StartPoint().Y() - yc);
      gp_Dir2d d2(ent->EndPoint().X()   - xc, ent->EndPoint().Y()   - yc);
      Standard_Real t1 = d0.Angle(d1);
      Standard_Real t2 = d0.Angle(d2);
      if ( !(-PI/2 < t1 && t1 < PI/2) || !(-PI/2 < t2 && t2 < PI/2) )
	ach.AddFail("Parameter Error for Parabola");
    }
*/
}


//=======================================================================
//function : OwnDump
//purpose  : 
//=======================================================================

void IGESGeom_ToolConicArc::OwnDump(const Handle(IGESGeom_ConicArc)& ent,
                                    const IGESData_IGESDumper& /* dumper */,
                                    const Handle(Message_Messenger)& S,
                                    const Standard_Integer level)  const
{
  Standard_Real A,B,C,D,E,F;
  ent->Equation(A,B,C,D,E,F);
  S << "IGESGeom_ConicArc" << endl;
  Standard_Integer cf = ent->FormNumber();
  if (cf == 0) cf = ent->ComputedFormNumber();
  if (cf == 1)      S << " --     Ellipse     --" << endl;
  else if (cf == 2) S << " --    Hyperbola    --" << endl;
  else if (cf == 3) S << " --    Parabola    --"  << endl;
  else              S << " --    (Undetermined type of Conic)    --" << endl;
  S << "Conic Coefficient A : " << A << endl;
  S << "Conic Coefficient B : " << B << endl;
  S << "Conic Coefficient C : " << C << endl;
  S << "Conic Coefficient D : " << D << endl;
  S << "Conic Coefficient E : " << E << endl;
  S << "Conic Coefficient F : " << F << endl;
  S << "Z-Plane shift : " << ent->ZPlane() << endl;
  S << "Start Point : ";
  IGESData_DumpXYLZ(S,level, ent->StartPoint(), ent->Location(),ent->ZPlane());
  S << endl;
  S << "End   Point : ";
  IGESData_DumpXYLZ(S,level, ent->EndPoint(), ent->Location(), ent->ZPlane());
  S << endl;
  if (level <= 4) S<<" -- Computed Definition : ask level > 4" << endl;
  else {
    gp_Pnt Cen;  gp_Dir Ax;  Standard_Real Rmin,Rmax;
    ent->Definition (Cen,Ax,Rmin,Rmax);
    S << " -- Computed Definition (and Transformed if level > 5)" << endl;

    if (cf != 3) {
      S<<" Center        : "; IGESData_DumpXYZL(S,level,Cen,ent->Location());
      S<<endl;
    }
    S << " Main Axis   : "; IGESData_DumpXYZL(S,level,Ax,ent->VectorLocation());
    S<<endl;
    if (cf == 3) S << " Focal : " << Rmin << endl;
    else if (Rmin == Rmax) S << " Radius (Major = Minor) : " << Rmin << endl;
    else S << " Major Radius : " << Rmax << "  Minor Radius : " << Rmin <<endl;
    S<< "  Normal Axis : ";  IGESData_DumpXYZL(S,level,ent->Axis(),ent->VectorLocation());
    S << endl;
  }
}