0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / StepData / StepData_StepDumper.cxx
CommitLineData
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//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 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>
22#include <stdio.h>
23
24StepData_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)
29{
30 themodel = amodel;
31 if (mode > 0) thewriter.LabelMode () = 2;
32}
33
34
35StepData_StepWriter& StepData_StepDumper::StepWriter ()
36{
37 return thewriter;
38}
39
40
41Standard_Boolean StepData_StepDumper::Dump
42 (const Handle(Message_Messenger)& S, const Handle(Standard_Transient)& ent,
43 const Standard_Integer level)
44{
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) );
50
51 if (level <= 0) {
52 Handle(StepData_ReadWriteModule) module;
53 Standard_Integer CN;
54 if (num > 0) S << "#" << num << " = ";
55 else S << "#??? = ";
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;
62 else {
63 Standard_Integer n = listypes.Length();
64 for (i = 1; i <= n; i ++) S << listypes.Value(i) << " (...)";
65 S << endl;
66 }
67 }
68 else S << module->StepType(CN) << " (...);" << endl;
69 }
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;
73 }
74
75 else if (level == 1) {
76// ... Idents ...
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()) {
84 anent = iter.Value();
85 nlab = themodel->IdentLabel(anent);
86 ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
87 }
88 }
89// ... Envoi ...
90 thewriter.SendEntity (num,thewlib);
91//// thewriter.Print(S);
92 }
93 else {
94 Handle(Standard_Transient) anent;
95// S << " -- Dumping Entity n0 " << num << " --" << endl;
96// ... Envoi ...
97 TColStd_Array1OfInteger tab(0,nb); tab.Init(0);
98 tab.SetValue(num,1);
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);
106 }
107 }
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) );
121 }
122 }
123 }
124//// thewriter.Print(S);
125 }
126
127// .... Affichage des idents silya ....
128 Standard_Integer nbi = 0 , nbe = 0 , nbq = 0 , nbu = 0;
129 for (i = 1; i <= nb; i ++) {
130 nlab = ids.Value(i);
131 if (nlab == 0) continue;
132 nbe ++;
133 if (nlab < 0) nbu = 0;
134 else if (nlab == i) nbq = 0;
135 else if (nlab > 0) nbi ++;
136 }
137 if (nbe > 0) {
138// S <<" -- Displayed nums:"<<nbe<<" with ident=num:"<<nbq<<" , distinct proper ident:"<<nbi<<"\n";
139 if (nbu > 0) {
140 S<<" (no ident): ";
141 for (i = 1; i <= nb; i ++)
142 { if (ids.Value(i) >= 0) continue; S<<" #"<<i; }
143 S<<endl;
144 }
145 if (nbq > 0) {
146 S<<" (ident = num): ";
147 for (i = 1; i <= nb; i ++) { if (ids.Value(i) == i) S<<" #"<<i; }
148 S<<endl;
149 }
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;
152 char unid[30];
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));
60be1f9b 158 nbc = (Standard_Integer) strlen (unid); nbr = ((80-nbc) %4) +2;
7fd59977 159 nbl += nbc;
160 if (nbl+nbr0 > 79) { nbl = nbc; S<<endl; }
161 else { nbl += nbr0; for (; nbr0 > 0; nbr0 --) S << " "; }
162 S<<unid;
163 nbr0 = nbr;
164
165// if (nbl+nbc > 79) { S<<endl<<unid; nbl = 0; }
166// else { S<<unid; }
167// nbl += (nbc+nbr);
168// nbr = ((80-nbc) % 4) +1;
169// S<<" "<<i<<" ->#"<<ids.Value(i);
170// nbl ++; if (nbl > 5) { nbl = nbr = 0; S<<endl; }
171 }
172 if (nbl > 0) S<<endl;
173 }
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;
176 }
177 if (level > 0)
178 {
179 Standard_SStream aStream;
180 thewriter.Print(aStream);
181 S << aStream;
182 }
183 return Standard_True;
184}
185
186
187Standard_Boolean StepData_StepDumper::Dump
188 (const Handle(Message_Messenger)& S, const Standard_Integer num,
189 const Standard_Integer level)
190{
191 if (num <= 0 || num > themodel->NbEntities()) return Standard_False;
192 Handle(Standard_Transient) ent = themodel->Value(num);
193 return Dump (S,ent,level);
194}