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.
15 #include <Interface_EntityIterator.hxx>
16 #include <Interface_GeneralModule.hxx>
17 #include <Interface_InterfaceMismatch.hxx>
18 #include <Message.hxx>
19 #include <Message_Messenger.hxx>
20 #include <Standard_Transient.hxx>
21 #include <StepData_Protocol.hxx>
22 #include <StepData_ReadWriteModule.hxx>
23 #include <StepData_StepDumper.hxx>
24 #include <StepData_StepModel.hxx>
25 #include <StepData_StepWriter.hxx>
26 #include <TColStd_Array1OfInteger.hxx>
27 #include <TColStd_SequenceOfAsciiString.hxx>
30 StepData_StepDumper::StepData_StepDumper
31 (const Handle(StepData_StepModel)& amodel,
32 const Handle(StepData_Protocol)& protocol,
33 const Standard_Integer mode)
34 : theslib (protocol) , thewlib (protocol) , thewriter (amodel)
37 if (mode > 0) thewriter.LabelMode () = 2;
41 StepData_StepWriter& StepData_StepDumper::StepWriter ()
47 Standard_Boolean StepData_StepDumper::Dump
48 (const Handle(Message_Messenger)& S, const Handle(Standard_Transient)& ent,
49 const Standard_Integer level)
51 Standard_Integer i, nb = themodel->NbEntities();
52 TColStd_Array1OfInteger ids(0,nb); ids.Init(0);
53 Standard_Integer num = themodel->Number(ent);
54 Standard_Integer nlab = themodel->IdentLabel(ent);
55 ids.SetValue(num, (nlab > 0 ? nlab : -1) );
58 Handle(StepData_ReadWriteModule) module;
60 if (num > 0) S << "#" << num << " = ";
62 if (thewlib.Select(ent,module,CN)) {
63 if (module->IsComplex(CN)) {
64 TColStd_SequenceOfAsciiString listypes;
65 if (!module->ComplexType(CN,listypes))
66 S << "(Complex Type : ask level > 0) cdl = "
67 << ent->DynamicType()->Name() << " (...);" << Message_EndLine;
69 Standard_Integer n = listypes.Length();
70 for (i = 1; i <= n; i ++) S << listypes.Value(i) << " (...)";
74 else S << module->StepType(CN) << " (...);" << Message_EndLine;
76 else S << "(Unrecognized Type for protocol) cdl = "
77 << ent->DynamicType()->Name() << " (...);" << Message_EndLine;
78 if (nlab > 0) S << "/* Ident in file for "<<num<<" : #"<<nlab<<" */"<<Message_EndLine;
81 else if (level == 1) {
83 Handle(Standard_Transient) anent;
84 Handle(Interface_GeneralModule) module; Standard_Integer CN;
85 if (theslib.Select(ent,module,CN)) {
86 Interface_EntityIterator iter;
87 module->FillSharedCase (CN,ent,iter);
88 module->ListImpliedCase (CN,ent,iter); // on cumule ...
89 for (; iter.More(); iter.Next()) {
91 nlab = themodel->IdentLabel(anent);
92 ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
96 thewriter.SendEntity (num,thewlib);
97 //// thewriter.Print(S);
100 Handle(Standard_Transient) anent;
101 // S << " -- Dumping Entity n0 " << num << " --" << std::endl;
103 TColStd_Array1OfInteger tab(0,nb); tab.Init(0);
105 Handle(Interface_GeneralModule) module; Standard_Integer CN;
106 if (theslib.Select(ent,module,CN)) {
107 Interface_EntityIterator iter;
108 module->FillSharedCase (CN,ent,iter);
109 module->ListImpliedCase (CN,ent,iter); // on cumule ...
110 for (; iter.More(); iter.Next()) {
111 tab.SetValue(themodel->Number(iter.Value()),1);
114 for (i = 1; i <= nb; i ++) {
115 // ... Listes des idents ...
116 if (tab.Value(i) == 0) continue;
117 anent = themodel->Value(i);
118 thewriter.SendEntity(i,thewlib);
119 if (theslib.Select(anent,module,CN)) {
120 Interface_EntityIterator iter;
121 module->FillSharedCase (CN,anent,iter);
122 module->ListImpliedCase (CN,anent,iter); // on cumule ...
123 for (; iter.More(); iter.Next()) {
124 anent = iter.Value();
125 nlab = themodel->IdentLabel(anent);
126 ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
130 //// thewriter.Print(S);
133 // .... Affichage des idents silya ....
134 Standard_Integer nbi = 0 , nbe = 0 , nbq = 0 , nbu = 0;
135 for (i = 1; i <= nb; i ++) {
137 if (nlab == 0) continue;
139 if (nlab < 0) nbu = 0;
140 else if (nlab == i) nbq = 0;
141 else if (nlab > 0) nbi ++;
144 // S <<" -- Displayed nums:"<<nbe<<" with ident=num:"<<nbq<<" , distinct proper ident:"<<nbi<<"\n";
147 for (i = 1; i <= nb; i ++)
148 { if (ids.Value(i) >= 0) continue; S<<" #"<<i; }
152 S<<" (ident = num): ";
153 for (i = 1; i <= nb; i ++) { if (ids.Value(i) == i) S<<" #"<<i; }
156 if (nbi < 0) { // on n affiche plus num:#id , on envoie un petit help
157 Standard_Integer nbl = 0, nbr = 0, nbr0 = 0, nbc = 0;
159 // S<<" (proper ident): #num #ident"<<std::endl;
160 S<<" (proper ident): num:#ident num:#ident ..."<<Message_EndLine;
161 for (i = 1; i <= nb; i ++) {
162 if (ids.Value(i) <= 0 || ids.Value(i) == i) continue;
163 sprintf (unid,"%d:#%d",i,ids.Value(i));
164 nbc = (Standard_Integer) strlen (unid); nbr = ((80-nbc) %4) +2;
166 if (nbl+nbr0 > 79) { nbl = nbc; S<<Message_EndLine; }
167 else { nbl += nbr0; for (; nbr0 > 0; nbr0 --) S << " "; }
171 // if (nbl+nbc > 79) { S<<std::endl<<unid; nbl = 0; }
174 // nbr = ((80-nbc) % 4) +1;
175 // S<<" "<<i<<" ->#"<<ids.Value(i);
176 // nbl ++; if (nbl > 5) { nbl = nbr = 0; S<<std::endl; }
178 if (nbl > 0) S<<Message_EndLine;
180 if (nbi > 0) S<<"In dump, iii:#jjj means : entity rank iii has step ident #jjj"<<Message_EndLine;
181 // S <<" -- Dumping data, entity "<<num<<" level "<<level<<" :"<<std::endl;
185 Standard_SStream aStream;
186 thewriter.Print(aStream);
189 return Standard_True;
193 Standard_Boolean StepData_StepDumper::Dump
194 (const Handle(Message_Messenger)& S, const Standard_Integer num,
195 const Standard_Integer level)
197 if (num <= 0 || num > themodel->NbEntities()) return Standard_False;
198 Handle(Standard_Transient) ent = themodel->Value(num);
199 return Dump (S,ent,level);