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; |
aa00364d |
103 | Handle(Standard_Transient) aVal; |
104 | if (!thealiases->Value(command,aVal)) return str; |
105 | Handle(TCollection_HAsciiString) val = |
106 | Handle(TCollection_HAsciiString)::DownCast (aVal); |
107 | if (!val.IsNull()) |
108 | str.AssignCat (val->ToCString()); |
109 | return str; |
7fd59977 |
110 | } |
111 | |
112 | |
113 | Standard_Boolean IFSelect_Activator::Select |
114 | (const Standard_CString command, Standard_Integer& number, |
115 | Handle(IFSelect_Activator)& actor) |
116 | { |
117 | Standard_Integer num; |
118 | if (!thedico->GetItem(command,num,Standard_False)) return Standard_False; |
119 | number = thenums(num); |
120 | actor = Handle(IFSelect_Activator)::DownCast(theacts(num)); |
121 | return Standard_True; |
122 | } |
123 | |
124 | Standard_Integer IFSelect_Activator::Mode |
125 | (const Standard_CString command) |
126 | { |
127 | Standard_Integer num; |
128 | if (!thedico->GetItem(command,num,Standard_False)) return -1; |
129 | return themodes(num); |
130 | } |
131 | |
132 | |
133 | Handle(TColStd_HSequenceOfAsciiString) IFSelect_Activator::Commands |
134 | (const Standard_Integer mode, const Standard_CString command) |
135 | { |
136 | Standard_Integer num; |
137 | Dico_IteratorOfDictionaryOfInteger iter (thedico,command); |
138 | Handle(TColStd_HSequenceOfAsciiString) list = |
139 | new TColStd_HSequenceOfAsciiString(); |
140 | for (iter.Start(); iter.More(); iter.Next()) { |
141 | if (mode < 0) { |
142 | DeclareAndCast(IFSelect_Activator,acti,theacts(iter.Value())); |
143 | if (acti.IsNull()) continue; |
144 | if (command[0] == '\0' || !strcmp(command,acti->Group()) ) |
145 | list->Append(iter.Name()); |
146 | } else { |
147 | num = iter.Value(); |
148 | if (themodes(num) == mode) list->Append(iter.Name()); |
149 | } |
150 | } |
151 | return list; |
152 | } |
153 | |
154 | |
155 | IFSelect_Activator::IFSelect_Activator () |
156 | : thegroup ("XSTEP") { } |
157 | |
158 | void IFSelect_Activator::SetForGroup |
159 | (const Standard_CString group, const Standard_CString file) |
160 | { thegroup.Clear(); thegroup.AssignCat (group); |
161 | thefile.Clear(); thefile.AssignCat (file); } |
162 | |
163 | Standard_CString IFSelect_Activator::Group () const |
164 | { return thegroup.ToCString(); } |
165 | |
166 | Standard_CString IFSelect_Activator::File () const |
167 | { return thefile.ToCString(); } |