Salome HOME
Update copyright information
[modules/visu.git] / src / VISUGUI / VisuGUI_FilterScalarsDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "VisuGUI_FilterScalarsDlg.h"
21 #include "VISU_ColoredPrs3d_i.hh"
22 #include "VISU_ColoredPrs3dHolder_i.hh"
23
24 #include "VisuGUI.h"
25 #include "VisuGUI_Tools.h"
26 #include "VisuGUI_ViewTools.h"
27
28 #include <SalomeApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
30
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35
36 #include <QPushButton>
37 #include <QVBoxLayout>
38 #include <QHBoxLayout>
39 #include <QGroupBox>
40 #include <QLabel>
41 #include <QLineEdit>
42 #include <QDoubleValidator>
43   
44
45 VisuGUI_FilterScalarsDlg::VisuGUI_FilterScalarsDlg( VisuGUI* theModule )
46   : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
47     myVisuGUI( theModule )
48 {
49   setModal( false );
50   setWindowTitle(tr("TITLE"));
51   setSizeGripEnabled(true);
52   setAttribute( Qt::WA_DeleteOnClose, true );
53   
54   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
55   
56   myRangeBox = new QGroupBox(this);
57   myRangeBox->setTitle(tr("BOXTITLE"));
58   myRangeBox->setCheckable(true);
59   aMainLayout->addWidget(myRangeBox);
60
61   QHBoxLayout* aBoxLayout = new QHBoxLayout(myRangeBox);
62   aBoxLayout->addWidget(new QLabel(tr("MINLBL"), myRangeBox));
63   myMinEdit = new QLineEdit( myRangeBox );
64   myMinEdit->setValidator( new QDoubleValidator(myMinEdit) );
65   aBoxLayout->addWidget(myMinEdit);
66
67   aBoxLayout->addWidget(new QLabel(tr("MAXLBL"), myRangeBox));
68   myMaxEdit = new QLineEdit( myRangeBox );
69   myMaxEdit->setValidator( new QDoubleValidator(myMaxEdit) );
70   aBoxLayout->addWidget(myMaxEdit);
71
72   QGroupBox* aGroupButtons = new QGroupBox(this);
73   QHBoxLayout* aButtonsLayout = new QHBoxLayout(aGroupButtons);
74
75   QPushButton* aBtnOk = new QPushButton(tr("BUT_OK"), aGroupButtons);
76   aBtnOk->setAutoDefault(true);
77   aBtnOk->setDefault(true);
78   aButtonsLayout->addWidget(aBtnOk);
79
80   QPushButton* aBtnCancel = new QPushButton(tr("BUT_CANCEL"), aGroupButtons);
81   aBtnCancel->setAutoDefault(true);
82   aButtonsLayout->addWidget(aBtnCancel);
83
84   aButtonsLayout->addStretch();
85
86   QPushButton* aBtnHelp = new QPushButton(tr("BUT_HELP"), aGroupButtons);
87   aBtnHelp->setAutoDefault(true);
88   aButtonsLayout->addWidget(aBtnHelp);
89
90   aMainLayout->addWidget(aGroupButtons);
91
92   connect(aBtnOk,     SIGNAL(clicked()), this, SLOT(accept()));
93   connect(aBtnCancel, SIGNAL(clicked()), this, SLOT(reject()));
94   connect(aBtnHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
95
96   SalomeApp_Application* anApp = theModule->getApp();
97   LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
98   connect( aSelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionEvent() ) );
99
100   onSelectionEvent();
101 }
102
103
104 VisuGUI_FilterScalarsDlg::~VisuGUI_FilterScalarsDlg()
105 {}
106
107 void VisuGUI_FilterScalarsDlg::onSelectionEvent()
108 {
109   typedef SALOME::GenericObjPtr< VISU::ColoredPrs3d_i  > TColoredPrs3dPtr;
110   VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects( myVisuGUI );
111   myColoredPrs3d = TColoredPrs3dPtr();
112   if ( !aSelectionInfo.empty() ) {
113     VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
114     if ( VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase ) {
115       if ( VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast< VISU::ColoredPrs3d_i* >( aBase ) ) {
116         myColoredPrs3d = aColoredPrs3d;
117       } else if (VISU::ColoredPrs3dHolder_i* aHolder = 
118                  dynamic_cast< VISU::ColoredPrs3dHolder_i* >( aBase )) {
119         myColoredPrs3d = aHolder->GetPrs3dDevice();
120       }
121       if (myColoredPrs3d.get() != NULL) {
122         myRangeBox->setChecked( myColoredPrs3d->IsScalarFilterUsed() );
123         myMinEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMin() ) );
124         myMaxEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMax() ) );
125         setEnabled( true );
126         return;
127       }
128     }
129   }
130   setEnabled( false );
131   return;
132 }
133
134 void VisuGUI_FilterScalarsDlg::accept()
135 {
136   myColoredPrs3d->SetScalarFilterRange( myMinEdit->text().toDouble(), myMaxEdit->text().toDouble() );
137   myColoredPrs3d->UseScalarFiltering( myRangeBox->isChecked() );
138
139   bool isToUpdate = true;
140   if( myColoredPrs3d->IsForcedHidden() )
141     if( SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>( myVisuGUI ) )
142       if( isToUpdate = VISU::PublishInView( myVisuGUI, myColoredPrs3d, aViewWindow, true ) )
143         myColoredPrs3d->SetForcedHidden( false );
144
145   if( isToUpdate )
146     myColoredPrs3d->UpdateActors();
147
148   QDialog::accept();
149 }
150
151 void VisuGUI_FilterScalarsDlg::reject()
152 {
153   QDialog::reject();
154 }
155   
156 void VisuGUI_FilterScalarsDlg::onHelp()
157 {
158   QString aHelpFileName = "viewing_3d_presentations_page.html#filter_by_scalars_anchor";
159   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
160   if (app)
161     app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
162   else {
163     QString platform;
164 #ifdef WIN32
165     platform = "winapplication";
166 #else
167     platform = "application";
168 #endif
169     SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
170                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
171                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
172                              tr("BUT_OK"));
173   }
174 }