1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
21 #include <IFSelect_Profile.hxx>
22 #include <IFSelect_Option.hxx>
23 #include <TCollection_HAsciiString.hxx>
25 #include <Interface_Macros.hxx>
28 static Handle(Dico_DictionaryOfInteger) thedico; // = new Dico_DictionaryOfInteger;
29 static TColStd_SequenceOfInteger thenums, themodes;
30 static TColStd_SequenceOfTransient theacts;
32 static Handle(IFSelect_Profile) thealiases;
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)
41 Standard_Boolean deja;
42 if (thedico.IsNull()) thedico = new Dico_DictionaryOfInteger;
43 Standard_Integer& num = thedico->NewItem(command,deja,Standard_True);
46 cout<<"**** XSTEP commands, name conflict on "<<command<<" first defined remains ****"<<endl;
47 // Standard_DomainError::Raise("IFSelect_Activator : Add");
50 num = thenums.Length() + 1;
51 thenums.Append(number);
52 theacts.Append(actor);
53 themodes.Append(mode);
56 void IFSelect_Activator::Add
57 (const Standard_Integer number, const Standard_CString command) const
58 { Adding (this,number,command,0); }
60 void IFSelect_Activator::AddSet
61 (const Standard_Integer number, const Standard_CString command) const
62 { Adding (this,number,command,1); }
65 void IFSelect_Activator::Remove (const Standard_CString command)
66 { thedico->RemoveItem(command); }
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
75 void IFSelect_Activator::SetAlias
76 (const Standard_CString conf,
77 const Standard_CString command, const Standard_CString alias)
79 if (thealiases.IsNull()) thealiases = new IFSelect_Profile;
80 Handle(IFSelect_Option) opt = thealiases->Option(command);
82 opt = new IFSelect_Option(STANDARD_TYPE(TCollection_HAsciiString),command);
83 thealiases->AddOption (opt);
85 opt->Add (conf,new TCollection_HAsciiString(alias));
87 if (!thealiases->HasConf(conf)) thealiases->AddConf (conf);
88 thealiases->AddSwitch (conf,command,conf);
91 void IFSelect_Activator::SetCurrentAlias (const Standard_CString conf)
93 if (!thealiases.IsNull()) thealiases->SetCurrent (conf);
96 TCollection_AsciiString IFSelect_Activator::Alias
97 (const Standard_CString command)
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());
108 Standard_Boolean IFSelect_Activator::Select
109 (const Standard_CString command, Standard_Integer& number,
110 Handle(IFSelect_Activator)& actor)
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;
119 Standard_Integer IFSelect_Activator::Mode
120 (const Standard_CString command)
122 Standard_Integer num;
123 if (!thedico->GetItem(command,num,Standard_False)) return -1;
124 return themodes(num);
128 Handle(TColStd_HSequenceOfAsciiString) IFSelect_Activator::Commands
129 (const Standard_Integer mode, const Standard_CString command)
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()) {
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());
143 if (themodes(num) == mode) list->Append(iter.Name());
150 IFSelect_Activator::IFSelect_Activator ()
151 : thegroup ("XSTEP") { }
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); }
158 Standard_CString IFSelect_Activator::Group () const
159 { return thegroup.ToCString(); }
161 Standard_CString IFSelect_Activator::File () const
162 { return thefile.ToCString(); }