skeleton for feature snap operation (edge sharpening)
[engrid-github.git] / src / main.cpp
blob5f37605b647f2ef477ed6377a3ca27a4f3ed0de9
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include <QtCore>
22 #include <QtGui>
23 #include <QApplication>
24 #include <QFile>
25 #include <QTextStream>
26 #include <QDate>
28 #include "guimainwindow.h"
29 #include "filetemplate.h"
31 #include "geometrytools.h"
32 using namespace GeometryTools;
34 ///\todo replace with shellscript?
35 void appendLicense(int argc, char ** argv)
37 int first_year = 2008;
38 QString first_year_text;
39 first_year_text.setNum(first_year);
40 int year = QDate::currentDate().year();
41 QString year_text;
42 year_text.setNum(year);
43 if (year-first_year == 1) {
44 year_text = first_year_text + "," + year_text;
46 if (year-first_year > 1) {
47 year_text = first_year_text + "-" + year_text;
49 QString year_end_text = " +\n";
50 if (year == first_year) {
51 year_end_text = " " + year_end_text;
53 for (int i = 2; i < argc; ++i) {
54 QString filename(argv[i]);
55 QString comment = "// ";
56 QString buffer = "";
57 bool script = false;
58 if (filename.right(3) == ".sh") script = true;
59 if (filename.right(3) == ".py") script = true;
60 if (filename.right(5) == ".bash") script = true;
61 QFile file(filename);
62 file.open(QIODevice::ReadOnly);
63 QTextStream f(&file);
64 if (script) {
65 comment = "# ";
66 QString line = f.readLine();
67 buffer += line + "\n";
69 buffer += comment + "\n";
70 buffer += comment + "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
71 buffer += comment + "+ +\n";
72 buffer += comment + "+ This file is part of enGrid. +\n";
73 buffer += comment + "+ +\n";
74 buffer += comment + "+ Copyright " + year_text + " enGits GmbH" + year_end_text;
75 buffer += comment + "+ +\n";
76 buffer += comment + "+ enGrid is free software: you can redistribute it and/or modify +\n";
77 buffer += comment + "+ it under the terms of the GNU General Public License as published by +\n";
78 buffer += comment + "+ the Free Software Foundation, either version 3 of the License, or +\n";
79 buffer += comment + "+ (at your option) any later version. +\n";
80 buffer += comment + "+ +\n";
81 buffer += comment + "+ enGrid is distributed in the hope that it will be useful, +\n";
82 buffer += comment + "+ but WITHOUT ANY WARRANTY; without even the implied warranty of +\n";
83 buffer += comment + "+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\n";
84 buffer += comment + "+ GNU General Public License for more details. +\n";
85 buffer += comment + "+ +\n";
86 buffer += comment + "+ You should have received a copy of the GNU General Public License +\n";
87 buffer += comment + "+ along with enGrid. If not, see <http://www.gnu.org/licenses/>. +\n";
88 buffer += comment + "+ +\n";
89 buffer += comment + "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
90 buffer += comment + "\n";
92 bool src_code = false;
93 while (!f.atEnd()) {
94 QString line = f.readLine();
95 if (!src_code) {
96 if (line.size() >= comment.length()-1) {
97 if (line.left(comment.length()-1) != comment.left(comment.length()-1)) {
98 src_code = true;
100 } else {
101 src_code = true;
104 if (src_code) {
105 buffer += line + "\n";
110 QFile file(filename);
111 file.open(QIODevice::WriteOnly);
112 QTextStream f(&file);
113 f << buffer;
118 ///\todo replace with shellscript?
119 void makeDistribution()
121 system ("ldd ./engrid > ldd.out");
122 system ("mkdir enGrid");
123 system ("cp engrid enGrid");
125 QFile file("ldd.out");
126 file.open(QIODevice::ReadOnly);
127 QTextStream f(&file);
128 while (!f.atEnd()) {
129 QString line = f.readLine();
130 QTextStream l(&line, QIODevice::ReadOnly);
131 QString word;
132 l >> word;
133 if (word.left(1) != "/") {
134 l >> word;
135 l >> word;
137 QString cmd = "cp " + word + " enGrid";
138 system(qPrintable(cmd));
139 cout << qPrintable(cmd) << endl;
142 system ("tar czf enGrid_bin.tar.gz enGrid/*");
143 system ("rm -rf enGrid");
144 system ("rm ldd.out");
147 /** Message handler to allow output of Qt objects in the terminal (stderr) or the logfile/output window of engrid (stdout)
148 qDebug() is used for writing custom debug output.
149 qWarning() is used to report warnings and recoverable errors in your application.
150 qCritical() is used for writing critical error mesages and reporting system errors.
151 qFatal() is used for writing fatal error messages shortly before exiting.
153 void engridMessageHandler(QtMsgType type, const char *msg)
155 switch (type) {
156 case QtDebugMsg:
157 // fprintf(stdout, "%s", msg);
158 cout<<msg<<endl;
159 break;
160 case QtWarningMsg:
161 // fprintf(stderr, "%s", msg);
162 cerr<<msg<<endl;
163 break;
164 case QtCriticalMsg:
165 fprintf(stderr, "Critical: %s\n", msg);
166 break;
167 case QtFatalMsg:
168 fprintf(stderr, "Fatal: %s\n", msg);
169 abort();
173 double getNumber(QString text)
175 double myNumber = 0;
176 while (true) {
177 qDebug() << text;
178 string input = "";
179 getline(cin, input);
181 // This code converts from string to number safely.
182 stringstream myStream(input);
183 if (myStream >> myNumber)
184 break;
185 qDebug() << "Invalid number, please try again" << endl;
187 return myNumber;
190 int main( int argc, char ** argv )
193 #ifdef QT_DEBUG
194 //omp_set_num_threads(1);
195 #endif
196 qInstallMsgHandler(engridMessageHandler);
197 Q_INIT_RESOURCE(engrid);
198 int app_result=0;
200 ///\todo use gnu getopt ? Check windows/mac compatibility.
201 if (argc > 1) {
202 if (QString(argv[1]) == QString("-h")) {
203 QFileInfo file_info(argv[0]);
204 cout<<"Usage:"<<endl;
205 cout<<qPrintable(file_info.fileName())<<" : start engrid"<<endl;
206 cout<<qPrintable(file_info.fileName())<<" -f FILE : start engrid and open FILE"<<endl;
207 cout<<qPrintable(file_info.fileName())<<" -h : Display usage instructions"<<endl;
208 cout<<qPrintable(file_info.fileName())<<" -appendlic FILE1 FILE2 ...: Append license to files"<<endl;
209 cout<<qPrintable(file_info.fileName())<<" -distbin : Create binary distribution"<<endl;
210 exit(0);
212 if (QString(argv[1]) == QString("-appendlic")) {
213 appendLicense(argc, argv);
215 if (QString(argv[1]) == QString("-distbin")) {
216 makeDistribution();
218 if (QString(argv[1]) == QString("-f") && argc == 3) {
219 QApplication a( argc, argv );
220 QString filename = QString(argv[2]);
221 GuiMainWindow w(filename);
222 w.show();
223 a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
224 app_result = a.exec();
226 } else {
227 QApplication a( argc, argv );
228 GuiMainWindow w;
229 w.show();
230 a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
231 app_result = a.exec();
234 return app_result;