| 1 | #include <XSControl_FuncShape.ixx> |
| 2 | #include <Standard_ErrorHandler.hxx> |
| 3 | #include <Standard_Failure.hxx> |
| 4 | |
| 5 | #include <XSControl.hxx> |
| 6 | #include <XSControl_Controller.hxx> |
| 7 | #include <XSControl_WorkSession.hxx> |
| 8 | #include <XSControl_Vars.hxx> |
| 9 | #include <IFSelect_Act.hxx> |
| 10 | #include <IFSelect_SessionPilot.hxx> |
| 11 | #include <IFSelect_Functions.hxx> |
| 12 | |
| 13 | #include <Interface_InterfaceModel.hxx> |
| 14 | #include <Transfer_TransientProcess.hxx> |
| 15 | #include <Transfer_FinderProcess.hxx> |
| 16 | #include <Transfer_Finder.hxx> |
| 17 | #include <Transfer_Binder.hxx> |
| 18 | #include <Interface_CheckIterator.hxx> |
| 19 | |
| 20 | //#include <TransferBRep_Analyzer.hxx> |
| 21 | #include <TransferBRep_ShapeMapper.hxx> |
| 22 | #include <TransferBRep_ShapeBinder.hxx> |
| 23 | #include <TransferBRep_ShapeListBinder.hxx> |
| 24 | #include <Transfer_SimpleBinderOfTransient.hxx> |
| 25 | |
| 26 | #include <XSControl_ConnectedShapes.hxx> |
| 27 | #include <XSControl_TransferWriter.hxx> |
| 28 | #include <XSControl_TransferReader.hxx> |
| 29 | #include <TColStd_HSequenceOfTransient.hxx> |
| 30 | #include <Transfer_ResultFromModel.hxx> |
| 31 | |
| 32 | #include <TopTools_HSequenceOfShape.hxx> |
| 33 | #include <TopoDS_Compound.hxx> |
| 34 | #include <BRep_Builder.hxx> |
| 35 | #include <TransferBRep.hxx> |
| 36 | #include <BRepTools.hxx> |
| 37 | |
| 38 | #include <TopoDS.hxx> |
| 39 | #include <TColStd_SequenceOfInteger.hxx> |
| 40 | #include <TopExp_Explorer.hxx> |
| 41 | |
| 42 | #include <Geom_Geometry.hxx> |
| 43 | #include <Geom2d_Curve.hxx> |
| 44 | |
| 45 | #include <IFSelect_CheckCounter.hxx> |
| 46 | #include <ShapeExtend_Explorer.hxx> |
| 47 | #include <Interface_Macros.hxx> |
| 48 | #include <stdio.h> |
| 49 | #include <TopoDS_Iterator.hxx> |
| 50 | #include <Transfer_TransientListBinder.hxx> |
| 51 | |
| 52 | #include <Message_Messenger.hxx> |
| 53 | #include <Message.hxx> |
| 54 | |
| 55 | // ###################################################################### |
| 56 | // #### #### |
| 57 | // #### COMMANDS #### |
| 58 | // #### #### |
| 59 | // ###################################################################### |
| 60 | |
| 61 | |
| 62 | //======================================================================= |
| 63 | //function : XSControl_tpdraw |
| 64 | //purpose : |
| 65 | //======================================================================= |
| 66 | static IFSelect_ReturnStatus XSControl_tpdraw |
| 67 | (const Handle(IFSelect_SessionPilot)& pilot) |
| 68 | { |
| 69 | Standard_Integer argc = pilot->NbWords(); |
| 70 | const Standard_CString arg1 = pilot->Arg(1); |
| 71 | const Standard_CString arg2 = pilot->Arg(2); |
| 72 | const Standard_CString arg3 = pilot->Arg(3); |
| 73 | Handle(Transfer_TransientProcess) TP = XSControl::Session(pilot)->TransferReader()->TransientProcess(); |
| 74 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 75 | if (TP.IsNull()) { sout<<"No Transfer Read"<<endl; return IFSelect_RetError;} |
| 76 | // **** tpdraw **** |
| 77 | if (argc < 2) { |
| 78 | sout<<"Donner [mode facultatif : item ou root] , NUMERO , nom DRAW facultatif"<<endl; |
| 79 | sout<<" mode si present : item ou root, sinon n0 d entite modele"<<endl; |
| 80 | sout<<" NUMERO entier : d entite, d item transfert ou de root transfert\n" |
| 81 | << " ou * pour dire tous"<<endl; |
| 82 | return IFSelect_RetError; |
| 83 | } |
| 84 | Standard_Integer mode = 0, num=0; |
| 85 | if (arg1[0] == 'i') mode = 1; |
| 86 | else if (arg1[0] == 'r') mode = 2; |
| 87 | Standard_Boolean tout = Standard_False; |
| 88 | if (mode == 0) { |
| 89 | if (argc < 2) { sout<<"Donner au moins un NUMERO ou *"<<endl; return IFSelect_RetError; } |
| 90 | if (arg1[0] == '*') tout = Standard_True; |
| 91 | else num = IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot),arg1); |
| 92 | } else { |
| 93 | if (arg2[0] == '*') tout = Standard_True; |
| 94 | else num = IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot),arg2); |
| 95 | } |
| 96 | |
| 97 | Standard_Integer nbvar = 0; |
| 98 | Handle(Transfer_Binder) binder; |
| 99 | Handle(Standard_Transient) ent; |
| 100 | TopoDS_Shape sh; char nomvar[40]; |
| 101 | // Standard_Boolean moderoot = (pilot->Word(0).Value(3) == 'r'); |
| 102 | |
| 103 | Standard_Integer n1, n2, i, max=0, index=0; |
| 104 | Handle(Interface_InterfaceModel) model = TP->Model(); |
| 105 | if (model.IsNull()) { |
| 106 | if (mode == 0) { |
| 107 | sout<<"Pas de modele, preciser n0 d item de transfert"<<endl; |
| 108 | return IFSelect_RetError; |
| 109 | } |
| 110 | } |
| 111 | if (mode == 0) { sout<<"Entite de modele"; max = model->NbEntities(); } |
| 112 | if (mode == 1) { sout<<"Item de transfert"; max = TP->NbMapped(); } |
| 113 | if (mode == 2) { sout<<"Racine de transfert"; max = TP->NbRoots(); } |
| 114 | if (tout) { |
| 115 | n1 = 1; n2 = max; |
| 116 | sout<<", listage de 1 a "<<max<<endl; |
| 117 | } |
| 118 | else if (num <= 0 || num > max) { |
| 119 | sout<<" - Num="<<num<<" hors limite (de 1 a "<<max<<")"<<endl; |
| 120 | return IFSelect_RetError; |
| 121 | } else { |
| 122 | n1 = n2 = num; nbvar = -1; // nbvar : 1ere shape simple = pas de n0 |
| 123 | sout<<", n0 "<<num<<endl; |
| 124 | } |
| 125 | |
| 126 | for (i = n1; i <= n2; i ++) { |
| 127 | if (mode == 0) { |
| 128 | ent = model->Value(i); |
| 129 | num = i; |
| 130 | index = TP->MapIndex(ent); |
| 131 | } else if (mode == 1) { |
| 132 | ent = TP->Mapped(i); |
| 133 | if (model.IsNull()) num = 0; |
| 134 | else num = model->Number(ent); |
| 135 | index = i; |
| 136 | } else if (mode == 2) { |
| 137 | ent = TP->Root(i); |
| 138 | if (model.IsNull()) num = 0; |
| 139 | else num = model->Number(ent); |
| 140 | index = TP->MapIndex(ent); |
| 141 | } |
| 142 | |
| 143 | if (index > 0) binder = TP->MapItem (index); |
| 144 | if (binder.IsNull()) index = 0; |
| 145 | if (index == 0) { |
| 146 | if (!tout) sout<<"Entite n0 "<<num<<" : non repertoriee"<<endl; |
| 147 | continue; |
| 148 | } |
| 149 | if (!binder->HasResult()) { |
| 150 | if (!tout) sout<<"Entite n0 "<<num<<" : pas de resultat"<<endl; |
| 151 | continue; |
| 152 | } |
| 153 | sh = TransferBRep::ShapeResult (binder); |
| 154 | //DeclareAndCast(TransferBRep_ShapeBinder,shb,binder); |
| 155 | if (!sh.IsNull()) { |
| 156 | //sh = shb->Result(); |
| 157 | nbvar ++; |
| 158 | if (sh.IsNull()) { sout<<" (no Shape recorded)"<<endl; continue; } |
| 159 | if (tout) sout<<"[ "<<i<<" ]:"; |
| 160 | if (num == 0) sout<<" pas dans le modele"; |
| 161 | else sout<<" ent.n0 "<<num; |
| 162 | sout<<", item transfert n0 "<<index; |
| 163 | if (nbvar == 0) { |
| 164 | if (argc > 3 && mode > 0) sprintf (nomvar,"%s",arg3); |
| 165 | else if (argc > 2 && mode == 0) sprintf (nomvar,"%s",arg2); |
| 166 | else sprintf (nomvar,"tp_%d",i); |
| 167 | } else { |
| 168 | if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar); |
| 169 | else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar); |
| 170 | else sprintf (nomvar,"tp_%d",i); |
| 171 | } |
| 172 | sout<<" -> 1 DRAW Shape: "<<nomvar<<endl; |
| 173 | XSControl::Vars(pilot)->SetShape(nomvar,sh); |
| 174 | continue; |
| 175 | } |
| 176 | DeclareAndCast(TransferBRep_ShapeListBinder,slb,binder); |
| 177 | if (!slb.IsNull()) { |
| 178 | Standard_Integer nbs = slb->NbShapes(); |
| 179 | if (tout) sout<<"[ "<<i<<" ]:"; |
| 180 | if (num == 0) sout<<" pas dans le modele"; |
| 181 | else sout<<" ent.n0 "<<num; |
| 182 | sout<<", item transfert n0 "<<index; |
| 183 | sout<<" -> "<<nbs<<" DRAW Shapes :"; |
| 184 | for (Standard_Integer j = 1; j <= nbs; j ++) { |
| 185 | sh = slb->Shape(j); if (nbvar < 0) nbvar = 0; nbvar ++; |
| 186 | if (sh.IsNull()) { sout<<" (no Shape recorded)"<<endl; continue; } |
| 187 | if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar); |
| 188 | else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar); |
| 189 | else sprintf (nomvar,"tp_%d_%d",i,nbvar); |
| 190 | sout<<" "<<nomvar; |
| 191 | XSControl::Vars(pilot)->SetShape(nomvar,sh); |
| 192 | } |
| 193 | sout<<endl; |
| 194 | continue; |
| 195 | } |
| 196 | DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder); |
| 197 | if (!trb.IsNull()) { |
| 198 | Handle(Standard_Transient) resu = trb->Result(); |
| 199 | if (resu.IsNull()) { |
| 200 | sout<<"Entite n0 "<<num<<" : pas de resultat"<<endl; |
| 201 | continue; |
| 202 | } |
| 203 | DeclareAndCast(Geom_Geometry,geom,resu); |
| 204 | sout<<"Entite n0 "<<num<<" : resultat "<<resu->DynamicType()->Name(); |
| 205 | if (geom.IsNull()) { sout<<endl; continue; } |
| 206 | nbvar ++; |
| 207 | if (nbvar == 0) { |
| 208 | if (argc > 3 && mode > 0) sprintf (nomvar,"%s",arg3); |
| 209 | else if (argc > 2 && mode == 0) sprintf (nomvar,"%s",arg2); |
| 210 | else sprintf (nomvar,"tp_%d",i); |
| 211 | } else { |
| 212 | if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar); |
| 213 | else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar); |
| 214 | else sprintf (nomvar,"tp_%d",i); |
| 215 | } |
| 216 | char* nomv = nomvar; |
| 217 | XSControl::Vars(pilot)->Set (nomv,geom); |
| 218 | sout<<" -> DRAW Geom : "<<nomvar<<endl; |
| 219 | continue; |
| 220 | } |
| 221 | |
| 222 | if (sh.IsNull() && trb.IsNull()) |
| 223 | if (!tout) sout<<"Entite n0 "<<num<<" : resultat pas une Shape mais "<<binder->ResultTypeName()<<endl; |
| 224 | } |
| 225 | |
| 226 | if (sh.IsNull()) sout<<" (No Shape)"<<endl; |
| 227 | return IFSelect_RetDone; |
| 228 | } |
| 229 | |
| 230 | //======================================================================= |
| 231 | //function : XSControl_tpcompound |
| 232 | //purpose : |
| 233 | //======================================================================= |
| 234 | static IFSelect_ReturnStatus XSControl_tpcompound |
| 235 | (const Handle(IFSelect_SessionPilot)& pilot) |
| 236 | { |
| 237 | Standard_Integer argc = pilot->NbWords(); |
| 238 | const Standard_CString arg1 = pilot->Arg(1); |
| 239 | Handle(Transfer_TransientProcess) TP = XSControl::Session(pilot)->TransferReader()->TransientProcess(); |
| 240 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 241 | if (TP.IsNull()) { sout<<"No Transfer Read"<<endl; return IFSelect_RetError;} |
| 242 | // **** tpcompound **** |
| 243 | if (argc < 2) { sout<<"Give a NAME for the Compound + optional givelist, else roots are taken"<<endl; return IFSelect_RetError; } |
| 244 | Handle(TopTools_HSequenceOfShape) list; |
| 245 | if (argc == 2) list = TransferBRep::Shapes(TP); |
| 246 | else { |
| 247 | Handle(TColStd_HSequenceOfTransient) lise = IFSelect_Functions::GiveList(pilot->Session(),pilot->CommandPart(2)); |
| 248 | if (lise.IsNull()) { sout<<"Not a valid entity list : "<<pilot->CommandPart(2)<<endl; return IFSelect_RetError; } |
| 249 | list = TransferBRep::Shapes (TP,lise); |
| 250 | sout<<lise->Length()<<" Entities, "; |
| 251 | } |
| 252 | if (list.IsNull()) { sout<<"No Shape listed"<<endl; return IFSelect_RetError; } |
| 253 | Standard_Integer nb = list->Length(); |
| 254 | sout<<nb<<" Shape(s) listed"<<endl; |
| 255 | TopoDS_Compound C; |
| 256 | BRep_Builder B; |
| 257 | B.MakeCompound(C); |
| 258 | for (Standard_Integer i = 1; i <= nb; i ++) B.Add (C,list->Value(i)); |
| 259 | XSControl::Vars(pilot)->SetShape (arg1,C); |
| 260 | return IFSelect_RetDone; |
| 261 | } |
| 262 | |
| 263 | |
| 264 | |
| 265 | //======================================================================= |
| 266 | //function : XSControl_traccess |
| 267 | //purpose : |
| 268 | //======================================================================= |
| 269 | static IFSelect_ReturnStatus XSControl_traccess |
| 270 | (const Handle(IFSelect_SessionPilot)& pilot) |
| 271 | { |
| 272 | Standard_Integer argc = pilot->NbWords(); |
| 273 | const Standard_CString arg1 = pilot->Arg(1); |
| 274 | const Standard_CString arg2 = pilot->Arg(2); |
| 275 | // **** trdraw : TransferReader **** 26 |
| 276 | // **** trsave : TransferReader **** 27 |
| 277 | // **** trcomp (comp -> DRAW) **** 28 |
| 278 | // **** trscomp (comp -> save) **** 29 |
| 279 | Standard_Boolean cascomp = (pilot->Word(0).Location(1,'o',1,5) > 0); |
| 280 | Standard_Boolean cassave = (pilot->Word(0).Location(1,'s',1,5) > 0); |
| 281 | char nomsh[100], noms[100]; |
| 282 | Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader(); |
| 283 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 284 | if (TR.IsNull()) { sout<<" manque init"<<endl; return IFSelect_RetError; } |
| 285 | Handle(Interface_InterfaceModel) mdl = TR->Model(); |
| 286 | if (mdl.IsNull()) { sout<<" modele absent"<<endl; return IFSelect_RetError; } |
| 287 | Standard_Integer num = (argc > 1 ? IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot),arg1) : 0); |
| 288 | |
| 289 | if (argc > 1) strcpy (nomsh,arg1); |
| 290 | else strcpy (nomsh,(cascomp ? "TREAD_COMP" : "TREAD_LIST")); |
| 291 | if (cassave) sout<<" save shapes -> current directory"<<endl; |
| 292 | |
| 293 | if (num == 0 || cascomp) { |
| 294 | TopoDS_Compound C; // pour cas compound |
| 295 | BRep_Builder B; |
| 296 | B.MakeCompound(C); |
| 297 | |
| 298 | Handle(TopTools_HSequenceOfShape) list = TR->ShapeResultList(Standard_True); |
| 299 | Standard_Integer i, nb = list->Length(); |
| 300 | sout<<" TOUS RESULTATS par ShapeResultList, soit "<<nb<<endl; |
| 301 | for (i = 1; i <= nb; i ++) { |
| 302 | sprintf (noms,"%s_%d",nomsh,i); |
| 303 | if ( (i%1000) == 0) sout<<"("<<i<<")"<<endl; |
| 304 | else if ( (i%100) == 0) sout<<"*"; |
| 305 | else if ( (i%10) == 0) sout<<"0"; |
| 306 | else sout<<"."; |
| 307 | if (list->Value(i).IsNull()) continue; |
| 308 | if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape(noms,list->Value(i)); |
| 309 | else if (!cascomp && cassave) BRepTools::Write (list->Value(i),noms); |
| 310 | else if (cascomp) B.Add (C,list->Value(i)); |
| 311 | } |
| 312 | sout<<endl; |
| 313 | if (cascomp && !cassave) XSControl::Vars(pilot)->SetShape(nomsh,C); |
| 314 | else if (cascomp && cassave) BRepTools::Write (C,nomsh); |
| 315 | } else { |
| 316 | if (num < 1 || num > mdl->NbEntities()) { sout<<" incorrect:"<<arg1<<endl; return IFSelect_RetError; } |
| 317 | TopoDS_Shape sh = TR->ShapeResult(mdl->Value(num)); |
| 318 | if (sh.IsNull()) { sout<<" Pas de resultat pour "<<arg1<<endl; return IFSelect_RetError; } |
| 319 | if (argc > 2) sprintf (nomsh,"%s",arg2); |
| 320 | else sprintf (nomsh,"TREAD_%d",num); |
| 321 | if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape(nomsh,sh); |
| 322 | else if (!cascomp && cassave) BRepTools::Write (sh,nomsh); |
| 323 | else sout<<"Option non comprise"<<endl; |
| 324 | } |
| 325 | return IFSelect_RetDone; |
| 326 | } |
| 327 | |
| 328 | //======================================================================= |
| 329 | //function : XSControl_IsEqualSubShape |
| 330 | //purpose : |
| 331 | //======================================================================= |
| 332 | // PTV 23.08.2000 Added for checking where are an entity from. |
| 333 | static Standard_Boolean XSControl_IsEqualSubShape (const TopoDS_Shape& Shape, |
| 334 | TopoDS_Shape& sh, Standard_Integer aLevel) |
| 335 | { |
| 336 | if ( sh.IsSame(Shape) ) return Standard_True; |
| 337 | if (aLevel > 0) { |
| 338 | TopoDS_Shape varShape; |
| 339 | aLevel--; |
| 340 | TopoDS_Iterator it(sh); |
| 341 | for (; it.More(); it.Next() ) { |
| 342 | varShape = it.Value(); |
| 343 | if ( XSControl_IsEqualSubShape(Shape, varShape, aLevel) ) return Standard_True; |
| 344 | } |
| 345 | } |
| 346 | return Standard_False; |
| 347 | } |
| 348 | |
| 349 | //======================================================================= |
| 350 | //function : XSControl_fromshape |
| 351 | //purpose : |
| 352 | //======================================================================= |
| 353 | static IFSelect_ReturnStatus XSControl_fromshape |
| 354 | (const Handle(IFSelect_SessionPilot)& pilot) |
| 355 | { |
| 356 | Standard_Integer argc = pilot->NbWords(); |
| 357 | const Standard_CString arg1 = pilot->Arg(1); |
| 358 | // **** fromshape (tread) **** |
| 359 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 360 | if (argc < 2) { |
| 361 | sout<<"Give name of a DRAW Shape"<<endl; |
| 362 | return IFSelect_RetError; |
| 363 | } |
| 364 | const char* a1 = (char *)arg1; |
| 365 | TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(a1); |
| 366 | if (Shape.IsNull()) { |
| 367 | sout<<"Not a DRAW Shape:"<<arg1<<endl; |
| 368 | return IFSelect_RetError; |
| 369 | } |
| 370 | Standard_Boolean yena = Standard_False; |
| 371 | Standard_Integer aLevel = 1; |
| 372 | if (argc >=3 ) |
| 373 | aLevel = atoi(pilot->Arg(2)); |
| 374 | Standard_Boolean silent = Standard_False; |
| 375 | if (aLevel <0 ) { |
| 376 | silent = Standard_True; |
| 377 | aLevel = -aLevel; |
| 378 | } |
| 379 | |
| 380 | // IMPORT |
| 381 | Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader(); |
| 382 | if (TR.IsNull()) { } // sout<<"No read transfer (import) recorded"<<endl; |
| 383 | else { |
| 384 | yena = Standard_True; |
| 385 | if ( ! silent ) sout<<"Shape "<<arg1<<" : "; |
| 386 | Standard_Integer modrec = 1; |
| 387 | Handle(Standard_Transient) ent = TR->EntityFromShapeResult (Shape,modrec); |
| 388 | if (ent.IsNull()) { |
| 389 | modrec = -1; |
| 390 | ent = TR->EntityFromShapeResult (Shape,modrec); |
| 391 | } |
| 392 | if (ent.IsNull()) { |
| 393 | modrec = 2; |
| 394 | Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); |
| 395 | if (TP.IsNull()) { |
| 396 | if ( silent ) |
| 397 | sout << "Shape "<<arg1<<" : "; |
| 398 | sout<<"no map"<<endl; |
| 399 | } |
| 400 | else { |
| 401 | TopoDS_Shape S0 = Shape; |
| 402 | TopLoc_Location L; |
| 403 | S0.Location ( L ); |
| 404 | Standard_Integer i, nb = TP->NbMapped(); |
| 405 | if ( ! silent ) sout<<"searching in map among "<<nb<<" ..."; |
| 406 | for (i = 1; i <= nb; i ++) { |
| 407 | ent = TP->Mapped(i); |
| 408 | TopoDS_Shape sh = TransferBRep::ShapeResult(TP,ent); |
| 409 | if (sh.IsNull()) { |
| 410 | ent.Nullify(); |
| 411 | continue; |
| 412 | } |
| 413 | if (XSControl_IsEqualSubShape(Shape, sh, aLevel)) break; |
| 414 | modrec = -2; |
| 415 | sh.Location ( L ); |
| 416 | if (XSControl_IsEqualSubShape(S0, sh, aLevel)) break; |
| 417 | ent.Nullify(); |
| 418 | modrec = 2; |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | if ( ! ent.IsNull() ) { |
| 423 | if ( silent ) sout << "Shape " << arg1 << ": "; |
| 424 | if (modrec <0) sout<<"(moved from origin) "; |
| 425 | //else sout<<"(origin) "; |
| 426 | } |
| 427 | // on affiche |
| 428 | if (ent.IsNull()) { |
| 429 | if ( ! silent ) sout<<" unknown as imported"; |
| 430 | // skl 11.05.2004 |
| 431 | // if Shape is a compound try to make "fromshape" for its subshapes |
| 432 | if(Shape.ShapeType()==TopAbs_COMPOUND) { |
| 433 | sout<<endl<<"Subshapes imported from entities:"; |
| 434 | TopoDS_Iterator Iter(Shape); |
| 435 | for (; Iter.More(); Iter.Next()) { |
| 436 | TopoDS_Shape subsh = Iter.Value(); |
| 437 | Standard_Integer submodrec = 1; |
| 438 | Handle(Standard_Transient) subent = TR->EntityFromShapeResult(subsh,submodrec); |
| 439 | if (subent.IsNull()) { |
| 440 | submodrec = -1; |
| 441 | subent = TR->EntityFromShapeResult(subsh,submodrec); |
| 442 | } |
| 443 | if (!subent.IsNull()) { |
| 444 | sout<<" "<<XSControl::Session(pilot)->Model()->Number(subent); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | else { |
| 450 | sout<<"imported from entity "; |
| 451 | XSControl::Session(pilot)->Model()->Print(ent,sout); |
| 452 | if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile() << endl; |
| 453 | } |
| 454 | if ( ! silent ) sout<<endl; |
| 455 | } |
| 456 | |
| 457 | // ET EN EXPORT ? |
| 458 | Handle(Transfer_FinderProcess) FP = XSControl::Session(pilot)->MapWriter(); |
| 459 | if (FP.IsNull()) { } //sout<<"No write transfer (export) recorded"<<endl; |
| 460 | else { |
| 461 | yena = Standard_True; |
| 462 | Handle(Transfer_Finder) fnd = TransferBRep::ShapeMapper (FP,Shape); |
| 463 | Handle(Standard_Transient) ent; |
| 464 | if (!fnd.IsNull()) ent = FP->FindTransient (fnd); |
| 465 | if (!ent.IsNull()) { |
| 466 | sout<<"Shape "<<arg1<<": exported to entity "; |
| 467 | XSControl::Session(pilot)->Model()->Print(ent,sout); |
| 468 | if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile(); |
| 469 | sout<<endl; |
| 470 | } |
| 471 | // abv 31.08.00: treat case of splitted shape (several results) |
| 472 | // it is supposed that results are of the same type and lie in one-level comp |
| 473 | else { |
| 474 | Handle(Transfer_Binder) bnd = FP->Find ( fnd ); |
| 475 | if ( ! bnd.IsNull() ) { |
| 476 | Handle(Transfer_TransientListBinder) TransientListBinder = |
| 477 | //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) ); //skl |
| 478 | Handle(Transfer_TransientListBinder)::DownCast( bnd ); //skl |
| 479 | if (! TransientListBinder.IsNull() ) { |
| 480 | Standard_Integer i = 1, nb = TransientListBinder->NbTransients(); |
| 481 | if (nb > 0) sout<<"Shape "<<arg1<<": exported to entities "; |
| 482 | for (; i<=nb; i++) { |
| 483 | XSControl::Session(pilot)->Model()->Print( TransientListBinder->Transient(i), sout ); |
| 484 | if (i < nb) sout<<", "; |
| 485 | } |
| 486 | if (nb > 0) { |
| 487 | if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile(); |
| 488 | sout<<endl; |
| 489 | } |
| 490 | } |
| 491 | /* else { |
| 492 | TopoDS_Shape comp = TransferBRep::ShapeResult(bnd); |
| 493 | if ( ! comp.IsNull() && comp.ShapeType() < Shape.ShapeType() ) { |
| 494 | Standard_Boolean start = Standard_True; |
| 495 | for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) { |
| 496 | Handle(Transfer_Finder) cfnd = TransferBRep::ShapeMapper (FP,it.Value()); |
| 497 | if ( cfnd.IsNull() ) continue; |
| 498 | Handle(Standard_Transient) cent = FP->FindTransient (cfnd); |
| 499 | if ( cent.IsNull() ) continue; |
| 500 | if ( start ) |
| 501 | sout<<"Shape "<<arg1<<" : exported to entities "; |
| 502 | else sout << ", "; |
| 503 | start = Standard_False; |
| 504 | XSControl::Session(pilot)->Model()->Print(cent,sout); |
| 505 | } |
| 506 | if ( ! start ) sout<<endl; |
| 507 | } |
| 508 | } */ |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | if (!yena) sout<<"No transfer (either import or export) recorded"<<endl; |
| 513 | |
| 514 | return IFSelect_RetVoid; |
| 515 | } |
| 516 | |
| 517 | //======================================================================= |
| 518 | //function : XSControl_trconnexentities |
| 519 | //purpose : |
| 520 | //======================================================================= |
| 521 | static IFSelect_ReturnStatus XSControl_trconnexentities |
| 522 | (const Handle(IFSelect_SessionPilot)& pilot) |
| 523 | { |
| 524 | Standard_Integer argc = pilot->NbWords(); |
| 525 | const Standard_CString arg1 = pilot->Arg(1); |
| 526 | // **** connected entities (last transfer) **** |
| 527 | Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader(); |
| 528 | Handle(Transfer_TransientProcess) TP; |
| 529 | if (!TR.IsNull()) TP = TR->TransientProcess(); |
| 530 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 531 | if (TP.IsNull()) { sout<<"no transfer map"<<endl; return IFSelect_RetVoid; } |
| 532 | if (argc < 2) { |
| 533 | sout<<"Give name of a DRAW Shape + optional shape type v-e-w-f(D)-s"<<endl; |
| 534 | return IFSelect_RetError; |
| 535 | } |
| 536 | const char* a1 = (const char *)arg1; |
| 537 | TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(a1); |
| 538 | if (Shape.IsNull()) { sout<<"Not a DRAW Shape:"<<arg1<<endl; return IFSelect_RetError; } |
| 539 | sout<<"Shape "<<arg1<<" : "; |
| 540 | |
| 541 | Handle(TColStd_HSequenceOfTransient) list = |
| 542 | XSControl_ConnectedShapes::AdjacentEntities (Shape,TP,TopAbs_FACE); |
| 543 | Standard_Integer i, nb = list->Length(); |
| 544 | sout<<nb<<" Entities produced Connected Shapes :"<<endl; |
| 545 | Handle(Interface_InterfaceModel) model = XSControl::Session(pilot)->Model(); |
| 546 | sout<<"("; |
| 547 | for (i = 1; i <= nb; i ++) { |
| 548 | if (i > 1) sout<<","; |
| 549 | sout<<model->Number(list->Value(i)); |
| 550 | } |
| 551 | sout<<")"<<endl; |
| 552 | return IFSelect_RetDone; |
| 553 | } |
| 554 | |
| 555 | //======================================================================= |
| 556 | //function : XSControl_trimport |
| 557 | //purpose : |
| 558 | //======================================================================= |
| 559 | static IFSelect_ReturnStatus XSControl_trimport |
| 560 | (const Handle(IFSelect_SessionPilot)& pilot) |
| 561 | { |
| 562 | // FileName ou . (pour courant) VarName GiveList (obligatoire) |
| 563 | // GiveList : * pour xst-transferrable-roots |
| 564 | Handle(XSControl_WorkSession) WS = XSControl::Session(pilot); |
| 565 | |
| 566 | Standard_Integer argc = pilot->NbWords(); |
| 567 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 568 | if (argc < 4) { |
| 569 | sout<<"Give : filename or . for current model; varname or . to take fileroot\n GiveList, * for all transferrable roots"<<endl; |
| 570 | return IFSelect_RetError; |
| 571 | } |
| 572 | const Standard_CString arg1 = pilot->Arg(1); |
| 573 | const Standard_CString arg2 = pilot->Arg(2); |
| 574 | const Standard_CString arg3 = pilot->Arg(3); |
| 575 | |
| 576 | // File Name and Variable (root) Name |
| 577 | |
| 578 | TCollection_AsciiString fnom,rnom; |
| 579 | Standard_Boolean modfic = XSControl_FuncShape::FileAndVar |
| 580 | (WS,arg1,arg2,"IMPORT",fnom,rnom); |
| 581 | if (modfic) sout<<" File to read : "<<fnom<<endl; |
| 582 | else sout<<" Model taken from the session : "<<fnom<<endl; |
| 583 | sout<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<endl; |
| 584 | |
| 585 | // keep the current command, because sub-commands will be called |
| 586 | TCollection_AsciiString compart = pilot->CommandPart (3); |
| 587 | |
| 588 | // Reading file if required |
| 589 | |
| 590 | if (modfic) { |
| 591 | TCollection_AsciiString comload ("xload "); |
| 592 | comload.AssignCat(arg1); |
| 593 | IFSelect_ReturnStatus status = pilot->Execute(comload); |
| 594 | if (status != IFSelect_RetDone) |
| 595 | { sout<<"Abandon import"<<endl; return status; } |
| 596 | } else { |
| 597 | sout<<"Currently Loaded Model"<<endl; |
| 598 | } |
| 599 | |
| 600 | // Selecting Entities |
| 601 | |
| 602 | Handle(TColStd_HSequenceOfTransient) list; |
| 603 | if (arg3[0] == '*' && arg3[1] == '\0') { |
| 604 | list = WS->GiveList ("xst-transferrable-roots"); |
| 605 | sout<<"All Transferrable Roots : "; |
| 606 | } else { |
| 607 | sout<<"List given by "<<compart.ToCString()<<" : "; |
| 608 | list = WS->GiveList (compart.ToCString()); |
| 609 | } |
| 610 | if (list.IsNull()) { sout<<"No list defined. Abandon"<<endl; return IFSelect_RetError; } |
| 611 | Standard_Integer nbl = list->Length(); |
| 612 | sout<<"Nb entities selected : "<<nbl<<endl; |
| 613 | |
| 614 | // Starting Transfer |
| 615 | |
| 616 | WS->InitTransferReader (0); |
| 617 | Handle(XSControl_TransferReader) TR = WS->TransferReader(); |
| 618 | if (TR.IsNull()) { sout<<" init not done or failed"<<endl; return IFSelect_RetError; } |
| 619 | |
| 620 | TR->BeginTransfer(); |
| 621 | |
| 622 | // Transferring |
| 623 | Standard_Integer nbt = TR->TransferList(list); |
| 624 | sout<<"Nb Entities Selected : "<<nbl<<" have given "<<nbt<<" results"<<endl; |
| 625 | |
| 626 | // Filling VARS. one compound (trimpcomp) or one shape per ent (trimport) |
| 627 | Standard_Boolean iscomp = (pilot->Arg(0)[5] == 'c'); |
| 628 | Standard_Integer nbs = 0; |
| 629 | TopoDS_Shape sh; |
| 630 | TopoDS_Compound C; |
| 631 | BRep_Builder B; |
| 632 | B.MakeCompound (C); |
| 633 | Handle(Interface_InterfaceModel) mdl = TR->Model(); |
| 634 | if (mdl.IsNull()) { sout<<" modele absent"<<endl; return IFSelect_RetError; } |
| 635 | for (Standard_Integer il= 1; il <= nbl; il ++) { |
| 636 | Handle(Standard_Transient) ent = list->Value(il); |
| 637 | sh = TR->ShapeResult(ent); |
| 638 | if (sh.IsNull()) continue; |
| 639 | nbs ++; |
| 640 | if (iscomp) B.Add (C,sh); |
| 641 | else { |
| 642 | char nomsh[50]; |
| 643 | sprintf (nomsh,"%s_%d",rnom.ToCString(),nbs); |
| 644 | XSControl::Vars(pilot)->SetShape(nomsh,sh); |
| 645 | } |
| 646 | } |
| 647 | if (nbs == 0) sout<<"No Shape produced"<<endl; |
| 648 | else if (nbs == 1) { |
| 649 | sout<<"One Shape produced, named "<<rnom.ToCString()<<endl; |
| 650 | XSControl::Vars(pilot)->SetShape(rnom.ToCString(),sh); |
| 651 | } else if (iscomp) { |
| 652 | sout<<"One compound made of "<<nbs<<" Shapes, named "<<rnom.ToCString()<<endl; |
| 653 | XSControl::Vars(pilot)->SetShape(rnom.ToCString(),C); |
| 654 | } else { // several individual shapes |
| 655 | sout<<nbs<<" Shapes, named "<<rnom.ToCString()<<"_1 to "<<rnom.ToCString()<<"_"<<nbs<<endl; |
| 656 | } |
| 657 | |
| 658 | return IFSelect_RetDone; |
| 659 | } |
| 660 | |
| 661 | //======================================================================= |
| 662 | //function : XSControl_twrite |
| 663 | //purpose : |
| 664 | //======================================================================= |
| 665 | static IFSelect_ReturnStatus XSControl_twrite |
| 666 | (const Handle(IFSelect_SessionPilot)& pilot) |
| 667 | { |
| 668 | Standard_Integer argc = pilot->NbWords(); |
| 669 | const Standard_CString arg1 = pilot->Arg(1); |
| 670 | // **** twrite **** |
| 671 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 672 | Handle(XSControl_TransferWriter) TW = XSControl::Session(pilot)->TransferWriter(); |
| 673 | if (argc < 2) { sout<<" donner nom de shape draw"<<endl; return IFSelect_RetError; } |
| 674 | sout<<"Attention, on alimente le modele courant ..."<<endl; |
| 675 | |
| 676 | // Shape |
| 677 | for (Standard_Integer i = 1; i < argc; i ++) { |
| 678 | const char* ai = (const char *)pilot->Arg(i); |
| 679 | TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(ai); |
| 680 | if (Shape.IsNull()) { sout<<"pas un nom de shape draw:"<<arg1<<endl; continue; } |
| 681 | sout<<"Pour Shape : "<<ai; |
| 682 | Standard_Integer stat = TW->TransferWriteShape (XSControl::Session(pilot)->Model(),Shape); |
| 683 | sout<<" Transfer Write Status = "<<stat<<endl; |
| 684 | } |
| 685 | pilot->Session()->ComputeGraph(); |
| 686 | // Transient ? (Geom) : ignore |
| 687 | return IFSelect_RetDone; |
| 688 | } |
| 689 | |
| 690 | // ###################################################################### |
| 691 | // #### TIMERS #### |
| 692 | // ###################################################################### |
| 693 | |
| 694 | |
| 695 | // ###################################################################### |
| 696 | // #### #### |
| 697 | // #### Initialising Commands #### |
| 698 | // #### #### |
| 699 | // ###################################################################### |
| 700 | |
| 701 | static int initactor = 0; |
| 702 | |
| 703 | |
| 704 | //======================================================================= |
| 705 | //function : Init |
| 706 | //purpose : |
| 707 | //======================================================================= |
| 708 | |
| 709 | void XSControl_FuncShape::Init () |
| 710 | { |
| 711 | if (initactor) return; initactor = 1; |
| 712 | |
| 713 | IFSelect_Act::SetGroup("DE: General"); |
| 714 | |
| 715 | IFSelect_Act::AddFunc ("tpdraw","[mode:item or root] num|* [nomvar] Passes an ITEM to Shape Draw (Start or Result)",XSControl_tpdraw); |
| 716 | |
| 717 | IFSelect_Act::AddFunc ("tpcompound","name:cstring [givelist] : -> compound with Shapes Root or from givelist",XSControl_tpcompound); |
| 718 | |
| 719 | IFSelect_Act::AddFunc ("trdraw","results ->DRAW : all; or num [name] : from ent.num -> DRAW [name/tread_num]",XSControl_traccess); |
| 720 | IFSelect_Act::AddFunc ("trsave","results ->files : all; or num [name] : from ent.num -> DRAW [name/tread_num]",XSControl_traccess); |
| 721 | IFSelect_Act::AddFunc ("trcomp","results -> 1 compound -> DRAW + name optional",XSControl_traccess); |
| 722 | IFSelect_Act::AddFunc ("trscomp","results -> 1 compound -> file + name optional",XSControl_traccess); |
| 723 | |
| 724 | IFSelect_Act::AddFunc ("fromshape","shape [level=1]: imported/exported entity (when known)",XSControl_fromshape); |
| 725 | IFSelect_Act::AddFunc ("trconnexent","name of draw shape : entities -> connected shapes (when known)",XSControl_trconnexentities); |
| 726 | |
| 727 | IFSelect_Act::AddFunc ("trimport","filename or . varname givelist -> 1 shape per entity",XSControl_trimport); |
| 728 | IFSelect_Act::AddFunc ("trimpcomp","filename or . varname givelist -> one xcompound",XSControl_trimport); |
| 729 | |
| 730 | IFSelect_Act::AddFunc ("twrite","shape : transfer write for this shape, AFTER newmodel !",XSControl_twrite); |
| 731 | |
| 732 | //skl IFSelect_Act::AddFunc ("checkbrep","shapename or * [+ rootname for expurged and faulties [+ mode f-s]]",XSHAPE_checkbrep); |
| 733 | //skl IFSelect_Act::AddFunc ("dblist","option : clear nb index set n1 data n1 n2",XSHAPE_dblist); |
| 734 | } |
| 735 | |
| 736 | // ###################################################################### |
| 737 | // #### #### |
| 738 | // #### Additional Methods #### |
| 739 | // #### #### |
| 740 | // ###################################################################### |
| 741 | |
| 742 | |
| 743 | //======================================================================= |
| 744 | //function : MoreShapes |
| 745 | //purpose : |
| 746 | //======================================================================= |
| 747 | |
| 748 | Standard_Integer XSControl_FuncShape::MoreShapes |
| 749 | (const Handle(XSControl_WorkSession)& session, |
| 750 | Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name) |
| 751 | { |
| 752 | // name = un nom -> Draw |
| 753 | // name = "*" -> tous les transferts RACINES du TP |
| 754 | // name = "**" -> tous les transferts du TP : VRAIMENT TOUS |
| 755 | // name = "." -> reperage graphique (not yet impl) |
| 756 | // name = nom(n1-n2) avec n1,n2 entiers : les variables de nom nomn1 a nomn2 |
| 757 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
| 758 | if (list.IsNull()) list = new TopTools_HSequenceOfShape(); |
| 759 | if (name[0] == '*' && (name[1] == '\0' || (name[1] == '*' && name[2] == '\0'))) { |
| 760 | Handle(Transfer_TransientProcess) TP = session->TransferReader()->TransientProcess(); |
| 761 | if (TP.IsNull()) { sout<<"last transfer : unknown"<<endl;return 0; } |
| 762 | Handle(TopTools_HSequenceOfShape) li = TransferBRep::Shapes(TP,(name[1] == '\0')); |
| 763 | if (li.IsNull()) return 0; |
| 764 | list->Append (li); |
| 765 | return li->Length(); |
| 766 | } |
| 767 | Standard_Integer i, paro = 0, parf = 0, moins = 0, n1 = 0, n2 = 0; |
| 768 | for (i = 0; name[i] != '\0'; i ++) { |
| 769 | if (name[i] == '(') paro = i; |
| 770 | if (name[i] == '-') moins = i; |
| 771 | if (name[i] == ')') parf = i; |
| 772 | } |
| 773 | if (paro && moins && parf) { |
| 774 | n2 = atoi (&name[moins+1]); |
| 775 | n1 = atoi (&name[paro +1]); if (n1 < 0) n1 += n2; // sinon on a n1-n2 |
| 776 | } |
| 777 | // liste |
| 778 | if (n1 <= n2 && n1 > 0) { |
| 779 | char nom[50], nomsh[60]; Standard_Integer nbsh = 0; |
| 780 | for (i = 0; i < paro; i ++) nom[i]=name[i]; nom[paro] = '\0'; |
| 781 | sout<<"Shapes DRAW named : "<<nom<<n1<<" to "<<nom<<n2; |
| 782 | for (i = n1; i <= n2 ; i ++) { |
| 783 | const char* nomshh = &nomsh[0]; |
| 784 | sprintf (nomsh,"%s%d",nom,i); |
| 785 | TopoDS_Shape Shape = session->Vars()->GetShape(nomshh); |
| 786 | if (Shape.IsNull()) continue; |
| 787 | list->Append(Shape); |
| 788 | nbsh ++; |
| 789 | } |
| 790 | sout<<" -> taken "<<nbsh<<" Shapes"<<endl; |
| 791 | return nbsh; |
| 792 | } |
| 793 | const char* a1 = (const char *)name; |
| 794 | TopoDS_Shape Shape = session->Vars()->GetShape(a1); |
| 795 | if (Shape.IsNull()) { sout<<"not a shape draw:"<<a1<<endl; return 0; } |
| 796 | list->Append(Shape); |
| 797 | return 1; |
| 798 | } |
| 799 | |
| 800 | |
| 801 | //======================================================================= |
| 802 | //function : FileAndVar |
| 803 | //purpose : |
| 804 | //======================================================================= |
| 805 | |
| 806 | Standard_Boolean XSControl_FuncShape::FileAndVar |
| 807 | (const Handle(XSControl_WorkSession)& session, |
| 808 | const Standard_CString file, const Standard_CString var, |
| 809 | const Standard_CString def, |
| 810 | TCollection_AsciiString& resfile, TCollection_AsciiString& resvar) |
| 811 | { |
| 812 | Standard_Boolean iafic = Standard_True; |
| 813 | resfile.Clear(); resvar.Clear(); |
| 814 | if (file) |
| 815 | if ( file[0] == '\0' || |
| 816 | (file[0] == '.' && file[1] == '\0')) iafic = Standard_False; |
| 817 | if (!iafic) resfile.AssignCat (session->LoadedFile()); |
| 818 | else resfile.AssignCat (file); |
| 819 | |
| 820 | if (var && var[0] != '\0' && (var[0] != '.' || var[1] != '\0') ) |
| 821 | resvar.AssignCat (var); |
| 822 | else if (resfile.Length() == 0) resvar.AssignCat (def); |
| 823 | else { |
| 824 | Standard_Integer nomdeb, nomfin; |
| 825 | nomdeb = resfile.SearchFromEnd ("/"); |
| 826 | if (nomdeb <= 0) nomdeb = resfile.SearchFromEnd("\\"); // pour NT |
| 827 | if (nomdeb < 0) nomdeb = 0; |
| 828 | nomfin = resfile.SearchFromEnd ("."); |
| 829 | if (nomfin < nomdeb) nomfin = resfile.Length() + 1; |
| 830 | resvar = resfile.SubString(nomdeb+1,nomfin-1); |
| 831 | } |
| 832 | return iafic; |
| 833 | } |