1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Dico_DictionaryOfInteger.hxx>
16 #include <IFSelect_EditForm.hxx>
17 #include <IFSelect_Editor.hxx>
18 #include <IFSelect_ListEditor.hxx>
19 #include <Interface_InterfaceModel.hxx>
20 #include <Interface_MSG.hxx>
21 #include <Interface_TypedValue.hxx>
22 #include <Message_Messenger.hxx>
23 #include <Standard_OutOfRange.hxx>
24 #include <Standard_Transient.hxx>
25 #include <Standard_Type.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TCollection_HAsciiString.hxx>
30 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_Editor,MMgt_TShared)
32 IFSelect_Editor::IFSelect_Editor (const Standard_Integer nbval)
33 : thenbval (nbval) , themaxsh (0) , themaxco (0) , themaxla (0) ,
34 thevalues (1,nbval) , theshorts (1,nbval) , themodes (1,nbval) ,
36 { thenames = new Dico_DictionaryOfInteger; thelists.Init(-1); }
38 void IFSelect_Editor::SetNbValues (const Standard_Integer nbval)
40 if (nbval > thevalues.Upper()) Standard_OutOfRange::Raise("IFSelect_Editor:SetNbValues");
44 void IFSelect_Editor::SetValue
45 (const Standard_Integer num, const Handle(Interface_TypedValue)& typval,
46 const Standard_CString shortname, const IFSelect_EditValue editmode)
48 if (num < 1 || num > thenbval) return;
49 TCollection_AsciiString shn (shortname);
50 Standard_Integer lng = shn.Length();
51 if (lng > 0) thenames->SetItem (shortname,num);
52 if (lng > themaxsh) themaxsh = lng;
53 lng = (Standard_Integer) strlen (typval->Name());
54 if (lng > themaxco) themaxco = lng;
55 lng = (Standard_Integer) strlen (typval->Label());
56 if (lng > themaxla) themaxla = lng;
58 thenames->SetItem (typval->Name(),num);
59 Standard_Integer edm = (Standard_Integer) editmode;
60 thevalues.SetValue (num,typval);
61 theshorts.SetValue (num,shn);
62 themodes.SetValue (num,edm);
65 void IFSelect_Editor::SetList
66 (const Standard_Integer num, const Standard_Integer max)
68 if (num < 1 || num > thenbval) return;
69 thelists.SetValue (num,max);
72 Standard_Integer IFSelect_Editor::NbValues () const
75 Handle(Interface_TypedValue) IFSelect_Editor::TypedValue
76 (const Standard_Integer num) const
77 { return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num)); }
79 Standard_Boolean IFSelect_Editor::IsList (const Standard_Integer num) const
81 if (num < 1 || num > thenbval) return Standard_False;
82 return (thelists.Value(num) >= 0);
85 Standard_Integer IFSelect_Editor::MaxList (const Standard_Integer num) const
87 if (num < 1 || num > thenbval) return -1;
88 return thelists.Value(num);
91 Standard_CString IFSelect_Editor::Name
92 (const Standard_Integer num, const Standard_Boolean isshort) const
94 if (num < 1 || num > thenbval) return "";
95 if (isshort) return theshorts.Value (num).ToCString();
96 else return TypedValue (num)->Name();
99 IFSelect_EditValue IFSelect_Editor::EditMode
100 (const Standard_Integer num) const
102 if (num < 1 || num > thenbval) return IFSelect_EditDynamic;
103 Standard_Integer edm = themodes.Value(num);
104 return (IFSelect_EditValue) edm;
107 void IFSelect_Editor::PrintNames (const Handle(Message_Messenger)& S) const
109 Standard_Integer i, nb = NbValues();
110 S<<"**** Editor : "<<Label()<<endl;
111 S<<"**** Nb Values = "<<nb<<" **** Names / Labels"<<endl;
113 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" ";
114 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<" Label"<<endl;
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<<" ";
121 const TCollection_AsciiString& sho = theshorts(i);
122 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
124 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<" "<<tv->Label()<<endl;
128 void IFSelect_Editor::PrintDefs
129 (const Handle(Message_Messenger)& S, const Standard_Boolean labels) const
131 Standard_Integer i, nb = NbValues();
132 S<<"**** Editor : "<<Label()<<endl;
133 S<<"**** Nb Values = "<<nb<<" **** "<<(labels ? "Labels" : "Names")<<" / Definitions"<<endl;
135 if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla);
137 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1);
138 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco);
140 S<<" Edit Mode & Definition"<<endl;
142 for (i = 1; i <= nb; i ++) {
143 Handle(Interface_TypedValue) tv = TypedValue(i);
144 if (tv.IsNull()) continue;
145 S<<" "<<Interface_MSG::Blanks(i,3)<<i<<" ";
146 if (labels) S<<tv->Label()<<Interface_MSG::Blanks(tv->Label(),themaxla);
149 const TCollection_AsciiString& sho = theshorts(i);
150 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
152 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco);
156 Standard_Integer maxls = MaxList (i);
157 if (maxls == 0) S<<" (List) ";
158 else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) ";
160 IFSelect_EditValue edm = EditMode (i);
162 case IFSelect_Optional : S<<"Optional "; break;
163 case IFSelect_Editable : S<<"Editable "; break;
164 case IFSelect_EditProtected : S<<"Protected"; break;
165 case IFSelect_EditComputed : S<<"Computed "; break;
166 case IFSelect_EditRead : S<<"ReadOnly "; break;
167 case IFSelect_EditDynamic : S<<"Dynamic "; break;
168 default : S<<"?????????"; break;
171 S<<" "<<tv->Definition()<<endl;
176 Standard_Integer IFSelect_Editor::MaxNameLength
177 (const Standard_Integer what) const
179 if (what == -1) return themaxsh;
180 if (what == 0) return themaxco;
181 if (what == 1) return themaxla;
186 Standard_Integer IFSelect_Editor::NameNumber
187 (const Standard_CString name) const
189 Standard_Integer res;
190 if (thenames->GetItem(name,res,Standard_False)) return res;
191 res = atoi (name); // si c est un entier, on tente le coup
192 if (res < 1 || res > NbValues()) res = 0;
197 Handle(IFSelect_EditForm) IFSelect_Editor::Form
198 (const Standard_Boolean readonly, const Standard_Boolean undoable) const
200 return new IFSelect_EditForm (this,readonly,undoable,Label().ToCString());
203 Handle(IFSelect_ListEditor) IFSelect_Editor::ListEditor
204 (const Standard_Integer num) const
206 Handle(IFSelect_ListEditor) led;
207 Standard_Integer max = MaxList (num);
208 if (max < 0) return led;
209 led = new IFSelect_ListEditor (TypedValue(num),max);
213 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_Editor::ListValue
214 (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/) const
216 Handle(TColStd_HSequenceOfHAsciiString) list;
221 Standard_Boolean IFSelect_Editor::Update
222 (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/,
223 const Handle(TCollection_HAsciiString)& /*newval*/,
224 const Standard_Boolean /*enforce*/) const
225 { return Standard_True; }
227 Standard_Boolean IFSelect_Editor::UpdateList
228 (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/,
229 const Handle(TColStd_HSequenceOfHAsciiString)& /*newval*/,
230 const Standard_Boolean /*enforce*/) const
231 { return Standard_True; }