// Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include // ###################################################################### // #### #### // #### COMMANDS #### // #### #### // ###################################################################### //======================================================================= //function : XSControl_tpdraw //purpose : //======================================================================= static IFSelect_ReturnStatus XSControl_tpdraw (const Handle(IFSelect_SessionPilot)& pilot) { Standard_Integer argc = pilot->NbWords(); const Standard_CString arg1 = pilot->Arg(1); const Standard_CString arg2 = pilot->Arg(2); const Standard_CString arg3 = pilot->Arg(3); Handle(Transfer_TransientProcess) TP = XSControl::Session(pilot)->TransferReader()->TransientProcess(); Handle(Message_Messenger) sout = Message::DefaultMessenger(); if (TP.IsNull()) { sout<<"No Transfer Read"<Word(0).Value(3) == 'r'); Standard_Integer n1, n2, i, max=0, index=0; Handle(Interface_InterfaceModel) model = TP->Model(); if (model.IsNull()) { if (mode == 0) { sout<<"Pas de modele, preciser n0 d item de transfert"<NbEntities(); } if (mode == 1) { sout<<"Item de transfert"; max = TP->NbMapped(); } if (mode == 2) { sout<<"Racine de transfert"; max = TP->NbRoots(); } if (tout) { n1 = 1; n2 = max; sout<<", listage de 1 a "< max) { sout<<" - Num="<Value(i); num = i; index = TP->MapIndex(ent); } else if (mode == 1) { ent = TP->Mapped(i); if (model.IsNull()) num = 0; else num = model->Number(ent); index = i; } else if (mode == 2) { ent = TP->Root(i); if (model.IsNull()) num = 0; else num = model->Number(ent); index = TP->MapIndex(ent); } if (index > 0) binder = TP->MapItem (index); if (binder.IsNull()) index = 0; if (index == 0) { if (!tout) sout<<"Entite n0 "<HasResult()) { if (!tout) sout<<"Entite n0 "<Result(); nbvar ++; if (sh.IsNull()) { sout<<" (no Shape recorded)"< 3 && mode > 0) sprintf (nomvar,"%s",arg3); else if (argc > 2 && mode == 0) sprintf (nomvar,"%s",arg2); else sprintf (nomvar,"tp_%d",i); } else { if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar); else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar); else sprintf (nomvar,"tp_%d",i); } sout<<" -> 1 DRAW Shape: "<SetShape(nomvar,sh); continue; } DeclareAndCast(TransferBRep_ShapeListBinder,slb,binder); if (!slb.IsNull()) { Standard_Integer nbs = slb->NbShapes(); if (tout) sout<<"[ "< "<Shape(j); if (nbvar < 0) nbvar = 0; nbvar ++; if (sh.IsNull()) { sout<<" (no Shape recorded)"< 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar); else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar); else sprintf (nomvar,"tp_%d_%d",i,nbvar); sout<<" "<SetShape(nomvar,sh); } sout<Result(); if (resu.IsNull()) { sout<<"Entite n0 "<DynamicType()->Name(); if (geom.IsNull()) { sout< 3 && mode > 0) sprintf (nomvar,"%s",arg3); else if (argc > 2 && mode == 0) sprintf (nomvar,"%s",arg2); else sprintf (nomvar,"tp_%d",i); } else { if (argc > 3 && mode > 0) sprintf (nomvar,"%s_%d",arg3,nbvar); else if (argc > 2 && mode == 0) sprintf (nomvar,"%s_%d",arg2,nbvar); else sprintf (nomvar,"tp_%d",i); } char* nomv = nomvar; XSControl::Vars(pilot)->Set (nomv,geom); sout<<" -> DRAW Geom : "<ResultTypeName()<NbWords(); const Standard_CString arg1 = pilot->Arg(1); Handle(Transfer_TransientProcess) TP = XSControl::Session(pilot)->TransferReader()->TransientProcess(); Handle(Message_Messenger) sout = Message::DefaultMessenger(); if (TP.IsNull()) { sout<<"No Transfer Read"<Session(),pilot->CommandPart(2)); if (lise.IsNull()) { sout<<"Not a valid entity list : "<CommandPart(2)<Length()<<" Entities, "; } if (list.IsNull()) { sout<<"No Shape listed"<Length(); sout<Value(i)); XSControl::Vars(pilot)->SetShape (arg1,C); return IFSelect_RetDone; } //======================================================================= //function : XSControl_traccess //purpose : //======================================================================= static IFSelect_ReturnStatus XSControl_traccess (const Handle(IFSelect_SessionPilot)& pilot) { Standard_Integer argc = pilot->NbWords(); const Standard_CString arg1 = pilot->Arg(1); const Standard_CString arg2 = pilot->Arg(2); // **** trdraw : TransferReader **** 26 // **** trsave : TransferReader **** 27 // **** trcomp (comp -> DRAW) **** 28 // **** trscomp (comp -> save) **** 29 Standard_Boolean cascomp = (pilot->Word(0).Location(1,'o',1,5) > 0); Standard_Boolean cassave = (pilot->Word(0).Location(1,'s',1,5) > 0); char nomsh[100], noms[100]; Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader(); Handle(Message_Messenger) sout = Message::DefaultMessenger(); if (TR.IsNull()) { sout<<" manque init"<Model(); if (mdl.IsNull()) { sout<<" modele absent"< 1 ? IFSelect_Functions::GiveEntityNumber(XSControl::Session(pilot),arg1) : 0); if (argc > 1) strcpy (nomsh,arg1); else strcpy (nomsh,(cascomp ? "TREAD_COMP" : "TREAD_LIST")); if (cassave) sout<<" save shapes -> current directory"<ShapeResultList(Standard_True); Standard_Integer i, nb = list->Length(); sout<<" TOUS RESULTATS par ShapeResultList, soit "<Value(i).IsNull()) continue; if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape(noms,list->Value(i)); else if (!cascomp && cassave) BRepTools::Write (list->Value(i),noms); else if (cascomp) B.Add (C,list->Value(i)); } sout<SetShape(nomsh,C); else if (cascomp && cassave) BRepTools::Write (C,nomsh); } else { if (num < 1 || num > mdl->NbEntities()) { sout<<" incorrect:"<ShapeResult(mdl->Value(num)); if (sh.IsNull()) { sout<<" Pas de resultat pour "< 2) sprintf (nomsh,"%s",arg2); else sprintf (nomsh,"TREAD_%d",num); if (!cascomp && !cassave) XSControl::Vars(pilot)->SetShape(nomsh,sh); else if (!cascomp && cassave) BRepTools::Write (sh,nomsh); else sout<<"Option non comprise"< 0) { TopoDS_Shape varShape; aLevel--; TopoDS_Iterator it(sh); for (; it.More(); it.Next() ) { varShape = it.Value(); if ( XSControl_IsEqualSubShape(Shape, varShape, aLevel) ) return Standard_True; } } return Standard_False; } //======================================================================= //function : XSControl_fromshape //purpose : //======================================================================= static IFSelect_ReturnStatus XSControl_fromshape (const Handle(IFSelect_SessionPilot)& pilot) { Standard_Integer argc = pilot->NbWords(); const Standard_CString arg1 = pilot->Arg(1); // **** fromshape (tread) **** Handle(Message_Messenger) sout = Message::DefaultMessenger(); if (argc < 2) { sout<<"Give name of a DRAW Shape"<GetShape(a1); if (Shape.IsNull()) { sout<<"Not a DRAW Shape:"<=3 ) aLevel = atoi(pilot->Arg(2)); Standard_Boolean silent = Standard_False; if (aLevel <0 ) { silent = Standard_True; aLevel = -aLevel; } // IMPORT Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader(); if (TR.IsNull()) { } // sout<<"No read transfer (import) recorded"<EntityFromShapeResult (Shape,modrec); if (ent.IsNull()) { modrec = -1; ent = TR->EntityFromShapeResult (Shape,modrec); } if (ent.IsNull()) { modrec = 2; Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); if (TP.IsNull()) { if ( silent ) sout << "Shape "<NbMapped(); if ( ! silent ) sout<<"searching in map among "<Mapped(i); TopoDS_Shape sh = TransferBRep::ShapeResult(TP,ent); if (sh.IsNull()) { ent.Nullify(); continue; } if (XSControl_IsEqualSubShape(Shape, sh, aLevel)) break; modrec = -2; sh.Location ( L ); if (XSControl_IsEqualSubShape(S0, sh, aLevel)) break; ent.Nullify(); modrec = 2; } } } if ( ! ent.IsNull() ) { if ( silent ) sout << "Shape " << arg1 << ": "; if (modrec <0) sout<<"(moved from origin) "; //else sout<<"(origin) "; } // on affiche if (ent.IsNull()) { if ( ! silent ) sout<<" unknown as imported"; // skl 11.05.2004 // if Shape is a compound try to make "fromshape" for its subshapes if(Shape.ShapeType()==TopAbs_COMPOUND) { sout<EntityFromShapeResult(subsh,submodrec); if (subent.IsNull()) { submodrec = -1; subent = TR->EntityFromShapeResult(subsh,submodrec); } if (!subent.IsNull()) { sout<<" "<Model()->Number(subent); } } } } else { sout<<"imported from entity "; XSControl::Session(pilot)->Model()->Print(ent,sout); if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile() << endl; } if ( ! silent ) sout<MapWriter(); if (FP.IsNull()) { } //sout<<"No write transfer (export) recorded"<FindTransient (fnd); if (!ent.IsNull()) { sout<<"Shape "<Model()->Print(ent,sout); if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile(); sout<Find ( fnd ); if ( ! bnd.IsNull() ) { Handle(Transfer_TransientListBinder) TransientListBinder = //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) ); //skl Handle(Transfer_TransientListBinder)::DownCast( bnd ); //skl if (! TransientListBinder.IsNull() ) { Standard_Integer i = 1, nb = TransientListBinder->NbTransients(); if (nb > 0) sout<<"Shape "<Model()->Print( TransientListBinder->Transient(i), sout ); if (i < nb) sout<<", "; } if (nb > 0) { if ( silent ) sout << " in file " << XSControl::Session(pilot)->LoadedFile(); sout<FindTransient (cfnd); if ( cent.IsNull() ) continue; if ( start ) sout<<"Shape "<Model()->Print(cent,sout); } if ( ! start ) sout<NbWords(); const Standard_CString arg1 = pilot->Arg(1); // **** connected entities (last transfer) **** Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader(); Handle(Transfer_TransientProcess) TP; if (!TR.IsNull()) TP = TR->TransientProcess(); Handle(Message_Messenger) sout = Message::DefaultMessenger(); if (TP.IsNull()) { sout<<"no transfer map"<GetShape(a1); if (Shape.IsNull()) { sout<<"Not a DRAW Shape:"<Length(); sout<Model(); sout<<"("; for (i = 1; i <= nb; i ++) { if (i > 1) sout<<","; sout<Number(list->Value(i)); } sout<<")"<NbWords(); Handle(Message_Messenger) sout = Message::DefaultMessenger(); if (argc < 4) { sout<<"Give : filename or . for current model; varname or . to take fileroot\n GiveList, * for all transferrable roots"<Arg(1); const Standard_CString arg2 = pilot->Arg(2); const Standard_CString arg3 = pilot->Arg(3); // File Name and Variable (root) Name TCollection_AsciiString fnom,rnom; Standard_Boolean modfic = XSControl_FuncShape::FileAndVar (WS,arg1,arg2,"IMPORT",fnom,rnom); if (modfic) sout<<" File to read : "<CommandPart (3); // Reading file if required if (modfic) { TCollection_AsciiString comload ("xload "); comload.AssignCat(arg1); IFSelect_ReturnStatus status = pilot->Execute(comload); if (status != IFSelect_RetDone) { sout<<"Abandon import"<GiveList ("xst-transferrable-roots"); sout<<"All Transferrable Roots : "; } else { sout<<"List given by "<GiveList (compart.ToCString()); } if (list.IsNull()) { sout<<"No list defined. Abandon"<Length(); sout<<"Nb entities selected : "<InitTransferReader (0); Handle(XSControl_TransferReader) TR = WS->TransferReader(); if (TR.IsNull()) { sout<<" init not done or failed"<BeginTransfer(); // Transferring Standard_Integer nbt = TR->TransferList(list); sout<<"Nb Entities Selected : "<Arg(0)[5] == 'c'); Standard_Integer nbs = 0; TopoDS_Shape sh; TopoDS_Compound C; BRep_Builder B; B.MakeCompound (C); Handle(Interface_InterfaceModel) mdl = TR->Model(); if (mdl.IsNull()) { sout<<" modele absent"<Value(il); sh = TR->ShapeResult(ent); if (sh.IsNull()) continue; nbs ++; if (iscomp) B.Add (C,sh); else { char nomsh[50]; sprintf (nomsh,"%s_%d",rnom.ToCString(),nbs); XSControl::Vars(pilot)->SetShape(nomsh,sh); } } if (nbs == 0) sout<<"No Shape produced"<SetShape(rnom.ToCString(),sh); } else if (iscomp) { sout<<"One compound made of "<SetShape(rnom.ToCString(),C); } else { // several individual shapes sout<NbWords(); const Standard_CString arg1 = pilot->Arg(1); // **** twrite **** Handle(Message_Messenger) sout = Message::DefaultMessenger(); Handle(XSControl_TransferWriter) TW = XSControl::Session(pilot)->TransferWriter(); if (argc < 2) { sout<<" donner nom de shape draw"<Arg(i); TopoDS_Shape Shape = XSControl::Vars(pilot)->GetShape(ai); if (Shape.IsNull()) { sout<<"pas un nom de shape draw:"<TransferWriteShape (XSControl::Session(pilot)->Model(),Shape); sout<<" Transfer Write Status = "<Session()->ComputeGraph(); // Transient ? (Geom) : ignore return IFSelect_RetDone; } // ###################################################################### // #### TIMERS #### // ###################################################################### // ###################################################################### // #### #### // #### Initialising Commands #### // #### #### // ###################################################################### static int initactor = 0; //======================================================================= //function : Init //purpose : //======================================================================= void XSControl_FuncShape::Init () { if (initactor) return; initactor = 1; IFSelect_Act::SetGroup("DE: General"); IFSelect_Act::AddFunc ("tpdraw","[mode:item or root] num|* [nomvar] Passes an ITEM to Shape Draw (Start or Result)",XSControl_tpdraw); IFSelect_Act::AddFunc ("tpcompound","name:cstring [givelist] : -> compound with Shapes Root or from givelist",XSControl_tpcompound); IFSelect_Act::AddFunc ("trdraw","results ->DRAW : all; or num [name] : from ent.num -> DRAW [name/tread_num]",XSControl_traccess); IFSelect_Act::AddFunc ("trsave","results ->files : all; or num [name] : from ent.num -> DRAW [name/tread_num]",XSControl_traccess); IFSelect_Act::AddFunc ("trcomp","results -> 1 compound -> DRAW + name optional",XSControl_traccess); IFSelect_Act::AddFunc ("trscomp","results -> 1 compound -> file + name optional",XSControl_traccess); IFSelect_Act::AddFunc ("fromshape","shape [level=1]: imported/exported entity (when known)",XSControl_fromshape); IFSelect_Act::AddFunc ("trconnexent","name of draw shape : entities -> connected shapes (when known)",XSControl_trconnexentities); IFSelect_Act::AddFunc ("trimport","filename or . varname givelist -> 1 shape per entity",XSControl_trimport); IFSelect_Act::AddFunc ("trimpcomp","filename or . varname givelist -> one xcompound",XSControl_trimport); IFSelect_Act::AddFunc ("twrite","shape : transfer write for this shape, AFTER newmodel !",XSControl_twrite); //skl IFSelect_Act::AddFunc ("checkbrep","shapename or * [+ rootname for expurged and faulties [+ mode f-s]]",XSHAPE_checkbrep); //skl IFSelect_Act::AddFunc ("dblist","option : clear nb index set n1 data n1 n2",XSHAPE_dblist); } // ###################################################################### // #### #### // #### Additional Methods #### // #### #### // ###################################################################### //======================================================================= //function : MoreShapes //purpose : //======================================================================= Standard_Integer XSControl_FuncShape::MoreShapes (const Handle(XSControl_WorkSession)& session, Handle(TopTools_HSequenceOfShape)& list, const Standard_CString name) { // name = un nom -> Draw // name = "*" -> tous les transferts RACINES du TP // name = "**" -> tous les transferts du TP : VRAIMENT TOUS // name = "." -> reperage graphique (not yet impl) // name = nom(n1-n2) avec n1,n2 entiers : les variables de nom nomn1 a nomn2 Handle(Message_Messenger) sout = Message::DefaultMessenger(); if (list.IsNull()) list = new TopTools_HSequenceOfShape(); if (name[0] == '*' && (name[1] == '\0' || (name[1] == '*' && name[2] == '\0'))) { Handle(Transfer_TransientProcess) TP = session->TransferReader()->TransientProcess(); if (TP.IsNull()) { sout<<"last transfer : unknown"<Append (li); return li->Length(); } Standard_Integer i, paro = 0, parf = 0, moins = 0, n1 = 0, n2 = 0; for (i = 0; name[i] != '\0'; i ++) { if (name[i] == '(') paro = i; if (name[i] == '-') moins = i; if (name[i] == ')') parf = i; } if (paro && moins && parf) { n2 = atoi (&name[moins+1]); n1 = atoi (&name[paro +1]); if (n1 < 0) n1 += n2; // sinon on a n1-n2 } // liste if (n1 <= n2 && n1 > 0) { char nom[50], nomsh[60]; Standard_Integer nbsh = 0; for (i = 0; i < paro; i ++) nom[i]=name[i]; nom[paro] = '\0'; sout<<"Shapes DRAW named : "<Vars()->GetShape(nomshh); if (Shape.IsNull()) continue; list->Append(Shape); nbsh ++; } sout<<" -> taken "<Vars()->GetShape(a1); if (Shape.IsNull()) { sout<<"not a shape draw:"<Append(Shape); return 1; } //======================================================================= //function : FileAndVar //purpose : //======================================================================= Standard_Boolean XSControl_FuncShape::FileAndVar (const Handle(XSControl_WorkSession)& session, const Standard_CString file, const Standard_CString var, const Standard_CString def, TCollection_AsciiString& resfile, TCollection_AsciiString& resvar) { Standard_Boolean iafic = Standard_True; resfile.Clear(); resvar.Clear(); if (file) if ( file[0] == '\0' || (file[0] == '.' && file[1] == '\0')) iafic = Standard_False; if (!iafic) resfile.AssignCat (session->LoadedFile()); else resfile.AssignCat (file); if (var && var[0] != '\0' && (var[0] != '.' || var[1] != '\0') ) resvar.AssignCat (var); else if (resfile.Length() == 0) resvar.AssignCat (def); else { Standard_Integer nomdeb, nomfin; nomdeb = resfile.SearchFromEnd ("/"); if (nomdeb <= 0) nomdeb = resfile.SearchFromEnd("\\"); // pour NT if (nomdeb < 0) nomdeb = 0; nomfin = resfile.SearchFromEnd ("."); if (nomfin < nomdeb) nomfin = resfile.Length() + 1; resvar = resfile.SubString(nomdeb+1,nomfin-1); } return iafic; }