-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
306 lines (260 loc) · 8.73 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
MIT License
Copyright (c) 2021 Ramesh Choudhary
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "aboutdialog.h"
#include "dialog.h"
#include "scene.h"
#include<QFileDialog>
#include<QDebug>
QList<QList<bool>> demoMat =
{{0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
{1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0}};
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
resize(900,800);
setWindowTitle("FDG Layout");
scene = new Scene(this);
view = new View(ui->centralwidget);
ui->verticalLayout->addWidget(view);
graphLayout = new GraphLayout(QList<QList<bool>>(),scene,view);
scene->setBackgroundBrush(QBrush("black"));
view->setScene(scene);
ui->settingFrame->show();
ui->menubar->addAction(ui->actionSetting);
connect(ui->actionSetting,&QAction::triggered,this,[this](){
if(ui->settingFrame->isVisible())ui->settingFrame->hide();
else ui->settingFrame->show();
graphLayout->fitInView();
});
ui->animationSpeedSpinBox->setRange(0,50);
ui->animationSpeedSpinBox->setValue(47);
ui->mechanicalForceSlider->setRange(0,6000);
ui->mechanicalForceSlider->setValue(500);
ui->electricalForceSlider->setRange(0,99999999);
ui->electricalForceSlider->setValue(1353383);
ui->nodeSizeSpinBox->setValue(20);
ui->nodeSizeSpinBox->setRange(1,50);
ui->EdgeSizeSpinBox->setValue(3);
ui->EdgeSizeSpinBox->setRange(1,25);
ui->dragSpinBox->setRange(0,1000);
ui->dragSpinBox->setValue(4);
ui->maxSpeedSpinBox->setRange(1,1000);
ui->maxSpeedSpinBox->setValue(70);
ui->actionNo_Editing->setChecked(true);
connect(view,&View::transformed,this,[this](){
QTransform t = view->transform();
int edgeSize = (edgeWidthFactor/3)+edgeWidthFactor/(t.m11()*1.414);
graphLayout->setEdgeSize(edgeSize);
int nodeSize = (nodeRadiusFactor/3)+nodeRadiusFactor/(t.m11()*1.414);
graphLayout->setNodeRadius(nodeSize);
});
graphLayout->startAnimation();
}
MainWindow::~MainWindow()
{
delete graphLayout;
delete view;
delete ui;
}
//cmd
void MainWindow::loadFromAdjacencyMatrix(QString data)
{
graphLayout->loadAdjacencyMatrix(data,QStringList());
}
void MainWindow::on_actionzoom_in_triggered()
{
view->scaleView(1);
}
void MainWindow::on_actionzoom_out_triggered()
{
view->scaleView(-1);
}
void MainWindow::on_dragSpinBox_valueChanged(int arg1)
{
graphLayout->setDRAG(arg1*0.001f);
}
void MainWindow::on_animationSpeedSpinBox_valueChanged(int arg1)
{
if(arg1==0)graphLayout->setFrameInterval(0);
else graphLayout->setFrameInterval(1001-arg1*20);
}
void MainWindow::on_EdgeSizeSpinBox_valueChanged(int arg1)
{
QTransform t = view->transform();
edgeWidthFactor=arg1;
int size = (edgeWidthFactor/3)+edgeWidthFactor/(t.m11()*1.414);
graphLayout->setEdgeSize(size);
}
void MainWindow::on_nodeSizeSpinBox_valueChanged(int arg1)
{
QTransform t = view->transform();
nodeRadiusFactor=arg1;
int size = (nodeRadiusFactor/3)+nodeRadiusFactor/(t.m11()*1.414);
graphLayout->setNodeRadius(size);
}
void MainWindow::on_actionClear_Scene_triggered()
{
graphLayout->clearLayout();
}
void MainWindow::on_mechanicalForceSlider_valueChanged(int value)
{
graphLayout->setSpring_RestingLength(value);
QTimer::singleShot(100,this,[this](){ graphLayout->fitInView(); });
}
void MainWindow::on_electricalForceSlider_valueChanged(int value)
{
graphLayout->setCharge(value);
QTimer::singleShot(100,this,[this](){ graphLayout->fitInView(); });
}
void MainWindow:: on_actionFit_In_View_triggered()
{
graphLayout->fitInView();
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
if(event->size().width()>10 && event->size().height()>10)
QTimer::singleShot(100,this,[this](){ graphLayout->fitInView(); });
}
void MainWindow::on_actionLoad_From_adjacency_Matrix_triggered()
{
Dialog dialog(this);
dialog.setTitle("Load Adjacency Matrix");
dialog.setPlaceHolderText("Type/Paste your adjacency Matrix with comma separator\ne.g :- for three node\n1,0,1\n1,0,0\n0,1,0");
dialog.setPlaceHolderTextForNodeList("Type/Paste your node name with newline separator\ne.g :- eg\nNode1\nNode2\nNode3");
dialog.exec();
graphLayout->loadAdjacencyMatrix( dialog.getText(),dialog.getNodeNameList());
}
void MainWindow::on_actionLoad_From_Incidence_Matrix_triggered()
{
graphLayout->setEditingMode(GraphLayout::NoEditing);
Dialog dialog(this);
dialog.setTitle("Load Incidence Matrix");
dialog.setPlaceHolderText("Type/Paste your Incidence Matrix with comma separator\ne.g :- for three node\n1,0,1\n-1,0,0\n0,1,1");
dialog.setPlaceHolderTextForNodeList("Type/Paste your node name with newline separator\ne.g :- eg\nNode1\nNode2\nNode3");
dialog.exec();
graphLayout->loadIncidencMatrix(dialog.getText(),dialog.getNodeNameList());
}
void MainWindow::on_actionWith_Bracket_triggered()
{
Dialog dialog;
dialog.setTitle("Adjacency Matrix");
dialog.setReadOnly();
dialog.setText(graphLayout->getAdjacenyMatrix_AsString(true));
dialog.setNodeNameText(graphLayout->getNodeName());
dialog.exec();
}
void MainWindow::on_actionWithout_Bracket_triggered()
{
Dialog dialog;
dialog.setTitle("Adjacency Matrix");
dialog.setReadOnly();
dialog.setText(graphLayout->getAdjacenyMatrix_AsString());
dialog.setNodeNameText(graphLayout->getNodeName());
dialog.exec();
}
void MainWindow::on_actionWith_Bracket_2_triggered()
{
Dialog dialog;
dialog.setTitle("Incidence Matrix");
dialog.setReadOnly();
dialog.setText(graphLayout->getIncidenceMatrix_AsString(true));
dialog.setNodeNameText(graphLayout->getNodeName());
dialog.exec();
}
void MainWindow::on_actionWithout_Bracket_2_triggered()
{
Dialog dialog;
dialog.setTitle("Incidence Matrix");
dialog.setReadOnly();
dialog.setText(graphLayout->getIncidenceMatrix_AsString());
dialog.setNodeNameText(graphLayout->getNodeName());
dialog.exec();
}
void MainWindow::on_actionAbout_triggered()
{
AboutDialog dialog;
dialog.exec();
}
void MainWindow::on_actionDemo_triggered()
{
graphLayout->loadAdjacencyMatrix(demoMat,QStringList());
}
void MainWindow::on_actionExport_Scene_triggered()
{
QString filePath = QFileDialog::getSaveFileName(this,"save",QString()," *.png");
graphLayout->exportLayoutAsImage(filePath);
}
void MainWindow::on_maxSpeedSpinBox_valueChanged(int arg1)
{
graphLayout->setMaxSpeed(arg1);
}
void MainWindow::on_actionInsert_Node_triggered()
{
activateEditingMode(GraphLayout::NodeInsertion);
}
void MainWindow::on_actionRemove_Node_triggered()
{
activateEditingMode(GraphLayout::NodeRemoval);
}
void MainWindow::on_actionConnect_Node_triggered()
{
activateEditingMode(GraphLayout::ConnectNode);
}
void MainWindow::on_actionDisconnect_Node_triggered()
{
activateEditingMode(GraphLayout::DisconnectNode);
}
void MainWindow::on_actionNo_Editing_triggered()
{
activateEditingMode(GraphLayout::NoEditing);
}
void MainWindow::on_actionupdate_current_matrix_triggered()
{
QString currentmatrix = graphLayout->getAdjacenyMatrix_AsString();
if(!currentmatrix.isEmpty())
{
Dialog dialog;
dialog.setTitle("Update current Matrix");
dialog.setText(currentmatrix);
dialog.setNodeNameText(graphLayout->getNodeName());
if(dialog.exec())
graphLayout->loadAdjacencyMatrix( dialog.getText(),dialog.getNodeNameList());
}
}
void MainWindow::activateEditingMode(GraphLayout::EditingMode mode)
{
ui->actionInsert_Node->setChecked(false);
ui->actionRemove_Node->setChecked(false);
ui->actionConnect_Node->setChecked(false);
ui->actionDisconnect_Node->setChecked(false);
ui->actionNo_Editing->setChecked(false);
graphLayout->setEditingMode(mode);
switch (mode){
case GraphLayout::NodeInsertion :ui->actionInsert_Node->setChecked(true); break;
case GraphLayout::NodeRemoval :ui->actionRemove_Node->setChecked(true);break;
case GraphLayout::ConnectNode :ui->actionConnect_Node->setChecked(true);break;
case GraphLayout::DisconnectNode :ui->actionDisconnect_Node->setChecked(true);break;
case GraphLayout::NoEditing:ui->actionNo_Editing->setChecked(true); break;
}
}