summaryrefslogtreecommitdiff
path: root/src/IFSelect/IFSelect_Activator.cxx
blob: 93009f33069fa1ec6acc5ad61eba4af38978f0ea (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
#include <IFSelect_Activator.ixx>
#include <Dico_DictionaryOfInteger.hxx>
#include <Dico_IteratorOfDictionaryOfInteger.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TColStd_SequenceOfTransient.hxx>
#include <Standard_DomainError.hxx>

#include <IFSelect_Profile.hxx>
#include <IFSelect_Option.hxx>
#include <TCollection_HAsciiString.hxx>

#include <Interface_Macros.hxx>


static Handle(Dico_DictionaryOfInteger) thedico; // = new Dico_DictionaryOfInteger;
static TColStd_SequenceOfInteger   thenums, themodes;
static TColStd_SequenceOfTransient theacts;

static Handle(IFSelect_Profile) thealiases;


    void IFSelect_Activator::Adding
  (const Handle(IFSelect_Activator)& actor,
   const Standard_Integer number,
   const Standard_CString command,
   const Standard_Integer mode)
{
  Standard_Boolean deja;
  if (thedico.IsNull()) thedico = new Dico_DictionaryOfInteger;
  Standard_Integer& num = thedico->NewItem(command,deja,Standard_True);
  if (deja) {
#ifdef DEB
    cout<<"****  XSTEP commands, name conflict on "<<command<<" first defined remains  ****"<<endl;
//    Standard_DomainError::Raise("IFSelect_Activator : Add");
#endif
  }
  num = thenums.Length() + 1;
  thenums.Append(number);
  theacts.Append(actor);
  themodes.Append(mode);
}

    void IFSelect_Activator::Add
  (const Standard_Integer number, const Standard_CString command) const
      {  Adding (this,number,command,0);  }

    void IFSelect_Activator::AddSet
  (const Standard_Integer number, const Standard_CString command) const
      {  Adding (this,number,command,1);  }


    void IFSelect_Activator::Remove (const Standard_CString command)
      {  thedico->RemoveItem(command);  }

//  ALIAS : gere avec un Profile
//  Chaque commande est representee par une Option
//   Au sein de laquelle chaque configuration nomme un cas, dont la valeur
//   est le nom de son alias pour cette conf
//  Et chaque conf porte un switch sur cette option avec pour valeur le propre
//   nom de la conf

    void  IFSelect_Activator::SetAlias
  (const Standard_CString conf,
   const Standard_CString command, const Standard_CString alias)
{
  if (thealiases.IsNull()) thealiases = new IFSelect_Profile;
  Handle(IFSelect_Option) opt = thealiases->Option(command);
  if (opt.IsNull()) {
    opt = new IFSelect_Option(STANDARD_TYPE(TCollection_HAsciiString),command);
    thealiases->AddOption (opt);
  }
  opt->Add (conf,new TCollection_HAsciiString(alias));

  if (!thealiases->HasConf(conf)) thealiases->AddConf (conf);
  thealiases->AddSwitch (conf,command,conf);
}

    void  IFSelect_Activator::SetCurrentAlias (const Standard_CString conf)
{
  if (!thealiases.IsNull()) thealiases->SetCurrent (conf);
}

    TCollection_AsciiString  IFSelect_Activator::Alias
  (const Standard_CString command)
{
  TCollection_AsciiString str;
  if (thealiases.IsNull()) return str;
  Handle(TCollection_HAsciiString) val;
  if (!thealiases->Value(command,val)) return str;
  str.AssignCat (val->ToCString());
  return str;
}


    Standard_Boolean IFSelect_Activator::Select
  (const Standard_CString command, Standard_Integer& number,
   Handle(IFSelect_Activator)& actor)
{
  Standard_Integer num;
  if (!thedico->GetItem(command,num,Standard_False)) return Standard_False;
  number = thenums(num);
  actor = Handle(IFSelect_Activator)::DownCast(theacts(num));
  return Standard_True;
}

    Standard_Integer IFSelect_Activator::Mode
  (const Standard_CString command)
{
  Standard_Integer num;
  if (!thedico->GetItem(command,num,Standard_False)) return -1;
  return themodes(num);
}


    Handle(TColStd_HSequenceOfAsciiString) IFSelect_Activator::Commands
  (const Standard_Integer mode, const Standard_CString command)
{
  Standard_Integer num;
  Dico_IteratorOfDictionaryOfInteger iter (thedico,command);
  Handle(TColStd_HSequenceOfAsciiString) list =
    new  TColStd_HSequenceOfAsciiString();
  for (iter.Start(); iter.More(); iter.Next()) {
    if (mode < 0) {
      DeclareAndCast(IFSelect_Activator,acti,theacts(iter.Value()));
      if (acti.IsNull()) continue;
      if (command[0] == '\0' || !strcmp(command,acti->Group()) )
	list->Append(iter.Name());
    } else {
      num = iter.Value();
      if (themodes(num) == mode) list->Append(iter.Name());
    }
  }
  return list;
}


    IFSelect_Activator::IFSelect_Activator ()
    : thegroup ("XSTEP")    {  }

    void  IFSelect_Activator::SetForGroup
  (const Standard_CString group, const Standard_CString file)
    {  thegroup.Clear();  thegroup.AssignCat (group);
       thefile.Clear();   thefile.AssignCat  (file);   }

    Standard_CString  IFSelect_Activator::Group () const
    {  return thegroup.ToCString();  }

    Standard_CString  IFSelect_Activator::File  () const
    {  return thefile.ToCString();   }