]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Merge with V3_1_0a
authorapo <apo@opencascade.com>
Mon, 10 Oct 2005 14:48:55 +0000 (14:48 +0000)
committerapo <apo@opencascade.com>
Mon, 10 Oct 2005 14:48:55 +0000 (14:48 +0000)
src/VISUGUI/VisuGUI.cxx
src/VISUGUI/VisuGUI.h
src/VISUGUI/VisuGUI_Module.cxx
src/VISUGUI/VisuGUI_Prs3dTools.h
src/VISUGUI/VisuGUI_Tools.cxx
src/VISUGUI/VisuGUI_Tools.h
src/VISU_I/VISU_View_i.cc

index 3b6293816d5b2afb5f259efe6699a02bb277973d..275e4523bb616b2290ed759ec48c71f878cf98ae 100644 (file)
@@ -561,14 +561,14 @@ void
 VisuGUI::
 OnCreateCutPlanes()
 {
-  CreatePrs3d<VISU::CutPlanes_i,VisuGUI_CutPlanesDlg,1>(this);
+  CreatePrs3d<VISU::CutPlanes_i,VisuGUI_CutPlanesDlg,0>(this);
 }
 
 void
 VisuGUI::
 OnCreateCutLines()
 {
-  CreatePrs3d<VISU::CutLines_i,VisuGUI_CutLinesDlg,1>(this);
+  CreatePrs3d<VISU::CutLines_i,VisuGUI_CutLinesDlg,0>(this);
 }
 
 void
@@ -582,7 +582,7 @@ void
 VisuGUI::
 OnCreatePlot3D()
 {
-  CreatePrs3d<VISU::Plot3D_i,VisuGUI_Plot3DDlg,1>(this);
+  CreatePrs3d<VISU::Plot3D_i,VisuGUI_Plot3DDlg,0>(this);
 }
 
 void
@@ -696,7 +696,7 @@ OnEditScalarMap()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::ScalarMap_i, VisuGUI_ScalarBarDlg>(this, aPrs3d);
+    EditPrs3d<VISU::ScalarMap_i, VisuGUI_ScalarBarDlg,1>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -710,7 +710,7 @@ OnEditDeformedShape()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg>(this, aPrs3d);
+    EditPrs3d<VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg,1>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -724,7 +724,7 @@ OnEditCutPlanes()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::CutPlanes_i, VisuGUI_CutPlanesDlg>(this, aPrs3d);
+    EditPrs3d<VISU::CutPlanes_i, VisuGUI_CutPlanesDlg,0>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -738,7 +738,7 @@ OnEditCutLines()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::CutLines_i, VisuGUI_CutLinesDlg>(this, aPrs3d);
+    EditPrs3d<VISU::CutLines_i, VisuGUI_CutLinesDlg,0>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -752,7 +752,7 @@ OnEditIsoSurfaces()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg>(this, aPrs3d);
+    EditPrs3d<VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg,1>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -766,7 +766,7 @@ OnEditVectors()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::Vectors_i, VisuGUI_VectorsDlg>(this, aPrs3d);
+    EditPrs3d<VISU::Vectors_i, VisuGUI_VectorsDlg,1>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -780,7 +780,7 @@ OnEditStreamLines()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::StreamLines_i, VisuGUI_StreamLinesDlg>(this, aPrs3d);
+    EditPrs3d<VISU::StreamLines_i, VisuGUI_StreamLinesDlg,1>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -794,7 +794,7 @@ OnEditPlot3D()
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::Plot3D_i, VisuGUI_Plot3DDlg>(this, aPrs3d);
+    EditPrs3d<VISU::Plot3D_i, VisuGUI_Plot3DDlg,0>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow()){
       aViewWindow->highlight(anIO, 1);
     }
@@ -2892,3 +2892,7 @@ VisuGUI
   return getApp()->getViewManager(theType,theIsCreate);
 }
 
+SalomeApp_Displayer* VisuGUI::displayer()
+{
+  return 0;
+}
index 5b76de10432c10a31ec6d4dfbbac67b866afbb52..d0b5c1a5bc4dc2be1cef17b37984cc7c0f9d8ab7 100644 (file)
@@ -42,6 +42,7 @@ public:
   VisuGUI();
   virtual ~VisuGUI();
 
+  virtual SalomeApp_Displayer*    displayer();
   virtual void initialize( CAM_Application* );
   virtual void windows( QMap<int, int>& ) const;
   virtual void viewManagers( QStringList& ) const;
@@ -147,6 +148,9 @@ private:
   void createMenus();
   void createToolBars();
   void createPopupMenus();
+
+private:
+  SalomeApp_Displayer*  myDisplayer;
 };
 
 #endif
index 6dc6997da7fa571a63ad09b3b99e9f4ea34da844..73ed530000f9ec07a28519de7bbb44440a01643b 100644 (file)
@@ -737,7 +737,7 @@ VisuGUI_Module
 {
   Handle(SALOME_InteractiveObject) anIO;
   if(VISU::Prs3d_i* aPrs3d = GetPrsToModify(this,&anIO)){
-    EditPrs3d<VISU::GaussPoints_i, VisuGUI_GaussPointsDlg>(this, aPrs3d);
+    EditPrs3d<VISU::GaussPoints_i,VisuGUI_GaussPointsDlg,1>(this, aPrs3d);
     if(SVTK_ViewWindow* aViewWindow = GetViewWindow<VVTK_Viewer>(this,true)){
       aViewWindow->highlight(anIO,1);
     }
index b13975c84349192aef47a8b5c415cd679c7bdf6d..4287a9abe700782ea7a9a88fd40ab29922cd495f 100644 (file)
@@ -29,8 +29,9 @@
 #ifndef VisuGUI_Prs3dTools_HeaderFile
 #define VisuGUI_Prs3dTools_HeaderFile
 
-#include "VisuGUI_ViewTools.h"
 #include "VISU_Gen_i.hh"
+#include "VisuGUI_ViewTools.h"
+#include "VisuGUI_DialogRunner.h"
 
 #include <vtkRenderer.h>
 
@@ -39,8 +40,16 @@ namespace VISU
   class CutLines_i;
 
   //---------------------------------------------------------------
-  template<class TPrs3d_i, class TViewer, class TDlg>
   inline
+  int
+  runAndWait( QDialog* dlg, const bool modal )
+  {
+    VisuGUI_DialogRunner r( dlg );
+    return r.run( modal );
+  }
+
+  //---------------------------------------------------------------
+  template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
   void
   EditPrs3d(VisuGUI* theModule, 
            VISU::Prs3d_i* thePrs3d)
@@ -48,7 +57,7 @@ namespace VISU
     if(TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)){
       TDlg* aDlg = new TDlg (theModule);
       aDlg->initFromPrsObject(aPrs3d);
-      if (aDlg->exec()) {
+      if (runAndWait(aDlg,TIsDlgModal)) {
        if (!(aDlg->storeToPrsObject(aPrs3d))) {
          delete aDlg;
          return;
@@ -71,13 +80,13 @@ namespace VISU
     }
   }
 
-  template<class TPrs3d_i, class TDlg>
+  template<class TPrs3d_i, class TDlg, int TIsDlgModal>
   inline
   void
   EditPrs3d(VisuGUI* theModule, 
            VISU::Prs3d_i* thePrs3d)
   {
-    EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg>(theModule,thePrs3d);
+    EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule,thePrs3d);
   }
 
   //---------------------------------------------------------------
@@ -146,8 +155,8 @@ namespace VISU
       if(!aValue){
        if(TDlg* aDlg = new TDlg(theModule)){ // dialog box in creation mode
          aDlg->initFromPrsObject(aPrs3d);
-         if(IsDlgModal)
-           if(aDlg->exec() && (aDlg->storeToPrsObject(aPrs3d))){
+
+           if(runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
              // Optionally, create table and curves for cut lines
              QApplication::setOverrideCursor(Qt::waitCursor);
              CreateCurves( theModule,
@@ -161,10 +170,6 @@ namespace VISU
              delete aDlg;
              return false;
            }
-         else{
-           aDlg->show();
-           return true;
-         }
        }
       }
       PublishInView<TViewer>(theModule,aPrs3d,true,theIsCreateView);
index 6db5b293be0b6516bcbf02ead14e045e79801148..5593929b8848c88848361763d358744f144b67e3 100644 (file)
@@ -213,15 +213,15 @@ namespace VISU
   {
     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
       return NULL;
-    
+
     CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
-    if (CORBA::is_nil(anObject)) 
+    if (CORBA::is_nil(anObject))
       return NULL;
 
     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
-    if (!aServant.in()) 
+    if (!aServant.in())
       return NULL;
-    
+
     return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
   }
 
@@ -391,9 +391,13 @@ namespace VISU
                  _PTR(Study)       theStudy,
                  _PTR(SObject)     theSObject)
   {
+    SalomeApp_Study* study = GetAppStudy( theModule );
+    study->deleteReferencesTo( theSObject );
+
     _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
     for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
       _PTR(SObject) aChildSObject = aChildIter->Value();
+      study->deleteReferencesTo( aChildSObject );
       CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
       ErasePrs(theModule, aChildObj);
     }
@@ -408,6 +412,7 @@ namespace VISU
       }
     } else {
       // Remove aSObject together with all its sub-objects
+
       VISU::RemoveFromStudy(theSObject,
                             false,  // remove not only IOR attribute, but Object With Children
                             false); // not Destroy() sub-objects
@@ -457,13 +462,19 @@ namespace VISU
   ChangeRepresentation (const SalomeApp_Module* theModule,
                         VISU::PresentationType  theType)
   {
-    SUIT_ViewWindow* aView = GetActiveView(theModule, VTKViewer_Viewer::Type());
+    SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
     if (!aView) return;
-    SVTK_ViewWindow* vw  = (SVTK_ViewWindow*) aView;
+    SVTK_ViewWindow* vw  = dynamic_cast<SVTK_ViewWindow*>( aView );
+    if( !vw )
+      return;
 
     Handle(SALOME_InteractiveObject) anIO;
     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
     if (CORBA::is_nil(anObject)) return;
+
+    VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
+    if (CORBA::is_nil(aVisuObj)) return;
+
     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
     if (!aServant.in()) return;
 
@@ -778,6 +789,89 @@ namespace VISU
     QApplication::restoreOverrideCursor();
   }
 
+  static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
+                                      float             allBounds[6], 
+                                      const char*       theActorClassName = "VISU_Actor")
+  {
+    vtkRenderer *aRen = theViewWindow->getRenderer();
+    vtkActorCollection *anActColl = aRen->GetActors(); 
+    vtkProp *prop;
+    float   *bounds;
+    int     somethingVisible = false;
+
+    allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
+    allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
+    // loop through all props
+    for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
+      // if it's invisible, or has no geometry, we can skip the rest 
+      if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
+        bounds = prop->GetBounds();
+        // make sure we haven't got bogus bounds
+        if (bounds != NULL &&
+            bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
+            bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
+            bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
+        {
+         somethingVisible = true;
+         if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
+         if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
+         if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
+         if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
+         if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
+         if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
+        }//not bogus
+      }
+    }
+    return somethingVisible;
+  }
+
+  void SetFitAll(SVTK_ViewWindow* theViewWindow)
+  {
+    static float PRECISION = 0.000001;
+    static float DEVIATION = 600;
+    float XYZ_Bnd[6];
+    if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
+
+    float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
+    float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
+    float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
+
+    enum CameraOrient {e3D, eFront, eLeft, eTop};
+    CameraOrient aCameraOrient = e3D;
+    if (absX <= PRECISION) aCameraOrient = eFront;
+    else {
+      if (absY <= PRECISION) aCameraOrient = eLeft;
+      else {
+        if (absZ <= PRECISION) aCameraOrient = eTop;
+        else {
+          // all the three dimensions exceeds precision
+          float dev_abs_XY = absX / absY;
+          float dev_abs_YZ = absY / absZ;
+          float dev_abs_XZ = absX / absZ;
+          if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
+            aCameraOrient = eLeft;
+          else {
+            if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
+              aCameraOrient = eFront;
+            else {
+              if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
+                aCameraOrient = eTop;
+            }
+          }
+        }
+      }
+    }
+
+    switch (aCameraOrient) {
+    case eFront: theViewWindow->onFrontView(); break;
+    case eLeft:  theViewWindow->onLeftView();  break;
+    case eTop:   theViewWindow->onTopView();   break;
+    case e3D:    theViewWindow->onResetView(); break;
+    }
+    theViewWindow->getRenderer()->ResetCameraClippingRange();
+    theViewWindow->onFitAll();
+  }
+
   //************************************************************
   // Plot2d View
 
@@ -1056,7 +1150,8 @@ namespace VISU
         timer.Start();
 #endif
         PublishInView(theModule, pPresent);
-        aView->onFitAll();
+        //aView->onFitAll();
+        SetFitAll(aView);
 #ifdef CHECKTIME
         timer.Stop();
         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
index 63a767f41f5d341bfdc591d39330bd9afd17fb15..3d6fd0e56892d317e97109da5c4988d6f513d459 100644 (file)
@@ -150,6 +150,17 @@ namespace VISU {
   void                                 RecreateActor(const SalomeApp_Module* theModule,
                                                     VISU::Prs3d_i* thePrs);
 
+  /*!
+   * \brief Advanced FitAll, sets view projection in accordance with current view contents
+   *
+   * If common bounding box of all actors in \a theViewWindow has
+   * at least one small side, then corresponding projection will be set
+   * (Top, Left or Front), else 3D projection will be used.
+   *
+   * \param theViewWindow - the view to perform FitAll in.
+   */
+  void                                 SetFitAll(SVTK_ViewWindow* theViewWindow);
+
   // Plot2d View
   SPlot2d_Viewer*                      GetPlot2dViewer(const SalomeApp_Module* theModule,
                                                       const bool theCreate = false);
index 54c646238bce15bd0c99071480e8aa20a4ab01c7..92e46a57a9d6f8c0e8b5d30b341a912526299ff9 100644 (file)
@@ -926,7 +926,11 @@ namespace VISU {
     void
     Execute()
     {
-      myResult = myApplication->getViewManager(TViewer::Type(), true);
+      myResult = myApplication->getViewManager(TViewer::Type(), false);
+      if (!myResult) {
+       myResult = myApplication->getViewManager(TViewer::Type(), true);
+       myResult->closeAllViews();
+      }
     }
   };