summaryrefslogtreecommitdiff
path: root/src/IGESGeom/IGESGeom_ToolOffsetCurve.cxx
blob: 835fe8b2231a4d44b823a70f828f06f5585abf29 (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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
//--------------------------------------------------------------------
//
//  File Name : IGESGeom_OffsetCurve.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------
//:l9 abv 15.01.99: CTS22023 and TEC0278: issue data fail on offset tapered flag 
// only if type is not constant

#include <IGESGeom_ToolOffsetCurve.ixx>
#include <IGESData_ParamCursor.hxx>
#include <gp_XYZ.hxx>
#include <gp_Vec.hxx>
#include <IGESData_IGESEntity.hxx>
#include <IGESData_Dump.hxx>
#include <Interface_Macros.hxx>

// MGE 30/07/98
#include <Message_Msg.hxx>
#include <IGESData_Status.hxx>

//=======================================================================
//function : IGESGeom_ToolOffsetCurve
//purpose  : 
//=======================================================================

IGESGeom_ToolOffsetCurve::IGESGeom_ToolOffsetCurve ()
{
}


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

void IGESGeom_ToolOffsetCurve::ReadOwnParams(const Handle(IGESGeom_OffsetCurve)& ent,
                                             const Handle(IGESData_IGESReaderData)& IR,
                                             IGESData_ParamReader& PR) const
{
  // MGE 30/07/98
  // Building of messages
  //========================================
  Message_Msg Msg121("XSTEP_121");
  //========================================

  Standard_Integer anOffsetType, aFunctionCoord, aTaperedOffsetType; 
  Standard_Real offDistance1, offDistance2;
  Standard_Real arcLength1, arcLength2, anOffsetParam, anotherOffsetParam;
  gp_XYZ aNormalVec;
  Handle(IGESData_IGESEntity) aBaseCurve;
  Handle(IGESData_IGESEntity) aFunction;
  IGESData_Status aStatus;
  //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed

  // Reading the curve entity to be offset
  if (!PR.ReadEntity(IR, PR.Current(), aStatus, aBaseCurve)){
    Message_Msg Msg110("XSTEP_110");
    switch(aStatus) {
    case IGESData_ReferenceError: {  
      Message_Msg Msg216 ("IGES_216");
      Msg110.Arg(Msg216.Value());
      PR.SendFail(Msg110);
      break; }
    case IGESData_EntityError: {
      Message_Msg Msg217 ("IGES_217");
      Msg110.Arg(Msg217.Value());
      PR.SendFail(Msg110);
      break; }
    default:{
    }
    }
  } //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadEntity(IR, PR.Current(), "Curve to be offset", aBaseCurve);

  // Reading the offset distance flag
  if (!PR.ReadInteger(PR.Current(), anOffsetType)){ //szv#4:S4163:12Mar99 `st=` not needed
    Message_Msg Msg111("XSTEP_111");
    PR.SendFail(Msg111);
  }
  //st = PR.ReadInteger(PR.Current(), "Offset Distance Flag", anOffsetType);

  // Reading the curve entity describing the offset as a function, can be Null
  if (!PR.ReadEntity(IR, PR.Current(), aStatus, aFunction, Standard_True)){
    Message_Msg Msg112("XSTEP_112");
    switch(aStatus) {
    case IGESData_ReferenceError: {  
      Message_Msg Msg216 ("IGES_216");
      Msg112.Arg(Msg216.Value());
      PR.SendFail(Msg112);
      break; }
    case IGESData_EntityError: {
      Message_Msg Msg217 ("IGES_217");
      Msg112.Arg(Msg217.Value());
      PR.SendFail(Msg112);
      break; }
    default:{
    }
    }
  } //szv#4:S4163:12Mar99 `st=` not needed
/*
  st = PR.ReadEntity(IR, PR.Current(), "Curve whose coordinate describes the offset", aFunction, Standard_True);
*/

  // Reading the coordinate describing the offset as a function
  if (!PR.ReadInteger(PR.Current(), aFunctionCoord)){ //szv#4:S4163:12Mar99 `st=` not needed
    Message_Msg Msg113("XSTEP_113");
    PR.SendFail(Msg113);
  }
  //st = PR.ReadInteger(PR.Current(), "Coordinate of the curve", aFunctionCoord);

  // Reading the tapered offset type flag
  if (!PR.ReadInteger(PR.Current(), aTaperedOffsetType)){ //szv#4:S4163:12Mar99 `st=` not needed
    Message_Msg Msg114("XSTEP_114");
    PR.SendFail(Msg114);
  }
  //st = PR.ReadInteger(PR.Current(), "Tapered offset type flag", aTaperedOffsetType);

  // Reading the first offset distance
  if (!PR.ReadReal(PR.Current(), offDistance1)){
    Message_Msg Msg115("XSTEP_115");
    PR.SendFail(Msg115);
  } //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadReal(PR.Current(), "First Offset distance", offDistance1);

  // Reading the arc length or parameter value of the first offset distance
  if (!PR.ReadReal(PR.Current(), arcLength1)){
    Message_Msg Msg116("XSTEP_116");
    PR.SendFail(Msg116);
  } //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadReal(PR.Current(), "Arc length of first offset distance", arcLength1);

  // Reading the second offset distance
  if (!PR.ReadReal(PR.Current(),offDistance2)){
    Message_Msg Msg117("XSTEP_117");
    PR.SendFail(Msg117);
  } //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadReal(PR.Current(), "Second Offset distance", offDistance2);

  // Reading the arc length or parameter value of the second offset distance
  if (!PR.ReadReal(PR.Current(), arcLength2)){
    Message_Msg Msg118("XSTEP_118");
    PR.SendFail(Msg118);
  } //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadReal(PR.Current(), "Arc length of Second offset distance", arcLength2);

  // Reading the Unit vector normal to plane
  PR.ReadXYZ (PR.CurrentList(1, 3), Msg121, aNormalVec); //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadXYZ (PR.CurrentList(1, 3), "Unit vector normal to plane", aNormalVec);

  // Reading the offset curve starting parameter value
  if (!PR.ReadReal(PR.Current(), anOffsetParam)){
    Message_Msg Msg119("XSTEP_119");
    PR.SendFail(Msg119);
  } //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadReal(PR.Current(), "Starting parameter value of Offset curve", anOffsetParam);

  // Reading the offset curve ending parameter value
  if (!PR.ReadReal(PR.Current(), anotherOffsetParam)){
    Message_Msg Msg120("XSTEP_120");
    PR.SendFail(Msg120);
  } //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadReal(PR.Current(), "Ending parameter value of Offset curve", anotherOffsetParam);

  // Reading the Unit vector normal to plane
  PR.ReadXYZ (PR.CurrentList(1, 3), Msg121, aNormalVec); //szv#4:S4163:12Mar99 `st=` not needed
  //st = PR.ReadXYZ (PR.CurrentList(1, 3), "Unit vector normal to plane", aNormalVec);

  DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
  ent->Init
    (aBaseCurve, anOffsetType, aFunction, aFunctionCoord,
     aTaperedOffsetType, offDistance1, arcLength1, offDistance2,
     arcLength2, aNormalVec, anOffsetParam, anotherOffsetParam);
}


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

void IGESGeom_ToolOffsetCurve::WriteOwnParams(const Handle(IGESGeom_OffsetCurve)& ent,
                                              IGESData_IGESWriter& IW)  const
{
  IW.Send(ent->BaseCurve());
  IW.Send(ent->OffsetType());

  IW.Send(ent->Function());

  IW.Send(ent->FunctionParameter());
  IW.Send(ent->TaperedOffsetType());
  IW.Send(ent->FirstOffsetDistance());
  IW.Send(ent->ArcLength1());
  IW.Send(ent->SecondOffsetDistance());
  IW.Send(ent->ArcLength2());
  IW.Send(ent->NormalVector().X());
  IW.Send(ent->NormalVector().Y());
  IW.Send(ent->NormalVector().Z());
  IW.Send(ent->StartParameter());
  IW.Send(ent->EndParameter());
}


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

void IGESGeom_ToolOffsetCurve::OwnShared(const Handle(IGESGeom_OffsetCurve)& ent,
                                         Interface_EntityIterator& iter) const
{
  iter.GetOneItem(ent->BaseCurve());
  iter.GetOneItem(ent->Function());
}


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

void IGESGeom_ToolOffsetCurve::OwnCopy(const Handle(IGESGeom_OffsetCurve)& another,
                                       const Handle(IGESGeom_OffsetCurve)& ent,
                                       Interface_CopyTool& TC) const
{
  Standard_Integer anOffsetType, aFunctionCoord, aTaperedOffsetType; 
  Standard_Real offDistance1, offDistance2;
  Standard_Real arcLength1, arcLength2, anOffsetParam1, anOffsetParam2;

  DeclareAndCast(IGESData_IGESEntity, aBaseCurve,
		 TC.Transferred(another->BaseCurve()));
  anOffsetType   = another->OffsetType();
  DeclareAndCast(IGESData_IGESEntity, aFunction,
		 TC.Transferred(another->Function()));
  aFunctionCoord = another->FunctionParameter();
  aTaperedOffsetType = another->TaperedOffsetType();
  offDistance1   = another->FirstOffsetDistance();
  arcLength1     = another->ArcLength1();
  offDistance2   = another->SecondOffsetDistance();
  arcLength2     = another->ArcLength2();
  gp_XYZ aNormalVec = (another->NormalVector()).XYZ();
  anOffsetParam1 = another->StartParameter();
  anOffsetParam2 = another->EndParameter();

  ent->Init(aBaseCurve, anOffsetType, aFunction, aFunctionCoord,
	    aTaperedOffsetType, offDistance1, arcLength1, offDistance2,
	    arcLength2, aNormalVec, anOffsetParam1, anOffsetParam2);
}


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

Standard_Boolean IGESGeom_ToolOffsetCurve::OwnCorrect
  (const Handle(IGESGeom_OffsetCurve)& ent) const
{
  if (ent->OffsetType() == 3) return Standard_False;
  Handle(IGESData_IGESEntity) func = ent->Function();
  if (func.IsNull()) return Standard_False;
//  OffsetType != 3 : reconstruire avec Offset Function Nulle
  func.Nullify();
  ent->Init (ent->BaseCurve(), ent->OffsetType(), func,0,  // func+coord Nuls
	     ent->TaperedOffsetType(),
	     ent->FirstOffsetDistance(),  ent->ArcLength1(),
	     ent->SecondOffsetDistance(), ent->ArcLength2(),
	     ent->NormalVector().XYZ(),
	     ent->StartParameter(), ent->EndParameter() );
  return Standard_True;
}


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

IGESData_DirChecker IGESGeom_ToolOffsetCurve::DirChecker
  (const Handle(IGESGeom_OffsetCurve)& /* ent */ )   const
{
  IGESData_DirChecker DC(130, 0);
  DC.Structure(IGESData_DefVoid);
  DC.LineFont(IGESData_DefAny);
//  DC.LineWeight(IGESData_DefValue);
  DC.Color(IGESData_DefAny);
  DC.HierarchyStatusIgnored();
  return DC;
}


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

void IGESGeom_ToolOffsetCurve::OwnCheck(const Handle(IGESGeom_OffsetCurve)& ent,
                                        const Interface_ShareTool&,
                                        Handle(Interface_Check)& ach)  const
{
  // MGE 30/07/98
  // Building of messages
  //========================================
  //Message_Msg Msg111("XSTEP_111");
  //Message_Msg Msg114("XSTEP_114");
  //========================================

  Standard_Integer ot = ent->OffsetType();
  if (ot < 1 || ot > 3) {
    Message_Msg Msg111("XSTEP_111");
    ach->SendFail(Msg111);
  }
/*  if (ot == 3)  if (ent->Function().IsNull())
    ach.SendFail("Offset Function Not Defined while Offset Type = 3");
  if (ot == 3 && (ent->FunctionParameter() < 1 || ent->FunctionParameter() > 3))
    ach.SendFail("Offset Function Parameter != 1-2 or 3 (rq : for X-Y or Z)");
*/
  if (ot !=1 && //:l9 abv 15.01.99: CTS22023 and TEC0278: only if ot is function
      (ent->TaperedOffsetType() < 1) || (ent->TaperedOffsetType() > 2)) {
    Message_Msg Msg114("XSTEP_114");
    ach->SendFail(Msg114);
  }
}


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

void IGESGeom_ToolOffsetCurve::OwnDump(const Handle(IGESGeom_OffsetCurve)& ent,
                                       const IGESData_IGESDumper& dumper,
                                       const Handle(Message_Messenger)& S,
                                       const Standard_Integer level)  const
{
  Standard_Integer sublevel = (level <= 4) ? 0 : 1;

  S << "IGESGeom_OffsetCurve" << endl;

  S << "The curve to be offset     : " << endl;
  dumper.Dump(ent->BaseCurve(),S, sublevel);
  S << "Offset Distance Flag       : " << ent->OffsetType() << endl;
  S << "Curve entity whose coordinate defines the offset : ";
  dumper.Dump(ent->Function(),S, sublevel);
  S << endl;
  S << "In which Coordinate to use : " << ent->FunctionParameter()    << endl;
  S << "Tapered Offset Type Flag   : " << ent->TaperedOffsetType()    << endl;
  S << "First Offset Distance      : " << ent->FirstOffsetDistance()  << "  ";
  S << "Arc Length : " << ent->ArcLength1() << endl;
  S << "Second Offset Distance     : " << ent->SecondOffsetDistance() << "  ";
  S << "Arc Length : " << ent->ArcLength2() << endl;
  S << "Normal Vector : ";
  IGESData_DumpXYZL(S,level, ent->NormalVector(), ent->VectorLocation());  S<<endl;
  S << "Offset curve Parameters. Starting : " << ent->StartParameter() << "  ";
  S << "Ending : " << ent->EndParameter()   << endl;
}