| 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 | //: abv 09.04.99: S4136: remove parameter lastpreci |
| 15 | // szv#11:CASCADE30:01Feb00 BRepBuilderAPI::Precision(p) removed |
| 16 | #include <XSControl_TransferReader.ixx> |
| 17 | #include <Standard_ErrorHandler.hxx> |
| 18 | #include <Standard_Failure.hxx> |
| 19 | #include <Transfer_SimpleBinderOfTransient.hxx> |
| 20 | #include <Transfer_ResultFromTransient.hxx> |
| 21 | #include <Transfer_TransferOutput.hxx> |
| 22 | |
| 23 | #include <TransferBRep.hxx> |
| 24 | #include <TransferBRep_BinderOfShape.hxx> |
| 25 | #include <TransferBRep_ShapeBinder.hxx> |
| 26 | #include <TopoDS_HShape.hxx> |
| 27 | #include <XSControl_Utils.hxx> |
| 28 | #include <TopTools_MapOfShape.hxx> |
| 29 | |
| 30 | // Precision : |
| 31 | #include <Interface_Static.hxx> |
| 32 | #include <BRepBuilderAPI.hxx> |
| 33 | |
| 34 | // Pour les regularites |
| 35 | #include <BRepLib.hxx> |
| 36 | |
| 37 | #include <Interface_EntityIterator.hxx> |
| 38 | #include <IFSelect_SignatureList.hxx> |
| 39 | #include <Interface_MSG.hxx> |
| 40 | |
| 41 | #include <TCollection_HAsciiString.hxx> |
| 42 | #include <Interface_Macros.hxx> |
| 43 | |
| 44 | #include <Transfer_IteratorOfProcessForTransient.hxx> |
| 45 | #include <IFSelect_CheckCounter.hxx> |
| 46 | |
| 47 | #include <Interface_InterfaceModel.hxx> |
| 48 | #include <Interface_SignLabel.hxx> |
| 49 | #include <Interface_Check.hxx> |
| 50 | |
| 51 | #include <Message_Messenger.hxx> |
| 52 | |
| 53 | #include <ShapeFix.hxx> |
| 54 | #include <Transfer_ResultFromModel.hxx> |
| 55 | #include <TColStd_HSequenceOfTransient.hxx> |
| 56 | #include <stdio.h> |
| 57 | |
| 58 | |
| 59 | //======================================================================= |
| 60 | //function : XSControl_TransferReader |
| 61 | //purpose : |
| 62 | //======================================================================= |
| 63 | |
| 64 | XSControl_TransferReader::XSControl_TransferReader () |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | |
| 69 | //======================================================================= |
| 70 | //function : SetController |
| 71 | //purpose : |
| 72 | //======================================================================= |
| 73 | |
| 74 | void XSControl_TransferReader::SetController(const Handle(XSControl_Controller)& control) |
| 75 | { |
| 76 | theController = control; |
| 77 | theActor.Nullify(); |
| 78 | Clear(-1); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | //======================================================================= |
| 83 | //function : SetActor |
| 84 | //purpose : |
| 85 | //======================================================================= |
| 86 | |
| 87 | void XSControl_TransferReader::SetActor |
| 88 | (const Handle(Transfer_ActorOfTransientProcess)& actor) |
| 89 | { |
| 90 | theActor = actor; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | //======================================================================= |
| 95 | //function : Actor |
| 96 | //purpose : |
| 97 | //======================================================================= |
| 98 | |
| 99 | Handle(Transfer_ActorOfTransientProcess) XSControl_TransferReader::Actor () |
| 100 | { |
| 101 | if ( theActor.IsNull() && !theController.IsNull() && !theModel.IsNull()) |
| 102 | theActor = theController->ActorRead(theModel); |
| 103 | return theActor; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | //======================================================================= |
| 108 | //function : SetModel |
| 109 | //purpose : |
| 110 | //======================================================================= |
| 111 | |
| 112 | void XSControl_TransferReader::SetModel(const Handle(Interface_InterfaceModel)& model) |
| 113 | { |
| 114 | theModel = model; |
| 115 | if (!theTransfer.IsNull()) theTransfer->SetModel(model); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | //======================================================================= |
| 120 | //function : SetGraph |
| 121 | //purpose : |
| 122 | //======================================================================= |
| 123 | |
| 124 | void XSControl_TransferReader::SetGraph(const Handle(Interface_HGraph)& graph) |
| 125 | { |
| 126 | if (graph.IsNull()) |
| 127 | { |
| 128 | theModel.Nullify(); |
| 129 | } |
| 130 | else |
| 131 | theModel = graph->Graph().Model(); |
| 132 | |
| 133 | theGraph = graph; |
| 134 | |
| 135 | if (!theTransfer.IsNull()) theTransfer->SetGraph(graph); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | //======================================================================= |
| 140 | //function : Model |
| 141 | //purpose : |
| 142 | //======================================================================= |
| 143 | |
| 144 | Handle(Interface_InterfaceModel) XSControl_TransferReader::Model () const |
| 145 | { |
| 146 | return theModel; |
| 147 | } |
| 148 | |
| 149 | |
| 150 | //======================================================================= |
| 151 | //function : SetContext |
| 152 | //purpose : |
| 153 | //======================================================================= |
| 154 | |
| 155 | void XSControl_TransferReader::SetContext(const Standard_CString name, |
| 156 | const Handle(Standard_Transient)& ctx) |
| 157 | { |
| 158 | if (theContext.IsNull()) theContext = new Dico_DictionaryOfTransient; |
| 159 | theContext->SetItem (name,ctx); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | //======================================================================= |
| 164 | //function : GetContext |
| 165 | //purpose : |
| 166 | //======================================================================= |
| 167 | |
| 168 | Standard_Boolean XSControl_TransferReader::GetContext |
| 169 | (const Standard_CString name, const Handle(Standard_Type)& type, |
| 170 | Handle(Standard_Transient)& ctx) const |
| 171 | { |
| 172 | if (theContext.IsNull()) return Standard_False; |
| 173 | if (!theContext->GetItem (name,ctx)) ctx.Nullify(); |
| 174 | if (ctx.IsNull()) return Standard_False; |
| 175 | if (type.IsNull()) return Standard_True; |
| 176 | if (!ctx->IsKind(type)) ctx.Nullify(); |
| 177 | return !ctx.IsNull(); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | //======================================================================= |
| 182 | //function : Context |
| 183 | //purpose : |
| 184 | //======================================================================= |
| 185 | |
| 186 | Handle(Dico_DictionaryOfTransient)& XSControl_TransferReader::Context () |
| 187 | { |
| 188 | return theContext; |
| 189 | } |
| 190 | |
| 191 | |
| 192 | //======================================================================= |
| 193 | //function : SetFileName |
| 194 | //purpose : |
| 195 | //======================================================================= |
| 196 | |
| 197 | void XSControl_TransferReader::SetFileName (const Standard_CString name) |
| 198 | { |
| 199 | theFilename.Clear(); |
| 200 | theFilename.AssignCat(name); |
| 201 | } |
| 202 | |
| 203 | |
| 204 | //======================================================================= |
| 205 | //function : FileName |
| 206 | //purpose : |
| 207 | //======================================================================= |
| 208 | |
| 209 | Standard_CString XSControl_TransferReader::FileName () const |
| 210 | { |
| 211 | return theFilename.ToCString(); |
| 212 | } |
| 213 | |
| 214 | |
| 215 | //======================================================================= |
| 216 | //function : Clear |
| 217 | //purpose : |
| 218 | //======================================================================= |
| 219 | |
| 220 | void XSControl_TransferReader::Clear (const Standard_Integer mode) |
| 221 | { |
| 222 | if (mode & 1) { |
| 223 | theResults.Clear(); |
| 224 | theShapeResult.Nullify(); |
| 225 | } |
| 226 | if (mode & 2) { |
| 227 | theModel.Nullify(); |
| 228 | theGraph.Nullify(); |
| 229 | theTransfer.Nullify(); |
| 230 | theActor.Nullify(); |
| 231 | theFilename.Clear(); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | |
| 236 | //======================================================================= |
| 237 | //function : TransientProcess |
| 238 | //purpose : |
| 239 | //======================================================================= |
| 240 | |
| 241 | Handle(Transfer_TransientProcess) XSControl_TransferReader::TransientProcess () const |
| 242 | { |
| 243 | return theTransfer; |
| 244 | } |
| 245 | |
| 246 | |
| 247 | //======================================================================= |
| 248 | //function : SetTransientProcess |
| 249 | //purpose : |
| 250 | //======================================================================= |
| 251 | |
| 252 | void XSControl_TransferReader::SetTransientProcess |
| 253 | (const Handle(Transfer_TransientProcess)& TP) |
| 254 | { |
| 255 | theTransfer = TP; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | // ######################################################## |
| 260 | // ########### RESULTATS ############ |
| 261 | |
| 262 | |
| 263 | //======================================================================= |
| 264 | //function : RecordResult |
| 265 | //purpose : |
| 266 | //======================================================================= |
| 267 | |
| 268 | Standard_Boolean XSControl_TransferReader::RecordResult |
| 269 | (const Handle(Standard_Transient)& ent) |
| 270 | { |
| 271 | if (theModel.IsNull() || theTransfer.IsNull()) return Standard_False; |
| 272 | Standard_Integer num = theModel->Number(ent); |
| 273 | if (num == 0) return Standard_False; |
| 274 | Handle(TCollection_HAsciiString) lab = theModel->StringLabel(ent); |
| 275 | |
| 276 | Handle(Transfer_ResultFromModel) res = new Transfer_ResultFromModel; |
| 277 | res->Fill (theTransfer,ent); |
| 278 | |
| 279 | // Cas du resultat Shape : pour resultat principal, faire HShape ... |
| 280 | Handle(Transfer_Binder) binder = res->MainResult()->Binder(); |
| 281 | DeclareAndCast(TransferBRep_ShapeBinder,shb,binder); |
| 282 | if (!shb.IsNull()) { |
| 283 | Handle(Transfer_SimpleBinderOfTransient) trb = new Transfer_SimpleBinderOfTransient; |
| 284 | trb->SetResult ( new TopoDS_HShape(shb->Result()) ); |
| 285 | trb->Merge(binder); |
| 286 | res->MainResult()->SetBinder (trb); |
| 287 | } |
| 288 | |
| 289 | res->SetFileName(theFilename.ToCString()); |
| 290 | theResults.Bind(num,res); |
| 291 | return Standard_True; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | //======================================================================= |
| 296 | //function : IsRecorded |
| 297 | //purpose : |
| 298 | //======================================================================= |
| 299 | |
| 300 | Standard_Boolean XSControl_TransferReader::IsRecorded |
| 301 | (const Handle(Standard_Transient)& ent) const |
| 302 | { |
| 303 | if (theModel.IsNull()) return Standard_False; |
| 304 | Standard_Integer num = theModel->Number(ent); |
| 305 | if (num == 0) return Standard_False; |
| 306 | if(!theResults.IsBound(num)) return Standard_False; |
| 307 | return (theResults.Find(num)->DynamicType() == STANDARD_TYPE(Transfer_ResultFromModel) ); |
| 308 | } |
| 309 | |
| 310 | |
| 311 | //======================================================================= |
| 312 | //function : HasResult |
| 313 | //purpose : |
| 314 | //======================================================================= |
| 315 | |
| 316 | Standard_Boolean XSControl_TransferReader::HasResult |
| 317 | (const Handle(Standard_Transient)& ent) const |
| 318 | { |
| 319 | if (theModel.IsNull()) return Standard_False; |
| 320 | Standard_Integer num = theModel->Number(ent); |
| 321 | if (num == 0) return Standard_False; |
| 322 | if(!theResults.IsBound(num)) return Standard_False; |
| 323 | DeclareAndCast(Transfer_ResultFromModel,fr,theResults.Find(num)); |
| 324 | if (fr.IsNull()) return Standard_False; |
| 325 | return fr->HasResult(); |
| 326 | } |
| 327 | |
| 328 | |
| 329 | //======================================================================= |
| 330 | //function : RecordedList |
| 331 | //purpose : |
| 332 | //======================================================================= |
| 333 | |
| 334 | Handle(TColStd_HSequenceOfTransient) XSControl_TransferReader::RecordedList () const |
| 335 | { |
| 336 | Handle(TColStd_HSequenceOfTransient) li = new TColStd_HSequenceOfTransient(); |
| 337 | if (theModel.IsNull()) return li; |
| 338 | Standard_Integer i, nb = theModel->NbEntities(); |
| 339 | for (i = 1; i <= nb; i ++) { |
| 340 | if(theResults.IsBound(i)) |
| 341 | if(!theResults.Find(i).IsNull()) li->Append (theModel->Value(i)); |
| 342 | } |
| 343 | return li; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | //======================================================================= |
| 348 | //function : Skip |
| 349 | //purpose : |
| 350 | //======================================================================= |
| 351 | |
| 352 | Standard_Boolean XSControl_TransferReader::Skip(const Handle(Standard_Transient)& ent) |
| 353 | { |
| 354 | if (theModel.IsNull() || theTransfer.IsNull()) return Standard_False; |
| 355 | Standard_Integer num = theModel->Number(ent); |
| 356 | if (num == 0) return Standard_False; |
| 357 | theResults.Bind(num,ent); |
| 358 | return Standard_True; |
| 359 | } |
| 360 | |
| 361 | |
| 362 | //======================================================================= |
| 363 | //function : IsSkipped |
| 364 | //purpose : |
| 365 | //======================================================================= |
| 366 | |
| 367 | Standard_Boolean XSControl_TransferReader::IsSkipped |
| 368 | (const Handle(Standard_Transient)& ent) const |
| 369 | { |
| 370 | if (theModel.IsNull()) return Standard_False; |
| 371 | Standard_Integer num = theModel->Number(ent); |
| 372 | if (num == 0) return Standard_False; |
| 373 | if(!theResults.IsBound(num)) return Standard_False; |
| 374 | return (theResults.Find(num)->DynamicType() != STANDARD_TYPE(Transfer_ResultFromModel) ); |
| 375 | } |
| 376 | |
| 377 | |
| 378 | //======================================================================= |
| 379 | //function : IsMarked |
| 380 | //purpose : |
| 381 | //======================================================================= |
| 382 | |
| 383 | Standard_Boolean XSControl_TransferReader::IsMarked |
| 384 | (const Handle(Standard_Transient)& ent) const |
| 385 | { |
| 386 | if (theModel.IsNull()) return Standard_False; |
| 387 | Standard_Integer num = theModel->Number(ent); |
| 388 | if (num == 0) return Standard_False; |
| 389 | if(!theResults.IsBound(num)) return Standard_False; |
| 390 | if (theResults.Find(num).IsNull()) return Standard_False; |
| 391 | return Standard_True; |
| 392 | } |
| 393 | |
| 394 | |
| 395 | // ######### ACCES UN PEU PLUS FIN ######### |
| 396 | |
| 397 | |
| 398 | //======================================================================= |
| 399 | //function : FinalResult |
| 400 | //purpose : |
| 401 | //======================================================================= |
| 402 | |
| 403 | Handle(Transfer_ResultFromModel) XSControl_TransferReader::FinalResult |
| 404 | (const Handle(Standard_Transient)& ent) const |
| 405 | { |
| 406 | Handle(Transfer_ResultFromModel) res; |
| 407 | if (theModel.IsNull()) return res; |
| 408 | Standard_Integer num = theModel->Number(ent); |
| 409 | if (num == 0) return res; |
| 410 | if(!theResults.IsBound(num)) return res; |
| 411 | res = GetCasted(Transfer_ResultFromModel,theResults.Find(num)); |
| 412 | return res; |
| 413 | } |
| 414 | |
| 415 | |
| 416 | //======================================================================= |
| 417 | //function : FinalEntityLabel |
| 418 | //purpose : |
| 419 | //======================================================================= |
| 420 | |
| 421 | Standard_CString XSControl_TransferReader::FinalEntityLabel |
| 422 | (const Handle(Standard_Transient)& ent) const |
| 423 | { |
| 424 | Handle(Transfer_ResultFromModel) resu = FinalResult (ent); |
| 425 | if (resu.IsNull()) return ""; |
| 426 | return resu->MainLabel(); |
| 427 | } |
| 428 | |
| 429 | |
| 430 | //======================================================================= |
| 431 | //function : FinalEntityNumber |
| 432 | //purpose : |
| 433 | //======================================================================= |
| 434 | |
| 435 | Standard_Integer XSControl_TransferReader::FinalEntityNumber |
| 436 | (const Handle(Standard_Transient)& ent) const |
| 437 | { |
| 438 | Handle(Transfer_ResultFromModel) resu = FinalResult (ent); |
| 439 | if (resu.IsNull()) return 0; |
| 440 | return resu->MainNumber(); |
| 441 | } |
| 442 | |
| 443 | |
| 444 | //======================================================================= |
| 445 | //function : ResultFromNumber |
| 446 | //purpose : |
| 447 | //======================================================================= |
| 448 | |
| 449 | Handle(Transfer_ResultFromModel) XSControl_TransferReader::ResultFromNumber |
| 450 | (const Standard_Integer num) const |
| 451 | { |
| 452 | Handle(Transfer_ResultFromModel) res; |
| 453 | if ( num<1 || num>theModel->NbEntities() ) return res; |
| 454 | if(!theResults.IsBound(num)) return res; |
| 455 | res = GetCasted(Transfer_ResultFromModel,theResults.Find(num)); |
| 456 | return res; |
| 457 | } |
| 458 | |
| 459 | |
| 460 | //======================================================================= |
| 461 | //function : TransientResult |
| 462 | //purpose : |
| 463 | //======================================================================= |
| 464 | |
| 465 | Handle(Standard_Transient) XSControl_TransferReader::TransientResult |
| 466 | (const Handle(Standard_Transient)& ent) const |
| 467 | { |
| 468 | Handle(Standard_Transient) tres; |
| 469 | Handle(Transfer_ResultFromModel) res = FinalResult(ent); |
| 470 | if (res.IsNull()) return tres; |
| 471 | Handle(Transfer_ResultFromTransient) mres = res->MainResult(); |
| 472 | if (mres.IsNull()) return tres; |
| 473 | DeclareAndCast(Transfer_SimpleBinderOfTransient,bnd,mres->Binder()); |
| 474 | if (bnd.IsNull()) return tres; |
| 475 | if (!bnd->HasResult()) return tres; |
| 476 | return bnd->Result(); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | //======================================================================= |
| 481 | //function : ShapeResult |
| 482 | //purpose : |
| 483 | //======================================================================= |
| 484 | |
| 485 | TopoDS_Shape XSControl_TransferReader::ShapeResult |
| 486 | (const Handle(Standard_Transient)& ent) const |
| 487 | { |
| 488 | TopoDS_Shape tres; // DOIT RESTER NULL |
| 489 | Handle(Transfer_ResultFromModel) res = FinalResult(ent); |
| 490 | if (res.IsNull()) return tres; |
| 491 | Handle(Transfer_ResultFromTransient) mres = res->MainResult(); |
| 492 | if (mres.IsNull()) return tres; |
| 493 | XSControl_Utils xu; |
| 494 | TopoDS_Shape sh = xu.BinderShape (mres->Binder()); |
| 495 | |
| 496 | // Ouh la vilaine verrue |
| 497 | Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle"); |
| 498 | if (tolang <= 0 || sh.IsNull()) return sh; |
| 499 | ShapeFix::EncodeRegularity (sh,tolang); |
| 500 | return sh; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | //======================================================================= |
| 505 | //function : ClearResult |
| 506 | //purpose : |
| 507 | //======================================================================= |
| 508 | |
| 509 | Standard_Boolean XSControl_TransferReader::ClearResult |
| 510 | (const Handle(Standard_Transient)& ent, const Standard_Integer mode) |
| 511 | { |
| 512 | if (theModel.IsNull()) return Standard_False; |
| 513 | Standard_Integer num = theModel->Number(ent); |
| 514 | if (num == 0) return Standard_False; |
| 515 | if(!theResults.IsBound(num)) return Standard_False; |
| 516 | if (mode < 0) |
| 517 | theResults.ChangeFind(num).Nullify(); |
| 518 | else { |
| 519 | DeclareAndCast(Transfer_ResultFromModel,resu,theResults.Find(num)); |
| 520 | if (resu.IsNull()) return Standard_False; |
| 521 | resu->Strip (mode); |
| 522 | } |
| 523 | return Standard_True; |
| 524 | } |
| 525 | |
| 526 | |
| 527 | // <<<< >>>> ATTENTION, pas terrible : mieux vaudrait |
| 528 | // faire une map inverse et la consulter |
| 529 | // ou muscler ResultFromModel ... |
| 530 | |
| 531 | |
| 532 | //======================================================================= |
| 533 | //function : EntityFromResult |
| 534 | //purpose : |
| 535 | //======================================================================= |
| 536 | |
| 537 | Handle(Standard_Transient) XSControl_TransferReader::EntityFromResult |
| 538 | (const Handle(Standard_Transient)& res, const Standard_Integer mode) const |
| 539 | { |
| 540 | Handle(Standard_Transient) nulh; |
| 541 | // cas de la shape |
| 542 | XSControl_Utils xu; |
| 543 | TopoDS_Shape sh = xu.BinderShape (res); |
| 544 | if (!sh.IsNull()) return EntityFromShapeResult (sh,mode); |
| 545 | |
| 546 | Handle(Transfer_Binder) abinder; |
| 547 | DeclareAndCast(Transfer_Binder,binder,res); |
| 548 | Standard_Integer i,j,nb; |
| 549 | |
| 550 | if (mode == 0 || mode == 1) { |
| 551 | // on regarde dans le TransientProcess (Roots ou tous Mappeds) |
| 552 | if (!theTransfer.IsNull()) { |
| 553 | nb = (mode == 0 ? theTransfer->NbRoots() : theTransfer->NbMapped()); |
| 554 | for (j = 1; j <= nb; j ++) { |
| 555 | i = (mode == 0 ? theModel->Number (theTransfer->Root(j)) : j); |
| 556 | if (i == 0) continue; |
| 557 | abinder = theTransfer->MapItem(i); |
| 558 | if (abinder.IsNull()) continue; |
| 559 | if (!binder.IsNull()) { |
| 560 | if (binder == abinder) return theTransfer->Mapped(i); |
| 561 | continue; |
| 562 | } |
| 563 | DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,abinder); |
| 564 | if (trb.IsNull()) continue; |
| 565 | if (trb->Result() == res) return theTransfer->Mapped(i); |
| 566 | } |
| 567 | } |
| 568 | return nulh; // Null |
| 569 | } |
| 570 | |
| 571 | // Recherche dans theResults (racines) |
| 572 | // 2 : Main only 3 : Main + one sub; 4 : all |
| 573 | if (mode >= 2) { |
| 574 | nb = theModel->NbEntities(); |
| 575 | for (i = 1; i <= nb; i ++) { |
| 576 | Handle(Transfer_ResultFromModel) rec = ResultFromNumber (i); |
| 577 | if (rec.IsNull()) return nulh; |
| 578 | Handle(TColStd_HSequenceOfTransient) list = rec->Results (mode-2); |
| 579 | Standard_Integer ir,nr = list->Length(); |
| 580 | for (ir = 1; ir <= nr; ir ++) { |
| 581 | DeclareAndCast(Transfer_ResultFromTransient,rft,list->Value(ir)); |
| 582 | if (rft.IsNull()) continue; |
| 583 | if (rft->Binder() == binder) return rft->Start(); |
| 584 | } |
| 585 | |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | // autres cas non encore implementes |
| 590 | return nulh; |
| 591 | } |
| 592 | |
| 593 | |
| 594 | // <<<< >>>> ATTENTION, encore moins bien que le precedent |
| 595 | |
| 596 | |
| 597 | //======================================================================= |
| 598 | //function : EntityFromShapeResult |
| 599 | //purpose : |
| 600 | //======================================================================= |
| 601 | |
| 602 | Handle(Standard_Transient) XSControl_TransferReader::EntityFromShapeResult |
| 603 | (const TopoDS_Shape& res, const Standard_Integer mode) const |
| 604 | { |
| 605 | Handle(Standard_Transient) nulh, samesh, partner; |
| 606 | if (res.IsNull()) return nulh; |
| 607 | Standard_Integer i,j,nb; |
| 608 | |
| 609 | XSControl_Utils xu; |
| 610 | if (mode == 0 || mode == 1 || mode == -1) { |
| 611 | // on regarde dans le TransientProcess |
| 612 | if (!theTransfer.IsNull()) { |
| 613 | nb = (mode == 0 ? theTransfer->NbRoots() : theTransfer->NbMapped()); |
| 614 | for (j = 1; j <= nb; j ++) { |
| 615 | i = (mode == 0 ? theModel->Number (theTransfer->Root(j)) : j); |
| 616 | if (i == 0) continue; |
| 617 | Handle(Standard_Transient) ent = theTransfer->Mapped(i); |
| 618 | TopoDS_Shape sh = TransferBRep::ShapeResult (theTransfer,ent); |
| 619 | if (!sh.IsNull()) { |
| 620 | if (sh == res) return ent; |
| 621 | // priorites moindre : Same (tjrs) ou Partner (mode < 0) |
| 622 | if (sh.IsSame(res)) samesh = ent; |
| 623 | if (mode == -1 && sh.IsPartner(res)) partner= ent; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | // Ici, pas trouve de vraie egalite. Priorites moindres : Same puis Partner |
| 628 | if (!samesh.IsNull()) return samesh; |
| 629 | if (!partner.IsNull()) return partner; // calcule si mode = -1 |
| 630 | return nulh; |
| 631 | } |
| 632 | |
| 633 | // Recherche dans theResults (racines) |
| 634 | // 2 : Main only 3 : Main + one sub; 4 : all |
| 635 | if (mode >= 2) { |
| 636 | nb = theModel->NbEntities(); |
| 637 | for (i = 1; i <= nb; i ++) { |
| 638 | Handle(Transfer_ResultFromModel) rec = ResultFromNumber (i); |
| 639 | if (rec.IsNull()) continue; |
| 640 | |
| 641 | Handle(TColStd_HSequenceOfTransient) list = rec->Results (mode-2); |
| 642 | Standard_Integer ir,nr = list->Length(); |
| 643 | for (ir = 1; ir <= nr; ir ++) { |
| 644 | DeclareAndCast(Transfer_ResultFromTransient,rft,list->Value(ir)); |
| 645 | if (rft.IsNull()) continue; |
| 646 | TopoDS_Shape sh = xu.BinderShape (rft->Binder()); |
| 647 | if (!sh.IsNull() && sh == res) return rft->Start(); |
| 648 | } |
| 649 | |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | return nulh; |
| 654 | } |
| 655 | |
| 656 | |
| 657 | //======================================================================= |
| 658 | //function : EntitiesFromShapeList |
| 659 | //purpose : |
| 660 | //======================================================================= |
| 661 | |
| 662 | Handle(TColStd_HSequenceOfTransient) XSControl_TransferReader::EntitiesFromShapeList |
| 663 | (const Handle(TopTools_HSequenceOfShape)& res, |
| 664 | const Standard_Integer mode) const |
| 665 | { |
| 666 | Handle(TColStd_HSequenceOfTransient) lt = new TColStd_HSequenceOfTransient(); |
| 667 | if (res.IsNull()) return lt; |
| 668 | TopTools_MapOfShape shapes; |
| 669 | |
| 670 | // On convertit res en une map, pour test de presence rapide |
| 671 | Standard_Integer i, j, nb = res->Length(); |
| 672 | if (nb == 0) return lt; |
| 673 | for (i = 1; i <= nb; i ++) shapes.Add (res->Value(i)); |
| 674 | |
| 675 | // A present, recherche et enregistrement |
| 676 | |
| 677 | XSControl_Utils xu; |
| 678 | if (mode == 0 || mode == 1) { |
| 679 | // on regarde dans le TransientProcess |
| 680 | if (!theTransfer.IsNull()) { |
| 681 | nb = (mode == 0 ? theTransfer->NbRoots() : theTransfer->NbMapped()); |
| 682 | for (j = 1; j <= nb; j ++) { |
| 683 | i = (mode == 0 ? theModel->Number (theTransfer->Root(j)) : j); |
| 684 | if (i == 0) continue; |
| 685 | TopoDS_Shape sh = xu.BinderShape (theTransfer->MapItem(i)); |
| 686 | if (!sh.IsNull() && shapes.Contains(sh)) { |
| 687 | lt->Append (theTransfer->Mapped(i)); |
| 688 | j=nb; //skl (for looking for entities in checkbrep) |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | // Recherche dans theResults (racines) |
| 695 | // 2 : Main only 3 : Main + one sub; 4 : all |
| 696 | if (mode >= 2) { |
| 697 | nb = theModel->NbEntities(); |
| 698 | for (i = 1; i <= nb; i ++) { |
| 699 | Handle(Transfer_ResultFromModel) rec = ResultFromNumber (i); |
| 700 | if (rec.IsNull()) continue; |
| 701 | |
| 702 | Handle(TColStd_HSequenceOfTransient) list = rec->Results (mode-2); |
| 703 | Standard_Integer ir,nr = list->Length(); |
| 704 | for (ir = 1; ir <= nr; ir ++) { |
| 705 | DeclareAndCast(Transfer_ResultFromTransient,rft,list->Value(i)); |
| 706 | if (rft.IsNull()) continue; |
| 707 | TopoDS_Shape sh = xu.BinderShape (rft->Binder()); |
| 708 | if (!sh.IsNull() && shapes.Contains(sh)) lt->Append (rft->Start()); |
| 709 | } |
| 710 | |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | return lt; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | // <<<< >>>> ATTENTION, level pas traite (utile ?) -> ResultFromModel |
| 719 | |
| 720 | |
| 721 | //======================================================================= |
| 722 | //function : CheckList |
| 723 | //purpose : |
| 724 | //======================================================================= |
| 725 | |
| 726 | Interface_CheckIterator XSControl_TransferReader::CheckList |
| 727 | (const Handle(Standard_Transient)& ent, const Standard_Integer level) const |
| 728 | { |
| 729 | Interface_CheckIterator chl; |
| 730 | if (theModel.IsNull() || ent.IsNull()) return chl; |
| 731 | // Check-List COMPLETE ... tout le Modele |
| 732 | if (ent == theModel) { |
| 733 | Standard_Integer i,nb = theModel->NbEntities(); |
| 734 | for (i = 1; i <= nb; i ++) { |
| 735 | Handle(Transfer_ResultFromModel) rec = ResultFromNumber (i); |
| 736 | if (!rec.IsNull()) { |
| 737 | Interface_CheckIterator chiter = rec->CheckList (Standard_False,2); |
| 738 | chl.Merge (chiter); |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | // Check-List sur une LISTE ... |
| 743 | else if (ent->IsKind(STANDARD_TYPE(TColStd_HSequenceOfTransient))) { |
| 744 | DeclareAndCast(TColStd_HSequenceOfTransient,list,ent); |
| 745 | Standard_Integer i,nb = list->Length(); |
| 746 | for (i = 1; i <= nb; i ++) { |
| 747 | Handle(Transfer_ResultFromModel) rec = FinalResult (list->Value(i)); |
| 748 | if (!rec.IsNull()) { |
| 749 | Interface_CheckIterator chiter = rec->CheckList (Standard_False,level); |
| 750 | chl.Merge (chiter); |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | // sinon, Check-List sur une entite : Last ou FinalResult |
| 756 | else if (level < 0) { |
| 757 | if (theTransfer.IsNull()) return chl; |
| 758 | chl.Add (theTransfer->Check(ent),theModel->Number(ent)); |
| 759 | } else { |
| 760 | Handle(Transfer_ResultFromModel) rec = FinalResult (ent); |
| 761 | if (rec.IsNull()) return chl; |
| 762 | chl = rec->CheckList(Standard_False,level); // manque level ... |
| 763 | } |
| 764 | if (ent == theModel) chl.SetName ("XSControl : CheckList complete Model"); |
| 765 | else if (level < 0) chl.SetName ("XSControl : CheckList Last"); |
| 766 | else if (level == 0) chl.SetName ("XSControl : CheckList Final Main"); |
| 767 | else if (level == 1) chl.SetName ("XSControl : CheckList Final Main+Subs"); |
| 768 | else if (level >= 2) chl.SetName ("XSControl : CheckList Final Complete"); |
| 769 | return chl; |
| 770 | } |
| 771 | |
| 772 | |
| 773 | //======================================================================= |
| 774 | //function : HasChecks |
| 775 | //purpose : |
| 776 | //======================================================================= |
| 777 | |
| 778 | Standard_Boolean XSControl_TransferReader::HasChecks |
| 779 | (const Handle(Standard_Transient)& ent, const Standard_Boolean failsonly) const |
| 780 | { |
| 781 | Handle(Transfer_ResultFromModel) resu = FinalResult (ent); |
| 782 | if (resu.IsNull()) return Standard_False; |
| 783 | Standard_Integer stat = resu->ComputeCheckStatus (Standard_False); |
| 784 | if (stat == 0) return Standard_False; |
| 785 | if (stat > 1) return Standard_True; |
| 786 | return (!failsonly); |
| 787 | } |
| 788 | |
| 789 | |
| 790 | //======================================================================= |
| 791 | //function : CheckedList |
| 792 | //purpose : |
| 793 | //======================================================================= |
| 794 | |
| 795 | Handle(TColStd_HSequenceOfTransient) XSControl_TransferReader::CheckedList |
| 796 | (const Handle(Standard_Transient)& ent, |
| 797 | const Interface_CheckStatus withcheck, const Standard_Boolean level) const |
| 798 | { |
| 799 | Handle(TColStd_HSequenceOfTransient) res = new TColStd_HSequenceOfTransient(); |
| 800 | if (ent.IsNull()) return res; |
| 801 | |
| 802 | if (ent == theModel) { |
| 803 | Standard_Integer i,nb = theModel->NbEntities(); |
| 804 | for (i = 1; i <= nb; i ++) { |
| 805 | Handle(Transfer_ResultFromModel) rec = ResultFromNumber (i); |
| 806 | if (!rec.IsNull()) res->Append (rec->CheckedList(withcheck,level)); |
| 807 | } |
| 808 | } else if (ent->IsKind(STANDARD_TYPE(TColStd_HSequenceOfTransient))) { |
| 809 | DeclareAndCast(TColStd_HSequenceOfTransient,list,ent); |
| 810 | Standard_Integer i,nb = list->Length(); |
| 811 | for (i = 1; i <= nb; i ++) { |
| 812 | Handle(Transfer_ResultFromModel) rec = FinalResult (list->Value(i)); |
| 813 | if (!rec.IsNull()) res->Append (rec->CheckedList(withcheck,level)); |
| 814 | } |
| 815 | } else { |
| 816 | Handle(Transfer_ResultFromModel) rec = FinalResult (ent); |
| 817 | if (!rec.IsNull()) res = rec->CheckedList(withcheck,level); |
| 818 | } |
| 819 | return res; |
| 820 | } |
| 821 | |
| 822 | |
| 823 | // ######################################################## |
| 824 | // ########### TRANSFERT ############ |
| 825 | // ######################################################## |
| 826 | |
| 827 | |
| 828 | //======================================================================= |
| 829 | //function : BeginTransfer |
| 830 | //purpose : |
| 831 | //======================================================================= |
| 832 | |
| 833 | Standard_Boolean XSControl_TransferReader::BeginTransfer () |
| 834 | { |
| 835 | if (theModel.IsNull()) return Standard_False; |
| 836 | if (Actor().IsNull()) return Standard_False; |
| 837 | theShapeResult.Nullify(); |
| 838 | |
| 839 | if (theTransfer.IsNull()) theTransfer = new Transfer_TransientProcess |
| 840 | (theModel->NbEntities()); |
| 841 | |
| 842 | Handle(Transfer_ActorOfTransientProcess) actor; |
| 843 | theTransfer->SetActor (actor); // -> RAZ |
| 844 | actor = Actor(); |
| 845 | theTransfer->SetActor (actor); // Set proprement dit |
| 846 | theTransfer->SetErrorHandle (Standard_True); |
| 847 | theTransfer->Context() = theContext; |
| 848 | return Standard_True; |
| 849 | } |
| 850 | |
| 851 | |
| 852 | //======================================================================= |
| 853 | //function : Recognize |
| 854 | //purpose : |
| 855 | //======================================================================= |
| 856 | |
| 857 | Standard_Boolean XSControl_TransferReader::Recognize |
| 858 | (const Handle(Standard_Transient)& ent) |
| 859 | { |
| 860 | if (theActor.IsNull()) return Standard_False; |
| 861 | return theActor->Recognize (ent); |
| 862 | } |
| 863 | |
| 864 | |
| 865 | //======================================================================= |
| 866 | //function : TransferOne |
| 867 | //purpose : |
| 868 | //======================================================================= |
| 869 | |
| 870 | Standard_Integer XSControl_TransferReader::TransferOne |
| 871 | (const Handle(Standard_Transient)& ent, const Standard_Boolean rec) |
| 872 | { |
| 873 | if (theActor.IsNull() || theModel.IsNull()) return 0; |
| 874 | |
| 875 | if (theTransfer.IsNull()) { if (!BeginTransfer()) return 0; } |
| 876 | |
| 877 | Handle(Message_Messenger) sout = theTransfer->Messenger(); |
| 878 | Standard_Integer level = theTransfer->TraceLevel(); |
| 879 | |
| 880 | |
| 881 | Transfer_TransferOutput TP (theTransfer,theModel); |
| 882 | if (theGraph.IsNull()) theTransfer->SetModel(theModel); |
| 883 | else theTransfer->SetGraph(theGraph); |
| 884 | |
| 885 | // pour le log-file |
| 886 | if (level > 1) { |
| 887 | Standard_Integer num = theModel->Number(ent); |
| 888 | Handle(TCollection_HAsciiString) lab = theModel->StringLabel(ent); |
| 889 | sout<<"\n*******************************************************************\n"; |
| 890 | sout << "****** Transferring one Entity ******"<<endl; |
| 891 | if (!lab.IsNull()) |
| 892 | sout<<"****** N0 in file : "<<Interface_MSG::Blanks(num,5)<<num |
| 893 | <<" Ident : "<<lab->ToCString() |
| 894 | << Interface_MSG::Blanks(14 - lab->Length())<<"******\n"; |
| 895 | sout << "****** Type : "<<theModel->TypeName(ent,Standard_False) |
| 896 | << Interface_MSG::Blanks((Standard_Integer) (44 - strlen(theModel->TypeName(ent,Standard_False)))) |
| 897 | << "******"; |
| 898 | sout<<"\n*******************************************************************\n"; |
| 899 | } |
| 900 | |
| 901 | // seule difference entre TransferRoots et TransferOne |
| 902 | Standard_Integer res = 0; |
| 903 | Handle(Standard_Transient) obj = ent; |
| 904 | TP.Transfer (obj); |
| 905 | theTransfer->SetRoot (obj); |
| 906 | |
| 907 | // Resultat ... |
| 908 | Handle(Transfer_Binder) binder = theTransfer->Find (obj); |
| 909 | if (binder.IsNull()) return res; |
| 910 | if (rec) RecordResult (obj); |
| 911 | |
| 912 | if (!binder->HasResult()) return res; |
| 913 | res ++; |
| 914 | |
| 915 | return res; |
| 916 | } |
| 917 | |
| 918 | |
| 919 | //======================================================================= |
| 920 | //function : TransferList |
| 921 | //purpose : |
| 922 | //======================================================================= |
| 923 | |
| 924 | Standard_Integer XSControl_TransferReader::TransferList |
| 925 | (const Handle(TColStd_HSequenceOfTransient)& list, const Standard_Boolean rec) |
| 926 | { |
| 927 | if (theActor.IsNull() || theModel.IsNull()) return 0; |
| 928 | |
| 929 | if (theTransfer.IsNull()) { if (!BeginTransfer()) return 0; } |
| 930 | |
| 931 | Handle(Message_Messenger) sout = theTransfer->Messenger(); |
| 932 | Standard_Integer level = theTransfer->TraceLevel(); |
| 933 | |
| 934 | Transfer_TransferOutput TP (theTransfer,theModel); |
| 935 | if (theGraph.IsNull()) theTransfer->SetModel(theModel); |
| 936 | else theTransfer->SetGraph(theGraph); |
| 937 | |
| 938 | Standard_Integer i,nb = list->Length(); |
| 939 | |
| 940 | // Pour le log-file |
| 941 | if (level > 0) { |
| 942 | sout<<"\n*******************************************************************\n"; |
| 943 | sout << "****** Transferring a list of "<<Interface_MSG::Blanks(nb,5)<<" Entities ******"<<endl; |
| 944 | sout<<"\n*******************************************************************\n"; |
| 945 | |
| 946 | Handle(IFSelect_SignatureList) sl = new IFSelect_SignatureList; |
| 947 | for (i = 1; i <= nb; i ++) |
| 948 | sl->Add (list->Value(i), theModel->TypeName(list->Value(i),Standard_False)); |
| 949 | sl->SetName ("Entities to Transfer"); |
| 950 | sl->PrintCount (sout); |
| 951 | sout<<"\n*******************************************************************\n"; |
| 952 | } |
| 953 | |
| 954 | // seule difference entre TransferRoots et TransferOne |
| 955 | Standard_Integer res = 0; |
| 956 | nb = list->Length(); |
| 957 | Handle(Standard_Transient) obj; |
| 958 | |
| 959 | for (i = 1; i <= nb; i ++) { |
| 960 | obj = list->Value(i); |
| 961 | TP.Transfer (obj); |
| 962 | theTransfer->SetRoot (obj); |
| 963 | |
| 964 | // Resultat ... |
| 965 | Handle(Transfer_Binder) binder = theTransfer->Find (obj); |
| 966 | if (binder.IsNull()) continue; |
| 967 | if (rec) RecordResult (obj); |
| 968 | |
| 969 | if (!binder->HasResult()) continue; |
| 970 | res ++; |
| 971 | } |
| 972 | return res; |
| 973 | } |
| 974 | |
| 975 | |
| 976 | // <<<< >>>> passage Graph : judicieux ? |
| 977 | |
| 978 | |
| 979 | //======================================================================= |
| 980 | //function : TransferRoots |
| 981 | //purpose : |
| 982 | //======================================================================= |
| 983 | |
| 984 | Standard_Integer XSControl_TransferReader::TransferRoots(const Interface_Graph& G) |
| 985 | { |
| 986 | if (theModel != G.Model()) return -1; |
| 987 | if (!BeginTransfer()) return -1; |
| 988 | Handle(Message_Messenger) sout = theTransfer->Messenger(); |
| 989 | Standard_Integer level = theTransfer->TraceLevel(); |
| 990 | |
| 991 | Transfer_TransferOutput TP (theTransfer,theModel); |
| 992 | if (theGraph.IsNull()) theTransfer->SetModel(theModel); |
| 993 | else theTransfer->SetGraph(theGraph); |
| 994 | |
| 995 | // Pour le log-file |
| 996 | if (level > 0) { |
| 997 | Interface_EntityIterator roots = G.RootEntities(); |
| 998 | Standard_Integer nb = roots.NbEntities(); |
| 999 | sout<<"\n*******************************************************************\n"; |
| 1000 | sout << "****** Transferring the "<<Interface_MSG::Blanks(nb,5)<<" Root Entities ******"<<endl; |
| 1001 | sout<<"\n*******************************************************************\n"; |
| 1002 | Handle(IFSelect_SignatureList) sl = new IFSelect_SignatureList; |
| 1003 | for (roots.Start(); roots.More(); roots.Next()) |
| 1004 | sl->Add (roots.Value(),theModel->TypeName(roots.Value(),Standard_False)); |
| 1005 | sl->SetName ("Entities to Transfer"); |
| 1006 | sl->PrintCount (sout); |
| 1007 | sout<<"\n*******************************************************************\n"; |
| 1008 | } |
| 1009 | |
| 1010 | TP.TransferRoots (G); |
| 1011 | |
| 1012 | // Les entites transferees sont notees "asmain" |
| 1013 | Standard_Integer i,n = theTransfer->NbMapped(); |
| 1014 | for (i = 1; i <= n; i ++) { |
| 1015 | Handle(Standard_Transient) ent = theTransfer->Mapped(i); |
| 1016 | Handle(Transfer_Binder) bnd = theTransfer->MapItem(i); |
| 1017 | if (bnd.IsNull()) continue; |
| 1018 | if (!bnd->HasResult()) continue; |
| 1019 | RecordResult (ent); |
| 1020 | } |
| 1021 | |
| 1022 | // Resultat ... on note soigneuseument les Shapes |
| 1023 | theShapeResult = TransferBRep::Shapes (theTransfer,Standard_True); |
| 1024 | // ???? Et ici, il faut alimenter Imagine ... |
| 1025 | return theShapeResult->Length(); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | //======================================================================= |
| 1030 | //function : TransferClear |
| 1031 | //purpose : |
| 1032 | //======================================================================= |
| 1033 | |
| 1034 | void XSControl_TransferReader::TransferClear(const Handle(Standard_Transient)& ent, |
| 1035 | const Standard_Integer level) |
| 1036 | { |
| 1037 | if (theTransfer.IsNull()) return; |
| 1038 | if (ent == theModel) { theTransfer->Clear(); return; } |
| 1039 | |
| 1040 | theTransfer->RemoveResult (ent,level); |
| 1041 | ClearResult (ent,-1); |
| 1042 | |
| 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | //======================================================================= |
| 1047 | //function : PrintStats |
| 1048 | //purpose : |
| 1049 | //======================================================================= |
| 1050 | |
| 1051 | void XSControl_TransferReader::PrintStats |
| 1052 | (const Standard_Integer what, const Standard_Integer mode) const |
| 1053 | { |
| 1054 | Handle(Message_Messenger) sout = theTransfer->Messenger(); |
| 1055 | // A ameliorer ... ! |
| 1056 | sout<<"\n*******************************************************************\n"; |
| 1057 | sout << "****** Statistics on Transfer (Read) ******"<<endl; |
| 1058 | sout<<"\n*******************************************************************\n"; |
| 1059 | if (what > 10) { sout<<" *** Not yet implemented"<<endl; return; } |
| 1060 | if (what < 10) { |
| 1061 | sout << "****** Data recorded on Last Transfer ******"<<endl; |
| 1062 | PrintStatsProcess (theTransfer,what,mode); |
| 1063 | } |
| 1064 | // reste what = 10 : on liste les racines des final results |
| 1065 | sout << "****** Final Results ******"<<endl; |
| 1066 | if (theModel.IsNull()) { sout<<"**** Model unknown"<<endl; return; } |
| 1067 | Handle(TColStd_HSequenceOfTransient) list = RecordedList(); |
| 1068 | Standard_Integer i, nb = list->Length(); |
| 1069 | Handle(IFSelect_SignatureList) counter; |
| 1070 | if (mode > 2) counter = new IFSelect_SignatureList (mode == 6); |
| 1071 | IFSelect_PrintCount pcm = IFSelect_CountByItem; |
| 1072 | if (mode == 6) pcm = IFSelect_ListByItem; |
| 1073 | |
| 1074 | sout<<"**** Nb Recorded : "<<nb<<" : entities n0s : "; |
| 1075 | for (i = 1; i <= nb; i ++) { |
| 1076 | Handle(Standard_Transient) ent = list->Value(i); |
| 1077 | if (mode == 0) { sout<<" "<<theModel->Number(ent); continue; } |
| 1078 | if (mode == 1 || mode == 2) { |
| 1079 | sout<<"[ "<<Interface_MSG::Blanks (i,6)<<" ]:"; |
| 1080 | theModel->Print (ent,sout); |
| 1081 | sout<<" Type:"<<theModel->TypeName(ent,Standard_False); |
| 1082 | } |
| 1083 | if (mode >= 3 && mode <= 6) { |
| 1084 | counter->Add (ent,theModel->TypeName(ent,Standard_False)); |
| 1085 | } |
| 1086 | } |
| 1087 | if (!counter.IsNull()) counter->PrintList(sout,theModel,pcm); |
| 1088 | |
| 1089 | sout<<endl; |
| 1090 | } |
| 1091 | |
| 1092 | |
| 1093 | // ######################################################## |
| 1094 | // ########### TRANSFERT ############ |
| 1095 | |
| 1096 | |
| 1097 | //======================================================================= |
| 1098 | //function : LastCheckList |
| 1099 | //purpose : |
| 1100 | //======================================================================= |
| 1101 | |
| 1102 | Interface_CheckIterator XSControl_TransferReader::LastCheckList () const |
| 1103 | { |
| 1104 | Interface_CheckIterator chl; |
| 1105 | if (!theTransfer.IsNull()) chl = theTransfer->CheckList (Standard_False); |
| 1106 | return chl; |
| 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | //======================================================================= |
| 1111 | //function : LastTransferList |
| 1112 | //purpose : |
| 1113 | //======================================================================= |
| 1114 | |
| 1115 | Handle(TColStd_HSequenceOfTransient) XSControl_TransferReader::LastTransferList |
| 1116 | (const Standard_Boolean roots) const |
| 1117 | { |
| 1118 | Handle(TColStd_HSequenceOfTransient) li = new TColStd_HSequenceOfTransient(); |
| 1119 | if (theTransfer.IsNull()) return li; |
| 1120 | Standard_Integer i,j,nb = |
| 1121 | (roots ? theTransfer->NbRoots() : theTransfer->NbMapped()); |
| 1122 | for (j = 1; j <= nb; j ++) { |
| 1123 | i = (roots ? theModel->Number (theTransfer->Root(j)) : j); |
| 1124 | Handle(Transfer_Binder) bnd = theTransfer->MapItem(i); |
| 1125 | if (bnd.IsNull()) continue; |
| 1126 | if (!bnd->HasResult()) continue; |
| 1127 | li->Append (theTransfer->Mapped(i)); |
| 1128 | } |
| 1129 | return li; |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | //======================================================================= |
| 1134 | //function : ShapeResultList |
| 1135 | //purpose : |
| 1136 | //======================================================================= |
| 1137 | |
| 1138 | Handle(TopTools_HSequenceOfShape) XSControl_TransferReader::ShapeResultList |
| 1139 | (const Standard_Boolean rec) |
| 1140 | { |
| 1141 | if (!rec) { |
| 1142 | if (theShapeResult.IsNull()) theShapeResult = |
| 1143 | TransferBRep::Shapes (theTransfer,Standard_True); |
| 1144 | if (theShapeResult.IsNull()) theShapeResult = new TopTools_HSequenceOfShape(); |
| 1145 | } else { |
| 1146 | if (theShapeResult.IsNull()) theShapeResult = new TopTools_HSequenceOfShape(); |
| 1147 | if (theModel.IsNull()) return theShapeResult; |
| 1148 | Handle(TColStd_HSequenceOfTransient) li = RecordedList(); |
| 1149 | theShapeResult = new TopTools_HSequenceOfShape(); |
| 1150 | Standard_Integer i, nb = theModel->NbEntities(); |
| 1151 | TopoDS_Shape sh; |
| 1152 | for (i = 1; i <= nb; i ++) { |
| 1153 | sh = ShapeResult (theModel->Value(i)); |
| 1154 | if (!sh.IsNull()) theShapeResult->Append(sh); |
| 1155 | } |
| 1156 | } |
| 1157 | return theShapeResult; |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | // **** UTILITAIRE DE STATISTIQUES GENERALES |
| 1162 | |
| 1163 | // BinderStatus retourne une valeur : |
| 1164 | // 0 Binder Null. 1 void 2 Warning seul 3 Fail seul |
| 1165 | // 11 Resultat OK. 12 Resultat+Warning. 13 Resultat+Fail |
| 1166 | |
| 1167 | //======================================================================= |
| 1168 | //function : |
| 1169 | //purpose : |
| 1170 | //======================================================================= |
| 1171 | static Standard_Integer BinderStatus (const Handle(Transfer_Binder)& binder, char* mess) |
| 1172 | { |
| 1173 | Standard_Integer stat = 0; |
| 1174 | mess[0] = '\0'; |
| 1175 | if (binder.IsNull()) { sprintf (mess,"(no data recorded)"); return 0; } |
| 1176 | Interface_CheckStatus cst = binder->Check()->Status(); |
| 1177 | if (cst == Interface_CheckOK) { |
| 1178 | stat = 11; |
| 1179 | if (binder->HasResult()) sprintf(mess,"%s",binder->ResultTypeName()); |
| 1180 | else { sprintf(mess,"(no result)"); stat = 1; } |
| 1181 | } else if (cst == Interface_CheckWarning) { |
| 1182 | stat = 12; |
| 1183 | if (binder->HasResult()) sprintf(mess,"%s (+ warning)",binder->ResultTypeName()); |
| 1184 | else { sprintf(mess,"(warning)"); stat = 2; } |
| 1185 | } else if (cst == Interface_CheckFail) { |
| 1186 | stat = 13; |
| 1187 | if (binder->HasResult()) sprintf(mess,"%s (+ FAIL)",binder->ResultTypeName()); |
| 1188 | else { sprintf(mess,"(FAIL)"); stat = 3; } |
| 1189 | } |
| 1190 | return stat; |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | //======================================================================= |
| 1195 | //function : |
| 1196 | //purpose : |
| 1197 | //======================================================================= |
| 1198 | static void PrintPercent(const Handle(Message_Messenger)& sout, const Standard_CString mess, |
| 1199 | const Standard_Integer nb, const Standard_Integer nl) |
| 1200 | { |
| 1201 | if (nb <= 0 || nl == 0) return; |
| 1202 | sout<<"****** "<<mess<<": "; |
| 1203 | if (nb == nl) sout<<"100 %"<<endl; |
| 1204 | else if (nb*100/nl == 0) sout<<"< 1 %"<<endl; |
| 1205 | else sout<<(nb*100/nl < 10 ? " " : " ")<<nb*100/nl<<" %"<<endl; |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | //======================================================================= |
| 1210 | //function : PrintStatsProcess |
| 1211 | //purpose : |
| 1212 | //======================================================================= |
| 1213 | |
| 1214 | void XSControl_TransferReader::PrintStatsProcess(const Handle(Transfer_TransientProcess)& TP, |
| 1215 | const Standard_Integer what, |
| 1216 | const Standard_Integer mode) |
| 1217 | { |
| 1218 | Handle(TColStd_HSequenceOfTransient) list; // null |
| 1219 | XSControl_TransferReader::PrintStatsOnList (TP,list,what,mode); |
| 1220 | } |
| 1221 | |
| 1222 | |
| 1223 | //======================================================================= |
| 1224 | //function : PrintStatsOnList |
| 1225 | //purpose : |
| 1226 | //======================================================================= |
| 1227 | |
| 1228 | void XSControl_TransferReader::PrintStatsOnList(const Handle(Transfer_TransientProcess)& TP, |
| 1229 | const Handle(TColStd_HSequenceOfTransient)& list, |
| 1230 | const Standard_Integer what, |
| 1231 | const Standard_Integer mode) |
| 1232 | { |
| 1233 | Handle(Message_Messenger) sout = TP->Messenger(); |
| 1234 | char mess[250]; |
| 1235 | if (TP.IsNull()) return; |
| 1236 | if (what == 0) { TP->PrintStats(0,sout); return; } |
| 1237 | |
| 1238 | sout<<"\n*******************************************************************\n"; |
| 1239 | sout << "****** Statistics on Transfer Process (Read) ******"<<endl; |
| 1240 | if (what == 1) sout << "****** Individual Transfers (Roots) ******\n"; |
| 1241 | if (what == 2) sout << "****** All recorded data about Transfer ******\n"; |
| 1242 | if (what == 3) sout << "****** Abnormal records ******\n"; |
| 1243 | if (what == 1 || what == 2 || what == 3) { |
| 1244 | if (mode == 0) sout<<"****** (n0s of recorded entities) ******\n"; |
| 1245 | if (mode == 1) sout<<"****** (per entity : type + result) ******\n"; |
| 1246 | if (mode == 2) sout<<"****** (per entity : type + result/status) ******\n"; |
| 1247 | if (mode == 3) sout<<"****** (count per type of entity) ******\n"; |
| 1248 | if (mode == 4) sout<<"****** (count per type of result) ******\n"; |
| 1249 | if (mode == 5) sout<<"****** (count per couple entity-type / result-type/status) ******\n"; |
| 1250 | if (mode == 6) sout<<"****** (list per couple entity-type / result-type/status) ******\n"; |
| 1251 | } |
| 1252 | if (what == 4) sout << "****** Check messages ******\n"; |
| 1253 | if (what == 5) sout << "****** Fail messages ******\n"; |
| 1254 | sout<<"*******************************************************************\n"; |
| 1255 | |
| 1256 | // Cas what = 1,2,3 : contenu du TP (binders) |
| 1257 | |
| 1258 | Standard_Boolean nolist = list.IsNull(); |
| 1259 | Handle(Interface_InterfaceModel) model = TP->Model(); |
| 1260 | if (what >= 1 && what <= 3) { |
| 1261 | |
| 1262 | Standard_Integer stat; |
| 1263 | Standard_Integer nbv = 0, nbw = 0, nbf = 0, nbr = 0, nbrw = 0, nbrf = 0, nbnr = 0, nbi = 0; |
| 1264 | Transfer_IteratorOfProcessForTransient itrp(Standard_True); |
| 1265 | if (what == 1) itrp = TP->RootResult(Standard_True); |
| 1266 | if (what == 2) itrp = TP->CompleteResult(Standard_True); |
| 1267 | if (what == 3) itrp = TP->AbnormalResult(); |
| 1268 | Standard_Integer i = 0, nb = itrp.Number(); |
| 1269 | if (!nolist) itrp.Filter (list); |
| 1270 | Standard_Integer nl = itrp.Number(); // apres filtrage |
| 1271 | Handle(IFSelect_SignatureList) counter; |
| 1272 | if (mode > 2) counter = new IFSelect_SignatureList (mode == 6); |
| 1273 | Standard_Boolean notrec = (!nolist && mode > 2); // noter les "no record" |
| 1274 | IFSelect_PrintCount pcm = IFSelect_CountByItem; |
| 1275 | if (mode == 6) pcm = IFSelect_ListByItem; |
| 1276 | |
| 1277 | sout <<"**** Entities in Model : "<<model->NbEntities()<<endl; |
| 1278 | sout <<"**** Nb Items (Transfer) : "<<nb<<endl; |
| 1279 | if (!nolist) |
| 1280 | sout<<"**** Nb Items (Listed) : "<<nl<<endl; |
| 1281 | |
| 1282 | for (itrp.Start(); itrp.More(); itrp.Next()) { |
| 1283 | nbi ++; |
| 1284 | Handle(Transfer_Binder) binder = itrp.Value(); |
| 1285 | Handle(Standard_Transient) ent = itrp.Starting(); |
| 1286 | if (binder.IsNull()) { |
| 1287 | nbnr ++; |
| 1288 | if (notrec) counter->Add(ent,"(not recorded)"); |
| 1289 | else if (mode == 1 || mode == 2) { |
| 1290 | sout<<"["<<Interface_MSG::Blanks (nbi,4)<<nbi<<" ]:"; |
| 1291 | model->Print (ent,sout); |
| 1292 | sout<<" "<<model->TypeName(ent,Standard_False)<<" (not recorded)"<<endl; |
| 1293 | continue; |
| 1294 | } |
| 1295 | } |
| 1296 | if (mode == 0) { sout<<" "<<model->Number(ent); continue; } |
| 1297 | if (mode != 3) { |
| 1298 | stat = BinderStatus(binder,mess); |
| 1299 | // 0 Binder Null. 1 void 2 Warning seul 3 Fail seul |
| 1300 | // 11 Resultat OK. 12 Resultat+Warning. 13 Resultat+Fail |
| 1301 | if (stat == 0 || stat == 1) nbv ++; |
| 1302 | if (stat == 2) nbw ++; |
| 1303 | if (stat == 3) nbf ++; |
| 1304 | if (stat == 11) nbr ++; |
| 1305 | if (stat == 12) nbrw ++; |
| 1306 | if (stat == 13) nbrf ++; |
| 1307 | } |
| 1308 | |
| 1309 | // mode : 0 list num; 1 : num+label + type + result (abrege); 2 : complet |
| 1310 | if (mode == 1 || mode == 2) { |
| 1311 | sout<<"["<<Interface_MSG::Blanks (i,4)<<i<<" ]:"; |
| 1312 | model->Print (ent,sout); |
| 1313 | sout<<" "<<model->TypeName(ent,Standard_False); |
| 1314 | sout<<" Result:"<<mess<<endl; |
| 1315 | if (mode == 1) continue; |
| 1316 | |
| 1317 | const Handle(Interface_Check)& ch = binder->Check(); |
| 1318 | Standard_Integer newi,newnbw = ch->NbWarnings(), newnbf = ch->NbFails(); |
| 1319 | |
| 1320 | if (newnbw > 0) { |
| 1321 | sout<<" - Warnings : "<<newnbw<<":\n"; |
| 1322 | for (newi = 1; newi <= newnbw; newi ++) sout<<ch->CWarning(newi)<<endl; |
| 1323 | } |
| 1324 | if (newnbf > 0) { |
| 1325 | sout<<" - Fails : "<<newnbf<<":\n"; |
| 1326 | for (newi = 1; newi <= newnbf; newi ++) sout<<ch->CFail(newi)<<endl; |
| 1327 | } |
| 1328 | continue; |
| 1329 | } |
| 1330 | |
| 1331 | // mode : 3, counts per type of starting entity (class type) |
| 1332 | // 4 : counts per result type and/or status |
| 1333 | // 5 : counts per couple (starting type / result type/status) |
| 1334 | // 6 : idem plus gives for each item, the list of numbers of |
| 1335 | // entities in the starting model |
| 1336 | if (mode >= 3 && mode <= 6) { |
| 1337 | //IFSelect_PrintCount newpcm = IFSelect_CountByItem; |
| 1338 | //if (mode == 6) newpcm = IFSelect_ListByItem; |
| 1339 | if (mode == 3) counter->Add (ent,model->TypeName(ent,Standard_False)); |
| 1340 | if (mode == 4) counter->Add (ent,mess); |
| 1341 | if (mode >= 5) { |
| 1342 | TCollection_AsciiString mest (model->TypeName(ent,Standard_False)); |
| 1343 | mest.AssignCat(" -> "); |
| 1344 | mest.AssignCat(mess); |
| 1345 | //sprintf(mest,"%s -> %s",model->TypeName(ent,Standard_False),mess); |
| 1346 | counter->Add (ent,mest.ToCString()); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | // Fin de l iteration |
| 1351 | } |
| 1352 | if (!counter.IsNull()) counter->PrintList(sout,model,pcm); |
| 1353 | else sout<<endl; |
| 1354 | // Pourcentages |
| 1355 | if (mode != 3 && nbi > 0) { |
| 1356 | sout << "****** Percentages according Transfer Status ******"<<endl; |
| 1357 | PrintPercent (sout,"Result ",nbr+nbrw,nl); |
| 1358 | PrintPercent (sout,"Result + FAIL ",nbrf,nl); |
| 1359 | PrintPercent (sout,"FAIL, no Result ",nbf,nl); |
| 1360 | PrintPercent (sout,"Just Warning ",nbw,nl); |
| 1361 | PrintPercent (sout,"Nothing Recorded",nbnr,nl); |
| 1362 | /* if (nbr+nbrw > 0) |
| 1363 | sout<<"****** Result : "<< (nbr+nbrw)*100/nl<<" %"<<endl; |
| 1364 | if (nbrf > 0) |
| 1365 | sout<<"****** Result + FAIL : "<< (nbrf)*100/nl<<" %"<<endl; |
| 1366 | if (nbf > 0) |
| 1367 | sout<<"****** FAIL, no Result : "<< (nbf)*100/nl<<" %"<<endl; |
| 1368 | if (nbw > 0) |
| 1369 | sout<<"****** Just Warning : "<< (nbw)*100/nl<<" %"<<endl; |
| 1370 | if (nbnr > 0) |
| 1371 | sout<<"****** Nothing Recorded: "<< (nbnr)*100/nl<<" %"<<endl; */ |
| 1372 | } |
| 1373 | return; |
| 1374 | } |
| 1375 | |
| 1376 | // Cas what = 4,5 : check-list |
| 1377 | |
| 1378 | if (what == 4 || what == 5) { |
| 1379 | |
| 1380 | Interface_CheckIterator chl = TP->CheckList(Standard_False); |
| 1381 | chl.SetName("** TRANSFER READ CHECK **"); |
| 1382 | if (mode == 0) chl.Print (sout,model,(what == 5)); |
| 1383 | else { |
| 1384 | IFSelect_PrintCount pcm = IFSelect_CountByItem; |
| 1385 | if (mode == 2) pcm = IFSelect_ListByItem; |
| 1386 | Handle(IFSelect_CheckCounter) counter = new IFSelect_CheckCounter(Standard_True); |
| 1387 | counter->Analyse (chl,model,Standard_True,(what == 5)); |
| 1388 | counter->PrintList (sout,model,pcm); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | } |