Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/twod/twodview.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI TwodView *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter RÃ¥back *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
#include <QAction>
41
#include <QIcon>
42
#include <QMenu>
43
#include <QMenuBar>
44
#include <QStatusBar>
45
#include <QFileDialog>
46
#include <QMessageBox>
47
#include <QDockWidget>
48
#include <iostream>
49
50
#include "twodview.h"
51
#include "renderarea.h"
52
#include "curveeditor.h"
53
54
using namespace std;
55
56
TwodView::TwodView(QWidget *parent)
57
: QMainWindow(parent)
58
{
59
renderArea = new RenderArea(this);
60
setCentralWidget(renderArea);
61
62
connect(renderArea, SIGNAL(statusMessage(QString)), this, SLOT(statusMessage(QString)));
63
64
curveEditor = new CurveEditor;
65
66
connect(curveEditor, SIGNAL(statusMessage(QString)), this, SLOT(statusMessage(QString)));
67
68
QDockWidget *dockWidget = new QDockWidget("Editor", this);
69
dockWidget->setAllowedAreas(Qt::RightDockWidgetArea);
70
dockWidget->setWidget(curveEditor);
71
addDockWidget(Qt::RightDockWidgetArea, dockWidget);
72
73
renderArea->setCurveEditor(curveEditor);
74
curveEditor->setRenderArea(renderArea);
75
76
createActions();
77
createMenus();
78
createStatusBar();
79
80
setWindowTitle("ElmerGUI 2D modeler (experimental)");
81
setWindowIcon(QIcon(":/icons/Mesh3D.png"));
82
resize(620, 400);
83
}
84
85
TwodView::~TwodView()
86
{
87
}
88
89
void TwodView::createActions()
90
{
91
openAction = new QAction(QIcon(""), tr("&Open..."), this);
92
openAction->setShortcut(tr("Ctrl+O"));
93
connect(openAction, SIGNAL(triggered()), this, SLOT(openSlot()));
94
95
saveAction = new QAction(QIcon(""), tr("&Save as..."), this);
96
saveAction->setShortcut(tr("Ctrl+S"));
97
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveSlot()));
98
99
quitAction = new QAction(QIcon(""), tr("&Quit"), this);
100
quitAction->setShortcut(tr("Ctrl+Q"));
101
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
102
103
addPointAction = new QAction(QIcon(""), tr("&Insert point"), this);
104
addPointAction->setShortcut(tr("Ctrl+P"));
105
connect(addPointAction, SIGNAL(triggered()), this, SLOT(addPointSlot()));
106
107
addCurveAction = new QAction(QIcon(""), tr("&Insert curve"), this);
108
addCurveAction->setShortcut(tr("Ctrl+C"));
109
connect(addCurveAction, SIGNAL(triggered()), this, SLOT(addCurveSlot()));
110
111
deletePointAction = new QAction(QIcon(""), tr("&Delete point"), this);
112
deletePointAction->setShortcut(tr("Ctrl+Z"));
113
connect(deletePointAction, SIGNAL(triggered()), this, SLOT(deletePointSlot()));
114
115
deleteCurveAction = new QAction(QIcon(""), tr("&Delete curve"), this);
116
deleteCurveAction->setShortcut(tr("Ctrl+X"));
117
connect(deleteCurveAction, SIGNAL(triggered()), this, SLOT(deleteCurveSlot()));
118
119
fitAction = new QAction(QIcon(""), tr("&Fit to window"), this);
120
fitAction->setShortcut(tr("Ctrl+F"));
121
connect(fitAction, SIGNAL(triggered()), renderArea, SLOT(fitSlot()));
122
123
drawPointsAction = new QAction(QIcon(""), tr("Draw points"), this);
124
drawPointsAction->setCheckable(true);
125
connect(drawPointsAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawPointsSlot(bool)));
126
drawPointsAction->setChecked(true);
127
128
drawSplinesAction = new QAction(QIcon(""), tr("Draw splines"), this);
129
drawSplinesAction->setCheckable(true);
130
connect(drawSplinesAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawSplinesSlot(bool)));
131
drawSplinesAction->setChecked(true);
132
133
drawTangentsAction = new QAction(QIcon(""), tr("Draw tangents"), this);
134
drawTangentsAction->setCheckable(true);
135
connect(drawTangentsAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawTangentsSlot(bool)));
136
drawTangentsAction->setChecked(true);
137
138
drawPointNumbersAction = new QAction(QIcon(""), tr("Point numbers"), this);
139
drawPointNumbersAction->setCheckable(true);
140
connect(drawPointNumbersAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawPointNumbersSlot(bool)));
141
drawPointNumbersAction->setChecked(true);
142
143
drawSplineNumbersAction = new QAction(QIcon(""), tr("Spline numbers"), this);
144
drawSplineNumbersAction->setCheckable(true);
145
connect(drawSplineNumbersAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawSplineNumbersSlot(bool)));
146
drawSplineNumbersAction->setChecked(true);
147
148
drawMaterialNumbersAction = new QAction(QIcon(""), tr("Material numbers"), this);
149
drawMaterialNumbersAction->setCheckable(true);
150
connect(drawMaterialNumbersAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawMaterialNumbersSlot(bool)));
151
drawMaterialNumbersAction->setChecked(true);
152
153
helpAction = new QAction(QIcon(""), tr("&Help"), this);
154
helpAction->setShortcut(tr("Ctrl+H"));
155
connect(helpAction, SIGNAL(triggered()), this, SLOT(helpSlot()));
156
}
157
158
void TwodView::createMenus()
159
{
160
fileMenu = menuBar()->addMenu(tr("&File"));
161
fileMenu->addAction(openAction);
162
fileMenu->addAction(saveAction);
163
fileMenu->addSeparator();
164
fileMenu->addAction(quitAction);
165
166
editMenu = menuBar()->addMenu(tr("&Edit"));
167
editMenu->addAction(addPointAction);
168
editMenu->addAction(addCurveAction);
169
editMenu->addSeparator();
170
editMenu->addAction(deletePointAction);
171
editMenu->addAction(deleteCurveAction);
172
173
viewMenu = menuBar()->addMenu(tr("&View"));
174
viewMenu->addAction(drawPointsAction);
175
viewMenu->addAction(drawSplinesAction);
176
viewMenu->addAction(drawTangentsAction);
177
viewMenu->addSeparator();
178
viewMenu->addAction(drawPointNumbersAction);
179
viewMenu->addAction(drawSplineNumbersAction);
180
viewMenu->addAction(drawMaterialNumbersAction);
181
viewMenu->addSeparator();
182
viewMenu->addAction(fitAction);
183
184
helpMenu = menuBar()->addMenu(tr("&Help"));
185
helpMenu->addAction(helpAction);
186
}
187
188
void TwodView::createStatusBar()
189
{
190
statusBar()->showMessage(tr("Ready"));
191
}
192
193
void TwodView::statusMessage(QString message)
194
{
195
statusBar()->showMessage(message);
196
}
197
198
void TwodView::saveSlot()
199
{
200
QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"), "", tr("Geometry Input Files (*.in2d)"));
201
202
if(fileName.isEmpty())
203
return;
204
205
renderArea->saveSlot(fileName);
206
}
207
208
void TwodView::openSlot()
209
{
210
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), "", tr("Geometry Input Files (*.in2d)"));
211
212
if(fileName.isEmpty())
213
return;
214
215
renderArea->readSlot(fileName);
216
renderArea->fitSlot();
217
}
218
219
void TwodView::addPointSlot()
220
{
221
curveEditor->addPoint();
222
}
223
224
void TwodView::addCurveSlot()
225
{
226
curveEditor->addCurve();
227
}
228
229
void TwodView::deletePointSlot()
230
{
231
curveEditor->deletePoint();
232
}
233
234
void TwodView::deleteCurveSlot()
235
{
236
curveEditor->deleteCurve();
237
}
238
239
void TwodView::helpSlot()
240
{
241
QMessageBox::information(this, tr("Information"),
242
tr("Mouse controls:\n"
243
" Left-click to move points\n"
244
" Right-click to pan\n"
245
" Rotate wheel to zoom\n\n"
246
"Supported formats:\n"
247
" splinecurves2dv2"));
248
}
249
250