-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdlg_centerofmass.cpp
More file actions
executable file
·95 lines (76 loc) · 2.23 KB
/
dlg_centerofmass.cpp
File metadata and controls
executable file
·95 lines (76 loc) · 2.23 KB
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
/**
* @brief
* @details
* @author Ludovic A.
* @date 2015 /2016/2017/2018
* @bug No known bugs
* @copyright GNU Public License v3
*/
#include "dlg_centerofmass.h"
#include "ui_dlg_centerofmass.h"
#include <QDebug>
#include <QDialogButtonBox>
Dlg_centerOfMass::Dlg_centerOfMass(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dlg_centerOfMass),
gridCount(0)
{
ui->setupUi(this);
xSum = ySum = wSum = 0;
}
Dlg_centerOfMass::~Dlg_centerOfMass()
{
delete ui;
}
/**
* @brief return the center of mass of the points listed by the dialog.
*/
QPointF Dlg_centerOfMass::getCoMCoord()
{
return QPointF(xSum/wSum, ySum/wSum);
}
/**
* @brief Add the description of a point to the dialog layout and proceed
* to compute CoM data.
*/
void Dlg_centerOfMass::addPoint(int x, int y, int weight)
{
//Only display weighted points in the layout, weight != 0
if (weight != 0)
{
QGridLayout *comLayout = dynamic_cast<QGridLayout*>(layout());
QString pointString = QString::number(gridCount+1)+
". Point at position (" +
QString::number(x) + "; " +
QString::number(y) + ") " +
"with weight " + QString::number(weight);
comLayout->addWidget(new QLabel(pointString), gridCount+1, 0);
gridCount++;
//CoM computation
xSum += weight*x;
ySum += weight*y;
wSum += weight;
}
}
/**
* @brief Add a standard ButtonBox
*/
void Dlg_centerOfMass::finalizeLayout()
{
QGridLayout *comLayout = dynamic_cast<QGridLayout*>(layout());
QDialogButtonBox* buttonBox;
if ( wSum != 0 )
{
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &Dlg_centerOfMass::accept);
}
else
{
ui->comLabel->setText("No weighted points found!");
buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel);
}
connect(buttonBox, &QDialogButtonBox::rejected, this, &Dlg_centerOfMass::reject);
comLayout->addWidget(new QLabel());
comLayout->addWidget(buttonBox, gridCount+2, 0);
}