1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ZIProgressIndicator.h"
20 #include "HYDROGUI_Tool.h"
22 #include "HYDROData_Tool.h"
25 #include <QProgressBar>
26 #include <QVBoxLayout>
27 #include <QApplication>
29 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_ZIProgressIndicator, Message_ProgressIndicator)
31 HYDROGUI_ZIProgressIndicator::HYDROGUI_ZIProgressIndicator( QWidget* theParent )
32 : QtxDialog( theParent, true, false, QtxDialog::Cancel ), myUserBreak(Standard_False),
35 setWindowTitle( tr( "BATHYMETRY_INTERPOLATION_TLT" ) );
37 QVBoxLayout* aLayout = new QVBoxLayout( mainFrame() );
38 aLayout->setMargin( 5 );
39 aLayout->setSpacing( 5 );
41 myQuadTreeBar = new QProgressBar( mainFrame() );
42 myTriangulationState = new QLabel( tr( "PENDING" ), mainFrame() );
43 mySummaryBar = new QProgressBar( mainFrame() );
45 QString aBold("<b>%1</b>");
47 aLayout->addWidget( new QLabel( aBold.arg( tr( "QUADTREE_STAGE" ) ) ) );
48 aLayout->addWidget( myQuadTreeBar );
49 aLayout->addSpacing( 10 );
50 aLayout->addWidget( new QLabel( aBold.arg( tr( "TRIANGULATION_STAGE" ) ) ) );
51 aLayout->addWidget( myTriangulationState );
52 aLayout->addSpacing( 10 );
53 aLayout->addWidget( new QLabel( aBold.arg( tr( "EXPLORATION_STAGE" ) ) ) );
54 aLayout->addWidget( mySummaryBar );
56 setButtonText( Cancel, tr( "CANCEL" ) );
57 setButtonPosition( Center, Cancel );
58 setMinimumWidth( 350 );
61 HYDROGUI_ZIProgressIndicator::~HYDROGUI_ZIProgressIndicator()
65 Standard_Boolean HYDROGUI_ZIProgressIndicator::Show(const Standard_Boolean theForce)
67 Standard_Boolean isUserBreak = UserBreak();
68 Standard_Real aPosition = GetPosition();
72 for ( Standard_Integer i = 1; i <= GetNbScopes(); i++ ) {
73 Message_ProgressScale aScope = GetScope(i);
74 QString aName = HYDROGUI_Tool::ToQString( aScope.GetName() );
75 if ( aName != "QuadTree" ) {
79 Standard_Real aMin = aScope.GetMin();
80 Standard_Real aMax = aScope.GetMax();
81 Standard_Real aScopeValue = aScope.BaseToLocal( aPosition );
82 myQuadTreePosition = aScopeValue / (aMax - aMin);
87 myQuadTreeBar->setValue( int( myQuadTreePosition * 100 ) );
88 mySummaryBar->setValue( int( aPosition * 100 ) );
89 HYDROData_Tool::ExecStatus aStatus = HYDROData_Tool::GetTriangulationStatus();
90 if ( aStatus == HYDROData_Tool::Running ) {
91 myTriangulationState->setText( tr("IN_PROGRESS") );
92 } else if ( aStatus == HYDROData_Tool::Finished ) {
93 myTriangulationState->setText( tr("COMPLETED") );
97 bool isFinished = aPosition >= 1 || ( isUserBreak && GetNbScopes() < 2 );
99 if ( result() != Accepted ) {
102 } else if ( !isVisible() ) {
107 QApplication::processEvents();
113 Standard_Boolean HYDROGUI_ZIProgressIndicator::UserBreak()
118 void HYDROGUI_ZIProgressIndicator::Reset()
120 Message_ProgressIndicator::Reset();
121 myTriangulationState->setText( tr( "PENDING" ) );
122 setButtonText( Cancel, tr("CANCEL") );
123 setButtonEnabled( true, Cancel );
124 myUserBreak = Standard_False;
127 void HYDROGUI_ZIProgressIndicator::reject()
129 myUserBreak = Standard_True;
130 setButtonText( Cancel, tr("CANCELLING") );
131 setButtonEnabled( false, Cancel );
132 QApplication::processEvents();