]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Templatesation of SALOME_Event descendants
authorsmh <smh@opencascade.com>
Thu, 15 Apr 2004 13:38:59 +0000 (13:38 +0000)
committersmh <smh@opencascade.com>
Thu, 15 Apr 2004 13:38:59 +0000 (13:38 +0000)
src/VISU_I/VISU_ViewManager_i.cc

index eadf3ecfe95f0618ca1ef9dad7235225b5395b0e..2ba2c0309559ee3621578b82ddaeb7091122b54f 100644 (file)
@@ -80,6 +80,44 @@ static int MYDELAY = 1;
 
 namespace VISU{
   //===========================================================================
+  template<class TObject, typename TResult = void>
+  class TMemFunEvent: public SALOME_Event{
+  public:
+    typedef TResult (TObject::* TAction)();
+    TMemFunEvent(TObject* theObject, TAction theAction):
+      myObject(theObject),
+      myAction(theAction)
+    {}
+    virtual bool Execute(){
+      (myObject->*myAction)();
+      return true; 
+    }
+  private:
+    TObject* myObject;
+    TAction myAction;
+  };
+  
+
+  template<class TObject, typename TArg, typename TStoreArg = TArg, typename TResult = void>
+  class TMemFun1ArgEvent: public SALOME_Event{
+  public:
+    typedef TResult (TObject::* TAction)(TArg);
+    TMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg):
+      myObject(theObject),
+      myAction(theAction),
+      myArg(theArg)
+    {}
+    virtual bool Execute(){
+      (myObject->*myAction)(myArg);
+      return true; 
+    }
+  private:
+    TObject* myObject;
+    TAction myAction;
+    TStoreArg myArg;
+  };
+  
+
   VTKViewer_ViewFrame* GetViewFrame(QAD_StudyFrame* theStudyFrame){
     return dynamic_cast<VTKViewer_ViewFrame*>(theStudyFrame->getRightFrame()->getViewFrame());
   }
@@ -447,53 +485,56 @@ namespace VISU{
     if(MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i");
   }
   Storable* XYPlot_i::Create(int theNew){
-    if(MYDEBUG) MESSAGE("XYPlot_i::Create");
-    Mutex mt(myMutex,qApp,MYDELAY);
     if(theNew)
       myStudyFrame = myStudy->newWindow3d("",VIEW_PLOT2D);
     else
       myStudyFrame = myStudy->getActiveStudyFrame();
     myView = dynamic_cast<Plot2d_ViewFrame*>(myStudyFrame->getRightFrame()->getViewFrame());
-    Update();
+    myView->Repaint();
     return this;
   } 
+
+
   void XYPlot_i::Update() {
-    if(MYDEBUG) MESSAGE("XYPlot_i::Update");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    myName = (const char*)(myStudyFrame->title());
-    myView->Repaint();
+    ProcessVoidEvent(new TMemFunEvent<Plot2d_ViewFrame>(myView,&Plot2d_ViewFrame::Repaint));
   }
+
+
   void XYPlot_i::Close(){
-    if(MYDEBUG) MESSAGE("XYPlot_i::Close");
-    Mutex mt(myMutex,qApp,MYDELAY);
     myStudyFrame->close();
   }
+
   XYPlot_i::~XYPlot_i() {
     if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    myStudyFrame->close();
   }
+
+
   void XYPlot_i::SetTitle(const char* theTitle){
-    if(MYDEBUG) MESSAGE("XYPlot_i::SetTitle");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    myName = theTitle;
-    myStudyFrame->setCaption(myName.c_str());
+    ProcessVoidEvent(new TMemFun1ArgEvent<QAD_StudyFrame,const QString&,QString>
+                    (myStudyFrame,&QAD_StudyFrame::setCaption,QString(theTitle)));
   }
   char* XYPlot_i::GetTitle() {
-    if(MYDEBUG) MESSAGE("XYPlot_i::GetTitle");
-    Mutex mt(myMutex,qApp);
-    myName = (const char*)(myStudyFrame->title());
-    return CORBA::string_dup(myName.c_str());
+    return CORBA::string_dup(myStudyFrame->title().latin1());
   }
 
   void XYPlot_i::SetSubTitle(const char* theTitle){
-    if(MYDEBUG) MESSAGE("XYPlot_i::SetSubTitle");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    myView->setTitle(theTitle);
+     class TEvent: public SALOME_Event{
+      Plot2d_ViewFrame* myView;
+      const char* myName;
+    public:
+      TEvent(Plot2d_ViewFrame* theView,
+            const char* theName):
+       myView(theView),
+       myName(theName)
+      {}
+      virtual bool Execute(){
+       myView->setTitle(myName);
+       return true; 
+      }
+    };
+    ProcessVoidEvent(new TEvent(myView,theTitle));
   }
   char* XYPlot_i::GetSubTitle() {
-    if(MYDEBUG) MESSAGE("XYPlot_i::GetSubTitle");
-    Mutex mt(myMutex,qApp,MYDELAY);
     return CORBA::string_dup(myView->getTitle());
   }
 
@@ -780,7 +821,7 @@ namespace VISU{
                                          SALOMEGUI_TableDlg::ttAuto, 
                                          Qt::Vertical);
          myView->show();
-         myName = (myView->caption()).latin1();
+         myName = myView->caption().latin1();
          return this;
        }
       }
@@ -1081,39 +1122,20 @@ namespace VISU{
 
 
   void View3D_i::Close(){
-    if(MYDEBUG) MESSAGE("View3D_i::Close");
     myStudyFrame->close();
   }
 
   View3D_i::~View3D_i() {
     if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
-    myStudyFrame->close();
   }
 
   //-------------------- View interface --------------------
   void View3D_i::SetTitle(const char* theTitle){
-    class TEvent: public SALOME_Event{
-      QAD_StudyFrame* myStudyFrame;
-      const char* myName;
-    public:
-      TEvent(QAD_StudyFrame* theStudyFrame,
-            const char* theName):
-       myStudyFrame(theStudyFrame),
-       myName(theName)
-      {}
-      virtual bool Execute(){
-       myStudyFrame->setTitle(myName);
-       return true; 
-      }
-    };
-    if(MYDEBUG) MESSAGE("View3D_i::SetTitle");
-    myName = theTitle;
-    ProcessVoidEvent(new TEvent(myStudyFrame,theTitle));
+    ProcessVoidEvent(new TMemFun1ArgEvent<QAD_StudyFrame,const QString&,QString>
+                    (myStudyFrame,&QAD_StudyFrame::setTitle,QString(theTitle)));
   }
   char* View3D_i::GetTitle() {
-    if(MYDEBUG) MESSAGE("View3D_i::GetTitle");
-    myName = myStudyFrame->title().latin1();
-    return CORBA::string_dup(myName.c_str());
+    return CORBA::string_dup(myStudyFrame->title().latin1());
   }
 
 
@@ -1158,34 +1180,14 @@ namespace VISU{
   }
 
 
-  class TFrameActionEvent: public SALOME_Event{
-  public:
-    typedef void (QAD_StudyFrame::* TFrameAction)();
-    TFrameActionEvent(QAD_StudyFrame* theStudyFrame,
-                     TFrameAction theFrameAction):
-      myStudyFrame(theStudyFrame),
-      myFrameAction(theFrameAction)
-    {}
-    virtual bool Execute(){
-      (myStudyFrame->*myFrameAction)();
-      return true; 
-    }
-  private:
-    QAD_StudyFrame* myStudyFrame;
-    TFrameAction myFrameAction;
-  };
-
-
+  typedef TMemFunEvent<QAD_StudyFrame> TFrameActionEvent;
   void View3D_i::Minimize() {
-    if(MYDEBUG) MESSAGE("View3D_i::Minimize");
     ProcessVoidEvent(new TFrameActionEvent(myStudyFrame,&QAD_StudyFrame::showMinimized));
   }
   void View3D_i::Restore() {
-    if(MYDEBUG) MESSAGE("View3D_i::Restore");
     ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showNormal));
   }
   void View3D_i::Maximize() {
-    if(MYDEBUG) MESSAGE("View3D_i::Maximize");
     ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showMaximized));
   }
 
@@ -1244,27 +1246,12 @@ namespace VISU{
   }
 
   //-------------------- View3D interface --------------------
-  class TViewActionEvent: public SALOME_Event{
-  public:
-    typedef void (VTKViewer_ViewFrame::* TViewAction)();
-    TViewActionEvent(QAD_StudyFrame* theStudyFrame,
-                    TViewAction theViewAction):
-      myStudyFrame(theStudyFrame),
-      myViewAction(theViewAction)
-    {}
-    virtual bool Execute(){
-      (GetViewFrame(myStudyFrame)->*myViewAction)();
-      return true; 
-    }
-  private:
-    QAD_StudyFrame* myStudyFrame;
-    TViewAction myViewAction;
-  };
+  typedef TMemFunEvent<VTKViewer_ViewFrame> TViewActionEvent;
 
   
   void View3D_i::FitAll() { 
     if(MYDEBUG) MESSAGE("View3D_i::FitAll");
-    ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewFitAll));
+    ProcessVoidEvent(new TViewActionEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewFitAll));
     Update();
   }
 
@@ -1273,22 +1260,22 @@ namespace VISU{
     if(MYDEBUG) MESSAGE("View3D_i::SetView");
     switch(theType){
     case VISU::View3D::FRONT : 
-      ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewFront));
+      ProcessVoidEvent(new TViewActionEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewFront));
       break;
     case VISU::View3D::BACK : 
-      ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewBack));
+      ProcessVoidEvent(new TViewActionEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewBack));
       break;
     case VISU::View3D::LEFT : 
-      ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewLeft));
+      ProcessVoidEvent(new TViewActionEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewLeft));
       break;
     case VISU::View3D::RIGHT : 
-      ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewRight));
+      ProcessVoidEvent(new TViewActionEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewRight));
       break;
     case VISU::View3D::TOP : 
-      ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewTop));
+      ProcessVoidEvent(new TViewActionEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewTop));
       break;
     case VISU::View3D::BOTTOM : 
-      ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewBottom));
+      ProcessVoidEvent(new TViewActionEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewBottom));
       break;
     }
     Update();