|
| 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 | +} |
0 commit comments