-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
122 lines (90 loc) · 2.35 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent *e){
double ang1,ang2,ang3,ang4;
double gx,gy;
gx=100,gy=100;
cinematica_inversa(posx,posy,&ang1,&ang2,&ang3,&ang4);
QPainter painter(this);
painter.setPen(QPen(Qt::black,3));
QLineF angL1;
angL1.setP1(QPointF(centrox,centroy));
angL1.setAngle(ang1);angL1.setLength(100);
QLineF angL2;
angL2.setP1(angL1.p2());
angL2.setAngle(ang2+angL1.angle()-180);angL2.setLength(100);
painter.setPen(QPen(Qt::blue,3));
QLineF angL3;
angL3.setP1(QPointF(centrox,centroy));
angL3.setAngle(ang3);angL3.setLength(100);
QLineF angL4;
angL4.setP1(angL3.p2());
angL4.setAngle(ang4+angL3.angle()-180);angL4.setLength(100);
if(ui->radioButton->isChecked() || ui->radioButton_2->isChecked()){
painter.drawLine(angL1);
painter.drawLine(angL2);
}
if(ui->radioButton_2->isChecked() || ui->radioButton_3->isChecked()){
painter.drawLine(angL3);
painter.drawLine(angL4);
}
painter.setPen(QPen(Qt::red,3));
painter.drawEllipse(QPointF(centrox,centroy),200,200);
}
void MainWindow::mousePressEvent(QMouseEvent *e){
if(e->buttons() == Qt::LeftButton){
posx=e->pos().x()-centrox;
posy=centroy-e->pos().y();
ui->spinBox_3->setValue(posx);
ui->spinBox_4->setValue(posy);
update();
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *e){
if(e->buttons() == Qt::LeftButton){
posx=e->pos().x()-centrox;
posy=centroy-e->pos().y();
ui->spinBox_3->setValue(posx);
ui->spinBox_4->setValue(posy);
update();
}
}
void MainWindow::on_spinBox_valueChanged(const QString &arg1)
{
}
void MainWindow::on_spinBox_2_valueChanged(const QString &arg1)
{
}
void MainWindow::on_radioButton_2_clicked()
{
update();
}
void MainWindow::on_radioButton_clicked()
{
update();
}
void MainWindow::on_radioButton_3_clicked()
{
update();
}
void MainWindow::on_spinBox_3_valueChanged(const QString &arg1)
{
posx=ui->spinBox_3->value();
update();
}
void MainWindow::on_spinBox_4_valueChanged(const QString &arg1)
{
posy=ui->spinBox_4->value();
update();
}