Path: blob/devel/ElmerGUI/Application/twod/twodview.cpp
3203 views
/*****************************************************************************1* *2* Elmer, A Finite Element Software for Multiphysical Problems *3* *4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *5* *6* This program is free software; you can redistribute it and/or *7* modify it under the terms of the GNU General Public License *8* as published by the Free Software Foundation; either version 2 *9* of the License, or (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program (in file fem/GPL-2); if not, write to the *18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *19* Boston, MA 02110-1301, USA. *20* *21*****************************************************************************/2223/*****************************************************************************24* *25* ElmerGUI TwodView *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter RÃ¥back *30* Email: [email protected] *31* Web: http://www.csc.fi/elmer *32* Address: CSC - IT Center for Science Ltd. *33* Keilaranta 14 *34* 02101 Espoo, Finland *35* *36* Original Date: 15 Mar 2008 *37* *38*****************************************************************************/39#include <QAction>40#include <QIcon>41#include <QMenu>42#include <QMenuBar>43#include <QStatusBar>44#include <QFileDialog>45#include <QMessageBox>46#include <QDockWidget>47#include <iostream>4849#include "twodview.h"50#include "renderarea.h"51#include "curveeditor.h"5253using namespace std;5455TwodView::TwodView(QWidget *parent)56: QMainWindow(parent)57{58renderArea = new RenderArea(this);59setCentralWidget(renderArea);6061connect(renderArea, SIGNAL(statusMessage(QString)), this, SLOT(statusMessage(QString)));6263curveEditor = new CurveEditor;6465connect(curveEditor, SIGNAL(statusMessage(QString)), this, SLOT(statusMessage(QString)));6667QDockWidget *dockWidget = new QDockWidget("Editor", this);68dockWidget->setAllowedAreas(Qt::RightDockWidgetArea);69dockWidget->setWidget(curveEditor);70addDockWidget(Qt::RightDockWidgetArea, dockWidget);7172renderArea->setCurveEditor(curveEditor);73curveEditor->setRenderArea(renderArea);7475createActions();76createMenus();77createStatusBar();7879setWindowTitle("ElmerGUI 2D modeler (experimental)");80setWindowIcon(QIcon(":/icons/Mesh3D.png"));81resize(620, 400);82}8384TwodView::~TwodView()85{86}8788void TwodView::createActions()89{90openAction = new QAction(QIcon(""), tr("&Open..."), this);91openAction->setShortcut(tr("Ctrl+O"));92connect(openAction, SIGNAL(triggered()), this, SLOT(openSlot()));9394saveAction = new QAction(QIcon(""), tr("&Save as..."), this);95saveAction->setShortcut(tr("Ctrl+S"));96connect(saveAction, SIGNAL(triggered()), this, SLOT(saveSlot()));9798quitAction = new QAction(QIcon(""), tr("&Quit"), this);99quitAction->setShortcut(tr("Ctrl+Q"));100connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));101102addPointAction = new QAction(QIcon(""), tr("&Insert point"), this);103addPointAction->setShortcut(tr("Ctrl+P"));104connect(addPointAction, SIGNAL(triggered()), this, SLOT(addPointSlot()));105106addCurveAction = new QAction(QIcon(""), tr("&Insert curve"), this);107addCurveAction->setShortcut(tr("Ctrl+C"));108connect(addCurveAction, SIGNAL(triggered()), this, SLOT(addCurveSlot()));109110deletePointAction = new QAction(QIcon(""), tr("&Delete point"), this);111deletePointAction->setShortcut(tr("Ctrl+Z"));112connect(deletePointAction, SIGNAL(triggered()), this, SLOT(deletePointSlot()));113114deleteCurveAction = new QAction(QIcon(""), tr("&Delete curve"), this);115deleteCurveAction->setShortcut(tr("Ctrl+X"));116connect(deleteCurveAction, SIGNAL(triggered()), this, SLOT(deleteCurveSlot()));117118fitAction = new QAction(QIcon(""), tr("&Fit to window"), this);119fitAction->setShortcut(tr("Ctrl+F"));120connect(fitAction, SIGNAL(triggered()), renderArea, SLOT(fitSlot()));121122drawPointsAction = new QAction(QIcon(""), tr("Draw points"), this);123drawPointsAction->setCheckable(true);124connect(drawPointsAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawPointsSlot(bool)));125drawPointsAction->setChecked(true);126127drawSplinesAction = new QAction(QIcon(""), tr("Draw splines"), this);128drawSplinesAction->setCheckable(true);129connect(drawSplinesAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawSplinesSlot(bool)));130drawSplinesAction->setChecked(true);131132drawTangentsAction = new QAction(QIcon(""), tr("Draw tangents"), this);133drawTangentsAction->setCheckable(true);134connect(drawTangentsAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawTangentsSlot(bool)));135drawTangentsAction->setChecked(true);136137drawPointNumbersAction = new QAction(QIcon(""), tr("Point numbers"), this);138drawPointNumbersAction->setCheckable(true);139connect(drawPointNumbersAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawPointNumbersSlot(bool)));140drawPointNumbersAction->setChecked(true);141142drawSplineNumbersAction = new QAction(QIcon(""), tr("Spline numbers"), this);143drawSplineNumbersAction->setCheckable(true);144connect(drawSplineNumbersAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawSplineNumbersSlot(bool)));145drawSplineNumbersAction->setChecked(true);146147drawMaterialNumbersAction = new QAction(QIcon(""), tr("Material numbers"), this);148drawMaterialNumbersAction->setCheckable(true);149connect(drawMaterialNumbersAction, SIGNAL(toggled(bool)), renderArea, SLOT(drawMaterialNumbersSlot(bool)));150drawMaterialNumbersAction->setChecked(true);151152helpAction = new QAction(QIcon(""), tr("&Help"), this);153helpAction->setShortcut(tr("Ctrl+H"));154connect(helpAction, SIGNAL(triggered()), this, SLOT(helpSlot()));155}156157void TwodView::createMenus()158{159fileMenu = menuBar()->addMenu(tr("&File"));160fileMenu->addAction(openAction);161fileMenu->addAction(saveAction);162fileMenu->addSeparator();163fileMenu->addAction(quitAction);164165editMenu = menuBar()->addMenu(tr("&Edit"));166editMenu->addAction(addPointAction);167editMenu->addAction(addCurveAction);168editMenu->addSeparator();169editMenu->addAction(deletePointAction);170editMenu->addAction(deleteCurveAction);171172viewMenu = menuBar()->addMenu(tr("&View"));173viewMenu->addAction(drawPointsAction);174viewMenu->addAction(drawSplinesAction);175viewMenu->addAction(drawTangentsAction);176viewMenu->addSeparator();177viewMenu->addAction(drawPointNumbersAction);178viewMenu->addAction(drawSplineNumbersAction);179viewMenu->addAction(drawMaterialNumbersAction);180viewMenu->addSeparator();181viewMenu->addAction(fitAction);182183helpMenu = menuBar()->addMenu(tr("&Help"));184helpMenu->addAction(helpAction);185}186187void TwodView::createStatusBar()188{189statusBar()->showMessage(tr("Ready"));190}191192void TwodView::statusMessage(QString message)193{194statusBar()->showMessage(message);195}196197void TwodView::saveSlot()198{199QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"), "", tr("Geometry Input Files (*.in2d)"));200201if(fileName.isEmpty())202return;203204renderArea->saveSlot(fileName);205}206207void TwodView::openSlot()208{209QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), "", tr("Geometry Input Files (*.in2d)"));210211if(fileName.isEmpty())212return;213214renderArea->readSlot(fileName);215renderArea->fitSlot();216}217218void TwodView::addPointSlot()219{220curveEditor->addPoint();221}222223void TwodView::addCurveSlot()224{225curveEditor->addCurve();226}227228void TwodView::deletePointSlot()229{230curveEditor->deletePoint();231}232233void TwodView::deleteCurveSlot()234{235curveEditor->deleteCurve();236}237238void TwodView::helpSlot()239{240QMessageBox::information(this, tr("Information"),241tr("Mouse controls:\n"242" Left-click to move points\n"243" Right-click to pan\n"244" Rotate wheel to zoom\n\n"245"Supported formats:\n"246" splinecurves2dv2"));247}248249250