1 //pdn 11.01.99 modification for linking on NT
2 //#73 rln 10.03.99 S4135: "read.scale.unit" does not affect GlobalSection
3 //#13 smh 13.01.2000 : Parsing long year date
4 #include <IGESData_IGESModel.ixx>
5 #include <TCollection_HAsciiString.hxx>
6 #include <IGESData_Protocol.hxx>
7 #include <IGESData_BasicEditor.hxx>
8 #include <Interface_Static.hxx>
9 #include <Interface_Macros.hxx>
10 #include <Message_Msg.hxx>
15 static Standard_CString voidline = "";
17 // Routine interne utilisee pour VerifyCheck
18 void IGESData_VerifyDate
19 (const Handle(TCollection_HAsciiString)& str,
20 Handle(Interface_Check)& ach, const Standard_CString mess);
24 //=======================================================================
25 //function : IGESData_IGESModel
27 //=======================================================================
29 IGESData_IGESModel::IGESData_IGESModel ()
31 thestart = new TColStd_HSequenceOfHAsciiString();
32 // thecheckstx = new Interface_Check;
33 // thechecksem = new Interface_Check;
37 //=======================================================================
38 //function : ClearHeader
40 //=======================================================================
42 void IGESData_IGESModel::ClearHeader ()
44 IGESData_GlobalSection newheader; // Un peu brutal, certes
45 theheader = newheader;
46 thestart = new TColStd_HSequenceOfHAsciiString();
50 //=======================================================================
51 //function : DumpHeader
53 //=======================================================================
55 void IGESData_IGESModel::DumpHeader
56 (const Handle(Message_Messenger)& S, const Standard_Integer ) const
58 Standard_Integer ns = thestart->Length();
59 S<<"**** Dump of IGES Model , Start and Global Sections ****"<<endl;
61 S << "**** Start Section : "<<ns<<" Line(s) ****"<<"\n";
62 for (Standard_Integer i = 1; i <= ns; i ++)
63 S<<"["<<(i<10 ? " ": "")<<i<<"]:"<<thestart->Value(i)->ToCString()<<endl;
65 S << "\n"<<"**** Global Section ****"<<"\n";
66 char sep = theheader.Separator();
67 if (sep == ',') S << "[ 1] Default Separator : " << sep;
68 else S << "[ 1] Non Default Separator : " << sep;
69 char emk = theheader.EndMark();
70 if (emk == ';') S << " [ 2] Default End Mark : " << emk;
71 else S << " [ 2] Non Default End Mark : " << emk;
73 Handle(TCollection_HAsciiString) str;
74 str = theheader.SendName();
75 if (!str.IsNull()) S<<"[ 3] Sender : "<<str->ToCString()<<endl;
76 str = theheader.FileName();
77 if (!str.IsNull()) S<<"[ 4] (recorded) File Name : "<<str->ToCString()<<endl;
78 str = theheader.SystemId();
79 if (!str.IsNull()) S<<"[ 5] System Identification : "<<str->ToCString()<<endl;
80 str = theheader.InterfaceVersion();
81 if (!str.IsNull()) S<<"[ 6] Interface Version : "<<str->ToCString()<<endl;
83 S << "[ 7] Integer Bits : " << theheader.IntegerBits()
84 << " Features for Reals : " << endl;
85 S << "[ 8] Single Max.Power(10) : " << theheader.MaxPower10Single();
86 S << " [ 9] Digits : " << theheader.MaxDigitsSingle()<<"\n";
87 S << "[10] Double Max.Power(10) : " << theheader.MaxPower10Double();
88 S << " [11] Digits : " << theheader.MaxDigitsDouble() << "\n\n";
89 str = theheader.ReceiveName();
90 if (!str.IsNull()) S<<"[12] Receiver : "<<str->ToCString()<<"\n";
91 S << "[13] Scale : " << theheader.Scale()<<"\n";
92 S << "[14] Unit Flag : " << theheader.UnitFlag();
93 // if (Interface_Static::IVal("read.scale.unit") == 1)
94 //#73 rln 10.03.99 S4135: "read.scale.unit" does not affect GlobalSection
95 // S << " -> Value (in Meter) = " << theheader.UnitValue() / 1000 <<"\n";
96 // else S << " -> Value (in Millimeter) = " << theheader.UnitValue()<<"\n";
97 //abv 02 Mar 00: no unit parameter in OCC
98 S << " -> Value (in CASCADE units) = " << theheader.UnitValue() <<"\n";
100 str = theheader.UnitName();
101 if (!str.IsNull()) S<<"[15] Unit Name : " << str->ToCString()<<"\n\n";
102 S << "[16] Line Weight Gradient : " << theheader.LineWeightGrad()<<"\n";
103 S << "[17] Line Weight Max Value: " << theheader.MaxLineWeight()<<"\n";
105 str = theheader.Date();
106 if (!str.IsNull()) S<<"[18] (Creation) Date : "<<str->ToCString()
107 <<" i.e. "<<IGESData_GlobalSection::NewDateString(str,1)->ToCString()<<"\n";
108 S << "[19] Resolution : " << theheader.Resolution()<<"\n";
109 if (theheader.HasMaxCoord())
110 S<<"[20] Maximum Coord : " << theheader.MaxCoord() << "\n\n";
111 else S<<"[20] Maximum Coord not defined"<<"\n\n";
113 str = theheader.AuthorName();
114 if (!str.IsNull()) S<<"[21] Author : "<<str->ToCString()<<"\n";
115 str = theheader.CompanyName();
116 if (!str.IsNull()) S<<"[22] Company : "<<str->ToCString()<<"\n";
117 Standard_Integer num = theheader.IGESVersion();
118 S << "[23] IGES Version Number : " << num << " -> Name : "
119 << IGESData_BasicEditor::IGESVersionName(num);
121 num = theheader.DraftingStandard();
122 S << "\n"<<"[24] Drafting Standard : " << num;
123 if (num > 0) S<< " -> Name : " << IGESData_BasicEditor::DraftingName(num);
126 if (theheader.HasLastChangeDate()) {
127 str = theheader.LastChangeDate();
128 S << "[25] Last Change Date : " << str->ToCString()
129 <<" i.e. "<<IGESData_GlobalSection::NewDateString(str,1)->ToCString()<<endl;
131 else S<<"[25] Last Change Date not defined (version IGES < 5.1)" << endl;
133 if (theheader.HasApplicationProtocol()) {
134 str = theheader.ApplicationProtocol();
135 S << "[26] Application Protocol : " << str->ToCString() <<endl;
138 S << " **** End of Dump ****"<<endl;
142 //=======================================================================
143 //function : StartSection
145 //=======================================================================
147 Handle(TColStd_HSequenceOfHAsciiString) IGESData_IGESModel::StartSection
152 //=======================================================================
153 //function : NbStartLines
155 //=======================================================================
157 Standard_Integer IGESData_IGESModel::NbStartLines () const
158 { return thestart->Length(); }
161 //=======================================================================
162 //function : StartLine
164 //=======================================================================
166 Standard_CString IGESData_IGESModel::StartLine
167 (const Standard_Integer num) const
169 if (num > 0 && num <= thestart->Length()) return
170 thestart->Value(num)->ToCString();
175 //=======================================================================
176 //function : ClearStartSection
178 //=======================================================================
180 void IGESData_IGESModel::ClearStartSection ()
181 { thestart->Clear(); }
183 void IGESData_IGESModel::SetStartSection
184 (const Handle(TColStd_HSequenceOfHAsciiString)& list,
185 const Standard_Boolean copy)
188 thestart = new TColStd_HSequenceOfHAsciiString();
189 if (list.IsNull()) return;
190 Standard_Integer i, nb = list->Length();
191 for (i = 1; i <= nb; i ++) thestart->Append
192 (new TCollection_HAsciiString(list->Value(i)->ToCString()));
194 else if (list.IsNull()) thestart = new TColStd_HSequenceOfHAsciiString();
195 else thestart = list;
199 //=======================================================================
200 //function : AddStartLine
202 //=======================================================================
204 void IGESData_IGESModel::AddStartLine
205 (const Standard_CString line, const Standard_Integer atnum)
207 if (atnum <= 0 || atnum > thestart->Length())
208 thestart->Append (new TCollection_HAsciiString(line));
209 else thestart->InsertBefore (atnum,new TCollection_HAsciiString(line));
214 //=======================================================================
215 //function : GlobalSection
217 //=======================================================================
219 const IGESData_GlobalSection& IGESData_IGESModel::GlobalSection () const
220 { return theheader; }
223 //=======================================================================
224 //function : SetGlobalSection
226 //=======================================================================
228 void IGESData_IGESModel::SetGlobalSection
229 (const IGESData_GlobalSection& header)
230 { theheader = header; }
233 //=======================================================================
234 //function : ApplyStatic
236 //=======================================================================
238 Standard_Boolean IGESData_IGESModel::ApplyStatic
239 (const Standard_CString param)
241 if (param[0] == '\0') {
242 //Standard_Boolean ret = Standard_True; //szv#4:S4163:12Mar99 not needed
243 ApplyStatic("receiver"); //szv#4:S4163:12Mar99 'ret =' not needed
244 ApplyStatic("author"); //szv#4:S4163:12Mar99 'ret =' not needed
245 ApplyStatic("company"); //szv#4:S4163:12Mar99 'ret =' not needed
246 return Standard_True;
249 Standard_CString val;
250 if (param[0] == 'r') {
251 val = Interface_Static::CVal("write.iges.header.receiver");
252 if (!val || val[0] == '\0') return Standard_False;
253 theheader.SetReceiveName (new TCollection_HAsciiString(val));
255 if (param[0] == 'a') {
256 val = Interface_Static::CVal("write.iges.header.author");
257 if (!val || val[0] == '\0') return Standard_False;
258 theheader.SetAuthorName (new TCollection_HAsciiString(val));
260 if (param[0] == 'c') {
261 val = Interface_Static::CVal("write.iges.header.company");
262 if (!val || val[0] == '\0') return Standard_False;
263 theheader.SetCompanyName (new TCollection_HAsciiString(val));
265 return Standard_True;
269 //=======================================================================
272 //=======================================================================
274 Handle(IGESData_IGESEntity) IGESData_IGESModel::Entity
275 (const Standard_Integer num) const
276 { return GetCasted(IGESData_IGESEntity,Value(num)); }
279 //=======================================================================
282 //=======================================================================
284 Standard_Integer IGESData_IGESModel::DNum
285 (const Handle(IGESData_IGESEntity)& ent) const
287 Standard_Integer num = Number(ent);
288 if (num == 0) return 0;
293 //=======================================================================
294 //function : GetFromAnother
296 //=======================================================================
298 void IGESData_IGESModel::GetFromAnother
299 (const Handle(Interface_InterfaceModel)& other)
301 DeclareAndCast(IGESData_IGESModel,another,other);
302 theheader = another->GlobalSection();
303 theheader.CopyRefs();
304 SetStartSection (another->StartSection(),Standard_True);
308 //=======================================================================
309 //function : NewEmptyModel
311 //=======================================================================
313 Handle(Interface_InterfaceModel) IGESData_IGESModel::NewEmptyModel () const
314 { return new IGESData_IGESModel; }
317 //=======================================================================
318 //function : VerifyCheck
320 //=======================================================================
322 void IGESData_IGESModel::VerifyCheck (Handle(Interface_Check)& ach) const
325 // =====================================
326 //Message_Msg Msg40 ("XSTEP_40");
327 //Message_Msg Msg41 ("XSTEP_41");
328 //Message_Msg Msg42 ("XSTEP_42");
329 //Message_Msg Msg43 ("XSTEP_43");
330 //Message_Msg Msg44 ("XSTEP_44");
331 //Message_Msg Msg45 ("XSTEP_45");
332 //Message_Msg Msg46 ("XSTEP_46");
333 //Message_Msg Msg47 ("XSTEP_47");
334 //Message_Msg Msg48 ("XSTEP_48");
335 //Message_Msg Msg50 ("XSTEP_50");
336 //Message_Msg Msg51 ("XSTEP_51");
337 //Message_Msg Msg52 ("XSTEP_52");
338 //Message_Msg Msg53 ("XSTEP_53");
339 //Message_Msg Msg54 ("XSTEP_54");
340 //Message_Msg Msg55 ("XSTEP_55");
341 // =====================================
344 del[0] = theheader.Separator();
345 del[1] = theheader.EndMark();
346 // Sending of message : Parameter Delimiter Character and Record Delimiter Character must be different.
347 if (del[0] == del[1]) {
348 Message_Msg Msg40 ("XSTEP_40");
349 ach->SendFail(Msg40);
351 for (int i = 0; i <= 1; i ++) {
352 if ( del[i] <= 32 || del[i] == 43 || del[i] == 45 || del[i] == 46 ||
353 (del[i] >= 48 && del[i] <= 57) || del[i] == 68 || del[i] == 69 ||
354 del [i] == 72 || del[i] >= 127) {
355 // Sending of message : Parameter Delimiter Character is incorrect.
357 Message_Msg Msg41 ("XSTEP_41");
358 ach->SendFail(Msg41);
360 // Sending of message : Character Record Delimiter parameter is incorrect.
362 Message_Msg Msg42 ("XSTEP_42");
363 ach->SendFail (Msg42);
367 // Sending of message : Single Precision Magnitude parameter is incorrect.
368 if (theheader.MaxPower10Single() <= 0) {
369 Message_Msg Msg43 ("XSTEP_43");
370 ach->SendFail(Msg43);
373 // Sending of message : Precision Significance parameter is incorrect.
374 if (theheader.MaxDigitsSingle() <= 0) {
375 Message_Msg Msg44 ("XSTEP_44");
376 ach->SendFail(Msg44);
379 // Sending of messages : Double Precision Magnitude parameter is incorrect.
380 if (theheader.MaxPower10Double() <= 0) {
381 Message_Msg Msg45 ("XSTEP_45");
382 ach->SendFail(Msg45);
385 // Sending of message : Double Precision Significance parameter is incorrect.
386 if (theheader.MaxDigitsDouble() <= 0) {
387 Message_Msg Msg46 ("XSTEP_46");
388 ach->SendFail(Msg46);
391 // Sending of message : Model Space Scale parameter is incorrect.
392 if (theheader.Scale() <= 0.) {
393 Message_Msg Msg47 ("XSTEP_47");
394 ach->SendFail(Msg47);
397 Standard_Integer unf = theheader.UnitFlag();
399 // Sending of message : Unit Flag parameter is incorrect.
400 if (unf < 1 || unf > 11) {
401 Message_Msg Msg48 ("XSTEP_48");
402 ach->SendFail(Msg48);
405 // .. verifie-t-on UnitName en accord avec UnitFlag ?
406 if (theheader.UnitName().IsNull()) {
407 // Sending of message : Unit Name parameter is undefined.
409 Message_Msg Msg50 ("XSTEP_50");
410 ach->SendFail(Msg50);
414 Standard_CString unm = theheader.UnitName()->ToCString();
415 Standard_Boolean unok = Standard_True;
417 case 1 : unok = (!strcmp(unm,"IN") || !strcmp(unm,"INCH")); break;
418 case 2 : unok = !strcmp(unm,"MM"); break;
419 case 3 : unok = Standard_True; break; // nom libre
420 case 4 : unok = !strcmp(unm,"FT"); break;
421 case 5 : unok = !strcmp(unm,"MI"); break;
422 case 6 : unok = !strcmp(unm,"M"); break;
423 case 7 : unok = !strcmp(unm,"KM"); break;
424 case 8 : unok = !strcmp(unm,"MIL"); break;
425 case 9 : unok = !strcmp(unm,"UM"); break;
426 case 10 : unok = !strcmp(unm,"CM"); break;
427 case 11 : unok = !strcmp(unm,"UIN"); break;
428 default : Message_Msg Msg48 ("XSTEP_48"); ach->SendFail(Msg48);
431 // Sending of message : Flag parameter doesn`t correspond to the Unit Name parameter.
433 Message_Msg Msg51 ("XSTEP_51");
434 ach->SendFail(Msg51);
438 IGESData_VerifyDate (theheader.Date(),ach,"Creation Date");
439 // Sending of message : Minimum Resolution parameter is incorrect.
440 if (theheader.Resolution() <= 0.) {
441 Message_Msg Msg52 ("XSTEP_52");
442 ach->SendFail(Msg52);
444 // .. comment verifier les coordonnees max ?
446 // Sending of message : Version Flag parameter is incorrect.
447 if (theheader.IGESVersion() < 1 ||
448 theheader.IGESVersion() > IGESData_BasicEditor::IGESVersionMax()) {
449 Message_Msg Msg53 ("XSTEP_53");
450 ach->SendWarning(Msg53);
453 // Sending of message : Drafting Standard Flag parameter is incorrect.
454 if (theheader.DraftingStandard() < 0 ||
455 theheader.DraftingStandard() > IGESData_BasicEditor::DraftingMax()) {
456 Message_Msg Msg54 ("XSTEP_54");
457 ach->SendWarning(Msg54);
460 // Sending of message :
461 if (theheader.IGESVersion() >= 9) {
462 // Sending of message : Last change Date parameter is undefined.
463 if (!theheader.HasLastChangeDate()) {
464 Message_Msg Msg55 ("XSTEP_55");
465 ach->SendWarning(Msg55);
467 else IGESData_VerifyDate (theheader.LastChangeDate(),ach,"Last Change Date");
472 void IGESData_VerifyDate(const Handle(TCollection_HAsciiString)& str,
473 Handle(Interface_Check)& ach,
474 const Standard_CString mess)
477 // =====================================
478 Message_Msg Msg57 ("XSTEP_57");
479 // =====================================
481 // Attention c est du Hollerith
483 { ach->SendFail(Msg57); return; }
485 Handle(TCollection_HAsciiString) stdvar = str;
486 if (strcmp(mess,"Last Change Date")==0)
490 if (((stdvar->Length() != 13) && (stdvar->Length() != 15)) || !stdvar->IsRealValue()) ach->SendFail(Msg57);
491 //smh#13 For short year date
492 else if ((stdvar->Value(3) > '1' ||
493 (stdvar->Value(3) == '1' && stdvar->Value(4) > '2'))&&(stdvar->Length() == 13)) ach->SendFail(Msg57);
495 else if ((stdvar->Value(5) > '3' ||
496 (stdvar->Value(5) == '3' && stdvar->Value(6) > '1'))&&(stdvar->Length() == 13)) ach->SendFail(Msg57);
497 else if ((stdvar->Value(7) != '.' || stdvar->Value(10) > '5' || stdvar->Value(12) > '5')&&(stdvar->Length() == 13))
498 ach->SendFail(Msg57);
499 else if ((stdvar->Value(8) > '2' ||
500 stdvar->Value(8) == '2' && stdvar->Value(9) > '3')&&(stdvar->Length() == 13)) ach->SendFail(Msg57);
501 //smh#13 For long year date
502 else if ( (stdvar->Value(5) > '1' ||
503 (stdvar->Value(5) == '1' && stdvar->Value(6) > '2'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
504 else if ((stdvar->Value(7) > '3' ||
505 (stdvar->Value(7) == '3' && stdvar->Value(8) > '1'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
506 else if ((stdvar->Value(9) != '.' || stdvar->Value(12) > '5' || stdvar->Value(14) > '5')&&(stdvar->Length() == 15))
507 ach->SendFail(Msg57);
508 else if ((stdvar->Value(10) > '2' ||
509 stdvar->Value(10) == '2' && stdvar->Value(11) > '3')&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
514 //=======================================================================
515 //function : SetLineWeights
517 //=======================================================================
519 void IGESData_IGESModel::SetLineWeights (const Standard_Real defw)
521 Standard_Integer nb = NbEntities();
522 Standard_Integer lwg = theheader.LineWeightGrad();
523 Standard_Real maxw = theheader.MaxLineWeight();
524 if (lwg > 0) { maxw = maxw/lwg; lwg = 1; }
525 for (Standard_Integer i = 1; i <= nb; i ++)
526 Entity(i)->SetLineWeight(defw,maxw,lwg);
530 //=======================================================================
531 //function : ClearLabels
533 //=======================================================================
535 void IGESData_IGESModel::ClearLabels ()
540 //=======================================================================
541 //function : PrintLabel
543 //=======================================================================
545 void IGESData_IGESModel::PrintLabel
546 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
548 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
549 if (igesent.IsNull()) S<<"Null";
551 Standard_Integer num = Number(ent);
552 if (num == 0) S<<"??";
553 else S<<"D"<<(2*num-1);
558 //=======================================================================
559 //function : PrintToLog
561 //=======================================================================
563 void IGESData_IGESModel::PrintToLog
564 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
566 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
567 if (!igesent.IsNull()) {
568 Standard_Integer num = Number(ent);
569 if (num == 0) S<<"??";
571 S<<" DE : "<<(2*num-1) << " type : " << igesent->TypeNumber();
572 // Standard_Integer num2 = igesent->TypeNumber();
578 //=======================================================================
579 //function : PrintInfo
581 //=======================================================================
583 void IGESData_IGESModel::PrintInfo
584 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
586 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
587 if (igesent.IsNull()) S<<"(NOT IGES)";
589 Standard_Integer num = Number(ent);
590 if (num == 0) S<<"??";
592 S<<(2*num-1) << "type " << Type(ent)->Name();
598 //=======================================================================
599 //function : StringLabel
601 //=======================================================================
603 Handle(TCollection_HAsciiString) IGESData_IGESModel::StringLabel(const Handle(Standard_Transient)& ent) const
605 Handle(TCollection_HAsciiString) label;
606 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
607 if (igesent.IsNull()) return new TCollection_HAsciiString("(NOT IGES)");
610 Standard_Integer num = Number(ent);
611 if (num > 0) sprintf(text,"D%d",2*num-1);
612 else sprintf(text,"D0...");
613 label = new TCollection_HAsciiString(text);