Salome HOME
IPAL21035 It's impossible to hide scalar bar for gauss points
[modules/visu.git] / src / VISUGUI / VisuGUI_FilterScalarsDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "VisuGUI_FilterScalarsDlg.h"
23 #include "VISU_ColoredPrs3d_i.hh"
24 #include "VISU_ColoredPrs3dHolder_i.hh"
25
26 #include "VisuGUI.h"
27 #include "VisuGUI_Tools.h"
28
29 #include <SalomeApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31
32 #include <SUIT_Desktop.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36
37 #include <QPushButton>
38 #include <QVBoxLayout>
39 #include <QHBoxLayout>
40 #include <QGroupBox>
41 #include <QLabel>
42 #include <QLineEdit>
43 #include <QDoubleValidator>
44   
45
46 VisuGUI_FilterScalarsDlg::VisuGUI_FilterScalarsDlg( VisuGUI* theModule )
47   : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
48     myVisuGUI( theModule )
49 {
50   setModal( false );
51   setWindowTitle(tr("TITLE"));
52   setSizeGripEnabled(true);
53   setAttribute( Qt::WA_DeleteOnClose, true );
54   
55   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
56   
57   myRangeBox = new QGroupBox(this);
58   myRangeBox->setTitle(tr("BOXTITLE"));
59   myRangeBox->setCheckable(true);
60   aMainLayout->addWidget(myRangeBox);
61
62   QHBoxLayout* aBoxLayout = new QHBoxLayout(myRangeBox);
63   aBoxLayout->addWidget(new QLabel(tr("MINLBL"), myRangeBox));
64   myMinEdit = new QLineEdit( myRangeBox );
65   myMinEdit->setValidator( new QDoubleValidator(myMinEdit) );
66   aBoxLayout->addWidget(myMinEdit);
67
68   aBoxLayout->addWidget(new QLabel(tr("MAXLBL"), myRangeBox));
69   myMaxEdit = new QLineEdit( myRangeBox );
70   myMaxEdit->setValidator( new QDoubleValidator(myMaxEdit) );
71   aBoxLayout->addWidget(myMaxEdit);
72
73   QGroupBox* aGroupButtons = new QGroupBox(this);
74   QHBoxLayout* aButtonsLayout = new QHBoxLayout(aGroupButtons);
75
76   QPushButton* aBtnOk = new QPushButton(tr("BUT_OK"), aGroupButtons);
77   aBtnOk->setAutoDefault(true);
78   aBtnOk->setDefault(true);
79   aButtonsLayout->addWidget(aBtnOk);
80
81   QPushButton* aBtnCancel = new QPushButton(tr("BUT_CANCEL"), aGroupButtons);
82   aBtnCancel->setAutoDefault(true);
83   aButtonsLayout->addWidget(aBtnCancel);
84
85   aButtonsLayout->addStretch();
86
87   QPushButton* aBtnHelp = new QPushButton(tr("BUT_HELP"), aGroupButtons);
88   aBtnHelp->setAutoDefault(true);
89   aButtonsLayout->addWidget(aBtnHelp);
90
91   aMainLayout->addWidget(aGroupButtons);
92
93   connect(aBtnOk,     SIGNAL(clicked()), this, SLOT(accept()));
94   connect(aBtnCancel, SIGNAL(clicked()), this, SLOT(reject()));
95   connect(aBtnHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
96
97   SalomeApp_Application* anApp = theModule->getApp();
98   LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
99   connect( aSelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionEvent() ) );
100
101   onSelectionEvent();
102 }
103
104
105 VisuGUI_FilterScalarsDlg::~VisuGUI_FilterScalarsDlg()
106 {}
107
108 void VisuGUI_FilterScalarsDlg::onSelectionEvent()
109 {
110   typedef SALOME::GenericObjPtr< VISU::ColoredPrs3d_i  > TColoredPrs3dPtr;
111   VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects( myVisuGUI );
112   myColoredPrs3d = TColoredPrs3dPtr();
113   if ( !aSelectionInfo.empty() ) {
114     VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
115     if ( VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase ) {
116       if ( VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast< VISU::ColoredPrs3d_i* >( aBase ) ) {
117         myColoredPrs3d = aColoredPrs3d;
118       } else if (VISU::ColoredPrs3dHolder_i* aHolder = 
119                  dynamic_cast< VISU::ColoredPrs3dHolder_i* >( aBase )) {
120         myColoredPrs3d = aHolder->GetPrs3dDevice();
121       }
122       if (myColoredPrs3d.get() != NULL) {
123         myRangeBox->setChecked( myColoredPrs3d->IsScalarFilterUsed() );
124         myMinEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMin() ) );
125         myMaxEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMax() ) );
126         setEnabled( true );
127         return;
128       }
129     }
130   }
131   setEnabled( false );
132   return;
133 }
134
135 void VisuGUI_FilterScalarsDlg::accept()
136 {
137   myColoredPrs3d->SetScalarFilterRange( myMinEdit->text().toDouble(), myMaxEdit->text().toDouble() );
138   myColoredPrs3d->UseScalarFiltering( myRangeBox->isChecked() );
139   myColoredPrs3d->UpdateActors();
140   QDialog::accept();
141 }
142
143 void VisuGUI_FilterScalarsDlg::reject()
144 {
145   QDialog::reject();
146 }
147   
148 void VisuGUI_FilterScalarsDlg::onHelp()
149 {
150   QString aHelpFileName = "viewing_3d_presentations_page.html#filter_by_scalars_anchor";
151   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
152   if (app)
153     app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
154   else {
155     QString platform;
156 #ifdef WIN32
157     platform = "winapplication";
158 #else
159     platform = "application";
160 #endif
161     SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
162                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
163                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
164                              tr("BUT_OK"));
165   }
166 }