7fd59977 |
1 | #include <TransferBRep_Reader.ixx> |
2 | |
3 | #include <Interface_Macros.hxx> |
4 | #include <Interface_CheckTool.hxx> |
5 | #include <Transfer_TransferOutput.hxx> |
6 | #include <Transfer_TransientProcess.hxx> |
7 | #include <TransferBRep.hxx> |
8 | |
9 | #include <TopoDS_Compound.hxx> |
10 | #include <BRep_Builder.hxx> |
11 | #include <Message_Messenger.hxx> |
12 | |
13 | TransferBRep_Reader::TransferBRep_Reader () |
14 | : theDone (Standard_False) , theFilest (0) , theNewpr (Standard_False) |
15 | { theShapes = new TopTools_HSequenceOfShape(); theTransi = new TColStd_HSequenceOfTransient(); } |
16 | |
17 | void TransferBRep_Reader::SetProtocol |
18 | (const Handle(Interface_Protocol)& protocol) |
19 | { theProto = protocol; } |
20 | |
21 | Handle(Interface_Protocol) TransferBRep_Reader::Protocol () const |
22 | { return theProto; } |
23 | |
24 | void TransferBRep_Reader::SetActor |
25 | (const Handle(Transfer_ActorOfTransientProcess)& actor) |
26 | { theActor = actor; } |
27 | |
28 | Handle(Transfer_ActorOfTransientProcess) TransferBRep_Reader::Actor () const |
29 | { return theActor; } |
30 | |
31 | void TransferBRep_Reader::SetFileStatus (const Standard_Integer status) |
32 | { theFilest = status; } |
33 | |
34 | Standard_Integer TransferBRep_Reader::FileStatus () const |
35 | { return theFilest; } |
36 | |
37 | Standard_Boolean TransferBRep_Reader::FileNotFound () const |
38 | { return (theFilest < 0); } |
39 | |
40 | Standard_Boolean TransferBRep_Reader::SyntaxError () const |
41 | { return (theFilest > 0); } |
42 | |
43 | |
44 | void TransferBRep_Reader::SetModel |
45 | (const Handle(Interface_InterfaceModel)& model) |
46 | { |
47 | theModel = model; |
48 | Clear(); |
49 | } |
50 | |
51 | Handle(Interface_InterfaceModel) TransferBRep_Reader::Model () const |
52 | { return theModel; } |
53 | |
54 | |
55 | void TransferBRep_Reader::Clear () |
56 | { |
57 | theDone = Standard_False; |
58 | theShapes->Clear(); theTransi->Clear(); |
59 | } |
60 | |
61 | Standard_Boolean TransferBRep_Reader::CheckStatusModel |
62 | (const Standard_Boolean withprint) const |
63 | { |
64 | Interface_CheckTool cht (theModel,theProto); |
65 | Interface_CheckIterator chl = cht.CompleteCheckList(); |
66 | if ( withprint && ! theProc.IsNull() ) |
67 | chl.Print (theProc->Messenger(), theModel, Standard_False); |
68 | return chl.IsEmpty(Standard_True); |
69 | } |
70 | |
71 | Interface_CheckIterator TransferBRep_Reader::CheckListModel () const |
72 | { |
73 | Interface_CheckTool cht (theModel,theProto); |
74 | Interface_CheckIterator chl = cht.CompleteCheckList(); |
75 | return chl; |
76 | } |
77 | |
78 | Standard_Boolean& TransferBRep_Reader::ModeNewTransfer () |
79 | { return theNewpr; } |
80 | |
81 | Standard_Boolean TransferBRep_Reader::BeginTransfer () |
82 | { |
83 | theDone = Standard_False; |
84 | if (theModel.IsNull()) return Standard_False; |
85 | |
86 | if (theNewpr || theProc.IsNull()) |
87 | theProc = new Transfer_TransientProcess (theModel->NbEntities()); |
88 | else theProc->Clear(); |
89 | theProc->SetErrorHandle(Standard_True); |
90 | theProc->SetModel (theModel); |
91 | PrepareTransfer(); |
92 | theProc->SetActor (theActor); |
93 | return Standard_True; |
94 | } |
95 | |
96 | void TransferBRep_Reader::EndTransfer () |
97 | { |
98 | theShapes->Append ( TransferBRep::Shapes (theProc,Standard_True) ); |
99 | Standard_Integer i,nb = theProc->NbRoots(); |
100 | for (i = 1; i <= nb; i ++) { |
101 | Handle(Standard_Transient) ent = theProc->Root(i); |
102 | Handle(Standard_Transient) res = theProc->FindTransient(ent); |
103 | if (!res.IsNull()) theTransi->Append (res); |
104 | } |
105 | theDone = Standard_True; |
106 | } |
107 | |
108 | |
109 | void TransferBRep_Reader::PrepareTransfer () { } |
110 | |
111 | void TransferBRep_Reader::TransferRoots () |
112 | { |
113 | Clear(); |
114 | if (!BeginTransfer()) return; |
115 | Transfer_TransferOutput TP (theProc,theModel); |
116 | |
117 | TP.TransferRoots(theProto); |
118 | EndTransfer(); |
119 | } |
120 | |
121 | Standard_Boolean TransferBRep_Reader::Transfer (const Standard_Integer num) |
122 | { |
123 | if (!BeginTransfer()) return Standard_False; |
124 | if (num <= 0 || num > theModel->NbEntities()) return Standard_False; |
125 | Handle(Standard_Transient) ent = theModel->Value(num); |
126 | Transfer_TransferOutput TP (theProc,theModel); |
127 | |
128 | if (theProc->TraceLevel() > 1) { |
129 | Handle(Message_Messenger) sout = theProc->Messenger(); |
130 | sout<<"-- Transfer(Read) : "; |
131 | theModel->Print (ent,sout); |
132 | sout<<endl; |
133 | } |
134 | TP.Transfer(ent); |
135 | theProc->SetRoot(ent); |
136 | EndTransfer(); |
137 | return Standard_True; |
138 | } |
139 | |
140 | void TransferBRep_Reader::TransferList |
141 | (const Handle(TColStd_HSequenceOfTransient)& list) |
142 | { |
143 | if (!BeginTransfer()) return; |
144 | if (list.IsNull()) return; |
145 | Transfer_TransferOutput TP (theProc,theModel); |
146 | Standard_Integer i, nb = list->Length(); |
147 | Handle(Message_Messenger) sout = theProc->Messenger(); |
148 | |
149 | if (theProc->TraceLevel() > 1) |
150 | sout<<"-- Transfer(Read-List) : "<<nb<<" Items"<<endl; |
151 | for (i = 1; i <= nb; i ++) { |
152 | Handle(Standard_Transient) ent = list->Value(i); |
153 | if (theModel->Number(ent) == 0) continue; |
154 | |
155 | if (theProc->TraceLevel() > 1) |
156 | { |
157 | sout<<"-- Transfer(Read-List), Item "<<i<<" : "; |
158 | theModel->Print (ent,sout); |
159 | sout<<endl; |
160 | } |
161 | TP.Transfer(ent); |
162 | theProc->SetRoot(ent); |
163 | } |
164 | EndTransfer(); |
165 | } |
166 | |
167 | Standard_Boolean TransferBRep_Reader::IsDone () const |
168 | { return theDone; } |
169 | |
170 | // ###### RESULTAT : SHAPES ###### |
171 | |
172 | Standard_Integer TransferBRep_Reader::NbShapes () const |
173 | { return theShapes->Length(); } |
174 | |
175 | Handle(TopTools_HSequenceOfShape) TransferBRep_Reader::Shapes () const |
176 | { return theShapes; } |
177 | |
178 | const TopoDS_Shape& TransferBRep_Reader::Shape |
179 | (const Standard_Integer num) const |
180 | { return theShapes->Value(num); } |
181 | |
182 | TopoDS_Shape TransferBRep_Reader::OneShape () const |
183 | { |
184 | TopoDS_Shape res; |
185 | Standard_Integer nb = theShapes->Length(); |
186 | if (nb == 0) return res; |
187 | else if (nb == 1) return theShapes->Value(1); |
188 | else { |
189 | TopoDS_Compound C; |
190 | BRep_Builder B; |
191 | B.MakeCompound(C); |
192 | for (Standard_Integer i = 1; i <= nb; i ++) B.Add (C,theShapes->Value(i)); |
193 | return C; |
194 | } |
195 | } |
196 | |
197 | TopoDS_Shape TransferBRep_Reader::ShapeResult |
198 | (const Handle(Standard_Transient)& ent) const |
199 | { return TransferBRep::ShapeResult (theProc,ent); } |
200 | |
201 | // ###### RESULTAT : TRANSIENTS ###### |
202 | |
203 | Standard_Integer TransferBRep_Reader::NbTransients () const |
204 | { return theTransi->Length(); } |
205 | |
206 | Handle(TColStd_HSequenceOfTransient) TransferBRep_Reader::Transients () const |
207 | { return theTransi; } |
208 | |
209 | Handle(Standard_Transient) TransferBRep_Reader::Transient |
210 | (const Standard_Integer num) const |
211 | { return theTransi->Value(num); } |
212 | |
213 | |
214 | // ###### CHECKS ###### |
215 | |
216 | Standard_Boolean TransferBRep_Reader::CheckStatusResult |
217 | (const Standard_Boolean withprint) const |
218 | { |
219 | Interface_CheckIterator chl; |
220 | if (!theProc.IsNull()) chl = theProc->CheckList(Standard_False); |
221 | if (withprint && ! theProc.IsNull()) |
222 | chl.Print (theProc->Messenger(), theModel, Standard_False); |
223 | return chl.IsEmpty(Standard_True); |
224 | } |
225 | |
226 | Interface_CheckIterator TransferBRep_Reader::CheckListResult () const |
227 | { |
228 | if (!theProc.IsNull()) return theProc->CheckList(Standard_False); |
229 | Interface_CheckIterator chbid; return chbid; |
230 | } |
231 | |
232 | Handle(Transfer_TransientProcess) TransferBRep_Reader::TransientProcess |
233 | () const |
234 | { return theProc; } |
235 | |
236 | void TransferBRep_Reader::Destroy() {} |
237 | |