b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #include <IFSelect_Editor.ixx> |
19 | #include <Interface_MSG.hxx> |
20 | #include <string.h> |
21 | |
22 | |
b311480e |
23 | IFSelect_Editor::IFSelect_Editor (const Standard_Integer nbval) |
7fd59977 |
24 | : thenbval (nbval) , themaxsh (0) , themaxco (0) , themaxla (0) , |
25 | thevalues (1,nbval) , theshorts (1,nbval) , themodes (1,nbval) , |
26 | thelists (1,nbval) |
27 | { thenames = new Dico_DictionaryOfInteger; thelists.Init(-1); } |
28 | |
29 | void IFSelect_Editor::SetNbValues (const Standard_Integer nbval) |
30 | { |
31 | if (nbval > thevalues.Upper()) Standard_OutOfRange::Raise("IFSelect_Editor:SetNbValues"); |
32 | thenbval = nbval; |
33 | } |
34 | |
35 | void IFSelect_Editor::SetValue |
36 | (const Standard_Integer num, const Handle(Interface_TypedValue)& typval, |
37 | const Standard_CString shortname, const IFSelect_EditValue editmode) |
38 | { |
39 | if (num < 1 || num > thenbval) return; |
40 | TCollection_AsciiString shn (shortname); |
41 | Standard_Integer lng = shn.Length(); |
42 | if (lng > 0) thenames->SetItem (shortname,num); |
43 | if (lng > themaxsh) themaxsh = lng; |
60be1f9b |
44 | lng = (Standard_Integer) strlen (typval->Name()); |
7fd59977 |
45 | if (lng > themaxco) themaxco = lng; |
60be1f9b |
46 | lng = (Standard_Integer) strlen (typval->Label()); |
7fd59977 |
47 | if (lng > themaxla) themaxla = lng; |
48 | |
49 | thenames->SetItem (typval->Name(),num); |
50 | Standard_Integer edm = (Standard_Integer) editmode; |
51 | thevalues.SetValue (num,typval); |
52 | theshorts.SetValue (num,shn); |
53 | themodes.SetValue (num,edm); |
54 | } |
55 | |
56 | void IFSelect_Editor::SetList |
57 | (const Standard_Integer num, const Standard_Integer max) |
58 | { |
59 | if (num < 1 || num > thenbval) return; |
60 | thelists.SetValue (num,max); |
61 | } |
62 | |
63 | Standard_Integer IFSelect_Editor::NbValues () const |
64 | { return thenbval; } |
65 | |
66 | Handle(Interface_TypedValue) IFSelect_Editor::TypedValue |
67 | (const Standard_Integer num) const |
68 | { return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num)); } |
69 | |
70 | Standard_Boolean IFSelect_Editor::IsList (const Standard_Integer num) const |
71 | { |
72 | if (num < 1 || num > thenbval) return Standard_False; |
73 | return (thelists.Value(num) >= 0); |
74 | } |
75 | |
76 | Standard_Integer IFSelect_Editor::MaxList (const Standard_Integer num) const |
77 | { |
78 | if (num < 1 || num > thenbval) return -1; |
79 | return thelists.Value(num); |
80 | } |
81 | |
82 | Standard_CString IFSelect_Editor::Name |
83 | (const Standard_Integer num, const Standard_Boolean isshort) const |
84 | { |
85 | if (num < 1 || num > thenbval) return ""; |
86 | if (isshort) return theshorts.Value (num).ToCString(); |
87 | else return TypedValue (num)->Name(); |
88 | } |
89 | |
90 | IFSelect_EditValue IFSelect_Editor::EditMode |
91 | (const Standard_Integer num) const |
92 | { |
93 | if (num < 1 || num > thenbval) return IFSelect_EditDynamic; |
94 | Standard_Integer edm = themodes.Value(num); |
95 | return (IFSelect_EditValue) edm; |
96 | } |
97 | |
98 | void IFSelect_Editor::PrintNames (const Handle(Message_Messenger)& S) const |
99 | { |
100 | Standard_Integer i, nb = NbValues(); |
101 | S<<"**** Editor : "<<Label()<<endl; |
102 | S<<"**** Nb Values = "<<nb<<" **** Names / Labels"<<endl; |
103 | S<<" Num "; |
104 | if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" "; |
105 | S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<" Label"<<endl; |
106 | |
107 | for (i = 1; i <= nb; i ++) { |
108 | Handle(Interface_TypedValue) tv = TypedValue(i); |
109 | if (tv.IsNull()) continue; |
110 | S<<Interface_MSG::Blanks(i,3)<<i<<" "; |
111 | if (themaxsh > 0) { |
112 | const TCollection_AsciiString& sho = theshorts(i); |
113 | S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" "; |
114 | } |
115 | S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<" "<<tv->Label()<<endl; |
116 | } |
117 | } |
118 | |
119 | void IFSelect_Editor::PrintDefs |
120 | (const Handle(Message_Messenger)& S, const Standard_Boolean labels) const |
121 | { |
122 | Standard_Integer i, nb = NbValues(); |
123 | S<<"**** Editor : "<<Label()<<endl; |
124 | S<<"**** Nb Values = "<<nb<<" **** "<<(labels ? "Labels" : "Names")<<" / Definitions"<<endl; |
125 | S<<" Num "; |
126 | if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla); |
127 | else { |
128 | if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1); |
129 | S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco); |
130 | } |
131 | S<<" Edit Mode & Definition"<<endl; |
132 | |
133 | for (i = 1; i <= nb; i ++) { |
134 | Handle(Interface_TypedValue) tv = TypedValue(i); |
135 | if (tv.IsNull()) continue; |
136 | S<<" "<<Interface_MSG::Blanks(i,3)<<i<<" "; |
137 | if (labels) S<<tv->Label()<<Interface_MSG::Blanks(tv->Label(),themaxla); |
138 | else { |
139 | if (themaxsh > 0) { |
140 | const TCollection_AsciiString& sho = theshorts(i); |
141 | S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" "; |
142 | } |
143 | S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco); |
144 | } |
145 | |
146 | S<<" "; |
147 | Standard_Integer maxls = MaxList (i); |
148 | if (maxls == 0) S<<" (List) "; |
149 | else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) "; |
150 | else S<<" "; |
151 | IFSelect_EditValue edm = EditMode (i); |
152 | switch (edm) { |
153 | case IFSelect_Optional : S<<"Optional "; break; |
154 | case IFSelect_Editable : S<<"Editable "; break; |
155 | case IFSelect_EditProtected : S<<"Protected"; break; |
156 | case IFSelect_EditComputed : S<<"Computed "; break; |
157 | case IFSelect_EditRead : S<<"ReadOnly "; break; |
158 | case IFSelect_EditDynamic : S<<"Dynamic "; break; |
159 | default : S<<"?????????"; break; |
160 | } |
161 | |
162 | S<<" "<<tv->Definition()<<endl; |
163 | } |
164 | } |
165 | |
166 | |
167 | Standard_Integer IFSelect_Editor::MaxNameLength |
168 | (const Standard_Integer what) const |
169 | { |
170 | if (what == -1) return themaxsh; |
171 | if (what == 0) return themaxco; |
172 | if (what == 1) return themaxla; |
173 | return 0; |
174 | } |
175 | |
176 | |
177 | Standard_Integer IFSelect_Editor::NameNumber |
178 | (const Standard_CString name) const |
179 | { |
180 | Standard_Integer res; |
181 | if (thenames->GetItem(name,res,Standard_False)) return res; |
182 | res = atoi (name); // si c est un entier, on tente le coup |
183 | if (res < 1 || res > NbValues()) res = 0; |
184 | return res; |
185 | } |
186 | |
187 | |
188 | Handle(IFSelect_EditForm) IFSelect_Editor::Form |
189 | (const Standard_Boolean readonly, const Standard_Boolean undoable) const |
190 | { |
191 | return new IFSelect_EditForm (this,readonly,undoable,Label().ToCString()); |
192 | } |
193 | |
194 | Handle(IFSelect_ListEditor) IFSelect_Editor::ListEditor |
195 | (const Standard_Integer num) const |
196 | { |
197 | Handle(IFSelect_ListEditor) led; |
198 | Standard_Integer max = MaxList (num); |
199 | if (max < 0) return led; |
200 | led = new IFSelect_ListEditor (TypedValue(num),max); |
201 | return led; |
202 | } |
203 | |
204 | Handle(TColStd_HSequenceOfHAsciiString) IFSelect_Editor::ListValue |
205 | (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/) const |
206 | { |
207 | Handle(TColStd_HSequenceOfHAsciiString) list; |
208 | return list; |
209 | } |
210 | |
211 | |
212 | Standard_Boolean IFSelect_Editor::Update |
213 | (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/, |
214 | const Handle(TCollection_HAsciiString)& /*newval*/, |
215 | const Standard_Boolean /*enforce*/) const |
216 | { return Standard_True; } |
217 | |
218 | Standard_Boolean IFSelect_Editor::UpdateList |
219 | (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/, |
220 | const Handle(TColStd_HSequenceOfHAsciiString)& /*newval*/, |
221 | const Standard_Boolean /*enforce*/) const |
222 | { return Standard_True; } |