summaryrefslogtreecommitdiff
path: root/src/StepData/StepData_StepDumper.cxx
blob: bc5df94caad9d09b79b876d73e3d836794a4196c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <StepData_StepDumper.ixx>
#include <StepData_ReadWriteModule.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Interface_GeneralModule.hxx>
#include <Interface_EntityIterator.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
#include <Message_Messenger.hxx>
#include <Message.hxx>
#include <stdio.h>

StepData_StepDumper::StepData_StepDumper
  (const Handle(StepData_StepModel)& amodel,
   const Handle(StepData_Protocol)& protocol,
   const Standard_Integer mode)
    : theslib (protocol) , thewlib (protocol) , thewriter (amodel)
{
  themodel = amodel;
  if (mode > 0) thewriter.LabelMode () = 2;
}


StepData_StepWriter&  StepData_StepDumper::StepWriter ()
{
  return thewriter;
}


Standard_Boolean  StepData_StepDumper::Dump
  (const Handle(Message_Messenger)& S, const Handle(Standard_Transient)& ent,
   const Standard_Integer level)
{
  Standard_Integer i, nb = themodel->NbEntities();
  TColStd_Array1OfInteger ids(0,nb); ids.Init(0);
  Standard_Integer num  = themodel->Number(ent);
  Standard_Integer nlab = themodel->IdentLabel(ent);
  ids.SetValue(num, (nlab > 0 ? nlab : -1) );

  if (level <= 0) {
    Handle(StepData_ReadWriteModule) module;
    Standard_Integer CN;
    if (num > 0) S << "#" << num << " = ";
    else S << "#??? = ";
    if (thewlib.Select(ent,module,CN)) {
      if (module->IsComplex(CN)) {
	TColStd_SequenceOfAsciiString listypes;
	if (!module->ComplexType(CN,listypes))
	  S << "(Complex Type : ask level > 0) cdl = "
	    << ent->DynamicType()->Name() << " (...);" << endl;
	else {
	  Standard_Integer n = listypes.Length();
	  for (i = 1; i <= n; i ++) S << listypes.Value(i) << " (...)";
	  S << endl;
	}
      }
      else S << module->StepType(CN)  << " (...);" << endl;
    }
    else S << "(Unrecognized Type for protocol) cdl = "
        << ent->DynamicType()->Name() << " (...);" << endl;
    if (nlab > 0) S << "/*   Ident in file for "<<num<<" : #"<<nlab<<"   */"<<endl;
  }

  else if (level == 1) {
//  ...  Idents  ...
    Handle(Standard_Transient) anent;
    Handle(Interface_GeneralModule) module;  Standard_Integer CN;
    if (theslib.Select(ent,module,CN)) {
      Interface_EntityIterator iter;
      module->FillSharedCase  (CN,ent,iter);
      module->ListImpliedCase (CN,ent,iter);  // on cumule ...
      for (; iter.More(); iter.Next()) {
	anent = iter.Value();
	nlab = themodel->IdentLabel(anent);
	ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
      }
    }
//  ...  Envoi  ...
    thewriter.SendEntity (num,thewlib);
////    thewriter.Print(S);
  }
  else {
    Handle(Standard_Transient) anent;
//    S << " --  Dumping Entity n0 " << num << "  --" << endl;
//  ...  Envoi  ...
    TColStd_Array1OfInteger tab(0,nb); tab.Init(0);
    tab.SetValue(num,1);
    Handle(Interface_GeneralModule) module;  Standard_Integer CN;
    if (theslib.Select(ent,module,CN)) {
      Interface_EntityIterator iter;
      module->FillSharedCase  (CN,ent,iter);
      module->ListImpliedCase (CN,ent,iter);  // on cumule ...
      for (; iter.More(); iter.Next()) {
	tab.SetValue(themodel->Number(iter.Value()),1);
      }
    }
    for (i = 1; i <= nb; i ++) {
// ...   Listes des idents  ...
      if (tab.Value(i) == 0) continue;
      anent = themodel->Value(i);
      thewriter.SendEntity(i,thewlib);
      if (theslib.Select(anent,module,CN)) {
	Interface_EntityIterator iter;
	module->FillSharedCase  (CN,anent,iter);
	module->ListImpliedCase (CN,anent,iter);  // on cumule ...
	for (; iter.More(); iter.Next()) {
	  anent = iter.Value();
	  nlab = themodel->IdentLabel(anent);
	  ids.SetValue (themodel->Number(anent), (nlab > 0 ? nlab : -1) );
	}
      }
    }
////    thewriter.Print(S);
  }

//  ....  Affichage des idents  silya  ....
  Standard_Integer nbi = 0 , nbe = 0 , nbq = 0 , nbu = 0;
  for (i = 1; i <= nb; i ++) {
    nlab = ids.Value(i);
    if (nlab == 0) continue;
    nbe ++;
    if      (nlab <  0) nbu = 0;
    else if (nlab == i) nbq = 0;
    else if (nlab >  0) nbi ++;
  }
  if (nbe > 0) {
//    S <<" --   Displayed nums:"<<nbe<<"  with ident=num:"<<nbq<<" , distinct proper ident:"<<nbi<<"\n";
    if (nbu > 0) {
      S<<" (no ident): ";
      for (i = 1; i <= nb; i ++)
	{  if (ids.Value(i) >=  0) continue;	S<<" #"<<i;      }
      S<<endl;
    }
    if (nbq > 0) {
      S<<" (ident = num): ";
      for (i = 1; i <= nb; i ++)  {  if (ids.Value(i) == i) S<<" #"<<i;  }
      S<<endl;
    }
    if (nbi < 0) {  // on n affiche plus num:#id , on envoie un petit help
      Standard_Integer nbl = 0, nbr = 0, nbr0 = 0, nbc = 0;
      char unid[30];
//      S<<" (proper ident):  #num	     #ident"<<endl;
      S<<" (proper ident):  num:#ident  num:#ident  ..."<<endl;
      for (i = 1; i <= nb; i ++)  {
	if (ids.Value(i) <= 0 || ids.Value(i) == i) continue;
	sprintf (unid,"%d:#%d",i,ids.Value(i));
	nbc = strlen (unid);  nbr = ((80-nbc) %4) +2;
	nbl +=  nbc;
	if (nbl+nbr0 > 79) { nbl  = nbc;  S<<endl; }
	else               { nbl += nbr0; for (; nbr0 > 0; nbr0 --) S << " "; }
	S<<unid;
	nbr0 = nbr;

//	if (nbl+nbc > 79) { S<<endl<<unid; nbl  = 0; }
//	else              { S<<unid;       }
//	nbl += (nbc+nbr);
//	nbr = ((80-nbc) % 4) +1;
//	S<<"  "<<i<<" ->#"<<ids.Value(i);
//	nbl ++; if (nbl > 5) {  nbl = nbr = 0;  S<<endl;  }
      }
      if (nbl > 0) S<<endl;
    }
    if (nbi > 0) S<<"In dump, iii:#jjj means : entity rank iii has step ident #jjj"<<endl;
//    S <<" --   Dumping data, entity "<<num<<"  level "<<level<<" :"<<endl;
  }
  if (level > 0) 
  {
    Standard_SStream aStream;
    thewriter.Print(aStream);
    S << aStream;
  }
  return Standard_True;
}


Standard_Boolean  StepData_StepDumper::Dump
  (const Handle(Message_Messenger)& S, const Standard_Integer num,
   const Standard_Integer level)
{
  if (num <= 0 || num > themodel->NbEntities()) return Standard_False;
  Handle(Standard_Transient) ent = themodel->Value(num);
  return Dump (S,ent,level);
}