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 | // |
d5f74e42 |
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 |
973c2be1 |
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 | |
42cf5bc1 |
15 | #include <BRep_Builder.hxx> |
16 | #include <Interface_CheckIterator.hxx> |
7fd59977 |
17 | #include <Interface_CheckTool.hxx> |
42cf5bc1 |
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> |
7fd59977 |
27 | #include <Transfer_TransferOutput.hxx> |
28 | #include <Transfer_TransientProcess.hxx> |
29 | #include <TransferBRep.hxx> |
42cf5bc1 |
30 | #include <TransferBRep_Reader.hxx> |
7fd59977 |
31 | |
b311480e |
32 | TransferBRep_Reader::TransferBRep_Reader () |
7fd59977 |
33 | : theDone (Standard_False) , theFilest (0) , theNewpr (Standard_False) |
34 | { theShapes = new TopTools_HSequenceOfShape(); theTransi = new TColStd_HSequenceOfTransient(); } |
35 | |
36 | void TransferBRep_Reader::SetProtocol |
37 | (const Handle(Interface_Protocol)& protocol) |
38 | { theProto = protocol; } |
39 | |
40 | Handle(Interface_Protocol) TransferBRep_Reader::Protocol () const |
41 | { return theProto; } |
42 | |
43 | void TransferBRep_Reader::SetActor |
44 | (const Handle(Transfer_ActorOfTransientProcess)& actor) |
45 | { theActor = actor; } |
46 | |
47 | Handle(Transfer_ActorOfTransientProcess) TransferBRep_Reader::Actor () const |
48 | { return theActor; } |
49 | |
50 | void TransferBRep_Reader::SetFileStatus (const Standard_Integer status) |
51 | { theFilest = status; } |
52 | |
53 | Standard_Integer TransferBRep_Reader::FileStatus () const |
54 | { return theFilest; } |
55 | |
56 | Standard_Boolean TransferBRep_Reader::FileNotFound () const |
57 | { return (theFilest < 0); } |
58 | |
59 | Standard_Boolean TransferBRep_Reader::SyntaxError () const |
60 | { return (theFilest > 0); } |
61 | |
62 | |
63 | void TransferBRep_Reader::SetModel |
64 | (const Handle(Interface_InterfaceModel)& model) |
65 | { |
66 | theModel = model; |
67 | Clear(); |
68 | } |
69 | |
70 | Handle(Interface_InterfaceModel) TransferBRep_Reader::Model () const |
71 | { return theModel; } |
72 | |
73 | |
74 | void TransferBRep_Reader::Clear () |
75 | { |
76 | theDone = Standard_False; |
77 | theShapes->Clear(); theTransi->Clear(); |
78 | } |
79 | |
80 | Standard_Boolean TransferBRep_Reader::CheckStatusModel |
81 | (const Standard_Boolean withprint) const |
82 | { |
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); |
88 | } |
89 | |
90 | Interface_CheckIterator TransferBRep_Reader::CheckListModel () const |
91 | { |
92 | Interface_CheckTool cht (theModel,theProto); |
93 | Interface_CheckIterator chl = cht.CompleteCheckList(); |
94 | return chl; |
95 | } |
96 | |
97 | Standard_Boolean& TransferBRep_Reader::ModeNewTransfer () |
98 | { return theNewpr; } |
99 | |
100 | Standard_Boolean TransferBRep_Reader::BeginTransfer () |
101 | { |
102 | theDone = Standard_False; |
103 | if (theModel.IsNull()) return Standard_False; |
104 | |
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); |
110 | PrepareTransfer(); |
111 | theProc->SetActor (theActor); |
112 | return Standard_True; |
113 | } |
114 | |
115 | void TransferBRep_Reader::EndTransfer () |
116 | { |
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); |
123 | } |
124 | theDone = Standard_True; |
125 | } |
126 | |
127 | |
128 | void TransferBRep_Reader::PrepareTransfer () { } |
129 | |
130 | void TransferBRep_Reader::TransferRoots () |
131 | { |
132 | Clear(); |
133 | if (!BeginTransfer()) return; |
134 | Transfer_TransferOutput TP (theProc,theModel); |
135 | |
136 | TP.TransferRoots(theProto); |
137 | EndTransfer(); |
138 | } |
139 | |
140 | Standard_Boolean TransferBRep_Reader::Transfer (const Standard_Integer num) |
141 | { |
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); |
146 | |
147 | if (theProc->TraceLevel() > 1) { |
148 | Handle(Message_Messenger) sout = theProc->Messenger(); |
149 | sout<<"-- Transfer(Read) : "; |
150 | theModel->Print (ent,sout); |
151 | sout<<endl; |
152 | } |
153 | TP.Transfer(ent); |
154 | theProc->SetRoot(ent); |
155 | EndTransfer(); |
156 | return Standard_True; |
157 | } |
158 | |
159 | void TransferBRep_Reader::TransferList |
160 | (const Handle(TColStd_HSequenceOfTransient)& list) |
161 | { |
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(); |
167 | |
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; |
173 | |
174 | if (theProc->TraceLevel() > 1) |
175 | { |
176 | sout<<"-- Transfer(Read-List), Item "<<i<<" : "; |
177 | theModel->Print (ent,sout); |
178 | sout<<endl; |
179 | } |
180 | TP.Transfer(ent); |
181 | theProc->SetRoot(ent); |
182 | } |
183 | EndTransfer(); |
184 | } |
185 | |
186 | Standard_Boolean TransferBRep_Reader::IsDone () const |
187 | { return theDone; } |
188 | |
189 | // ###### RESULTAT : SHAPES ###### |
190 | |
191 | Standard_Integer TransferBRep_Reader::NbShapes () const |
192 | { return theShapes->Length(); } |
193 | |
194 | Handle(TopTools_HSequenceOfShape) TransferBRep_Reader::Shapes () const |
195 | { return theShapes; } |
196 | |
197 | const TopoDS_Shape& TransferBRep_Reader::Shape |
198 | (const Standard_Integer num) const |
199 | { return theShapes->Value(num); } |
200 | |
201 | TopoDS_Shape TransferBRep_Reader::OneShape () const |
202 | { |
203 | TopoDS_Shape res; |
204 | Standard_Integer nb = theShapes->Length(); |
205 | if (nb == 0) return res; |
206 | else if (nb == 1) return theShapes->Value(1); |
207 | else { |
208 | TopoDS_Compound C; |
209 | BRep_Builder B; |
210 | B.MakeCompound(C); |
211 | for (Standard_Integer i = 1; i <= nb; i ++) B.Add (C,theShapes->Value(i)); |
212 | return C; |
213 | } |
214 | } |
215 | |
216 | TopoDS_Shape TransferBRep_Reader::ShapeResult |
217 | (const Handle(Standard_Transient)& ent) const |
218 | { return TransferBRep::ShapeResult (theProc,ent); } |
219 | |
220 | // ###### RESULTAT : TRANSIENTS ###### |
221 | |
222 | Standard_Integer TransferBRep_Reader::NbTransients () const |
223 | { return theTransi->Length(); } |
224 | |
225 | Handle(TColStd_HSequenceOfTransient) TransferBRep_Reader::Transients () const |
226 | { return theTransi; } |
227 | |
228 | Handle(Standard_Transient) TransferBRep_Reader::Transient |
229 | (const Standard_Integer num) const |
230 | { return theTransi->Value(num); } |
231 | |
232 | |
233 | // ###### CHECKS ###### |
234 | |
235 | Standard_Boolean TransferBRep_Reader::CheckStatusResult |
236 | (const Standard_Boolean withprint) const |
237 | { |
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); |
243 | } |
244 | |
245 | Interface_CheckIterator TransferBRep_Reader::CheckListResult () const |
246 | { |
247 | if (!theProc.IsNull()) return theProc->CheckList(Standard_False); |
248 | Interface_CheckIterator chbid; return chbid; |
249 | } |
250 | |
251 | Handle(Transfer_TransientProcess) TransferBRep_Reader::TransientProcess |
252 | () const |
253 | { return theProc; } |
254 | |
255 | void TransferBRep_Reader::Destroy() {} |
256 | |