Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:54

0001 // Created on: 1993-07-27
0002 // Created by: Christian CAILLET
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _IFSelect_SessionPilot_HeaderFile
0018 #define _IFSelect_SessionPilot_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 
0022 #include <Standard_Integer.hxx>
0023 #include <TColStd_Array1OfAsciiString.hxx>
0024 #include <TColStd_Array1OfInteger.hxx>
0025 #include <IFSelect_Activator.hxx>
0026 #include <IFSelect_ReturnStatus.hxx>
0027 #include <IFSelect_PrintCount.hxx>
0028 class IFSelect_WorkSession;
0029 class IFSelect_WorkLibrary;
0030 class IFSelect_SignCounter;
0031 
0032 class IFSelect_SessionPilot;
0033 DEFINE_STANDARD_HANDLE(IFSelect_SessionPilot, IFSelect_Activator)
0034 
0035 //! A SessionPilot is intended to make easier the use of a WorkSession.
0036 //! It receives commands, under alphanumeric form,
0037 //! then calls a library of Activators to interpret and run them.
0038 //!
0039 //! Then, WorkSession just records data required to work :
0040 //! Rules for Selection, Dispatch ... ; File Data (InterfaceModel
0041 //! and results of Evaluations and Transfer as required).
0042 //! SessionPilot records and works with alphanumeric commands and
0043 //! their results (under a very simple form). It calls a list of
0044 //! Activators to perform the actions.
0045 //!
0046 //! A Command can have several forms :
0047 //! - classic execution, to list, evaluate, or enrich the session
0048 //! - command which creates a new item (a Selection for instance)
0049 //! such a command should not add it to the session, but make it
0050 //! recorded by the Pilot (method RecordItem). The Pilot will
0051 //! add the item in the session, with no name
0052 //! -> such a command may be called :
0053 //! - directly, it will add an item with no name
0054 //! - by command xset, in the following form :
0055 //! xset name command ...  calls the command and adds the item
0056 //! to the session under the specified name (if not yet known)
0057 //!
0058 //! Thus, to a specific Norm or way of working, only Activators
0059 //! change. A specific Initialisation can be done by starting
0060 //! with a specific set of commands.
0061 //!
0062 //! In addition, SessionPilot is a sub-type of Activator, to
0063 //! recognize some built-in commands : exit/x, help/?, control of
0064 //! command line, and commands xstep xset ... See method Do
0065 //!
0066 //! At least, empty lines and comment lines (beginning by '#')
0067 //! are skipped (comment lines are display if read from file)
0068 class IFSelect_SessionPilot : public IFSelect_Activator
0069 {
0070 
0071 public:
0072 
0073   //! Creates an empty SessionPilot, with a prompt which will be
0074   //! displayed on querying commands. If not precised (""), this
0075   //! prompt is set to "Test-XSTEP>"
0076   Standard_EXPORT IFSelect_SessionPilot(const Standard_CString prompt = "");
0077   
0078   //! Returns the WorkSession which is worked on
0079   Standard_EXPORT Handle(IFSelect_WorkSession) Session() const;
0080   
0081   //! Returns the WorKlibrary (Null if not set). WorkLibrary is used
0082   //! to Read and Write Files, according to the Norm
0083   Standard_EXPORT Handle(IFSelect_WorkLibrary) Library() const;
0084   
0085   //! Returns the Record Mode for Commands. Default is False.
0086   Standard_EXPORT Standard_Boolean RecordMode() const;
0087   
0088   //! Sets a WorkSession to be worked on
0089   Standard_EXPORT void SetSession (const Handle(IFSelect_WorkSession)& WS);
0090   
0091   //! Sets a WorkLibrary
0092   Standard_EXPORT void SetLibrary (const Handle(IFSelect_WorkLibrary)& WL);
0093   
0094   //! Changes the RecordMode.
0095   Standard_EXPORT void SetRecordMode (const Standard_Boolean mode);
0096   
0097   //! Sets the value of the Command Line to be interpreted
0098   //! Also prepares the interpretation (splitting by blanks)
0099   Standard_EXPORT void SetCommandLine (const TCollection_AsciiString& command);
0100   
0101   //! Returns the Command Line to be interpreted
0102   Standard_EXPORT const TCollection_AsciiString& CommandLine() const;
0103   
0104   //! Returns the part of the command line which begins at argument
0105   //! <numarg> between 0 and NbWords-1 (by default, all the line)
0106   //! Empty string if out of range
0107   Standard_EXPORT Standard_CString CommandPart (const Standard_Integer numarg = 0) const;
0108   
0109   //! Returns the count of words of the Command Line, separated by
0110   //! blanks : 0 if empty, one if a command without args, else it
0111   //! gives the count of args minus one.
0112   //! Warning : limited to 10 (command title + 9 args)
0113   Standard_EXPORT Standard_Integer NbWords() const;
0114   
0115   //! Returns a word given its rank in the Command Line. Begins at 0
0116   //! which is the Command Title, 1 is the 1st arg., etc...
0117   Standard_EXPORT const TCollection_AsciiString& Word (const Standard_Integer num) const;
0118   
0119   //! Returns a word given its rank, as a CString.
0120   //! As for Word, begins at 0 (the command name), etc...
0121   Standard_EXPORT Standard_CString Arg (const Standard_Integer num) const;
0122   
0123   //! Removes a word given its rank. Returns True if Done, False if
0124   //! <num> is out of range
0125   Standard_EXPORT Standard_Boolean RemoveWord (const Standard_Integer num);
0126   
0127   //! Returns the count of recorded Commands
0128   Standard_EXPORT Standard_Integer NbCommands() const;
0129   
0130   //! Returns a recorded Command, given its rank (from 1)
0131   Standard_EXPORT const TCollection_AsciiString& Command (const Standard_Integer num) const;
0132   
0133   //! Allows to associate a Transient Value with the last execution
0134   //! as a partial result
0135   //! Returns RetDone if item is not Null, RetFail if item is Null
0136   //! Remark : it is nullified for each Perform
0137   Standard_EXPORT IFSelect_ReturnStatus RecordItem (const Handle(Standard_Transient)& item);
0138   
0139   //! Returns the Transient Object which was recorded with the
0140   //! current Line Command. If none was, returns a Null Handle
0141   Standard_EXPORT Handle(Standard_Transient) RecordedItem() const;
0142   
0143   //! Clears the recorded information (commands, objects)
0144   Standard_EXPORT void Clear();
0145   
0146   //! Reads commands from a Script File, named <file>. By default
0147   //! (file = ""), reads from standard input with a prompt
0148   //! Else (reading from a file), the read commands are displayed
0149   //! onto standard output. Allows nested reads. Reading is stopped
0150   //! either by command x or exit, or by reaching end of file
0151   //! Return Value follows the rules of Do : RetEnd for normal end,
0152   //! RetFail if script could not be opened
0153   Standard_EXPORT IFSelect_ReturnStatus ReadScript (const Standard_CString file = "");
0154   
0155   //! Executes the Command, itself (for built-in commands, which
0156   //! have priority) or by using the list of Activators.
0157   //! The value returned is : RetVoid if nothing done (void command)
0158   //! RetDone if execution OK, RetEnd if END OF SESSION, RetError if
0159   //! command unknown or incorrect, RetFail if error on execution
0160   //! If execution is OK and RecordMode is set, this Command Line is
0161   //! recorded to the list (see below).
0162   Standard_EXPORT IFSelect_ReturnStatus Perform();
0163   
0164   //! Executes the Commands, except that the command name (word 0)
0165   //! is aliased. The rest of the command line is unchanged
0166   //! If <alias> is empty, Executes with no change
0167   //!
0168   //! Error status is returned if the alias is unknown as command
0169   Standard_EXPORT IFSelect_ReturnStatus ExecuteAlias (const TCollection_AsciiString& aliasname);
0170   
0171   //! Sets the Command then tries to execute it. Return value :
0172   //! same as for Perform
0173   Standard_EXPORT IFSelect_ReturnStatus Execute (const TCollection_AsciiString& command);
0174   
0175   //! Executes a Counter in a general way
0176   //! If <numword> is greater than count of command words, it counts
0177   //! all the model. Else it considers the word <numword> as the
0178   //! identifier of a Selection
0179   //! <mode> gives the mode of printing results, default is
0180   //! CountByItem
0181   Standard_EXPORT IFSelect_ReturnStatus ExecuteCounter (const Handle(IFSelect_SignCounter)& counter, const Standard_Integer numword, const IFSelect_PrintCount mode = IFSelect_CountByItem);
0182   
0183   //! Interprets a string value as an entity number :
0184   //! if it gives an integer, returns its value
0185   //! else, considers it as ENtityLabel (preferably case sensitive)
0186   //! in case of failure, returns 0
0187   Standard_EXPORT Standard_Integer Number (const Standard_CString val) const;
0188   
0189   //! Processes specific commands, which are :
0190   //! x or exit for end of session
0191   //! ? or help for help messages
0192   //! xcommand to control command lines (Record Mode, List, Clear,
0193   //! File Output ...)
0194   //! xsource to execute a command file (no nesting allowed),
0195   //! in case of error, source is stopped and keyword recovers
0196   //! xstep is a simple prefix (useful in a wider environment, to
0197   //! avoid conflicts on command names)
0198   //! xset control commands which create items with names
0199   Standard_EXPORT IFSelect_ReturnStatus Do (const Standard_Integer number, const Handle(IFSelect_SessionPilot)& session) Standard_OVERRIDE;
0200   
0201   //! Help for specific commands (apart from general command help)
0202   Standard_EXPORT Standard_CString Help (const Standard_Integer number) const Standard_OVERRIDE;
0203 
0204   DEFINE_STANDARD_RTTIEXT(IFSelect_SessionPilot,IFSelect_Activator)
0205 
0206 private:
0207 
0208   Handle(IFSelect_WorkSession) thesession;
0209   TCollection_AsciiString theprompt;
0210   TCollection_AsciiString thecommand;
0211   Standard_Integer thenbwords;
0212   TColStd_Array1OfAsciiString thewords;
0213   TColStd_Array1OfInteger thewordeb;
0214   Standard_Boolean therecord;
0215   Standard_Integer thenumrec;
0216   Handle(Standard_Transient) theobjrec;
0217   TColStd_SequenceOfAsciiString thecomlist;
0218 
0219 };
0220 
0221 #endif // _IFSelect_SessionPilot_HeaderFile