1 -- Created on: 1993-07-27
2 -- Created by: Christian CAILLET
3 -- Copyright (c) 1993-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
23 class SessionPilot from IFSelect inherits Activator
25 ---Purpose : A SessionPilot is intended to make easier the use of a
26 -- WorkSession. It receives commands, under alphanumeric form,
27 -- then calls a library of Activators to interprete and run them.
29 -- Then, WorkSession just records data required to work :
30 -- Rules for Selection, Dispatch ... ; File Data (InterfaceModel
31 -- and results of Evaluations and Transfer as required).
32 -- SessionPilot records and works with alphanumeric commands and
33 -- their results (under a very simple form). It calls a list of
34 -- Activators to perform the actions.
36 -- A Command can have several forms :
37 -- - classic execution, to list, evaluate, or enrich the session
38 -- - command which creates a new item (a Selection for instance)
39 -- such a command should not add it to the session, but make it
40 -- recorded by the Pilot (method RecordItem). The Pilot will
41 -- add the item in the session, with no name
42 -- -> such a command may be called :
43 -- - directly, it will add an item with no name
44 -- - by command xset, in the following form :
45 -- xset name command ... calls the command and adds the item
46 -- to the session under the specified name (if not yet known)
48 -- Thus, to a specific Norm or way of working, only Activators
49 -- change. A specific Initialisation can be done by starting
50 -- with a specific set of commands.
52 -- In addition, SessionPilot is a sub-type of Activator, to
53 -- recognize some built-in commands : exit/x, help/?, control of
54 -- command line, and commands xstep xset ... See method Do
56 -- At least, empty lines and comment lines (beginning by '#')
57 -- are skipped (comment lines are display if read from file)
59 uses CString, OStream, Transient, AsciiString from TCollection,
60 Array1OfAsciiString, SequenceOfAsciiString, Array1OfInteger,
61 SequenceOfInteger, SequenceOfTransient,
62 WorkSession, WorkLibrary, ReturnStatus, -- Activator
63 Selection, Dispatch, Modifier, SignCounter, PrintCount
67 Create (prompt : CString = "") returns mutable SessionPilot;
68 ---Purpose : Creates an empty SessionPilot, with a prompt which will be
69 -- displayed on querying commands. If not precised (""), this
70 -- prompt is set to "Test-XSTEP>"
72 Session (me) returns mutable WorkSession;
73 ---Purpose : Returns the WorkSession which is worked on
75 Library (me) returns mutable WorkLibrary;
76 ---Purpose : Returns the WorKlibrary (Null if not set). WorkLibrary is used
77 -- to Read and Write Files, according to the Norm
79 RecordMode (me) returns Boolean;
80 ---Purpose : Returns the Record Mode for Commands. Default is False.
82 SetSession (me : mutable; WS : mutable WorkSession);
83 ---Purpose : Sets a WorkSession to be worked on
85 SetLibrary (me : mutable; WL : mutable WorkLibrary);
86 ---Purpose : Sets a WorkLibrary
88 SetRecordMode (me : mutable; mode : Boolean);
89 ---Purpose : Changes the RecordMode.
91 SetCommandLine (me : mutable; command : AsciiString from TCollection);
92 ---Purpose : Sets the value of the Command Line to be interpreted
93 -- Also prepares the interpretation (splitting by blanks)
95 CommandLine (me) returns AsciiString from TCollection;
96 ---Purpose : Returns the Command Line to be interpreted
97 ---C++ : return const &
99 CommandPart (me; numarg : Integer = 0) returns CString;
100 ---Purpose : Returns the part of the command line which begins at argument
101 -- <numarg> between 0 and NbWords-1 (by default, all the line)
102 -- Empty string if out of range
104 NbWords (me) returns Integer;
105 ---Purpose : Returns the count of words of the Command Line, separated by
106 -- blanks : 0 if empty, one if a command without args, else it
107 -- gives the count of args minus one.
108 -- Warning : limited to 10 (command title + 9 args)
110 Word (me; num : Integer) returns AsciiString from TCollection;
111 ---Purpose : Returns a word given its rank in the Command Line. Begins at 0
112 -- which is the Command Title, 1 is the 1st arg., etc...
113 ---C++ : return const &
115 Arg (me; num : Integer) returns CString;
116 ---Purpose : Returns a word given its rank, as a CString.
117 -- As for Word, begins at 0 (the command name), etc...
119 RemoveWord (me : mutable; num : Integer) returns Boolean;
120 ---Purpose : Removes a word given its rank. Returns True if Done, False if
121 -- <num> is out of range
123 NbCommands (me) returns Integer;
124 ---Purpose : Returns the count of recorded Commands
126 Command (me; num : Integer) returns AsciiString from TCollection;
127 ---Purpose : Returns a recorded Command, given its rank (from 1)
128 ---C++ : return const &
130 RecordItem (me : mutable; item : any Transient) returns ReturnStatus;
131 ---Purpose : Allows to associate a Transient Value with the last execution
132 -- as a partial result
133 -- Returns RetDone if item is not Null, RetFail if item is Null
134 -- Remark : it is nullified for each Perform
136 RecordedItem (me) returns any Transient;
137 ---Purpose : Returns the Transient Object which was recorded with the
138 -- current Line Command. If none was, returns a Null Handle
140 Clear (me : mutable);
141 ---Purpose : Clears the recorded informations (commands, objects)
143 -- -- Execution -- --
145 ReadScript (me : mutable; file : CString = "") returns ReturnStatus;
146 ---Purpose : Reads commands from a Script File, named <file>. By default
147 -- (file = ""), reads from standard input with a prompt
148 -- Else (reading from a file), the read commands are displayed
149 -- onto standard output. Allows nested reads. Reading is stopped
150 -- either by command x or exit, or by reaching end of file
151 -- Return Value follows the rules of Do : RetEnd for normal end,
152 -- RetFail if script could not be opened
154 Perform (me : mutable) returns ReturnStatus;
155 ---Purpose : Executes the Command, itself (for built-in commands, which
156 -- have priority) or by using the list of Activators.
157 -- The value returned is : RetVoid if nothing done (void command)
158 -- RetDone if execution OK, RetEnd if END OF SESSION, RetError if
159 -- command unknown or incorrect, RetFail if error on execution
160 -- If execution is OK and RecordMode is set, this Command Line is
161 -- recorded to the list (see below).
163 ExecuteAlias (me : mutable; aliasname : AsciiString from TCollection)
164 returns ReturnStatus;
165 ---Purpose : Executes the Commands, except that the command name (word 0)
166 -- is aliased. The rest of the command line is unchanged
167 -- If <alias> is empty, Executes with no change
169 -- Error status is returned if the alias is unknown as command
171 Execute (me : mutable; command : AsciiString from TCollection)
172 returns ReturnStatus;
173 ---Purpose : Sets the Command then tries to execute it. Return value :
174 -- same as for Perform
176 ExecuteCounter (me : mutable; counter : mutable SignCounter;
177 numword : Integer; mode : PrintCount = IFSelect_CountByItem)
178 returns ReturnStatus;
179 ---Purpose : Executes a Counter in a general way
180 -- If <numword> is greater than count of command words, it counts
181 -- all the model. Else it considers the word <numword> as the
182 -- identifier of a Selection
183 -- <mode> gives the mode of printing results, default is
186 Number(me; val : CString) returns Integer;
187 ---Purpose : Interprets a string value as an entity number :
188 -- if it gives an integer, returns its value
189 -- else, considers it as ENtityLabel (preferably case sensitive)
190 -- in case of failure, returns 0
192 Do (me : mutable; number : Integer; session : mutable SessionPilot)
193 returns ReturnStatus;
194 ---Purpose : Processes specific commands, which are :
195 -- x or exit for end of session
196 -- ? or help for help messages
197 -- xcommand to control command lines (Record Mode, List, Clear,
199 -- xsource to execute a command file (no nesting allowed),
200 -- in case of error, source is stopped and keyword recovers
201 -- xstep is a simple prefix (useful in a wider environment, to
202 -- avoid conflicts on command names)
203 -- xset control commands which create items with names
205 Help (me; number : Integer) returns CString;
206 ---Purpose : Help for specific commands (apart from general command help)
210 thesession : WorkSession;
211 theprompt : AsciiString from TCollection;
212 thecommand : AsciiString from TCollection;
213 thenbwords : Integer;
214 thewords : Array1OfAsciiString;
215 thewordeb : Array1OfInteger;
219 theobjrec : Transient;
220 thecomlist : SequenceOfAsciiString;