0023072: Eliminate compiler warnings (level 3) on Windows / MSVC++
[occt.git] / src / StepData / StepData_StepDumper.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
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.
7 //
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.
10 //
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.
17
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>
26 #include <stdio.h>
27
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)
33 {
34   themodel = amodel;
35   if (mode > 0) thewriter.LabelMode () = 2;
36 }
37
38
39 StepData_StepWriter&  StepData_StepDumper::StepWriter ()
40 {
41   return thewriter;
42 }
43
44
45 Standard_Boolean  StepData_StepDumper::Dump
46   (const Handle(Message_Messenger)& S, const Handle(Standard_Transient)& ent,
47    const Standard_Integer level)
48 {
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) );
54
55   if (level <= 0) {
56     Handle(StepData_ReadWriteModule) module;
57     Standard_Integer CN;
58     if (num > 0) S << "#" << num << " = ";
59     else S << "#??? = ";
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;
66         else {
67           Standard_Integer n = listypes.Length();
68           for (i = 1; i <= n; i ++) S << listypes.Value(i) << " (...)";
69           S << endl;
70         }
71       }
72       else S << module->StepType(CN)  << " (...);" << endl;
73     }
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;
77   }
78
79   else if (level == 1) {
80 //  ...  Idents  ...
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()) {
88         anent = iter.Value();
89         nlab = themodel->IdentLabel(anent);
90         ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
91       }
92     }
93 //  ...  Envoi  ...
94     thewriter.SendEntity (num,thewlib);
95 ////    thewriter.Print(S);
96   }
97   else {
98     Handle(Standard_Transient) anent;
99 //    S << " --  Dumping Entity n0 " << num << "  --" << endl;
100 //  ...  Envoi  ...
101     TColStd_Array1OfInteger tab(0,nb); tab.Init(0);
102     tab.SetValue(num,1);
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);
110       }
111     }
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) );
125         }
126       }
127     }
128 ////    thewriter.Print(S);
129   }
130
131 //  ....  Affichage des idents  silya  ....
132   Standard_Integer nbi = 0 , nbe = 0 , nbq = 0 , nbu = 0;
133   for (i = 1; i <= nb; i ++) {
134     nlab = ids.Value(i);
135     if (nlab == 0) continue;
136     nbe ++;
137     if      (nlab <  0) nbu = 0;
138     else if (nlab == i) nbq = 0;
139     else if (nlab >  0) nbi ++;
140   }
141   if (nbe > 0) {
142 //    S <<" --   Displayed nums:"<<nbe<<"  with ident=num:"<<nbq<<" , distinct proper ident:"<<nbi<<"\n";
143     if (nbu > 0) {
144       S<<" (no ident): ";
145       for (i = 1; i <= nb; i ++)
146         {  if (ids.Value(i) >=  0) continue;    S<<" #"<<i;      }
147       S<<endl;
148     }
149     if (nbq > 0) {
150       S<<" (ident = num): ";
151       for (i = 1; i <= nb; i ++)  {  if (ids.Value(i) == i) S<<" #"<<i;  }
152       S<<endl;
153     }
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;
156       char unid[30];
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;
163         nbl +=  nbc;
164         if (nbl+nbr0 > 79) { nbl  = nbc;  S<<endl; }
165         else               { nbl += nbr0; for (; nbr0 > 0; nbr0 --) S << " "; }
166         S<<unid;
167         nbr0 = nbr;
168
169 //      if (nbl+nbc > 79) { S<<endl<<unid; nbl  = 0; }
170 //      else              { S<<unid;       }
171 //      nbl += (nbc+nbr);
172 //      nbr = ((80-nbc) % 4) +1;
173 //      S<<"  "<<i<<" ->#"<<ids.Value(i);
174 //      nbl ++; if (nbl > 5) {  nbl = nbr = 0;  S<<endl;  }
175       }
176       if (nbl > 0) S<<endl;
177     }
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;
180   }
181   if (level > 0) 
182   {
183     Standard_SStream aStream;
184     thewriter.Print(aStream);
185     S << aStream;
186   }
187   return Standard_True;
188 }
189
190
191 Standard_Boolean  StepData_StepDumper::Dump
192   (const Handle(Message_Messenger)& S, const Standard_Integer num,
193    const Standard_Integer level)
194 {
195   if (num <= 0 || num > themodel->NbEntities()) return Standard_False;
196   Handle(Standard_Transient) ent = themodel->Value(num);
197   return Dump (S,ent,level);
198 }