Salome HOME
New Py2YacsDialog using PyEditor_Window.
[modules/yacs.git] / src / ydfx_gui / YDFXResourceModel.cxx
1 #include "YDFXResourceModel.hxx"
2
3 #include "YACSEvalYFX.hxx"
4 #include "YACSEvalResource.hxx"
5 //#include "ResourcesManager.hxx" 
6
7 #include <algorithm>
8 #include <sstream>
9 #include <cstdlib>
10
11 YDFXResourceModel::YDFXResourceModel(YACSEvalYFX* eval)
12 : AbstractResourceModel(),
13   _eval(eval)
14 {
15 }
16
17 YDFXResourceModel::~YDFXResourceModel()
18 {
19 }
20
21 bool YDFXResourceModel::getParallelizeStatus()const
22 {
23   return _eval->getParallelizeStatus();
24 }
25
26 void YDFXResourceModel::setParallelizeStatus(bool v)
27 {
28   _eval->setParallelizeStatus(v);
29 }
30
31 std::string YDFXResourceModel::getRemoteDir()const
32 {
33   return getClusterParams().getRemoteWorkingDir();
34 }
35
36 void YDFXResourceModel::setRemoteDir(const std::string& v)
37 {
38   getClusterParams().setRemoteWorkingDir(v);
39 }
40
41 std::string YDFXResourceModel::getDefaultRemoteDir(std::string machine)const
42 {
43   return "/tmp";
44 }
45
46 std::string YDFXResourceModel::getLocalDir()const
47 {
48   return getClusterParams().getLocalWorkingDir();
49 }
50
51 void YDFXResourceModel::setLocalDir(const std::string& v)
52 {
53   getClusterParams().setLocalWorkingDir(v);
54 }
55
56 std::string YDFXResourceModel::getWckey()const
57 {
58   return getClusterParams().getWCKey();
59 }
60
61 void YDFXResourceModel::setWckey(const std::string& v)
62 {
63   getClusterParams().setWCKey(v);
64 }
65
66 int YDFXResourceModel::getMaxDurationMinutes()const
67 {
68   int minutes;
69   int hours;
70   getMaxDuration(hours, minutes);
71   return minutes;
72 }
73
74 void YDFXResourceModel::setMaxDurationMinutes(int v)
75 {
76   int minutes;
77   int hours;
78   getMaxDuration(hours, minutes);
79   setMaxDuration(hours, v);
80 }
81
82 int YDFXResourceModel::getMaxDurationHours()const
83 {
84   int minutes;
85   int hours;
86   getMaxDuration(hours, minutes);
87   return hours;
88 }
89
90 void YDFXResourceModel::setMaxDurationHours(int v)
91 {
92   int minutes;
93   int hours;
94   getMaxDuration(hours, minutes);
95   setMaxDuration(v, minutes);
96 }
97
98 unsigned int YDFXResourceModel::getNbprocs()const
99 {
100   return getClusterParams().getNbProcs();
101 }
102
103 void YDFXResourceModel::setNbprocs(unsigned int v)
104 {
105   getClusterParams().setNbProcs(v);
106 }
107
108 std::string YDFXResourceModel::getWantedMachine()const
109 {
110   const std::string default_machine("localhost");
111   std::vector<std::string> chosenMachines = resources()->getAllChosenMachines();
112   std::vector<std::string> fittingMachines = resources()->getAllFittingMachines();
113   std::string wantedMachine="";
114   std::vector<std::string>::const_iterator it;
115   bool foundMachine = false;
116   it = chosenMachines.begin();
117   // take the first chosen machine which is also fitting.
118   while(!foundMachine && it!=chosenMachines.end())
119   {
120     if(std::find(fittingMachines.begin(), fittingMachines.end(), *it)
121        != fittingMachines.end())
122     {
123       foundMachine = true;
124       wantedMachine = *it;
125     }
126   }
127   if(!foundMachine)
128   {
129     // take localhost if fitting
130     if(std::find(fittingMachines.begin(), fittingMachines.end(),
131                  default_machine) != fittingMachines.end())
132     {
133       foundMachine = true;
134       wantedMachine = default_machine;
135     }
136     else if(fittingMachines.size() > 0)
137     {
138       foundMachine = true;
139       wantedMachine = fittingMachines[0];
140     }
141   }
142   
143 }
144
145 void YDFXResourceModel::setWantedMachine(const std::string& v)
146 {
147   resources()->setWantedMachine(v);
148 }
149
150 std::vector<std::string> YDFXResourceModel::getFittingMachines()const
151 {
152   return resources()->getAllFittingMachines();
153 }
154
155 const std::list<std::string>& YDFXResourceModel::getInFiles()const
156 {
157   return getClusterParams().getInFiles();
158 }
159
160 std::list<std::string>& YDFXResourceModel::getInFiles()
161 {
162   return getClusterParams().getInFiles();
163 }
164   
165 bool YDFXResourceModel::isMachineInteractive(const std::string& machine)const
166 {
167   return resources()->isMachineInteractive(machine);
168 }
169
170 void YDFXResourceModel::reset(YACSEvalYFX* eval)
171 {
172   _eval = eval;
173 }
174
175 YACSEvalListOfResources* YDFXResourceModel::resources()
176 {
177   return _eval->giveResources();
178 }
179
180 const YACSEvalListOfResources* YDFXResourceModel::resources()const
181 {
182   return _eval->giveResources();
183 }
184
185 YACSEvalParamsForCluster& YDFXResourceModel::getClusterParams()
186 {
187   return _eval->giveResources()->getAddParamsForCluster();
188 }
189
190 const YACSEvalParamsForCluster& YDFXResourceModel::getClusterParams()const
191 {
192   return _eval->giveResources()->getAddParamsForCluster();
193 }
194
195 void YDFXResourceModel::getMaxDuration(int& hours, int& minutes)const
196 {
197   std::string duration = getClusterParams().getMaxDuration();
198   hours=0;
199   minutes=0;
200   if(duration.size() > 0)
201   {
202     std::stringstream ss(duration);
203     std::string value;
204     std::getline(ss, value, ':');
205     hours = atoi(value.c_str());
206     std::getline(ss, value, ':');
207     minutes = atoi(value.c_str());
208   }
209   if(hours<0)
210     hours = 0;
211   if(hours>99)
212     hours = 99;
213   if(minutes<0)
214     minutes = 0;
215   if(minutes > 59)
216     minutes = 59;
217 }
218
219 void YDFXResourceModel::setMaxDuration(int hours, int minutes)
220 {
221   getClusterParams().setMaxDuration(AbstractResourceModel::getMaxDuration());
222 }