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 <IFSelect_EditForm.hxx>
16 #include <IFSelect_Editor.hxx>
17 #include <IFSelect_ListEditor.hxx>
18 #include <Interface_InterfaceModel.hxx>
19 #include <Interface_MSG.hxx>
20 #include <Interface_TypedValue.hxx>
21 #include <Message_Messenger.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <Standard_Transient.hxx>
24 #include <Standard_Type.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <TCollection_HAsciiString.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_Editor,Standard_Transient)
31 IFSelect_Editor::IFSelect_Editor (const Standard_Integer nbval)
32 : thenbval (nbval) , themaxsh (0) , themaxco (0) , themaxla (0) ,
33 thevalues (1,nbval) , theshorts (1,nbval) , themodes (1,nbval) ,
35 { thelists.Init(-1); }
37 void IFSelect_Editor::SetNbValues (const Standard_Integer nbval)
39 if (nbval > thevalues.Upper()) throw Standard_OutOfRange("IFSelect_Editor:SetNbValues");
43 void IFSelect_Editor::SetValue
44 (const Standard_Integer num, const Handle(Interface_TypedValue)& typval,
45 const Standard_CString shortname, const IFSelect_EditValue editmode)
47 if (num < 1 || num > thenbval) return;
48 TCollection_AsciiString shn (shortname);
49 Standard_Integer lng = shn.Length();
50 if (lng > 0) thenames.Bind (shortname,num);
51 if (lng > themaxsh) themaxsh = lng;
52 lng = (Standard_Integer) strlen (typval->Name());
53 if (lng > themaxco) themaxco = lng;
54 lng = (Standard_Integer) strlen (typval->Label());
55 if (lng > themaxla) themaxla = lng;
57 thenames.Bind (typval->Name(),num);
58 Standard_Integer edm = (Standard_Integer) editmode;
59 thevalues.SetValue (num,typval);
60 theshorts.SetValue (num,shn);
61 themodes.SetValue (num,edm);
64 void IFSelect_Editor::SetList
65 (const Standard_Integer num, const Standard_Integer max)
67 if (num < 1 || num > thenbval) return;
68 thelists.SetValue (num,max);
71 Standard_Integer IFSelect_Editor::NbValues () const
74 Handle(Interface_TypedValue) IFSelect_Editor::TypedValue
75 (const Standard_Integer num) const
76 { return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num)); }
78 Standard_Boolean IFSelect_Editor::IsList (const Standard_Integer num) const
80 if (num < 1 || num > thenbval) return Standard_False;
81 return (thelists.Value(num) >= 0);
84 Standard_Integer IFSelect_Editor::MaxList (const Standard_Integer num) const
86 if (num < 1 || num > thenbval) return -1;
87 return thelists.Value(num);
90 Standard_CString IFSelect_Editor::Name
91 (const Standard_Integer num, const Standard_Boolean isshort) const
93 if (num < 1 || num > thenbval) return "";
94 if (isshort) return theshorts.Value (num).ToCString();
95 else return TypedValue (num)->Name();
98 IFSelect_EditValue IFSelect_Editor::EditMode
99 (const Standard_Integer num) const
101 if (num < 1 || num > thenbval) return IFSelect_EditDynamic;
102 Standard_Integer edm = themodes.Value(num);
103 return (IFSelect_EditValue) edm;
106 void IFSelect_Editor::PrintNames (Standard_OStream& S) const
108 Standard_Integer i, nb = NbValues();
109 S<<"**** Editor : "<<Label()<<std::endl;
110 S<<"**** Nb Values = "<<nb<<" **** Names / Labels"<<std::endl;
112 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" ";
113 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<" Label"<<std::endl;
115 for (i = 1; i <= nb; i ++) {
116 Handle(Interface_TypedValue) tv = TypedValue(i);
117 if (tv.IsNull()) continue;
118 S<<Interface_MSG::Blanks(i,3)<<i<<" ";
120 const TCollection_AsciiString& sho = theshorts(i);
121 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
123 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<" "<<tv->Label()<<std::endl;
127 void IFSelect_Editor::PrintDefs
128 (Standard_OStream& S, const Standard_Boolean labels) const
130 Standard_Integer i, nb = NbValues();
131 S<<"**** Editor : "<<Label()<<std::endl;
132 S<<"**** Nb Values = "<<nb<<" **** "<<(labels ? "Labels" : "Names")<<" / Definitions"<<std::endl;
134 if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla);
136 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1);
137 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco);
139 S<<" Edit Mode & Definition"<<std::endl;
141 for (i = 1; i <= nb; i ++) {
142 Handle(Interface_TypedValue) tv = TypedValue(i);
143 if (tv.IsNull()) continue;
144 S<<" "<<Interface_MSG::Blanks(i,3)<<i<<" ";
145 if (labels) S<<tv->Label()<<Interface_MSG::Blanks(tv->Label(),themaxla);
148 const TCollection_AsciiString& sho = theshorts(i);
149 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
151 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco);
155 Standard_Integer maxls = MaxList (i);
156 if (maxls == 0) S<<" (List) ";
157 else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) ";
159 IFSelect_EditValue edm = EditMode (i);
161 case IFSelect_Optional : S<<"Optional "; break;
162 case IFSelect_Editable : S<<"Editable "; break;
163 case IFSelect_EditProtected : S<<"Protected"; break;
164 case IFSelect_EditComputed : S<<"Computed "; break;
165 case IFSelect_EditRead : S<<"ReadOnly "; break;
166 case IFSelect_EditDynamic : S<<"Dynamic "; break;
167 default : S<<"?????????"; break;
170 S<<" "<<tv->Definition()<<std::endl;
175 Standard_Integer IFSelect_Editor::MaxNameLength
176 (const Standard_Integer what) const
178 if (what == -1) return themaxsh;
179 if (what == 0) return themaxco;
180 if (what == 1) return themaxla;
185 Standard_Integer IFSelect_Editor::NameNumber
186 (const Standard_CString name) const
188 Standard_Integer res;
189 if (thenames.Find(name,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; }