0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / MoniTool / MoniTool_TypedValue.hxx
CommitLineData
42cf5bc1 1// Created on: 1998-02-23
2// Created by: Christian CAILLET
3// Copyright (c) 1998-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _MoniTool_TypedValue_HeaderFile
18#define _MoniTool_TypedValue_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <TCollection_AsciiString.hxx>
24#include <MoniTool_ValueType.hxx>
997e128f 25#include <NCollection_DataMap.hxx>
42cf5bc1 26#include <Standard_Type.hxx>
27#include <Standard_Integer.hxx>
28#include <Standard_Real.hxx>
29#include <TColStd_HArray1OfAsciiString.hxx>
30#include <MoniTool_ValueInterpret.hxx>
31#include <MoniTool_ValueSatisfies.hxx>
25e59720 32#include <Standard_Transient.hxx>
42cf5bc1 33#include <Standard_CString.hxx>
34#include <Standard_Boolean.hxx>
35#include <TColStd_HSequenceOfAsciiString.hxx>
42cf5bc1 36class TCollection_HAsciiString;
37class Standard_Transient;
38class Standard_ConstructionError;
39class TCollection_AsciiString;
42cf5bc1 40
41class MoniTool_TypedValue;
25e59720 42DEFINE_STANDARD_HANDLE(MoniTool_TypedValue, Standard_Transient)
42cf5bc1 43
44//! This class allows to dynamically manage .. typed values, i.e.
45//! values which have an alphanumeric expression, but with
46//! controls. Such as "must be an Integer" or "Enumerative Text"
47//! etc
48//!
49//! Hence, a TypedValue brings a specification (type + constraints
50//! if any) and a value. Its basic form is a string, it can be
51//! specified as integer or real or enumerative string, then
52//! queried as such.
53//! Its string content, which is a Handle(HAsciiString) can be
54//! shared by other data structures, hence gives a direct on line
55//! access to its value.
25e59720 56class MoniTool_TypedValue : public Standard_Transient
42cf5bc1 57{
58
59public:
60
61
62 //! Creates a TypedValue, with a name
63 //!
64 //! type gives the type of the parameter, default is free text
65 //! Also available : Integer, Real, Enum, Entity (i.e. Object)
66 //! More precise specifications, titles, can be given to the
67 //! TypedValue once created
68 //!
69 //! init gives an initial value. If it is not given, the
70 //! TypedValue begins as "not set", its value is empty
71 Standard_EXPORT MoniTool_TypedValue(const Standard_CString name, const MoniTool_ValueType type = MoniTool_ValueText, const Standard_CString init = "");
72
73 //! Creates a TypedValue from another one, by duplication
74 Standard_EXPORT MoniTool_TypedValue(const Handle(MoniTool_TypedValue)& other);
75
76 //! Access to internal data which have no other access
997e128f 77 Standard_EXPORT void Internals (MoniTool_ValueInterpret& interp, MoniTool_ValueSatisfies& satisf, Standard_CString& satisname, NCollection_DataMap<TCollection_AsciiString, Standard_Integer>& enums) const;
42cf5bc1 78
79 //! Returns the name
80 Standard_EXPORT Standard_CString Name() const;
81
82 //! Returns the type of the value
83 Standard_EXPORT MoniTool_ValueType ValueType() const;
84
85 //! Returns the Definition
86 //! By priority, the enforced one, else an automatic one, computed
87 //! from the specification
88 Standard_EXPORT TCollection_AsciiString Definition() const;
89
90 //! Enforces a Definition
91 Standard_EXPORT void SetDefinition (const Standard_CString deftext);
92
93 //! Prints definition, specification, and actual status and value
0ebe5b0a 94 Standard_EXPORT virtual void Print (Standard_OStream& S) const;
42cf5bc1 95
96 //! Prints only the Value
0ebe5b0a 97 Standard_EXPORT void PrintValue (Standard_OStream& S) const;
42cf5bc1 98
99 //! Completes the definition of a TypedValue by command <initext>,
100 //! once created with its type
101 //! Returns True if done, False if could not be interpreted
102 //! <initext> may be :
103 //! imin ival : minimum value for an integer
104 //! imax ival : maximum value for an integer
105 //! rmin rval : minimum value for a real
106 //! rmax rval : maximum value for a real
107 //! unit name : name of unit
108 //! ematch i : enum from integer value i, match required
109 //! enum i : enum from integer value i, match not required
110 //! eval text : add an enumerative value (increments max by 1)
111 //! eval ?? : add a non-authorised enum value (to be skipped)
112 //! tmax l : maximum length for a text
113 Standard_EXPORT Standard_Boolean AddDef (const Standard_CString initext);
114
115 //! Sets a label, which can then be displayed
116 Standard_EXPORT void SetLabel (const Standard_CString label);
117
118 //! Returns the label, if set; else returns an empty string
119 Standard_EXPORT Standard_CString Label() const;
120
121 //! Sets a maximum length for a text (active only for a free text)
122 Standard_EXPORT void SetMaxLength (const Standard_Integer max);
123
124 //! Returns the maximum length, 0 if not set
125 Standard_EXPORT Standard_Integer MaxLength() const;
126
127 //! Sets an Integer limit (included) to <val>, the upper limit
128 //! if <max> is True, the lower limit if <max> is False
129 Standard_EXPORT void SetIntegerLimit (const Standard_Boolean max, const Standard_Integer val);
130
131 //! Gives an Integer Limit (upper if <max> True, lower if <max>
132 //! False). Returns True if this limit is defined, False else
133 //! (in that case, gives the natural limit for Integer)
134 Standard_EXPORT Standard_Boolean IntegerLimit (const Standard_Boolean max, Standard_Integer& val) const;
135
136 //! Sets a Real limit (included) to <val>, the upper limit
137 //! if <max> is True, the lower limit if <max> is False
138 Standard_EXPORT void SetRealLimit (const Standard_Boolean max, const Standard_Real val);
139
140 //! Gives an Real Limit (upper if <max> True, lower if <max>
141 //! False). Returns True if this limit is defined, False else
142 //! (in that case, gives the natural limit for Real)
143 Standard_EXPORT Standard_Boolean RealLimit (const Standard_Boolean max, Standard_Real& val) const;
144
145 //! Sets (Clears if <def> empty) a unit definition, as an equation
146 //! of dimensions. TypedValue just records this definition, does
147 //! not exploit it, to be done as required by user applications
148 Standard_EXPORT void SetUnitDef (const Standard_CString def);
149
150 //! Returns the recorded unit definition, empty if not set
151 Standard_EXPORT Standard_CString UnitDef() const;
152
153 //! For an enumeration, precises the starting value (default 0)
154 //! and the match condition : if True (D), the string value must
155 //! match the definition, else it may take another value : in that
156 //! case, the Integer Value will be Start - 1.
157 //! (empty value remains allowed)
158 Standard_EXPORT void StartEnum (const Standard_Integer start = 0, const Standard_Boolean match = Standard_True);
159
160 //! Adds enumerative definitions. For more than 10, several calls
161 Standard_EXPORT void AddEnum (const Standard_CString v1 = "", const Standard_CString v2 = "", const Standard_CString v3 = "", const Standard_CString v4 = "", const Standard_CString v5 = "", const Standard_CString v6 = "", const Standard_CString v7 = "", const Standard_CString v8 = "", const Standard_CString v9 = "", const Standard_CString v10 = "");
162
163 //! Adds an enumeration definition, by its string and numeric
164 //! values. If it is the first setting for this value, it is
165 //! recorded as main value. Else, it is recognized as alternate
166 //! string for this numeric value
167 Standard_EXPORT void AddEnumValue (const Standard_CString val, const Standard_Integer num);
168
169 //! Gives the Enum definitions : start value, end value, match
170 //! status. Returns True for an Enum, False else.
171 Standard_EXPORT Standard_Boolean EnumDef (Standard_Integer& startcase, Standard_Integer& endcase, Standard_Boolean& match) const;
172
173 //! Returns the value of an enumerative definition, from its rank
174 //! Empty string if out of range or not an Enum
175 Standard_EXPORT Standard_CString EnumVal (const Standard_Integer num) const;
176
177 //! Returns the case number which cooresponds to a string value
178 //! Works with main and additionnal values
179 //! Returns (StartEnum - 1) if not OK, -1 if not an Enum
180 Standard_EXPORT Standard_Integer EnumCase (const Standard_CString val) const;
181
182 //! Sets type of which an Object TypedValue must be kind of
183 //! Error for a TypedValue not an Object (Entity)
184 Standard_EXPORT void SetObjectType (const Handle(Standard_Type)& typ);
185
186 //! Returns the type of which an Object TypedValue must be kind of
187 //! Default is Standard_Transient
188 //! Null for a TypedValue not an Object
189 Standard_EXPORT Handle(Standard_Type) ObjectType() const;
190
191 //! Sets a specific Interpret function
192 Standard_EXPORT void SetInterpret (const MoniTool_ValueInterpret func);
193
194 //! Tells if a TypedValue has an Interpret
195 Standard_EXPORT virtual Standard_Boolean HasInterpret() const;
196
197 //! Sets a specific Satisfies function : it is added to the
198 //! already defined criteria
199 //! It must match the form :
200 //! statisfies (val : HAsciiString) returns Boolean
201 Standard_EXPORT void SetSatisfies (const MoniTool_ValueSatisfies func, const Standard_CString name);
202
203 //! Returns name of specific satisfy, empty string if none
204 Standard_EXPORT Standard_CString SatisfiesName() const;
205
206 //! Returns True if the value is set (not empty/not null object)
207 Standard_EXPORT Standard_Boolean IsSetValue() const;
208
209 //! Returns the value, as a cstring. Empty if not set.
210 Standard_EXPORT Standard_CString CStringValue() const;
211
212 //! Returns the value, as a Handle (can then be shared)
213 //! Null if not defined
214 Standard_EXPORT Handle(TCollection_HAsciiString) HStringValue() const;
215
216 //! Interprets a value.
217 //! <native> True : returns a native value
218 //! <native> False : returns a coded value
219 //! If the Interpret function is set, calls it
220 //! Else, for an Enum, Native returns the Text, Coded returns
221 //! the number
222 //! STANDARD RETURNS : = hval means no specific interpretation
223 //! Null means senseless
224 //! Can also be redefined
225 Standard_EXPORT virtual Handle(TCollection_HAsciiString) Interpret (const Handle(TCollection_HAsciiString)& hval, const Standard_Boolean native) const;
226
227 //! Returns True if a value statifies the specification
228 //! (remark : does not apply to Entity : see ObjectType, for this
229 //! type, the string is just a comment)
230 Standard_EXPORT virtual Standard_Boolean Satisfies (const Handle(TCollection_HAsciiString)& hval) const;
231
232 //! Clears the recorded Value : it is now unset
233 Standard_EXPORT void ClearValue();
234
235 //! Changes the value. The new one must satisfy the specification
236 //! Returns False (and did not set) if the new value
237 //! does not satisfy the specification
238 //! Can be redefined to be managed (in a subclass)
239 Standard_EXPORT virtual Standard_Boolean SetCStringValue (const Standard_CString val);
240
241 //! Forces a new Handle for the Value
242 //! It can be empty, else (if Type is not free Text), it must
243 //! satisfy the specification.
244 //! Not only the value is changed, but also the way it is shared
245 //! Remark : for Type=Object, this value is not controlled, it can
246 //! be set as a comment
247 //! Returns False (and did not set) if the new value
248 //! does not satisfy the specification
249 //! Can be redefined to be managed (in a subclass)
250 Standard_EXPORT virtual Standard_Boolean SetHStringValue (const Handle(TCollection_HAsciiString)& hval);
251
252 //! Returns the value as integer, i.e. :
253 //! For type = Integer, the integer itself; 0 if not set
254 //! For type = Enum, the designated rank (see Enum definition)
255 //! StartEnum - 1 if not set or not in the definition
256 //! Else, returns 0
257 Standard_EXPORT Standard_Integer IntegerValue() const;
258
259 //! Changes the value as an integer, only for Integer or Enum
260 Standard_EXPORT virtual Standard_Boolean SetIntegerValue (const Standard_Integer ival);
261
262 //! Returns the value as real, for a Real type TypedValue
263 //! Else, returns 0.
264 Standard_EXPORT Standard_Real RealValue() const;
265
266 //! Changes the value as a real, only for Real
267 Standard_EXPORT virtual Standard_Boolean SetRealValue (const Standard_Real rval);
268
269 //! Returns the value as Transient Object, only for Object/Entity
270 //! Remark that the "HString value" is IGNORED here
271 //! Null if not set; remains to be casted
272 Standard_EXPORT Handle(Standard_Transient) ObjectValue() const;
273
274 //! Same as ObjectValue, but avoids DownCast : the receiving
275 //! variable is directly loaded. It is assumed that it complies
276 //! with the definition of ObjectType ! Otherwise, big trouble
277 Standard_EXPORT void GetObjectValue (Handle(Standard_Transient)& val) const;
278
279 //! Changes the value as Transient Object, only for Object/Entity
280 //! Returns False if DynamicType does not satisfy ObjectType
281 //! Can be redefined to be managed (in a subclass)
282 Standard_EXPORT virtual Standard_Boolean SetObjectValue (const Handle(Standard_Transient)& obj);
283
284 //! Returns the type name of the ObjectValue, or an empty string
285 //! if not set
286 Standard_EXPORT Standard_CString ObjectTypeName() const;
287
288 //! Adds a TypedValue in the library.
289 //! It is recorded then will be accessed by its Name
290 //! Its Definition may be imposed, else it is computed as usual
291 //! By default it will be accessed by its Definition (string)
292 //! Returns True if done, False if tv is Null or brings no
293 //! Definition or <def> not defined
294 //!
295 //! If a TypedValue was already recorded under this name, it is
296 //! replaced
297 Standard_EXPORT static Standard_Boolean AddLib (const Handle(MoniTool_TypedValue)& tv, const Standard_CString def = "");
298
299 //! Returns the TypedValue bound with a given Name
300 //! Null Handle if none recorded
301 //! Warning : it is the original, not duplicated
302 Standard_EXPORT static Handle(MoniTool_TypedValue) Lib (const Standard_CString def);
303
304 //! Returns a COPY of the TypedValue bound with a given Name
305 //! Null Handle if none recorded
306 Standard_EXPORT static Handle(MoniTool_TypedValue) FromLib (const Standard_CString def);
307
308 //! Returns the list of names of items of the Library of Types
309 //! -- Library of TypedValue as Valued Parameters, -- --
310 //! accessed by parameter name
311 //! for use by management of Static Parameters
312 Standard_EXPORT static Handle(TColStd_HSequenceOfAsciiString) LibList();
313
314 //! Returns a static value from its name, null if unknown
315 Standard_EXPORT static Handle(MoniTool_TypedValue) StaticValue (const Standard_CString name);
316
317
318
319
25e59720 320 DEFINE_STANDARD_RTTIEXT(MoniTool_TypedValue,Standard_Transient)
42cf5bc1 321
322protected:
323
324
325 //! Gives the internal library of static values
997e128f 326 Standard_EXPORT static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& Stats();
42cf5bc1 327
328
329
330private:
331
332
333 TCollection_AsciiString thename;
334 TCollection_AsciiString thedef;
335 TCollection_AsciiString thelabel;
336 MoniTool_ValueType thetype;
337 Handle(Standard_Type) theotyp;
338 Standard_Integer thelims;
339 Standard_Integer themaxlen;
340 Standard_Integer theintlow;
341 Standard_Integer theintup;
342 Standard_Real therealow;
343 Standard_Real therealup;
344 TCollection_AsciiString theunidef;
345 Handle(TColStd_HArray1OfAsciiString) theenums;
997e128f 346 NCollection_DataMap<TCollection_AsciiString, Standard_Integer> theeadds;
42cf5bc1 347 MoniTool_ValueInterpret theinterp;
348 MoniTool_ValueSatisfies thesatisf;
349 TCollection_AsciiString thesatisn;
350 Standard_Integer theival;
351 Handle(TCollection_HAsciiString) thehval;
352 Handle(Standard_Transient) theoval;
353
354
355};
356
357
358
359
360
361
362
363#endif // _MoniTool_TypedValue_HeaderFile