Salome HOME
test linear interpolation of a stream
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZIProgressIndicator.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ZIProgressIndicator.h"
20 #include "HYDROGUI_Tool.h"
21
22 #include "HYDROData_Tool.h"
23
24 #include <QLabel>
25 #include <QProgressBar>
26 #include <QVBoxLayout>
27 #include <QApplication>
28 //#define _DEVDEBUG_
29 #include "HYDRO_trace.hxx"
30
31 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_ZIProgressIndicator, Message_ProgressIndicator)
32
33 HYDROGUI_ZIProgressIndicator::HYDROGUI_ZIProgressIndicator( QWidget* theParent )
34 : QtxDialog( theParent, true, false, QtxDialog::Cancel ), myUserBreak(Standard_False),
35   myQuadTreePosition(0)
36 {
37   setWindowTitle( tr( "BATHYMETRY_INTERPOLATION_TLT" ) );
38
39   QVBoxLayout* aLayout = new QVBoxLayout( mainFrame() );
40   aLayout->setMargin( 5 );
41   aLayout->setSpacing( 5 );
42
43   myQuadTreeBar = new QProgressBar( mainFrame() );
44   myTriangulationState = new QLabel( tr( "PENDING" ), mainFrame() );
45   mySummaryBar = new QProgressBar( mainFrame() );
46
47   QString aBold("<b>%1</b>");
48
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 );
57
58   setButtonText( Cancel, tr( "CANCEL" ) );
59   setButtonPosition( Center, Cancel );
60   setMinimumWidth( 350 );
61 }
62
63 HYDROGUI_ZIProgressIndicator::~HYDROGUI_ZIProgressIndicator()
64 {
65 }
66
67 Standard_Boolean HYDROGUI_ZIProgressIndicator::Show(const Standard_Boolean theForce)
68 {
69   //DEBTRACE("...");
70   Standard_Boolean isUserBreak = UserBreak();
71   Standard_Real aPosition = GetPosition(); 
72   myCount++;
73   if (theForce)
74       DEBTRACE("aPosition=" << aPosition << " myCount:" <<myCount);
75
76   if ( !theForce ) {
77     // quadtree
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" ) {
82         continue;
83       }
84
85       Standard_Real aMin = aScope.GetMin();
86       Standard_Real aMax = aScope.GetMax();
87       Standard_Real aScopeValue = aScope.BaseToLocal( aPosition );
88       myQuadTreePosition = aScopeValue / (aMax - aMin);
89       break;
90     }
91   } else {
92     if ( !isUserBreak ) {
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") );
100       }
101     }
102
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 ) {
106         QDialog::accept();
107       } 
108     } else if ( !isVisible() && theForce ) { // theForce == true : call from main thread, Qt display safe
109       open();
110     }
111
112
113     QApplication::processEvents();
114   }
115
116   return true;
117 }
118
119 Standard_Boolean HYDROGUI_ZIProgressIndicator::UserBreak()
120 {
121   return myUserBreak;
122 }
123
124 void HYDROGUI_ZIProgressIndicator::Reset()
125 {
126   Message_ProgressIndicator::Reset();
127   myTriangulationState->setText( tr( "PENDING" ) );
128   setButtonText( Cancel, tr("CANCEL") );
129   setButtonEnabled( true, Cancel );
130   myUserBreak = Standard_False;
131   myCount = 0;
132 }
133
134 void HYDROGUI_ZIProgressIndicator::reject()
135 {
136   myUserBreak = Standard_True;
137   setButtonText( Cancel, tr("CANCELLING") );
138   setButtonEnabled( false, Cancel );
139   QApplication::processEvents();
140 }