0031501: Foundation Classes, Message_Printer - remove theToPutEndl argument -- prepar...
[occt.git] / src / IFSelect / IFSelect_Editor.hxx
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 _IFSelect_Editor_HeaderFile
18 #define _IFSelect_Editor_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_Integer.hxx>
24 #include <TColStd_Array1OfTransient.hxx>
25 #include <TColStd_Array1OfAsciiString.hxx>
26 #include <TColStd_Array1OfInteger.hxx>
27 #include <Standard_Transient.hxx>
28 #include <Standard_CString.hxx>
29 #include <IFSelect_EditValue.hxx>
30 #include <Standard_Boolean.hxx>
31 #include <TColStd_HSequenceOfHAsciiString.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <NCollection_DataMap.hxx>
34 class Standard_OutOfRange;
35 class Interface_TypedValue;
36 class IFSelect_EditForm;
37 class TCollection_HAsciiString;
38 class IFSelect_ListEditor;
39 class Standard_Transient;
40 class Interface_InterfaceModel;
41
42
43 class IFSelect_Editor;
44 DEFINE_STANDARD_HANDLE(IFSelect_Editor, Standard_Transient)
45
46 //! An Editor defines a set of values and a way to edit them, on
47 //! an entity or on the model (e.g. on its header)
48 //!
49 //! Each Value is controlled by a TypedValue, with a number (it is
50 //! an Integer) and a name under two forms (complete and short)
51 //! and an edit mode
52 class IFSelect_Editor : public Standard_Transient
53 {
54
55 public:
56
57   
58   //! Sets a Typed Value for a given ident and short name, with an
59   //! Edit Mode
60   Standard_EXPORT void SetValue (const Standard_Integer num, const Handle(Interface_TypedValue)& typval, const Standard_CString shortname = "", const IFSelect_EditValue accessmode = IFSelect_Editable);
61   
62   //! Sets a parameter to be a List
63   //! max < 0 : not for a list (set when starting)
64   //! max = 0 : list with no length limit (default for SetList)
65   //! max > 0 : list limited to <max> items
66   Standard_EXPORT void SetList (const Standard_Integer num, const Standard_Integer max = 0);
67   
68   //! Returns the count of Typed Values
69   Standard_EXPORT Standard_Integer NbValues() const;
70   
71   //! Returns a Typed Value from its ident
72   Standard_EXPORT Handle(Interface_TypedValue) TypedValue (const Standard_Integer num) const;
73   
74   //! Tells if a parameter is a list
75   Standard_EXPORT Standard_Boolean IsList (const Standard_Integer num) const;
76   
77   //! Returns max length allowed for a list
78   //! = 0 means : list with no limit
79   //! < 0 means : not a list
80   Standard_EXPORT Standard_Integer MaxList (const Standard_Integer num) const;
81   
82   //! Returns the name of a Value (complete or short) from its ident
83   //! Short Name can be empty
84   Standard_EXPORT Standard_CString Name (const Standard_Integer num, const Standard_Boolean isshort = Standard_False) const;
85   
86   //! Returns the edit mode of a Value
87   Standard_EXPORT IFSelect_EditValue EditMode (const Standard_Integer num) const;
88   
89   //! Returns the number (ident) of a Value, from its name, short or
90   //! complete. If not found, returns 0
91   Standard_EXPORT Standard_Integer NameNumber (const Standard_CString name) const;
92   
93   Standard_EXPORT void PrintNames (Standard_OStream& S) const;
94   
95   Standard_EXPORT void PrintDefs (Standard_OStream& S, const Standard_Boolean labels = Standard_False) const;
96   
97   //! Returns the MaxLength of, according to what :
98   //! <what> = -1 : length of short names
99   //! <what> =  0 : length of complete names
100   //! <what> =  1 : length of values labels
101   Standard_EXPORT Standard_Integer MaxNameLength (const Standard_Integer what) const;
102   
103   //! Returns the specific label
104   Standard_EXPORT virtual TCollection_AsciiString Label() const = 0;
105   
106   //! Builds and Returns an EditForm, empty (no data yet)
107   //! Can be redefined to return a specific type of EditForm
108   Standard_EXPORT virtual Handle(IFSelect_EditForm) Form (const Standard_Boolean readonly, const Standard_Boolean undoable = Standard_True) const;
109   
110   //! Tells if this Editor can work on this EditForm and its content
111   //! (model, entity ?)
112   Standard_EXPORT virtual Standard_Boolean Recognize (const Handle(IFSelect_EditForm)& form) const = 0;
113   
114   //! Returns the value of an EditForm, for a given item
115   //! (if not a list. for a list, a Null String may be returned)
116   Standard_EXPORT virtual Handle(TCollection_HAsciiString) StringValue (const Handle(IFSelect_EditForm)& form, const Standard_Integer num) const = 0;
117   
118   //! Returns a ListEditor for a parameter which is a List
119   //! Default returns a basic ListEditor for a List, a Null Handle
120   //! if <num> is not for a List. Can be redefined
121   Standard_EXPORT virtual Handle(IFSelect_ListEditor) ListEditor (const Standard_Integer num) const;
122   
123   //! Returns the value of an EditForm as a List, for a given item
124   //! If not a list, a Null Handle should be returned
125   //! Default returns a Null Handle, because many Editors have
126   //! no list to edit. To be redefined as required
127   Standard_EXPORT virtual Handle(TColStd_HSequenceOfHAsciiString) ListValue (const Handle(IFSelect_EditForm)& form, const Standard_Integer num) const;
128   
129   //! Loads original values from some data, to an EditForm
130   //! Remark: <ent> may be Null, this means all <model> is concerned
131   //! Also <model> may be Null, if no context applies for <ent>
132   //! And both <ent> and <model> may be Null, for a full static
133   //! editor
134   Standard_EXPORT virtual Standard_Boolean Load (const Handle(IFSelect_EditForm)& form, const Handle(Standard_Transient)& ent, const Handle(Interface_InterfaceModel)& model) const = 0;
135   
136   //! Updates the EditForm when a parameter is modified
137   //! I.E.  default does nothing, can be redefined, as follows :
138   //! Returns True when done (even if does nothing), False in case
139   //! of refuse (for instance, if the new value is not suitable)
140   //! <num> is the rank of the parameter for the EDITOR itself
141   //! <enforce> True means that protected parameters can be touched
142   //!
143   //! If a parameter commands the value of other ones, when it is
144   //! modified, it is necessary to touch them by Touch from EditForm
145   Standard_EXPORT virtual Standard_Boolean Update (const Handle(IFSelect_EditForm)& form, const Standard_Integer num, const Handle(TCollection_HAsciiString)& newval, const Standard_Boolean enforce) const;
146   
147   //! Acts as Update, but when the value is a list
148   Standard_EXPORT virtual Standard_Boolean UpdateList (const Handle(IFSelect_EditForm)& form, const Standard_Integer num, const Handle(TColStd_HSequenceOfHAsciiString)& newlist, const Standard_Boolean enforce) const;
149   
150   //! Applies modified values of the EditForm with some data
151   //! Remark: <ent> may be Null, this means all <model> is concerned
152   //! Also <model> may be Null, if no context applies for <ent>
153   //! And both <ent> and <model> may be Null, for a full static
154   //! editor
155   Standard_EXPORT virtual Standard_Boolean Apply (const Handle(IFSelect_EditForm)& form, const Handle(Standard_Transient)& ent, const Handle(Interface_InterfaceModel)& model) const = 0;
156
157
158
159
160   DEFINE_STANDARD_RTTIEXT(IFSelect_Editor,Standard_Transient)
161
162 protected:
163
164   
165   //! Prepares the list of Typed Values (gives its count)
166   //! This count can be tuned later, to a LOWER value, this allows
167   //! to initialize with a "maximum reservation" then cut the extra
168   Standard_EXPORT IFSelect_Editor(const Standard_Integer nbval);
169   
170   //! Adjusts the true count of values. It can be LOWER or equal to
171   //! the initial size (which then acts as a reservation), but never
172   //! greater
173   Standard_EXPORT void SetNbValues (const Standard_Integer nbval);
174
175
176
177 private:
178
179
180   Standard_Integer thenbval;
181   Standard_Integer themaxsh;
182   Standard_Integer themaxco;
183   Standard_Integer themaxla;
184   NCollection_DataMap<TCollection_AsciiString, Standard_Integer> thenames;
185   TColStd_Array1OfTransient thevalues;
186   TColStd_Array1OfAsciiString theshorts;
187   TColStd_Array1OfInteger themodes;
188   TColStd_Array1OfInteger thelists;
189
190
191 };
192
193
194
195
196
197
198
199 #endif // _IFSelect_Editor_HeaderFile