0028832: MMgt_TShared can be replaced by Standard_Transient
[occt.git] / src / IFSelect / IFSelect_ListEditor.hxx
1 // Created on: 1998-07-28
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_ListEditor_HeaderFile
18 #define _IFSelect_ListEditor_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_Integer.hxx>
24 #include <TColStd_HSequenceOfHAsciiString.hxx>
25 #include <TColStd_HSequenceOfInteger.hxx>
26 #include <Standard_Transient.hxx>
27 #include <Standard_Boolean.hxx>
28 class Interface_TypedValue;
29 class Interface_InterfaceModel;
30 class TCollection_HAsciiString;
31
32
33 class IFSelect_ListEditor;
34 DEFINE_STANDARD_HANDLE(IFSelect_ListEditor, Standard_Transient)
35
36 //! A ListEditor is an auxiliary operator for Editor/EditForm
37 //! I.E. it works on parameter values expressed as strings
38 //!
39 //! For a parameter which is a list, it may not be edited in once
40 //! by just setting a new value (as a string)
41 //!
42 //! Firstly, a list can be long (and tedious to be accessed flat)
43 //! then requires a better way of accessing
44 //!
45 //! Moreover, not only its VALUES may be changed (SetValue), but
46 //! also its LENGTH : items may be added or removed ...
47 //!
48 //! Hence, the way of editing a parameter as a list is :
49 //! - edit it separately, with the help of a ListEditor
50 //! - it remains possible to prepare a new list of values apart
51 //! - then give the new list in once to the EditForm
52 //!
53 //! An EditList is produced by the Editor, with a basic definition
54 //! This definition (brought by this class) can be redefined
55 //! Hence the Editor may produce a specific ListEditor as needed
56 class IFSelect_ListEditor : public Standard_Transient
57 {
58
59 public:
60
61   
62   //! Creates a ListEditor with absolutely no constraint
63   Standard_EXPORT IFSelect_ListEditor();
64   
65   //! Creates a ListEditor, for which items of the list to edit are
66   //! defined by <def>, and <max> describes max length :
67   //! 0 (D) means no limit
68   //! value > 0 means : no more the <max> items are allowed
69   Standard_EXPORT IFSelect_ListEditor(const Handle(Interface_TypedValue)& def, const Standard_Integer max = 0);
70   
71   //! Loads a Model. It is used to check items of type Entity(Ident)
72   Standard_EXPORT void LoadModel (const Handle(Interface_InterfaceModel)& model);
73   
74   //! Loads the original values for the list
75   //! Remark : If its length is mor then MaxLength, editions remain
76   //! allowed, except Add
77   Standard_EXPORT void LoadValues (const Handle(TColStd_HSequenceOfHAsciiString)& vals);
78   
79   //! Declares this ListEditor to have been touched (whatever action)
80   Standard_EXPORT void SetTouched();
81   
82   //! Clears all editions already recorded
83   Standard_EXPORT void ClearEdit();
84   
85   //! Loads a new list to replace the older one, in once !
86   //! By default (can be redefined) checks the length of the list
87   //! and the value of each item according to the def
88   //! Items are all recorded as Modified
89   //!
90   //! If no def has been given at creation time, no check is done
91   //! Returns True when done, False if checks have failed ... a
92   //! specialisation may also lock it by returning always False ...
93   Standard_EXPORT virtual Standard_Boolean LoadEdited (const Handle(TColStd_HSequenceOfHAsciiString)& list);
94   
95   //! Sets a new value for the item <num> (in edited list)
96   //! <val> may be a Null Handle, then the value will be cleared but
97   //! not removed
98   //! Returns True when done. False if <num> is out of range or if
99   //! <val> does not satisfy the definition
100   Standard_EXPORT virtual Standard_Boolean SetValue (const Standard_Integer num, const Handle(TCollection_HAsciiString)& val);
101   
102   //! Adds a new item. By default appends (at the end of the list)
103   //! Can insert before a given rank <num>, if positive
104   //! Returns True when done. False if MaxLength may be overpassed
105   //! or if <val> does not satisfy the definition
106   Standard_EXPORT virtual Standard_Boolean AddValue (const Handle(TCollection_HAsciiString)& val, const Standard_Integer atnum = 0);
107   
108   //! Removes items from the list
109   //! By default removes one item. Else, count given by <howmany>
110   //! Remove from rank <num> included. By default, from the end
111   //! Returns True when done, False (and does not work) if case of
112   //! out of range of if <howmany> is greater than current length
113   Standard_EXPORT virtual Standard_Boolean Remove (const Standard_Integer num = 0, const Standard_Integer howmany = 1);
114   
115   //! Returns the value from which the edition started
116   Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) OriginalValues() const;
117   
118   //! Returns the result of the edition
119   Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) EditedValues() const;
120   
121   //! Returns count of values, edited (D) or original
122   Standard_EXPORT Standard_Integer NbValues (const Standard_Boolean edited = Standard_True) const;
123   
124   //! Returns a value given its rank. Edited (D) or Original
125   //! A Null String means the value is cleared but not removed
126   Standard_EXPORT Handle(TCollection_HAsciiString) Value (const Standard_Integer num, const Standard_Boolean edited = Standard_True) const;
127   
128   //! Tells if a value (in edited list) has been changed, i.e.
129   //! either modified-value, or added
130   Standard_EXPORT Standard_Boolean IsChanged (const Standard_Integer num) const;
131   
132   //! Tells if a value (in edited list) has been modified-value
133   //! (not added)
134   Standard_EXPORT Standard_Boolean IsModified (const Standard_Integer num) const;
135   
136   //! Tells if a value (in edited list) has been added (new one)
137   Standard_EXPORT Standard_Boolean IsAdded (const Standard_Integer num) const;
138   
139   //! Tells if at least one edition (SetValue-AddValue-Remove) has
140   //! been recorded
141   Standard_EXPORT Standard_Boolean IsTouched() const;
142
143
144
145
146   DEFINE_STANDARD_RTTIEXT(IFSelect_ListEditor,Standard_Transient)
147
148 protected:
149
150
151
152
153 private:
154
155
156   Standard_Integer themax;
157   Handle(Interface_TypedValue) thedef;
158   Standard_Integer thetouc;
159   Handle(TColStd_HSequenceOfHAsciiString) theorig;
160   Handle(TColStd_HSequenceOfHAsciiString) theedit;
161   Handle(TColStd_HSequenceOfInteger) thestat;
162   Handle(Interface_InterfaceModel) themodl;
163
164
165 };
166
167
168
169
170
171
172
173 #endif // _IFSelect_ListEditor_HeaderFile