| 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 | //:i1 pdn 03.04.99 BUC60301 |
| 15 | |
| 16 | #include <Geom2d_Point.hxx> |
| 17 | #include <Interface_Check.hxx> |
| 18 | #include <Interface_CheckIterator.hxx> |
| 19 | #include <Interface_Graph.hxx> |
| 20 | #include <Interface_HGraph.hxx> |
| 21 | #include <Interface_InterfaceModel.hxx> |
| 22 | #include <Interface_IntVal.hxx> |
| 23 | #include <Interface_Macros.hxx> |
| 24 | #include <Message_Messenger.hxx> |
| 25 | #include <Standard_ErrorHandler.hxx> |
| 26 | #include <Standard_Failure.hxx> |
| 27 | #include <TColStd_HSequenceOfTransient.hxx> |
| 28 | #include <TopoDS_Shape.hxx> |
| 29 | #include <Transfer_Binder.hxx> |
| 30 | #include <Transfer_Finder.hxx> |
| 31 | #include <Transfer_FinderProcess.hxx> |
| 32 | #include <Transfer_ResultFromModel.hxx> |
| 33 | #include <Transfer_ResultFromTransient.hxx> |
| 34 | #include <Transfer_SimpleBinderOfTransient.hxx> |
| 35 | #include <Transfer_TransientProcess.hxx> |
| 36 | #include <TransferBRep.hxx> |
| 37 | #include <XSControl_Controller.hxx> |
| 38 | #include <XSControl_TransferReader.hxx> |
| 39 | #include <XSControl_Vars.hxx> |
| 40 | #include <XSControl_WorkSession.hxx> |
| 41 | |
| 42 | IMPLEMENT_STANDARD_RTTIEXT(XSControl_WorkSession,IFSelect_WorkSession) |
| 43 | |
| 44 | //======================================================================= |
| 45 | //function : XSControl_WorkSession |
| 46 | //purpose : |
| 47 | //======================================================================= |
| 48 | |
| 49 | XSControl_WorkSession::XSControl_WorkSession () |
| 50 | : myTransferReader(new XSControl_TransferReader), |
| 51 | myTransferWriter(new XSControl_TransferWriter), |
| 52 | myVars(new XSControl_Vars) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | |
| 57 | //======================================================================= |
| 58 | //function : ClearData |
| 59 | //purpose : |
| 60 | //======================================================================= |
| 61 | |
| 62 | void XSControl_WorkSession::ClearData (const Standard_Integer mode) |
| 63 | { |
| 64 | // 1-2-3-4 : standard IFSelect |
| 65 | if (mode >= 1 && mode <= 4) IFSelect_WorkSession::ClearData (mode); |
| 66 | |
| 67 | // 5 : Transferts seuls |
| 68 | // 6 : Resultats forces seuls |
| 69 | // 7 : Management, y compris tous transferts (forces/calcules), views |
| 70 | |
| 71 | if (mode == 5 || mode == 7) { |
| 72 | myTransferReader->Clear(-1); |
| 73 | myTransferWriter->Clear(-1); |
| 74 | } |
| 75 | if (mode == 6 && !myTransferReader.IsNull()) myTransferReader->Clear(1); |
| 76 | myTransferReader->SetGraph (HGraph()); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | //======================================================================= |
| 81 | //function : SelectNorm |
| 82 | //purpose : |
| 83 | //======================================================================= |
| 84 | |
| 85 | Standard_Boolean XSControl_WorkSession::SelectNorm(const Standard_CString normname) |
| 86 | { |
| 87 | // Old norm and results |
| 88 | myTransferReader->Clear(-1); |
| 89 | // ???? En toute rigueur, menage a faire dans XWS : virer les items |
| 90 | // ( a la limite, pourquoi pas, refaire XWS en entier) |
| 91 | |
| 92 | Handle(XSControl_Controller) newadapt = XSControl_Controller::Recorded (normname); |
| 93 | if (newadapt.IsNull()) return Standard_False; |
| 94 | if (newadapt == myController) return Standard_True; |
| 95 | SetController (newadapt); |
| 96 | return Standard_True; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | //======================================================================= |
| 101 | //function : SetController |
| 102 | //purpose : |
| 103 | //======================================================================= |
| 104 | |
| 105 | void XSControl_WorkSession::SetController(const Handle(XSControl_Controller)& ctl) |
| 106 | { |
| 107 | myController = ctl; |
| 108 | |
| 109 | SetLibrary ( myController->WorkLibrary() ); |
| 110 | SetProtocol ( myController->Protocol() ); |
| 111 | |
| 112 | ClearItems(); |
| 113 | ClearFinalModifiers(); |
| 114 | ClearShareOut(Standard_False); |
| 115 | ClearFile(); |
| 116 | |
| 117 | // Set worksession parameters from teh controller |
| 118 | Handle(XSControl_WorkSession) aWorkSession(this); |
| 119 | myController->Customise (aWorkSession); |
| 120 | |
| 121 | myTransferReader->SetController (myController); |
| 122 | myTransferWriter->SetController (myController); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | //======================================================================= |
| 127 | //function : SelectedNorm |
| 128 | //purpose : |
| 129 | //======================================================================= |
| 130 | |
| 131 | Standard_CString XSControl_WorkSession::SelectedNorm(const Standard_Boolean rsc) const |
| 132 | { |
| 133 | //JR/Hp : |
| 134 | Standard_CString astr = (Standard_CString ) (myController.IsNull() ? "" : myController->Name(rsc)); |
| 135 | return astr ; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | // ########################################## |
| 140 | // ############ Contexte de Transfert ###### |
| 141 | // ########################################## |
| 142 | |
| 143 | |
| 144 | //======================================================================= |
| 145 | //function : SetAllContext |
| 146 | //purpose : |
| 147 | //======================================================================= |
| 148 | |
| 149 | void XSControl_WorkSession::SetAllContext(const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& context) |
| 150 | { |
| 151 | myContext = context; |
| 152 | myTransferReader->Context() = context; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | //======================================================================= |
| 157 | //function : ClearContext |
| 158 | //purpose : |
| 159 | //======================================================================= |
| 160 | |
| 161 | void XSControl_WorkSession::ClearContext () |
| 162 | { |
| 163 | myContext.Clear(); |
| 164 | myTransferReader->Context().Clear(); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | // ########################################## |
| 169 | // ############ RESULTATS FORCES ###### |
| 170 | // ########################################## |
| 171 | |
| 172 | |
| 173 | //======================================================================= |
| 174 | //function : PrintTransferStatus |
| 175 | //purpose : |
| 176 | //======================================================================= |
| 177 | |
| 178 | Standard_Boolean XSControl_WorkSession::PrintTransferStatus(const Standard_Integer num, |
| 179 | const Standard_Boolean wri, |
| 180 | const Handle(Message_Messenger)& S) const |
| 181 | { |
| 182 | const Handle(Transfer_FinderProcess) &FP = myTransferWriter->FinderProcess(); |
| 183 | Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess(); |
| 184 | |
| 185 | Handle(Transfer_Binder) binder; |
| 186 | Handle(Transfer_Finder) finder; |
| 187 | Handle(Standard_Transient) ent; |
| 188 | |
| 189 | // *** WRITE *** |
| 190 | if (wri) { |
| 191 | if (FP.IsNull()) return Standard_False; |
| 192 | if (num == 0 ) return Standard_False; |
| 193 | |
| 194 | Standard_Integer ne=0, nr=0, max = FP->NbMapped() ,maxr = FP->NbRoots(); |
| 195 | if (num > 0) { |
| 196 | if (num > max) return Standard_False; |
| 197 | ne = num; |
| 198 | finder = FP->Mapped(ne); |
| 199 | nr = FP->RootIndex(finder); |
| 200 | } else if (num < 0) { |
| 201 | nr = -num; |
| 202 | if (nr > maxr) return Standard_False; |
| 203 | finder = FP->Root(nr); |
| 204 | ne = FP->MapIndex(finder); |
| 205 | } |
| 206 | |
| 207 | S<<"Transfer Write item n0."<<ne<<" of "<<max; |
| 208 | if (nr > 0) |
| 209 | { |
| 210 | S<<" ** Transfer Root n0."<<ne; |
| 211 | } |
| 212 | S<<endl; |
| 213 | ent = FP->FindTransient(finder); |
| 214 | S<<" -> Type "<<finder->DynamicType()->Name()<<endl; |
| 215 | FP->StartTrace (binder,finder,0,0); // pb sout/S |
| 216 | if (!ent.IsNull()) { |
| 217 | S<<" ** Resultat Transient, type "<<ent->DynamicType()->Name(); |
| 218 | const Handle(Interface_InterfaceModel) &model = Model(); |
| 219 | if (!model.IsNull()) |
| 220 | { S<<" In output Model, Entity "; model->Print(ent,S); } |
| 221 | S<<endl; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | // *** READ *** |
| 226 | else { |
| 227 | if (TP.IsNull()) return Standard_False; |
| 228 | Handle(Interface_InterfaceModel) model = TP->Model(); |
| 229 | if (model.IsNull()) cout<<"No Model"<<endl; |
| 230 | else if (model != Model()) cout<<"Model different from the session"<<endl; |
| 231 | if (num == 0) return Standard_False; |
| 232 | |
| 233 | Standard_Integer ne=0, nr=0, max = TP->NbMapped() ,maxr = TP->NbRoots(); |
| 234 | if (num > 0) { |
| 235 | if (num > max) return Standard_False; |
| 236 | ne = num; |
| 237 | ent = TP->Mapped(ne); |
| 238 | nr = TP->RootIndex(finder); |
| 239 | } else if (num < 0) { |
| 240 | nr = -num; |
| 241 | if (nr > maxr) return Standard_False; |
| 242 | ent = TP->Root(nr); |
| 243 | ne = TP->MapIndex(ent); |
| 244 | } |
| 245 | |
| 246 | S<<"Transfer Read item n0."<<ne<<" of "<<max; |
| 247 | if (nr > 0) |
| 248 | { |
| 249 | S<<" ** Transfer Root n0."<<ne; |
| 250 | } |
| 251 | S<<endl; |
| 252 | if (!model.IsNull()) { S<<" In Model, Entity "; model->Print(ent,S); } |
| 253 | binder = TP->MapItem (ne); |
| 254 | S<<endl; |
| 255 | TP->StartTrace (binder,ent,0,0); |
| 256 | |
| 257 | } |
| 258 | |
| 259 | // *** CHECK (commun READ+WRITE) *** |
| 260 | if (!binder.IsNull()) { |
| 261 | const Handle(Interface_Check) ch = binder->Check(); |
| 262 | Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails(); |
| 263 | if (nbw > 0) { |
| 264 | S<<" - Warnings : "<<nbw<<" :\n"; |
| 265 | for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl; |
| 266 | } |
| 267 | if (nbf > 0) { |
| 268 | S<<" - Fails : "<<nbf<<" :\n"; |
| 269 | for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl; |
| 270 | } |
| 271 | } |
| 272 | return Standard_True; |
| 273 | } |
| 274 | |
| 275 | |
| 276 | //======================================================================= |
| 277 | //function : InitTransferReader |
| 278 | //purpose : |
| 279 | //======================================================================= |
| 280 | |
| 281 | void XSControl_WorkSession::InitTransferReader(const Standard_Integer mode) |
| 282 | { |
| 283 | if (mode == 0 || mode == 5) myTransferReader->Clear(-1); // full clear |
| 284 | if (myTransferReader.IsNull()) SetTransferReader (new XSControl_TransferReader); |
| 285 | else SetTransferReader (myTransferReader); |
| 286 | |
| 287 | // mode = 0 fait par SetTransferReader suite a Nullify |
| 288 | if (mode == 1) { |
| 289 | if (!myTransferReader.IsNull()) myTransferReader->Clear(-1); |
| 290 | else SetTransferReader (new XSControl_TransferReader); |
| 291 | } |
| 292 | if (mode == 2) { |
| 293 | Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess(); |
| 294 | if (TP.IsNull()) { |
| 295 | TP = new Transfer_TransientProcess; |
| 296 | myTransferReader->SetTransientProcess(TP); |
| 297 | TP->SetGraph (HGraph()); |
| 298 | } |
| 299 | Handle(TColStd_HSequenceOfTransient) lis = myTransferReader->RecordedList(); |
| 300 | Standard_Integer i, nb = lis->Length(); |
| 301 | for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i)); |
| 302 | } |
| 303 | if (mode == 3) { |
| 304 | Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess(); |
| 305 | if (TP.IsNull()) return; |
| 306 | Standard_Integer i, nb = TP->NbRoots(); |
| 307 | for (i = 1; i <= nb; i ++) myTransferReader->RecordResult(TP->Root(i)); |
| 308 | } |
| 309 | if (mode == 4 || mode == 5) myTransferReader->BeginTransfer(); |
| 310 | } |
| 311 | |
| 312 | |
| 313 | //======================================================================= |
| 314 | //function : SetTransferReader |
| 315 | //purpose : |
| 316 | //======================================================================= |
| 317 | |
| 318 | void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR) |
| 319 | { |
| 320 | if (myTransferReader != TR) //i1 pdn 03.04.99 BUC60301 |
| 321 | myTransferReader = TR; |
| 322 | if (TR.IsNull()) return; |
| 323 | TR->SetController (myController); |
| 324 | TR->SetGraph (HGraph()); |
| 325 | if (!TR->TransientProcess().IsNull()) return; |
| 326 | Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess |
| 327 | (Model().IsNull() ? 100 : Model()->NbEntities() + 100); |
| 328 | TP->SetGraph (HGraph()); |
| 329 | TP->SetErrorHandle(Standard_True); |
| 330 | TR->SetTransientProcess(TP); |
| 331 | } |
| 332 | |
| 333 | //======================================================================= |
| 334 | //function : MapReader |
| 335 | //purpose : |
| 336 | //======================================================================= |
| 337 | |
| 338 | Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader() const |
| 339 | { |
| 340 | return myTransferReader->TransientProcess(); |
| 341 | } |
| 342 | |
| 343 | //======================================================================= |
| 344 | //function : SetMapReader |
| 345 | //purpose : |
| 346 | //======================================================================= |
| 347 | |
| 348 | Standard_Boolean XSControl_WorkSession::SetMapReader (const Handle(Transfer_TransientProcess)& TP) |
| 349 | { |
| 350 | if (TP.IsNull()) return Standard_False; |
| 351 | if (TP->Model().IsNull()) TP->SetModel (Model()); |
| 352 | TP->SetGraph (HGraph()); |
| 353 | if (TP->Model() != Model()) return Standard_False; |
| 354 | // TR ne doit pas bouger, c est un "crochet" pour signatures, selections ... |
| 355 | // En revanche, mieux vaut le RAZ |
| 356 | // Handle(XSControl_TransferReader) TR = new XSControl_TransferReader; |
| 357 | Handle(XSControl_TransferReader) TR = myTransferReader; |
| 358 | TR->Clear(-1); |
| 359 | |
| 360 | SetTransferReader (TR); // avec le meme mais le reinitialise |
| 361 | TR->SetTransientProcess (TP); // et prend le nouveau TP |
| 362 | return Standard_True; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | //======================================================================= |
| 367 | //function : Result |
| 368 | //purpose : |
| 369 | //======================================================================= |
| 370 | |
| 371 | Handle(Standard_Transient) XSControl_WorkSession::Result |
| 372 | (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const |
| 373 | { |
| 374 | Standard_Integer ouca = (mode % 10); |
| 375 | Standard_Integer kica = (mode / 10); |
| 376 | |
| 377 | Handle(Transfer_Binder) binder; |
| 378 | Handle(Transfer_ResultFromModel) resu; |
| 379 | |
| 380 | if (ouca != 1) resu = myTransferReader->FinalResult(ent); |
| 381 | if (mode == 20) return resu; |
| 382 | |
| 383 | if (!resu.IsNull()) binder = resu->MainResult()->Binder(); |
| 384 | if (binder.IsNull() && ouca > 0) |
| 385 | binder = myTransferReader->TransientProcess()->Find(ent); |
| 386 | |
| 387 | if (kica == 1) return binder; |
| 388 | DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder); |
| 389 | if (!trb.IsNull()) return trb->Result(); |
| 390 | return binder; |
| 391 | } |
| 392 | |
| 393 | // ########################################## |
| 394 | // ############ TRANSFERT ############# |
| 395 | // ########################################## |
| 396 | |
| 397 | |
| 398 | //======================================================================= |
| 399 | //function : TransferReadOne |
| 400 | //purpose : |
| 401 | //======================================================================= |
| 402 | |
| 403 | Standard_Integer XSControl_WorkSession::TransferReadOne (const Handle(Standard_Transient)& ent) |
| 404 | { |
| 405 | Handle(Interface_InterfaceModel) model = Model(); |
| 406 | if (ent == model) return TransferReadRoots(); |
| 407 | |
| 408 | Handle(TColStd_HSequenceOfTransient) list = GiveList(ent); |
| 409 | if (list->Length() == 1) return myTransferReader->TransferOne(list->Value(1)); |
| 410 | else return myTransferReader->TransferList (list); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | //======================================================================= |
| 415 | //function : TransferReadRoots |
| 416 | //purpose : |
| 417 | //======================================================================= |
| 418 | |
| 419 | Standard_Integer XSControl_WorkSession::TransferReadRoots () |
| 420 | { |
| 421 | return myTransferReader->TransferRoots(Graph()); |
| 422 | } |
| 423 | |
| 424 | |
| 425 | // ########################################## |
| 426 | // ############ TRANSFERT WRITE |
| 427 | // ########################################## |
| 428 | |
| 429 | //======================================================================= |
| 430 | //function : NewModel |
| 431 | //purpose : |
| 432 | //======================================================================= |
| 433 | |
| 434 | Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel () |
| 435 | { |
| 436 | Handle(Interface_InterfaceModel) newmod; |
| 437 | if (myController.IsNull()) return newmod; |
| 438 | newmod = myController->NewModel(); |
| 439 | |
| 440 | SetModel(newmod); |
| 441 | if(!myTransferReader->TransientProcess().IsNull()) |
| 442 | myTransferReader->TransientProcess()->Clear(); |
| 443 | //clear all contains of WS |
| 444 | myTransferReader->Clear(3); |
| 445 | myTransferWriter->Clear(-1); |
| 446 | |
| 447 | return newmod; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | //======================================================================= |
| 452 | //function : TransferWriteShape |
| 453 | //purpose : |
| 454 | //======================================================================= |
| 455 | |
| 456 | IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape (const TopoDS_Shape& shape, const Standard_Boolean compgraph) |
| 457 | { |
| 458 | IFSelect_ReturnStatus status; |
| 459 | if (myController.IsNull()) return IFSelect_RetError; |
| 460 | const Handle(Interface_InterfaceModel) &model = Model(); |
| 461 | if (model.IsNull() || shape.IsNull()) |
| 462 | { |
| 463 | return IFSelect_RetVoid; |
| 464 | } |
| 465 | |
| 466 | status = myTransferWriter->TransferWriteShape (model,shape); |
| 467 | // qui s occupe de tout, try/catch inclus |
| 468 | |
| 469 | //skl insert param compgraph for XDE writing 10.12.2003 |
| 470 | if(compgraph) ComputeGraph(Standard_True); |
| 471 | |
| 472 | return status; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | //======================================================================= |
| 477 | //function : TransferWriteCheckList |
| 478 | //purpose : |
| 479 | //======================================================================= |
| 480 | |
| 481 | Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const |
| 482 | { |
| 483 | return myTransferWriter->ResultCheckList (Model()); |
| 484 | } |
| 485 | |
| 486 | |
| 487 | //======================================================================= |
| 488 | //function : ClearBinders |
| 489 | //purpose : |
| 490 | //======================================================================= |
| 491 | |
| 492 | void XSControl_WorkSession::ClearBinders() |
| 493 | { |
| 494 | const Handle(Transfer_FinderProcess) &FP = myTransferWriter->FinderProcess(); |
| 495 | //Due to big number of chains of binders it is necessary to |
| 496 | //collect head binders of each chain in the sequence |
| 497 | TColStd_SequenceOfTransient aSeqBnd; |
| 498 | TColStd_SequenceOfTransient aSeqShapes; |
| 499 | Standard_Integer i =1; |
| 500 | for( ; i <= FP->NbMapped();i++) { |
| 501 | Handle(Transfer_Binder) bnd = FP->MapItem ( i ); |
| 502 | if(!bnd.IsNull()) |
| 503 | aSeqBnd.Append(bnd); |
| 504 | Handle(Standard_Transient) ash (FP->Mapped(i)); |
| 505 | aSeqShapes.Append(ash); |
| 506 | } |
| 507 | //removing finder process containing result of translation. |
| 508 | FP->Clear(); |
| 509 | ClearData(1); |
| 510 | ClearData(5); |
| 511 | |
| 512 | //removing each chain of binders |
| 513 | while(aSeqBnd.Length() >0) { |
| 514 | Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1)); |
| 515 | Handle(Standard_Transient) ash =aSeqShapes.Value(1); |
| 516 | aSeqBnd.Remove(1); |
| 517 | aSeqShapes.Remove(1); |
| 518 | ash.Nullify(); |
| 519 | while(!aBnd.IsNull()) { |
| 520 | Handle(Transfer_Binder) aBndNext = aBnd->NextResult(); |
| 521 | aBnd.Nullify(); |
| 522 | aBnd = aBndNext; |
| 523 | } |
| 524 | |
| 525 | } |
| 526 | |
| 527 | } |