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