Salome HOME
Merge from BR_Dev_For_4_0 branch (from tag mergeto_BR_QT4_Dev_17Jan08)
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
index a258dccc159d36a69a6d14c001e9ffb51581799a..2be9e4c79c3337620eb53591fdb0b2c26a5f1e00 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 // File   : GEOMToolsGUI_1.cxx
-// Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
+// Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
 //
 
 #include <PyConsole_Console.h>
 
 #include "GEOMToolsGUI.h"
+#include "GEOMToolsGUI_TransparencyDlg.h"
+#include "GEOMToolsGUI_NbIsosDlg.h"
 
 #include <GeometryGUI.h>
 #include <GEOM_Displayer.h>
-#include "GEOMToolsGUI_TransparencyDlg.h"
-#include "GEOMToolsGUI_NbIsosDlg.h"        // Method ISOS adjustement
 
 #include <GEOMBase.h>
+#include <GEOM_Actor.h>
 
 #include <SALOME_ListIO.hxx>
 #include <SALOME_ListIteratorOfListIO.hxx>
 
+#include <SOCC_Prs.h>
+
+#include <SVTK_Prs.h>
 #include <SVTK_ViewModel.h>
 #include <SVTK_ViewWindow.h>
 #include <SVTK_View.h>
@@ -57,6 +61,8 @@
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_NameDlg.h>
 
+#include <GEOMImpl_Types.hxx>
+
 #include "utilities.h"
 
 // OCCT Includes
 
 // QT Includes
 #include <QColorDialog>
+#include <QList>
 
-using namespace std;
-
+// VTK includes
+#include <vtkRenderer.h>
 
 void GEOMToolsGUI::OnSettingsColor()
 {
@@ -90,66 +97,6 @@ void GEOMToolsGUI::OnSettingsColor()
   }
 }
 
-void GEOMToolsGUI::OnSettingsIsos()
-{
-/*
-  SUIT_Session* sess = SUIT_Session::session();
-  SUIT_ResourceMgr* resMgr = sess->resourceMgr();
-  SUIT_Desktop* desk = sess->activeApplication()->desktop();
-
-  SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
-  QString type = vman->getType();
-
-  if ( type != OCCViewer_Viewer::Type() )
-    return;
-
-  OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
-  Handle (AIS_InteractiveContext) ic = vm->getAISContext();
-
-  int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
-  int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
-
-  ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
-  ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
-
-  GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
-
-  NbIsosDlg->SpinBoxU->setValue(IsoU);
-  NbIsosDlg->SpinBoxV->setValue(IsoV);
-
-  if(NbIsosDlg->exec()) {
-    IsoU = NbIsosDlg->SpinBoxU->text().toInt();
-    IsoV = NbIsosDlg->SpinBoxV->text().toInt();
-
-    ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
-    ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
-    resMgr->setValue("Geometry:SettingsIsoU", isoU);
-    resMgr->setValue("Geometry:SettingsIsoV", isoV);
-  }
-*/
-}
-
-void GEOMToolsGUI::OnSettingsStep()
-{
-  SUIT_Session* sess = SUIT_Session::session();
-  SUIT_ResourceMgr* resMgr = sess->resourceMgr();
-
-  double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
-
-  Standard_Boolean res = false;
-  double dd = GEOMBase::Parameter( res, QString("%1").arg(step).toLatin1().constData(), 
-                                  tr("GEOM_MEN_STEP_LABEL").toLatin1().constData(), 
-                                  tr("GEOM_STEP_TITLE").toLatin1().constData(), 0.001, 10000.0, 3);
-  if(res) {
-    resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
-
-    /* Emit signal to GeometryGUI_SpinBoxes */
-    getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
-  }
-  else
-    sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
-}
-
 void GEOMToolsGUI::OnRename()
 {
   SALOME_ListIO selected;
@@ -209,11 +156,147 @@ void GEOMToolsGUI::OnCheckGeometry()
     pyConsole->exec("from GEOM_usinggeom import *");
 }
 
+void GEOMToolsGUI::OnAutoColor()
+{
+  QList<SALOME_Prs> aListOfGroups;
+
+  SALOME_ListIO selected;
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if( !app )
+    return;
+
+  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if( !aSelMgr || !appStudy )
+    return;
+
+  aSelMgr->selectedObjects( selected );
+  if( selected.IsEmpty() )
+    return;
+
+  Handle(SALOME_InteractiveObject) anIObject = selected.First();
+
+  _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;
+
+  aMainObject->SetAutoColor( true );
+
+  QList<SALOMEDS::Color> aReservedColors;
+
+  GEOM_Displayer aDisp (appStudy);
+
+  SALOME_View* vf = aDisp.GetActiveView();
+
+  SUIT_ViewWindow* window = app->desktop()->activeWindow();
+  bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
+  bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
+
+  for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
+  {
+    _PTR(SObject) aChildSObject( it->Value() );
+    GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
+    if( CORBA::is_nil( aChildObject ) )
+      continue;
+
+    if( aChildObject->GetType() != GEOM_GROUP )
+      continue;
+
+    SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
+    aChildObject->SetColor( aColor );
+    aReservedColors.append( aColor );
+
+    QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
+
+    SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
+
+    if ( isVTK )
+    {
+      SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
+      if ( !vtkVW )
+       return;
+      SVTK_View* aView = vtkVW->getView();
+      SUIT_OverrideCursor();
+      for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
+       aView->SetColor( It.Value(), c );
+    }
+    else if ( isOCC )
+    {
+      OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
+      Handle(AIS_InteractiveContext) ic = vm->getAISContext();
+
+      SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
+      if( !anOCCPrs )
+       continue;
+
+      AIS_ListOfInteractive aList;
+      anOCCPrs->GetObjects( aList );
+      if( !aList.Extent() )
+       continue;
+
+      Handle(AIS_InteractiveObject) io = aList.First();
+      if( io.IsNull() )
+       continue;
+
+      Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
+
+      // Set color for a point
+      Handle(AIS_Drawer) aCurDrawer = io->Attributes();
+      Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
+      Quantity_Color aCurColor;
+      Standard_Real aCurScale;
+      Aspect_TypeOfMarker aCurTypeOfMarker;
+      aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
+      aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
+      ic->SetLocalAttributes( io, aCurDrawer );
+
+      io->SetColor( aQuanColor );
+      if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
+       Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
+
+      io->Redisplay( Standard_True );
+    }
+  }
+
+  app->updateActions(); //SRN: To update a Save button in the toolbar
+}
+
+void GEOMToolsGUI::OnDisableAutoColor()
+{
+  SALOME_ListIO selected;
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if( !app )
+    return;
+
+  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if( !aSelMgr || !appStudy )
+    return;
+
+  aSelMgr->selectedObjects( selected );
+  if( selected.IsEmpty() )
+    return;
+
+  Handle(SALOME_InteractiveObject) anIObject = selected.First();
+
+  _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;
+
+  aMainObject->SetAutoColor( false );
+
+}
+
 void GEOMToolsGUI::OnColor()
 {
   SALOME_ListIO selected;
   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( app ) {
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if ( app && appStudy ) {
     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
     if ( aSelMgr ) {
       aSelMgr->selectedObjects( selected );
@@ -227,7 +310,7 @@ void GEOMToolsGUI::OnColor()
            return;
          SVTK_View* aView = vtkVW->getView();
          QColor initcolor = aView->GetColor( selected.First()  );
-         QColor c = QColorDialog::getColor( QColor(), app->desktop() );
+         QColor c = QColorDialog::getColor( initcolor, app->desktop() );
          if ( c.isValid() ) {
            SUIT_OverrideCursor();
            for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
@@ -265,6 +348,19 @@ void GEOMToolsGUI::OnColor()
                    Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
 
                  io->Redisplay( Standard_True );
+
+                 // store color to GEOM_Object
+                 _PTR(Study) aStudy = appStudy->studyDS();
+                 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
+                 GEOM::GEOM_Object_var anObject =
+                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
+
+                 SALOMEDS::Color aSColor;
+                 aSColor.R = (double)c.red() / 255.0;
+                 aSColor.G = (double)c.green() / 255.0;
+                 aSColor.B = (double)c.blue() / 255.0;
+                 anObject->SetColor( aSColor );
+                 anObject->SetAutoColor( false );
                }
              }
            } // if c.isValid()
@@ -286,22 +382,84 @@ void GEOMToolsGUI::OnTransparency()
 void GEOMToolsGUI::OnNbIsos()
 {
   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
+  
   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
-
-  if ( !isOCC )
-    return;
-
-  OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
-  Handle (AIS_InteractiveContext) ic = vm->getAISContext();
-
-  ic->InitCurrent();
-  if ( ic->MoreCurrent() ) {
-    Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
-    Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
-
-    int UIso = CurDrawer->UIsoAspect()->Number();
-    int VIso = CurDrawer->VIsoAspect()->Number();
-
+  bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
+
+  if(isOCC){ // if is OCCViewer
+
+    OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
+    Handle (AIS_InteractiveContext) ic = vm->getAISContext();
+
+    ic->InitCurrent();
+    if ( ic->MoreCurrent() ) {
+      Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
+      Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
+      
+      int UIso = CurDrawer->UIsoAspect()->Number();
+      int VIso = CurDrawer->VIsoAspect()->Number();
+      
+      GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
+       new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
+      
+      NbIsosDlg->setU( UIso );
+      NbIsosDlg->setV( VIso );
+      
+      if ( NbIsosDlg->exec() ) {
+       SUIT_OverrideCursor();
+       for(; ic->MoreCurrent(); ic->NextCurrent()) {
+         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
+         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
+         
+         int nbUIso = NbIsosDlg->getU();
+         int nbVIso = NbIsosDlg->getV();
+         
+         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
+         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
+         
+         ic->SetLocalAttributes(CurObject, CurDrawer);
+         ic->Redisplay(CurObject);
+       }
+      }
+    }
+  }
+  else if(isVTK){ // if is VTKViewer
+    //
+    // Warning. It's works incorrect. must be recheked.
+    //
+    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+    if ( !app )
+      return;
+    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+    if ( !aSelMgr )
+      return;
+    SALOME_ListIO selected;
+    aSelMgr->selectedObjects( selected );
+    if ( selected.IsEmpty() )
+      return;
+    
+    Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
+    if ( FirstIOS.IsNull() )
+      return;
+    
+    SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
+    if ( !vtkVW )
+      return;
+    
+    SVTK_View* aView = vtkVW->getView();
+    vtkActorCollection* aCollection = aView->getRenderer()->GetActors();
+    
+    int UIso = 0;
+    int VIso = 0;
+    if(aCollection){
+      aCollection->InitTraversal();
+    }
+    
+    vtkActor *anAct = aCollection->GetNextActor();
+    if(GEOM_Actor *anActor = dynamic_cast<GEOM_Actor*>(anAct)){
+      anActor->GetNbIsos(UIso,VIso);
+    }
+    
     GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
       new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
 
@@ -310,21 +468,18 @@ void GEOMToolsGUI::OnNbIsos()
 
     if ( NbIsosDlg->exec() ) {
       SUIT_OverrideCursor();
-      for(; ic->MoreCurrent(); ic->NextCurrent()) {
-        CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
-       Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
-
-       int nbUIso = NbIsosDlg->getU();
-       int nbVIso = NbIsosDlg->getV();
-
-       CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
-       CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
-
-       ic->SetLocalAttributes(CurObject, CurDrawer);
-       ic->Redisplay(CurObject);
+      
+      while(anAct = aCollection->GetNextActor()) {
+       if(GEOM_Actor *anActor = dynamic_cast<GEOM_Actor*>(anAct)){
+         // There are no casting to needed actor.
+         UIso = NbIsosDlg->getU();
+         VIso = NbIsosDlg->getV();
+         int aIsos[2]={UIso,VIso};
+         anActor->SetNbIsos(aIsos);
+       }
       }
     }
-  }
+  } // end vtkviewer
 }
 
 void GEOMToolsGUI::OnOpen()