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 <BRep_Builder.hxx>
16 #include <BRep_Tool.hxx>
17 #include <BRepLib.hxx>
18 #include <Interface_Check.hxx>
19 #include <Interface_CheckIterator.hxx>
20 #include <Interface_InterfaceModel.hxx>
21 #include <Interface_Macros.hxx>
22 #include <Message_Msg.hxx>
23 #include <Message_Printer.hxx>
24 #include <Standard_ErrorHandler.hxx>
25 #include <Standard_Failure.hxx>
26 #include <Standard_Transient.hxx>
27 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS_HShape.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <Transfer_Binder.hxx>
33 #include <Transfer_FinderProcess.hxx>
34 #include <Transfer_IteratorOfProcessForTransient.hxx>
35 #include <Transfer_SimpleBinderOfTransient.hxx>
36 #include <Transfer_TransientProcess.hxx>
37 #include <TransferBRep.hxx>
38 #include <TransferBRep_BinderOfShape.hxx>
39 #include <TransferBRep_ShapeBinder.hxx>
40 #include <TransferBRep_ShapeListBinder.hxx>
41 #include <TransferBRep_ShapeMapper.hxx>
42 #include <TransferBRep_TransferResultInfo.hxx>
45 //#include <TransferBRep_Analyzer.hxx>
46 static void ShapeAppend
47 (const Handle(Transfer_Binder)& binder,
48 const Handle(TopTools_HSequenceOfShape)& shapes)
50 if (binder.IsNull()) return;
51 if (binder->IsKind(STANDARD_TYPE(TransferBRep_BinderOfShape))) {
52 DeclareAndCast(TransferBRep_BinderOfShape,shbind,binder);
53 if (shbind->HasResult()) shapes->Append (shbind->Result());
55 else if (binder->IsKind(STANDARD_TYPE(TransferBRep_ShapeListBinder))) {
56 DeclareAndCast(TransferBRep_ShapeListBinder,slbind,binder);
57 Standard_Integer i,nb = slbind->NbShapes();
58 for (i = 1; i <= nb; i ++) shapes->Append (slbind->Shape(i));
60 else if (binder->IsKind(STANDARD_TYPE(Transfer_SimpleBinderOfTransient))) {
61 DeclareAndCast(Transfer_SimpleBinderOfTransient,trbind,binder);
62 DeclareAndCast(TopoDS_HShape,hs,trbind->Result());
63 if (!hs.IsNull()) shapes->Append (hs->Shape());
65 Handle(Transfer_Binder) nextr = binder->NextResult();
66 if (!nextr.IsNull()) ShapeAppend (nextr,shapes);
70 TopoDS_Shape TransferBRep::ShapeResult
71 (const Handle(Transfer_Binder)& binder)
74 Handle(Transfer_Binder) bnd = binder;
75 while (!bnd.IsNull()) {
76 DeclareAndCast(TransferBRep_BinderOfShape,shb,bnd);
77 if (!shb.IsNull()) return shb->Result();
78 DeclareAndCast(Transfer_SimpleBinderOfTransient,hsb,bnd);
80 Handle(TopoDS_HShape) hsp = GetCasted(TopoDS_HShape,hsb->Result());
81 if (!hsp.IsNull()) return hsp->Shape();
83 bnd = bnd->NextResult();
88 TopoDS_Shape TransferBRep::ShapeResult
89 (const Handle(Transfer_TransientProcess)& TP,
90 const Handle(Standard_Transient)& ent)
93 Handle(Transfer_Binder) binder = TP->Find(ent);
94 if (binder.IsNull()) binder = GetCasted (Transfer_Binder,ent);
95 if (!binder.IsNull()) return TransferBRep::ShapeResult (binder);
96 DeclareAndCast(TopoDS_HShape,hsp,ent);
97 if (!hsp.IsNull()) return hsp->Shape();
102 void TransferBRep::SetShapeResult
103 (const Handle(Transfer_TransientProcess)& TP,
104 const Handle(Standard_Transient)& ent, const TopoDS_Shape& result)
106 if (result.IsNull() || ent.IsNull() || TP.IsNull()) return;
107 TP->Bind (ent,new TransferBRep_ShapeBinder(result));
111 Handle(TopTools_HSequenceOfShape) TransferBRep::Shapes
112 (const Handle(Transfer_TransientProcess)& TP, const Standard_Boolean roots)
114 Handle(TopTools_HSequenceOfShape) shapes;
115 if (TP.IsNull()) return shapes;
116 shapes = new TopTools_HSequenceOfShape();
118 Transfer_IteratorOfProcessForTransient list =
119 (roots ? TP->RootResult() : TP->CompleteResult());
121 for (list.Start(); list.More(); list.Next()) {
122 Handle(Transfer_Binder) binder = list.Value();
123 ShapeAppend (binder,shapes);
128 Handle(TopTools_HSequenceOfShape) TransferBRep::Shapes
129 (const Handle(Transfer_TransientProcess)& TP,
130 const Handle(TColStd_HSequenceOfTransient)& list)
132 Handle(TopTools_HSequenceOfShape) shapes;
133 if (TP.IsNull() && list.IsNull()) return shapes;
134 shapes = new TopTools_HSequenceOfShape();
136 Standard_Integer ie, ne = list->Length();
137 for (ie = 1; ie <= ne; ie ++) {
138 Handle(Transfer_Binder) binder = TP->Find(list->Value(ie));
139 ShapeAppend (binder,shapes);
146 TopAbs_Orientation TransferBRep::ShapeState
147 (const Handle(Transfer_FinderProcess)& FP, const TopoDS_Shape& shape)
149 if (FP.IsNull() || shape.IsNull()) return TopAbs_EXTERNAL;
150 Handle(TransferBRep_ShapeMapper) sm = new TransferBRep_ShapeMapper(shape);
151 Standard_Integer index = FP->MapIndex (sm);
152 if (index == 0) return TopAbs_EXTERNAL;
153 sm = Handle(TransferBRep_ShapeMapper)::DownCast(FP->Mapped(index));
154 if (sm.IsNull()) return TopAbs_EXTERNAL;
155 const TopoDS_Shape& mapped = sm->Value();
156 // l egalite est assumee, on ne teste que l orientation
157 if (mapped.Orientation() != shape.Orientation()) return TopAbs_REVERSED;
158 return TopAbs_FORWARD;
161 Handle(Transfer_Binder) TransferBRep::ResultFromShape
162 (const Handle(Transfer_FinderProcess)& FP, const TopoDS_Shape& shape)
164 Handle(Transfer_Binder) res;
165 if (FP.IsNull() || shape.IsNull()) return res;
166 Handle(TransferBRep_ShapeMapper) sm = new TransferBRep_ShapeMapper(shape);
167 return FP->Find (sm);
170 Handle(Standard_Transient) TransferBRep::TransientFromShape
171 (const Handle(Transfer_FinderProcess)& FP, const TopoDS_Shape& shape)
173 Handle(Standard_Transient) res;
174 if (FP.IsNull() || shape.IsNull()) return res;
175 Handle(TransferBRep_ShapeMapper) sm = new TransferBRep_ShapeMapper(shape);
176 return FP->FindTransient (sm);
180 void TransferBRep::SetTransientFromShape
181 (const Handle(Transfer_FinderProcess)& FP,
182 const TopoDS_Shape& shape, const Handle(Standard_Transient)& result)
184 if (FP.IsNull() || shape.IsNull()) return;
185 Handle(TransferBRep_ShapeMapper) sm = new TransferBRep_ShapeMapper(shape);
186 FP->BindTransient (sm,result);
189 Handle(TransferBRep_ShapeMapper) TransferBRep::ShapeMapper
190 (const Handle(Transfer_FinderProcess)& FP,
191 const TopoDS_Shape& shape)
193 Handle(TransferBRep_ShapeMapper) mapper = new TransferBRep_ShapeMapper(shape);
194 Standard_Integer index = FP->MapIndex (mapper);
195 if (index == 0) return mapper;
196 return Handle(TransferBRep_ShapeMapper)::DownCast(FP->Mapped(index));
199 // Functions to collect transfer result information
201 //=======================================================================
202 //function : FillInfo
204 //=======================================================================
206 static void FillInfo (const Handle(Transfer_Binder)& Binder,
207 const Handle(Interface_Check)& Check,
208 const Handle(TransferBRep_TransferResultInfo)& Info)
210 Standard_Integer R = 0, RW = 0, RF = 0, RWF = 0, NR = 0, NRW = 0, NRF = 0, NRWF = 0;
211 if (Binder->HasResult())
212 if (Check->HasWarnings() && Check->HasFailed()) RWF++;
213 else if (Check->HasWarnings()) RW++;
214 else if (Check->HasFailed()) RF++;
217 if (Check->HasWarnings() && Check->HasFailed()) NRWF++;
218 else if (Check->HasWarnings()) NRW++;
219 else if (Check->HasFailed()) NRF++;
221 Info->Result() += R; Info->ResultWarning() += RW; Info->ResultFail() += RF; Info->ResultWarningFail() += RWF;
222 Info->NoResult() += NR; Info->NoResultWarning() += NRW; Info->NoResultFail() += NRF; Info->NoResultWarningFail() += NRWF;
225 //=======================================================================
226 //function : TransferResultInfo
228 //=======================================================================
230 void TransferBRep::TransferResultInfo (const Handle(Transfer_TransientProcess)& TP,
231 const Handle(TColStd_HSequenceOfTransient)& EntityTypes,
232 Handle(TransferBRep_HSequenceOfTransferResultInfo)& InfoSeq)
234 // create output Sequence in accordance with required ShapeTypes
235 InfoSeq = new TransferBRep_HSequenceOfTransferResultInfo;
236 if (TP.IsNull() || EntityTypes.IsNull()) return;
237 Standard_Integer SeqLen = EntityTypes->Length();
238 Standard_Integer i; // svv Jan11 2000 : porting on DEC
239 for (i = 1; i <= SeqLen; i++) {
240 InfoSeq->Append (new TransferBRep_TransferResultInfo);
244 Standard_Integer NbMapped = TP->NbMapped();
245 for (i = 1; i <= NbMapped; i++) {
246 Handle(Standard_Transient) Entity = TP->Mapped (i);
248 Handle(Transfer_Binder) Binder = TP->Find (Entity);
249 if (Binder.IsNull()) continue;
250 const Handle(Interface_Check) Check = Binder->Check ();
252 // find appropriate element in the Sequence
253 for (Standard_Integer index = 1; index <= SeqLen; index++) {
254 if (Entity->IsKind (EntityTypes->Value(index)->DynamicType())) {
255 Handle(TransferBRep_TransferResultInfo) Info = InfoSeq->Value (index);
257 FillInfo (Binder, Check, Info);
263 //=======================================================================
264 //function : TransferResultInfo
266 //=======================================================================
268 void TransferBRep::TransferResultInfo (const Handle(Transfer_FinderProcess)& FP,
269 const Handle(TColStd_HSequenceOfInteger)& ShapeTypes,
270 Handle(TransferBRep_HSequenceOfTransferResultInfo)& InfoSeq)
272 // create output Sequence in accordance with required ShapeTypes
273 InfoSeq = new TransferBRep_HSequenceOfTransferResultInfo;
274 if (FP.IsNull() || ShapeTypes.IsNull()) return;
275 Standard_Integer SeqLen = ShapeTypes->Length();
276 Standard_Integer i; // svv Jan11 2000 : porting on DEC
277 for (i = 1; i <= SeqLen; i++) {
278 InfoSeq->Append (new TransferBRep_TransferResultInfo);
282 Standard_Integer NbMapped = FP->NbMapped();
283 for (i = 1; i <= NbMapped; i++) {
284 Handle(TransferBRep_ShapeMapper) Mapper = Handle(TransferBRep_ShapeMapper)::DownCast (FP->Mapped (i));
285 Handle(Transfer_Binder) Binder = FP->Find (Mapper);
286 if (Binder.IsNull()) continue;
287 const Handle(Interface_Check) Check = Binder->Check ();
289 TopoDS_Shape S = Mapper->Value();
290 TopAbs_ShapeEnum ShapeType = S.ShapeType();
292 // find appropriate element in the Sequence
293 for (Standard_Integer index = 1; index <= SeqLen; index++) {
295 TopAbs_ShapeEnum CurrentType = (TopAbs_ShapeEnum)ShapeTypes->Value (index);
296 // TopAbs_ShapeEnum CurrentType = (TopAbs_ShapeEnum)ShapeTypes->Value (index);
297 if (CurrentType == ShapeType || CurrentType == TopAbs_SHAPE) {
298 Handle(TransferBRep_TransferResultInfo) Info = InfoSeq->Value (index);
300 FillInfo (Binder, Check, Info);
306 // ######## CHECK LOURD ########
308 // # # # # # # Enchainement General du CHECK LOURD # # # # # #
311 Interface_CheckIterator TransferBRep::BRepCheck
312 (const TopoDS_Shape& shape, const Standard_Integer lev)
314 Interface_CheckIterator result;
315 TransferBRep_Analyzer ana;
316 ana.Check (shape,lev);
317 return ana.CheckResult ();
321 // ### conversion resultat -> starting
323 Interface_CheckIterator TransferBRep::ResultCheckList
324 (const Interface_CheckIterator& chl,
325 const Handle(Transfer_FinderProcess)& FP,
326 const Handle(Interface_InterfaceModel)& model)
328 Interface_CheckIterator nchl;
329 if (FP.IsNull() || model.IsNull()) return nchl;
330 nchl.SetModel(model);
331 for (chl.Start(); chl.More(); chl.Next()) {
332 Standard_Integer num = 0;
333 Handle(Interface_Check) ach = chl.Value();
334 if (ach->NbFails() + ach->NbWarnings() == 0) continue;
335 DeclareAndCast(Transfer_Finder,starting,ach->Entity());
336 Handle(Standard_Transient) ent;
337 if (!starting.IsNull()) ent = FP->FindTransient(starting);
340 num = model->Number(ent);
347 Handle(TColStd_HSequenceOfTransient) TransferBRep::Checked
348 (const Interface_CheckIterator& chl, const Standard_Boolean alsoshapes)
350 Handle(TColStd_HSequenceOfTransient) ls = new TColStd_HSequenceOfTransient();
351 for (chl.Start(); chl.More(); chl.Next()) {
352 const Handle(Interface_Check) ach = chl.Value();
353 if (ach->NbFails() + ach->NbWarnings() == 0) continue;
354 Handle(Standard_Transient) ent = ach->Entity();
355 if (ent.IsNull()) continue;
357 if (ent->IsKind(STANDARD_TYPE(TransferBRep_BinderOfShape)) ||
358 ent->IsKind(STANDARD_TYPE(TopoDS_HShape)) ||
359 ent->IsKind(STANDARD_TYPE(TransferBRep_ShapeMapper)) ) continue;
366 Handle(TopTools_HSequenceOfShape) TransferBRep::CheckedShapes
367 (const Interface_CheckIterator& chl)
369 Handle(TopTools_HSequenceOfShape) ls = new TopTools_HSequenceOfShape();
370 for (chl.Start(); chl.More(); chl.Next()) {
371 const Handle(Interface_Check) ach = chl.Value();
372 if (ach->NbFails() + ach->NbWarnings() == 0) continue;
373 Handle(Standard_Transient) ent = ach->Entity();
374 if (ent.IsNull()) continue;
375 DeclareAndCast(TopoDS_HShape,hs,ent);
376 DeclareAndCast(TransferBRep_BinderOfShape,sb,ent);
377 DeclareAndCast(TransferBRep_ShapeMapper,sm,ent);
378 if (!hs.IsNull()) ls->Append (hs->Shape());
379 if (!sb.IsNull()) ls->Append (sb->Result());
380 if (!sm.IsNull()) ls->Append (sm->Value());
385 Interface_CheckIterator TransferBRep::CheckObject
386 (const Interface_CheckIterator& chl, const Handle(Standard_Transient)& obj)
389 DeclareAndCast(TopoDS_HShape,hs,obj);
390 DeclareAndCast(TransferBRep_BinderOfShape,sb,obj);
391 DeclareAndCast(TransferBRep_ShapeMapper,sm,obj);
392 if (!hs.IsNull()) S = hs->Shape();
393 if (!sb.IsNull()) S = sb->Result();
394 if (!sm.IsNull()) S = sm->Value();
395 Interface_CheckIterator nchl;
397 for (chl.Start(); chl.More(); chl.Next()) {
398 const Handle(Interface_Check) ach = chl.Value();
399 if (ach->NbFails() + ach->NbWarnings() == 0) continue;
400 Handle(Standard_Transient) ent = ach->Entity();
401 if (ent.IsNull()) continue;
404 Handle(Interface_Check) bch(ach); bch->SetEntity(ent);
409 DeclareAndCast(TopoDS_HShape,hsh,ent);
410 DeclareAndCast(TransferBRep_BinderOfShape,sbs,ent);
411 DeclareAndCast(TransferBRep_ShapeMapper,smp,ent);
412 if (!hsh.IsNull()) sh = hsh->Shape();
413 if (!sbs.IsNull()) sh = sbs->Result();
414 if (!smp.IsNull()) sh = smp->Value();
416 Handle(Interface_Check) bch(ach); bch->SetEntity(ent);
424 //=======================================================================
425 //function : PrintResultInfo
427 //=======================================================================
429 void TransferBRep::PrintResultInfo(const Handle(Message_Printer)& Printer,
430 const Message_Msg& Header,
431 const Handle(TransferBRep_TransferResultInfo)& ResultInfo,
432 const Standard_Boolean printEmpty)
434 Standard_Integer R, RW, RF, RWF, NR, NRW, NRF, NRWF;
435 R = ResultInfo->Result();
436 RW = ResultInfo->ResultWarning();
437 RF = ResultInfo->ResultFail();
438 RWF = ResultInfo->ResultWarningFail();
439 NR = ResultInfo->NoResult();
440 NRW = ResultInfo->NoResultWarning();
441 NRF = ResultInfo->NoResultFail();
442 NRWF = ResultInfo->NoResultWarningFail();
444 Message_Msg aLocalHeader = Header;
445 Printer->Send (aLocalHeader, Message_Info, Standard_True);
447 Message_Msg EPMSG30 ("Result.Print.MSG30"); // Result: %d
449 Printer->Send (EPMSG30, Message_Info, Standard_True);
450 if(printEmpty || (RW > 0 )) {
451 Message_Msg EPMSG32 ("Result.Print.MSG32"); // Result + Warning(s): %d
453 Printer->Send (EPMSG32, Message_Info, Standard_True);
455 if(printEmpty || (RF > 0 )) {
456 Message_Msg EPMSG34 ("Result.Print.MSG34"); // Result + Fail(s): %d
458 Printer->Send (EPMSG34, Message_Info, Standard_True);
460 if(printEmpty || (RWF > 0)) {
461 Message_Msg EPMSG36 ("Result.Print.MSG36"); // Result + Warning(s) + Fail(s): %d
463 Printer->Send (EPMSG36, Message_Info, Standard_True);
465 Message_Msg EPMSG38 ("Result.Print.MSG38"); // TOTAL Result: %d
466 EPMSG38.Arg (R + RW + RF + RWF);
467 Printer->Send (EPMSG38, Message_Info, Standard_True);
468 if(printEmpty || (NR > 0)) {
469 Message_Msg EPMSG40 ("Result.Print.MSG40"); // No Result: %d
471 Printer->Send (EPMSG40, Message_Info, Standard_True);
473 if(printEmpty || (NRW > 0)) {
474 Message_Msg EPMSG42 ("Result.Print.MSG42"); // No Result + Warning(s): %d
476 Printer->Send (EPMSG42, Message_Info, Standard_True);
478 if(printEmpty || (NRF > 0)) {
479 Message_Msg EPMSG44 ("Result.Print.MSG44"); // No Result + Fail(s): %d
481 Printer->Send (EPMSG44, Message_Info, Standard_True);
483 if(printEmpty || (NRWF > 0)) {
484 Message_Msg EPMSG46 ("Result.Print.MSG46"); // No Result + Warning(s) + Fail(s): %d
486 Printer->Send (EPMSG46, Message_Info, Standard_True);
489 Message_Msg EPMSG48 ("Result.Print.MSG48"); // TOTAL No Result: %d
490 EPMSG48.Arg (NR + NRW + NRF + NRWF);
491 Printer->Send (EPMSG48, Message_Info, Standard_True);