summaryrefslogtreecommitdiff
path: root/src/TransferBRep/TransferBRep_Reader.cxx
blob: f7e40bbfc571bbd75ca28d4fd3c7d8c888b4d25f (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include <TransferBRep_Reader.ixx>

#include <Interface_Macros.hxx>
#include <Interface_CheckTool.hxx>
#include <Transfer_TransferOutput.hxx>
#include <Transfer_TransientProcess.hxx>
#include <TransferBRep.hxx>

#include <TopoDS_Compound.hxx>
#include <BRep_Builder.hxx>
#include <Message_Messenger.hxx>

    TransferBRep_Reader::TransferBRep_Reader ()
    : theDone (Standard_False) , theFilest (0) , theNewpr (Standard_False)
      {    theShapes = new TopTools_HSequenceOfShape();  theTransi = new TColStd_HSequenceOfTransient();  }

    void  TransferBRep_Reader::SetProtocol
  (const Handle(Interface_Protocol)& protocol)
      {  theProto = protocol;  }

    Handle(Interface_Protocol)  TransferBRep_Reader::Protocol () const
      {  return theProto;  }

    void  TransferBRep_Reader::SetActor
  (const Handle(Transfer_ActorOfTransientProcess)& actor)
      {  theActor = actor;  }

    Handle(Transfer_ActorOfTransientProcess) TransferBRep_Reader::Actor () const
      {  return theActor;  }

    void  TransferBRep_Reader::SetFileStatus (const Standard_Integer status)
      {  theFilest = status;  }

    Standard_Integer  TransferBRep_Reader::FileStatus () const
      { return theFilest;  }

    Standard_Boolean  TransferBRep_Reader::FileNotFound () const
      {  return (theFilest < 0);  }

    Standard_Boolean  TransferBRep_Reader::SyntaxError () const
      {  return (theFilest > 0);  }


    void  TransferBRep_Reader::SetModel
  (const Handle(Interface_InterfaceModel)& model)
{
  theModel = model;
  Clear();
}

    Handle(Interface_InterfaceModel)  TransferBRep_Reader::Model () const
      {  return theModel;  }


    void  TransferBRep_Reader::Clear ()
{
  theDone = Standard_False;
  theShapes->Clear();  theTransi->Clear();
}

    Standard_Boolean  TransferBRep_Reader::CheckStatusModel
  (const Standard_Boolean withprint) const
{
  Interface_CheckTool cht (theModel,theProto);
  Interface_CheckIterator chl = cht.CompleteCheckList();
  if ( withprint && ! theProc.IsNull() ) 
    chl.Print (theProc->Messenger(), theModel, Standard_False);
  return chl.IsEmpty(Standard_True);
}

    Interface_CheckIterator  TransferBRep_Reader::CheckListModel () const
{
  Interface_CheckTool cht (theModel,theProto);
  Interface_CheckIterator chl = cht.CompleteCheckList();
  return chl;
}

    Standard_Boolean&  TransferBRep_Reader::ModeNewTransfer ()
      {  return theNewpr;  }

    Standard_Boolean  TransferBRep_Reader::BeginTransfer ()
{
  theDone = Standard_False;
  if (theModel.IsNull()) return Standard_False;

  if (theNewpr || theProc.IsNull())
    theProc = new Transfer_TransientProcess (theModel->NbEntities());
  else theProc->Clear();
  theProc->SetErrorHandle(Standard_True);
  theProc->SetModel (theModel);
  PrepareTransfer();
  theProc->SetActor (theActor);
  return Standard_True;
}

    void  TransferBRep_Reader::EndTransfer ()
{
  theShapes->Append ( TransferBRep::Shapes (theProc,Standard_True) );
  Standard_Integer i,nb = theProc->NbRoots();
  for (i = 1; i <= nb; i ++) {
    Handle(Standard_Transient) ent = theProc->Root(i);
    Handle(Standard_Transient) res = theProc->FindTransient(ent);
    if (!res.IsNull()) theTransi->Append (res);
  }
  theDone = Standard_True;
}


    void  TransferBRep_Reader::PrepareTransfer ()    {  }

    void  TransferBRep_Reader::TransferRoots ()
{
  Clear();
  if (!BeginTransfer()) return;
  Transfer_TransferOutput TP (theProc,theModel);

  TP.TransferRoots(theProto);
  EndTransfer();
}

    Standard_Boolean TransferBRep_Reader::Transfer (const Standard_Integer num)
{
  if (!BeginTransfer()) return Standard_False;
  if (num <= 0 || num > theModel->NbEntities()) return Standard_False;
  Handle(Standard_Transient) ent = theModel->Value(num);
  Transfer_TransferOutput TP (theProc,theModel);

  if (theProc->TraceLevel() > 1) {
    Handle(Message_Messenger) sout = theProc->Messenger();
    sout<<"--  Transfer(Read) : ";  
    theModel->Print (ent,sout);  
    sout<<endl;
  }
  TP.Transfer(ent);
  theProc->SetRoot(ent);
  EndTransfer();
  return Standard_True;
}

    void  TransferBRep_Reader::TransferList
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
  if (!BeginTransfer()) return;
  if (list.IsNull()) return;
  Transfer_TransferOutput TP (theProc,theModel);
  Standard_Integer i, nb = list->Length();
  Handle(Message_Messenger) sout = theProc->Messenger();

  if (theProc->TraceLevel() > 1) 
    sout<<"--  Transfer(Read-List) : "<<nb<<" Items"<<endl;
  for (i = 1; i <= nb; i ++) {
    Handle(Standard_Transient) ent = list->Value(i);
    if (theModel->Number(ent) == 0) continue;

    if (theProc->TraceLevel() > 1) 
    {
      sout<<"--  Transfer(Read-List), Item "<<i<<" : ";  
      theModel->Print (ent,sout);  
      sout<<endl;
    }
    TP.Transfer(ent);
    theProc->SetRoot(ent);
  }
  EndTransfer();
}

    Standard_Boolean  TransferBRep_Reader::IsDone () const
      {  return theDone;  }

//   ######    RESULTAT : SHAPES    ######

    Standard_Integer  TransferBRep_Reader::NbShapes () const
      {  return theShapes->Length();  }

    Handle(TopTools_HSequenceOfShape)  TransferBRep_Reader::Shapes () const
      {  return theShapes;  }

    const TopoDS_Shape&  TransferBRep_Reader::Shape
  (const Standard_Integer num) const
      {  return theShapes->Value(num);  }

    TopoDS_Shape  TransferBRep_Reader::OneShape () const
{
  TopoDS_Shape res;
  Standard_Integer nb = theShapes->Length();
  if (nb == 0) return res;
  else if (nb == 1) return theShapes->Value(1);
  else {
    TopoDS_Compound C;
    BRep_Builder B;
    B.MakeCompound(C);
    for (Standard_Integer i = 1; i <= nb; i ++)  B.Add (C,theShapes->Value(i));
    return C;
  }
}

    TopoDS_Shape  TransferBRep_Reader::ShapeResult
  (const Handle(Standard_Transient)& ent) const
      {  return TransferBRep::ShapeResult (theProc,ent);  }

//   ######    RESULTAT : TRANSIENTS    ######

    Standard_Integer  TransferBRep_Reader::NbTransients () const
      {  return theTransi->Length();  }

    Handle(TColStd_HSequenceOfTransient)  TransferBRep_Reader::Transients () const
      {  return theTransi;  }

    Handle(Standard_Transient)  TransferBRep_Reader::Transient
  (const Standard_Integer num) const
      {  return theTransi->Value(num);  }


//   ######    CHECKS    ######

    Standard_Boolean  TransferBRep_Reader::CheckStatusResult
  (const Standard_Boolean withprint) const
{
  Interface_CheckIterator chl;
  if (!theProc.IsNull()) chl = theProc->CheckList(Standard_False);
  if (withprint && ! theProc.IsNull()) 
    chl.Print (theProc->Messenger(), theModel, Standard_False);
  return chl.IsEmpty(Standard_True);
}

    Interface_CheckIterator  TransferBRep_Reader::CheckListResult () const
{
  if (!theProc.IsNull()) return theProc->CheckList(Standard_False);
  Interface_CheckIterator chbid;  return chbid;
}

    Handle(Transfer_TransientProcess)  TransferBRep_Reader::TransientProcess
  () const
      {  return theProc;  }

void TransferBRep_Reader::Destroy() {}