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.
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>
20 #include <Standard_ErrorHandler.hxx>
21 #include <Standard_Failure.hxx>
22 #include <Standard_Transient.hxx>
23 #include <Standard_Type.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <Transfer_ActorOfFinderProcess.hxx>
26 #include <Transfer_FinderProcess.hxx>
27 #include <Transfer_SimpleBinderOfTransient.hxx>
28 #include <Transfer_TransientMapper.hxx>
29 #include <XSControl_Controller.hxx>
30 #include <XSControl_TransferWriter.hxx>
31 #include <XSControl_Utils.hxx>
33 IMPLEMENT_STANDARD_RTTIEXT(XSControl_TransferWriter,MMgt_TShared)
35 XSControl_TransferWriter::XSControl_TransferWriter ()
36 { theTransferWrite = new Transfer_FinderProcess; theTransferMode = 0; }
38 Handle(Transfer_FinderProcess) XSControl_TransferWriter::FinderProcess () const
39 { return theTransferWrite; }
41 void XSControl_TransferWriter::SetFinderProcess (const Handle(Transfer_FinderProcess)& FP)
42 { theTransferWrite = FP; }
44 Handle(XSControl_Controller) XSControl_TransferWriter::Controller () const
45 { return theController; }
47 void XSControl_TransferWriter::SetController (const Handle(XSControl_Controller)& ctl)
53 void XSControl_TransferWriter::Clear (const Standard_Integer mode)
55 if (mode < 0 || theTransferWrite.IsNull())
56 theTransferWrite = new Transfer_FinderProcess;
57 else theTransferWrite->Clear();
60 Standard_Integer XSControl_TransferWriter::TransferMode () const
61 { return theTransferMode; }
63 void XSControl_TransferWriter::SetTransferMode (const Standard_Integer mod)
64 { theTransferMode = mod; }
66 void XSControl_TransferWriter::PrintStats
67 (const Standard_Integer , const Standard_Integer ) const
69 Handle(Message_Messenger) sout = theTransferWrite->Messenger();
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;
81 // ########## LES ACTIONS ##########
83 Standard_Boolean XSControl_TransferWriter::RecognizeTransient
84 (const Handle(Standard_Transient)& obj)
86 if (theController.IsNull()) return Standard_False;
88 TopoDS_Shape sh = xu.BinderShape (obj);
89 if (!sh.IsNull()) return RecognizeShape (sh);
90 return theController->RecognizeWriteTransient (obj,theTransferMode);
93 IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteTransient
94 (const Handle(Interface_InterfaceModel)& model,
95 const Handle(Standard_Transient)& obj)
97 IFSelect_ReturnStatus status = IFSelect_RetVoid;
98 if (theController.IsNull()) return IFSelect_RetError;
99 if (model.IsNull()) return IFSelect_RetVoid;
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();
108 PrintStats(theTransferMode);
109 sout << "****** Transferring Transient, CDL Type = ";
110 sout<<obj->DynamicType()->Name()<<" ******"<<endl;
111 status = theController->TransferWriteTransient
112 (obj,theTransferWrite,model,theTransferMode);
114 catch(Standard_Failure) {
115 sout<<"**** **** TransferWriteShape, EXCEPTION : ";
116 sout<<Standard_Failure::Caught()->GetMessageString();
118 status = IFSelect_RetFail;
124 Standard_Boolean XSControl_TransferWriter::RecognizeShape
125 (const TopoDS_Shape& shape)
127 if (theController.IsNull()) return Standard_False;
128 if (shape.IsNull()) return Standard_False;
129 return theController->RecognizeWriteShape (shape,theTransferMode);
133 IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteShape
134 (const Handle(Interface_InterfaceModel)& model,
135 const TopoDS_Shape& shape)
137 IFSelect_ReturnStatus status = IFSelect_RetVoid;
138 if (theController.IsNull()) return IFSelect_RetError;
139 if (model.IsNull()) return IFSelect_RetVoid;
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();
149 PrintStats(theTransferMode);
150 sout << "****** Transferring Shape, ShapeType = " << shape.ShapeType();
151 sout<<" ******"<<endl;
152 status = theController->TransferWriteShape
153 (shape,theTransferWrite,model,theTransferMode);
155 catch(Standard_Failure) {
156 sout<<"**** **** TransferWriteShape, EXCEPTION : ";
157 sout<<Standard_Failure::Caught()->GetMessageString();
159 status = IFSelect_RetFail;
165 Interface_CheckIterator XSControl_TransferWriter::CheckList () const
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
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());
184 Interface_CheckIterator XSControl_TransferWriter::ResultCheckList
185 (const Handle(Interface_InterfaceModel)& model) const
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
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));
203 void XSControl_TransferWriter::PrintStatsProcess
204 (const Handle(Transfer_FinderProcess)& ,
205 const Standard_Integer , const Standard_Integer )