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.
15 #include <BRep_Builder.hxx>
16 #include <Interface_CheckIterator.hxx>
17 #include <Interface_CheckTool.hxx>
18 #include <Interface_InterfaceModel.hxx>
19 #include <Interface_Macros.hxx>
20 #include <Interface_Protocol.hxx>
21 #include <Message_Messenger.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <Standard_Transient.hxx>
24 #include <TopoDS_Compound.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <Transfer_ActorOfTransientProcess.hxx>
27 #include <Transfer_TransferOutput.hxx>
28 #include <Transfer_TransientProcess.hxx>
29 #include <TransferBRep.hxx>
30 #include <TransferBRep_Reader.hxx>
32 TransferBRep_Reader::TransferBRep_Reader ()
33 : theDone (Standard_False) , theFilest (0) , theNewpr (Standard_False)
34 { theShapes = new TopTools_HSequenceOfShape(); theTransi = new TColStd_HSequenceOfTransient(); }
36 void TransferBRep_Reader::SetProtocol
37 (const Handle(Interface_Protocol)& protocol)
38 { theProto = protocol; }
40 Handle(Interface_Protocol) TransferBRep_Reader::Protocol () const
43 void TransferBRep_Reader::SetActor
44 (const Handle(Transfer_ActorOfTransientProcess)& actor)
47 Handle(Transfer_ActorOfTransientProcess) TransferBRep_Reader::Actor () const
50 void TransferBRep_Reader::SetFileStatus (const Standard_Integer status)
51 { theFilest = status; }
53 Standard_Integer TransferBRep_Reader::FileStatus () const
56 Standard_Boolean TransferBRep_Reader::FileNotFound () const
57 { return (theFilest < 0); }
59 Standard_Boolean TransferBRep_Reader::SyntaxError () const
60 { return (theFilest > 0); }
63 void TransferBRep_Reader::SetModel
64 (const Handle(Interface_InterfaceModel)& model)
70 Handle(Interface_InterfaceModel) TransferBRep_Reader::Model () const
74 void TransferBRep_Reader::Clear ()
76 theDone = Standard_False;
77 theShapes->Clear(); theTransi->Clear();
80 Standard_Boolean TransferBRep_Reader::CheckStatusModel
81 (const Standard_Boolean withprint) const
83 Interface_CheckTool cht (theModel,theProto);
84 Interface_CheckIterator chl = cht.CompleteCheckList();
85 if ( withprint && ! theProc.IsNull() )
86 chl.Print (theProc->Messenger(), theModel, Standard_False);
87 return chl.IsEmpty(Standard_True);
90 Interface_CheckIterator TransferBRep_Reader::CheckListModel () const
92 Interface_CheckTool cht (theModel,theProto);
93 Interface_CheckIterator chl = cht.CompleteCheckList();
97 Standard_Boolean& TransferBRep_Reader::ModeNewTransfer ()
100 Standard_Boolean TransferBRep_Reader::BeginTransfer ()
102 theDone = Standard_False;
103 if (theModel.IsNull()) return Standard_False;
105 if (theNewpr || theProc.IsNull())
106 theProc = new Transfer_TransientProcess (theModel->NbEntities());
107 else theProc->Clear();
108 theProc->SetErrorHandle(Standard_True);
109 theProc->SetModel (theModel);
111 theProc->SetActor (theActor);
112 return Standard_True;
115 void TransferBRep_Reader::EndTransfer ()
117 theShapes->Append ( TransferBRep::Shapes (theProc,Standard_True) );
118 Standard_Integer i,nb = theProc->NbRoots();
119 for (i = 1; i <= nb; i ++) {
120 Handle(Standard_Transient) ent = theProc->Root(i);
121 Handle(Standard_Transient) res = theProc->FindTransient(ent);
122 if (!res.IsNull()) theTransi->Append (res);
124 theDone = Standard_True;
128 void TransferBRep_Reader::PrepareTransfer () { }
130 void TransferBRep_Reader::TransferRoots ()
133 if (!BeginTransfer()) return;
134 Transfer_TransferOutput TP (theProc,theModel);
136 TP.TransferRoots(theProto);
140 Standard_Boolean TransferBRep_Reader::Transfer (const Standard_Integer num)
142 if (!BeginTransfer()) return Standard_False;
143 if (num <= 0 || num > theModel->NbEntities()) return Standard_False;
144 Handle(Standard_Transient) ent = theModel->Value(num);
145 Transfer_TransferOutput TP (theProc,theModel);
147 if (theProc->TraceLevel() > 1) {
148 Handle(Message_Messenger) sout = theProc->Messenger();
149 sout<<"-- Transfer(Read) : ";
150 theModel->Print (ent,sout);
154 theProc->SetRoot(ent);
156 return Standard_True;
159 void TransferBRep_Reader::TransferList
160 (const Handle(TColStd_HSequenceOfTransient)& list)
162 if (!BeginTransfer()) return;
163 if (list.IsNull()) return;
164 Transfer_TransferOutput TP (theProc,theModel);
165 Standard_Integer i, nb = list->Length();
166 Handle(Message_Messenger) sout = theProc->Messenger();
168 if (theProc->TraceLevel() > 1)
169 sout<<"-- Transfer(Read-List) : "<<nb<<" Items"<<endl;
170 for (i = 1; i <= nb; i ++) {
171 Handle(Standard_Transient) ent = list->Value(i);
172 if (theModel->Number(ent) == 0) continue;
174 if (theProc->TraceLevel() > 1)
176 sout<<"-- Transfer(Read-List), Item "<<i<<" : ";
177 theModel->Print (ent,sout);
181 theProc->SetRoot(ent);
186 Standard_Boolean TransferBRep_Reader::IsDone () const
189 // ###### RESULTAT : SHAPES ######
191 Standard_Integer TransferBRep_Reader::NbShapes () const
192 { return theShapes->Length(); }
194 Handle(TopTools_HSequenceOfShape) TransferBRep_Reader::Shapes () const
195 { return theShapes; }
197 const TopoDS_Shape& TransferBRep_Reader::Shape
198 (const Standard_Integer num) const
199 { return theShapes->Value(num); }
201 TopoDS_Shape TransferBRep_Reader::OneShape () const
204 Standard_Integer nb = theShapes->Length();
205 if (nb == 0) return res;
206 else if (nb == 1) return theShapes->Value(1);
211 for (Standard_Integer i = 1; i <= nb; i ++) B.Add (C,theShapes->Value(i));
216 TopoDS_Shape TransferBRep_Reader::ShapeResult
217 (const Handle(Standard_Transient)& ent) const
218 { return TransferBRep::ShapeResult (theProc,ent); }
220 // ###### RESULTAT : TRANSIENTS ######
222 Standard_Integer TransferBRep_Reader::NbTransients () const
223 { return theTransi->Length(); }
225 Handle(TColStd_HSequenceOfTransient) TransferBRep_Reader::Transients () const
226 { return theTransi; }
228 Handle(Standard_Transient) TransferBRep_Reader::Transient
229 (const Standard_Integer num) const
230 { return theTransi->Value(num); }
233 // ###### CHECKS ######
235 Standard_Boolean TransferBRep_Reader::CheckStatusResult
236 (const Standard_Boolean withprint) const
238 Interface_CheckIterator chl;
239 if (!theProc.IsNull()) chl = theProc->CheckList(Standard_False);
240 if (withprint && ! theProc.IsNull())
241 chl.Print (theProc->Messenger(), theModel, Standard_False);
242 return chl.IsEmpty(Standard_True);
245 Interface_CheckIterator TransferBRep_Reader::CheckListResult () const
247 if (!theProc.IsNull()) return theProc->CheckList(Standard_False);
248 Interface_CheckIterator chbid; return chbid;
251 Handle(Transfer_TransientProcess) TransferBRep_Reader::TransientProcess
255 TransferBRep_Reader::~TransferBRep_Reader()