Path: blob/devel/ElmerGUI/Application/vtkpost/colorbar.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 colorbar *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*****************************************************************************/3940#include <QtGui>41#include <iostream>42#include "vtkpost.h"43#include "colorbar.h"4445#include <vtkActor.h>46#include <vtkMapper.h>47#include <vtkScalarBarActor.h>48#include <vtkTextMapper.h>49#include <vtkTextProperty.h>50#include <vtkActor.h>5152using namespace std;5354ColorBar::ColorBar(QWidget *parent)55: QDialog(parent)56{57ui.setupUi(this);5859connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));60connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));61connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));62connect(ui.colorCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(colorSelectionChanged(int)));6364setWindowTitle("Colorbar");65setWindowIcon(QIcon(":/icons/Mesh3D.png"));6667ui.cancelButton->setIcon(QIcon::fromTheme("dialog-error-round"));68ui.applyButton->setIcon(QIcon::fromTheme("view-refresh"));69ui.okButton->setIcon(QIcon::fromTheme("dialog-accept"));70}7172ColorBar::~ColorBar()73{74}7576void ColorBar::cancelButtonClicked()77{78emit(hideColorBarSignal());79close();80}8182void ColorBar::okButtonClicked()83{84applyButtonClicked();85close();86}8788void ColorBar::applyButtonClicked()89{90emit(drawColorBarSignal());91}9293void ColorBar::colorSelectionChanged(int newIndex)94{95}9697void ColorBar::populateWidgets(VtkPost* vtkPost)98{99ui.colorCombo->clear();100ui.colorCombo->addItem("Surface");101ui.colorCombo->addItem("Vector");102ui.colorCombo->addItem("Isocontour");103ui.colorCombo->addItem("Isosurface");104ui.colorCombo->addItem("Streamline");105}106107void ColorBar::draw(VtkPost* vtkPost)108{109vtkScalarBarActor* colorBarActor = vtkPost->GetColorBarActor();110/*111vtkTextMapper* tMapper = vtkTextMapper::New();112colorBarActor->SetMapper(tMapper);113tMapper->Delete();114*/115116QString actorName = ui.colorCombo->currentText().trimmed();117118if(actorName.isEmpty()) return;119120QString fieldName = "";121122vtkScalarsToColors* lut = NULL;123124if(actorName == "Surface") {125fieldName = vtkPost->GetCurrentSurfaceName();126if(fieldName.isEmpty()) return;127lut = vtkPost->GetSurfaceActor()->GetMapper()->GetLookupTable();128}129130if(actorName == "Vector") {131fieldName = vtkPost->GetCurrentVectorName();132if(fieldName.isEmpty()) return;133lut = vtkPost->GetVectorActor()->GetMapper()->GetLookupTable();134}135136if(actorName == "Isocontour") {137fieldName = vtkPost->GetCurrentIsoContourName();138if(fieldName.isEmpty()) return;139lut = vtkPost->GetIsoContourActor()->GetMapper()->GetLookupTable();140}141142if(actorName == "Isosurface") {143fieldName = vtkPost->GetCurrentIsoSurfaceName();144if(fieldName.isEmpty()) return;145lut = vtkPost->GetIsoSurfaceActor()->GetMapper()->GetLookupTable();146}147148if(actorName == "Streamline") {149fieldName = vtkPost->GetCurrentStreamLineName();150if(fieldName.isEmpty()) return;151lut = vtkPost->GetStreamLineActor()->GetMapper()->GetLookupTable();152}153154if(!lut) return;155156//colorBarActor->SetLookupTable(lut);157colorBarActor->SetLookupTable((vtkScalarsToColors*)vtkPost->GetLut(actorName));158159bool horizontal = ui.horizontalRButton->isChecked();160bool annotate = ui.annotateBox->isChecked();161int labels = ui.labelsSpin->value();162double width = ui.widthEdit->text().toDouble();163double height = ui.heightEdit->text().toDouble();164165if(width < 0.01) width = 0.01;166if(width > 1.00) width = 1.00;167if(height < 0.01) height = 0.01;168if(height > 1.00) height = 1.00;169170colorBarActor->SetPosition(0.05, 0.05);171172if(horizontal) {173colorBarActor->SetOrientationToHorizontal();174colorBarActor->SetWidth(height);175colorBarActor->SetHeight(width);176} else {177colorBarActor->SetOrientationToVertical();178colorBarActor->SetWidth(width);179colorBarActor->SetHeight(height);180}181182colorBarActor->SetNumberOfLabels(labels);183184colorBarActor->GetLabelTextProperty()->SetFontSize(16);185colorBarActor->GetLabelTextProperty()->SetFontFamilyToArial();186colorBarActor->GetLabelTextProperty()->BoldOn();187colorBarActor->GetLabelTextProperty()->ItalicOn();188colorBarActor->GetLabelTextProperty()->SetColor(0, 0, 1);189190colorBarActor->GetTitleTextProperty()->SetFontSize(16);191colorBarActor->GetTitleTextProperty()->SetFontFamilyToArial();192colorBarActor->GetTitleTextProperty()->BoldOn();193colorBarActor->GetTitleTextProperty()->ItalicOn();194colorBarActor->GetTitleTextProperty()->SetColor(0, 0, 1);195196if(annotate) {197#if WITH_QT5 || WITH_QT6198colorBarActor->SetTitle(fieldName.toLatin1().data());199#else200colorBarActor->SetTitle(fieldName.toAscii().data());201#endif202} else {203colorBarActor->SetTitle("");204}205}206207// Public slots:208//---------------209bool ColorBar::SetFieldName(QString name)210{211for(int i = 0; i < ui.colorCombo->count(); i++) {212if(ui.colorCombo->itemText(i) == name) {213ui.colorCombo->setCurrentIndex(i);214return true;215}216}217return false;218}219220void ColorBar::UseHorizontalLayout(bool b)221{222ui.horizontalRButton->setChecked(b);223}224225void ColorBar::UseVerticalLayout(bool b)226{227ui.verticalRButton->setChecked(b);228}229230void ColorBar::AnnotateFieldName(bool b)231{232ui.annotateBox->setChecked(b);233}234235void ColorBar::SetLabels(int n)236{237ui.labelsSpin->setValue(n);238}239240void ColorBar::SetLineWidth(double f)241{242ui.widthEdit->setText(QString::number(f));243}244245void ColorBar::SetLength(double f)246{247ui.heightEdit->setText(QString::number(f));248}249250251