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 _IFSelect_EditForm_HeaderFile |
18 | #define _IFSelect_EditForm_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_Type.hxx> |
22 | |
23 | #include <Standard_Boolean.hxx> |
24 | #include <TCollection_AsciiString.hxx> |
25 | #include <TColStd_Array1OfInteger.hxx> |
26 | #include <TColStd_Array1OfTransient.hxx> |
27 | #include <Standard_Integer.hxx> |
25e59720 |
28 | #include <Standard_Transient.hxx> |
42cf5bc1 |
29 | #include <Standard_CString.hxx> |
30 | #include <TColStd_SequenceOfInteger.hxx> |
31 | #include <TColStd_HSequenceOfHAsciiString.hxx> |
32 | class IFSelect_Editor; |
33 | class Standard_Transient; |
34 | class Interface_InterfaceModel; |
35 | class IFSelect_ListEditor; |
36 | class TCollection_HAsciiString; |
42cf5bc1 |
37 | |
38 | class IFSelect_EditForm; |
25e59720 |
39 | DEFINE_STANDARD_HANDLE(IFSelect_EditForm, Standard_Transient) |
42cf5bc1 |
40 | |
41 | //! An EditForm is the way to apply an Editor on an Entity or on |
42 | //! the Model |
43 | //! It gives read-only or read-write access, with or without undo |
44 | //! |
45 | //! It can be complete (all the values of the Editor are present) |
46 | //! or partial (a sub-list of these value are present) |
47 | //! Anyway, all references to Number (argument <num>) refer to |
48 | //! Number of Value for the Editor |
49 | //! While references to Rank are for rank in the EditForm, which |
50 | //! may differ if it is not Complete |
51 | //! Two methods give the correspondance between this Number and |
52 | //! the Rank in the EditForm : RankFromNumber and NumberFromRank |
25e59720 |
53 | class IFSelect_EditForm : public Standard_Transient |
42cf5bc1 |
54 | { |
55 | |
56 | public: |
57 | |
58 | |
59 | //! Creates a complete EditForm from an Editor |
60 | //! A specific Label can be given |
61 | Standard_EXPORT IFSelect_EditForm(const Handle(IFSelect_Editor)& editor, const Standard_Boolean readonly, const Standard_Boolean undoable, const Standard_CString label = ""); |
62 | |
63 | //! Creates an extracted EditForm from an Editor, limited to |
64 | //! the values identified in <nums> |
65 | //! A specific Label can be given |
66 | Standard_EXPORT IFSelect_EditForm(const Handle(IFSelect_Editor)& editor, const TColStd_SequenceOfInteger& nums, const Standard_Boolean readonly, const Standard_Boolean undoable, const Standard_CString label = ""); |
67 | |
68 | //! Returns and may change the keep status on modif |
69 | //! It starts as False |
70 | //! If it is True, Apply does not clear modification status |
71 | //! and the EditForm can be loaded again, modified value remain |
72 | //! and may be applied again |
73 | //! Remark that ApplyData does not clear the modification status, |
74 | //! a call to ClearEdit does |
75 | Standard_EXPORT Standard_Boolean& EditKeepStatus(); |
76 | |
77 | Standard_EXPORT Standard_CString Label() const; |
78 | |
79 | //! Tells if the EditForm is loaded now |
80 | Standard_EXPORT Standard_Boolean IsLoaded() const; |
81 | |
82 | Standard_EXPORT void ClearData(); |
83 | |
84 | Standard_EXPORT void SetData (const Handle(Standard_Transient)& ent, const Handle(Interface_InterfaceModel)& model); |
85 | |
86 | Standard_EXPORT void SetEntity (const Handle(Standard_Transient)& ent); |
87 | |
88 | Standard_EXPORT void SetModel (const Handle(Interface_InterfaceModel)& model); |
89 | |
90 | Standard_EXPORT Handle(Standard_Transient) Entity() const; |
91 | |
92 | Standard_EXPORT Handle(Interface_InterfaceModel) Model() const; |
93 | |
94 | Standard_EXPORT Handle(IFSelect_Editor) Editor() const; |
95 | |
96 | //! Tells if an EditForm is complete or is an extract from Editor |
97 | Standard_EXPORT Standard_Boolean IsComplete() const; |
98 | |
99 | //! Returns the count of values |
100 | //! <editable> True : count of editable values, i.e. |
101 | //! For a complete EditForm, it is given by the Editor |
102 | //! Else, it is the length of the extraction map |
103 | //! <editable> False : all the values from the Editor |
104 | Standard_EXPORT Standard_Integer NbValues (const Standard_Boolean editable) const; |
105 | |
106 | //! Returns the Value Number in the Editor from a given Rank in |
107 | //! the EditForm |
108 | //! For a complete EditForm, both are equal |
109 | //! Else, it is given by the extraction map |
110 | //! Returns 0 if <rank> exceeds the count of editable values, |
111 | Standard_EXPORT Standard_Integer NumberFromRank (const Standard_Integer rank) const; |
112 | |
113 | //! Returns the Rank in the EditForm from a given Number of Value |
114 | //! for the Editor |
115 | //! For a complete EditForm, both are equal |
116 | //! Else, it is given by the extraction map |
117 | //! Returns 0 if <number> is not forecast to be edited, or is |
118 | //! out of range |
119 | Standard_EXPORT Standard_Integer RankFromNumber (const Standard_Integer number) const; |
120 | |
121 | //! Returns the Value Number in the Editor for a given Name |
122 | //! i.e. the true ValueNumber which can be used in various methods |
123 | //! of EditForm |
124 | //! If it is not complete, for a recorded (in the Editor) but |
125 | //! non-loaded name, returns negative value (- number) |
126 | Standard_EXPORT Standard_Integer NameNumber (const Standard_CString name) const; |
127 | |
128 | //! Returns the Rank of Value in the EditForm for a given Name |
129 | //! i.e. if it is not complete, for a recorded (in the Editor) but |
130 | //! non-loaded name, returns 0 |
131 | Standard_EXPORT Standard_Integer NameRank (const Standard_CString name) const; |
132 | |
133 | //! For a read-write undoable EditForm, loads original values |
134 | //! from defaults stored in the Editor |
135 | Standard_EXPORT void LoadDefault(); |
136 | |
137 | //! Loads modifications to data |
138 | //! Default uses Editor. Can be redefined |
139 | //! Remark that <ent> and/or <model> may be null, according to the |
140 | //! kind of Editor. Shortcuts are available for these cases, but |
141 | //! they finally call LoadData (hence, just ignore non-used args) |
142 | Standard_EXPORT virtual Standard_Boolean LoadData (const Handle(Standard_Transient)& ent, const Handle(Interface_InterfaceModel)& model); |
143 | |
144 | //! Shortcut for LoadData when <model> is not used |
145 | Standard_EXPORT Standard_Boolean LoadEntity (const Handle(Standard_Transient)& ent); |
146 | |
147 | //! Shortcut for LoadData when only the model is concerned |
148 | Standard_EXPORT Standard_Boolean LoadModel (const Handle(Interface_InterfaceModel)& model); |
149 | |
150 | //! Shortcut when both <ent> and <model> are not used |
151 | //! (when the Editor works on fully static or global data) |
152 | Standard_EXPORT Standard_Boolean LoadData(); |
153 | |
154 | //! Returns a ListEditor to edit the parameter <num> of the |
155 | //! EditForm, if it is a List |
156 | //! The Editor created it (by ListEditor) then loads it (by |
157 | //! ListValue) |
158 | //! For a single parameter, returns a Null Handle ... |
159 | Standard_EXPORT Handle(IFSelect_ListEditor) ListEditor (const Standard_Integer num) const; |
160 | |
161 | //! Loads an original value (single). Called by the Editor only |
162 | Standard_EXPORT void LoadValue (const Standard_Integer num, const Handle(TCollection_HAsciiString)& val); |
163 | |
164 | //! Loads an original value as a list. Called by the Editor only |
165 | Standard_EXPORT void LoadList (const Standard_Integer num, const Handle(TColStd_HSequenceOfHAsciiString)& list); |
166 | |
167 | //! From an edited value, returns its ... value (original one) |
168 | //! Null means that this value is not defined |
169 | //! <num> is for the EditForm, not the Editor |
170 | //! It is for a single parameter. For a list, gives a Null Handle |
171 | Standard_EXPORT Handle(TCollection_HAsciiString) OriginalValue (const Standard_Integer num) const; |
172 | |
173 | //! Returns an original value, as a list |
174 | //! <num> is for the EditForm, not the Editor |
175 | //! For a single parameter, gives a Null Handle |
176 | Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) OriginalList (const Standard_Integer num) const; |
177 | |
178 | //! Returns the Edited (i.e. Modified) Value (string for single) |
179 | //! <num> reports to the EditForm |
180 | //! If IsModified is False, returns OriginalValue |
181 | //! Null with IsModified True : means that this value is not |
182 | //! defined or has been removed |
183 | //! It is for a single parameter. For a list, gives a Null Handle |
184 | Standard_EXPORT Handle(TCollection_HAsciiString) EditedValue (const Standard_Integer num) const; |
185 | |
186 | //! Returns the Edited Value as a list |
187 | //! If IsModified is False, returns OriginalValue |
188 | //! Null with IsModified True : means that this value is not |
189 | //! defined or has been removed |
190 | //! For a single parameter, gives a Null Handle |
191 | Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) EditedList (const Standard_Integer num) const; |
192 | |
193 | //! Tells if a Value (of the EditForm) is modified (directly or |
194 | //! through touching by Update) |
195 | Standard_EXPORT Standard_Boolean IsModified (const Standard_Integer num) const; |
196 | |
197 | //! Tells if a Value (of the EditForm) has been touched, i.e. |
198 | //! not modified directly but by the modification of another one |
199 | //! (by method Update from the Editor) |
200 | Standard_EXPORT Standard_Boolean IsTouched (const Standard_Integer num) const; |
201 | |
202 | //! Gives a new value for the item <num> of the EditForm, if |
203 | //! it is a single parameter (for a list, just returns False) |
204 | //! Null means to Remove it |
205 | //! <enforce> True to overpass Protected or Computed Access Mode |
206 | //! Calls the method Update from the Editor, which can touch other |
207 | //! parameters (see NbTouched) |
208 | //! Returns True if well recorded, False if this value is not |
209 | //! allowed |
210 | //! Warning : Does not apply immediately : will be applied by the method |
211 | //! Apply |
212 | Standard_EXPORT Standard_Boolean Modify (const Standard_Integer num, const Handle(TCollection_HAsciiString)& newval, const Standard_Boolean enforce = Standard_False); |
213 | |
214 | //! Changes the value of an item of the EditForm, if it is a List |
215 | //! (else, just returns False) |
216 | //! The ListEditor contains the edited values of the list |
217 | //! If no edition was recorded, just returns False |
218 | //! Calls the method Update from the Editor, which can touch other |
219 | //! parameters (see NbTouched) |
220 | //! Returns True if well recorded, False if this value is not |
221 | //! allowed |
222 | //! Warning : Does not apply immediately : will be applied by the method |
223 | //! Apply |
224 | Standard_EXPORT Standard_Boolean ModifyList (const Standard_Integer num, const Handle(IFSelect_ListEditor)& edited, const Standard_Boolean enforce = Standard_False); |
225 | |
226 | //! As ModifyList but the new value is given as such |
227 | //! Creates a ListEditor, Loads it, then calls ModifyList |
228 | Standard_EXPORT Standard_Boolean ModifyListValue (const Standard_Integer num, const Handle(TColStd_HSequenceOfHAsciiString)& list, const Standard_Boolean enforce = Standard_False); |
229 | |
230 | //! Gives a new value computed by the Editor, if another parameter |
231 | //! commands the value of <num> |
232 | //! It is generally the case for a Computed Parameter for instance |
233 | //! Increments the counter of touched parameters |
234 | //! Warning : it gives no protection for ReadOnly etc... while it is the |
235 | //! internal way of touching parameters |
236 | //! Does not work (returns False) if <num> is for a list |
237 | Standard_EXPORT Standard_Boolean Touch (const Standard_Integer num, const Handle(TCollection_HAsciiString)& newval); |
238 | |
239 | //! Acts as Touch but for a list |
240 | //! Does not work (returns False) if <num> is for a single param |
241 | Standard_EXPORT Standard_Boolean TouchList (const Standard_Integer num, const Handle(TColStd_HSequenceOfHAsciiString)& newlist); |
242 | |
243 | //! Returns the count of parameters touched by the last Modify |
244 | //! (apart from the modified parameter itself) |
245 | //! Normally it is zero |
246 | Standard_EXPORT Standard_Integer NbTouched() const; |
247 | |
248 | //! Clears modification status : by default all, or one by its |
249 | //! numbers (in the Editor) |
250 | Standard_EXPORT void ClearEdit (const Standard_Integer num = 0); |
251 | |
252 | //! Prints Definitions, relative to the Editor |
0ebe5b0a |
253 | Standard_EXPORT void PrintDefs (Standard_OStream& S) const; |
42cf5bc1 |
254 | |
255 | //! Prints Values, according to what and alsolist |
256 | //! <names> True : prints Long Names; False : prints Short Names |
257 | //! <what> < 0 : prints Original Values (+ flag Modified) |
258 | //! <what> > 0 : prints Final Values (+flag Modified) |
259 | //! <what> = 0 : prints Modified Values (Original + Edited) |
260 | //! <alsolist> False (D) : lists are printed only as their count |
261 | //! <alsolist> True : lists are printed for all their items |
0ebe5b0a |
262 | Standard_EXPORT void PrintValues (Standard_OStream& S, const Standard_Integer what, const Standard_Boolean names, const Standard_Boolean alsolist = Standard_False) const; |
42cf5bc1 |
263 | |
264 | //! Applies modifications to own data |
265 | //! Calls ApplyData then Clears Status according EditKeepStatus |
266 | Standard_EXPORT Standard_Boolean Apply(); |
267 | |
268 | //! Tells if this EditForm can work with its Editor and its actual |
269 | //! Data (Entity and Model) |
270 | //! Default uses Editor. Can be redefined |
271 | Standard_EXPORT virtual Standard_Boolean Recognize() const; |
272 | |
273 | //! Applies modifications to data |
274 | //! Default uses Editor. Can be redefined |
275 | Standard_EXPORT virtual Standard_Boolean ApplyData (const Handle(Standard_Transient)& ent, const Handle(Interface_InterfaceModel)& model); |
276 | |
277 | //! For an undoable EditForm, Applies ... origibal values ! |
278 | //! and clears modified ones |
279 | //! Can be run only once |
280 | Standard_EXPORT Standard_Boolean Undo(); |
281 | |
282 | |
283 | |
284 | |
25e59720 |
285 | DEFINE_STANDARD_RTTIEXT(IFSelect_EditForm,Standard_Transient) |
42cf5bc1 |
286 | |
287 | protected: |
288 | |
289 | |
290 | |
291 | |
292 | private: |
293 | |
294 | |
295 | Standard_Boolean thecomplete; |
296 | Standard_Boolean theloaded; |
297 | Standard_Boolean thekeepst; |
298 | TCollection_AsciiString thelabel; |
299 | TColStd_Array1OfInteger thenums; |
300 | TColStd_Array1OfTransient theorigs; |
301 | TColStd_Array1OfTransient themodifs; |
302 | TColStd_Array1OfInteger thestatus; |
303 | Handle(IFSelect_Editor) theeditor; |
304 | Handle(Standard_Transient) theent; |
305 | Handle(Interface_InterfaceModel) themodel; |
306 | Standard_Integer thetouched; |
307 | |
308 | |
309 | }; |
310 | |
311 | |
312 | |
313 | |
314 | |
315 | |
316 | |
317 | #endif // _IFSelect_EditForm_HeaderFile |