summaryrefslogtreecommitdiff
path: root/src/XSControl/XSControl_TransferWriter.cxx
blob: ec1b6a9ec921d2bbd27c80ca333c1ff7e16c9de7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <XSControl_TransferWriter.ixx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <Transfer_SimpleBinderOfTransient.hxx>
#include <Transfer_TransientMapper.hxx>
#include <XSControl_Utils.hxx>

#include <Message_Messenger.hxx>
#include <Interface_Macros.hxx>
#include <Interface_Check.hxx>


    XSControl_TransferWriter::XSControl_TransferWriter ()
{  theTransferWrite = new Transfer_FinderProcess;  theTransferMode = 0;  }

    Handle(Transfer_FinderProcess)  XSControl_TransferWriter::FinderProcess () const
      {  return theTransferWrite;  }

    void  XSControl_TransferWriter::SetFinderProcess (const Handle(Transfer_FinderProcess)& FP)
      {  theTransferWrite = FP;  }

    Handle(XSControl_Controller)  XSControl_TransferWriter::Controller () const
      {  return theController;  }

    void  XSControl_TransferWriter::SetController (const Handle(XSControl_Controller)& ctl)
{
  theController = ctl;
  Clear(-1);
}

    void  XSControl_TransferWriter::Clear (const Standard_Integer mode)
{
  if (mode < 0 || theTransferWrite.IsNull())
    theTransferWrite = new Transfer_FinderProcess;
  else theTransferWrite->Clear();
}

    Standard_Integer  XSControl_TransferWriter::TransferMode () const
      {  return theTransferMode;  }

    void  XSControl_TransferWriter::SetTransferMode (const Standard_Integer mod)
      {  theTransferMode = mod;  }

    void  XSControl_TransferWriter::PrintStats
  (const Standard_Integer , const Standard_Integer ) const
{
  Handle(Message_Messenger) sout = theTransferWrite->Messenger();
//  A ameliorer ... !
  sout<<"\n*******************************************************************\n";
  sout << "******        Statistics on Transfer (Write)                 ******"<<endl;
  sout<<"\n*******************************************************************\n";
  sout << "******        Transfer Mode = "<<theTransferMode;
  Standard_CString modehelp = theController->ModeWriteHelp (theTransferMode);
  if (modehelp && modehelp[0] != 0) sout<<"  I.E.  "<<modehelp;
  sout<<"       ******"<<endl;
}


//  ##########    LES ACTIONS    ##########

    Standard_Boolean  XSControl_TransferWriter::RecognizeTransient
  (const Handle(Standard_Transient)& obj)
{
  if (theController.IsNull()) return Standard_False;
  XSControl_Utils xu;
  TopoDS_Shape sh = xu.BinderShape (obj);
  if (!sh.IsNull()) return RecognizeShape (sh);
  return theController->RecognizeWriteTransient (obj,theTransferMode);
}

    IFSelect_ReturnStatus  XSControl_TransferWriter::TransferWriteTransient
  (const Handle(Interface_InterfaceModel)& model,
   const Handle(Standard_Transient)& obj)
{
  IFSelect_ReturnStatus status = IFSelect_RetVoid;
  if (theController.IsNull()) return IFSelect_RetError;
  if (model.IsNull()) return IFSelect_RetVoid;

  if (theTransferWrite.IsNull()) theTransferWrite = new Transfer_FinderProcess;
  Handle(Transfer_ActorOfFinderProcess) nulact;
  theTransferWrite->SetActor (nulact);
  Handle(Standard_Transient) resultat;
  Handle(Message_Messenger) sout = theTransferWrite->Messenger();
  try {
    OCC_CATCH_SIGNALS
    PrintStats(theTransferMode);
    sout << "******        Transferring Transient, CDL Type = ";
    sout<<obj->DynamicType()->Name()<<"   ******"<<endl;
    status = theController->TransferWriteTransient
      (obj,theTransferWrite,model,theTransferMode);
  }
  catch(Standard_Failure) {
    sout<<"****  ****  TransferWriteShape, EXCEPTION : ";
    sout<<Standard_Failure::Caught()->GetMessageString(); 
    sout<<endl;
    status = IFSelect_RetFail;
  }
  return status;
}


    Standard_Boolean  XSControl_TransferWriter::RecognizeShape
  (const TopoDS_Shape& shape)
{
  if (theController.IsNull()) return Standard_False;
  if (shape.IsNull()) return Standard_False;
  return theController->RecognizeWriteShape (shape,theTransferMode);
}


    IFSelect_ReturnStatus  XSControl_TransferWriter::TransferWriteShape
  (const Handle(Interface_InterfaceModel)& model,
   const TopoDS_Shape& shape)
{
  IFSelect_ReturnStatus status = IFSelect_RetVoid;
  if (theController.IsNull()) return IFSelect_RetError;
  if (model.IsNull()) return IFSelect_RetVoid;

  if (theTransferWrite.IsNull()) theTransferWrite = new Transfer_FinderProcess;
//  effacer l actor : Controller s en charge
  Handle(Transfer_ActorOfFinderProcess) nulact;
  theTransferWrite->SetActor (nulact);
  Handle(Standard_Transient) resultat;
  Handle(Message_Messenger) sout = theTransferWrite->Messenger();
  try {
    OCC_CATCH_SIGNALS
    PrintStats(theTransferMode);
    sout << "******        Transferring Shape, ShapeType = " << shape.ShapeType();
    sout<<"                      ******"<<endl;
    status = theController->TransferWriteShape
      (shape,theTransferWrite,model,theTransferMode);
  }
  catch(Standard_Failure) {
    sout<<"****  ****  TransferWriteShape, EXCEPTION : "; 
    sout<<Standard_Failure::Caught()->GetMessageString(); 
    sout<<endl;
    status = IFSelect_RetFail;
  }
  return status;
}


    Interface_CheckIterator  XSControl_TransferWriter::CheckList () const
{
  Interface_CheckIterator  chl;
  if (theTransferWrite.IsNull()) return chl;
  Standard_Integer i, nb = theTransferWrite->NbMapped();
  for (i = 1; i <= nb; i ++) {
    DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,theTransferWrite->MapItem
(i));
    if (tb.IsNull()) continue;
    Handle(Interface_Check) ach = tb->Check();
    if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue;
    DeclareAndCast(Transfer_TransientMapper,tm,theTransferWrite->Mapped(i));
    if (tm.IsNull()) ach->GetEntity (theTransferWrite->Mapped(i));
    else  ach->GetEntity (tm->Value());
    chl.Add(ach);
  }
  return chl;
}

    Interface_CheckIterator  XSControl_TransferWriter::ResultCheckList
  (const Handle(Interface_InterfaceModel)& model) const
{
  Interface_CheckIterator  chl;
  if (theTransferWrite.IsNull()) return chl;
  Standard_Integer i, nb = theTransferWrite->NbMapped();
  for (i = 1; i <= nb; i ++) {
    DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,theTransferWrite->MapItem
(i));
    if (tb.IsNull()) continue;
    const Handle(Interface_Check) ach = tb->Check();
    if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue;
    Handle(Standard_Transient) ent = tb->Result();
    if (!ent.IsNull() && !model.IsNull()) chl.Add(ach,model->Number(ent));
    else  chl.Add(ach,0);
  }
  return chl;
}

    void  XSControl_TransferWriter::PrintStatsProcess
  (const Handle(Transfer_FinderProcess)& ,
   const Standard_Integer , const Standard_Integer )
{  }