2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 #include <QApplication>
27 #include <QTextStream>
30 #include "guimainwindow.h"
31 #include "filetemplate.h"
33 #include "geometrytools.h"
34 using namespace GeometryTools
;
36 ///\todo replace with shellscript?
37 void appendLicense(int argc
, char ** argv
)
39 int first_year
= 2008;
40 QString first_year_text
;
41 first_year_text
.setNum(first_year
);
42 int year
= QDate::currentDate().year();
44 year_text
.setNum(year
);
45 if (year
-first_year
== 1) {
46 year_text
= first_year_text
+ "," + year_text
;
48 if (year
-first_year
> 1) {
49 year_text
= first_year_text
+ "-" + year_text
;
51 QString year_end_text
= " +\n";
52 if (year
== first_year
) {
53 year_end_text
= " " + year_end_text
;
55 for (int i
= 2; i
< argc
; ++i
) {
56 QString
filename(argv
[i
]);
57 QString comment
= "// ";
60 if (filename
.right(3) == ".sh") script
= true;
61 if (filename
.right(3) == ".py") script
= true;
62 if (filename
.right(5) == ".bash") script
= true;
64 file
.open(QIODevice::ReadOnly
);
68 QString line
= f
.readLine();
69 buffer
+= line
+ "\n";
71 buffer
+= comment
+ "\n";
72 buffer
+= comment
+ "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
73 buffer
+= comment
+ "+ +\n";
74 buffer
+= comment
+ "+ This file is part of enGrid. +\n";
75 buffer
+= comment
+ "+ +\n";
76 buffer
+= comment
+ "+ Copyright " + year_text
+ " enGits GmbH" + year_end_text
;
77 buffer
+= comment
+ "+ +\n";
78 buffer
+= comment
+ "+ enGrid is free software: you can redistribute it and/or modify +\n";
79 buffer
+= comment
+ "+ it under the terms of the GNU General Public License as published by +\n";
80 buffer
+= comment
+ "+ the Free Software Foundation, either version 3 of the License, or +\n";
81 buffer
+= comment
+ "+ (at your option) any later version. +\n";
82 buffer
+= comment
+ "+ +\n";
83 buffer
+= comment
+ "+ enGrid is distributed in the hope that it will be useful, +\n";
84 buffer
+= comment
+ "+ but WITHOUT ANY WARRANTY; without even the implied warranty of +\n";
85 buffer
+= comment
+ "+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\n";
86 buffer
+= comment
+ "+ GNU General Public License for more details. +\n";
87 buffer
+= comment
+ "+ +\n";
88 buffer
+= comment
+ "+ You should have received a copy of the GNU General Public License +\n";
89 buffer
+= comment
+ "+ along with enGrid. If not, see <http://www.gnu.org/licenses/>. +\n";
90 buffer
+= comment
+ "+ +\n";
91 buffer
+= comment
+ "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
92 buffer
+= comment
+ "\n";
94 bool src_code
= false;
96 QString line
= f
.readLine();
98 if (line
.size() >= comment
.length()-1) {
99 if (line
.left(comment
.length()-1) != comment
.left(comment
.length()-1)) {
107 buffer
+= line
+ "\n";
112 QFile
file(filename
);
113 file
.open(QIODevice::WriteOnly
);
114 QTextStream
f(&file
);
120 ///\todo replace with shellscript?
121 void makeDistribution()
123 system ("ldd ./engrid > ldd.out");
124 system ("mkdir enGrid");
125 system ("cp engrid enGrid");
127 QFile
file("ldd.out");
128 file
.open(QIODevice::ReadOnly
);
129 QTextStream
f(&file
);
131 QString line
= f
.readLine();
132 QTextStream
l(&line
, QIODevice::ReadOnly
);
135 if (word
.left(1) != "/") {
139 QString cmd
= "cp " + word
+ " enGrid";
140 system(qPrintable(cmd
));
141 cout
<< qPrintable(cmd
) << endl
;
144 system ("tar czf enGrid_bin.tar.gz enGrid/*");
145 system ("rm -rf enGrid");
146 system ("rm ldd.out");
149 /** Message handler to allow output of Qt objects in the terminal (stderr) or the logfile/output window of engrid (stdout)
150 qDebug() is used for writing custom debug output.
151 qWarning() is used to report warnings and recoverable errors in your application.
152 qCritical() is used for writing critical error mesages and reporting system errors.
153 qFatal() is used for writing fatal error messages shortly before exiting.
155 void engridMessageHandler(QtMsgType type
, const char *msg
)
159 // fprintf(stdout, "%s", msg);
163 // fprintf(stderr, "%s", msg);
167 fprintf(stderr
, "Critical: %s\n", msg
);
170 fprintf(stderr
, "Fatal: %s\n", msg
);
175 double getNumber(QString text
)
183 // This code converts from string to number safely.
184 stringstream
myStream(input
);
185 if (myStream
>> myNumber
)
187 qDebug() << "Invalid number, please try again" << endl
;
192 int main( int argc
, char ** argv
)
195 double x, y, z, a, b, r;
196 cout << "x = "; cin >> x;
197 cout << "y = "; cin >> y;
198 cout << "z = "; cin >> z;
199 GeometryTools::cart2spherical(vec3_t(x,y,z), a, b, r);
201 cout << "r = " << r << endl;
202 cout << "alpha = " << GeometryTools::rad2deg(a) << endl;
203 cout << "beta = " << GeometryTools::rad2deg(b) << endl;
204 vec3_t X = spherical2cart(a, b, r);
205 cout << "\nX[0] = " << X[0] << endl;
206 cout << "X[1] = " << X[1] << endl;
207 cout << "X[2] = " << X[2] << endl;
211 qInstallMsgHandler(engridMessageHandler
);
212 Q_INIT_RESOURCE(engrid
);
215 ///\todo use gnu getopt ? Check windows/mac compatibility.
217 if (QString(argv
[1]) == QString("-h")) {
218 QFileInfo
file_info(argv
[0]);
219 cout
<<"Usage:"<<endl
;
220 cout
<<qPrintable(file_info
.fileName())<<" : start engrid"<<endl
;
221 cout
<<qPrintable(file_info
.fileName())<<" -f FILE : start engrid and open FILE"<<endl
;
222 cout
<<qPrintable(file_info
.fileName())<<" -h : Display usage instructions"<<endl
;
223 cout
<<qPrintable(file_info
.fileName())<<" -appendlic FILE1 FILE2 ...: Append license to files"<<endl
;
224 cout
<<qPrintable(file_info
.fileName())<<" -distbin : Create binary distribution"<<endl
;
227 if (QString(argv
[1]) == QString("-appendlic")) {
228 appendLicense(argc
, argv
);
230 if (QString(argv
[1]) == QString("-distbin")) {
233 if (QString(argv
[1]) == QString("-f") && argc
== 3) {
234 QApplication
a( argc
, argv
);
235 QString filename
= QString(argv
[2]);
236 GuiMainWindow
w(filename
);
238 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );
239 app_result
= a
.exec();
242 QApplication
a( argc
, argv
);
245 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );
246 app_result
= a
.exec();