b311480e |
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 |
5 | -- |
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. |
10 | -- |
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. |
13 | -- |
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. |
20 | |
7fd59977 |
21 | |
22 | |
23 | class SessionPilot from IFSelect inherits Activator |
24 | |
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. |
28 | -- |
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. |
35 | -- |
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) |
47 | -- |
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. |
51 | -- |
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 |
55 | -- |
56 | -- At least, empty lines and comment lines (beginning by '#') |
57 | -- are skipped (comment lines are display if read from file) |
58 | |
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 |
64 | |
65 | is |
66 | |
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>" |
71 | |
72 | Session (me) returns mutable WorkSession; |
73 | ---Purpose : Returns the WorkSession which is worked on |
74 | |
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 |
78 | |
79 | RecordMode (me) returns Boolean; |
80 | ---Purpose : Returns the Record Mode for Commands. Default is False. |
81 | |
82 | SetSession (me : mutable; WS : mutable WorkSession); |
83 | ---Purpose : Sets a WorkSession to be worked on |
84 | |
85 | SetLibrary (me : mutable; WL : mutable WorkLibrary); |
86 | ---Purpose : Sets a WorkLibrary |
87 | |
88 | SetRecordMode (me : mutable; mode : Boolean); |
89 | ---Purpose : Changes the RecordMode. |
90 | |
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) |
94 | |
95 | CommandLine (me) returns AsciiString from TCollection; |
96 | ---Purpose : Returns the Command Line to be interpreted |
97 | ---C++ : return const & |
98 | |
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 |
103 | |
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) |
109 | |
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 & |
114 | |
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... |
118 | |
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 |
122 | |
123 | NbCommands (me) returns Integer; |
124 | ---Purpose : Returns the count of recorded Commands |
125 | |
126 | Command (me; num : Integer) returns AsciiString from TCollection; |
127 | ---Purpose : Returns a recorded Command, given its rank (from 1) |
128 | ---C++ : return const & |
129 | |
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 |
135 | |
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 |
139 | |
140 | Clear (me : mutable); |
141 | ---Purpose : Clears the recorded informations (commands, objects) |
142 | |
143 | -- -- Execution -- -- |
144 | |
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 |
153 | |
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). |
162 | |
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 |
168 | -- |
169 | -- Error status is returned if the alias is unknown as command |
170 | |
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 |
175 | |
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 |
184 | -- CountByItem |
185 | |
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 |
191 | |
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, |
198 | -- File Output ...) |
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 |
204 | |
205 | Help (me; number : Integer) returns CString; |
206 | ---Purpose : Help for specific commands (apart from general command help) |
207 | |
208 | fields |
209 | |
210 | thesession : WorkSession; |
211 | theprompt : AsciiString from TCollection; |
212 | thecommand : AsciiString from TCollection; |
213 | thenbwords : Integer; |
214 | thewords : Array1OfAsciiString; |
215 | thewordeb : Array1OfInteger; |
216 | therecord : Boolean; |
217 | |
218 | thenumrec : Integer; |
219 | theobjrec : Transient; |
220 | thecomlist : SequenceOfAsciiString; |
221 | |
222 | end SessionPilot; |