// 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 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SessionPilot,IFSelect_Activator) #define MAXWORDS 200 #define MAXCARS 1000 static int THE_IFSelect_SessionPilot_initactor = 0; static TCollection_AsciiString nulword; //#define DEBUG_TRACE // Nb Maxi de words : cf thewords et method SetCommandLine IFSelect_SessionPilot::IFSelect_SessionPilot (const Standard_CString prompt) : theprompt (prompt), thewords (0, MAXWORDS - 1), thewordeb (0, MAXWORDS - 1) { if (theprompt.Length() == 0) { theprompt.AssignCat ("Test-XSTEP>"); } therecord = Standard_False; thenbwords = 0; if (THE_IFSelect_SessionPilot_initactor) { return; } THE_IFSelect_SessionPilot_initactor = 1; Add (1,"x"); Add (1,"exit"); Add (2,"?"); Add (2,"xhelp"); Add (3,"xcommand"); Add (4,"xsource"); Add (5,"xstep"); Add (6,"xnew"); } Handle(IFSelect_WorkSession) IFSelect_SessionPilot::Session () const { return thesession; } Handle(IFSelect_WorkLibrary) IFSelect_SessionPilot::Library () const { return thesession->WorkLibrary(); } Standard_Boolean IFSelect_SessionPilot::RecordMode () const { return therecord; } void IFSelect_SessionPilot::SetSession (const Handle(IFSelect_WorkSession)& WS) { thesession = WS; } void IFSelect_SessionPilot::SetLibrary (const Handle(IFSelect_WorkLibrary)& WL) { if (!thesession.IsNull()) thesession->SetLibrary(WL); } void IFSelect_SessionPilot::SetRecordMode (const Standard_Boolean mode) { therecord = mode; } void IFSelect_SessionPilot::SetCommandLine (const TCollection_AsciiString& command) { Standard_Integer lc = command.Length(); if (lc > 200) std::cout<<" Commande TRES LONGUE : "<= MAXWORDS) { unarg[nc] = val; nc ++; continue; } unarg[nc] = '\0'; thewords(thenbwords).Clear(); thewords(thenbwords).AssignCat(unarg); #ifdef DEBUG_TRACE std::cout<<"thewords("< MAXCARS) { std::cout<<"Arg."< "< 0) { unarg[nc] = '\0'; thewords(thenbwords).Clear(); thewords(thenbwords).AssignCat(unarg); #ifdef DEBUG_TRACE std::cout<<"thewords("< MAXWORDS) thenbwords = MAXWORDS; Standard_Integer nb = thewords.Upper(); for (i = 0; i <= nb; i ++) thewords(i).Clear(); switch (thenbwords) { case 20 : thewords(19).AssignCat(m9); case 19 : thewords(18).AssignCat(m8); case 18 : thewords(17).AssignCat(m7); case 17 : thewords(16).AssignCat(m6); case 16 : thewords(15).AssignCat(m5); case 15 : thewords(14).AssignCat(m4); case 14 : thewords(13).AssignCat(m3); case 13 : thewords(12).AssignCat(m2); case 12 : thewords(11).AssignCat(m1); case 11 : thewords(10).AssignCat(m0); case 10 : thewords(9).AssignCat(l9); case 9 : thewords(8).AssignCat(l8); case 8 : thewords(7).AssignCat(l7); case 7 : thewords(6).AssignCat(l6); case 6 : thewords(5).AssignCat(l5); case 5 : thewords(4).AssignCat(l4); case 4 : thewords(3).AssignCat(l3); case 3 : thewords(2).AssignCat(l2); case 2 : thewords(1).AssignCat(l1); case 1 : thewords(0).AssignCat(l0); default : break; } */ thenumrec = 0; theobjrec.Nullify(); } const TCollection_AsciiString& IFSelect_SessionPilot::CommandLine () const { return thecommand; } Standard_CString IFSelect_SessionPilot::CommandPart (const Standard_Integer numarg) const { if (numarg <= 0) return thecommand.ToCString(); if (numarg >= thenbwords) return ""; return &(thecommand.ToCString())[thewordeb(numarg)-1]; } Standard_Integer IFSelect_SessionPilot::NbWords () const { return thenbwords; } const TCollection_AsciiString& IFSelect_SessionPilot::Word (const Standard_Integer num) const { if (num < thenbwords) return thewords(num); return nulword; } Standard_CString IFSelect_SessionPilot::Arg (const Standard_Integer num) const { return Word(num).ToCString(); } Standard_Boolean IFSelect_SessionPilot::RemoveWord (const Standard_Integer num) { if (num < 0 || num > thenbwords) return Standard_False; Standard_Integer i; // svv Jan11 2000 : porting on DEC for (i = num; i < thenbwords; i ++) { thewords(i).Clear(); thewords(i).AssignCat(thewords(i+1).ToCString()); } thewords(thenbwords).Clear(); thenbwords --; // Et refaire thecommand. Si num = 0, on supprime le debut (facile) if (num == 0) { thecommand.Remove(1,thewordeb(1)); } else { // Sinon, reconstituer, a partir des words thecommand.Clear(); for (i = 0; i < thenbwords; i ++) { if (i > 0) thecommand.AssignCat(" "); thecommand.AssignCat(thewords(i)); } } return Standard_True; } Standard_Integer IFSelect_SessionPilot::NbCommands () const { return thecomlist.Length(); } const TCollection_AsciiString& IFSelect_SessionPilot::Command (const Standard_Integer num) const { return thecomlist(num); } IFSelect_ReturnStatus IFSelect_SessionPilot::RecordItem (const Handle(Standard_Transient)& item) { theobjrec = item; return (item.IsNull() ? IFSelect_RetFail : IFSelect_RetDone); } Handle(Standard_Transient) IFSelect_SessionPilot::RecordedItem () const { return theobjrec; } void IFSelect_SessionPilot::Clear () { thecomlist.Clear(); } // ####################################################################### // ######## CONTROLE D EXECUTION IFSelect_ReturnStatus IFSelect_SessionPilot::ReadScript (const Standard_CString file) { FILE* fic; int lefic = 0; if (file != NULL && file[0] != '\0') { fic = OSD_OpenFile (file,"r"); if (fic) lefic = 1; else { std::cout<<" ... Script File "<Do(num,this); // Prise en compte des commandes a resultat // Ici, resultat non nomme; Resultat nomme par commande x (plus loin) if (!theobjrec.IsNull()) { thesession->RemoveItem(theobjrec); //// depannage ? Standard_Integer addws = thesession->AddItem(theobjrec); if (addws == 0) { std::cout<<"Could not add item to session, sorry"< 0) thewords(0) = alias; return Perform(); } IFSelect_ReturnStatus IFSelect_SessionPilot::Execute (const TCollection_AsciiString& command) { SetCommandLine(command); return Perform(); } IFSelect_ReturnStatus IFSelect_SessionPilot::ExecuteCounter (const Handle(IFSelect_SignCounter)& counter, const Standard_Integer numword, const IFSelect_PrintCount mode) { if (counter.IsNull()) return IFSelect_RetError; counter->Clear(); if (NbWords() <= numword) counter->AddModel (thesession->Model()); else { // on demande un givelist Handle(TColStd_HSequenceOfTransient) list = thesession->GiveList (CommandPart(numword)); if (list.IsNull()) { std::cout<<"Nothing selected from : "<AddWithGraph (list,thesession->Graph()); } Message_Messenger::StreamBuffer sout = Message::SendInfo(); counter->PrintList (sout, thesession->Model(), mode); return IFSelect_RetVoid; } Standard_Integer IFSelect_SessionPilot::Number (const Standard_CString val) const { Standard_Integer num = thesession->NumberFromLabel (val); if (num < 0) std::cout<<" Label:"<"<<-num<<" ent.s, refus"<Length(); std::cout << " -- Liste des Commands Disponibles --"<Value(i); Standard_Integer loncom = uncom.Length(); nbcom ++; if (nbcom > MAXCOMPERLINE) { std::cout< 0) std::cout< liste la ou les commande debutant par " <<" avec un help sur chacune"<Length(); for (Standard_Integer i = 1; i <= nb; i ++) { Handle(IFSelect_Activator) actor; Standard_Integer num; if (IFSelect_Activator::Select (list->Value(i).ToCString(),num,actor)) { if (IFSelect_Activator::Mode (list->Value(i).ToCString()) == 1) std::cout<<"[xsnew name] "; std::cout << list->Value(i) << " : " << actor->Help(num) << std::endl; } } if (nb == 0 && thenbwords > 1) std::cout<<" Command "<CommandLine()<Word(i) <Clear(); break; // **** command clear case 'f' : { if (argc < 3) { std::cout<<"Donner nom de fichier"<NbCommands(); if (nb == 0) { std::cout<<"Aucune commande enregistree"<Command(i)<RecordMode()) std::cout<<" -- Record Mode Actif"<NbCommands(); std::cout << "Nb Commandes enregistrees : " << nb << " :"<Command(i)<RecordMode(); if (mode) std::cout << " -- Record Mode a present Inactif" <SetRecordMode(!mode); break; } default : std::cout << "Option de controle de commande non comprise"<ReadScript (TCollection_AsciiString(session->Word(1)).ToCString()); // On recopie la string parce que Word(1) change tout le temps ! } case 5 : { // **** XSTEP if (argc < 2) { std::cout<<"xstep : prefixe neutre pour toute commande xstep-draw"<NameIdent(thewords(0).ToCString()) > 0) ////// { std::cout<<"Command with name:"<Do(num,this); // Prise en compte des commandes a resultat if (!theobjrec.IsNull()) { thesession->RemoveItem(theobjrec); //// depannage ? Standard_Integer addws = thesession->AddNamedItem(name.ToCString(),theobjrec); theobjrec.Nullify(); if (addws == 0) { std::cout<<"Could not add named item:"< : commandes debutant par "; case 3 : return "controle de commande. command tout court pour help complet"; case 4 : return "lit les commandes depuis un fichier"; case 5 : return "prefixe neutre pour xstep-draw"; case 6 : return "creation item : donner nom_item puis commande args"; default : return ""; } }