Salome HOME
SMH: 3.0.0 preparation - merged and adopted version (POLYWORK+HEAD)
[modules/visu.git] / src / VISUGUI / VisuGUI_MagnitudeDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library 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 GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VisuGUI_MagnitudeDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_MagnitudeDlg.h"
30 #include "VisuGUI_Selection.h"
31 #include "VISU_DeformedShape_i.hh"
32 #include "VisuGUI.h"
33 #include "QtxDblSpinBox.h"
34
35 #include "SalomeApp_Application.h"
36
37 #include "SUIT_Desktop.h"
38
39 #include <qlayout.h>
40 #include <qtabwidget.h>
41
42 using namespace std;
43
44 /*!
45   Constructor
46 */
47 VisuGUI_MagnitudeDlg::VisuGUI_MagnitudeDlg()
48     : QDialog( VisuGUI::application()->desktop(), "VisuGUI_MagnitudeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
49 {
50   setCaption( tr( "Deformed Shape" ) );
51   setSizeGripEnabled( TRUE );
52
53   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
54   TopLayout->setSpacing( 6 );
55   TopLayout->setMargin( 11 );
56   
57   QTabWidget* aTabBox = new QTabWidget(this);
58   
59   QVBox* aBox = new QVBox(this);
60   aBox->setMargin( 11 );
61   QFrame* TopGroup = new QFrame( aBox, "TopGroup" );
62   TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
63   TopGroup->setLineWidth(1);
64   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup );
65   TopGroupLayout->setAlignment( Qt::AlignTop | Qt::AlignCenter );
66   TopGroupLayout->setSpacing( 6 );
67   TopGroupLayout->setMargin( 11 );
68
69   QLabel* ScaleLabel = new QLabel( tr( "Scale Factor:" ), TopGroup, "ScaleLabel" );
70   TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
71
72   ScalFact = new QtxDblSpinBox( 0, 1.0E+38, 0.1, TopGroup );
73   ScalFact->setPrecision( 5 );
74   ScalFact->setValue( 0.1 );
75   TopGroupLayout->addWidget( ScalFact, 0, 1 );
76
77   UseMagn = new QCheckBox( tr( "Magnitude coloring" ), TopGroup, "UseMagn" );
78   UseMagn->setChecked( true );
79   TopGroupLayout->addMultiCellWidget( UseMagn, 1, 1, 0, 1 );
80   //if (!enableUM)
81   //  UseMagn->hide();
82   aTabBox->addTab(aBox, "Deformed Shape");
83   
84   myScalarPane = new VisuGUI_ScalarBarPane(this, false);
85   myScalarPane->setMargin( 5 );
86   aTabBox->addTab(myScalarPane, "Scalar Bar");
87
88
89   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
90   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
91   GroupButtons->setColumnLayout(0, Qt::Vertical );
92   GroupButtons->layout()->setSpacing( 0 );
93   GroupButtons->layout()->setMargin( 0 );
94   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
95   GroupButtonsLayout->setAlignment( Qt::AlignTop );
96   GroupButtonsLayout->setSpacing( 6 );
97   GroupButtonsLayout->setMargin( 11 );
98
99   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
100   buttonOk->setAutoDefault( TRUE );
101   buttonOk->setDefault( TRUE );
102   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
103   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
104   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
105   buttonCancel->setAutoDefault( TRUE );
106   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
107   
108   TopLayout->addWidget( aTabBox );
109   TopLayout->addWidget( GroupButtons );
110
111   // signals and slots connections
112   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
113   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
114 }
115
116
117 void VisuGUI_MagnitudeDlg::initFromPrsObject(VISU::DeformedShape_i* thePrs) {
118   myScalarPane->initFromPrsObject(thePrs);
119   setFactor(thePrs->GetScale());
120   UseMagn->setChecked(thePrs->IsColored());
121 }
122
123
124 int VisuGUI_MagnitudeDlg::storeToPrsObject(VISU::DeformedShape_i* thePrs) {
125   myScalarPane->storeToPrsObject(thePrs);
126   thePrs->SetScale(getFactor());
127   thePrs->ShowColored(isColored());
128   return 1;
129 }
130
131
132 void VisuGUI_MagnitudeDlg::accept() {
133   if (myScalarPane->check())  QDialog::accept();
134 }
135