summaryrefslogtreecommitdiff
path: root/src/IFSelect/IFSelect_Editor.cxx
blob: 295ef4a3b9b9fdd680f7f869ab3f3c802c1a9b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <IFSelect_Editor.ixx>
#include <Interface_MSG.hxx>
#include <string.h>


    IFSelect_Editor::IFSelect_Editor (const Standard_Integer nbval)
    : thenbval (nbval) , themaxsh (0) , themaxco (0) , themaxla (0) ,
      thevalues (1,nbval) , theshorts (1,nbval) , themodes (1,nbval) ,
      thelists  (1,nbval)
      {  thenames = new Dico_DictionaryOfInteger;  thelists.Init(-1);  }

    void  IFSelect_Editor::SetNbValues (const Standard_Integer nbval)
{
  if (nbval > thevalues.Upper()) Standard_OutOfRange::Raise("IFSelect_Editor:SetNbValues");
  thenbval = nbval;
}

    void  IFSelect_Editor::SetValue
  (const Standard_Integer num, const Handle(Interface_TypedValue)& typval,
   const Standard_CString shortname, const IFSelect_EditValue editmode)
{
  if (num < 1 || num > thenbval) return;
  TCollection_AsciiString shn (shortname);
  Standard_Integer lng = shn.Length();
  if (lng > 0) thenames->SetItem (shortname,num);
  if (lng > themaxsh) themaxsh = lng;
  lng = strlen (typval->Name());
  if (lng > themaxco) themaxco = lng;
  lng = strlen (typval->Label());
  if (lng > themaxla) themaxla = lng;

  thenames->SetItem (typval->Name(),num);
  Standard_Integer edm = (Standard_Integer) editmode;
  thevalues.SetValue (num,typval);
  theshorts.SetValue (num,shn);
  themodes.SetValue  (num,edm);
}

    void  IFSelect_Editor::SetList
  (const Standard_Integer num, const Standard_Integer max)
{
  if (num < 1 || num > thenbval) return;
  thelists.SetValue (num,max);
}

    Standard_Integer  IFSelect_Editor::NbValues () const
      {  return thenbval;  }

    Handle(Interface_TypedValue)  IFSelect_Editor::TypedValue
  (const Standard_Integer num) const
    {  return Handle(Interface_TypedValue)::DownCast(thevalues.Value(num));  }

Standard_Boolean  IFSelect_Editor::IsList  (const Standard_Integer num) const
{
  if (num < 1 || num > thenbval) return Standard_False;
  return (thelists.Value(num) >= 0);
}

Standard_Integer  IFSelect_Editor::MaxList (const Standard_Integer num) const
{
  if (num < 1 || num > thenbval) return -1;
  return thelists.Value(num);
}

    Standard_CString  IFSelect_Editor::Name
  (const Standard_Integer num, const Standard_Boolean isshort) const
{
  if (num < 1 || num > thenbval) return "";
  if (isshort) return theshorts.Value (num).ToCString();
  else return TypedValue (num)->Name();
}

    IFSelect_EditValue  IFSelect_Editor::EditMode
  (const Standard_Integer num) const
{
  if (num < 1 || num > thenbval) return IFSelect_EditDynamic;
  Standard_Integer edm = themodes.Value(num);
  return (IFSelect_EditValue) edm;
}

    void  IFSelect_Editor::PrintNames (const Handle(Message_Messenger)& S) const
{
  Standard_Integer i, nb = NbValues();
  S<<"****    Editor : "<<Label()<<endl;
  S<<"****    Nb Values = "<<nb<<"    ****    Names / Labels"<<endl;
  S<<" Num ";
  if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh)<<" ";
  S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco)<<"  Label"<<endl;

  for (i = 1; i <= nb; i ++) {
    Handle(Interface_TypedValue) tv = TypedValue(i);
    if (tv.IsNull()) continue;
    S<<Interface_MSG::Blanks(i,3)<<i<<" ";
    if (themaxsh > 0) {
      const TCollection_AsciiString& sho = theshorts(i);
      S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
    }
    S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco)<<"  "<<tv->Label()<<endl;
  }
}

    void  IFSelect_Editor::PrintDefs
  (const Handle(Message_Messenger)& S, const Standard_Boolean labels) const
{
  Standard_Integer i, nb = NbValues();
  S<<"****    Editor : "<<Label()<<endl;
  S<<"****    Nb Values = "<<nb<<"    ****    "<<(labels ? "Labels" : "Names")<<"  /  Definitions"<<endl;
  S<<" Num ";
  if (labels) S<<"Label"<<Interface_MSG::Blanks("Label",themaxla);
  else {
    if (themaxsh > 0) S<<"Short"<<Interface_MSG::Blanks("Short",themaxsh+1);
    S<<"Complete"<<Interface_MSG::Blanks("Complete",themaxco);
  }
  S<<"  Edit Mode  &  Definition"<<endl;

  for (i = 1; i <= nb; i ++) {
    Handle(Interface_TypedValue) tv = TypedValue(i);
    if (tv.IsNull()) continue;
    S<<" "<<Interface_MSG::Blanks(i,3)<<i<<" ";
    if (labels) S<<tv->Label()<<Interface_MSG::Blanks(tv->Label(),themaxla);
    else {
      if (themaxsh > 0) {
	const TCollection_AsciiString& sho = theshorts(i);
	S<<sho<<Interface_MSG::Blanks(sho.ToCString(),themaxsh)<<" ";
      }
      S<<tv->Name()<<Interface_MSG::Blanks(tv->Name(),themaxco);
    }

    S<<" ";
    Standard_Integer maxls = MaxList (i);
    if (maxls == 0) S<<" (List) ";
    else if (maxls > 0) S<<" (List <= "<<maxls<<" Items) ";
    else S<<" ";
    IFSelect_EditValue edm = EditMode (i);
    switch (edm) {
      case IFSelect_Optional      : S<<"Optional ";  break;
      case IFSelect_Editable      : S<<"Editable ";  break;
      case IFSelect_EditProtected : S<<"Protected";  break;
      case IFSelect_EditComputed  : S<<"Computed ";  break;
      case IFSelect_EditRead      : S<<"ReadOnly ";  break;
      case IFSelect_EditDynamic   : S<<"Dynamic  ";  break;
      default :                     S<<"?????????";  break;
    }

    S<<" "<<tv->Definition()<<endl;
  }
}


    Standard_Integer  IFSelect_Editor::MaxNameLength
  (const Standard_Integer what) const
{
  if (what == -1) return themaxsh;
  if (what ==  0) return themaxco;
  if (what ==  1) return themaxla;
  return 0;
}


    Standard_Integer  IFSelect_Editor::NameNumber
  (const Standard_CString name) const
{
  Standard_Integer res;
  if (thenames->GetItem(name,res,Standard_False)) return res;
  res = atoi (name);  // si c est un entier, on tente le coup
  if (res < 1 || res > NbValues()) res = 0;
  return res;
}


    Handle(IFSelect_EditForm)  IFSelect_Editor::Form
  (const Standard_Boolean readonly, const Standard_Boolean undoable) const
{
  return new IFSelect_EditForm (this,readonly,undoable,Label().ToCString());
}

    Handle(IFSelect_ListEditor)  IFSelect_Editor::ListEditor
  (const Standard_Integer num) const
{
  Handle(IFSelect_ListEditor) led;
  Standard_Integer max = MaxList (num);
  if (max < 0) return led;
  led = new IFSelect_ListEditor (TypedValue(num),max);
  return led;
}

    Handle(TColStd_HSequenceOfHAsciiString)  IFSelect_Editor::ListValue
  (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/) const
{
  Handle(TColStd_HSequenceOfHAsciiString) list;
  return list;
}


    Standard_Boolean  IFSelect_Editor::Update
  (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/,
   const Handle(TCollection_HAsciiString)& /*newval*/,
   const Standard_Boolean /*enforce*/) const
      {  return Standard_True;  }

    Standard_Boolean  IFSelect_Editor::UpdateList
  (const Handle(IFSelect_EditForm)& /*form*/, const Standard_Integer /*num*/,
   const Handle(TColStd_HSequenceOfHAsciiString)& /*newval*/,
   const Standard_Boolean /*enforce*/) const
      {  return Standard_True;  }