Salome HOME
Merging with WPdev
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
index 1f455c67ba2458457a9de49b32736a34621ef44e..94c92abfc2b8f69d2ca66a6a52d4a3748b693f1d 100644 (file)
@@ -1,47 +1,51 @@
 //  GEOM GEOMGUI : GUI for Geometry component
 //
 //  Copyright (C) 2004  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 //
-//            
 //
 //  File   : GEOMToolsGUI_1.cxx
 //  Author : Sergey ANIKIN
 //  Module : GEOM
 //  $Header$
 
+#include <PythonConsole_PyConsole.h>
+
 #include "GEOMToolsGUI.h"
+
 #include "GeometryGUI.h"
-#include "GEOM_Actor.h"
-#include "GEOMBase.h"
 #include "GEOMToolsGUI_TransparencyDlg.h"
 #include "GEOMToolsGUI_NbIsosDlg.h"        // Method ISOS adjustement
 
-#include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
+#include "GEOM_Actor.h"
+#include "GEOMBase.h"
 
-#include <VTKViewer_ViewModel.h>
-#include <OCCViewer_ViewModel.h>
-#include <OCCViewer_ViewWindow.h>
+#include "SALOME_ListIO.hxx"
+#include "SALOME_ListIteratorOfListIO.hxx"
 
+#include <SVTK_ViewModel.h>
 #include <SVTK_ViewWindow.h>
-#include <SVTK_RenderWindowInteractor.h>
+#include <SVTK_View.h>
+
+#include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewWindow.h>
 
 #include <SUIT_ViewManager.h>
 #include <SUIT_Application.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
 #include <SUIT_OverrideCursor.h>
+#include <SUIT_MessageBox.h>
 
 #include <SalomeApp_Application.h>
-#include <SalomeApp_SelectionMgr.h>
+#include <SalomeApp_Study.h>
+#include <SalomeApp_Module.h>
+
+#include <LightApp_SelectionMgr.h>
+#include <LightApp_NameDlg.h>
+
+#include "SALOMEDSClient.hxx"
+
+#include "utilities.h"
 
+// OCCT Includes
 #include <AIS_Drawer.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <Prs3d_IsoAspect.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
 
+// VTK Includes
 #include <vtkBMPReader.h>
 #include <vtkTexture.h>
 #include <vtkTextureMapToPlane.h>
 #include <vtkDataSetMapper.h>
 #include <vtkRenderer.h>
 
+// QT Includes
 #include <qfileinfo.h>
 #include <qcolordialog.h>
 #include <qspinbox.h>
 #include <qapplication.h>
 
-#include "utilities.h"
-
 using namespace std;
 
-#include "SALOMEDSClient.hxx"
-#include "SALOMEDS_Study.hxx"
-
-
 
 void GEOMToolsGUI::OnSettingsColor()
 {
@@ -85,16 +97,16 @@ void GEOMToolsGUI::OnSettingsColor()
   SUIT_ResourceMgr* resMgr = sess->resourceMgr();
   SUIT_Desktop* desk = sess->activeApplication()->desktop();
 
-  QColor anInitColor = resMgr->colorValue( "Geometry:SettingsShadingColor", QColor( "yellow" ) );
-  
+  QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
+
   QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
-  if( aDialogColor.isValid() ) 
+  if( aDialogColor.isValid() )
   {
     QString type = desk->activeWindow()->getViewManager()->getType();
-    if( type != OCCViewer_Viewer::Type() && type != VTKViewer_Viewer::Type() )
+    if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
       MESSAGE("Settings Color is not supported for current Viewer");
-    
-    resMgr->setValue( "Geometry:SettingsShadingColor", aDialogColor );
+
+    resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
   }
 }
 
@@ -110,25 +122,25 @@ void GEOMToolsGUI::OnSettingsIsos()
 
   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);     
-  
+
+  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);
@@ -142,13 +154,13 @@ void GEOMToolsGUI::OnSettingsStep()
   SUIT_Session* sess = SUIT_Session::session();
   SUIT_ResourceMgr* resMgr = sess->resourceMgr();
 
-  double step = resMgr->doubleValue( "Geometry:SettingsGeomStep", 100. );
-  
+  double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
+
   Standard_Boolean res = false;
-  double dd = GEOMBase::Parameter(res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
+  double dd = GEOMBase::Parameter( res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
   if(res) {
-    resMgr->setValue( "Geometry:SettingsGeomStep", dd );
-    
+    resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
+
     /* Emit signal to GeometryGUI_SpinBoxes */
     getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
   }
@@ -158,81 +170,57 @@ void GEOMToolsGUI::OnSettingsStep()
 
 void GEOMToolsGUI::OnRename()
 {
-/*
-  SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
-  _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
-  
-  bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
-  if ( aLocked ) {
-    QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
-                           QObject::tr("WRN_WARNING"), 
-                           QObject::tr("WRN_STUDY_LOCKED"),
-                           QObject::tr("BUT_OK") );
-    return;
-  }
-  
-  SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
-  for(; It.More(); It.Next()) {
-    Handle(SALOME_InteractiveObject) IObject = It.Value();
-    
-    _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
-    _PTR(GenericAttribute) anAttr;
-    if(obj) {
-      if(obj->FindAttribute(anAttr, "AttributeName")) {
-       _PTR(AttributeName) aName (anAttr);
-       
-       QString nm = QString(aName->Value().c_str());
-       nm = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), nm);
-       if(!nm.isEmpty()) {
-         QApplication::setOverrideCursor(Qt::waitCursor);
-         QAD_Application::getDesktop()->getActiveStudy()->renameIObject(IObject, nm);
-         QApplication::restoreOverrideCursor();
+  SALOME_ListIO selected;
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if ( app ) {
+    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+    if ( aSelMgr && appStudy ) {
+      aSelMgr->selectedObjects( selected );
+      if ( !selected.IsEmpty() ) {
+       _PTR(Study) aStudy = appStudy->studyDS();
+
+       bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
+       if ( aLocked ) {
+         SUIT_MessageBox::warn1 ( app->desktop(),
+                                  QObject::tr("WRN_WARNING"),
+                                  QObject::tr("WRN_STUDY_LOCKED"),
+                                  QObject::tr("BUT_OK") );
+         return;
        }
+
+       for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
+         Handle(SALOME_InteractiveObject) IObject = It.Value();
+
+         _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
+         _PTR(GenericAttribute) anAttr;
+         if ( obj ) {
+           if( obj->FindAttribute(anAttr, "AttributeName") ) {
+             _PTR(AttributeName) aName (anAttr);
+
+             QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
+             if ( !newName.isEmpty() ) {
+               aName->SetValue( newName.latin1() ); // rename the SObject
+               IObject->setName( newName.latin1() );// rename the InteractiveObject
+               (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
+             }
+           } // if ( name attribute )
+         } // if ( obj )
+       } // iterator
       }
     }
   }
-*/
+  
+  app->updateActions(); //SRN: To update a Save button in the toolbar
 }
 
 void GEOMToolsGUI::OnCheckGeometry()
 {
-/*
-  QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
-  PyEditor->setText("from GEOM_usinggeom import *\n");
-  PyEditor->handleReturn();
-*/
-}
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  PythonConsole* pyConsole = app->pythonConsole();
 
-void GEOMToolsGUI::OnLoadScript()
-{
-/*
-  _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
-  bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties())->IsLocked();
-  if ( aLocked ) {
-    QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
-                           QObject::tr("WRN_WARNING"), 
-                           QObject::tr("WRN_STUDY_LOCKED"),
-                           QObject::tr("BUT_OK") );
-    return;
-  }
-  
-  QStringList filtersList;
-  filtersList.append(tr("GEOM_MEN_LOAD_SCRIPT"));
-  filtersList.append(tr("GEOM_MEN_ALL_FILES"));
-  
-  QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
-  if(!aFile.isEmpty()) {
-    QFileInfo file = aFile;
-    QApplication::setOverrideCursor(Qt::waitCursor);
-    QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
-    
-    QStringList aTextList = QStringList::split(".", file.fileName());
-    
-    PyEditor->setText("import geompy; geompy.addPath('" + file.dirPath() + "'); from " + aTextList.first() + " import *\n" );
-    PyEditor->handleReturn();
-  }
-  QApplication::restoreOverrideCursor();
-*/
+  if(pyConsole)
+    pyConsole->exec("from GEOM_usinggeom import *");
 }
 
 void GEOMToolsGUI::OnColor()
@@ -240,24 +228,24 @@ void GEOMToolsGUI::OnColor()
   SALOME_ListIO selected;
   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
   if ( app ) {
-    SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
+    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
     if ( aSelMgr ) {
       aSelMgr->selectedObjects( selected );
       if ( !selected.IsEmpty() ) {
        SUIT_ViewWindow* window = app->desktop()->activeWindow();
        bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
-       bool isVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
+       bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
        if ( isVTK ) {
          SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
          if ( !vtkVW )
            return;
-         SVTK_RenderWindowInteractor* rwi = vtkVW->getRWInteractor();
-         QColor initcolor = rwi->GetColor( selected.First()  );
+         SVTK_View* aView = vtkVW->getView();
+         QColor initcolor = aView->GetColor( selected.First()  );
          QColor c = QColorDialog::getColor( QColor(), app->desktop() );
          if ( c.isValid() ) {
            SUIT_OverrideCursor();
            for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
-             rwi->SetColor( It.Value(), c );
+             aView->SetColor( It.Value(), c );
            }
          }
        } // if ( isVTK )
@@ -274,6 +262,18 @@ void GEOMToolsGUI::OnColor()
              for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
                io = GEOMBase::GetAIS( It.Value(), true );
                if ( !io.IsNull() ) {
+                 // Set color for a point
+                 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
+                 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
+                 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, aColor, aCurScale) );
+                 ic->SetLocalAttributes(io, aCurDrawer);
+                 
                  io->SetColor( aColor );
                  if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
                    Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
@@ -287,6 +287,8 @@ void GEOMToolsGUI::OnColor()
       } // if ( selection not empty )
     }
   }
+  
+  app->updateActions(); //SRN: To update a Save button in the toolbar
 }
 
 void GEOMToolsGUI::OnTransparency()
@@ -302,36 +304,36 @@ void GEOMToolsGUI::OnNbIsos()
 
   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();
-    
+
     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);
       }
@@ -363,12 +365,12 @@ void GEOMToolsGUI::OnOpen()
          useSubItems = true;
          obj =  subobj;
        }
-       else 
+       else
          anIter->Next();
       }
       obj->FindAttribute(anAttr, "AttributePersistentRef");
-             
-      while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
+
+      while(useSubItems?anIter->More():!anAttr->_is_nil()) {
        if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
           obj->FindAttribute(anAttr, "AttributePersistentRef")) {
          _PTR(SComponent) FComp ( obj->GetFatherComponent() );
@@ -396,7 +398,7 @@ void GEOMToolsGUI::OnOpen()
                  } else {
                    return;
                  }
-               } 
+               }
                else {
                  MESSAGE("loadComponentData(): Driver is null");
                  return;
@@ -414,7 +416,7 @@ void GEOMToolsGUI::OnOpen()
                //                SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
                //                if (!CORBA::is_nil(SC))
                //                  aStudyBuilder->LoadWith(SC,driver);
-           } 
+           }
          }
          else {
            MESSAGE("Component is null");
@@ -423,8 +425,8 @@ void GEOMToolsGUI::OnOpen()
        if(useSubItems) {
          anIter->Next();
          obj.reset( anIter->Value() );
-       } 
-       else 
+       }
+       else
          anAttr = NULL;
       }
     }