1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <StepData_StepDumper.ixx>
19 #include <StepData_ReadWriteModule.hxx>
20 #include <TColStd_Array1OfInteger.hxx>
21 #include <Interface_GeneralModule.hxx>
22 #include <Interface_EntityIterator.hxx>
23 #include <TColStd_SequenceOfAsciiString.hxx>
24 #include <Message_Messenger.hxx>
25 #include <Message.hxx>
28 StepData_StepDumper::StepData_StepDumper
29 (const Handle(StepData_StepModel)& amodel,
30 const Handle(StepData_Protocol)& protocol,
31 const Standard_Integer mode)
32 : theslib (protocol) , thewlib (protocol) , thewriter (amodel)
35 if (mode > 0) thewriter.LabelMode () = 2;
39 StepData_StepWriter& StepData_StepDumper::StepWriter ()
45 Standard_Boolean StepData_StepDumper::Dump
46 (const Handle(Message_Messenger)& S, const Handle(Standard_Transient)& ent,
47 const Standard_Integer level)
49 Standard_Integer i, nb = themodel->NbEntities();
50 TColStd_Array1OfInteger ids(0,nb); ids.Init(0);
51 Standard_Integer num = themodel->Number(ent);
52 Standard_Integer nlab = themodel->IdentLabel(ent);
53 ids.SetValue(num, (nlab > 0 ? nlab : -1) );
56 Handle(StepData_ReadWriteModule) module;
58 if (num > 0) S << "#" << num << " = ";
60 if (thewlib.Select(ent,module,CN)) {
61 if (module->IsComplex(CN)) {
62 TColStd_SequenceOfAsciiString listypes;
63 if (!module->ComplexType(CN,listypes))
64 S << "(Complex Type : ask level > 0) cdl = "
65 << ent->DynamicType()->Name() << " (...);" << endl;
67 Standard_Integer n = listypes.Length();
68 for (i = 1; i <= n; i ++) S << listypes.Value(i) << " (...)";
72 else S << module->StepType(CN) << " (...);" << endl;
74 else S << "(Unrecognized Type for protocol) cdl = "
75 << ent->DynamicType()->Name() << " (...);" << endl;
76 if (nlab > 0) S << "/* Ident in file for "<<num<<" : #"<<nlab<<" */"<<endl;
79 else if (level == 1) {
81 Handle(Standard_Transient) anent;
82 Handle(Interface_GeneralModule) module; Standard_Integer CN;
83 if (theslib.Select(ent,module,CN)) {
84 Interface_EntityIterator iter;
85 module->FillSharedCase (CN,ent,iter);
86 module->ListImpliedCase (CN,ent,iter); // on cumule ...
87 for (; iter.More(); iter.Next()) {
89 nlab = themodel->IdentLabel(anent);
90 ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
94 thewriter.SendEntity (num,thewlib);
95 //// thewriter.Print(S);
98 Handle(Standard_Transient) anent;
99 // S << " -- Dumping Entity n0 " << num << " --" << endl;
101 TColStd_Array1OfInteger tab(0,nb); tab.Init(0);
103 Handle(Interface_GeneralModule) module; Standard_Integer CN;
104 if (theslib.Select(ent,module,CN)) {
105 Interface_EntityIterator iter;
106 module->FillSharedCase (CN,ent,iter);
107 module->ListImpliedCase (CN,ent,iter); // on cumule ...
108 for (; iter.More(); iter.Next()) {
109 tab.SetValue(themodel->Number(iter.Value()),1);
112 for (i = 1; i <= nb; i ++) {
113 // ... Listes des idents ...
114 if (tab.Value(i) == 0) continue;
115 anent = themodel->Value(i);
116 thewriter.SendEntity(i,thewlib);
117 if (theslib.Select(anent,module,CN)) {
118 Interface_EntityIterator iter;
119 module->FillSharedCase (CN,anent,iter);
120 module->ListImpliedCase (CN,anent,iter); // on cumule ...
121 for (; iter.More(); iter.Next()) {
122 anent = iter.Value();
123 nlab = themodel->IdentLabel(anent);
124 ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
128 //// thewriter.Print(S);
131 // .... Affichage des idents silya ....
132 Standard_Integer nbi = 0 , nbe = 0 , nbq = 0 , nbu = 0;
133 for (i = 1; i <= nb; i ++) {
135 if (nlab == 0) continue;
137 if (nlab < 0) nbu = 0;
138 else if (nlab == i) nbq = 0;
139 else if (nlab > 0) nbi ++;
142 // S <<" -- Displayed nums:"<<nbe<<" with ident=num:"<<nbq<<" , distinct proper ident:"<<nbi<<"\n";
145 for (i = 1; i <= nb; i ++)
146 { if (ids.Value(i) >= 0) continue; S<<" #"<<i; }
150 S<<" (ident = num): ";
151 for (i = 1; i <= nb; i ++) { if (ids.Value(i) == i) S<<" #"<<i; }
154 if (nbi < 0) { // on n affiche plus num:#id , on envoie un petit help
155 Standard_Integer nbl = 0, nbr = 0, nbr0 = 0, nbc = 0;
157 // S<<" (proper ident): #num #ident"<<endl;
158 S<<" (proper ident): num:#ident num:#ident ..."<<endl;
159 for (i = 1; i <= nb; i ++) {
160 if (ids.Value(i) <= 0 || ids.Value(i) == i) continue;
161 sprintf (unid,"%d:#%d",i,ids.Value(i));
162 nbc = (Standard_Integer) strlen (unid); nbr = ((80-nbc) %4) +2;
164 if (nbl+nbr0 > 79) { nbl = nbc; S<<endl; }
165 else { nbl += nbr0; for (; nbr0 > 0; nbr0 --) S << " "; }
169 // if (nbl+nbc > 79) { S<<endl<<unid; nbl = 0; }
172 // nbr = ((80-nbc) % 4) +1;
173 // S<<" "<<i<<" ->#"<<ids.Value(i);
174 // nbl ++; if (nbl > 5) { nbl = nbr = 0; S<<endl; }
176 if (nbl > 0) S<<endl;
178 if (nbi > 0) S<<"In dump, iii:#jjj means : entity rank iii has step ident #jjj"<<endl;
179 // S <<" -- Dumping data, entity "<<num<<" level "<<level<<" :"<<endl;
183 Standard_SStream aStream;
184 thewriter.Print(aStream);
187 return Standard_True;
191 Standard_Boolean StepData_StepDumper::Dump
192 (const Handle(Message_Messenger)& S, const Standard_Integer num,
193 const Standard_Integer level)
195 if (num <= 0 || num > themodel->NbEntities()) return Standard_False;
196 Handle(Standard_Transient) ent = themodel->Value(num);
197 return Dump (S,ent,level);