973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
7fd59977 |
15 | #include <Dico_DictionaryOfInteger.hxx> |
16 | #include <Dico_IteratorOfDictionaryOfInteger.hxx> |
42cf5bc1 |
17 | #include <IFSelect_Activator.hxx> |
18 | #include <IFSelect_SessionPilot.hxx> |
19 | #include <Interface_Macros.hxx> |
c04c30b3 |
20 | #include <MoniTool_Option.hxx> |
42cf5bc1 |
21 | #include <MoniTool_Profile.hxx> |
22 | #include <Standard_DomainError.hxx> |
23 | #include <Standard_Type.hxx> |
24 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
25 | #include <TCollection_HAsciiString.hxx> |
42cf5bc1 |
26 | #include <TColStd_SequenceOfInteger.hxx> |
27 | #include <TColStd_SequenceOfTransient.hxx> |
7fd59977 |
28 | |
92efcf78 |
29 | IMPLEMENT_STANDARD_RTTIEXT(IFSelect_Activator,MMgt_TShared) |
30 | |
7fd59977 |
31 | static Handle(Dico_DictionaryOfInteger) thedico; // = new Dico_DictionaryOfInteger; |
32 | static TColStd_SequenceOfInteger thenums, themodes; |
33 | static TColStd_SequenceOfTransient theacts; |
34 | |
c04c30b3 |
35 | static Handle(MoniTool_Profile) thealiases; |
7fd59977 |
36 | |
37 | |
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) |
43 | { |
44 | Standard_Boolean deja; |
45 | if (thedico.IsNull()) thedico = new Dico_DictionaryOfInteger; |
46 | Standard_Integer& num = thedico->NewItem(command,deja,Standard_True); |
47 | if (deja) { |
0797d9d3 |
48 | #ifdef OCCT_DEBUG |
7fd59977 |
49 | cout<<"**** XSTEP commands, name conflict on "<<command<<" first defined remains ****"<<endl; |
50 | // Standard_DomainError::Raise("IFSelect_Activator : Add"); |
51 | #endif |
52 | } |
53 | num = thenums.Length() + 1; |
54 | thenums.Append(number); |
55 | theacts.Append(actor); |
56 | themodes.Append(mode); |
57 | } |
58 | |
59 | void IFSelect_Activator::Add |
60 | (const Standard_Integer number, const Standard_CString command) const |
61 | { Adding (this,number,command,0); } |
62 | |
63 | void IFSelect_Activator::AddSet |
64 | (const Standard_Integer number, const Standard_CString command) const |
65 | { Adding (this,number,command,1); } |
66 | |
7fd59977 |
67 | void IFSelect_Activator::Remove (const Standard_CString command) |
68 | { thedico->RemoveItem(command); } |
69 | |
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 |
75 | // nom de la conf |
76 | |
77 | void IFSelect_Activator::SetAlias |
78 | (const Standard_CString conf, |
79 | const Standard_CString command, const Standard_CString alias) |
80 | { |
c04c30b3 |
81 | if (thealiases.IsNull()) thealiases = new MoniTool_Profile; |
82 | Handle(MoniTool_Option) opt = thealiases->Option(command); |
7fd59977 |
83 | if (opt.IsNull()) { |
c04c30b3 |
84 | opt = new MoniTool_Option(STANDARD_TYPE(TCollection_HAsciiString),command); |
7fd59977 |
85 | thealiases->AddOption (opt); |
86 | } |
87 | opt->Add (conf,new TCollection_HAsciiString(alias)); |
88 | |
89 | if (!thealiases->HasConf(conf)) thealiases->AddConf (conf); |
90 | thealiases->AddSwitch (conf,command,conf); |
91 | } |
92 | |
93 | void IFSelect_Activator::SetCurrentAlias (const Standard_CString conf) |
94 | { |
95 | if (!thealiases.IsNull()) thealiases->SetCurrent (conf); |
96 | } |
97 | |
98 | TCollection_AsciiString IFSelect_Activator::Alias |
99 | (const Standard_CString command) |
100 | { |
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()); |
c04c30b3 |
106 | return str; |
7fd59977 |
107 | } |
108 | |
109 | |
110 | Standard_Boolean IFSelect_Activator::Select |
111 | (const Standard_CString command, Standard_Integer& number, |
112 | Handle(IFSelect_Activator)& actor) |
113 | { |
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; |
119 | } |
120 | |
121 | Standard_Integer IFSelect_Activator::Mode |
122 | (const Standard_CString command) |
123 | { |
124 | Standard_Integer num; |
125 | if (!thedico->GetItem(command,num,Standard_False)) return -1; |
126 | return themodes(num); |
127 | } |
128 | |
129 | |
130 | Handle(TColStd_HSequenceOfAsciiString) IFSelect_Activator::Commands |
131 | (const Standard_Integer mode, const Standard_CString command) |
132 | { |
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()) { |
138 | if (mode < 0) { |
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()); |
143 | } else { |
144 | num = iter.Value(); |
145 | if (themodes(num) == mode) list->Append(iter.Name()); |
146 | } |
147 | } |
148 | return list; |
149 | } |
150 | |
151 | |
152 | IFSelect_Activator::IFSelect_Activator () |
153 | : thegroup ("XSTEP") { } |
154 | |
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); } |
159 | |
160 | Standard_CString IFSelect_Activator::Group () const |
161 | { return thegroup.ToCString(); } |
162 | |
163 | Standard_CString IFSelect_Activator::File () const |
164 | { return thefile.ToCString(); } |