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 | |
42cf5bc1 |
14 | |
15 | #include <Interface_Check.hxx> |
16 | #include <Interface_CheckIterator.hxx> |
17 | #include <Interface_InterfaceModel.hxx> |
18 | #include <Interface_Macros.hxx> |
c28d4a89 |
19 | #include <Interface_Static.hxx> |
42cf5bc1 |
20 | #include <Message_Messenger.hxx> |
7fd59977 |
21 | #include <Standard_ErrorHandler.hxx> |
22 | #include <Standard_Failure.hxx> |
42cf5bc1 |
23 | #include <Standard_Transient.hxx> |
24 | #include <Standard_Type.hxx> |
25 | #include <TopoDS_Shape.hxx> |
c04c30b3 |
26 | #include <Transfer_ActorOfFinderProcess.hxx> |
42cf5bc1 |
27 | #include <Transfer_FinderProcess.hxx> |
7fd59977 |
28 | #include <Transfer_SimpleBinderOfTransient.hxx> |
29 | #include <Transfer_TransientMapper.hxx> |
42cf5bc1 |
30 | #include <XSControl_Controller.hxx> |
31 | #include <XSControl_TransferWriter.hxx> |
7fd59977 |
32 | #include <XSControl_Utils.hxx> |
c28d4a89 |
33 | #include <ShapeUpgrade_RemoveLocations.hxx> |
7fd59977 |
34 | |
25e59720 |
35 | IMPLEMENT_STANDARD_RTTIEXT(XSControl_TransferWriter,Standard_Transient) |
92efcf78 |
36 | |
7fd59977 |
37 | |
7f56eba8 |
38 | //======================================================================= |
39 | //function : Clear |
40 | //purpose : |
41 | //======================================================================= |
7fd59977 |
42 | |
7f56eba8 |
43 | void XSControl_TransferWriter::Clear (const Standard_Integer mode) |
7fd59977 |
44 | { |
7f56eba8 |
45 | if (mode < 0 || myTransferWriter.IsNull()) |
46 | myTransferWriter = new Transfer_FinderProcess; |
47 | else myTransferWriter->Clear(); |
7fd59977 |
48 | } |
49 | |
7f56eba8 |
50 | //======================================================================= |
51 | //function : PrintStats |
52 | //purpose : |
53 | //======================================================================= |
7fd59977 |
54 | |
7f56eba8 |
55 | void XSControl_TransferWriter::PrintStats (const Standard_Integer , const Standard_Integer ) const |
7fd59977 |
56 | { |
0ebe5b0a |
57 | Message_Messenger::StreamBuffer sout = myTransferWriter->Messenger()->SendInfo(); |
7fd59977 |
58 | // A ameliorer ... ! |
59 | sout<<"\n*******************************************************************\n"; |
0ebe5b0a |
60 | sout << "****** Statistics on Transfer (Write) ******"<<std::endl; |
7fd59977 |
61 | sout<<"\n*******************************************************************\n"; |
7f56eba8 |
62 | sout << "****** Transfer Mode = "<<myTransferMode; |
63 | Standard_CString modehelp = myController->ModeWriteHelp (myTransferMode); |
7fd59977 |
64 | if (modehelp && modehelp[0] != 0) sout<<" I.E. "<<modehelp; |
0ebe5b0a |
65 | sout<<" ******"<<std::endl; |
7fd59977 |
66 | } |
67 | |
68 | |
69 | // ########## LES ACTIONS ########## |
70 | |
7f56eba8 |
71 | //======================================================================= |
72 | //function : RecognizeTransient |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | Standard_Boolean XSControl_TransferWriter::RecognizeTransient (const Handle(Standard_Transient)& obj) |
7fd59977 |
77 | { |
7f56eba8 |
78 | if (myController.IsNull()) return Standard_False; |
7fd59977 |
79 | XSControl_Utils xu; |
80 | TopoDS_Shape sh = xu.BinderShape (obj); |
81 | if (!sh.IsNull()) return RecognizeShape (sh); |
7f56eba8 |
82 | return myController->RecognizeWriteTransient (obj,myTransferMode); |
7fd59977 |
83 | } |
84 | |
7f56eba8 |
85 | //======================================================================= |
86 | //function : TransferWriteTransient |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteTransient |
7fd59977 |
91 | (const Handle(Interface_InterfaceModel)& model, |
92 | const Handle(Standard_Transient)& obj) |
93 | { |
94 | IFSelect_ReturnStatus status = IFSelect_RetVoid; |
7f56eba8 |
95 | if (myController.IsNull()) return IFSelect_RetError; |
7fd59977 |
96 | if (model.IsNull()) return IFSelect_RetVoid; |
97 | |
7f56eba8 |
98 | if (myTransferWriter.IsNull()) myTransferWriter = new Transfer_FinderProcess; |
7fd59977 |
99 | Handle(Transfer_ActorOfFinderProcess) nulact; |
7f56eba8 |
100 | myTransferWriter->SetActor (nulact); |
7fd59977 |
101 | Handle(Standard_Transient) resultat; |
0ebe5b0a |
102 | Message_Messenger::StreamBuffer sout = myTransferWriter->Messenger()->SendInfo(); |
7fd59977 |
103 | try { |
104 | OCC_CATCH_SIGNALS |
7f56eba8 |
105 | PrintStats(myTransferMode); |
7fd59977 |
106 | sout << "****** Transferring Transient, CDL Type = "; |
0ebe5b0a |
107 | sout<<obj->DynamicType()->Name()<<" ******"<<std::endl; |
7f56eba8 |
108 | status = myController->TransferWriteTransient |
109 | (obj,myTransferWriter,model,myTransferMode); |
7fd59977 |
110 | } |
9775fa61 |
111 | catch(Standard_Failure const& anException) { |
7fd59977 |
112 | sout<<"**** **** TransferWriteShape, EXCEPTION : "; |
9775fa61 |
113 | sout<<anException.GetMessageString(); |
0ebe5b0a |
114 | sout<<std::endl; |
7fd59977 |
115 | status = IFSelect_RetFail; |
116 | } |
117 | return status; |
118 | } |
119 | |
7f56eba8 |
120 | //======================================================================= |
121 | //function : RecognizeShape |
122 | //purpose : |
123 | //======================================================================= |
7fd59977 |
124 | |
7f56eba8 |
125 | Standard_Boolean XSControl_TransferWriter::RecognizeShape (const TopoDS_Shape& shape) |
7fd59977 |
126 | { |
7f56eba8 |
127 | if (myController.IsNull()) return Standard_False; |
7fd59977 |
128 | if (shape.IsNull()) return Standard_False; |
7f56eba8 |
129 | return myController->RecognizeWriteShape (shape,myTransferMode); |
7fd59977 |
130 | } |
131 | |
7f56eba8 |
132 | //======================================================================= |
133 | //function : TransferWriteShape |
134 | //purpose : |
135 | //======================================================================= |
7fd59977 |
136 | |
7f56eba8 |
137 | IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteShape |
c28d4a89 |
138 | (const Handle(Interface_InterfaceModel)& theModel, |
139 | const TopoDS_Shape& theShape) |
7fd59977 |
140 | { |
141 | IFSelect_ReturnStatus status = IFSelect_RetVoid; |
7f56eba8 |
142 | if (myController.IsNull()) return IFSelect_RetError; |
c28d4a89 |
143 | if (theModel.IsNull()) return IFSelect_RetVoid; |
144 | |
145 | TopoDS_Shape aShape = theShape; |
146 | Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold") != 0; |
147 | if (isNMMode) |
148 | { |
149 | ShapeUpgrade_RemoveLocations aRemLoc; |
150 | aRemLoc.SetRemoveLevel(TopAbs_COMPOUND); |
151 | aRemLoc.Remove(aShape); |
152 | aShape = aRemLoc.GetResult(); |
153 | } |
7fd59977 |
154 | |
7f56eba8 |
155 | if (myTransferWriter.IsNull()) myTransferWriter = new Transfer_FinderProcess; |
7fd59977 |
156 | // effacer l actor : Controller s en charge |
157 | Handle(Transfer_ActorOfFinderProcess) nulact; |
7f56eba8 |
158 | myTransferWriter->SetActor (nulact); |
7fd59977 |
159 | Handle(Standard_Transient) resultat; |
0ebe5b0a |
160 | Message_Messenger::StreamBuffer sout = myTransferWriter->Messenger()->SendInfo(); |
7fd59977 |
161 | try { |
162 | OCC_CATCH_SIGNALS |
7f56eba8 |
163 | PrintStats(myTransferMode); |
c28d4a89 |
164 | sout << "****** Transferring Shape, ShapeType = " << aShape.ShapeType(); |
0ebe5b0a |
165 | sout<<" ******"<<std::endl; |
7f56eba8 |
166 | status = myController->TransferWriteShape |
c28d4a89 |
167 | (aShape,myTransferWriter,theModel,myTransferMode); |
7fd59977 |
168 | } |
9775fa61 |
169 | catch(Standard_Failure const& anException) { |
7fd59977 |
170 | sout<<"**** **** TransferWriteShape, EXCEPTION : "; |
9775fa61 |
171 | sout<<anException.GetMessageString(); |
0ebe5b0a |
172 | sout<<std::endl; |
7fd59977 |
173 | status = IFSelect_RetFail; |
174 | } |
175 | return status; |
176 | } |
177 | |
7f56eba8 |
178 | //======================================================================= |
179 | //function : CheckList |
180 | //purpose : |
181 | //======================================================================= |
7fd59977 |
182 | |
7f56eba8 |
183 | Interface_CheckIterator XSControl_TransferWriter::CheckList () const |
7fd59977 |
184 | { |
185 | Interface_CheckIterator chl; |
7f56eba8 |
186 | if (myTransferWriter.IsNull()) return chl; |
187 | Standard_Integer i, nb = myTransferWriter->NbMapped(); |
7fd59977 |
188 | for (i = 1; i <= nb; i ++) { |
7f56eba8 |
189 | DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,myTransferWriter->MapItem(i)); |
7fd59977 |
190 | if (tb.IsNull()) continue; |
191 | Handle(Interface_Check) ach = tb->Check(); |
192 | if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue; |
7f56eba8 |
193 | DeclareAndCast(Transfer_TransientMapper,tm,myTransferWriter->Mapped(i)); |
194 | if (tm.IsNull()) ach->GetEntity (myTransferWriter->Mapped(i)); |
7fd59977 |
195 | else ach->GetEntity (tm->Value()); |
196 | chl.Add(ach); |
197 | } |
198 | return chl; |
199 | } |
200 | |
7f56eba8 |
201 | //======================================================================= |
202 | //function : ResultCheckList |
203 | //purpose : |
204 | //======================================================================= |
205 | |
206 | Interface_CheckIterator XSControl_TransferWriter::ResultCheckList |
7fd59977 |
207 | (const Handle(Interface_InterfaceModel)& model) const |
208 | { |
209 | Interface_CheckIterator chl; |
7f56eba8 |
210 | if (myTransferWriter.IsNull()) return chl; |
211 | Standard_Integer i, nb = myTransferWriter->NbMapped(); |
7fd59977 |
212 | for (i = 1; i <= nb; i ++) { |
7f56eba8 |
213 | DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,myTransferWriter->MapItem(i)); |
7fd59977 |
214 | if (tb.IsNull()) continue; |
215 | const Handle(Interface_Check) ach = tb->Check(); |
216 | if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue; |
217 | Handle(Standard_Transient) ent = tb->Result(); |
218 | if (!ent.IsNull() && !model.IsNull()) chl.Add(ach,model->Number(ent)); |
219 | else chl.Add(ach,0); |
220 | } |
221 | return chl; |
222 | } |