0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / IFSelect / IFSelect_Editor.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
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>
27
28 #include <string.h>
29 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_Editor,MMgt_TShared)
30
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) ,
34       thelists  (1,nbval)
35       {  thelists.Init(-1);  }
36
37     void  IFSelect_Editor::SetNbValues (const Standard_Integer nbval)
38 {
39   if (nbval > thevalues.Upper()) throw Standard_OutOfRange("IFSelect_Editor:SetNbValues");
40   thenbval = nbval;
41 }
42
43     void  IFSelect_Editor::SetValue
44   (const Standard_Integer num, const Handle(Interface_TypedValue)& typval,
45    const Standard_CString shortname, const IFSelect_EditValue editmode)
46 {
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;
56
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);
62 }
63
64     void  IFSelect_Editor::SetList
65   (const Standard_Integer num, const Standard_Integer max)
66 {
67   if (num < 1 || num > thenbval) return;
68   thelists.SetValue (num,max);
69 }
70
71     Standard_Integer  IFSelect_Editor::NbValues () const
72       {  return thenbval;  }
73
74     Handle(Interface_TypedValue)  IFSelect_Editor::TypedValue
75   (const Standard_Integer num) const
76     {  return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num));  }
77
78 Standard_Boolean  IFSelect_Editor::IsList  (const Standard_Integer num) const
79 {
80   if (num < 1 || num > thenbval) return Standard_False;
81   return (thelists.Value(num) >= 0);
82 }
83
84 Standard_Integer  IFSelect_Editor::MaxList (const Standard_Integer num) const
85 {
86   if (num < 1 || num > thenbval) return -1;
87   return thelists.Value(num);
88 }
89
90     Standard_CString  IFSelect_Editor::Name
91   (const Standard_Integer num, const Standard_Boolean isshort) const
92 {
93   if (num < 1 || num > thenbval) return "";
94   if (isshort) return theshorts.Value (num).ToCString();
95   else return TypedValue (num)->Name();
96 }
97
98     IFSelect_EditValue  IFSelect_Editor::EditMode
99   (const Standard_Integer num) const
100 {
101   if (num < 1 || num > thenbval) return IFSelect_EditDynamic;
102   Standard_Integer edm = themodes.Value(num);
103   return (IFSelect_EditValue) edm;
104 }
105
106     void  IFSelect_Editor::PrintNames (const Handle(Message_Messenger)& S) const
107 {
108   Standard_Integer i, nb = NbValues();
109   S<<"****    Editor : "<<Label()<<endl;
110   S<<"****    Nb Values = "<<nb<<"    ****    Names / Labels"<<endl;
111   S<<" Num ";
112   if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" ";
113   S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<"  Label"<<endl;
114
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<<" ";
119     if (themaxsh > 0) {
120       const TCollection_AsciiString& sho = theshorts(i);
121       S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
122     }
123     S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<"  "<<tv->Label()<<endl;
124   }
125 }
126
127     void  IFSelect_Editor::PrintDefs
128   (const Handle(Message_Messenger)& S, const Standard_Boolean labels) const
129 {
130   Standard_Integer i, nb = NbValues();
131   S<<"****    Editor : "<<Label()<<endl;
132   S<<"****    Nb Values = "<<nb<<"    ****    "<<(labels ? "Labels" : "Names")<<"  /  Definitions"<<endl;
133   S<<" Num ";
134   if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla);
135   else {
136     if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1);
137     S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco);
138   }
139   S<<"  Edit Mode  &  Definition"<<endl;
140
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);
146     else {
147       if (themaxsh > 0) {
148         const TCollection_AsciiString& sho = theshorts(i);
149         S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
150       }
151       S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco);
152     }
153
154     S<<" ";
155     Standard_Integer maxls = MaxList (i);
156     if (maxls == 0) S<<" (List) ";
157     else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) ";
158     else S<<" ";
159     IFSelect_EditValue edm = EditMode (i);
160     switch (edm) {
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;
168     }
169
170     S<<" "<<tv->Definition()<<endl;
171   }
172 }
173
174
175     Standard_Integer  IFSelect_Editor::MaxNameLength
176   (const Standard_Integer what) const
177 {
178   if (what == -1) return themaxsh;
179   if (what ==  0) return themaxco;
180   if (what ==  1) return themaxla;
181   return 0;
182 }
183
184
185     Standard_Integer  IFSelect_Editor::NameNumber
186   (const Standard_CString name) const
187 {
188   Standard_Integer res;
189   if (thenames.Find(name,res))
190     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;  }