0026809: Visualization, TKOpenGl - handle point arrays with per-vertex color within...
[occt.git] / src / MoniTool / MoniTool_Option.hxx
1 // Created on: 1998-12-14
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_Option_HeaderFile
18 #define _MoniTool_Option_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <TCollection_AsciiString.hxx>
24 #include <Standard_Type.hxx>
25 #include <MMgt_TShared.hxx>
26 #include <Standard_CString.hxx>
27 #include <Standard_Boolean.hxx>
28 #include <TColStd_HSequenceOfAsciiString.hxx>
29 class MoniTool_TypedValue;
30 class Dico_DictionaryOfTransient;
31 class Standard_Transient;
32 class TCollection_AsciiString;
33
34
35 class MoniTool_Option;
36 DEFINE_STANDARD_HANDLE(MoniTool_Option, MMgt_TShared)
37
38 //! An Option gives a way of recording an enumerated list of
39 //! instances of a given class, each instance being identified
40 //! by a case name.
41 //!
42 //! Also, an Option allows to manage basic types through a Typed
43 //! Value (which also applies to Static Parameter). It may record
44 //! an enumerated list of values for a TypedValue or Static
45 //! Parameter, each of them is recorded as a string (HAsciiString)
46 //!
47 //! An Option is defined by the type of the class to be optioned,
48 //! or (mutually exclusive) the TypedValue/Static of which values
49 //! are to be optioned, a specific name, a list of named values.
50 //! It brings a current case with its name and value
51 //! It may also have a default case (the first recorded one if not
52 //! precised)
53 //!
54 //! An Option may be created from another one, by sharing its Type
55 //! and its list of Items (one per case), with the same name or
56 //! another one. It may then be duplicated to break this sharing.
57 class MoniTool_Option : public MMgt_TShared
58 {
59
60 public:
61
62   
63   //! Creates an Option from scratch, with a Type and a Name
64   Standard_EXPORT MoniTool_Option(const Handle(Standard_Type)& atype, const Standard_CString aname);
65   
66   //! Creates an Option for a TypedValue (for basic, non-cdl-typed,
67   //! value : integer, real, string ...)
68   //! If <name> is not given, the name of the TypedValue is taken
69   //! Remark that Type is then enforced to TCollection_HAsciiString
70   Standard_EXPORT MoniTool_Option(const Handle(MoniTool_TypedValue)& aval, const Standard_CString aname = "");
71   
72   //! Creates an Option from another one, the name can be redefined
73   //! The Type remains the same. The list of Items, too, it can also
74   //! be later duplicated by call to Duplicate
75   Standard_EXPORT MoniTool_Option(const Handle(MoniTool_Option)& other, const Standard_CString aname = "");
76   
77   //! Adds an item : value and name (replaces it if name is already
78   //! recorded)
79   //! Returns True when done, False if <val> is not Kind of the
80   //! definition Type
81   //! For a TypedValue, val must be a HAsciiString, its content must
82   //! satisfy the definition of the TypedValue
83   Standard_EXPORT Standard_Boolean Add (const Standard_CString name, const Handle(Standard_Transient)& val);
84   
85   //! Short-cut to add an item for a TypedValue (basic type) : name
86   //! is the name of the case, val is its value as a CString
87   //! If val is not provided, val = name is assumed
88   //! Returns True when done, False if this Option is not for a
89   //! TypedValue or if the new value does not satisfy the definition
90   //! of the TypedValue
91   Standard_EXPORT Standard_Boolean AddBasic (const Standard_CString name, const Standard_CString val = "");
92   
93   //! Duplicates the list of items
94   //! It starts with the same definitions as before Duplicate, but
95   //! it is not longer shared with other options
96   Standard_EXPORT void Duplicate();
97   
98   //! Returns the Name of the Option
99   Standard_EXPORT const TCollection_AsciiString& Name() const;
100   
101   //! Returns the Type of the Option
102   Standard_EXPORT Handle(Standard_Type) Type() const;
103   
104   //! Returns the TypedValue of the Option, or a Null Handle
105   Standard_EXPORT Handle(MoniTool_TypedValue) TypedValue() const;
106   
107   //! Gives the value bound with a name, in val
108   //! Returns True if <name> is found, False else
109   //! This way of returning a Transient, bound with the Type Control
110   //! avoids DownCast and ensures the value is directly usable
111   Standard_EXPORT Standard_Boolean Item (const Standard_CString name, Handle(Standard_Transient)& val) const;
112   
113   //! Returns the list of available item names
114   Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) ItemList() const;
115   
116   //! Returns the list of cases, other than <name>, which bring the
117   //! same value as <name>
118   //! Empty list (not a Null Handle) if no alias, or <name> unknown
119   //! if <exact> is True (D), exact name is required, no completion
120   //! if <exact> is False and <name> is not complete, but addresses
121   //! only one item, completion is done and the list includes the
122   //! complete name
123   Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) Aliases (const Standard_CString name, const Standard_Boolean exact = Standard_True) const;
124   
125   //! Commands the Option to switch on an item name
126   //! Returns True when done, False if <name> is not recorded
127   //! (in that case, former switch remains unchanged)
128   //! If no switch has been called, it is active on the last added
129   //! items
130   Standard_EXPORT Standard_Boolean Switch (const Standard_CString name);
131   
132   //! Returns the Name of the currently switched item (Case)
133   Standard_EXPORT const TCollection_AsciiString& CaseName() const;
134   
135   //! Returns the Value of the currently switch item
136   //! To be down-casted as needed before use
137   Standard_EXPORT Handle(Standard_Transient) CaseValue() const;
138   
139   //! Returns the Value of the currently switch item
140   //! This way of returning a Transient, bound with the Type Control
141   //! avoids DownCast and ensures the value is directly usable
142   //! For a TypedValue, returns the corresponding HAsciiString
143   Standard_EXPORT void Value (Handle(Standard_Transient)& val) const;
144
145
146
147
148   DEFINE_STANDARD_RTTIEXT(MoniTool_Option,MMgt_TShared)
149
150 protected:
151
152
153
154
155 private:
156
157   
158   //! Returns the list of items, to be shared (to copy an option)
159   Standard_EXPORT Handle(Dico_DictionaryOfTransient) Items() const;
160
161   TCollection_AsciiString thename;
162   Handle(Standard_Type) thetype;
163   Handle(MoniTool_TypedValue) thevalue;
164   Handle(Dico_DictionaryOfTransient) theitems;
165   TCollection_AsciiString thecase;
166   Handle(Standard_Transient) theval;
167
168
169 };
170
171
172
173
174
175
176
177 #endif // _MoniTool_Option_HeaderFile