Test for 0022778: Bug in BRepMesh
[occt.git] / src / XSControl / XSControl_TransferWriter.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#include <XSControl_TransferWriter.ixx>
19#include <Standard_ErrorHandler.hxx>
20#include <Standard_Failure.hxx>
21#include <Transfer_SimpleBinderOfTransient.hxx>
22#include <Transfer_TransientMapper.hxx>
23#include <XSControl_Utils.hxx>
24
25#include <Message_Messenger.hxx>
26#include <Interface_Macros.hxx>
27#include <Interface_Check.hxx>
28
29
b311480e 30XSControl_TransferWriter::XSControl_TransferWriter ()
7fd59977 31{ theTransferWrite = new Transfer_FinderProcess; theTransferMode = 0; }
32
33 Handle(Transfer_FinderProcess) XSControl_TransferWriter::FinderProcess () const
34 { return theTransferWrite; }
35
36 void XSControl_TransferWriter::SetFinderProcess (const Handle(Transfer_FinderProcess)& FP)
37 { theTransferWrite = FP; }
38
39 Handle(XSControl_Controller) XSControl_TransferWriter::Controller () const
40 { return theController; }
41
42 void XSControl_TransferWriter::SetController (const Handle(XSControl_Controller)& ctl)
43{
44 theController = ctl;
45 Clear(-1);
46}
47
48 void XSControl_TransferWriter::Clear (const Standard_Integer mode)
49{
50 if (mode < 0 || theTransferWrite.IsNull())
51 theTransferWrite = new Transfer_FinderProcess;
52 else theTransferWrite->Clear();
53}
54
55 Standard_Integer XSControl_TransferWriter::TransferMode () const
56 { return theTransferMode; }
57
58 void XSControl_TransferWriter::SetTransferMode (const Standard_Integer mod)
59 { theTransferMode = mod; }
60
61 void XSControl_TransferWriter::PrintStats
62 (const Standard_Integer , const Standard_Integer ) const
63{
64 Handle(Message_Messenger) sout = theTransferWrite->Messenger();
65// A ameliorer ... !
66 sout<<"\n*******************************************************************\n";
67 sout << "****** Statistics on Transfer (Write) ******"<<endl;
68 sout<<"\n*******************************************************************\n";
69 sout << "****** Transfer Mode = "<<theTransferMode;
70 Standard_CString modehelp = theController->ModeWriteHelp (theTransferMode);
71 if (modehelp && modehelp[0] != 0) sout<<" I.E. "<<modehelp;
72 sout<<" ******"<<endl;
73}
74
75
76// ########## LES ACTIONS ##########
77
78 Standard_Boolean XSControl_TransferWriter::RecognizeTransient
79 (const Handle(Standard_Transient)& obj)
80{
81 if (theController.IsNull()) return Standard_False;
82 XSControl_Utils xu;
83 TopoDS_Shape sh = xu.BinderShape (obj);
84 if (!sh.IsNull()) return RecognizeShape (sh);
85 return theController->RecognizeWriteTransient (obj,theTransferMode);
86}
87
88 IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteTransient
89 (const Handle(Interface_InterfaceModel)& model,
90 const Handle(Standard_Transient)& obj)
91{
92 IFSelect_ReturnStatus status = IFSelect_RetVoid;
93 if (theController.IsNull()) return IFSelect_RetError;
94 if (model.IsNull()) return IFSelect_RetVoid;
95
96 if (theTransferWrite.IsNull()) theTransferWrite = new Transfer_FinderProcess;
97 Handle(Transfer_ActorOfFinderProcess) nulact;
98 theTransferWrite->SetActor (nulact);
99 Handle(Standard_Transient) resultat;
100 Handle(Message_Messenger) sout = theTransferWrite->Messenger();
101 try {
102 OCC_CATCH_SIGNALS
103 PrintStats(theTransferMode);
104 sout << "****** Transferring Transient, CDL Type = ";
105 sout<<obj->DynamicType()->Name()<<" ******"<<endl;
106 status = theController->TransferWriteTransient
107 (obj,theTransferWrite,model,theTransferMode);
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
118
119 Standard_Boolean XSControl_TransferWriter::RecognizeShape
120 (const TopoDS_Shape& shape)
121{
122 if (theController.IsNull()) return Standard_False;
123 if (shape.IsNull()) return Standard_False;
124 return theController->RecognizeWriteShape (shape,theTransferMode);
125}
126
127
128 IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteShape
129 (const Handle(Interface_InterfaceModel)& model,
130 const TopoDS_Shape& shape)
131{
132 IFSelect_ReturnStatus status = IFSelect_RetVoid;
133 if (theController.IsNull()) return IFSelect_RetError;
134 if (model.IsNull()) return IFSelect_RetVoid;
135
136 if (theTransferWrite.IsNull()) theTransferWrite = new Transfer_FinderProcess;
137// effacer l actor : Controller s en charge
138 Handle(Transfer_ActorOfFinderProcess) nulact;
139 theTransferWrite->SetActor (nulact);
140 Handle(Standard_Transient) resultat;
141 Handle(Message_Messenger) sout = theTransferWrite->Messenger();
142 try {
143 OCC_CATCH_SIGNALS
144 PrintStats(theTransferMode);
145 sout << "****** Transferring Shape, ShapeType = " << shape.ShapeType();
146 sout<<" ******"<<endl;
147 status = theController->TransferWriteShape
148 (shape,theTransferWrite,model,theTransferMode);
149 }
150 catch(Standard_Failure) {
151 sout<<"**** **** TransferWriteShape, EXCEPTION : ";
152 sout<<Standard_Failure::Caught()->GetMessageString();
153 sout<<endl;
154 status = IFSelect_RetFail;
155 }
156 return status;
157}
158
159
160 Interface_CheckIterator XSControl_TransferWriter::CheckList () const
161{
162 Interface_CheckIterator chl;
163 if (theTransferWrite.IsNull()) return chl;
164 Standard_Integer i, nb = theTransferWrite->NbMapped();
165 for (i = 1; i <= nb; i ++) {
166 DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,theTransferWrite->MapItem
167(i));
168 if (tb.IsNull()) continue;
169 Handle(Interface_Check) ach = tb->Check();
170 if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue;
171 DeclareAndCast(Transfer_TransientMapper,tm,theTransferWrite->Mapped(i));
172 if (tm.IsNull()) ach->GetEntity (theTransferWrite->Mapped(i));
173 else ach->GetEntity (tm->Value());
174 chl.Add(ach);
175 }
176 return chl;
177}
178
179 Interface_CheckIterator XSControl_TransferWriter::ResultCheckList
180 (const Handle(Interface_InterfaceModel)& model) const
181{
182 Interface_CheckIterator chl;
183 if (theTransferWrite.IsNull()) return chl;
184 Standard_Integer i, nb = theTransferWrite->NbMapped();
185 for (i = 1; i <= nb; i ++) {
186 DeclareAndCast(Transfer_SimpleBinderOfTransient,tb,theTransferWrite->MapItem
187(i));
188 if (tb.IsNull()) continue;
189 const Handle(Interface_Check) ach = tb->Check();
190 if (ach->NbFails() == 0 || ach->NbWarnings() == 0) continue;
191 Handle(Standard_Transient) ent = tb->Result();
192 if (!ent.IsNull() && !model.IsNull()) chl.Add(ach,model->Number(ent));
193 else chl.Add(ach,0);
194 }
195 return chl;
196}
197
198 void XSControl_TransferWriter::PrintStatsProcess
199 (const Handle(Transfer_FinderProcess)& ,
200 const Standard_Integer , const Standard_Integer )
201{ }