1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <TransferBRep_Reader.ixx>
16 #include <Interface_Macros.hxx>
17 #include <Interface_CheckTool.hxx>
18 #include <Transfer_TransferOutput.hxx>
19 #include <Transfer_TransientProcess.hxx>
20 #include <TransferBRep.hxx>
22 #include <TopoDS_Compound.hxx>
23 #include <BRep_Builder.hxx>
24 #include <Message_Messenger.hxx>
26 TransferBRep_Reader::TransferBRep_Reader ()
27 : theDone (Standard_False) , theFilest (0) , theNewpr (Standard_False)
28 { theShapes = new TopTools_HSequenceOfShape(); theTransi = new TColStd_HSequenceOfTransient(); }
30 void TransferBRep_Reader::SetProtocol
31 (const Handle(Interface_Protocol)& protocol)
32 { theProto = protocol; }
34 Handle(Interface_Protocol) TransferBRep_Reader::Protocol () const
37 void TransferBRep_Reader::SetActor
38 (const Handle(Transfer_ActorOfTransientProcess)& actor)
41 Handle(Transfer_ActorOfTransientProcess) TransferBRep_Reader::Actor () const
44 void TransferBRep_Reader::SetFileStatus (const Standard_Integer status)
45 { theFilest = status; }
47 Standard_Integer TransferBRep_Reader::FileStatus () const
50 Standard_Boolean TransferBRep_Reader::FileNotFound () const
51 { return (theFilest < 0); }
53 Standard_Boolean TransferBRep_Reader::SyntaxError () const
54 { return (theFilest > 0); }
57 void TransferBRep_Reader::SetModel
58 (const Handle(Interface_InterfaceModel)& model)
64 Handle(Interface_InterfaceModel) TransferBRep_Reader::Model () const
68 void TransferBRep_Reader::Clear ()
70 theDone = Standard_False;
71 theShapes->Clear(); theTransi->Clear();
74 Standard_Boolean TransferBRep_Reader::CheckStatusModel
75 (const Standard_Boolean withprint) const
77 Interface_CheckTool cht (theModel,theProto);
78 Interface_CheckIterator chl = cht.CompleteCheckList();
79 if ( withprint && ! theProc.IsNull() )
80 chl.Print (theProc->Messenger(), theModel, Standard_False);
81 return chl.IsEmpty(Standard_True);
84 Interface_CheckIterator TransferBRep_Reader::CheckListModel () const
86 Interface_CheckTool cht (theModel,theProto);
87 Interface_CheckIterator chl = cht.CompleteCheckList();
91 Standard_Boolean& TransferBRep_Reader::ModeNewTransfer ()
94 Standard_Boolean TransferBRep_Reader::BeginTransfer ()
96 theDone = Standard_False;
97 if (theModel.IsNull()) return Standard_False;
99 if (theNewpr || theProc.IsNull())
100 theProc = new Transfer_TransientProcess (theModel->NbEntities());
101 else theProc->Clear();
102 theProc->SetErrorHandle(Standard_True);
103 theProc->SetModel (theModel);
105 theProc->SetActor (theActor);
106 return Standard_True;
109 void TransferBRep_Reader::EndTransfer ()
111 theShapes->Append ( TransferBRep::Shapes (theProc,Standard_True) );
112 Standard_Integer i,nb = theProc->NbRoots();
113 for (i = 1; i <= nb; i ++) {
114 Handle(Standard_Transient) ent = theProc->Root(i);
115 Handle(Standard_Transient) res = theProc->FindTransient(ent);
116 if (!res.IsNull()) theTransi->Append (res);
118 theDone = Standard_True;
122 void TransferBRep_Reader::PrepareTransfer () { }
124 void TransferBRep_Reader::TransferRoots ()
127 if (!BeginTransfer()) return;
128 Transfer_TransferOutput TP (theProc,theModel);
130 TP.TransferRoots(theProto);
134 Standard_Boolean TransferBRep_Reader::Transfer (const Standard_Integer num)
136 if (!BeginTransfer()) return Standard_False;
137 if (num <= 0 || num > theModel->NbEntities()) return Standard_False;
138 Handle(Standard_Transient) ent = theModel->Value(num);
139 Transfer_TransferOutput TP (theProc,theModel);
141 if (theProc->TraceLevel() > 1) {
142 Handle(Message_Messenger) sout = theProc->Messenger();
143 sout<<"-- Transfer(Read) : ";
144 theModel->Print (ent,sout);
148 theProc->SetRoot(ent);
150 return Standard_True;
153 void TransferBRep_Reader::TransferList
154 (const Handle(TColStd_HSequenceOfTransient)& list)
156 if (!BeginTransfer()) return;
157 if (list.IsNull()) return;
158 Transfer_TransferOutput TP (theProc,theModel);
159 Standard_Integer i, nb = list->Length();
160 Handle(Message_Messenger) sout = theProc->Messenger();
162 if (theProc->TraceLevel() > 1)
163 sout<<"-- Transfer(Read-List) : "<<nb<<" Items"<<endl;
164 for (i = 1; i <= nb; i ++) {
165 Handle(Standard_Transient) ent = list->Value(i);
166 if (theModel->Number(ent) == 0) continue;
168 if (theProc->TraceLevel() > 1)
170 sout<<"-- Transfer(Read-List), Item "<<i<<" : ";
171 theModel->Print (ent,sout);
175 theProc->SetRoot(ent);
180 Standard_Boolean TransferBRep_Reader::IsDone () const
183 // ###### RESULTAT : SHAPES ######
185 Standard_Integer TransferBRep_Reader::NbShapes () const
186 { return theShapes->Length(); }
188 Handle(TopTools_HSequenceOfShape) TransferBRep_Reader::Shapes () const
189 { return theShapes; }
191 const TopoDS_Shape& TransferBRep_Reader::Shape
192 (const Standard_Integer num) const
193 { return theShapes->Value(num); }
195 TopoDS_Shape TransferBRep_Reader::OneShape () const
198 Standard_Integer nb = theShapes->Length();
199 if (nb == 0) return res;
200 else if (nb == 1) return theShapes->Value(1);
205 for (Standard_Integer i = 1; i <= nb; i ++) B.Add (C,theShapes->Value(i));
210 TopoDS_Shape TransferBRep_Reader::ShapeResult
211 (const Handle(Standard_Transient)& ent) const
212 { return TransferBRep::ShapeResult (theProc,ent); }
214 // ###### RESULTAT : TRANSIENTS ######
216 Standard_Integer TransferBRep_Reader::NbTransients () const
217 { return theTransi->Length(); }
219 Handle(TColStd_HSequenceOfTransient) TransferBRep_Reader::Transients () const
220 { return theTransi; }
222 Handle(Standard_Transient) TransferBRep_Reader::Transient
223 (const Standard_Integer num) const
224 { return theTransi->Value(num); }
227 // ###### CHECKS ######
229 Standard_Boolean TransferBRep_Reader::CheckStatusResult
230 (const Standard_Boolean withprint) const
232 Interface_CheckIterator chl;
233 if (!theProc.IsNull()) chl = theProc->CheckList(Standard_False);
234 if (withprint && ! theProc.IsNull())
235 chl.Print (theProc->Messenger(), theModel, Standard_False);
236 return chl.IsEmpty(Standard_True);
239 Interface_CheckIterator TransferBRep_Reader::CheckListResult () const
241 if (!theProc.IsNull()) return theProc->CheckList(Standard_False);
242 Interface_CheckIterator chbid; return chbid;
245 Handle(Transfer_TransientProcess) TransferBRep_Reader::TransientProcess
249 void TransferBRep_Reader::Destroy() {}