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));
233 //=======================================================================
234 //function : SetGlobalSection
236 //=======================================================================
238 void IGESData_IGESModel::SetGlobalSection
239 (const IGESData_GlobalSection& header)
240 { theheader = header; }
243 //=======================================================================
244 //function : ApplyStatic
246 //=======================================================================
248 Standard_Boolean IGESData_IGESModel::ApplyStatic
249 (const Standard_CString param)
251 if (param[0] == '\0') {
252 //Standard_Boolean ret = Standard_True; //szv#4:S4163:12Mar99 not needed
253 ApplyStatic("receiver"); //szv#4:S4163:12Mar99 'ret =' not needed
254 ApplyStatic("author"); //szv#4:S4163:12Mar99 'ret =' not needed
255 ApplyStatic("company"); //szv#4:S4163:12Mar99 'ret =' not needed
256 return Standard_True;
259 Standard_CString val;
260 if (param[0] == 'r') {
261 val = Interface_Static::CVal("write.iges.header.receiver");
262 if (!val || val[0] == '\0') return Standard_False;
263 theheader.SetReceiveName (new TCollection_HAsciiString(val));
265 if (param[0] == 'a') {
266 val = Interface_Static::CVal("write.iges.header.author");
267 if (!val || val[0] == '\0') return Standard_False;
268 theheader.SetAuthorName (new TCollection_HAsciiString(val));
270 if (param[0] == 'c') {
271 val = Interface_Static::CVal("write.iges.header.company");
272 if (!val || val[0] == '\0') return Standard_False;
273 theheader.SetCompanyName (new TCollection_HAsciiString(val));
275 return Standard_True;
279 //=======================================================================
282 //=======================================================================
284 Handle(IGESData_IGESEntity) IGESData_IGESModel::Entity
285 (const Standard_Integer num) const
286 { return GetCasted(IGESData_IGESEntity,Value(num)); }
289 //=======================================================================
292 //=======================================================================
294 Standard_Integer IGESData_IGESModel::DNum
295 (const Handle(IGESData_IGESEntity)& ent) const
297 Standard_Integer num = Number(ent);
298 if (num == 0) return 0;
303 //=======================================================================
304 //function : GetFromAnother
306 //=======================================================================
308 void IGESData_IGESModel::GetFromAnother
309 (const Handle(Interface_InterfaceModel)& other)
311 DeclareAndCast(IGESData_IGESModel,another,other);
312 theheader = another->GlobalSection();
313 theheader.CopyRefs();
314 SetStartSection (another->StartSection(),Standard_True);
318 //=======================================================================
319 //function : NewEmptyModel
321 //=======================================================================
323 Handle(Interface_InterfaceModel) IGESData_IGESModel::NewEmptyModel () const
324 { return new IGESData_IGESModel; }
327 //=======================================================================
328 //function : VerifyCheck
330 //=======================================================================
332 void IGESData_IGESModel::VerifyCheck (Handle(Interface_Check)& ach) const
335 // =====================================
336 //Message_Msg Msg40 ("XSTEP_40");
337 //Message_Msg Msg41 ("XSTEP_41");
338 //Message_Msg Msg42 ("XSTEP_42");
339 //Message_Msg Msg43 ("XSTEP_43");
340 //Message_Msg Msg44 ("XSTEP_44");
341 //Message_Msg Msg45 ("XSTEP_45");
342 //Message_Msg Msg46 ("XSTEP_46");
343 //Message_Msg Msg47 ("XSTEP_47");
344 //Message_Msg Msg48 ("XSTEP_48");
345 //Message_Msg Msg50 ("XSTEP_50");
346 //Message_Msg Msg51 ("XSTEP_51");
347 //Message_Msg Msg52 ("XSTEP_52");
348 //Message_Msg Msg53 ("XSTEP_53");
349 //Message_Msg Msg54 ("XSTEP_54");
350 //Message_Msg Msg55 ("XSTEP_55");
351 // =====================================
354 del[0] = theheader.Separator();
355 del[1] = theheader.EndMark();
356 // Sending of message : Parameter Delimiter Character and Record Delimiter Character must be different.
357 if (del[0] == del[1]) {
358 Message_Msg Msg40 ("XSTEP_40");
359 ach->SendFail(Msg40);
361 for (int i = 0; i <= 1; i ++) {
362 if ( del[i] <= 32 || del[i] == 43 || del[i] == 45 || del[i] == 46 ||
363 (del[i] >= 48 && del[i] <= 57) || del[i] == 68 || del[i] == 69 ||
364 del [i] == 72 || del[i] >= 127) {
365 // Sending of message : Parameter Delimiter Character is incorrect.
367 Message_Msg Msg41 ("XSTEP_41");
368 ach->SendFail(Msg41);
370 // Sending of message : Character Record Delimiter parameter is incorrect.
372 Message_Msg Msg42 ("XSTEP_42");
373 ach->SendFail (Msg42);
377 // Sending of message : Single Precision Magnitude parameter is incorrect.
378 if (theheader.MaxPower10Single() <= 0) {
379 Message_Msg Msg43 ("XSTEP_43");
380 ach->SendFail(Msg43);
383 // Sending of message : Precision Significance parameter is incorrect.
384 if (theheader.MaxDigitsSingle() <= 0) {
385 Message_Msg Msg44 ("XSTEP_44");
386 ach->SendFail(Msg44);
389 // Sending of messages : Double Precision Magnitude parameter is incorrect.
390 if (theheader.MaxPower10Double() <= 0) {
391 Message_Msg Msg45 ("XSTEP_45");
392 ach->SendFail(Msg45);
395 // Sending of message : Double Precision Significance parameter is incorrect.
396 if (theheader.MaxDigitsDouble() <= 0) {
397 Message_Msg Msg46 ("XSTEP_46");
398 ach->SendFail(Msg46);
401 // Sending of message : Model Space Scale parameter is incorrect.
402 if (theheader.Scale() <= 0.) {
403 Message_Msg Msg47 ("XSTEP_47");
404 ach->SendFail(Msg47);
407 Standard_Integer unf = theheader.UnitFlag();
409 // Sending of message : Unit Flag parameter is incorrect.
410 if (unf < 1 || unf > 11) {
411 Message_Msg Msg48 ("XSTEP_48");
412 ach->SendFail(Msg48);
415 // .. verifie-t-on UnitName en accord avec UnitFlag ?
416 if (theheader.UnitName().IsNull()) {
417 // Sending of message : Unit Name parameter is undefined.
419 Message_Msg Msg50 ("XSTEP_50");
420 ach->SendFail(Msg50);
424 Standard_CString unm = theheader.UnitName()->ToCString();
425 Standard_Boolean unok = Standard_True;
427 case 1 : unok = (!strcmp(unm,"IN") || !strcmp(unm,"INCH")); break;
428 case 2 : unok = !strcmp(unm,"MM"); break;
429 case 3 : unok = Standard_True; break; // nom libre
430 case 4 : unok = !strcmp(unm,"FT"); break;
431 case 5 : unok = !strcmp(unm,"MI"); break;
432 case 6 : unok = !strcmp(unm,"M"); break;
433 case 7 : unok = !strcmp(unm,"KM"); break;
434 case 8 : unok = !strcmp(unm,"MIL"); break;
435 case 9 : unok = !strcmp(unm,"UM"); break;
436 case 10 : unok = !strcmp(unm,"CM"); break;
437 case 11 : unok = !strcmp(unm,"UIN"); break;
438 default : Message_Msg Msg48 ("XSTEP_48"); ach->SendFail(Msg48);
441 // Sending of message : Flag parameter doesn`t correspond to the Unit Name parameter.
443 Message_Msg Msg51 ("XSTEP_51");
444 ach->SendFail(Msg51);
448 IGESData_VerifyDate (theheader.Date(),ach,"Creation Date");
449 // Sending of message : Minimum Resolution parameter is incorrect.
450 if (theheader.Resolution() <= 0.) {
451 Message_Msg Msg52 ("XSTEP_52");
452 ach->SendFail(Msg52);
454 // .. comment verifier les coordonnees max ?
456 // Sending of message : Version Flag parameter is incorrect.
457 if (theheader.IGESVersion() < 1 ||
458 theheader.IGESVersion() > IGESData_BasicEditor::IGESVersionMax()) {
459 Message_Msg Msg53 ("XSTEP_53");
460 ach->SendWarning(Msg53);
463 // Sending of message : Drafting Standard Flag parameter is incorrect.
464 if (theheader.DraftingStandard() < 0 ||
465 theheader.DraftingStandard() > IGESData_BasicEditor::DraftingMax()) {
466 Message_Msg Msg54 ("XSTEP_54");
467 ach->SendWarning(Msg54);
470 // Sending of message :
471 if (theheader.IGESVersion() >= 9) {
472 // Sending of message : Last change Date parameter is undefined.
473 if (!theheader.HasLastChangeDate()) {
474 Message_Msg Msg55 ("XSTEP_55");
475 ach->SendWarning(Msg55);
477 else IGESData_VerifyDate (theheader.LastChangeDate(),ach,"Last Change Date");
482 void IGESData_VerifyDate(const Handle(TCollection_HAsciiString)& str,
483 Handle(Interface_Check)& ach,
484 const Standard_CString mess)
487 // =====================================
488 Message_Msg Msg57 ("XSTEP_57");
489 // =====================================
491 // Attention c est du Hollerith
493 { ach->SendFail(Msg57); return; }
495 Handle(TCollection_HAsciiString) stdvar = str;
496 if (strcmp(mess,"Last Change Date")==0)
500 if (((stdvar->Length() != 13) && (stdvar->Length() != 15)) || !stdvar->IsRealValue()) ach->SendFail(Msg57);
501 //smh#13 For short year date
502 else if ((stdvar->Value(3) > '1' ||
503 (stdvar->Value(3) == '1' && stdvar->Value(4) > '2'))&&(stdvar->Length() == 13)) ach->SendFail(Msg57);
505 else if ((stdvar->Value(5) > '3' ||
506 (stdvar->Value(5) == '3' && stdvar->Value(6) > '1'))&&(stdvar->Length() == 13)) ach->SendFail(Msg57);
507 else if ((stdvar->Value(7) != '.' || stdvar->Value(10) > '5' || stdvar->Value(12) > '5')&&(stdvar->Length() == 13))
508 ach->SendFail(Msg57);
509 else if ((stdvar->Value(8) > '2' || (stdvar->Value(8) == '2' && stdvar->Value(9) > '3')) &&
510 (stdvar->Length() == 13)) ach->SendFail(Msg57);
511 //smh#13 For long year date
512 else if ( (stdvar->Value(5) > '1' ||
513 (stdvar->Value(5) == '1' && stdvar->Value(6) > '2'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
514 else if ((stdvar->Value(7) > '3' ||
515 (stdvar->Value(7) == '3' && stdvar->Value(8) > '1'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
516 else if ((stdvar->Value(9) != '.' || stdvar->Value(12) > '5' || stdvar->Value(14) > '5')&&(stdvar->Length() == 15))
517 ach->SendFail(Msg57);
518 else if ((stdvar->Value(10) > '2' ||
519 (stdvar->Value(10) == '2' && stdvar->Value(11) > '3'))&&(stdvar->Length() == 15)) ach->SendFail(Msg57);
524 //=======================================================================
525 //function : SetLineWeights
527 //=======================================================================
529 void IGESData_IGESModel::SetLineWeights (const Standard_Real defw)
531 Standard_Integer nb = NbEntities();
532 Standard_Integer lwg = theheader.LineWeightGrad();
533 Standard_Real maxw = theheader.MaxLineWeight();
534 if (lwg > 0) { maxw = maxw/lwg; lwg = 1; }
535 for (Standard_Integer i = 1; i <= nb; i ++)
536 Entity(i)->SetLineWeight(defw,maxw,lwg);
540 //=======================================================================
541 //function : ClearLabels
543 //=======================================================================
545 void IGESData_IGESModel::ClearLabels ()
550 //=======================================================================
551 //function : PrintLabel
553 //=======================================================================
555 void IGESData_IGESModel::PrintLabel
556 (const Handle(Standard_Transient)& ent, Standard_OStream& S) const
558 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
559 if (igesent.IsNull()) S <<"Null";
561 Standard_Integer num = Number(ent);
562 if (num == 0) S <<"??";
563 else S <<"D"<<(2*num-1);
568 //=======================================================================
569 //function : PrintToLog
571 //=======================================================================
573 void IGESData_IGESModel::PrintToLog
574 (const Handle(Standard_Transient)& ent, Standard_OStream& S) const
576 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
577 if (!igesent.IsNull()) {
578 Standard_Integer num = Number(ent);
579 if (num == 0) S <<"??";
581 S <<" DE : "<<(2*num-1) << " type : " << igesent->TypeNumber();
582 // Standard_Integer num2 = igesent->TypeNumber();
588 //=======================================================================
589 //function : PrintInfo
591 //=======================================================================
593 void IGESData_IGESModel::PrintInfo
594 (const Handle(Standard_Transient)& ent, Standard_OStream& S) const
596 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
597 if (igesent.IsNull()) S <<"(NOT IGES)";
599 Standard_Integer num = Number(ent);
600 if (num == 0) S <<"??";
602 S <<(2*num-1) << "type " << Type(ent)->Name();
608 //=======================================================================
609 //function : StringLabel
611 //=======================================================================
613 Handle(TCollection_HAsciiString) IGESData_IGESModel::StringLabel(const Handle(Standard_Transient)& ent) const
615 Handle(TCollection_HAsciiString) label;
616 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
617 if (igesent.IsNull()) return new TCollection_HAsciiString("(NOT IGES)");
620 Standard_Integer num = Number(ent);
621 if (num > 0) sprintf(text,"D%d",2*num-1);
622 else sprintf(text,"D0...");
623 label = new TCollection_HAsciiString(text);