-
Notifications
You must be signed in to change notification settings - Fork 5
/
cidialog.cpp
134 lines (129 loc) · 4.44 KB
/
cidialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/******************************************************/
/* */
/* cidialog.cpp - contour interval dialog */
/* */
/******************************************************/
/* Copyright 2020,2021 Pierre Abbat.
* This file is part of PerfectTIN.
*
* PerfectTIN is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* PerfectTIN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and Lesser General Public License along with PerfectTIN. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "cidialog.h"
using namespace std;
const double tol[]=
{
0.1,0.2,1/3.,0.5
};
const char tolStr[4][5]=
{
"1/10","1/5","1/3","1/2"
};
ContourIntervalDialog::ContourIntervalDialog(QWidget *parent):QDialog(parent)
{
intervalLabel=new QLabel(tr("Contour interval"),this);
toleranceLabel=new QLabel(tr("Relative tolerance"),this);
currentInterval=new QLabel(tr("None"),this);
intervalBox=new QComboBox(this);
toleranceBox=new QComboBox(this);
okButton=new QPushButton(tr("OK"),this);
cancelButton=new QPushButton(tr("Cancel"),this);
gridLayout=new QGridLayout(this);
setLayout(gridLayout);
gridLayout->addWidget(intervalLabel,0,0);
gridLayout->addWidget(currentInterval,0,1);
gridLayout->addWidget(intervalBox,0,2);
gridLayout->addWidget(toleranceLabel,1,0);
gridLayout->addWidget(toleranceBox,1,2);
gridLayout->addWidget(okButton,2,1);
gridLayout->addWidget(cancelButton,2,2);
contourInterval=nullptr;
okButton->setEnabled(false);
okButton->setDefault(true);
connect(intervalBox,SIGNAL(currentIndexChanged(int)),this,SLOT(selectInterval(int)));
connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
}
void ContourIntervalDialog::set(ContourInterval *ci,double unit)
{
bool precise;
int i,closeInx=-1;
ContourInterval temp;
double mantissa,closeDiff=INFINITY;
contourInterval=ci;
relTol=ci->getRelativeTolerance();
intervalBox->clear();
toleranceBox->clear();
ciList.clear();
if (ci)
{
/* The Indian and US feet are 1.3 ppm less and 2 ppm more than the
* international foot. If the current contour interval differs by more
* than 1.15 ppm from 1, 2, or 5 times a power of 10 in the current unit,
* display it with six more digits of precision to show that it's in
* a different unit.
*/
mantissa=frac(log10(ci->mediumInterval()/unit));
precise=fabs(mantissa)>0.0000005 && fabs(mantissa-0.30103)>0.0000005 &&
fabs(mantissa-0.69897)>0.0000005 && fabs(mantissa-1)>0.0000005;
currentInterval->setText(QString::fromStdString(ci->valueString(unit,precise)));
okButton->setEnabled(true);
for (i=rint(3*log10(MININTERVAL/3/unit));
i<=rint(3*log10(MAXINTERVAL*3/unit));i++)
{
temp=ContourInterval(unit,i,false);
if (fabs(log(ci->mediumInterval()/temp.mediumInterval()))<closeDiff)
{
closeDiff=fabs(log(ci->mediumInterval()/temp.mediumInterval()));
closeInx=intervalBox->count();
}
if (temp.mediumInterval()>=MININTERVAL && temp.mediumInterval()<=MAXINTERVAL)
{
ciList.push_back(temp);
intervalBox->addItem(QString::fromStdString(temp.valueString(unit,false)));
}
}
intervalBox->setCurrentIndex(closeInx);
for (i=0;i<sizeof(tol)/sizeof(tol[0]);i++)
{
toleranceBox->addItem(QString::fromStdString(tolStr[i]));
if (relTol==tol[i])
toleranceBox->setCurrentIndex(i);
}
}
else
{
currentInterval->setText(tr("None"));
okButton->setEnabled(false);
}
}
void ContourIntervalDialog::selectInterval(int n)
{
if (n>=0 && n<ciList.size())
{
//cout<<n<<" selected"<<endl;
selectedInterval=ciList[n];
}
}
void ContourIntervalDialog::accept()
{
if (contourInterval)
{
*contourInterval=selectedInterval;
contourInterval->setRelativeTolerance(tol[toleranceBox->currentIndex()]);
}
QDialog::accept();
}