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