0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / IFSelect / IFSelect_Editor.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#include <IFSelect_Editor.ixx>
15#include <Interface_MSG.hxx>
ec357c5c 16#include <Interface_TypedValue.hxx>
7fd59977 17#include <string.h>
18
19
b311480e 20IFSelect_Editor::IFSelect_Editor (const Standard_Integer nbval)
7fd59977 21 : thenbval (nbval) , themaxsh (0) , themaxco (0) , themaxla (0) ,
22 thevalues (1,nbval) , theshorts (1,nbval) , themodes (1,nbval) ,
23 thelists (1,nbval)
24 { thenames = new Dico_DictionaryOfInteger; thelists.Init(-1); }
25
26 void IFSelect_Editor::SetNbValues (const Standard_Integer nbval)
27{
28 if (nbval > thevalues.Upper()) Standard_OutOfRange::Raise("IFSelect_Editor:SetNbValues");
29 thenbval = nbval;
30}
31
32 void IFSelect_Editor::SetValue
33 (const Standard_Integer num, const Handle(Interface_TypedValue)& typval,
34 const Standard_CString shortname, const IFSelect_EditValue editmode)
35{
36 if (num < 1 || num > thenbval) return;
37 TCollection_AsciiString shn (shortname);
38 Standard_Integer lng = shn.Length();
39 if (lng > 0) thenames->SetItem (shortname,num);
40 if (lng > themaxsh) themaxsh = lng;
60be1f9b 41 lng = (Standard_Integer) strlen (typval->Name());
7fd59977 42 if (lng > themaxco) themaxco = lng;
60be1f9b 43 lng = (Standard_Integer) strlen (typval->Label());
7fd59977 44 if (lng > themaxla) themaxla = lng;
45
46 thenames->SetItem (typval->Name(),num);
47 Standard_Integer edm = (Standard_Integer) editmode;
48 thevalues.SetValue (num,typval);
49 theshorts.SetValue (num,shn);
50 themodes.SetValue (num,edm);
51}
52
53 void IFSelect_Editor::SetList
54 (const Standard_Integer num, const Standard_Integer max)
55{
56 if (num < 1 || num > thenbval) return;
57 thelists.SetValue (num,max);
58}
59
60 Standard_Integer IFSelect_Editor::NbValues () const
61 { return thenbval; }
62
63 Handle(Interface_TypedValue) IFSelect_Editor::TypedValue
64 (const Standard_Integer num) const
65 { return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num)); }
66
67Standard_Boolean IFSelect_Editor::IsList (const Standard_Integer num) const
68{
69 if (num < 1 || num > thenbval) return Standard_False;
70 return (thelists.Value(num) >= 0);
71}
72
73Standard_Integer IFSelect_Editor::MaxList (const Standard_Integer num) const
74{
75 if (num < 1 || num > thenbval) return -1;
76 return thelists.Value(num);
77}
78
79 Standard_CString IFSelect_Editor::Name
80 (const Standard_Integer num, const Standard_Boolean isshort) const
81{
82 if (num < 1 || num > thenbval) return "";
83 if (isshort) return theshorts.Value (num).ToCString();
84 else return TypedValue (num)->Name();
85}
86
87 IFSelect_EditValue IFSelect_Editor::EditMode
88 (const Standard_Integer num) const
89{
90 if (num < 1 || num > thenbval) return IFSelect_EditDynamic;
91 Standard_Integer edm = themodes.Value(num);
92 return (IFSelect_EditValue) edm;
93}
94
95 void IFSelect_Editor::PrintNames (const Handle(Message_Messenger)& S) const
96{
97 Standard_Integer i, nb = NbValues();
98 S<<"**** Editor : "<<Label()<<endl;
99 S<<"**** Nb Values = "<<nb<<" **** Names / Labels"<<endl;
100 S<<" Num ";
101 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" ";
102 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<" Label"<<endl;
103
104 for (i = 1; i <= nb; i ++) {
105 Handle(Interface_TypedValue) tv = TypedValue(i);
106 if (tv.IsNull()) continue;
107 S<<Interface_MSG::Blanks(i,3)<<i<<" ";
108 if (themaxsh > 0) {
109 const TCollection_AsciiString& sho = theshorts(i);
110 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
111 }
112 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<" "<<tv->Label()<<endl;
113 }
114}
115
116 void IFSelect_Editor::PrintDefs
117 (const Handle(Message_Messenger)& S, const Standard_Boolean labels) const
118{
119 Standard_Integer i, nb = NbValues();
120 S<<"**** Editor : "<<Label()<<endl;
121 S<<"**** Nb Values = "<<nb<<" **** "<<(labels ? "Labels" : "Names")<<" / Definitions"<<endl;
122 S<<" Num ";
123 if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla);
124 else {
125 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1);
126 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco);
127 }
128 S<<" Edit Mode & Definition"<<endl;
129
130 for (i = 1; i <= nb; i ++) {
131 Handle(Interface_TypedValue) tv = TypedValue(i);
132 if (tv.IsNull()) continue;
133 S<<" "<<Interface_MSG::Blanks(i,3)<<i<<" ";
134 if (labels) S<<tv->Label()<<Interface_MSG::Blanks(tv->Label(),themaxla);
135 else {
136 if (themaxsh > 0) {
137 const TCollection_AsciiString& sho = theshorts(i);
138 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
139 }
140 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco);
141 }
142
143 S<<" ";
144 Standard_Integer maxls = MaxList (i);
145 if (maxls == 0) S<<" (List) ";
146 else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) ";
147 else S<<" ";
148 IFSelect_EditValue edm = EditMode (i);
149 switch (edm) {
150 case IFSelect_Optional : S<<"Optional "; break;
151 case IFSelect_Editable : S<<"Editable "; break;
152 case IFSelect_EditProtected : S<<"Protected"; break;
153 case IFSelect_EditComputed : S<<"Computed "; break;
154 case IFSelect_EditRead : S<<"ReadOnly "; break;
155 case IFSelect_EditDynamic : S<<"Dynamic "; break;
156 default : S<<"?????????"; break;
157 }
158
159 S<<" "<<tv->Definition()<<endl;
160 }
161}
162
163
164 Standard_Integer IFSelect_Editor::MaxNameLength
165 (const Standard_Integer what) const
166{
167 if (what == -1) return themaxsh;
168 if (what == 0) return themaxco;
169 if (what == 1) return themaxla;
170 return 0;
171}
172
173
174 Standard_Integer IFSelect_Editor::NameNumber
175 (const Standard_CString name) const
176{
177 Standard_Integer res;
178 if (thenames->GetItem(name,res,Standard_False)) return res;
179 res = atoi (name); // si c est un entier, on tente le coup
180 if (res < 1 || res > NbValues()) res = 0;
181 return res;
182}
183
184
185 Handle(IFSelect_EditForm) IFSelect_Editor::Form
186 (const Standard_Boolean readonly, const Standard_Boolean undoable) const
187{
188 return new IFSelect_EditForm (this,readonly,undoable,Label().ToCString());
189}
190
191 Handle(IFSelect_ListEditor) IFSelect_Editor::ListEditor
192 (const Standard_Integer num) const
193{
194 Handle(IFSelect_ListEditor) led;
195 Standard_Integer max = MaxList (num);
196 if (max < 0) return led;
197 led = new IFSelect_ListEditor (TypedValue(num),max);
198 return led;
199}
200
201 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_Editor::ListValue
202 (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/) const
203{
204 Handle(TColStd_HSequenceOfHAsciiString) list;
205 return list;
206}
207
208
209 Standard_Boolean IFSelect_Editor::Update
210 (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/,
211 const Handle(TCollection_HAsciiString)& /*newval*/,
212 const Standard_Boolean /*enforce*/) const
213 { return Standard_True; }
214
215 Standard_Boolean IFSelect_Editor::UpdateList
216 (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/,
217 const Handle(TColStd_HSequenceOfHAsciiString)& /*newval*/,
218 const Standard_Boolean /*enforce*/) const
219 { return Standard_True; }