src/toolsets/extprogramtoolset.cpp

Thu, 04 Jan 2018 22:52:04 +0200

author
Santeri Piippo
date
Thu, 04 Jan 2018 22:52:04 +0200
changeset 1224
5a31b6d4bf81
parent 1222
34def2630300
permissions
-rw-r--r--

undo config change

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1222
34def2630300 happy new year 2018
Santeri Piippo
parents: 1221
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QProcess>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QTemporaryFile>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QDialog>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QDialogButtonBox>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QSpinBox>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QCheckBox>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include <QComboBox>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include <QGridLayout>
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
27 #include <QSettings>
879
c5b3bc08e609 - if an external program fails to run properly, an stdout&stderr log is now printed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
28 #include <QFileInfo>
974
b2fa5f89798a Added a GuiUtilities class to contain useful non-MainWindow-related GUI functions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
29 #include "../guiutilities.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
30 #include "../main.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
31 #include "../miscallenous.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
32 #include "../mainwindow.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
33 #include "../ldDocument.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
34 #include "../radioGroup.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
35 #include "../editHistory.h"
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
36 #include "../dialogs.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
37 #include "../documentmanager.h"
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
38 #include "extprogramtoolset.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 #include "ui_ytruder.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 #include "ui_intersector.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 #include "ui_rectifier.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 #include "ui_coverer.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 #include "ui_isecalc.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 #include "ui_edger2.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 //
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
48 ConfigOption(QString IsecalcPath)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
49 ConfigOption(QString IntersectorPath)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
50 ConfigOption(QString CovererPath)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
51 ConfigOption(QString RectifierPath)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
52 ConfigOption(QString YtruderPath)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
53 ConfigOption(QString Edger2Path)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
54 ConfigOption(bool IsecalcUsesWine = false)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
55 ConfigOption(bool IntersectorUsesWine = false)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
56 ConfigOption(bool CovererUsesWine = false)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
57 ConfigOption(bool YtruderUsesWine = false)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
58 ConfigOption(bool RectifierUsesWine = false)
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
59 ConfigOption(bool Edger2UsesWine = false)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
61 ExtProgramToolset::ExtProgramToolset(MainWindow* parent) :
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
62 Toolset(parent)
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
63 {
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
64 extProgramInfo[Isecalc].name = "Isecalc";
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
65 extProgramInfo[Intersector].name = "Intersector";
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
66 extProgramInfo[Coverer].name = "Coverer";
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
67 extProgramInfo[Ytruder].name = "Ytruder";
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
68 extProgramInfo[Rectifier].name = "Rectifier";
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
69 extProgramInfo[Edger2].name = "Edger2";
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
70 }
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
71
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
72 bool ExtProgramToolset::makeTempFile(QTemporaryFile& tmp, QString& fname)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
74 if (not tmp.open())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 fname = tmp.fileName();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 tmp.close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
82 bool ExtProgramToolset::programUsesWine(ExtProgramType program)
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
83 {
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
84 #ifndef Q_OS_WIN32
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
85 return getWineSetting(program);
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
86 #else
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
87 return false;
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
88 #endif
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
89 }
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
90
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
91 bool ExtProgramToolset::getWineSetting(ExtProgramType program)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
93 return m_window->getConfigValue(externalProgramName(program) + "UsesWine").toBool();
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
94 }
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
95
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
96 QString ExtProgramToolset::getPathSetting(ExtProgramType program)
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
97 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
98 return m_window->getConfigValue(externalProgramName(program) + "Path").toString();
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
99 }
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
100
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
101 void ExtProgramToolset::setPathSetting(ExtProgramType program, QString value)
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
102 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
103 m_window->getSettings()->setValue(externalProgramName(program) + "Path", QVariant::fromValue(value));
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
104 }
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
105
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
106 void ExtProgramToolset::setWineSetting(ExtProgramType program, bool value)
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
107 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
108 m_window->getSettings()->setValue(externalProgramName(program) + "UsesWine", QVariant::fromValue(value));
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
109 }
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
110
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
111 QString ExtProgramToolset::externalProgramName(ExtProgramType program)
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
112 {
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
113 return extProgramInfo[program].name;
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
114 }
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
115
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
116 bool ExtProgramToolset::checkExtProgramPath(ExtProgramType program)
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
117 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
118 QString path = getPathSetting(program);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
120 if (not path.isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
123 ExtProgPathPrompt* dialog = new ExtProgPathPrompt(externalProgramName(program));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
125 if (dialog->exec() and not dialog->getPath().isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
127 setPathSetting(program, dialog->getPath());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 //
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
136 QString ExtProgramToolset::errorCodeString(ExtProgramType program, QProcess& process)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
138 switch(process.error())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 {
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
140 case QProcess::FailedToStart:
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
141 if (programUsesWine(program))
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
142 return tr("Program failed to start, make sure that Wine is installed and check your permissions.");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
144 return tr("Program failed to start, %1check your permissions");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
146 case QProcess::Crashed:
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
147 return tr("Crashed.");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
149 case QProcess::WriteError:
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
150 case QProcess::ReadError:
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
151 return tr("I/O error.");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
153 case QProcess::UnknownError:
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
154 return tr("Unknown error");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
156 case QProcess::Timedout:
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
157 return tr("Timed out(30 seconds)");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 return "";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 //
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
165 void ExtProgramToolset::writeObjects(const LDObjectList& objects, QFile& f)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 {
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
167 for (LDObject* obj : objects)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1009
diff changeset
169 if (obj->type() == OBJ_SubfileReference)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
171 LDSubfileReference* ref = static_cast<LDSubfileReference*>(obj);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
172 LDObjectList objs = ref->inlineContents(true, false);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
173 writeObjects(objs, f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174
1009
85fd352bae45 Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
175 for (LDObject* obj : objs)
85fd352bae45 Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
176 obj->destroy();
85fd352bae45 Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
177 }
85fd352bae45 Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
178 else if (obj->type() == OBJ_BezierCurve)
85fd352bae45 Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
179 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
180 LDBezierCurve* curve = static_cast<LDBezierCurve*>(obj);
1009
85fd352bae45 Fix rectangle mode for real
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
181 LDObjectList objs = curve->rasterize();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
182 writeObjects(objs, f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
184 for (LDObject* obj : objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 obj->destroy();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 else
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
188 f.write((obj->asText() + "\r\n").toUtf8());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 //
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
194 void ExtProgramToolset::writeObjects(const LDObjectList& objects, QString fname)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 // Write the input file
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
197 QFile f(fname);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
199 if (not f.open(QIODevice::WriteOnly | QIODevice::Text))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
201 Critical(format("Couldn't open temporary file %1 for writing: %2\n", fname, f.errorString()));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
205 writeObjects(objects, f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 f.close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 #ifdef DEBUG
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
209 QFile::copy(fname, "debug_lastInput");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 #endif
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 //
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
215 void ExtProgramToolset::writeSelection(QString fname)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
217 writeObjects(selectedObjects(), fname);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 //
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
222 void ExtProgramToolset::writeColorGroup(LDColor color, QString fname)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 LDObjectList objects;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
226 for (LDObject* obj : currentDocument()->objects())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 806
diff changeset
228 if (not obj->isColored() or obj->color() != color)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 objects << obj;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
234 writeObjects(objects, fname);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 //
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
239 bool ExtProgramToolset::runExtProgram(ExtProgramType program, QStringList argv)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
241 QString path = getPathSetting(program);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 QTemporaryFile input;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
244 #ifndef Q_OS_WIN32
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
245 if (programUsesWine(program))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
247 argv.insert(0, path);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 path = "wine";
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 }
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
250 #endif // Q_OS_WIN32
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
252 print("Running command: %1 %2\n", path, argv.join(" "));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
254 if (not input.open())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
257 QProcess process;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 // Begin!
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
260 process.setStandardInputFile(input.fileName());
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
261 process.start(path, argv);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
263 if (not process.waitForStarted())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
265 Critical(format("Couldn't start %1: %2\n", externalProgramName(program),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
266 errorCodeString(program, process)));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 // Write an enter, the utility tools all expect one
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
271 input.write("\n");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 // Wait while it runs
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
274 process.waitForFinished();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
276 QString err = "";
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
278 if (process.exitStatus() != QProcess::NormalExit)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
279 err = errorCodeString(program, process);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 // Check the return code
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
282 if (process.exitCode() != 0)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
283 err = format("Program exited abnormally(return code %1).", process.exitCode());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
285 if (not err.isEmpty())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
287 Critical(format("%1 failed: %2\n", externalProgramName(program), err));
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
288 QString filename("externalProgramOutput.txt");
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
289 QFile file(filename);
880
5dcd2e741d1c - fixed documentless objects being selected on document close
Teemu Piippo <crimsondusk64@gmail.com>
parents: 879
diff changeset
290
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
291 if (file.open(QIODevice::WriteOnly | QIODevice::Text))
879
c5b3bc08e609 - if an external program fails to run properly, an stdout&stderr log is now printed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
292 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
293 file.write(process.readAllStandardOutput());
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
294 file.write(process.readAllStandardError());
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
295 print("Wrote output and error logs to %1", QFileInfo(file).absoluteFilePath());
879
c5b3bc08e609 - if an external program fails to run properly, an stdout&stderr log is now printed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
296 }
c5b3bc08e609 - if an external program fails to run properly, an stdout&stderr log is now printed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
297 else
c5b3bc08e609 - if an external program fails to run properly, an stdout&stderr log is now printed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
298 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
299 print("Couldn't open %1 for writing: %2",
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
300 QFileInfo(filename).absoluteFilePath(), file.errorString());
879
c5b3bc08e609 - if an external program fails to run properly, an stdout&stderr log is now printed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
301 }
880
5dcd2e741d1c - fixed documentless objects being selected on document close
Teemu Piippo <crimsondusk64@gmail.com>
parents: 879
diff changeset
302
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 //
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
311 void ExtProgramToolset::insertOutput(QString fname, bool replace, QList<LDColor> colorsToReplace)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 #ifdef DEBUG
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
314 QFile::copy(fname, "./debug_lastOutput");
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
315 #endif
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 // Read the output file
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
318 QFile f(fname);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
320 if (not f.open(QIODevice::ReadOnly))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
322 Critical(format("Couldn't open temporary file %1 for reading.\n", fname));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
326 // TODO: I don't like how I need to go to the document manager to load objects from a file...
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
327 // We're not loading this as a document so it shouldn't be necessary.
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
328 LDObjectList objs = m_documents->loadFileContents(&f, nullptr, nullptr);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 // If we replace the objects, delete the selection now.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 if (replace)
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
332 m_window->deleteSelection();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
334 for (LDColor color : colorsToReplace)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
335 m_window->deleteByColor(color);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 // Insert the new objects
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
338 currentDocument()->clearSelection();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
340 for (LDObject* obj : objs)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
342 if (not obj->isScemantic())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 obj->destroy();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
348 currentDocument()->addObject(obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 obj->select();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
352 m_window->doFullRefresh();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 // Interface for Ytruder
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 // =============================================================================
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
358 void ExtProgramToolset::ytruder()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
360 setlocale(LC_ALL, "C");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
362 if (not checkExtProgramPath(Ytruder))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 QDialog* dlg = new QDialog;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 Ui::YtruderUI ui;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
367 ui.setupUi(dlg);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
369 if (not dlg->exec())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 // Read the user's choices
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 const enum { Distance, Symmetry, Projection, Radial } mode =
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 ui.mode_distance->isChecked() ? Distance :
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 ui.mode_symmetry->isChecked() ? Symmetry :
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 ui.mode_projection->isChecked() ? Projection : Radial;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 const Axis axis =
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 ui.axis_x->isChecked() ? X :
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 ui.axis_y->isChecked() ? Y : Z;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 const double depth = ui.planeDepth->value(),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 condAngle = ui.condAngle->value();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 QTemporaryFile indat, outdat;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
386 QString inDATName, outDATName;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 // Make temp files for the input and output files
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
389 if (not makeTempFile(indat, inDATName) or not makeTempFile(outdat, outDATName))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 // Compose the command-line arguments
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
393 QStringList argv {
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
394 (axis == X) ? "-x" :
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
395 (axis == Y) ? "-y" :
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
396 "-z",
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
397 (mode == Distance) ? "-d" :
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
398 (mode == Symmetry) ? "-s" :
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
399 (mode == Projection) ? "-p" :
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
400 "-r",
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
401 toString(depth),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 "-a",
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
403 toString(condAngle),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 inDATName,
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
405 outDATName,
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
406 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
408 writeSelection(inDATName);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
410 if (not runExtProgram(Ytruder, argv))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
413 insertOutput(outDATName, false, {});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 // Rectifier interface
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 // =============================================================================
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
419 void ExtProgramToolset::rectifier()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
421 setlocale(LC_ALL, "C");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
423 if (not checkExtProgramPath(Rectifier))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
426 QDialog* dlg = new QDialog;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 Ui::RectifierUI ui;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
428 ui.setupUi(dlg);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
430 if (not dlg->exec())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433 QTemporaryFile indat, outdat;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
434 QString inDATName, outDATName;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 // Make temp files for the input and output files
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
437 if (not makeTempFile(indat, inDATName) or not makeTempFile(outdat, outDATName))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 // Compose arguments
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
441 QStringList argv = {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
442 (not ui.cb_condense->isChecked()) ? "-q" : "",
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
443 (not ui.cb_subst->isChecked()) ? "-r" : "",
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 (ui.cb_condlineCheck->isChecked()) ? "-a" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 (ui.cb_colorize->isChecked()) ? "-c" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
446 "-t",
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
447 toString(ui.dsb_coplthres->value()),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
448 inDATName,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
449 outDATName
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
450 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
452 writeSelection(inDATName);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
454 if (not runExtProgram(Rectifier, argv))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
457 insertOutput(outDATName, true, {});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 // Intersector interface
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 // =============================================================================
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
463 void ExtProgramToolset::intersector()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
464 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
465 setlocale(LC_ALL, "C");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
467 if (not checkExtProgramPath(Intersector))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 QDialog* dlg = new QDialog;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
471 Ui::IntersectorUI ui;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
472 ui.setupUi(dlg);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
473 guiUtilities()->fillUsedColorsToComboBox(ui.cmb_incol);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
474 guiUtilities()->fillUsedColorsToComboBox(ui.cmb_cutcol);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
475 ui.cb_repeat->setWhatsThis("If this is set, " APPNAME " runs Intersector a second time with inverse files to cut "
974
b2fa5f89798a Added a GuiUtilities class to contain useful non-MainWindow-related GUI functions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
476 " the cutter group with the input group. Both groups are cut by the intersection.");
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
477 ui.cb_edges->setWhatsThis("Makes " APPNAME " try run Isecalc to create edgelines for the intersection.");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
478
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
479 LDColor inCol, cutCol;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480 const bool repeatInverse = ui.cb_repeat->isChecked();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
482 forever
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
484 if (not dlg->exec())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
485 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
487 inCol = ui.cmb_incol->itemData(ui.cmb_incol->currentIndex()).toInt();
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
488 cutCol = ui.cmb_cutcol->itemData(ui.cmb_cutcol->currentIndex()).toInt();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490 if (inCol == cutCol)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
492 Critical("Cannot use the same color group for both input and cutter!");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
495
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
496 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
497 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499 // Five temporary files!
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500 // indat = input group file
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501 // cutdat = cutter group file
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 // outdat = primary output
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503 // outdat2 = inverse output
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
504 // edgesdat = edges output(isecalc)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
505 QTemporaryFile indat, cutdat, outdat, outdat2, edgesdat;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
506 QString inDATName, cutDATName, outDATName, outDAT2Name, edgesDATName;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
508 if (not makeTempFile(indat, inDATName) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
509 not makeTempFile(cutdat, cutDATName) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
510 not makeTempFile(outdat, outDATName) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
511 not makeTempFile(outdat2, outDAT2Name) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
512 not makeTempFile(edgesdat, edgesDATName))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
515 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
517 QStringList parms {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518 (ui.cb_colorize->isChecked()) ? "-c" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519 (ui.cb_nocondense->isChecked()) ? "-t" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520 "-s",
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
521 toString(ui.dsb_prescale->value()),
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
522 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
524 QStringList argv_normal = parms + QStringList {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525 inDATName,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 cutDATName,
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
527 outDATName,
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
528 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
530 QStringList argv_inverse = parms + QStringList {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 cutDATName,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532 inDATName,
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
533 outDAT2Name,
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
534 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
535
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
536 writeColorGroup(inCol, inDATName);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
537 writeColorGroup(cutCol, cutDATName);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
539 if (not runExtProgram(Intersector, argv_normal))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
542 insertOutput(outDATName, false, {inCol});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
544 if (repeatInverse and runExtProgram(Intersector, argv_inverse))
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
545 insertOutput(outDAT2Name, false, {cutCol});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 969
diff changeset
547 if (ui.cb_edges->isChecked()
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
548 and checkExtProgramPath(Isecalc)
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
549 and runExtProgram(Isecalc, {inDATName, cutDATName, edgesDATName}))
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
550 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
551 insertOutput(edgesDATName, false, {});
757
8ab9fa53142b - overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
552 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
555 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556 //
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
557 void ExtProgramToolset::coverer()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
559 setlocale(LC_ALL, "C");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
561 if (not checkExtProgramPath(Coverer))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
562 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564 QDialog* dlg = new QDialog;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 Ui::CovererUI ui;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
566 ui.setupUi(dlg);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
567 guiUtilities()->fillUsedColorsToComboBox(ui.cmb_col1);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
568 guiUtilities()->fillUsedColorsToComboBox(ui.cmb_col2);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
569
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
570 LDColor in1Col, in2Col;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
571
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 forever
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
574 if (not dlg->exec())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
575 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
576
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
577 in1Col = ui.cmb_col1->itemData(ui.cmb_col1->currentIndex()).toInt();
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
578 in2Col = ui.cmb_col2->itemData(ui.cmb_col2->currentIndex()).toInt();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 if (in1Col == in2Col)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
582 Critical("Cannot use the same color group for both inputs!");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
584 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 QTemporaryFile in1dat, in2dat, outdat;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
590 QString in1DATName, in2DATName, outDATName;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
592 if (not makeTempFile(in1dat, in1DATName) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
593 not makeTempFile(in2dat, in2DATName) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
594 not makeTempFile(outdat, outDATName))
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
595 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596 return;
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
597 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
599 QStringList argv = {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
600 (ui.cb_oldsweep->isChecked() ? "-s" : ""),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
601 (ui.cb_reverse->isChecked() ? "-r" : ""),
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
602 (ui.dsb_segsplit->value() != 0 ? format("-l %1", ui.dsb_segsplit->value()) : ""),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
603 (ui.sb_bias->value() != 0 ? format("-s %1", ui.sb_bias->value()) : ""),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
604 in1DATName,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
605 in2DATName,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
606 outDATName
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
607 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
608
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
609 writeColorGroup(in1Col, in1DATName);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
610 writeColorGroup(in2Col, in2DATName);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
611
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
612 if (not runExtProgram(Coverer, argv))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
615 insertOutput(outDATName, false, {});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
619 //
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
620 void ExtProgramToolset::isecalc()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
622 setlocale(LC_ALL, "C");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
623
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
624 if (not checkExtProgramPath(Isecalc))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627 Ui::IsecalcUI ui;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628 QDialog* dlg = new QDialog;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
629 ui.setupUi(dlg);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
631 guiUtilities()->fillUsedColorsToComboBox(ui.cmb_col1);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
632 guiUtilities()->fillUsedColorsToComboBox(ui.cmb_col2);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
634 LDColor in1Col, in2Col;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636 // Run the dialog and validate input
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
637 forever
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
638 {
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
639 if (not dlg->exec())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
640 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
642 in1Col = ui.cmb_col1->itemData(ui.cmb_col1->currentIndex()).toInt();
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
643 in2Col = ui.cmb_col2->itemData(ui.cmb_col2->currentIndex()).toInt();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 if (in1Col == in2Col)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
647 Critical("Cannot use the same color group for both input and cutter!");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
648 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654 QTemporaryFile in1dat, in2dat, outdat;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
655 QString in1DATName, in2DATName, outDATName;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
656
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
657 if (not makeTempFile(in1dat, in1DATName) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
658 not makeTempFile(in2dat, in2DATName) or
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
659 not makeTempFile(outdat, outDATName))
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
660 {
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
661 return;
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
662 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
664 writeColorGroup(in1Col, in1DATName);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
665 writeColorGroup(in2Col, in2DATName);
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
666 runExtProgram(Isecalc, {in1DATName, in2DATName, outDATName});
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
667 insertOutput(outDATName, false, {});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
668 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
669
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
670 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
671 //
969
b1742ee91d5b Split actions.cpp and actionsEdit.cpp into toolsets.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
672 void ExtProgramToolset::edger2()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
673 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
674 setlocale(LC_ALL, "C");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
675
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
676 if (not checkExtProgramPath(Edger2))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
677 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
678
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
679 QDialog* dlg = new QDialog;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
680 Ui::Edger2Dialog ui;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
681 ui.setupUi(dlg);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
682
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
683 if (not dlg->exec())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
684 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
685
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686 QTemporaryFile in, out;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
687 QString inName, outName;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
688
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
689 if (not makeTempFile(in, inName) or not makeTempFile(out, outName))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
690 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
691
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
692 int unmatched = ui.unmatched->currentIndex();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
693
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
694 QStringList argv = {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
695 format("-p %1", ui.precision->value()),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
696 format("-af %1", ui.flatAngle->value()),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
697 format("-ac %1", ui.condAngle->value()),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
698 format("-ae %1", ui.edgeAngle->value()),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
699 ui.delLines->isChecked() ? "-de" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
700 ui.delCondLines->isChecked() ? "-dc" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
701 ui.colored->isChecked() ? "-c" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
702 ui.bfc->isChecked() ? "-b" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
703 ui.convex->isChecked() ? "-cx" : "",
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
704 ui.concave->isChecked() ? "-cv" : "",
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
705 unmatched == 0 ? "-u+" :(unmatched == 2 ? "-u-" : ""),
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
706 inName,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
707 outName,
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
708 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
709
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
710 writeSelection(inName);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
711
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
712 if (not runExtProgram(Edger2, argv))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
714
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1011
diff changeset
715 insertOutput(outName, true, {});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
716 }

mercurial