0024428: Implementation of LGPL license
[occt.git] / src / IFSelect / IFSelect_Activator.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
6 // under the terms of the GNU Lesser General Public 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 #include <IFSelect_Activator.ixx>
15 #include <Dico_DictionaryOfInteger.hxx>
16 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
17 #include <TColStd_SequenceOfInteger.hxx>
18 #include <TColStd_SequenceOfTransient.hxx>
19 #include <Standard_DomainError.hxx>
20
21 #include <IFSelect_Profile.hxx>
22 #include <IFSelect_Option.hxx>
23 #include <TCollection_HAsciiString.hxx>
24
25 #include <Interface_Macros.hxx>
26
27
28 static Handle(Dico_DictionaryOfInteger) thedico; // = new Dico_DictionaryOfInteger;
29 static TColStd_SequenceOfInteger   thenums, themodes;
30 static TColStd_SequenceOfTransient theacts;
31
32 static Handle(IFSelect_Profile) thealiases;
33
34
35     void IFSelect_Activator::Adding
36   (const Handle(IFSelect_Activator)& actor,
37    const Standard_Integer number,
38    const Standard_CString command,
39    const Standard_Integer mode)
40 {
41   Standard_Boolean deja;
42   if (thedico.IsNull()) thedico = new Dico_DictionaryOfInteger;
43   Standard_Integer& num = thedico->NewItem(command,deja,Standard_True);
44   if (deja) {
45 #ifdef DEB
46     cout<<"****  XSTEP commands, name conflict on "<<command<<" first defined remains  ****"<<endl;
47 //    Standard_DomainError::Raise("IFSelect_Activator : Add");
48 #endif
49   }
50   num = thenums.Length() + 1;
51   thenums.Append(number);
52   theacts.Append(actor);
53   themodes.Append(mode);
54 }
55
56     void IFSelect_Activator::Add
57   (const Standard_Integer number, const Standard_CString command) const
58       {  Adding (this,number,command,0);  }
59
60     void IFSelect_Activator::AddSet
61   (const Standard_Integer number, const Standard_CString command) const
62       {  Adding (this,number,command,1);  }
63
64
65     void IFSelect_Activator::Remove (const Standard_CString command)
66       {  thedico->RemoveItem(command);  }
67
68 //  ALIAS : gere avec un Profile
69 //  Chaque commande est representee par une Option
70 //   Au sein de laquelle chaque configuration nomme un cas, dont la valeur
71 //   est le nom de son alias pour cette conf
72 //  Et chaque conf porte un switch sur cette option avec pour valeur le propre
73 //   nom de la conf
74
75     void  IFSelect_Activator::SetAlias
76   (const Standard_CString conf,
77    const Standard_CString command, const Standard_CString alias)
78 {
79   if (thealiases.IsNull()) thealiases = new IFSelect_Profile;
80   Handle(IFSelect_Option) opt = thealiases->Option(command);
81   if (opt.IsNull()) {
82     opt = new IFSelect_Option(STANDARD_TYPE(TCollection_HAsciiString),command);
83     thealiases->AddOption (opt);
84   }
85   opt->Add (conf,new TCollection_HAsciiString(alias));
86
87   if (!thealiases->HasConf(conf)) thealiases->AddConf (conf);
88   thealiases->AddSwitch (conf,command,conf);
89 }
90
91     void  IFSelect_Activator::SetCurrentAlias (const Standard_CString conf)
92 {
93   if (!thealiases.IsNull()) thealiases->SetCurrent (conf);
94 }
95
96     TCollection_AsciiString  IFSelect_Activator::Alias
97   (const Standard_CString command)
98 {
99   TCollection_AsciiString str;
100   if (thealiases.IsNull()) return str;
101   Handle(TCollection_HAsciiString) val;
102   if (!thealiases->Value(command,val)) return str;
103   str.AssignCat (val->ToCString());
104   return str;
105 }
106
107
108     Standard_Boolean IFSelect_Activator::Select
109   (const Standard_CString command, Standard_Integer& number,
110    Handle(IFSelect_Activator)& actor)
111 {
112   Standard_Integer num;
113   if (!thedico->GetItem(command,num,Standard_False)) return Standard_False;
114   number = thenums(num);
115   actor = Handle(IFSelect_Activator)::DownCast(theacts(num));
116   return Standard_True;
117 }
118
119     Standard_Integer IFSelect_Activator::Mode
120   (const Standard_CString command)
121 {
122   Standard_Integer num;
123   if (!thedico->GetItem(command,num,Standard_False)) return -1;
124   return themodes(num);
125 }
126
127
128     Handle(TColStd_HSequenceOfAsciiString) IFSelect_Activator::Commands
129   (const Standard_Integer mode, const Standard_CString command)
130 {
131   Standard_Integer num;
132   Dico_IteratorOfDictionaryOfInteger iter (thedico,command);
133   Handle(TColStd_HSequenceOfAsciiString) list =
134     new  TColStd_HSequenceOfAsciiString();
135   for (iter.Start(); iter.More(); iter.Next()) {
136     if (mode < 0) {
137       DeclareAndCast(IFSelect_Activator,acti,theacts(iter.Value()));
138       if (acti.IsNull()) continue;
139       if (command[0] == '\0' || !strcmp(command,acti->Group()) )
140         list->Append(iter.Name());
141     } else {
142       num = iter.Value();
143       if (themodes(num) == mode) list->Append(iter.Name());
144     }
145   }
146   return list;
147 }
148
149
150     IFSelect_Activator::IFSelect_Activator ()
151     : thegroup ("XSTEP")    {  }
152
153     void  IFSelect_Activator::SetForGroup
154   (const Standard_CString group, const Standard_CString file)
155     {  thegroup.Clear();  thegroup.AssignCat (group);
156        thefile.Clear();   thefile.AssignCat  (file);   }
157
158     Standard_CString  IFSelect_Activator::Group () const
159     {  return thegroup.ToCString();  }
160
161     Standard_CString  IFSelect_Activator::File  () const
162     {  return thefile.ToCString();   }