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.
15 #include <Dico_DictionaryOfInteger.hxx>
16 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
17 #include <IFSelect_Activator.hxx>
18 #include <IFSelect_SessionPilot.hxx>
19 #include <Interface_Macros.hxx>
20 #include <MoniTool_Option.hxx>
21 #include <MoniTool_Profile.hxx>
22 #include <Standard_DomainError.hxx>
23 #include <Standard_Type.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TCollection_HAsciiString.hxx>
26 #include <TColStd_SequenceOfInteger.hxx>
27 #include <TColStd_SequenceOfTransient.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_Activator,MMgt_TShared)
31 static Handle(Dico_DictionaryOfInteger) thedico; // = new Dico_DictionaryOfInteger;
32 static TColStd_SequenceOfInteger thenums, themodes;
33 static TColStd_SequenceOfTransient theacts;
35 static Handle(MoniTool_Profile) thealiases;
38 void IFSelect_Activator::Adding
39 (const Handle(IFSelect_Activator)& actor,
40 const Standard_Integer number,
41 const Standard_CString command,
42 const Standard_Integer mode)
44 Standard_Boolean deja;
45 if (thedico.IsNull()) thedico = new Dico_DictionaryOfInteger;
46 Standard_Integer& num = thedico->NewItem(command,deja,Standard_True);
49 cout<<"**** XSTEP commands, name conflict on "<<command<<" first defined remains ****"<<endl;
50 // Standard_DomainError::Raise("IFSelect_Activator : Add");
53 num = thenums.Length() + 1;
54 thenums.Append(number);
55 theacts.Append(actor);
56 themodes.Append(mode);
59 void IFSelect_Activator::Add
60 (const Standard_Integer number, const Standard_CString command) const
61 { Adding (this,number,command,0); }
63 void IFSelect_Activator::AddSet
64 (const Standard_Integer number, const Standard_CString command) const
65 { Adding (this,number,command,1); }
67 void IFSelect_Activator::Remove (const Standard_CString command)
68 { thedico->RemoveItem(command); }
70 // ALIAS : gere avec un Profile
71 // Chaque commande est representee par une Option
72 // Au sein de laquelle chaque configuration nomme un cas, dont la valeur
73 // est le nom de son alias pour cette conf
74 // Et chaque conf porte un switch sur cette option avec pour valeur le propre
77 void IFSelect_Activator::SetAlias
78 (const Standard_CString conf,
79 const Standard_CString command, const Standard_CString alias)
81 if (thealiases.IsNull()) thealiases = new MoniTool_Profile;
82 Handle(MoniTool_Option) opt = thealiases->Option(command);
84 opt = new MoniTool_Option(STANDARD_TYPE(TCollection_HAsciiString),command);
85 thealiases->AddOption (opt);
87 opt->Add (conf,new TCollection_HAsciiString(alias));
89 if (!thealiases->HasConf(conf)) thealiases->AddConf (conf);
90 thealiases->AddSwitch (conf,command,conf);
93 void IFSelect_Activator::SetCurrentAlias (const Standard_CString conf)
95 if (!thealiases.IsNull()) thealiases->SetCurrent (conf);
98 TCollection_AsciiString IFSelect_Activator::Alias
99 (const Standard_CString command)
101 TCollection_AsciiString str;
102 if (thealiases.IsNull()) return str;
103 Handle(TCollection_HAsciiString) val;
104 if (!thealiases->Value(command,val)) return str;
105 str.AssignCat (val->ToCString());
110 Standard_Boolean IFSelect_Activator::Select
111 (const Standard_CString command, Standard_Integer& number,
112 Handle(IFSelect_Activator)& actor)
114 Standard_Integer num;
115 if (!thedico->GetItem(command,num,Standard_False)) return Standard_False;
116 number = thenums(num);
117 actor = Handle(IFSelect_Activator)::DownCast(theacts(num));
118 return Standard_True;
121 Standard_Integer IFSelect_Activator::Mode
122 (const Standard_CString command)
124 Standard_Integer num;
125 if (!thedico->GetItem(command,num,Standard_False)) return -1;
126 return themodes(num);
130 Handle(TColStd_HSequenceOfAsciiString) IFSelect_Activator::Commands
131 (const Standard_Integer mode, const Standard_CString command)
133 Standard_Integer num;
134 Dico_IteratorOfDictionaryOfInteger iter (thedico,command);
135 Handle(TColStd_HSequenceOfAsciiString) list =
136 new TColStd_HSequenceOfAsciiString();
137 for (iter.Start(); iter.More(); iter.Next()) {
139 DeclareAndCast(IFSelect_Activator,acti,theacts(iter.Value()));
140 if (acti.IsNull()) continue;
141 if (command[0] == '\0' || !strcmp(command,acti->Group()) )
142 list->Append(iter.Name());
145 if (themodes(num) == mode) list->Append(iter.Name());
152 IFSelect_Activator::IFSelect_Activator ()
153 : thegroup ("XSTEP") { }
155 void IFSelect_Activator::SetForGroup
156 (const Standard_CString group, const Standard_CString file)
157 { thegroup.Clear(); thegroup.AssignCat (group);
158 thefile.Clear(); thefile.AssignCat (file); }
160 Standard_CString IFSelect_Activator::Group () const
161 { return thegroup.ToCString(); }
163 Standard_CString IFSelect_Activator::File () const
164 { return thefile.ToCString(); }