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 #include <StepData_StepDumper.ixx>
15 #include <StepData_ReadWriteModule.hxx>
16 #include <TColStd_Array1OfInteger.hxx>
17 #include <Interface_GeneralModule.hxx>
18 #include <Interface_EntityIterator.hxx>
19 #include <TColStd_SequenceOfAsciiString.hxx>
20 #include <Message_Messenger.hxx>
21 #include <Message.hxx>
24 StepData_StepDumper::StepData_StepDumper
25 (const Handle(StepData_StepModel)& amodel,
26 const Handle(StepData_Protocol)& protocol,
27 const Standard_Integer mode)
28 : theslib (protocol) , thewlib (protocol) , thewriter (amodel)
31 if (mode > 0) thewriter.LabelMode () = 2;
35 StepData_StepWriter& StepData_StepDumper::StepWriter ()
41 Standard_Boolean StepData_StepDumper::Dump
42 (const Handle(Message_Messenger)& S, const Handle(Standard_Transient)& ent,
43 const Standard_Integer level)
45 Standard_Integer i, nb = themodel->NbEntities();
46 TColStd_Array1OfInteger ids(0,nb); ids.Init(0);
47 Standard_Integer num = themodel->Number(ent);
48 Standard_Integer nlab = themodel->IdentLabel(ent);
49 ids.SetValue(num, (nlab > 0 ? nlab : -1) );
52 Handle(StepData_ReadWriteModule) module;
54 if (num > 0) S << "#" << num << " = ";
56 if (thewlib.Select(ent,module,CN)) {
57 if (module->IsComplex(CN)) {
58 TColStd_SequenceOfAsciiString listypes;
59 if (!module->ComplexType(CN,listypes))
60 S << "(Complex Type : ask level > 0) cdl = "
61 << ent->DynamicType()->Name() << " (...);" << endl;
63 Standard_Integer n = listypes.Length();
64 for (i = 1; i <= n; i ++) S << listypes.Value(i) << " (...)";
68 else S << module->StepType(CN) << " (...);" << endl;
70 else S << "(Unrecognized Type for protocol) cdl = "
71 << ent->DynamicType()->Name() << " (...);" << endl;
72 if (nlab > 0) S << "/* Ident in file for "<<num<<" : #"<<nlab<<" */"<<endl;
75 else if (level == 1) {
77 Handle(Standard_Transient) anent;
78 Handle(Interface_GeneralModule) module; Standard_Integer CN;
79 if (theslib.Select(ent,module,CN)) {
80 Interface_EntityIterator iter;
81 module->FillSharedCase (CN,ent,iter);
82 module->ListImpliedCase (CN,ent,iter); // on cumule ...
83 for (; iter.More(); iter.Next()) {
85 nlab = themodel->IdentLabel(anent);
86 ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
90 thewriter.SendEntity (num,thewlib);
91 //// thewriter.Print(S);
94 Handle(Standard_Transient) anent;
95 // S << " -- Dumping Entity n0 " << num << " --" << endl;
97 TColStd_Array1OfInteger tab(0,nb); tab.Init(0);
99 Handle(Interface_GeneralModule) module; Standard_Integer CN;
100 if (theslib.Select(ent,module,CN)) {
101 Interface_EntityIterator iter;
102 module->FillSharedCase (CN,ent,iter);
103 module->ListImpliedCase (CN,ent,iter); // on cumule ...
104 for (; iter.More(); iter.Next()) {
105 tab.SetValue(themodel->Number(iter.Value()),1);
108 for (i = 1; i <= nb; i ++) {
109 // ... Listes des idents ...
110 if (tab.Value(i) == 0) continue;
111 anent = themodel->Value(i);
112 thewriter.SendEntity(i,thewlib);
113 if (theslib.Select(anent,module,CN)) {
114 Interface_EntityIterator iter;
115 module->FillSharedCase (CN,anent,iter);
116 module->ListImpliedCase (CN,anent,iter); // on cumule ...
117 for (; iter.More(); iter.Next()) {
118 anent = iter.Value();
119 nlab = themodel->IdentLabel(anent);
120 ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
124 //// thewriter.Print(S);
127 // .... Affichage des idents silya ....
128 Standard_Integer nbi = 0 , nbe = 0 , nbq = 0 , nbu = 0;
129 for (i = 1; i <= nb; i ++) {
131 if (nlab == 0) continue;
133 if (nlab < 0) nbu = 0;
134 else if (nlab == i) nbq = 0;
135 else if (nlab > 0) nbi ++;
138 // S <<" -- Displayed nums:"<<nbe<<" with ident=num:"<<nbq<<" , distinct proper ident:"<<nbi<<"\n";
141 for (i = 1; i <= nb; i ++)
142 { if (ids.Value(i) >= 0) continue; S<<" #"<<i; }
146 S<<" (ident = num): ";
147 for (i = 1; i <= nb; i ++) { if (ids.Value(i) == i) S<<" #"<<i; }
150 if (nbi < 0) { // on n affiche plus num:#id , on envoie un petit help
151 Standard_Integer nbl = 0, nbr = 0, nbr0 = 0, nbc = 0;
153 // S<<" (proper ident): #num #ident"<<endl;
154 S<<" (proper ident): num:#ident num:#ident ..."<<endl;
155 for (i = 1; i <= nb; i ++) {
156 if (ids.Value(i) <= 0 || ids.Value(i) == i) continue;
157 sprintf (unid,"%d:#%d",i,ids.Value(i));
158 nbc = (Standard_Integer) strlen (unid); nbr = ((80-nbc) %4) +2;
160 if (nbl+nbr0 > 79) { nbl = nbc; S<<endl; }
161 else { nbl += nbr0; for (; nbr0 > 0; nbr0 --) S << " "; }
165 // if (nbl+nbc > 79) { S<<endl<<unid; nbl = 0; }
168 // nbr = ((80-nbc) % 4) +1;
169 // S<<" "<<i<<" ->#"<<ids.Value(i);
170 // nbl ++; if (nbl > 5) { nbl = nbr = 0; S<<endl; }
172 if (nbl > 0) S<<endl;
174 if (nbi > 0) S<<"In dump, iii:#jjj means : entity rank iii has step ident #jjj"<<endl;
175 // S <<" -- Dumping data, entity "<<num<<" level "<<level<<" :"<<endl;
179 Standard_SStream aStream;
180 thewriter.Print(aStream);
183 return Standard_True;
187 Standard_Boolean StepData_StepDumper::Dump
188 (const Handle(Message_Messenger)& S, const Standard_Integer num,
189 const Standard_Integer level)
191 if (num <= 0 || num > themodel->NbEntities()) return Standard_False;
192 Handle(Standard_Transient) ent = themodel->Value(num);
193 return Dump (S,ent,level);