1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "VisuGUI_FilterScalarsDlg.h"
21 #include "VISU_ColoredPrs3d_i.hh"
22 #include "VISU_ColoredPrs3dHolder_i.hh"
25 #include "VisuGUI_Tools.h"
26 #include "VisuGUI_ViewTools.h"
28 #include <SalomeApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
36 #include <QPushButton>
37 #include <QVBoxLayout>
38 #include <QHBoxLayout>
42 #include <QDoubleValidator>
45 VisuGUI_FilterScalarsDlg::VisuGUI_FilterScalarsDlg( VisuGUI* theModule )
46 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
47 myVisuGUI( theModule )
50 setWindowTitle(tr("TITLE"));
51 setSizeGripEnabled(true);
52 setAttribute( Qt::WA_DeleteOnClose, true );
54 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
56 myRangeBox = new QGroupBox(this);
57 myRangeBox->setTitle(tr("BOXTITLE"));
58 myRangeBox->setCheckable(true);
59 aMainLayout->addWidget(myRangeBox);
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);
67 aBoxLayout->addWidget(new QLabel(tr("MAXLBL"), myRangeBox));
68 myMaxEdit = new QLineEdit( myRangeBox );
69 myMaxEdit->setValidator( new QDoubleValidator(myMaxEdit) );
70 aBoxLayout->addWidget(myMaxEdit);
72 QGroupBox* aGroupButtons = new QGroupBox(this);
73 QHBoxLayout* aButtonsLayout = new QHBoxLayout(aGroupButtons);
75 QPushButton* aBtnOk = new QPushButton(tr("BUT_OK"), aGroupButtons);
76 aBtnOk->setAutoDefault(true);
77 aBtnOk->setDefault(true);
78 aButtonsLayout->addWidget(aBtnOk);
80 QPushButton* aBtnCancel = new QPushButton(tr("BUT_CANCEL"), aGroupButtons);
81 aBtnCancel->setAutoDefault(true);
82 aButtonsLayout->addWidget(aBtnCancel);
84 aButtonsLayout->addStretch();
86 QPushButton* aBtnHelp = new QPushButton(tr("BUT_HELP"), aGroupButtons);
87 aBtnHelp->setAutoDefault(true);
88 aButtonsLayout->addWidget(aBtnHelp);
90 aMainLayout->addWidget(aGroupButtons);
92 connect(aBtnOk, SIGNAL(clicked()), this, SLOT(accept()));
93 connect(aBtnCancel, SIGNAL(clicked()), this, SLOT(reject()));
94 connect(aBtnHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
96 SalomeApp_Application* anApp = theModule->getApp();
97 LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
98 connect( aSelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionEvent() ) );
104 VisuGUI_FilterScalarsDlg::~VisuGUI_FilterScalarsDlg()
107 void VisuGUI_FilterScalarsDlg::onSelectionEvent()
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();
121 if (myColoredPrs3d.get() != NULL) {
122 myRangeBox->setChecked( myColoredPrs3d->IsScalarFilterUsed() );
123 myMinEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMin() ) );
124 myMaxEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMax() ) );
134 void VisuGUI_FilterScalarsDlg::accept()
136 myColoredPrs3d->SetScalarFilterRange( myMinEdit->text().toDouble(), myMaxEdit->text().toDouble() );
137 myColoredPrs3d->UseScalarFiltering( myRangeBox->isChecked() );
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 );
146 myColoredPrs3d->UpdateActors();
151 void VisuGUI_FilterScalarsDlg::reject()
156 void VisuGUI_FilterScalarsDlg::onHelp()
158 QString aHelpFileName = "viewing_3d_presentations_page.html#filter_by_scalars_anchor";
159 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
161 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
165 platform = "winapplication";
167 platform = "application";
169 SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
170 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
171 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),