From: adv Date: Thu, 5 Dec 2013 07:15:57 +0000 (+0000) Subject: Correctnes of user input data checks (Bug #176). X-Git-Tag: BR_hydro_v_0_4~37 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7ef8b24039790a8b495da4fe56ee49ce21d91d82;p=modules%2Fhydro.git Correctnes of user input data checks (Bug #176). --- diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 42ba2cbf..5d39423b 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -65,8 +65,6 @@ HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, co { addPage( createObjectsPage() ); addPage( createZonesPage() ); - connect( button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) ); - connect( button( QWizard::BackButton ), SIGNAL( clicked() ), SIGNAL( hideZones() ) ); } HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg() @@ -164,20 +162,6 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { return aPage; } -void HYDROGUI_CalculationDlg::onEmptyName() -{ - QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" ); - QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" ); - SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage ); -} - -void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName ) -{ - QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" ); - QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ); - SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage ); -} - QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { QWizardPage* aPage = new QWizardPage( mainFrame() ); QFrame* aFrame = new QFrame( aPage ); @@ -212,6 +196,42 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { return aPage; } + +bool HYDROGUI_CalculationDlg::acceptCurrent() const +{ + QString anErrorMsg; + + if ( myGeomObjects->count() == 0 ) + { + anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" ); + } + + if ( !anErrorMsg.isEmpty() ) + { + anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" ); + + QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" ); + SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg ); + } + + return anErrorMsg.isEmpty(); +} + +void HYDROGUI_CalculationDlg::onEmptyName() +{ + QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" ); + QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" ); + SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage ); +} + +void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName ) +{ + QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" ); + QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) + + "\n" + tr( "INPUT_VALID_DATA" ); + SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage ); +} + void HYDROGUI_CalculationDlg::onZonesDropped( const QList& theList, SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction ) { diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 15b7578b..7178207f 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -85,13 +85,15 @@ signals: void removeObjects(); void objectSelected( const QString & theObjName ); void boundarySelected( const QString & theObjName ); - void splitZones(); - void hideZones(); void setMergeType( int theMergeType, QString& theBathymetryName ); void createRegion( const QList& theZonesList ); void moveZones( SUIT_DataObject* theRegion, const QList& theZonesList ); void clickedInZonesBrowser( SUIT_DataObject* ); +protected: + + virtual bool acceptCurrent() const; + private: QWizardPage* createObjectsPage(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 6fb6cfb4..0323f921 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -186,8 +186,8 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const // Connect signals and slots connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) ); connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); - connect( aPanel, SIGNAL( splitZones() ), SLOT( onSplitZones() ) ); - connect( aPanel, SIGNAL( hideZones() ), SLOT( onHideZones() ) ); + connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onSplitZones() ) ); + connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) ); connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) ); connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList& ) ), @@ -206,43 +206,39 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName ) { - // Set the selected boundary polyline to the calculation case - Handle(HYDROData_PolylineXY) anObject; - Handle(AIS_InteractiveContext) aCtx; - if ( myPreviewViewManager ) - { - if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() ) - { - aCtx = aViewer->getAISContext(); - } - } + bool anIsToUpdateViewer = false; + // Remove the old boundary from the operation viewer - anObject = myEditedObject->GetBoundaryPolyline(); - if ( !anObject.IsNull() ) + Handle(HYDROData_PolylineXY) aPrevPolyline = + myEditedObject->GetBoundaryPolyline(); + if ( !aPrevPolyline.IsNull() ) { - module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject ); + module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aPrevPolyline ); + anIsToUpdateViewer = true; } - if ( theObjName.trimmed().isEmpty() ) - { - // No polyline is selected - myEditedObject->RemoveBoundaryPolyline(); - } - else + // Set the selected boundary polyline to the calculation case + Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) ); + myEditedObject->SetBoundaryPolyline( aNewPolyline ); + + if ( myPreviewViewManager ) { - Handle(HYDROData_Entity) anEntity = - HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ); - if ( !anEntity.IsNull() ) + OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer(); + if ( aViewer ) { - anObject = Handle(HYDROData_PolylineXY)::DownCast( anEntity ); - if ( !anObject.IsNull() ) + if ( !aNewPolyline.IsNull() ) { - myEditedObject->SetBoundaryPolyline( anObject ); + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); if ( !aCtx.IsNull() ) { - showObject( anEntity, aCtx ); + showObject( aNewPolyline, aCtx ); + anIsToUpdateViewer = true; } } + + if ( anIsToUpdateViewer ) + aViewer->update(); } } } @@ -617,6 +613,8 @@ void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible ) } } } + + aViewer->update(); } } } @@ -695,6 +693,8 @@ void HYDROGUI_CalculationOp::createPreview() if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() ) vw->onTopView(); } + + aViewer->update(); } } @@ -708,7 +708,7 @@ void HYDROGUI_CalculationOp::showObject( Handle(HYDROData_Entity) theEntity, Han aShape = new HYDROGUI_Shape( theCtx, theEntity ); module()->setObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, theEntity, aShape ); } - aShape->update(); + aShape->update( false ); } } diff --git a/src/HYDROGUI/HYDROGUI_Wizard.cxx b/src/HYDROGUI/HYDROGUI_Wizard.cxx index 8acc5641..35707867 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.cxx +++ b/src/HYDROGUI/HYDROGUI_Wizard.cxx @@ -81,28 +81,30 @@ int HYDROGUI_Wizard::addPage( QWizardPage* thePage ) void HYDROGUI_Wizard::onNext() { - if ( myWizard->count() > 0 ) + if ( !acceptCurrent() ) + return; + + if ( myWizard->count() <= 0 ) + return; + + myBack->setEnabled( true ); + int aCurIdx = myWizard->currentIndex(); + if ( aCurIdx == ( myWizard->count() - 2 ) ) { - myBack->setEnabled( true ); - int aCurIdx = myWizard->currentIndex(); - if ( aCurIdx == ( myWizard->count() - 2 ) ) - { - // Go to the last page - myNext->setVisible( false ); - myFinish->setVisible( true ); - } - myWizard->setCurrentIndex( aCurIdx + 1 ); + // Go to the last page + myNext->setVisible( false ); + myFinish->setVisible( true ); } + myWizard->setCurrentIndex( aCurIdx + 1 ); + + emit Next( myWizard->currentIndex() ); } void HYDROGUI_Wizard::onBack() { - int aCurIdx = myWizard->currentIndex(); - if ( aCurIdx <= 1 ) - { - // Disable back if go to the first page - myBack->setEnabled( false ); - } + if ( myWizard->count() <= 0 ) + return; + if ( myWizard->count() > 1 ) { myNext->setVisible( true ); @@ -114,7 +116,23 @@ void HYDROGUI_Wizard::onBack() myNext->setVisible( false ); myFinish->setVisible( true ); } + + int aCurIdx = myWizard->currentIndex(); myWizard->setCurrentIndex( aCurIdx - 1 ); + + aCurIdx = myWizard->currentIndex(); + if ( aCurIdx <= 0 ) + { + // Disable back if go to the first page + myBack->setEnabled( false ); + } + + emit Back( aCurIdx ); +} + +bool HYDROGUI_Wizard::acceptCurrent() const +{ + return true; } QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const diff --git a/src/HYDROGUI/HYDROGUI_Wizard.h b/src/HYDROGUI/HYDROGUI_Wizard.h index 39f4fbf2..2d31434a 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.h +++ b/src/HYDROGUI/HYDROGUI_Wizard.h @@ -45,8 +45,18 @@ public: QStackedWidget* wizard() const; public slots: - void onNext(); - void onBack(); + void onNext(); + void onBack(); + +signals: + void Next( const int ); + void Back( const int ); + +protected: + + // Returns the state of current page filing. + // Reimplement this method in your subclass to verify user input data. + virtual bool acceptCurrent() const; private: QStackedWidget* myWizard; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index fe2d0936..4fece1fa 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -213,6 +213,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) REMOVE Remove + + EMPTY_GEOMETRY_OBJECTS + No one geometry object is selected, should be at least one. +