973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
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> |
7fd59977 |
22 | #include <StepData_ReadWriteModule.hxx> |
42cf5bc1 |
23 | #include <StepData_StepDumper.hxx> |
24 | #include <StepData_StepModel.hxx> |
25 | #include <StepData_StepWriter.hxx> |
7fd59977 |
26 | #include <TColStd_Array1OfInteger.hxx> |
7fd59977 |
27 | #include <TColStd_SequenceOfAsciiString.hxx> |
7fd59977 |
28 | |
42cf5bc1 |
29 | #include <stdio.h> |
7fd59977 |
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) |
35 | { |
36 | themodel = amodel; |
37 | if (mode > 0) thewriter.LabelMode () = 2; |
38 | } |
39 | |
40 | |
41 | StepData_StepWriter& StepData_StepDumper::StepWriter () |
42 | { |
43 | return thewriter; |
44 | } |
45 | |
46 | |
47 | Standard_Boolean StepData_StepDumper::Dump |
48 | (const Handle(Message_Messenger)& S, const Handle(Standard_Transient)& ent, |
49 | const Standard_Integer level) |
50 | { |
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) ); |
56 | |
57 | if (level <= 0) { |
58 | Handle(StepData_ReadWriteModule) module; |
59 | Standard_Integer CN; |
60 | if (num > 0) S << "#" << num << " = "; |
61 | else S << "#??? = "; |
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() << " (...);" << endl; |
68 | else { |
69 | Standard_Integer n = listypes.Length(); |
70 | for (i = 1; i <= n; i ++) S << listypes.Value(i) << " (...)"; |
71 | S << endl; |
72 | } |
73 | } |
74 | else S << module->StepType(CN) << " (...);" << endl; |
75 | } |
76 | else S << "(Unrecognized Type for protocol) cdl = " |
77 | << ent->DynamicType()->Name() << " (...);" << endl; |
78 | if (nlab > 0) S << "/* Ident in file for "<<num<<" : #"<<nlab<<" */"<<endl; |
79 | } |
80 | |
81 | else if (level == 1) { |
82 | // ... Idents ... |
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()) { |
90 | anent = iter.Value(); |
91 | nlab = themodel->IdentLabel(anent); |
92 | ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) ); |
93 | } |
94 | } |
95 | // ... Envoi ... |
96 | thewriter.SendEntity (num,thewlib); |
97 | //// thewriter.Print(S); |
98 | } |
99 | else { |
100 | Handle(Standard_Transient) anent; |
101 | // S << " -- Dumping Entity n0 " << num << " --" << endl; |
102 | // ... Envoi ... |
103 | TColStd_Array1OfInteger tab(0,nb); tab.Init(0); |
104 | tab.SetValue(num,1); |
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); |
112 | } |
113 | } |
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) ); |
127 | } |
128 | } |
129 | } |
130 | //// thewriter.Print(S); |
131 | } |
132 | |
133 | // .... Affichage des idents silya .... |
134 | Standard_Integer nbi = 0 , nbe = 0 , nbq = 0 , nbu = 0; |
135 | for (i = 1; i <= nb; i ++) { |
136 | nlab = ids.Value(i); |
137 | if (nlab == 0) continue; |
138 | nbe ++; |
139 | if (nlab < 0) nbu = 0; |
140 | else if (nlab == i) nbq = 0; |
141 | else if (nlab > 0) nbi ++; |
142 | } |
143 | if (nbe > 0) { |
144 | // S <<" -- Displayed nums:"<<nbe<<" with ident=num:"<<nbq<<" , distinct proper ident:"<<nbi<<"\n"; |
145 | if (nbu > 0) { |
146 | S<<" (no ident): "; |
147 | for (i = 1; i <= nb; i ++) |
148 | { if (ids.Value(i) >= 0) continue; S<<" #"<<i; } |
149 | S<<endl; |
150 | } |
151 | if (nbq > 0) { |
152 | S<<" (ident = num): "; |
153 | for (i = 1; i <= nb; i ++) { if (ids.Value(i) == i) S<<" #"<<i; } |
154 | S<<endl; |
155 | } |
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; |
158 | char unid[30]; |
159 | // S<<" (proper ident): #num #ident"<<endl; |
160 | S<<" (proper ident): num:#ident num:#ident ..."<<endl; |
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)); |
60be1f9b |
164 | nbc = (Standard_Integer) strlen (unid); nbr = ((80-nbc) %4) +2; |
7fd59977 |
165 | nbl += nbc; |
166 | if (nbl+nbr0 > 79) { nbl = nbc; S<<endl; } |
167 | else { nbl += nbr0; for (; nbr0 > 0; nbr0 --) S << " "; } |
168 | S<<unid; |
169 | nbr0 = nbr; |
170 | |
171 | // if (nbl+nbc > 79) { S<<endl<<unid; nbl = 0; } |
172 | // else { S<<unid; } |
173 | // nbl += (nbc+nbr); |
174 | // nbr = ((80-nbc) % 4) +1; |
175 | // S<<" "<<i<<" ->#"<<ids.Value(i); |
176 | // nbl ++; if (nbl > 5) { nbl = nbr = 0; S<<endl; } |
177 | } |
178 | if (nbl > 0) S<<endl; |
179 | } |
180 | if (nbi > 0) S<<"In dump, iii:#jjj means : entity rank iii has step ident #jjj"<<endl; |
181 | // S <<" -- Dumping data, entity "<<num<<" level "<<level<<" :"<<endl; |
182 | } |
183 | if (level > 0) |
184 | { |
185 | Standard_SStream aStream; |
186 | thewriter.Print(aStream); |
187 | S << aStream; |
188 | } |
189 | return Standard_True; |
190 | } |
191 | |
192 | |
193 | Standard_Boolean StepData_StepDumper::Dump |
194 | (const Handle(Message_Messenger)& S, const Standard_Integer num, |
195 | const Standard_Integer level) |
196 | { |
197 | if (num <= 0 || num > themodel->NbEntities()) return Standard_False; |
198 | Handle(Standard_Transient) ent = themodel->Value(num); |
199 | return Dump (S,ent,level); |
200 | } |