Salome HOME
Copyright update 2022
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
index bf91fef8df998793550c98be49190fbeb5ad1cbc..95086a66061934e0aaaea24cd3d06b28b0c00e09 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -24,7 +24,9 @@
 //  File   : GEOMToolsGUI_1.cxx
 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
 
+#ifndef DISABLE_PYCONSOLE
 #include <PyConsole_Console.h>
+#endif
 
 #include "GEOMToolsGUI.h"
 #include "GEOMToolsGUI_TransparencyDlg.h"
 #include <GEOMBase.h>
 #include <GEOM_Actor.h>
 
+#ifndef DISABLE_GRAPHICSVIEW
 #include <DependencyTree_ViewModel.h>
 #include <DependencyTree_View.h>
 #include <DependencyTree_Selector.h>
-
-#include <Basics_OCCTVersion.hxx>
+#endif
 
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 
 #include <SALOMEDS_SObject.hxx>
 
 #include <SUIT_MessageBox.h>
 #include <SUIT_Tools.h>
 
+#include <STD_TabDesktop.h>
+
+#include <QtxWorkstack.h>
+
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <SalomeApp_Module.h>
@@ -87,7 +92,6 @@
 #include "utilities.h"
 
 // OCCT Includes
-#include <AIS_Drawer.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_ListOfInteractive.hxx>
 
-
-#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
 #include <TColStd_HArray1OfByte.hxx>
-#else
-#include <Graphic3d_HArray1OfBytes.hxx>
-#endif
 
 // QT Includes
 #include <QAction>
+#include <QApplication>
 #include <QColorDialog>
 #include <QInputDialog>
 #include <QFileDialog>
 // VTK includes
 #include <vtkRenderer.h>
 
-class QtxDialog;
 // If the next macro is defined, autocolor feature works for all sub-shapes;
 // if it is undefined, autocolor feature works for groups only
 #define GENERAL_AUTOCOLOR
 // Below macro, when uncommented, switches on simplified (more performant) algorithm
 // of auto-color picking up
 #define SIMPLE_AUTOCOLOR
+// Below macro, when defined, switches on automatic layouting of OCC and Dependency views
+// on Show Dependencies operation
+#define LAYOUT_DEPVIEW
 
+#ifndef DISABLE_PYCONSOLE
 void GEOMToolsGUI::OnCheckGeometry()
 {
   SalomeApp_Application* app =
@@ -135,6 +138,7 @@ void GEOMToolsGUI::OnCheckGeometry()
   if (pyConsole)
     pyConsole->exec("from GEOM_usinggeom import *");
 }
+#endif
 
 void GEOMToolsGUI::OnAutoColor()
 {
@@ -156,13 +160,13 @@ void GEOMToolsGUI::OnAutoColor()
   _PTR(Study) aStudy = appStudy->studyDS();
   _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
   GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
-  if (CORBA::is_nil(aMainObject)) return;
+  if (CORBA::is_nil(aMainObject) || !GeometryGUI::IsInGeomComponent( aMainSObject )) return;
 
   aMainObject->SetAutoColor( true );
 
   QList<SALOMEDS::Color> aReservedColors;
 
-  GEOM_Displayer displayer ( appStudy );
+  GEOM_Displayer displayer;
 
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -191,9 +195,9 @@ void GEOMToolsGUI::OnAutoColor()
   
     QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
 
-    SUIT_OverrideCursor();
+    SUIT_OverrideCursor wc;
     
-    appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
+    appStudy->setObjectProperty( aMgrId, aChildObject->GetStudyEntry(), GEOM::propertyName( GEOM::Color ), c );
     Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
   }
@@ -225,7 +229,7 @@ void GEOMToolsGUI::OnDisableAutoColor()
   _PTR(Study) aStudy = appStudy->studyDS();
   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
   GEOM::GEOM_Object_var aMainObject =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
-  if( CORBA::is_nil( aMainObject ) )
+  if( CORBA::is_nil( aMainObject ) || !GeometryGUI::IsInGeomComponent( aMainSObject ))
     return;
 
   aMainObject->SetAutoColor( false );
@@ -250,7 +254,7 @@ void GEOMToolsGUI::OnColor()
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
 
   // get active view
   SALOME_View* window = displayer.GetActiveView();
@@ -266,10 +270,17 @@ void GEOMToolsGUI::OnColor()
   color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
   if ( !color.isValid() ) return;
 
+  SALOMEDS::Color aSColor;
+  aSColor.R = (double)color.red() / 255.0;
+  aSColor.G = (double)color.green() / 255.0;
+  aSColor.B = (double)color.blue() / 255.0;
+
   // iterate through list of objects and assign new color
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
     Handle( SALOME_InteractiveObject ) io = It.Value();
+    GEOM::GEOM_Object_var aObject = GEOMBase::ConvertIOinGEOMObject( io );
+    if ( !CORBA::is_nil( aObject ) ) aObject->SetColor( aSColor );
     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
   }
@@ -295,7 +306,7 @@ void GEOMToolsGUI::OnTexture()
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
 
@@ -338,7 +349,7 @@ void GEOMToolsGUI::OnChangeTransparency( bool increase )
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
 
@@ -383,7 +394,7 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType )
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
  
@@ -410,7 +421,7 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType )
     NbIsosDlg->setV( VIso );
 
     if ( NbIsosDlg->exec() ) {
-      SUIT_OverrideCursor();     
+      SUIT_OverrideCursor wc;     
       newNbUIso = NbIsosDlg->getU();
       newNbVIso = NbIsosDlg->getV();
     } else //Cancel case
@@ -453,20 +464,20 @@ void GEOMToolsGUI::OnDeflection()
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
 
   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
 
   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
-  double aDC =  v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
+  double aDC =  v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coeff", 0.001 );
 
   GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
     ( SUIT_Session::session()->activeApplication()->desktop() );
   DeflectionDlg->setTheDC( aDC );
   if ( DeflectionDlg->exec() ) {
-    SUIT_OverrideCursor();
+    SUIT_OverrideCursor wc;
     aDC = DeflectionDlg->getTheDC();
 
     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
@@ -483,8 +494,7 @@ void GEOMToolsGUI::OnSelectOnly(int mode)
 {
   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
   if ( app ) {
-    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-    GEOM_Displayer aDisp (appStudy);
+    GEOM_Displayer aDisp;
     aDisp.GlobalSelection(mode);
     getGeometryGUI()->setLocalSelectionMode(mode);
   }
@@ -517,6 +527,8 @@ void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
           return;
         }
 
+        SUIT_OverrideCursor wc;
+        bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
           Handle(SALOME_InteractiveObject) IObject = It.Value();
 
@@ -525,10 +537,12 @@ void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
           if ( obj ) {
             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
             aExp->SetExpandable( show );
-            if(!show)
+            if ( !show ) {
               disp->EraseWithChildren(IObject,true);
+            }
           } // if ( obj )
         } // iterator
+        disp->SetUpdateColorScale( toUpdateColorScale );
       }
     }
     app->updateObjectBrowser( false );
@@ -580,7 +594,8 @@ void GEOMToolsGUI::OnUnpublishObject() {
                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
           return;
         }
-
+        SUIT_OverrideCursor wc;
+        bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
           Handle(SALOME_InteractiveObject) IObject = It.Value();
 
@@ -590,15 +605,22 @@ void GEOMToolsGUI::OnUnpublishObject() {
             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
             aDrw->SetDrawable( false );
             disp->EraseWithChildren(IObject);
+            // hide references if any
+            std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
+            for ( int i = 0; i < (int)vso.size(); i++ ) {
+              _PTR(SObject) refObj = vso[i];
+              aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
+              aDrw->SetDrawable( false );
+            }
           } // if ( obj )
         } // iterator
+        disp->SetUpdateColorScale( toUpdateColorScale ); // IPAL54049
         aSelMgr->clearSelected();
       }
     }
     app->updateObjectBrowser( false );
     app->updateActions();
   }
 }
 
 void GEOMToolsGUI::OnPublishObject() {
@@ -645,7 +667,7 @@ void GEOMToolsGUI::OnEdgeWidth()
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
 
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -660,7 +682,7 @@ void GEOMToolsGUI::OnEdgeWidth()
 
   Dlg->setTheLW( aWidth );
   if ( Dlg->exec() ) {
-    SUIT_OverrideCursor();
+    SUIT_OverrideCursor wc;
     aWidth = Dlg->getTheLW();
   } else
     return; //Cancel case
@@ -688,7 +710,7 @@ void GEOMToolsGUI::OnIsosWidth() {
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
 
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -703,7 +725,7 @@ void GEOMToolsGUI::OnIsosWidth() {
 
   Dlg->setTheLW( aWidth );
   if ( Dlg->exec() ) {
-    SUIT_OverrideCursor();
+    SUIT_OverrideCursor wc;
     aWidth = Dlg->getTheLW();
   } else
     return; //Cancel case
@@ -730,7 +752,7 @@ void GEOMToolsGUI::OnBringToFront() {
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
 
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -756,7 +778,7 @@ void GEOMToolsGUI::OnClsBringToFront() {
   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
   if ( !appStudy ) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
 
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -795,7 +817,7 @@ void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
 
   if ( selected.IsEmpty() ) return;
   
-  GEOM_Displayer displayer( study );
+  GEOM_Displayer displayer;
 
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -836,8 +858,8 @@ void GEOMToolsGUI::OnCreateFolder()
   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
   if ( !aFatherSO ) return;
 
-  GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(), 
-                                          _CAST(SObject, aFatherSO)->GetSObject() );
+  GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toUtf8().constData(), 
+                                           _CAST(SObject, aFatherSO)->GetSObject() );
   app->updateObjectBrowser( false );
 }
 
@@ -868,59 +890,62 @@ void GEOMToolsGUI::OnSortChildren()
   app->updateObjectBrowser( true );
 }
 
+#ifndef DISABLE_GRAPHICSVIEW
 void GEOMToolsGUI::OnShowDependencyTree()
 {
-  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+  //SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
 
   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
   if ( !app ) return;
 
-  SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
+#ifdef LAYOUT_DEPVIEW
+  SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
+  SUIT_ViewWindow* occVw = occVm->getActiveView();
+#endif
+  SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
+  SUIT_ViewWindow* depVw = 0;
 
-  if( !svm ) {
+  if ( !depVm ) {
     DependencyTree_View* view = new DependencyTree_View();
     DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
-    SUIT_ViewManager *svm = app->createViewManager( viewModel );
+    depVm = app->createViewManager( viewModel );
 
     LightApp_SelectionMgr* selMgr = app->selectionMgr();
     new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
 
-    SUIT_ViewWindow* svw = svm->getActiveView();
+    depVw = depVm->getActiveView();
     GraphicsView_ViewFrame* aViewFrame = 0;
-    if (!svw) svw = svm->createViewWindow();
-    if (svw) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>(svw);
+    if ( !depVw ) depVw = depVm->createViewWindow();
+    if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
 
     view->init( aViewFrame );
-    svm->setTitle( view->getViewName() );
+    depVm->setTitle( view->getViewName() );
   }
-  else
-    if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
-      if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
-        svm->getActiveView()->setFocus();
-        view->updateModel();
-      }
+  else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
+    if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
+      depVw = depVm->getActiveView();
+      view->updateModel();
+    }
+  }
+
+#ifdef LAYOUT_DEPVIEW
+  // layout views properly
+  STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
+  if ( d && depVw && occVw ) {
+    QtxWorkstack* ws = d->workstack();
+    ws->stack();
+    QApplication::instance()->processEvents();
+    ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
+    occVw->setFocus();
+  }
+#endif
+  depVw->setFocus();
 }
+#endif
 
 void GEOMToolsGUI::OnReduceStudy()
 {
-  GEOM::string_array_var objectsEntry = new GEOM::string_array();
-  SALOME_ListIO mainObjects;
-  int iter = 0;
-
-  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( !app ) return;
-  app->selectionMgr()->selectedObjects( mainObjects );
-  // create a list of selected object entry
-  objectsEntry->length( mainObjects.Extent() );
-  for ( SALOME_ListIteratorOfListIO It( mainObjects ); It.More(); It.Next(), iter++ ) {
-    Handle( SALOME_InteractiveObject ) io = It.Value();
-    if( !io->hasEntry() )
-      continue;
-    GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
-    geomObject = GEOMBase::ConvertIOinGEOMObject( io );
-    QString entry = geomObject->GetEntry();
-    objectsEntry[ iter ] = entry.toLatin1().constData();
-  }
-  GEOMToolsGUI_ReduceStudyDlg dlg( objectsEntry, SUIT_Session::session()->activeApplication()->desktop() );
-  dlg.exec();
+  QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );
+  if( dlg != NULL )
+    dlg->show();
 }