0026377: Passing Handle objects as arguments to functions as non-const reference...
[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
42cf5bc1 14
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>
7fd59977 20#include <Interface_MSG.hxx>
ec357c5c 21#include <Interface_TypedValue.hxx>
42cf5bc1 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>
7fd59977 28
42cf5bc1 29#include <string.h>
92efcf78 30IMPLEMENT_STANDARD_RTTIEXT(IFSelect_Editor,MMgt_TShared)
31
b311480e 32IFSelect_Editor::IFSelect_Editor (const Standard_Integer nbval)
7fd59977 33 : thenbval (nbval) , themaxsh (0) , themaxco (0) , themaxla (0) ,
34 thevalues (1,nbval) , theshorts (1,nbval) , themodes (1,nbval) ,
35 thelists (1,nbval)
36 { thenames = new Dico_DictionaryOfInteger; thelists.Init(-1); }
37
38 void IFSelect_Editor::SetNbValues (const Standard_Integer nbval)
39{
40 if (nbval > thevalues.Upper()) Standard_OutOfRange::Raise("IFSelect_Editor:SetNbValues");
41 thenbval = nbval;
42}
43
44 void IFSelect_Editor::SetValue
45 (const Standard_Integer num, const Handle(Interface_TypedValue)& typval,
46 const Standard_CString shortname, const IFSelect_EditValue editmode)
47{
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;
60be1f9b 53 lng = (Standard_Integer) strlen (typval->Name());
7fd59977 54 if (lng > themaxco) themaxco = lng;
60be1f9b 55 lng = (Standard_Integer) strlen (typval->Label());
7fd59977 56 if (lng > themaxla) themaxla = lng;
57
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);
63}
64
65 void IFSelect_Editor::SetList
66 (const Standard_Integer num, const Standard_Integer max)
67{
68 if (num < 1 || num > thenbval) return;
69 thelists.SetValue (num,max);
70}
71
72 Standard_Integer IFSelect_Editor::NbValues () const
73 { return thenbval; }
74
75 Handle(Interface_TypedValue) IFSelect_Editor::TypedValue
76 (const Standard_Integer num) const
77 { return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num)); }
78
79Standard_Boolean IFSelect_Editor::IsList (const Standard_Integer num) const
80{
81 if (num < 1 || num > thenbval) return Standard_False;
82 return (thelists.Value(num) >= 0);
83}
84
85Standard_Integer IFSelect_Editor::MaxList (const Standard_Integer num) const
86{
87 if (num < 1 || num > thenbval) return -1;
88 return thelists.Value(num);
89}
90
91 Standard_CString IFSelect_Editor::Name
92 (const Standard_Integer num, const Standard_Boolean isshort) const
93{
94 if (num < 1 || num > thenbval) return "";
95 if (isshort) return theshorts.Value (num).ToCString();
96 else return TypedValue (num)->Name();
97}
98
99 IFSelect_EditValue IFSelect_Editor::EditMode
100 (const Standard_Integer num) const
101{
102 if (num < 1 || num > thenbval) return IFSelect_EditDynamic;
103 Standard_Integer edm = themodes.Value(num);
104 return (IFSelect_EditValue) edm;
105}
106
107 void IFSelect_Editor::PrintNames (const Handle(Message_Messenger)& S) const
108{
109 Standard_Integer i, nb = NbValues();
110 S<<"**** Editor : "<<Label()<<endl;
111 S<<"**** Nb Values = "<<nb<<" **** Names / Labels"<<endl;
112 S<<" Num ";
113 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" ";
114 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<" Label"<<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 (themaxsh > 0) {
121 const TCollection_AsciiString& sho = theshorts(i);
122 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
123 }
124 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<" "<<tv->Label()<<endl;
125 }
126}
127
128 void IFSelect_Editor::PrintDefs
129 (const Handle(Message_Messenger)& S, const Standard_Boolean labels) const
130{
131 Standard_Integer i, nb = NbValues();
132 S<<"**** Editor : "<<Label()<<endl;
133 S<<"**** Nb Values = "<<nb<<" **** "<<(labels ? "Labels" : "Names")<<" / Definitions"<<endl;
134 S<<" Num ";
135 if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla);
136 else {
137 if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1);
138 S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco);
139 }
140 S<<" Edit Mode & Definition"<<endl;
141
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);
147 else {
148 if (themaxsh > 0) {
149 const TCollection_AsciiString& sho = theshorts(i);
150 S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
151 }
152 S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco);
153 }
154
155 S<<" ";
156 Standard_Integer maxls = MaxList (i);
157 if (maxls == 0) S<<" (List) ";
158 else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) ";
159 else S<<" ";
160 IFSelect_EditValue edm = EditMode (i);
161 switch (edm) {
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;
169 }
170
171 S<<" "<<tv->Definition()<<endl;
172 }
173}
174
175
176 Standard_Integer IFSelect_Editor::MaxNameLength
177 (const Standard_Integer what) const
178{
179 if (what == -1) return themaxsh;
180 if (what == 0) return themaxco;
181 if (what == 1) return themaxla;
182 return 0;
183}
184
185
186 Standard_Integer IFSelect_Editor::NameNumber
187 (const Standard_CString name) const
188{
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;
193 return res;
194}
195
196
197 Handle(IFSelect_EditForm) IFSelect_Editor::Form
198 (const Standard_Boolean readonly, const Standard_Boolean undoable) const
199{
200 return new IFSelect_EditForm (this,readonly,undoable,Label().ToCString());
201}
202
203 Handle(IFSelect_ListEditor) IFSelect_Editor::ListEditor
204 (const Standard_Integer num) const
205{
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);
210 return led;
211}
212
213 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_Editor::ListValue
214 (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/) const
215{
216 Handle(TColStd_HSequenceOfHAsciiString) list;
217 return list;
218}
219
220
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; }
226
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; }