]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
NPAL 16841 Apply Button in Deformed Shape Dlg
authordmv <dmv@opencascade.com>
Thu, 10 Jan 2008 15:29:36 +0000 (15:29 +0000)
committerdmv <dmv@opencascade.com>
Thu, 10 Jan 2008 15:29:36 +0000 (15:29 +0000)
src/VISUGUI/VisuGUI.cxx
src/VISUGUI/VisuGUI_DeformedShapeDlg.cxx
src/VISUGUI/VisuGUI_DeformedShapeDlg.h
src/VISUGUI/VisuGUI_Prs3dDlg.cxx
src/VISUGUI/VisuGUI_Prs3dDlg.h
src/VISUGUI/VisuGUI_Prs3dTools.h
src/VISU_I/VISU_Prs3d_i.cc
src/VISU_I/VISU_Prs3d_i.hh

index df389e78692d1fd5711796a890507d8e1ce5a6d6..5be1851f943d2768b7cc8bd3d0a32746208c9883 100644 (file)
@@ -657,7 +657,8 @@ void
 VisuGUI
 ::OnCreateDeformedShape()
 {
-  CreatePrs3d<VISU::DeformedShape_i,VisuGUI_DeformedShapeDlg,1>(this);
+  //  CreatePrs3d<VISU::DeformedShape_i,VisuGUI_DeformedShapeDlg,1>(this);
+  VisuGUI_DeformedShapeDlg::CreatePrs3d(this);
 }
 
 void
@@ -854,7 +855,8 @@ VisuGUI
 {
   Handle(SALOME_InteractiveObject) anIO;
   if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, anIO))
-    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg, 1>(this, anIO, aPrs3d);
+    VisuGUI_DeformedShapeDlg::EditPrs3d(this, aPrs3d, anIO);
+  //    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg, 1>(this, anIO, aPrs3d);
 }
 
 //----------------------------------------------------------------------------
index 0a42dc4c371917dd7503a3f51c5598e26498e4d9..3dca281f7aeceb2c097469d66c6570ad7c095f10 100644 (file)
 
 #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<SVTK_ViewWindow>();
+      VisuGUI* aVisuGUI = dynamic_cast <VisuGUI*>(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<TPrs3d_i>(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<SVTK_ViewWindow>();
+           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<TPrs3d_i*>(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;
+}
index 2d6d1edf9f342af1506fdef9983506442cfe8b15..34bac0680a810a16725b426ac8a990db925ff431 100644 (file)
@@ -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<VISU::DeformedShape_i> myPrsCopy;
 };
 
index 065a7478e03ed1f29d5c0a87ac8cc3f4f9a78058..98daa46d1355aa540e3b8dcabb43a91d145db1dc 100644 (file)
@@ -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()
 {
index 5ba245ec2f77772ed4cf3478b2b53b7b17a7e8ef..fb30012d117d996868f2d6600327b8c744995da3 100644 (file)
@@ -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,
index 9ab6a92810c876b3228a6c5952b4ed6589143c18..ba3347a037229a0ee404f44fa0165135e4c327e8 100644 (file)
@@ -33,6 +33,7 @@
 #include "VisuGUI_ViewTools.h"
 #include "VISU_ColoredPrs3dFactory.hh"
 #include "VISU_PipeLine.hxx"
+#include "VisuGUI_DialogRunner.h"
 
 #include <SPlot2d_ViewWindow.h>
 
index 0c2acd0b1b351ebc22547ea7c9f81cef8b6b3908..6c32b1685ff08ff2a41de27e861fbcad6567253a 100644 (file)
@@ -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();
+}
index 5471eef6e92f292d8ab5a49dedd9138598c88d65..92df8102554c8d7ceeab6d1e4073634a503e3e38 100644 (file)
@@ -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);