1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <XSControl_TransferWriter.ixx>
15 #include <Standard_ErrorHandler.hxx>
16 #include <Standard_Failure.hxx>
17 #include <Transfer_ActorOfFinderProcess.hxx>
18 #include <Transfer_SimpleBinderOfTransient.hxx>
19 #include <Transfer_TransientMapper.hxx>
20 #include <XSControl_Utils.hxx>
22 #include <Message_Messenger.hxx>
23 #include <Interface_Macros.hxx>
24 #include <Interface_Check.hxx>
27 XSControl_TransferWriter::XSControl_TransferWriter ()
28 { theTransferWrite = new Transfer_FinderProcess; theTransferMode = 0; }
30 Handle(Transfer_FinderProcess) XSControl_TransferWriter::FinderProcess () const
31 { return theTransferWrite; }
33 void XSControl_TransferWriter::SetFinderProcess (const Handle(Transfer_FinderProcess)& FP)
34 { theTransferWrite = FP; }
36 Handle(XSControl_Controller) XSControl_TransferWriter::Controller () const
37 { return theController; }
39 void XSControl_TransferWriter::SetController (const Handle(XSControl_Controller)& ctl)
45 void XSControl_TransferWriter::Clear (const Standard_Integer mode)
47 if (mode < 0 || theTransferWrite.IsNull())
48 theTransferWrite = new Transfer_FinderProcess;
49 else theTransferWrite->Clear();
52 Standard_Integer XSControl_TransferWriter::TransferMode () const
53 { return theTransferMode; }
55 void XSControl_TransferWriter::SetTransferMode (const Standard_Integer mod)
56 { theTransferMode = mod; }
58 void XSControl_TransferWriter::PrintStats
59 (const Standard_Integer , const Standard_Integer ) const
61 Handle(Message_Messenger) sout = theTransferWrite->Messenger();
63 sout<<"\n*******************************************************************\n";
64 sout << "****** Statistics on Transfer (Write) ******"<<endl;
65 sout<<"\n*******************************************************************\n";
66 sout << "****** Transfer Mode = "<<theTransferMode;
67 Standard_CString modehelp = theController->ModeWriteHelp (theTransferMode);
68 if (modehelp && modehelp[0] != 0) sout<<" I.E. "<<modehelp;
69 sout<<" ******"<<endl;
73 // ########## LES ACTIONS ##########
75 Standard_Boolean XSControl_TransferWriter::RecognizeTransient
76 (const Handle(Standard_Transient)& obj)
78 if (theController.IsNull()) return Standard_False;
80 TopoDS_Shape sh = xu.BinderShape (obj);
81 if (!sh.IsNull()) return RecognizeShape (sh);
82 return theController->RecognizeWriteTransient (obj,theTransferMode);
85 IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteTransient
86 (const Handle(Interface_InterfaceModel)& model,
87 const Handle(Standard_Transient)& obj)
89 IFSelect_ReturnStatus status = IFSelect_RetVoid;
90 if (theController.IsNull()) return IFSelect_RetError;
91 if (model.IsNull()) return IFSelect_RetVoid;
93 if (theTransferWrite.IsNull()) theTransferWrite = new Transfer_FinderProcess;
94 Handle(Transfer_ActorOfFinderProcess) nulact;
95 theTransferWrite->SetActor (nulact);
96 Handle(Standard_Transient) resultat;
97 Handle(Message_Messenger) sout = theTransferWrite->Messenger();
100 PrintStats(theTransferMode);
101 sout << "****** Transferring Transient, CDL Type = ";
102 sout<<obj->DynamicType()->Name()<<" ******"<<endl;
103 status = theController->TransferWriteTransient
104 (obj,theTransferWrite,model,theTransferMode);
106 catch(Standard_Failure) {
107 sout<<"**** **** TransferWriteShape, EXCEPTION : ";
108 sout<<Standard_Failure::Caught()->GetMessageString();
110 status = IFSelect_RetFail;
116 Standard_Boolean XSControl_TransferWriter::RecognizeShape
117 (const TopoDS_Shape& shape)
119 if (theController.IsNull()) return Standard_False;
120 if (shape.IsNull()) return Standard_False;
121 return theController->RecognizeWriteShape (shape,theTransferMode);
125 IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteShape
126 (const Handle(Interface_InterfaceModel)& model,
127 const TopoDS_Shape& shape)
129 IFSelect_ReturnStatus status = IFSelect_RetVoid;
130 if (theController.IsNull()) return IFSelect_RetError;
131 if (model.IsNull()) return IFSelect_RetVoid;
133 if (theTransferWrite.IsNull()) theTransferWrite = new Transfer_FinderProcess;
134 // effacer l actor : Controller s en charge
135 Handle(Transfer_ActorOfFinderProcess) nulact;
136 theTransferWrite->SetActor (nulact);
137 Handle(Standard_Transient) resultat;
138 Handle(Message_Messenger) sout = theTransferWrite->Messenger();
141 PrintStats(theTransferMode);
142 sout << "****** Transferring Shape, ShapeType = " << shape.ShapeType();
143 sout<<" ******"<<endl;
144 status = theController->TransferWriteShape
145 (shape,theTransferWrite,model,theTransferMode);
147 catch(Standard_Failure) {
148 sout<<"**** **** TransferWriteShape, EXCEPTION : ";
149 sout<<Standard_Failure::Caught()->GetMessageString();
151 status = IFSelect_RetFail;
157 Interface_CheckIterator XSControl_TransferWriter::CheckList () const
159 Interface_CheckIterator chl;
160 if (theTransferWrite.IsNull()) return chl;
161 Standard_Integer i, nb = theTransferWrite->NbMapped();
162 for (i = 1; i <= nb; i ++) {
163 DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,theTransferWrite->MapItem
165 if (tb.IsNull()) continue;
166 Handle(Interface_Check) ach = tb->Check();
167 if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue;
168 DeclareAndCast(Transfer_TransientMapper,tm,theTransferWrite->Mapped(i));
169 if (tm.IsNull()) ach->GetEntity (theTransferWrite->Mapped(i));
170 else ach->GetEntity (tm->Value());
176 Interface_CheckIterator XSControl_TransferWriter::ResultCheckList
177 (const Handle(Interface_InterfaceModel)& model) const
179 Interface_CheckIterator chl;
180 if (theTransferWrite.IsNull()) return chl;
181 Standard_Integer i, nb = theTransferWrite->NbMapped();
182 for (i = 1; i <= nb; i ++) {
183 DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,theTransferWrite->MapItem
185 if (tb.IsNull()) continue;
186 const Handle(Interface_Check) ach = tb->Check();
187 if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue;
188 Handle(Standard_Transient) ent = tb->Result();
189 if (!ent.IsNull() && !model.IsNull()) chl.Add(ach,model->Number(ent));
195 void XSControl_TransferWriter::PrintStatsProcess
196 (const Handle(Transfer_FinderProcess)& ,
197 const Standard_Integer , const Standard_Integer )