]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Wrap IDL method to SALOME_Event objects
authorsmh <smh@opencascade.com>
Wed, 14 Apr 2004 11:00:21 +0000 (11:00 +0000)
committersmh <smh@opencascade.com>
Wed, 14 Apr 2004 11:00:21 +0000 (11:00 +0000)
src/VISU_I/VISU_ViewManager_i.cc

index f50908a456f6ee90ef4c9ae74819e02057222469..07c1804b62a00bb74eed93249ba3cfcee34a85b7 100644 (file)
@@ -70,7 +70,7 @@
 using namespace std;
 
 #ifdef _DEBUG_
-static int MYDEBUG = 0;
+static int MYDEBUG = 1;
 #else
 static int MYDEBUG = 0;
 #endif
@@ -233,43 +233,43 @@ namespace VISU{
     return aStudy;
   }
   //===========================================================================
-  /*
-  #include <qthread.h> 
-  class TViewManager: public QThread{
-  public:
-    TViewManager(SALOMEDS::Study_ptr theStudy) : myStudyDocument(theStudy) {};
-    virtual void run(){
-      qApp->lock();
-      QAD_Desktop* aDesktop = QAD_Application::getDesktop();
-      QAD_Study* aStudy = aDesktop->findStudy(myStudyDocument);
-      if(!aStudy){
-       CORBA::String_var aName = myStudyDocument->Name();
-       aFileInfo.setFile(aName.in());
-       aStudy = aDesktop->loadStudy(aFileInfo.baseName());
-      }
-      qApp->unlock();
-    }
-    SALOMEDS::Study_ptr myStudyDocument;
-  };
-  */
   ViewManager_i::ViewManager_i(SALOMEDS::Study_ptr theStudy) {
     if(MYDEBUG) MESSAGE("ViewManager_i::ViewManager_i");
     Mutex mt(myMutex,qApp,MYDELAY);
     myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
-    //TViewManager* aTViewManager = new TViewManager(theStudy);
-    //aTViewManager->start();
   }
 
 
+
   VISU::View3D_ptr ViewManager_i::Create3DView(){
     if(MYDEBUG) MESSAGE("ViewManager_i::Create3DView");
-    VISU_ViewEvent* ve = new VISU_ViewEvent( VISU_Event::Create3DView, true, this );
+
+    class TEvent: public SALOME_Event{
+      SALOMEDS::Study_ptr myStudyDocument;
+    public:
+      TEvent( SALOMEDS::Study_ptr theStudy):
+       myStudyDocument(theStudy)
+      {}
+      virtual bool Execute(){
+       if ( CheckStudy( myStudyDocument ) ) {
+         VISU::View3D_i* pView = new View3D_i(myStudyDocument);
+         if(pView->Create(1) != NULL) 
+           myResult = pView->_this();
+       }
+       return CORBA::is_nil(myResult.in()); 
+      }
+      typedef VISU::View3D_var TResult;
+      TResult myResult;
+    };
+
+    TEvent* ve = new TEvent( myStudyDocument );
     ve->process();
-    VISU::View3D_ptr aView = VISU::View3D::_narrow( ve->getView() );
+    TEvent::TResult aResult = ve->myResult;
     ve->release();
-    return aView;
+    return aResult._retn();
   }
 
+  
 
   VISU::View_ptr ViewManager_i::GetCurrentView(){
     Mutex mt(myMutex,qApp,MYDELAY);
@@ -800,63 +800,45 @@ namespace VISU{
       myStudyFrame = myStudy->newWindow3d("",VIEW_VTK);
     else
       myStudyFrame = myStudy->getActiveStudyFrame();
+    return this;
+  }
 
-    //GetViewFrame(myStudyFrame)->GetScale(myScaleFactor);
-
-    return this; //Build(false);
-  }
-
-//   Storable* View3D_i::Build(int theRestoring){
-//     if(MYDEBUG) MESSAGE("View3D_i::Build");
-//     if(theRestoring){
-//       myStudyFrame->setTitle(myName.c_str());
-//       SetBackground(myColor);
-//       SetPointOfView(myPosition);
-//       SetViewUp(myViewUp);
-//       SetFocalPoint(myFocalPnt);
-//       SetParallelScale(myParallelScale);
-//       ScaleView(VISU::View3D::XAxis,myScaleFactor[0]);
-//       ScaleView(VISU::View3D::YAxis,myScaleFactor[1]);
-//       ScaleView(VISU::View3D::ZAxis,myScaleFactor[2]);
-//       RepaintView(myStudyFrame);
-//     }else{
-//       Update();
-      
-//       SALOMEDS::SComponent_var aSComponent = FindOrCreateVisuComponent(myStudyDocument);
-//       CORBA::String_var aSComponentEntry = aSComponent->GetID(), anIOR(GetID());
-//       string anEntry = CreateAttributes(myStudyDocument,aSComponentEntry,"",anIOR,myName.c_str(),"",GetComment());
-      
-//     }
-//     return this;
-//   }
 
   void View3D_i::Update(){
     if(MYDEBUG) MESSAGE("View3D_i::Update");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    myName = (const char*)myStudyFrame->title();
-//     myColor = GetBackground();
-//     GetCamera(myStudyFrame)->GetPosition(myPosition);
-//     GetCamera(myStudyFrame)->GetViewUp(myViewUp);
-//     GetCamera(myStudyFrame)->GetFocalPoint(myFocalPnt);
-//     myParallelScale = GetCamera(myStudyFrame)->GetParallelScale();
-    //RepaintView(myStudyFrame);
-
-    //GetViewFrame(myStudyFrame)->GetScale(myScaleFactor);
-
-    VTKViewer_ViewFrame* vf =  GetViewFrame(myStudyFrame);
-    vtkRenderer* Renderer = vf->getRenderer();
-    vtkActorCollection* theActors = Renderer->GetActors();
-    theActors->InitTraversal();
-    vtkActor *actor;
-    while(actor = theActors->GetNextActor()){
-      if(VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(actor)){
-       VISU::Prs3d_i* aPrs3d  = anActor->GetPrs3d();
-       if(anActor->GetVisibility() && aPrs3d){
-         aPrs3d->Update();
-         aPrs3d->UpdateActor(anActor);
+
+    class TEvent: public SALOME_Event{
+      QAD_StudyFrame* myStudyFrame;
+    public:
+      TEvent( QAD_StudyFrame* theStudyFrame ):
+       myStudyFrame(theStudyFrame)
+      {}
+      virtual bool Execute(){
+       VTKViewer_ViewFrame* vf =  GetViewFrame(myStudyFrame);
+       vtkRenderer* Renderer = vf->getRenderer();
+       vtkActorCollection* theActors = Renderer->GetActors();
+       theActors->InitTraversal();
+       vtkActor *actor;
+       while(actor = theActors->GetNextActor()){
+         if(VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(actor)){
+           VISU::Prs3d_i* aPrs3d  = anActor->GetPrs3d();
+           if(anActor->GetVisibility() && aPrs3d){
+             aPrs3d->Update();
+             aPrs3d->UpdateActor(anActor);
+           }
+         }
        }
+       myResult = myStudyFrame->title().latin1();
+       return true; 
       }
-    }
+      typedef string TResult;
+      TResult myResult;
+    };
+
+    TEvent* ve = new TEvent( myStudyFrame );
+    ve->process();
+    myName = ve->myResult;
+    ve->release();
   }
 
   CORBA::Boolean View3D_i::SavePicture(const char* theFileName) {
@@ -1030,20 +1012,6 @@ namespace VISU{
   }
 
 
-//   Storable* VISU::View3DRestore(SALOMEDS::SComponent_var& theSComponent, SALOMEDS::Study_var& theStudy,
-//                             const char* thePrefix, const Storable::TRestoringMap& theMap)
-//     {
-//       try{
-//     View3D_i* pView3D = new View3D_i(theStudy);
-//     return pView3D->Restore(theMap);
-//       }catch(std::logic_error& exc){
-//     MESSAGE("Follow exception was accured :\n"<<exc.what());
-//       }catch(...){
-//     MESSAGE("Unknown exception was accured!");
-//       }
-//       return NULL;
-//     }
-  
   void View3D_i::Close(){
     if(MYDEBUG) MESSAGE("View3D_i::Close");
     Mutex mt(myMutex,qApp,MYDELAY);
@@ -1114,76 +1082,143 @@ namespace VISU{
     Mutex mt(myMutex,qApp,MYDELAY);
     myStudyFrame->showMaximized();
   }
+
+
   //===========================================================================
+  class TUpdateViewerEvent: public SALOME_Event{
+    QAD_StudyFrame* myStudyFrame;
+    Prs3d_i* myPrs3d;
+    int myDisplaing;
+  public:
+    TUpdateViewerEvent( QAD_StudyFrame* theStudyFrame,
+                       Prs3d_i* thePrs3d,
+                       int theDisplaing ):
+      myStudyFrame(theStudyFrame),
+      myPrs3d(thePrs3d),
+      myDisplaing(theDisplaing)
+    {}
+    virtual bool Execute(){
+      UpdateViewer(myStudyFrame,myDisplaing,myPrs3d);
+      return true; 
+    }
+  };
+
   void View3D_i::EraseAll() {
     if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    UpdateViewer(myStudyFrame,eEraseAll);
+    ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, NULL, eEraseAll ));
   }
+
   void View3D_i::DisplayAll() {
     if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    UpdateViewer(myStudyFrame,eDisplayAll);
+    ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, NULL, eDisplayAll ));
   }
+
   void View3D_i::Erase(PrsObject_ptr thePrsObj) {
     if(MYDEBUG) MESSAGE("View3D_i::Erase");
-    Mutex mt(myMutex,qApp,MYDELAY);
     CORBA::Object_ptr anObj = thePrsObj;
-    if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in()))
-      UpdateViewer(myStudyFrame,eErase,aPrs);
+    if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
+      ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, aPrs, eErase ));
+    }
   }
+
   void View3D_i::Display(PrsObject_ptr thePrsObj) {
     if(MYDEBUG) MESSAGE("View3D_i::Display"); 
-    Mutex mt(myMutex,qApp,MYDELAY);
     CORBA::Object_ptr anObj = thePrsObj;
-    if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in()))
-      UpdateViewer(myStudyFrame,eDisplay,aPrs);
+    if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
+      ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, aPrs, eDisplay ));
+    }
   }
+
   void View3D_i::DisplayOnly(PrsObject_ptr thePrsObj) {
     if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
-    Mutex mt(myMutex,qApp,MYDELAY);
     CORBA::Object_ptr anObj = thePrsObj;
-    if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in()))
-      UpdateViewer(myStudyFrame,eDisplayOnly,aPrs);
+    if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
+      ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, aPrs, eDisplayOnly ));
+    }
   }
 
   //-------------------- 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;
+  };
+
+  
   void View3D_i::FitAll() { 
     if(MYDEBUG) MESSAGE("View3D_i::FitAll");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    GetViewFrame(myStudyFrame)->onViewFitAll();
+    ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewFitAll ));
     Update();
   }
+
   void View3D_i::SetView(VISU::View3D::ViewType theType) {
     if(MYDEBUG) MESSAGE("View3D_i::SetView");
-    Mutex mt(myMutex,qApp,MYDELAY);
     switch(theType){
-    case VISU::View3D::FRONT : GetViewFrame(myStudyFrame)->onViewFront(); break;
-    case VISU::View3D::BACK : GetViewFrame(myStudyFrame)->onViewBack(); break;
-    case VISU::View3D::LEFT : GetViewFrame(myStudyFrame)->onViewLeft(); break;
-    case VISU::View3D::RIGHT : GetViewFrame(myStudyFrame)->onViewRight(); break;
-    case VISU::View3D::TOP : GetViewFrame(myStudyFrame)->onViewTop(); break;
-    case VISU::View3D::BOTTOM : GetViewFrame(myStudyFrame)->onViewBottom(); break;
+    case VISU::View3D::FRONT : 
+      ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewFront ));
+      break;
+    case VISU::View3D::BACK : 
+      ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewBack ));
+      break;
+    case VISU::View3D::LEFT : 
+      ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewLeft ));
+      break;
+    case VISU::View3D::RIGHT : 
+      ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewRight ));
+      break;
+    case VISU::View3D::TOP : 
+      ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewTop ));
+      break;
+    case VISU::View3D::BOTTOM : 
+      ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewBottom ));
+      break;
     }
     Update();
   }
 
+
   void View3D_i::SetPointOfView(QAD_StudyFrame* theStudyFrame, const CORBA::Double thePosition[3]) {
     GetCamera(theStudyFrame)->SetPosition(thePosition);
   }
-  void View3D_i::SetPointOfView(const VISU::View3D::XYZ theCoord) {
+  void View3D_i::SetPointOfView(const VISU::View3D::XYZ thePosition) {
     if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
-    Mutex mt(myMutex,qApp,MYDELAY);
-    //VISU::View3D::XYZ_copy(myPosition,theCoord);
-    SetPointOfView(myStudyFrame, theCoord);
+
+    class TEvent: public SALOME_Event{
+    public:
+      TEvent( QAD_StudyFrame* theStudyFrame,
+             const CORBA::Double thePosition[3] ):
+       myStudyFrame(theStudyFrame),
+       myPosition(thePosition)
+      {}
+      virtual bool Execute(){
+       SetPointOfView(myStudyFrame, myPosition);
+       return true; 
+      }
+    private:
+      QAD_StudyFrame* myStudyFrame;
+      const CORBA::Double* myPosition;
+    };
+
+    ProcessVoidEvent(new TEvent( myStudyFrame, thePosition));
   }
 
+
   void View3D_i::GetPointOfView(QAD_StudyFrame* theStudyFrame, CORBA::Double thePosition[3]) { 
     GetCamera(theStudyFrame)->GetPosition(thePosition);
   }
   VISU::View3D::XYZ_slice* View3D_i::GetPointOfView() { 
     if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
-    Mutex mt(myMutex,qApp,MYDELAY);
     CORBA::Double aPosition[3];
     GetPointOfView(myStudyFrame,aPosition);
     return VISU::View3D::XYZ_dup(aPosition);