1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //pdn 11.01.99 modification for linking on NT
15 //#73 rln 10.03.99 S4135: "read.scale.unit" does not affect GlobalSection
16 //#13 smh 13.01.2000 : Parsing long year date
18 #include <IGESData_BasicEditor.hxx>
19 #include <IGESData_GlobalSection.hxx>
20 #include <IGESData_IGESEntity.hxx>
21 #include <IGESData_IGESModel.hxx>
22 #include <IGESData_Protocol.hxx>
23 #include <Interface_Check.hxx>
24 #include <Interface_InterfaceError.hxx>
25 #include <Interface_InterfaceModel.hxx>
26 #include <Interface_Macros.hxx>
27 #include <Interface_Static.hxx>
28 #include <Message_Msg.hxx>
29 #include <Standard_Transient.hxx>
30 #include <Standard_Type.hxx>
31 #include <TCollection_HAsciiString.hxx>
34 IMPLEMENT_STANDARD_RTTIEXT(IGESData_IGESModel,Interface_InterfaceModel)
36 static Standard_CString voidline = "";
38 // Routine interne utilisee pour VerifyCheck
39 void IGESData_VerifyDate
40 (const Handle(TCollection_HAsciiString)& str,
41 Handle(Interface_Check)& ach, const Standard_CString mess);
45 //=======================================================================
46 //function : IGESData_IGESModel
48 //=======================================================================
50 IGESData_IGESModel::IGESData_IGESModel ()
52 thestart = new TColStd_HSequenceOfHAsciiString();
53 // thecheckstx = new Interface_Check;
54 // thechecksem = new Interface_Check;
58 //=======================================================================
59 //function : ClearHeader
61 //=======================================================================
63 void IGESData_IGESModel::ClearHeader ()
65 IGESData_GlobalSection newheader; // Un peu brutal, certes
66 theheader = newheader;
67 thestart = new TColStd_HSequenceOfHAsciiString();
71 //=======================================================================
72 //function : DumpHeader
74 //=======================================================================
76 void IGESData_IGESModel::DumpHeader
77 (Standard_OStream& S, const Standard_Integer ) const
79 Standard_Integer ns = thestart->Length();
80 S <<"**** Dump of IGES Model , Start and Global Sections ****"<<std::endl;
82 S << "**** Start Section : "<<ns<<" Line(s) ****\n";
83 for (Standard_Integer i = 1; i <= ns; i ++)
84 S <<"["<<(i<10 ? " ": "")<<i<<"]:"<<thestart->Value(i)->ToCString()<<std::endl;
86 S << "\n**** Global Section ****\n";
87 char sep = theheader.Separator();
88 if (sep == ',') S << "[ 1] Default Separator : " << sep;
89 else S << "[ 1] Non Default Separator : " << sep;
90 char emk = theheader.EndMark();
91 if (emk == ';') S << " [ 2] Default End Mark : " << emk;
92 else S << " [ 2] Non Default End Mark : " << emk;
94 Handle(TCollection_HAsciiString) str;
95 str = theheader.SendName();
96 if (!str.IsNull()) S <<"[ 3] Sender : "<<str->ToCString()<<std::endl;
97 str = theheader.FileName();
98 if (!str.IsNull()) S <<"[ 4] (recorded) File Name : "<<str->ToCString()<<std::endl;
99 str = theheader.SystemId();
100 if (!str.IsNull()) S <<"[ 5] System Identification : "<<str->ToCString()<<std::endl;
101 str = theheader.InterfaceVersion();
102 if (!str.IsNull()) S <<"[ 6] Interface Version : "<<str->ToCString()<<std::endl;
104 S << "[ 7] Integer Bits : " << theheader.IntegerBits()
105 << " Features for Reals : " << std::endl;
106 S << "[ 8] Single Max.Power(10) : " << theheader.MaxPower10Single();
107 S << " [ 9] Digits : " << theheader.MaxDigitsSingle()<<"\n";
108 S << "[10] Double Max.Power(10) : " << theheader.MaxPower10Double();
109 S << " [11] Digits : " << theheader.MaxDigitsDouble() << "\n\n";
110 str = theheader.ReceiveName();
111 if (!str.IsNull()) S <<"[12] Receiver : "<<str->ToCString()<<"\n";
112 S << "[13] Scale : " << theheader.Scale()<<"\n";
113 S << "[14] Unit Flag : " << theheader.UnitFlag();
114 // if (Interface_Static::IVal("read.scale.unit") == 1)
115 //#73 rln 10.03.99 S4135: "read.scale.unit" does not affect GlobalSection
116 // S << " -> Value (in Meter) = " << theheader.UnitValue() / 1000 <<"\n";
117 // else S << " -> Value (in Millimeter) = " << theheader.UnitValue()<<"\n";
118 //abv 02 Mar 00: no unit parameter in OCC
119 S << " -> Value (in CASCADE units) = " << theheader.UnitValue() <<"\n";
121 str = theheader.UnitName();
122 if (!str.IsNull()) S <<"[15] Unit Name : " << str->ToCString()<<"\n\n";
123 S << "[16] Line Weight Gradient : " << theheader.LineWeightGrad()<<"\n";
124 S << "[17] Line Weight Max Value: " << theheader.MaxLineWeight()<<"\n";
126 str = theheader.Date();
127 if (!str.IsNull()) S <<"[18] (Creation) Date : "<<str->ToCString()
128 <<" i.e. "<<IGESData_GlobalSection::NewDateString(str,1)->ToCString()<<"\n";
129 S << "[19] Resolution : " << theheader.Resolution()<<"\n";
130 if (theheader.HasMaxCoord())
131 S <<"[20] Maximum Coord : " << theheader.MaxCoord() << "\n\n";
132 else S <<"[20] Maximum Coord not defined\n\n";
134 str = theheader.AuthorName();
135 if (!str.IsNull()) S <<"[21] Author : "<<str->ToCString()<<"\n";
136 str = theheader.CompanyName();
137 if (!str.IsNull()) S <<"[22] Company : "<<str->ToCString()<<"\n";
138 Standard_Integer num = theheader.IGESVersion();
139 S << "[23] IGES Version Number : " << num << " -> Name : "
140 << IGESData_BasicEditor::IGESVersionName(num);
142 num = theheader.DraftingStandard();
143 S << "\n[24] Drafting Standard : " << num;
144 if (num > 0) S << " -> Name : " << IGESData_BasicEditor::DraftingName(num);
147 if (theheader.HasLastChangeDate()) {
148 str = theheader.LastChangeDate();
149 S << "[25] Last Change Date : " << str->ToCString()
150 <<" i.e. "<<IGESData_GlobalSection::NewDateString(str,1)->ToCString()<<std::endl;
152 else S <<"[25] Last Change Date not defined (version IGES < 5.1)" << std::endl;
154 if (theheader.HasApplicationProtocol()) {
155 str = theheader.ApplicationProtocol();
156 S << "[26] Application Protocol : " << str->ToCString() <<std::endl;
159 S << " **** End of Dump ****"<<std::endl;
163 //=======================================================================
164 //function : StartSection
166 //=======================================================================
168 Handle(TColStd_HSequenceOfHAsciiString) IGESData_IGESModel::StartSection
173 //=======================================================================
174 //function : NbStartLines
176 //=======================================================================
178 Standard_Integer IGESData_IGESModel::NbStartLines () const
179 { return thestart->Length(); }
182 //=======================================================================
183 //function : StartLine
185 //=======================================================================
187 Standard_CString IGESData_IGESModel::StartLine
188 (const Standard_Integer num) const
190 if (num > 0 && num <= thestart->Length()) return
191 thestart->Value(num)->ToCString();
196 //=======================================================================
197 //function : ClearStartSection
199 //=======================================================================
201 void IGESData_IGESModel::ClearStartSection ()
202 { thestart->Clear(); }
204 void IGESData_IGESModel::SetStartSection
205 (const Handle(TColStd_HSequenceOfHAsciiString)& list,
206 const Standard_Boolean copy)
209 thestart = new TColStd_HSequenceOfHAsciiString();
210 if (list.IsNull()) return;
211 Standard_Integer i, nb = list->Length();
212 for (i = 1; i <= nb; i ++) thestart->Append
213 (new TCollection_HAsciiString(list->Value(i)->ToCString()));
215 else if (list.IsNull()) thestart = new TColStd_HSequenceOfHAsciiString();
216 else thestart = list;
220 //=======================================================================
221 //function : AddStartLine
223 //=======================================================================
225 void IGESData_IGESModel::AddStartLine
226 (const Standard_CString line, const Standard_Integer atnum)
228 if (atnum <= 0 || atnum > thestart->Length())
229 thestart->Append (new TCollection_HAsciiString(line));
230 else thestart->InsertBefore (atnum,new TCollection_HAsciiString(line));
235 //=======================================================================
236 //function : GlobalSection
238 //=======================================================================
240 const IGESData_GlobalSection& IGESData_IGESModel::GlobalSection () const
241 { return theheader; }
244 //=======================================================================
245 //function : SetGlobalSection
247 //=======================================================================
249 void IGESData_IGESModel::SetGlobalSection
250 (const IGESData_GlobalSection& header)
251 { theheader = header; }
254 //=======================================================================
255 //function : ApplyStatic
257 //=======================================================================
259 Standard_Boolean IGESData_IGESModel::ApplyStatic
260 (const Standard_CString param)
262 if (param[0] == '\0') {
263 //Standard_Boolean ret = Standard_True; //szv#4:S4163:12Mar99 not needed
264 ApplyStatic("receiver"); //szv#4:S4163:12Mar99 'ret =' not needed
265 ApplyStatic("author"); //szv#4:S4163:12Mar99 'ret =' not needed
266 ApplyStatic("company"); //szv#4:S4163:12Mar99 'ret =' not needed
267 return Standard_True;
270 Standard_CString val;
271 if (param[0] == 'r') {
272 val = Interface_Static::CVal("write.iges.header.receiver");
273 if (!val || val[0] == '\0') return Standard_False;
274 theheader.SetReceiveName (new TCollection_HAsciiString(val));
276 if (param[0] == 'a') {
277 val = Interface_Static::CVal("write.iges.header.author");
278 if (!val || val[0] == '\0') return Standard_False;
279 theheader.SetAuthorName (new TCollection_HAsciiString(val));
281 if (param[0] == 'c') {
282 val = Interface_Static::CVal("write.iges.header.company");
283 if (!val || val[0] == '\0') return Standard_False;
284 theheader.SetCompanyName (new TCollection_HAsciiString(val));
286 return Standard_True;
290 //=======================================================================
293 //=======================================================================
295 Handle(IGESData_IGESEntity) IGESData_IGESModel::Entity
296 (const Standard_Integer num) const
297 { return GetCasted(IGESData_IGESEntity,Value(num)); }
300 //=======================================================================
303 //=======================================================================
305 Standard_Integer IGESData_IGESModel::DNum
306 (const Handle(IGESData_IGESEntity)& ent) const
308 Standard_Integer num = Number(ent);
309 if (num == 0) return 0;
314 //=======================================================================
315 //function : GetFromAnother
317 //=======================================================================
319 void IGESData_IGESModel::GetFromAnother
320 (const Handle(Interface_InterfaceModel)& other)
322 DeclareAndCast(IGESData_IGESModel,another,other);
323 theheader = another->GlobalSection();
324 theheader.CopyRefs();
325 SetStartSection (another->StartSection(),Standard_True);
329 //=======================================================================
330 //function : NewEmptyModel
332 //=======================================================================
334 Handle(Interface_InterfaceModel) IGESData_IGESModel::NewEmptyModel () const
335 { return new IGESData_IGESModel; }
338 //=======================================================================
339 //function : VerifyCheck
341 //=======================================================================
343 void IGESData_IGESModel::VerifyCheck (Handle(Interface_Check)& ach) const
346 // =====================================
347 //Message_Msg Msg40 ("XSTEP_40");
348 //Message_Msg Msg41 ("XSTEP_41");
349 //Message_Msg Msg42 ("XSTEP_42");
350 //Message_Msg Msg43 ("XSTEP_43");
351 //Message_Msg Msg44 ("XSTEP_44");
352 //Message_Msg Msg45 ("XSTEP_45");
353 //Message_Msg Msg46 ("XSTEP_46");
354 //Message_Msg Msg47 ("XSTEP_47");
355 //Message_Msg Msg48 ("XSTEP_48");
356 //Message_Msg Msg50 ("XSTEP_50");
357 //Message_Msg Msg51 ("XSTEP_51");
358 //Message_Msg Msg52 ("XSTEP_52");
359 //Message_Msg Msg53 ("XSTEP_53");
360 //Message_Msg Msg54 ("XSTEP_54");
361 //Message_Msg Msg55 ("XSTEP_55");
362 // =====================================
365 del[0] = theheader.Separator();
366 del[1] = theheader.EndMark();
367 // Sending of message : Parameter Delimiter Character and Record Delimiter Character must be different.
368 if (del[0] == del[1]) {
369 Message_Msg Msg40 ("XSTEP_40");
370 ach->SendFail(Msg40);
372 for (int i = 0; i <= 1; i ++) {
373 if ( del[i] <= 32 || del[i] == 43 || del[i] == 45 || del[i] == 46 ||
374 (del[i] >= 48 && del[i] <= 57) || del[i] == 68 || del[i] == 69 ||
375 del [i] == 72 || del[i] >= 127) {
376 // Sending of message : Parameter Delimiter Character is incorrect.
378 Message_Msg Msg41 ("XSTEP_41");
379 ach->SendFail(Msg41);
381 // Sending of message : Character Record Delimiter parameter is incorrect.
383 Message_Msg Msg42 ("XSTEP_42");
384 ach->SendFail (Msg42);
388 // Sending of message : Single Precision Magnitude parameter is incorrect.
389 if (theheader.MaxPower10Single() <= 0) {
390 Message_Msg Msg43 ("XSTEP_43");
391 ach->SendFail(Msg43);
394 // Sending of message : Precision Significance parameter is incorrect.
395 if (theheader.MaxDigitsSingle() <= 0) {
396 Message_Msg Msg44 ("XSTEP_44");
397 ach->SendFail(Msg44);
400 // Sending of messages : Double Precision Magnitude parameter is incorrect.
401 if (theheader.MaxPower10Double() <= 0) {
402 Message_Msg Msg45 ("XSTEP_45");
403 ach->SendFail(Msg45);
406 // Sending of message : Double Precision Significance parameter is incorrect.
407 if (theheader.MaxDigitsDouble() <= 0) {
408 Message_Msg Msg46 ("XSTEP_46");
409 ach->SendFail(Msg46);
412 // Sending of message : Model Space Scale parameter is incorrect.
413 if (theheader.Scale() <= 0.) {
414 Message_Msg Msg47 ("XSTEP_47");
415 ach->SendFail(Msg47);
418 Standard_Integer unf = theheader.UnitFlag();
420 // Sending of message : Unit Flag parameter is incorrect.
421 if (unf < 1 || unf > 11) {
422 Message_Msg Msg48 ("XSTEP_48");
423 ach->SendFail(Msg48);
426 // .. verifie-t-on UnitName en accord avec UnitFlag ?
427 if (theheader.UnitName().IsNull()) {
428 // Sending of message : Unit Name parameter is undefined.
430 Message_Msg Msg50 ("XSTEP_50");
431 ach->SendFail(Msg50);
435 Standard_CString unm = theheader.UnitName()->ToCString();
436 Standard_Boolean unok = Standard_True;
438 case 1 : unok = (!strcmp(unm,"IN") || !strcmp(unm,"INCH")); break;
439 case 2 : unok = !strcmp(unm,"MM"); break;
440 case 3 : unok = Standard_True; break; // nom libre
441 case 4 : unok = !strcmp(unm,"FT"); break;
442 case 5 : unok = !strcmp(unm,"MI"); break;
443 case 6 : unok = !strcmp(unm,"M"); break;
444 case 7 : unok = !strcmp(unm,"KM"); break;
445 case 8 : unok = !strcmp(unm,"MIL"); break;
446 case 9 : unok = !strcmp(unm,"UM"); break;
447 case 10 : unok = !strcmp(unm,"CM"); break;
448 case 11 : unok = !strcmp(unm,"UIN"); break;
449 default : Message_Msg Msg48 ("XSTEP_48"); ach->SendFail(Msg48);
452 // Sending of message : Flag parameter doesn`t correspond to the Unit Name parameter.
454 Message_Msg Msg51 ("XSTEP_51");
455 ach->SendFail(Msg51);
459 IGESData_VerifyDate (theheader.Date(),ach,"Creation Date");
460 // Sending of message : Minimum Resolution parameter is incorrect.
461 if (theheader.Resolution() <= 0.) {
462 Message_Msg Msg52 ("XSTEP_52");
463 ach->SendFail(Msg52);
465 // .. comment verifier les coordonnees max ?
467 // Sending of message : Version Flag parameter is incorrect.
468 if (theheader.IGESVersion() < 1 ||
469 theheader.IGESVersion() > IGESData_BasicEditor::IGESVersionMax()) {
470 Message_Msg Msg53 ("XSTEP_53");
471 ach->SendWarning(Msg53);
474 // Sending of message : Drafting Standard Flag parameter is incorrect.
475 if (theheader.DraftingStandard() < 0 ||
476 theheader.DraftingStandard() > IGESData_BasicEditor::DraftingMax()) {
477 Message_Msg Msg54 ("XSTEP_54");
478 ach->SendWarning(Msg54);
481 // Sending of message :
482 if (theheader.IGESVersion() >= 9) {
483 // Sending of message : Last change Date parameter is undefined.
484 if (!theheader.HasLastChangeDate()) {
485 Message_Msg Msg55 ("XSTEP_55");
486 ach->SendWarning(Msg55);
488 else IGESData_VerifyDate (theheader.LastChangeDate(),ach,"Last Change Date");
493 void IGESData_VerifyDate(const Handle(TCollection_HAsciiString)& str,
494 Handle(Interface_Check)& ach,
495 const Standard_CString mess)
498 // =====================================
499 Message_Msg Msg57 ("XSTEP_57");
500 // =====================================
502 // Attention c est du Hollerith
504 { ach->SendFail(Msg57); return; }
506 Handle(TCollection_HAsciiString) stdvar = str;
507 if (strcmp(mess,"Last Change Date")==0)
511 if (((stdvar->Length() != 13) && (stdvar->Length() != 15)) || !stdvar->IsRealValue()) ach->SendFail(Msg57);
512 //smh#13 For short year date
513 else if ((stdvar->Value(3) > '1' ||
514 (stdvar->Value(3) == '1' && stdvar->Value(4) > '2'))&&(stdvar->Length() == 13)) ach->SendFail(Msg57);
516 else if ((stdvar->Value(5) > '3' ||
517 (stdvar->Value(5) == '3' && stdvar->Value(6) > '1'))&&(stdvar->Length() == 13)) ach->SendFail(Msg57);
518 else if ((stdvar->Value(7) != '.' || stdvar->Value(10) > '5' || stdvar->Value(12) > '5')&&(stdvar->Length() == 13))
519 ach->SendFail(Msg57);
520 else if ((stdvar->Value(8) > '2' || (stdvar->Value(8) == '2' && stdvar->Value(9) > '3')) &&
521 (stdvar->Length() == 13)) ach->SendFail(Msg57);
522 //smh#13 For long year date
523 else if ( (stdvar->Value(5) > '1' ||
524 (stdvar->Value(5) == '1' && stdvar->Value(6) > '2'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
525 else if ((stdvar->Value(7) > '3' ||
526 (stdvar->Value(7) == '3' && stdvar->Value(8) > '1'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
527 else if ((stdvar->Value(9) != '.' || stdvar->Value(12) > '5' || stdvar->Value(14) > '5')&&(stdvar->Length() == 15))
528 ach->SendFail(Msg57);
529 else if ((stdvar->Value(10) > '2' ||
530 (stdvar->Value(10) == '2' && stdvar->Value(11) > '3'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
535 //=======================================================================
536 //function : SetLineWeights
538 //=======================================================================
540 void IGESData_IGESModel::SetLineWeights (const Standard_Real defw)
542 Standard_Integer nb = NbEntities();
543 Standard_Integer lwg = theheader.LineWeightGrad();
544 Standard_Real maxw = theheader.MaxLineWeight();
545 if (lwg > 0) { maxw = maxw/lwg; lwg = 1; }
546 for (Standard_Integer i = 1; i <= nb; i ++)
547 Entity(i)->SetLineWeight(defw,maxw,lwg);
551 //=======================================================================
552 //function : ClearLabels
554 //=======================================================================
556 void IGESData_IGESModel::ClearLabels ()
561 //=======================================================================
562 //function : PrintLabel
564 //=======================================================================
566 void IGESData_IGESModel::PrintLabel
567 (const Handle(Standard_Transient)& ent, Standard_OStream& S) const
569 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
570 if (igesent.IsNull()) S <<"Null";
572 Standard_Integer num = Number(ent);
573 if (num == 0) S <<"??";
574 else S <<"D"<<(2*num-1);
579 //=======================================================================
580 //function : PrintToLog
582 //=======================================================================
584 void IGESData_IGESModel::PrintToLog
585 (const Handle(Standard_Transient)& ent, Standard_OStream& S) const
587 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
588 if (!igesent.IsNull()) {
589 Standard_Integer num = Number(ent);
590 if (num == 0) S <<"??";
592 S <<" DE : "<<(2*num-1) << " type : " << igesent->TypeNumber();
593 // Standard_Integer num2 = igesent->TypeNumber();
599 //=======================================================================
600 //function : PrintInfo
602 //=======================================================================
604 void IGESData_IGESModel::PrintInfo
605 (const Handle(Standard_Transient)& ent, Standard_OStream& S) const
607 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
608 if (igesent.IsNull()) S <<"(NOT IGES)";
610 Standard_Integer num = Number(ent);
611 if (num == 0) S <<"??";
613 S <<(2*num-1) << "type " << Type(ent)->Name();
619 //=======================================================================
620 //function : StringLabel
622 //=======================================================================
624 Handle(TCollection_HAsciiString) IGESData_IGESModel::StringLabel(const Handle(Standard_Transient)& ent) const
626 Handle(TCollection_HAsciiString) label;
627 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
628 if (igesent.IsNull()) return new TCollection_HAsciiString("(NOT IGES)");
631 Standard_Integer num = Number(ent);
632 if (num > 0) sprintf(text,"D%d",2*num-1);
633 else sprintf(text,"D0...");
634 label = new TCollection_HAsciiString(text);