From: dmv Date: Thu, 10 Jan 2008 15:29:36 +0000 (+0000) Subject: NPAL 16841 Apply Button in Deformed Shape Dlg X-Git-Tag: mergeto_BR_QT4_Dev_17Jan08~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=318c4a102b1e032f77cb46058ef961c4a3b6b915;p=modules%2Fvisu.git NPAL 16841 Apply Button in Deformed Shape Dlg --- diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index df389e78..5be1851f 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -657,7 +657,8 @@ void VisuGUI ::OnCreateDeformedShape() { - CreatePrs3d(this); + // CreatePrs3d(this); + VisuGUI_DeformedShapeDlg::CreatePrs3d(this); } void @@ -854,7 +855,8 @@ VisuGUI { Handle(SALOME_InteractiveObject) anIO; if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, anIO)) - EditPrs3d(this, anIO, aPrs3d); + VisuGUI_DeformedShapeDlg::EditPrs3d(this, aPrs3d, anIO); + // EditPrs3d(this, anIO, aPrs3d); } //---------------------------------------------------------------------------- diff --git a/src/VISUGUI/VisuGUI_DeformedShapeDlg.cxx b/src/VISUGUI/VisuGUI_DeformedShapeDlg.cxx index 0a42dc4c..3dca281f 100644 --- a/src/VISUGUI/VisuGUI_DeformedShapeDlg.cxx +++ b/src/VISUGUI/VisuGUI_DeformedShapeDlg.cxx @@ -28,13 +28,16 @@ #include "VisuGUI_DeformedShapeDlg.h" -#include "VisuGUI.h" #include "VisuGUI_Tools.h" #include "VisuGUI_InputPane.h" - +#include "VisuGUI.h" #include "VISU_ColoredPrs3dFactory.hh" #include "VISU_DeformedShape_i.hh" - +#include "VisuGUI_ViewTools.h" +#include "VISU_Gen_i.hh" +#include "VISU_Result_i.hh" +#include "VisuGUI_Prs3dTools.h" +#include "SVTK_ViewWindow.h" #include "SalomeApp_Module.h" #include "LightApp_Application.h" #include "SUIT_Desktop.h" @@ -51,10 +54,11 @@ using namespace std; * Constructor */ VisuGUI_DeformedShapeDlg::VisuGUI_DeformedShapeDlg (SalomeApp_Module* theModule) - : VisuGUI_ScalarBarBaseDlg(theModule) + : VisuGUI_ScalarBarBaseDlg(theModule, true) { setCaption(tr("DLG_TITLE")); setSizeGripEnabled(TRUE); + myModule = theModule; QVBoxLayout* TopLayout = new QVBoxLayout (this); TopLayout->setSpacing(6); @@ -112,8 +116,10 @@ VisuGUI_DeformedShapeDlg::VisuGUI_DeformedShapeDlg (SalomeApp_Module* theModule) buttonOk->setDefault(TRUE); GroupButtonsLayout->addWidget(buttonOk, 0, 0); - GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding, - QSizePolicy::Minimum), 0, 1); + QPushButton* buttonApply = new QPushButton (tr("&Apply"), GroupButtons, "buttonApply"); + buttonApply->setAutoDefault(TRUE); + buttonApply->setDefault(TRUE); + GroupButtonsLayout->addWidget(buttonApply, 0, 1); QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel"); buttonCancel->setAutoDefault(TRUE); @@ -129,6 +135,7 @@ VisuGUI_DeformedShapeDlg::VisuGUI_DeformedShapeDlg (SalomeApp_Module* theModule) // signals and slots connections connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); + connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply())); connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())); } @@ -156,7 +163,7 @@ void VisuGUI_DeformedShapeDlg::initFromPrsObject (VISU::ColoredPrs3d_i* thePrs, int VisuGUI_DeformedShapeDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs) { - if(!myInputPane->check() || !GetScalarPane()->check()) + if( !isValid() ) return 0; int anIsOk = myInputPane->storeToPrsObject( myPrsCopy ); @@ -172,15 +179,142 @@ int VisuGUI_DeformedShapeDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs) void VisuGUI_DeformedShapeDlg::accept() { - VisuGUI_ScalarBarBaseDlg::accept(); + VisuGUI_ScalarBarBaseDlg::done( isValid() ); } void VisuGUI_DeformedShapeDlg::reject() { - VisuGUI_ScalarBarBaseDlg::reject(); + if ( myPrsCopy->GetNumberOfActors() != 0 ) + VisuGUI_ScalarBarBaseDlg::done( 1 ); + else + VisuGUI_ScalarBarBaseDlg::reject(); } QString VisuGUI_DeformedShapeDlg::GetContextHelpFilePath() { return "deformed_shape_page.html"; } + +bool VisuGUI_DeformedShapeDlg::onApply() +{ + if ( storeToPrsObject( myPrsCopy ) ) + { + if ( myPrsCopy->GetNumberOfActors() == 0 ) { + SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(); + VisuGUI* aVisuGUI = dynamic_cast (myModule); + PublishInView(aVisuGUI, myPrsCopy, aViewWindow); + aViewWindow->onFitAll(); + int aPos = VISU::GetFreePositionOfDefaultScalarBar(aVisuGUI, aViewWindow); + VISU::AddScalarBarPosition(aVisuGUI, aViewWindow, myPrsCopy, aPos); + } else { + try { + myPrsCopy->UpdateActors(); + } catch (std::runtime_error& exc) { + myPrsCopy->RemoveActors(); + + INFOS(exc.what()); + SUIT_MessageBox::warn1 + (VISU::GetDesktop(myModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); + } + } + return true; + } + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// Create and Edit +//////////////////////////////////////////////////////////////////////////////// + +void VisuGUI_DeformedShapeDlg::CreatePrs3d(VisuGUI* theModule) +{ + _PTR(SObject) aTimeStamp; + Handle(SALOME_InteractiveObject) anIO; + VISU::ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode; + + if (VISU::CheckTimeStamp(theModule, aTimeStamp, anIO, aPublishInStudyMode)) + { + VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aTimeStamp); + VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap); + if ( aType == VISU::TTIMESTAMP ) + { + + QString aMeshName = aRestoringMap["myMeshName"]; + QString anEntity = aRestoringMap["myEntityId"]; + QString aFieldName = aRestoringMap["myFieldName"]; + QString aTimeStampId = aRestoringMap["myTimeStampId"]; + + typedef VISU::DeformedShape_i TPrs3d_i; + + TPrs3d_i* aPrs3d = + VISU::CreatePrs3dFromFactory(theModule, + aTimeStamp, + aMeshName.latin1(), + (VISU::Entity)anEntity.toInt(), + aFieldName.latin1(), + aTimeStampId.toInt(), + aPublishInStudyMode); + + VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule); + aDlg->initFromPrsObject(aPrs3d, true); + VisuGUI_DialogRunner r(aDlg); + int dlgResult = r.run( false ); + + if ( dlgResult == 0 ) + aPrs3d->RemoveFromStudy(); + else { + aDlg->storeToPrsObject( aPrs3d ); + SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(); + PublishInView(theModule, aPrs3d, aViewWindow); + aViewWindow->onFitAll(); + int aPos = VISU::GetFreePositionOfDefaultScalarBar(theModule, aViewWindow); + VISU::AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos); + } + + VISU::UpdateObjBrowser(theModule, true, aTimeStamp); + delete aDlg; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// + +void VisuGUI_DeformedShapeDlg::EditPrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs3d, Handle(SALOME_InteractiveObject)& theIO) +{ + typedef VISU::DeformedShape_i TPrs3d_i; + + if (TPrs3d_i* aPrs3d = dynamic_cast(thePrs3d)) { + VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule); + aDlg->initFromPrsObject(aPrs3d, true); + VisuGUI_DialogRunner r(aDlg); + int dlgResult = r.run( false ); + + if ( dlgResult != 0 ) + aDlg->storeToPrsObject( aPrs3d ); + + try { + aPrs3d->UpdateActors(); + } + catch (std::runtime_error& exc) { + aPrs3d->RemoveActors(); + + INFOS(exc.what()); + SUIT_MessageBox::warn1 + (VISU::GetDesktop(theModule), QObject::tr("WRN_VISU"), + QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()), + QObject::tr("BUT_OK")); + } + delete aDlg; + } +} + +/////////////////////////////////////////////////////////////////////////////////// +int VisuGUI_DeformedShapeDlg::isValid() +{ + if(myInputPane->check() && GetScalarPane()->check()) + return 1; + else + return 0; +} diff --git a/src/VISUGUI/VisuGUI_DeformedShapeDlg.h b/src/VISUGUI/VisuGUI_DeformedShapeDlg.h index 2d6d1edf..34bac068 100644 --- a/src/VISUGUI/VisuGUI_DeformedShapeDlg.h +++ b/src/VISUGUI/VisuGUI_DeformedShapeDlg.h @@ -42,6 +42,7 @@ class SalomeApp_Module; class VisuGUI_InputPane; +class VisuGUI; namespace VISU { @@ -69,18 +70,23 @@ public: virtual int storeToPrsObject(VISU::ColoredPrs3d_i* thePrs); + static void CreatePrs3d(VisuGUI* theModule); + static void EditPrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs3d, Handle(SALOME_InteractiveObject)& theIO); + protected: virtual QString GetContextHelpFilePath(); - + int isValid(); protected slots: void accept(); + bool onApply(); void reject(); private: - QtxDblSpinBox* ScalFact; - QCheckBox* UseMagn; + QtxDblSpinBox* ScalFact; + QCheckBox* UseMagn; QTabWidget* myTabBox; VisuGUI_InputPane* myInputPane; + SalomeApp_Module* myModule; SALOME::GenericObjPtr myPrsCopy; }; diff --git a/src/VISUGUI/VisuGUI_Prs3dDlg.cxx b/src/VISUGUI/VisuGUI_Prs3dDlg.cxx index 065a7478..98daa46d 100644 --- a/src/VISUGUI/VisuGUI_Prs3dDlg.cxx +++ b/src/VISUGUI/VisuGUI_Prs3dDlg.cxx @@ -541,7 +541,7 @@ void VisuGUI_BarPrefDlg::keyPressEvent( QKeyEvent* e ) /*! Constructor */ -VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent): +VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool thePreview): QVBox(parent), myPreviewActor(0), myScalarMap(NULL), @@ -747,6 +747,10 @@ VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent): myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), CheckGroup); myPreviewCheck->setChecked(false); CheckGroupLayout->addWidget(myPreviewCheck , 0, 0 ); + if ( thePreview ) { + myPreviewCheck->hide(); + CheckGroup->hide(); + } if(RBvert->isChecked()) { myBarDlg->setRatios(myVerTW, myVerTH, myVerLW, myVerLH, myVerBW, myVerBH); @@ -914,7 +918,6 @@ void VisuGUI_ScalarBarPane::updatePreview() } } - //---------------------------------------------------------------------------- /*! Creating preview scalar bar */ @@ -1484,10 +1487,10 @@ void VisuGUI_Prs3dDlg::keyPressEvent( QKeyEvent* e ) //---------------------------------------------------------------------------- -VisuGUI_ScalarBarBaseDlg::VisuGUI_ScalarBarBaseDlg( SalomeApp_Module* theModule ) : +VisuGUI_ScalarBarBaseDlg::VisuGUI_ScalarBarBaseDlg( SalomeApp_Module* theModule, bool thePreview ) : VisuGUI_Prs3dDlg( theModule ) { - myScalarPane = new VisuGUI_ScalarBarPane(this); + myScalarPane = new VisuGUI_ScalarBarPane(this, thePreview); myScalarPane->setMargin( 5 ); } @@ -1526,7 +1529,6 @@ void VisuGUI_ScalarBarBaseDlg::reject() VisuGUI_Prs3dDlg::reject(); } - //---------------------------------------------------------------------------- VisuGUI_ScalarBarPane* VisuGUI_ScalarBarBaseDlg::GetScalarPane() { diff --git a/src/VISUGUI/VisuGUI_Prs3dDlg.h b/src/VISUGUI/VisuGUI_Prs3dDlg.h index 5ba245ec..fb30012d 100644 --- a/src/VISUGUI/VisuGUI_Prs3dDlg.h +++ b/src/VISUGUI/VisuGUI_Prs3dDlg.h @@ -157,7 +157,7 @@ class VisuGUI_ScalarBarPane : public QVBox Q_OBJECT; public: - VisuGUI_ScalarBarPane(QWidget* parent); + VisuGUI_ScalarBarPane(QWidget* parent, bool thePreview = FALSE); ~VisuGUI_ScalarBarPane(); void setRange( double imin, double imax, bool sbRange ); @@ -230,11 +230,11 @@ class VisuGUI_ScalarBarPane : public QVBox void createScalarBar(); void deleteScalarBar(); - QCheckBox* myPreviewCheck; + QCheckBox* myPreviewCheck; VISU_ScalarMapAct* myPreviewActor; VISU::ScalarMap_i* myScalarMap; - VISU_ScalarMapPL* myScalarMapPL; - std::string myTitle; + VISU_ScalarMapPL* myScalarMapPL; + std::string myTitle; bool myBusy; }; @@ -271,7 +271,7 @@ class VisuGUI_ScalarBarBaseDlg : public VisuGUI_Prs3dDlg Q_OBJECT; public: - VisuGUI_ScalarBarBaseDlg( SalomeApp_Module* theModule ); + VisuGUI_ScalarBarBaseDlg( SalomeApp_Module* theModule, bool thePreview = FALSE ); ~VisuGUI_ScalarBarBaseDlg(); virtual void initFromPrsObject( VISU::ColoredPrs3d_i* thePrs, diff --git a/src/VISUGUI/VisuGUI_Prs3dTools.h b/src/VISUGUI/VisuGUI_Prs3dTools.h index 9ab6a928..ba3347a0 100644 --- a/src/VISUGUI/VisuGUI_Prs3dTools.h +++ b/src/VISUGUI/VisuGUI_Prs3dTools.h @@ -33,6 +33,7 @@ #include "VisuGUI_ViewTools.h" #include "VISU_ColoredPrs3dFactory.hh" #include "VISU_PipeLine.hxx" +#include "VisuGUI_DialogRunner.h" #include diff --git a/src/VISU_I/VISU_Prs3d_i.cc b/src/VISU_I/VISU_Prs3d_i.cc index 0c2acd0b..6c32b168 100644 --- a/src/VISU_I/VISU_Prs3d_i.cc +++ b/src/VISU_I/VISU_Prs3d_i.cc @@ -675,3 +675,10 @@ VISU::Prs3d_i // Convert to mega bytes return aSize / (1024.0 * 1024.0); } + +int +VISU::Prs3d_i +::GetNumberOfActors() +{ + return myActorCollection->GetNumberOfItems(); +} diff --git a/src/VISU_I/VISU_Prs3d_i.hh b/src/VISU_I/VISU_Prs3d_i.hh index 5471eef6..92df8102 100644 --- a/src/VISU_I/VISU_Prs3d_i.hh +++ b/src/VISU_I/VISU_Prs3d_i.hh @@ -231,6 +231,9 @@ namespace VISU void GetBounds(vtkFloatingPointType aBounds[6]); + int + GetNumberOfActors (); + //! Move the 3D presentation according to the given offset parameters void SetOffset(const CORBA::Float* theOffsets);