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