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 #include "HYDRO_trace.hxx"
31 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_ZIProgressIndicator, Message_ProgressIndicator)
33 HYDROGUI_ZIProgressIndicator::HYDROGUI_ZIProgressIndicator( QWidget* theParent )
34 : QtxDialog( theParent, true, false, QtxDialog::Cancel ), myUserBreak(Standard_False),
37 setWindowTitle( tr( "BATHYMETRY_INTERPOLATION_TLT" ) );
39 QVBoxLayout* aLayout = new QVBoxLayout( mainFrame() );
40 aLayout->setMargin( 5 );
41 aLayout->setSpacing( 5 );
43 myQuadTreeBar = new QProgressBar( mainFrame() );
44 myTriangulationState = new QLabel( tr( "PENDING" ), mainFrame() );
45 mySummaryBar = new QProgressBar( mainFrame() );
47 QString aBold("<b>%1</b>");
49 aLayout->addWidget( new QLabel( aBold.arg( tr( "QUADTREE_STAGE" ) ) ) );
50 aLayout->addWidget( myQuadTreeBar );
51 aLayout->addSpacing( 10 );
52 aLayout->addWidget( new QLabel( aBold.arg( tr( "TRIANGULATION_STAGE" ) ) ) );
53 aLayout->addWidget( myTriangulationState );
54 aLayout->addSpacing( 10 );
55 aLayout->addWidget( new QLabel( aBold.arg( tr( "EXPLORATION_STAGE" ) ) ) );
56 aLayout->addWidget( mySummaryBar );
58 setButtonText( Cancel, tr( "CANCEL" ) );
59 setButtonPosition( Center, Cancel );
60 setMinimumWidth( 350 );
63 HYDROGUI_ZIProgressIndicator::~HYDROGUI_ZIProgressIndicator()
67 Standard_Boolean HYDROGUI_ZIProgressIndicator::Show(const Standard_Boolean theForce)
70 Standard_Boolean isUserBreak = UserBreak();
71 Standard_Real aPosition = GetPosition();
74 DEBTRACE("aPosition=" << aPosition << " myCount:" <<myCount);
78 for ( Standard_Integer i = 1; i <= GetNbScopes(); i++ ) {
79 Message_ProgressScale aScope = GetScope(i);
80 QString aName = HYDROGUI_Tool::ToQString( aScope.GetName() );
81 if ( aName != "QuadTree" ) {
85 Standard_Real aMin = aScope.GetMin();
86 Standard_Real aMax = aScope.GetMax();
87 Standard_Real aScopeValue = aScope.BaseToLocal( aPosition );
88 myQuadTreePosition = aScopeValue / (aMax - aMin);
93 myQuadTreeBar->setValue( int( myQuadTreePosition * 100 ) );
94 mySummaryBar->setValue( int( aPosition * 100 ) );
95 HYDROData_Tool::ExecStatus aStatus = HYDROData_Tool::GetTriangulationStatus();
96 if ( aStatus == HYDROData_Tool::Running ) {
97 myTriangulationState->setText( tr("IN_PROGRESS") );
98 } else if ( aStatus == HYDROData_Tool::Finished ) {
99 myTriangulationState->setText( tr("COMPLETED") );
103 bool isFinished = aPosition >= 1 || ( isUserBreak && GetNbScopes() < 2 );
104 if ( isFinished && theForce ) { // theForce == true : call from main thread, Qt display safe
105 if ( result() != Accepted ) {
108 } else if ( !isVisible() && theForce ) { // theForce == true : call from main thread, Qt display safe
113 QApplication::processEvents();
119 Standard_Boolean HYDROGUI_ZIProgressIndicator::UserBreak()
124 void HYDROGUI_ZIProgressIndicator::Reset()
126 Message_ProgressIndicator::Reset();
127 myTriangulationState->setText( tr( "PENDING" ) );
128 setButtonText( Cancel, tr("CANCEL") );
129 setButtonEnabled( true, Cancel );
130 myUserBreak = Standard_False;
134 void HYDROGUI_ZIProgressIndicator::reject()
136 myUserBreak = Standard_True;
137 setButtonText( Cancel, tr("CANCELLING") );
138 setButtonEnabled( false, Cancel );
139 QApplication::processEvents();