Skip to content

Commit e632259

Browse files
committed
Add unit buttons and the ConfigurationDialog class
The unit names and conversion factors are in configdialog.cpp.
1 parent 85a843b commit e632259

13 files changed

+409
-10
lines changed

Diff for: CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ find_package(Boost COMPONENTS program_options)
3434
find_package(Mitobrevno)
3535
find_package(Threads)
3636

37-
#qt5_add_resources(lib_resources wolkenbase.qrc)
37+
qt5_add_resources(lib_resources wolkenbase.qrc)
3838
qt5_add_translation(qm_files wolkenbase_en.ts wolkenbase_es.ts)
3939
# To update translations, run "lupdate *.cpp -ts *.ts" in the source directory.
4040

4141
# point.cpp must be before las.cpp for noPoint to be initialized to nanxyz.
42-
add_executable(wolkenbase angle.cpp binio.cpp boundrect.cpp brevno.cpp eisenstein.cpp
42+
add_executable(wolkenbase angle.cpp binio.cpp boundrect.cpp
43+
brevno.cpp configdialog.cpp eisenstein.cpp
4344
fileio.cpp flowsnake.cpp freeram.cpp point.cpp las.cpp ldecimal.cpp
4445
lissajous.cpp mainwindow.cpp octree.cpp ps.cpp quaternion.cpp
4546
random.cpp relprime.cpp shape.cpp testpattern.cpp
46-
threads.cpp wkt.cpp wolkenbase.cpp wolkencanvas.cpp ${qm_files})
47+
threads.cpp unitbutton.cpp wkt.cpp wolkenbase.cpp wolkencanvas.cpp
48+
${lib_resources} ${qm_files})
4749

4850
add_executable(wolkencli angle.cpp binio.cpp boundrect.cpp brevno.cpp eisenstein.cpp
4951
flowsnake.cpp freeram.cpp point.cpp las.cpp ldecimal.cpp

Diff for: configdialog.cpp

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/******************************************************/
2+
/* */
3+
/* configdialog.cpp - configuration dialog */
4+
/* */
5+
/******************************************************/
6+
/* Copyright 2020 Pierre Abbat.
7+
* This file is part of Wolkenbase.
8+
*
9+
* Wolkenbase is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* Wolkenbase is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with Wolkenbase. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
#include <cmath>
23+
#include "configdialog.h"
24+
#include "ldecimal.h"
25+
#include "threads.h"
26+
27+
using namespace std;
28+
29+
const double conversionFactors[4]={1,0.3048,12e2/3937,0.3047996};
30+
const char unitNames[4][12]=
31+
{
32+
QT_TRANSLATE_NOOP("ConfigurationDialog","Meter"),
33+
QT_TRANSLATE_NOOP("ConfigurationDialog","Int'l foot"),
34+
QT_TRANSLATE_NOOP("ConfigurationDialog","US foot"),
35+
QT_TRANSLATE_NOOP("ConfigurationDialog","Indian foot")
36+
};
37+
const double tolerances[10]={1e-2,25e-3,5e-2,1e-1,15e-2,2e-1,1/3.,2/3.,1.,10/3.};
38+
const char toleranceStr[10][7]=
39+
{
40+
"10 mm","25 mm","50 mm","100 mm","150 mm","200 mm","1/3 m","2/3 m","1 m","10/3 m"
41+
};
42+
const char shapeNames[2][12]=
43+
{
44+
QT_TRANSLATE_NOOP("Printer3dTab","Absolute"),
45+
QT_TRANSLATE_NOOP("Printer3dTab","Rectangular")
46+
};
47+
48+
GeneralTab::GeneralTab(QWidget *parent):QWidget(parent)
49+
{
50+
lengthUnitLabel=new QLabel(this);
51+
toleranceLabel=new QLabel(this);
52+
toleranceInUnit=new QLabel(this);
53+
threadLabel=new QLabel(this);
54+
threadDefault=new QLabel(this);
55+
lengthUnitBox=new QComboBox(this);
56+
toleranceBox=new QComboBox(this);
57+
threadInput=new QLineEdit(this);
58+
exportEmptyCheck=new QCheckBox(tr("Export empty"),this);
59+
gridLayout=new QGridLayout(this);
60+
setLayout(gridLayout);
61+
gridLayout->addWidget(lengthUnitLabel,1,0);
62+
gridLayout->addWidget(lengthUnitBox,1,1);
63+
gridLayout->addWidget(toleranceLabel,2,0);
64+
gridLayout->addWidget(toleranceBox,2,1);
65+
gridLayout->addWidget(toleranceInUnit,2,2);
66+
gridLayout->addWidget(threadLabel,3,0);
67+
gridLayout->addWidget(threadInput,3,1);
68+
gridLayout->addWidget(threadDefault,3,2);
69+
gridLayout->addWidget(exportEmptyCheck,4,1);
70+
}
71+
72+
Printer3dTab::Printer3dTab(QWidget *parent):QWidget(parent)
73+
{
74+
int i;
75+
shapeLabel=new QLabel(this);
76+
shapeLabel->setText(tr("Shape"));
77+
lengthLabel=new QLabel(this);
78+
lengthLabel->setText(tr("Length"));
79+
widthLabel=new QLabel(this);
80+
widthLabel->setText(tr("Width"));
81+
heightLabel=new QLabel(this);
82+
heightLabel->setText(tr("Height"));
83+
baseLabel=new QLabel(this);
84+
baseLabel->setText(tr("Base"));
85+
scaleLabel=new QLabel(this);
86+
scaleLabel->setText(tr("Scale"));
87+
colonLabel=new QLabel(this);
88+
colonLabel->setText(tr(":"));
89+
for (i=0;i<sizeof(mmLabel)/sizeof(mmLabel[0]);i++)
90+
{
91+
mmLabel[i]=new QLabel(this);
92+
mmLabel[i]->setText(tr("mm"));
93+
}
94+
gridLayout=new QGridLayout(this);
95+
shapeBox=new QComboBox(this);
96+
for (i=0;i<sizeof(shapeNames)/sizeof(shapeNames[0]);i++)
97+
{
98+
shapeBox->addItem(tr(shapeNames[i]));
99+
}
100+
lengthInput=new QLineEdit(this);
101+
widthInput=new QLineEdit(this);
102+
heightInput=new QLineEdit(this);
103+
baseInput=new QLineEdit(this);
104+
scaleNumInput=new QLineEdit(this);
105+
scaleDenomInput=new QLineEdit(this);
106+
gridLayout->addWidget(shapeLabel,0,0,1,1);
107+
gridLayout->addWidget(shapeBox,0,1,1,3);
108+
gridLayout->addWidget(lengthLabel,1,0,1,1);
109+
gridLayout->addWidget(lengthInput,1,1,1,3);
110+
gridLayout->addWidget(mmLabel[0],1,4,1,1);
111+
gridLayout->addWidget(widthLabel,2,0,1,1);
112+
gridLayout->addWidget(widthInput,2,1,1,3);
113+
gridLayout->addWidget(mmLabel[1],2,4,1,1);
114+
gridLayout->addWidget(heightLabel,3,0,1,1);
115+
gridLayout->addWidget(heightInput,3,1,1,3);
116+
gridLayout->addWidget(mmLabel[2],3,4,1,1);
117+
gridLayout->addWidget(baseLabel,4,0,1,1);
118+
gridLayout->addWidget(baseInput,4,1,1,3);
119+
gridLayout->addWidget(mmLabel[3],4,4,1,1);
120+
gridLayout->addWidget(scaleLabel,5,0,1,1);
121+
gridLayout->addWidget(scaleNumInput,5,1,1,1);
122+
gridLayout->addWidget(colonLabel,5,2,1,1);
123+
gridLayout->addWidget(scaleDenomInput,5,3,1,1);
124+
connect(shapeBox,SIGNAL(currentIndexChanged(int)),this,SLOT(disableSome()));
125+
connect(lengthInput,SIGNAL(textChanged(QString)),this,SIGNAL(contentChanged()));
126+
connect(widthInput,SIGNAL(textChanged(QString)),this,SIGNAL(contentChanged()));
127+
connect(heightInput,SIGNAL(textChanged(QString)),this,SIGNAL(contentChanged()));
128+
connect(baseInput,SIGNAL(textChanged(QString)),this,SIGNAL(contentChanged()));
129+
connect(scaleNumInput,SIGNAL(textChanged(QString)),this,SIGNAL(contentChanged()));
130+
connect(scaleDenomInput,SIGNAL(textChanged(QString)),this,SIGNAL(contentChanged()));
131+
connect(shapeBox,SIGNAL(currentIndexChanged(int)),this,SIGNAL(contentChanged()));
132+
}
133+
134+
ConfigurationDialog::ConfigurationDialog(QWidget *parent):QDialog(parent)
135+
{
136+
boxLayout=new QVBoxLayout(this);
137+
tabWidget=new QTabWidget(this);
138+
general=new GeneralTab(this);
139+
printTab=new Printer3dTab(this);
140+
buttonBox=new QDialogButtonBox(this);
141+
okButton=new QPushButton(tr("OK"),this);
142+
cancelButton=new QPushButton(tr("Cancel"),this);
143+
buttonBox->addButton(okButton,QDialogButtonBox::AcceptRole);
144+
buttonBox->addButton(cancelButton,QDialogButtonBox::RejectRole);
145+
boxLayout->addWidget(tabWidget);
146+
boxLayout->addWidget(buttonBox);
147+
tabWidget->addTab(general,tr("General"));
148+
tabWidget->addTab(printTab,tr("3D Printer"));
149+
connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
150+
connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
151+
connect(general->lengthUnitBox,SIGNAL(currentIndexChanged(int)),this,SLOT(updateToleranceConversion()));
152+
connect(general->toleranceBox,SIGNAL(currentIndexChanged(int)),this,SLOT(updateToleranceConversion()));
153+
connect(printTab,SIGNAL(contentChanged()),this,SLOT(checkValid()));
154+
}
155+
156+
void ConfigurationDialog::set(double lengthUnit,int threads)
157+
{
158+
int i;
159+
general->lengthUnitBox->clear();
160+
general->toleranceBox->clear();
161+
general->lengthUnitLabel->setText(tr("Length unit"));
162+
general->toleranceLabel->setText(tr("Tolerance"));
163+
general->threadLabel->setText(tr("Threads:"));
164+
general->threadDefault->setText(tr("default is %n","",thread::hardware_concurrency()));
165+
for (i=0;i<sizeof(conversionFactors)/sizeof(conversionFactors[1]);i++)
166+
{
167+
general->lengthUnitBox->addItem(tr(unitNames[i]));
168+
}
169+
for (i=0;i<sizeof(conversionFactors)/sizeof(conversionFactors[1]);i++)
170+
{
171+
if (lengthUnit==conversionFactors[i])
172+
general->lengthUnitBox->setCurrentIndex(i);
173+
}
174+
general->threadInput->setText(QString::number(threads));
175+
}
176+
177+
void ConfigurationDialog::updateToleranceConversion()
178+
{
179+
double tolIn;
180+
tolIn=tolerances[general->toleranceBox->currentIndex()]/conversionFactors[general->lengthUnitBox->currentIndex()];
181+
if (std::isfinite(tolIn))
182+
{
183+
general->toleranceInUnit->setText(QString::fromStdString(ldecimal(tolIn,tolIn/1000)));
184+
}
185+
}
186+
187+
void ConfigurationDialog::checkValid()
188+
{
189+
}
190+
191+
void ConfigurationDialog::accept()
192+
{
193+
settingsChanged(conversionFactors[general->lengthUnitBox->currentIndex()],
194+
general->threadInput->text().toInt());
195+
QDialog::accept();
196+
}

Diff for: configdialog.h

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/******************************************************/
2+
/* */
3+
/* configdialog.h - configuration dialog */
4+
/* */
5+
/******************************************************/
6+
/* Copyright 2020 Pierre Abbat.
7+
* This file is part of Wolkenbase.
8+
*
9+
* Wolkenbase is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* Wolkenbase is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with Wolkenbase. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
#ifndef CONFIGDIALOG_H
24+
#define CONFIGDIALOG_H
25+
#include <vector>
26+
#include <QDialog>
27+
#include <QDialogButtonBox>
28+
#include <QLabel>
29+
#include <QComboBox>
30+
#include <QCheckBox>
31+
#include <QPushButton>
32+
#include <QLineEdit>
33+
#include <QGridLayout>
34+
35+
extern const double conversionFactors[4];
36+
extern const char unitNames[4][12];
37+
38+
class GeneralTab: public QWidget
39+
{
40+
Q_OBJECT
41+
public:
42+
GeneralTab(QWidget *parent=nullptr);
43+
QLabel *lengthUnitLabel,*toleranceLabel;
44+
QLabel *threadLabel,*threadDefault;
45+
QLabel *toleranceInUnit;
46+
QComboBox *lengthUnitBox,*toleranceBox;
47+
QGridLayout *gridLayout;
48+
QLineEdit *threadInput;
49+
QCheckBox *exportEmptyCheck;
50+
};
51+
52+
class Printer3dTab: public QWidget
53+
{
54+
Q_OBJECT
55+
public:
56+
Printer3dTab(QWidget *parent=nullptr);
57+
QLabel *shapeLabel;
58+
QLabel *lengthLabel,*widthLabel,*heightLabel;
59+
QLabel *baseLabel;
60+
QLabel *scaleLabel,*colonLabel;
61+
QLabel *mmLabel[4];
62+
QGridLayout *gridLayout;
63+
QComboBox *shapeBox;
64+
QLineEdit *lengthInput,*widthInput,*heightInput;
65+
QLineEdit *baseInput;
66+
QLineEdit *scaleNumInput,*scaleDenomInput;
67+
signals:
68+
void contentChanged();
69+
public slots:
70+
};
71+
72+
class ConfigurationDialog: public QDialog
73+
{
74+
Q_OBJECT
75+
public:
76+
ConfigurationDialog(QWidget *parent=nullptr);
77+
signals:
78+
void settingsChanged(double lu,int thr);
79+
public slots:
80+
void set(double lengthUnit,int threads);
81+
void updateToleranceConversion();
82+
void checkValid();
83+
virtual void accept();
84+
private:
85+
QTabWidget *tabWidget;
86+
GeneralTab *general;
87+
Printer3dTab *printTab;
88+
QVBoxLayout *boxLayout;
89+
QDialogButtonBox *buttonBox;
90+
QPushButton *okButton,*cancelButton;
91+
};
92+
#endif
93+

Diff for: indian-foot.png

6.15 KB
Loading

Diff for: international-foot.png

4.23 KB
Loading

Diff for: mainwindow.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,16 @@ void MainWindow::makeActions()
280280
helpMenu->addAction(aboutQtAction);
281281
connect(aboutQtAction,SIGNAL(triggered(bool)),this,SLOT(aboutQt()));
282282
// Toolbar
283-
/*for (i=0;i<4;i++)
283+
for (i=0;i<4;i++)
284284
{
285285
unitButtons[i]=new UnitButton(this,conversionFactors[i]);
286-
unitButtons[i]->setText(configDialog->tr(unitNames[i])); // lupdate warns but it works
286+
//unitButtons[i]->setText(configDialog->tr(unitNames[i])); // lupdate warns but it works
287287
unitButtons[i]->setIcon(QIcon(unitIconNames[i]));
288288
connect(this,SIGNAL(lengthUnitChanged(double)),unitButtons[i],SLOT(setUnit(double)));
289289
connect(unitButtons[i],SIGNAL(triggered(bool)),unitButtons[i],SLOT(selfTriggered(bool)));
290290
connect(unitButtons[i],SIGNAL(unitChanged(double)),this,SLOT(setUnit(double)));
291291
toolbar->addAction(unitButtons[i]);
292-
}*/
292+
}
293293
}
294294

295295
void MainWindow::makeStatusBar()

Diff for: mainwindow.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include <QPixmap>
2727
#include <string>
2828
#include <array>
29-
//#include "configdialog.h"
30-
//#include "unitbutton.h"
29+
#include "configdialog.h"
30+
#include "unitbutton.h"
3131
#include "wolkencanvas.h"
3232

3333
class MainWindow: public QMainWindow
@@ -87,6 +87,6 @@ public slots:
8787
QAction *exportAction,*stopAction,*resumeAction,*exitAction;
8888
QAction *configureAction;
8989
QAction *aboutProgramAction,*aboutQtAction;
90-
//UnitButton *unitButtons[4];
90+
UnitButton *unitButtons[4];
9191
WolkenCanvas *canvas;
9292
};

Diff for: meter.png

1.86 KB
Loading

Diff for: unitbutton.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/******************************************************/
2+
/* */
3+
/* unitbutton.cpp - unit buttons */
4+
/* */
5+
/******************************************************/
6+
/* Copyright 2020 Pierre Abbat.
7+
* This file is part of Wolkenbase.
8+
*
9+
* Wolkenbase is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* Wolkenbase is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with Wolkenbase. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
#include "unitbutton.h"
23+
24+
using namespace std;
25+
26+
UnitButton::UnitButton(QObject *parent,double fac):QAction(parent)
27+
{
28+
factor=fac;
29+
setCheckable(true);
30+
}
31+
32+
void UnitButton::setUnit(double unit)
33+
{
34+
setChecked(unit==factor);
35+
}
36+
37+
void UnitButton::selfTriggered(bool dummy)
38+
{
39+
unitChanged(factor);
40+
}

0 commit comments

Comments
 (0)