Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[tools/hxx2salome.git] / src / hxx2salome.ui.h
1 /****************************************************************************
2 ** ui.h extension file, included from the uic-generated form implementation.
3 **
4 ** If you want to add, delete, or rename functions or slots, use
5 ** Qt Designer to update this file, preserving your code.
6 **
7 ** You should not define a constructor or destructor in this file.
8 ** Instead, write your code in functions called init() and destroy().
9 ** These will automatically be called by the form's constructor and
10 ** destructor.
11 *****************************************************************************/
12
13 #include <iostream>
14 #include <fstream>
15 #include <string>
16 #include <cstdlib>
17 #include <libgen.h>
18 #include <qfiledialog.h>
19
20 static
21 inline void extractDirNameBaseName(const QString & name, 
22                             QString & dir, QString & base )
23 {
24     if (name != "") {
25         char *s;
26         s = strdup(name.latin1());
27         dir = dirname(s);
28         dir += "/";
29         strcpy(s, name.latin1());
30         base = basename(s);
31         free(s);
32     }
33     else {
34         base = "";
35         dir = "";
36     }
37 }
38
39 static 
40 inline void extract_value( QString & Tq)
41 {
42     std::string t = Tq.latin1();
43     std::string::size_type p1, p2;
44     std::string spaces = " \t\n\r";
45     
46     p1 = t.find_first_of('"');
47     if (p1 == std::string::npos) p1 = 0;
48     else p1++;
49     while ((p1 < t.length()) && 
50            (spaces.find(t[p1]) != std::string::npos))
51         p1++;
52                 
53     p2 = t.find_last_of('"');
54     if (p2 == std::string::npos) p2 = t.length();
55     else p2--;
56     while ((p2 >= 0) && 
57            (spaces.find(t[p2]) != std::string::npos))
58         p2--;
59     
60     if (p1 <= p2)
61         t = t.substr(p1, p2-p1+1);
62     else
63         t = "";
64     Tq = t.c_str();
65 }
66
67 void HXX2Salome::CloseButton_pressed()
68 {
69     close();
70 }
71
72
73 void HXX2Salome::SourceTreeButton_pressed()
74 {
75     QString s = QFileDialog::getExistingDirectory(
76             CppDir,
77             this,
78             "get existing directory",
79             "Choose a directory",
80             TRUE ); 
81     if (!s.isEmpty()) {
82         CppDir = s;
83         SourceTreeText->setText(s);
84     }
85 }
86
87
88 void HXX2Salome::newComponentTree()
89 {
90     QString s = SourceTreeText->text();
91     if (!s.isEmpty()) CppDir = s;
92 }
93
94
95 void HXX2Salome::newIncludeFile()
96 {
97     QString s = IncludeText->text();
98     QString dir, base;
99     
100     if (!s.isEmpty()) {
101         extractDirNameBaseName(s, dir, base);
102         CppInc = base;
103         if (dir != "./")
104             CppIncDir = dir;
105     }
106 }
107
108
109 void HXX2Salome::newSharedLibrary()
110 {
111     QString s = LibraryText->text();
112     QString dir, base;
113     
114     if (!s.isEmpty()) {
115         extractDirNameBaseName(s, dir, base);
116         CppLib = base;
117         if (dir != "./")
118             CppLibDir = dir;
119     }
120 }
121
122
123 void HXX2Salome::newEnvFile()
124 {
125     QString s = EnvFileText->text();
126     if (!s.isEmpty()) EnvFile = s;
127 }
128
129
130 void HXX2Salome::newOutputTree()
131 {
132     QString s = OutputTreeText->text();
133     if (!s.isEmpty()) SalomeDir = s;
134     
135 }
136
137
138 void HXX2Salome::OutputTreeButton_pressed()
139 {
140     QString s = QFileDialog::getExistingDirectory(
141             SalomeDir,
142             this,
143             "get directory",
144             "Choose a directory",
145             TRUE ); 
146     if (!s.isEmpty()) {
147         SalomeDir = s;
148         OutputTreeText->setText(s);
149     }
150 }
151
152 void HXX2Salome::IncludeButton_pressed()
153 {
154     QString s = QFileDialog::getOpenFileName(
155             CppIncDir + CppInc,
156             "Include files (*.h *.hh *.hxx *.hpp)",
157             this,
158             "C++ include file",
159             "Choose a file to open" );
160     if (!s.isEmpty()) {
161         extractDirNameBaseName(s, CppIncDir, CppInc);
162         IncludeText->setText(CppInc);
163     }
164 }
165
166
167 void HXX2Salome::LibraryButton_pressed()
168 {
169     QString s = QFileDialog::getOpenFileName(
170             CppLibDir + CppLib,
171             "Shared Libraries (*.so *.dll)",
172             this,
173             "Library file",
174             "Choose a file to open" );
175     if (!s.isEmpty()) {
176         extractDirNameBaseName(s, CppLibDir, CppLib);
177         LibraryText->setText(CppLib);
178     }
179 }
180
181
182 void HXX2Salome::EnvFileButton_pressed()
183 {
184     QString s = QFileDialog::getSaveFileName(
185             EnvFile,
186             "Environment files (*.csh *.sh)",
187             this,
188             "Environment file",
189             "Choose a script file to open" );
190     if (!s.isEmpty()) {
191         EnvFile = s;
192         EnvFileText->setText(s);
193     }
194     
195 }
196
197
198 void HXX2Salome::shellChanged(int n)
199 {
200 }
201
202
203 void HXX2Salome::GenerateButton_pressed()
204 {
205     QString command;
206     command = "export HXX2SALOME_ROOT_DIR=";
207     command += BINDIR;
208     command += "; $HXX2SALOME_ROOT_DIR/hxx2salome ";
209     if (makeGUI->isChecked())
210         command += " \"-g\" ";
211     if (Compile->isChecked())
212         command += " \"-c\" ";
213     if (shell == 1)
214         command += " -s csh ";
215     if (!EnvFile.isEmpty()) {
216         command += " -e ";
217         command += EnvFile;
218         command += " ";
219     }
220     command += CppDir;
221     command += " \"";
222     command += CppInc;
223     command += "\" \"";
224     command += CppLib;
225     command += "\" \"";
226     command += SalomeDir;
227     command += "\"";
228   
229     std::cerr << "command = " << command << std::endl;
230     QCursor QOld(Qt::ArrowCursor), QNew(Qt::WaitCursor);
231     this->setCursor(QNew);
232     std::system(command);
233     this->setCursor(QOld);
234 }
235
236 void HXX2Salome::init()
237 {   
238     std::cerr << "HXX2Salome::init" << std::endl;
239     shell = 0;
240     CppDir = "";
241     CppInc = "";
242     CppLib = "";
243     EnvFile = "";
244     SalomeDir = "";
245         
246     char *home = getenv("HOME");
247     std::string s(home), t;
248     QString Tq;
249     s += "/.hxx2salome";
250     std::ifstream f(s.c_str());
251     while (f.good()) {
252         
253         f >> s;
254         getline(f, t);
255         Tq = t.c_str();
256         extract_value(Tq);
257         if (s == "CppDir") {
258             CppDir = Tq;
259             SourceTreeText->setText(CppDir);
260         }
261         else if (s == "CppInc") {
262             extractDirNameBaseName(Tq, CppIncDir, CppInc);
263             IncludeText->setText(CppInc);
264         }
265         else if (s == "CppLib") {
266             extractDirNameBaseName(Tq, CppLibDir, CppLib);
267             LibraryText->setText(CppLib);
268         }
269         else if (s == "EnvFile") {
270             EnvFile = Tq; 
271             EnvFileText->setText(EnvFile);
272         }
273         else if (s == "SalomeDir") {
274             SalomeDir = Tq;
275             OutputTreeText->setText(SalomeDir);
276         }
277         else if (s == "Shell") {
278             if (Tq == "bash") shell = 0;
279             else if (Tq == "csh") shell = 1;
280             ShellChoice->setCurrentItem(shell);
281             ShellChoice->setCurrentText(Tq);
282         }        
283         if (f.eof()) break;
284     }
285     
286     f.close();
287 }
288
289
290 void HXX2Salome::ShellChoice_activated( int n)
291 {
292     shell = ShellChoice->currentItem();
293 }
294
295
296 void HXX2Salome::destroy()
297 {
298     std::cerr << "HXX2Salome::destroy" << std::endl;
299     char *home = getenv("HOME");
300     std::string s(home);
301     s += "/.hxx2salome";
302     std::ofstream f(s.c_str());
303     f << "CppDir " << "\"" << CppDir << "\"" << std::endl;
304     f << "CppInc " << "\"" << CppIncDir << CppInc << "\"" << std::endl;
305     f << "CppLib " << "\"" << CppLibDir << CppLib << "\"" << std::endl;
306     f << "SalomeDir " << "\"" << SalomeDir << "\"" << std::endl;
307     f << "EnvFile " << "\"" << EnvFile << "\"" << std::endl;
308     f << "Shell ";
309     switch (shell) {
310     case 0 : f<< "bash";
311         break;
312     case 1: f << "csh";
313         break;
314     default: f << "bash";
315         break;
316     }
317     f << std::endl;
318     f.close();
319 }
320