Salome HOME
Update for occt 7.5.0
[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 void HYDROGUI_ZIProgressIndicator::Show(const Message_ProgressScope& theScope, 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     QString aName = HYDROGUI_Tool::ToQString( theScope.Name() );
79     DEBTRACE("ScopeName="<< aName);
80     myQuadTreePosition = theScope.GetPortion();
81   } else {
82     if ( !isUserBreak ) {
83       myQuadTreeBar->setValue( int( myQuadTreePosition * 100 ) );
84       mySummaryBar->setValue( int( aPosition * 100 ) );
85       HYDROData_Tool::ExecStatus aStatus = HYDROData_Tool::GetTriangulationStatus();
86       if ( aStatus == HYDROData_Tool::Running ) {
87         myTriangulationState->setText( tr("IN_PROGRESS") );
88       } else if ( aStatus == HYDROData_Tool::Finished ) {
89         myTriangulationState->setText( tr("COMPLETED") );
90       }
91     }
92
93     bool isFinished = aPosition >= 1 || ( isUserBreak );
94     if ( isFinished && theForce ) { // theForce == true : call from main thread, Qt display safe
95       if ( result() != Accepted ) {
96         QDialog::accept();
97       }
98     } else if ( !isVisible() && theForce ) { // theForce == true : call from main thread, Qt display safe
99       open();
100     }
101
102
103     QApplication::processEvents();
104   }
105
106   return;
107 }
108
109 Standard_Boolean HYDROGUI_ZIProgressIndicator::UserBreak()
110 {
111   return myUserBreak;
112 }
113
114 void HYDROGUI_ZIProgressIndicator::Reset()
115 {
116   Message_ProgressIndicator::Reset();
117   myTriangulationState->setText( tr( "PENDING" ) );
118   setButtonText( Cancel, tr("CANCEL") );
119   setButtonEnabled( true, Cancel );
120   myUserBreak = Standard_False;
121   myCount = 0;
122 }
123
124 void HYDROGUI_ZIProgressIndicator::reject()
125 {
126   myUserBreak = Standard_True;
127   setButtonText( Cancel, tr("CANCELLING") );
128   setButtonEnabled( false, Cancel );
129   QApplication::processEvents();
130 }