0024023: Revamp the OCCT Handle -- general
[occt.git] / src / XSControl / XSControl_TransferWriter.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
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>
21
22 #include <Message_Messenger.hxx>
23 #include <Interface_Macros.hxx>
24 #include <Interface_Check.hxx>
25
26
27 XSControl_TransferWriter::XSControl_TransferWriter ()
28 {  theTransferWrite = new Transfer_FinderProcess;  theTransferMode = 0;  }
29
30     Handle(Transfer_FinderProcess)  XSControl_TransferWriter::FinderProcess () const
31       {  return theTransferWrite;  }
32
33     void  XSControl_TransferWriter::SetFinderProcess (const Handle(Transfer_FinderProcess)& FP)
34       {  theTransferWrite = FP;  }
35
36     Handle(XSControl_Controller)  XSControl_TransferWriter::Controller () const
37       {  return theController;  }
38
39     void  XSControl_TransferWriter::SetController (const Handle(XSControl_Controller)& ctl)
40 {
41   theController = ctl;
42   Clear(-1);
43 }
44
45     void  XSControl_TransferWriter::Clear (const Standard_Integer mode)
46 {
47   if (mode < 0 || theTransferWrite.IsNull())
48     theTransferWrite = new Transfer_FinderProcess;
49   else theTransferWrite->Clear();
50 }
51
52     Standard_Integer  XSControl_TransferWriter::TransferMode () const
53       {  return theTransferMode;  }
54
55     void  XSControl_TransferWriter::SetTransferMode (const Standard_Integer mod)
56       {  theTransferMode = mod;  }
57
58     void  XSControl_TransferWriter::PrintStats
59   (const Standard_Integer , const Standard_Integer ) const
60 {
61   Handle(Message_Messenger) sout = theTransferWrite->Messenger();
62 //  A ameliorer ... !
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;
70 }
71
72
73 //  ##########    LES ACTIONS    ##########
74
75     Standard_Boolean  XSControl_TransferWriter::RecognizeTransient
76   (const Handle(Standard_Transient)& obj)
77 {
78   if (theController.IsNull()) return Standard_False;
79   XSControl_Utils xu;
80   TopoDS_Shape sh = xu.BinderShape (obj);
81   if (!sh.IsNull()) return RecognizeShape (sh);
82   return theController->RecognizeWriteTransient (obj,theTransferMode);
83 }
84
85     IFSelect_ReturnStatus  XSControl_TransferWriter::TransferWriteTransient
86   (const Handle(Interface_InterfaceModel)& model,
87    const Handle(Standard_Transient)& obj)
88 {
89   IFSelect_ReturnStatus status = IFSelect_RetVoid;
90   if (theController.IsNull()) return IFSelect_RetError;
91   if (model.IsNull()) return IFSelect_RetVoid;
92
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();
98   try {
99     OCC_CATCH_SIGNALS
100     PrintStats(theTransferMode);
101     sout << "******        Transferring Transient, CDL Type = ";
102     sout<<obj->DynamicType()->Name()<<"   ******"<<endl;
103     status = theController->TransferWriteTransient
104       (obj,theTransferWrite,model,theTransferMode);
105   }
106   catch(Standard_Failure) {
107     sout<<"****  ****  TransferWriteShape, EXCEPTION : ";
108     sout<<Standard_Failure::Caught()->GetMessageString(); 
109     sout<<endl;
110     status = IFSelect_RetFail;
111   }
112   return status;
113 }
114
115
116     Standard_Boolean  XSControl_TransferWriter::RecognizeShape
117   (const TopoDS_Shape& shape)
118 {
119   if (theController.IsNull()) return Standard_False;
120   if (shape.IsNull()) return Standard_False;
121   return theController->RecognizeWriteShape (shape,theTransferMode);
122 }
123
124
125     IFSelect_ReturnStatus  XSControl_TransferWriter::TransferWriteShape
126   (const Handle(Interface_InterfaceModel)& model,
127    const TopoDS_Shape& shape)
128 {
129   IFSelect_ReturnStatus status = IFSelect_RetVoid;
130   if (theController.IsNull()) return IFSelect_RetError;
131   if (model.IsNull()) return IFSelect_RetVoid;
132
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();
139   try {
140     OCC_CATCH_SIGNALS
141     PrintStats(theTransferMode);
142     sout << "******        Transferring Shape, ShapeType = " << shape.ShapeType();
143     sout<<"                      ******"<<endl;
144     status = theController->TransferWriteShape
145       (shape,theTransferWrite,model,theTransferMode);
146   }
147   catch(Standard_Failure) {
148     sout<<"****  ****  TransferWriteShape, EXCEPTION : "; 
149     sout<<Standard_Failure::Caught()->GetMessageString(); 
150     sout<<endl;
151     status = IFSelect_RetFail;
152   }
153   return status;
154 }
155
156
157     Interface_CheckIterator  XSControl_TransferWriter::CheckList () const
158 {
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
164 (i));
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());
171     chl.Add(ach);
172   }
173   return chl;
174 }
175
176     Interface_CheckIterator  XSControl_TransferWriter::ResultCheckList
177   (const Handle(Interface_InterfaceModel)& model) const
178 {
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
184 (i));
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));
190     else  chl.Add(ach,0);
191   }
192   return chl;
193 }
194
195     void  XSControl_TransferWriter::PrintStatsProcess
196   (const Handle(Transfer_FinderProcess)& ,
197    const Standard_Integer , const Standard_Integer )
198 {  }