-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
78 lines (68 loc) · 2.16 KB
/
MainWindow.cpp
File metadata and controls
78 lines (68 loc) · 2.16 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
/* ====================================================
# Copyright (C)2020 2021 fhyPayaso All rights reserved.
#
# @Author : fhyPayaso
# @Date : 2020/12/20
# @Email : 401619823@qq.com
# @Description :
# ====================================================*/
#include "MainWindow.h"
#include "ui_mainwindow.h"
#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
openGLWidget = new OpenGLWidget();
fileBtn = new QPushButton("Select DWG File",this);
pathLabel = new QLabel("please select file");
QVBoxLayout *centralLayout = new QVBoxLayout();
centralLayout->addWidget(fileBtn);
centralLayout->addWidget(pathLabel);
centralLayout->addWidget(openGLWidget);
this->ui->centralwidget->setLayout(centralLayout);
connect(fileBtn, &QAbstractButton::clicked, this, &MainWindow::onBtnClick);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updateGLWidget()
{
if (filePath.empty() || filePath.size() == 0)
return;
bool badState = false;
dx_data fData;
dx_iface *input = new dx_iface();
badState = input->printText(filePath, &fData);
if (!badState)
{
cout << "dwg file load error" << endl;
pathLabel->setText("dwg file load error");
return;
}
else
pathLabel->setText(filePath.c_str());
vector<DwgObject> objectList;
auto mDwgData = input->cData;
int size = mDwgData->mBlock->ent.size();
cout << "dwg file object num: " << size << endl;
for (std::list<DRW_Entity *>::const_iterator it =
mDwgData->mBlock->ent.begin(); it != mDwgData->mBlock->ent.end(); ++it)
{
DRW_Entity *e = *it;
DwgObject obj;
obj.type = e->eType;
obj.parse(e);
objectList.push_back(obj);
}
openGLWidget->setDataList(objectList);
}
void MainWindow::onBtnClick()
{
QString filter = "DWG File (*.dwg)";
QString path = QFileDialog::getOpenFileName(this, tr("Open DWG File"), ".", filter);
std::cout << path.toStdString() << std::endl;
filePath = path.toStdString();
updateGLWidget();
}