7fd59977 |
1 | #include <IFSelect_Editor.ixx> |
2 | #include <Interface_MSG.hxx> |
3 | #include <string.h> |
4 | |
5 | |
6 | IFSelect_Editor::IFSelect_Editor (const Standard_Integer nbval) |
7 | : thenbval (nbval) , themaxsh (0) , themaxco (0) , themaxla (0) , |
8 | thevalues (1,nbval) , theshorts (1,nbval) , themodes (1,nbval) , |
9 | thelists (1,nbval) |
10 | { thenames = new Dico_DictionaryOfInteger; thelists.Init(-1); } |
11 | |
12 | void IFSelect_Editor::SetNbValues (const Standard_Integer nbval) |
13 | { |
14 | if (nbval > thevalues.Upper()) Standard_OutOfRange::Raise("IFSelect_Editor:SetNbValues"); |
15 | thenbval = nbval; |
16 | } |
17 | |
18 | void IFSelect_Editor::SetValue |
19 | (const Standard_Integer num, const Handle(Interface_TypedValue)& typval, |
20 | const Standard_CString shortname, const IFSelect_EditValue editmode) |
21 | { |
22 | if (num < 1 || num > thenbval) return; |
23 | TCollection_AsciiString shn (shortname); |
24 | Standard_Integer lng = shn.Length(); |
25 | if (lng > 0) thenames->SetItem (shortname,num); |
26 | if (lng > themaxsh) themaxsh = lng; |
27 | lng = strlen (typval->Name()); |
28 | if (lng > themaxco) themaxco = lng; |
29 | lng = strlen (typval->Label()); |
30 | if (lng > themaxla) themaxla = lng; |
31 | |
32 | thenames->SetItem (typval->Name(),num); |
33 | Standard_Integer edm = (Standard_Integer) editmode; |
34 | thevalues.SetValue (num,typval); |
35 | theshorts.SetValue (num,shn); |
36 | themodes.SetValue (num,edm); |
37 | } |
38 | |
39 | void IFSelect_Editor::SetList |
40 | (const Standard_Integer num, const Standard_Integer max) |
41 | { |
42 | if (num < 1 || num > thenbval) return; |
43 | thelists.SetValue (num,max); |
44 | } |
45 | |
46 | Standard_Integer IFSelect_Editor::NbValues () const |
47 | { return thenbval; } |
48 | |
49 | Handle(Interface_TypedValue) IFSelect_Editor::TypedValue |
50 | (const Standard_Integer num) const |
51 | { return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num)); } |
52 | |
53 | Standard_Boolean IFSelect_Editor::IsList (const Standard_Integer num) const |
54 | { |
55 | if (num < 1 || num > thenbval) return Standard_False; |
56 | return (thelists.Value(num) >= 0); |
57 | } |
58 | |
59 | Standard_Integer IFSelect_Editor::MaxList (const Standard_Integer num) const |
60 | { |
61 | if (num < 1 || num > thenbval) return -1; |
62 | return thelists.Value(num); |
63 | } |
64 | |
65 | Standard_CString IFSelect_Editor::Name |
66 | (const Standard_Integer num, const Standard_Boolean isshort) const |
67 | { |
68 | if (num < 1 || num > thenbval) return ""; |
69 | if (isshort) return theshorts.Value (num).ToCString(); |
70 | else return TypedValue (num)->Name(); |
71 | } |
72 | |
73 | IFSelect_EditValue IFSelect_Editor::EditMode |
74 | (const Standard_Integer num) const |
75 | { |
76 | if (num < 1 || num > thenbval) return IFSelect_EditDynamic; |
77 | Standard_Integer edm = themodes.Value(num); |
78 | return (IFSelect_EditValue) edm; |
79 | } |
80 | |
81 | void IFSelect_Editor::PrintNames (const Handle(Message_Messenger)& S) const |
82 | { |
83 | Standard_Integer i, nb = NbValues(); |
84 | S<<"**** Editor : "<<Label()<<endl; |
85 | S<<"**** Nb Values = "<<nb<<" **** Names / Labels"<<endl; |
86 | S<<" Num "; |
87 | if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" "; |
88 | S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<" Label"<<endl; |
89 | |
90 | for (i = 1; i <= nb; i ++) { |
91 | Handle(Interface_TypedValue) tv = TypedValue(i); |
92 | if (tv.IsNull()) continue; |
93 | S<<Interface_MSG::Blanks(i,3)<<i<<" "; |
94 | if (themaxsh > 0) { |
95 | const TCollection_AsciiString& sho = theshorts(i); |
96 | S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" "; |
97 | } |
98 | S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<" "<<tv->Label()<<endl; |
99 | } |
100 | } |
101 | |
102 | void IFSelect_Editor::PrintDefs |
103 | (const Handle(Message_Messenger)& S, const Standard_Boolean labels) const |
104 | { |
105 | Standard_Integer i, nb = NbValues(); |
106 | S<<"**** Editor : "<<Label()<<endl; |
107 | S<<"**** Nb Values = "<<nb<<" **** "<<(labels ? "Labels" : "Names")<<" / Definitions"<<endl; |
108 | S<<" Num "; |
109 | if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla); |
110 | else { |
111 | if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1); |
112 | S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco); |
113 | } |
114 | S<<" Edit Mode & Definition"<<endl; |
115 | |
116 | for (i = 1; i <= nb; i ++) { |
117 | Handle(Interface_TypedValue) tv = TypedValue(i); |
118 | if (tv.IsNull()) continue; |
119 | S<<" "<<Interface_MSG::Blanks(i,3)<<i<<" "; |
120 | if (labels) S<<tv->Label()<<Interface_MSG::Blanks(tv->Label(),themaxla); |
121 | else { |
122 | if (themaxsh > 0) { |
123 | const TCollection_AsciiString& sho = theshorts(i); |
124 | S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" "; |
125 | } |
126 | S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco); |
127 | } |
128 | |
129 | S<<" "; |
130 | Standard_Integer maxls = MaxList (i); |
131 | if (maxls == 0) S<<" (List) "; |
132 | else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) "; |
133 | else S<<" "; |
134 | IFSelect_EditValue edm = EditMode (i); |
135 | switch (edm) { |
136 | case IFSelect_Optional : S<<"Optional "; break; |
137 | case IFSelect_Editable : S<<"Editable "; break; |
138 | case IFSelect_EditProtected : S<<"Protected"; break; |
139 | case IFSelect_EditComputed : S<<"Computed "; break; |
140 | case IFSelect_EditRead : S<<"ReadOnly "; break; |
141 | case IFSelect_EditDynamic : S<<"Dynamic "; break; |
142 | default : S<<"?????????"; break; |
143 | } |
144 | |
145 | S<<" "<<tv->Definition()<<endl; |
146 | } |
147 | } |
148 | |
149 | |
150 | Standard_Integer IFSelect_Editor::MaxNameLength |
151 | (const Standard_Integer what) const |
152 | { |
153 | if (what == -1) return themaxsh; |
154 | if (what == 0) return themaxco; |
155 | if (what == 1) return themaxla; |
156 | return 0; |
157 | } |
158 | |
159 | |
160 | Standard_Integer IFSelect_Editor::NameNumber |
161 | (const Standard_CString name) const |
162 | { |
163 | Standard_Integer res; |
164 | if (thenames->GetItem(name,res,Standard_False)) return res; |
165 | res = atoi (name); // si c est un entier, on tente le coup |
166 | if (res < 1 || res > NbValues()) res = 0; |
167 | return res; |
168 | } |
169 | |
170 | |
171 | Handle(IFSelect_EditForm) IFSelect_Editor::Form |
172 | (const Standard_Boolean readonly, const Standard_Boolean undoable) const |
173 | { |
174 | return new IFSelect_EditForm (this,readonly,undoable,Label().ToCString()); |
175 | } |
176 | |
177 | Handle(IFSelect_ListEditor) IFSelect_Editor::ListEditor |
178 | (const Standard_Integer num) const |
179 | { |
180 | Handle(IFSelect_ListEditor) led; |
181 | Standard_Integer max = MaxList (num); |
182 | if (max < 0) return led; |
183 | led = new IFSelect_ListEditor (TypedValue(num),max); |
184 | return led; |
185 | } |
186 | |
187 | Handle(TColStd_HSequenceOfHAsciiString) IFSelect_Editor::ListValue |
188 | (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/) const |
189 | { |
190 | Handle(TColStd_HSequenceOfHAsciiString) list; |
191 | return list; |
192 | } |
193 | |
194 | |
195 | Standard_Boolean IFSelect_Editor::Update |
196 | (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/, |
197 | const Handle(TCollection_HAsciiString)& /*newval*/, |
198 | const Standard_Boolean /*enforce*/) const |
199 | { return Standard_True; } |
200 | |
201 | Standard_Boolean IFSelect_Editor::UpdateList |
202 | (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/, |
203 | const Handle(TColStd_HSequenceOfHAsciiString)& /*newval*/, |
204 | const Standard_Boolean /*enforce*/) const |
205 | { return Standard_True; } |