Salome HOME
Merge remote branch 'origin/V7_dev' into V8_0_0_BR
[modules/geom.git] / src / MeasureGUI / MeasureGUI_Skeleton.cxx
index 4e89cddc86f30f77e6bbb3685cdc0b3b9070aa4f..50667f49105a92749ac9589d1f1093b6e73b0d1c 100644 (file)
@@ -1,48 +1,46 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// Copyright (C) 2003-2007  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, or (at your option) any later version.
 //
+// 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   : MeasureGUI_Skeleton.cxx
-//  Author : Damien COQUERET
-//  Module : GEOM
-//  $Header$
 
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : MeasureGUI_Skeleton.cxx
+// Author : Damine COQUERET, Open CASCADE S.A.S.
+//
 #include "MeasureGUI_Skeleton.h"
-#include "GEOMBase.h"
-#include "GEOM_Displayer.h"
-#include "GeometryGUI.h"
+#include "MeasureGUI_Widgets.h"
+
+#include <GEOMBase.h>
+#include <GEOM_Displayer.h>
+#include <GeometryGUI.h>
 
-#include "SalomeApp_Application.h"
-#include "SalomeApp_SelectionMgr.h"
-#include "SalomeApp_Tools.h"
-#include "SUIT_Session.h"
-#include "SUIT_OverrideCursor.h"
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Tools.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Session.h>
+#include <SUIT_OverrideCursor.h>
 
-#include <qlineedit.h>
-#include <qlayout.h>
-#include <qpushbutton.h>
-#include <qradiobutton.h>
-#include <qbuttongroup.h>
-#include <qapplication.h>
+#include <QKeyEvent>
 
 //=================================================================================
 // class    : MeasureGUI_Skeleton()
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI*      GUI,
-                                         QWidget*          parent,
-                                          const char*       name )
-: MeasureGUI_Skeleton_QTD( parent, name, false,
-                          WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
-  GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
-  myGeomGUI( GUI )
+MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI, QWidget* parent,
+                                          bool modal, Qt::WindowFlags f )
+  : QDialog( parent, f ),
+    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
+    myGeomGUI( GUI )
 {
+  myMainFrame = new MeasureGUI_SkeletonBox( this );
+  QVBoxLayout* topLayout = new QVBoxLayout( this );
+  topLayout->setMargin( 9 ); topLayout->setSpacing( 0 );
+  topLayout->addWidget( myMainFrame );
 
+  setAttribute( Qt::WA_DeleteOnClose );
+  setModal( modal );
   mySelBtn = 0;
   mySelEdit = 0;
   myDisplayer = 0;
+  myHelpFileName = "";
   
-  if ( !name )
-    setName( "MeasureGUI_Skeleton" );
-
-  buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
-
-  buttonClose->setAutoDefault( false );
-
-  GroupMedium->close( TRUE );
-  resize( 350, 0 );
+  buttonClose()->setText( tr( "GEOM_BUT_CLOSE" ) );
+  buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
 }
 
 
@@ -82,7 +78,8 @@ MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI*      GUI,
 //=================================================================================
 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
 {
-  myGeomGUI->SetActiveDialogBox( 0 );
+  if ( myGeomGUI )
+    myGeomGUI->SetActiveDialogBox( 0 );
   delete myDisplayer;
 }
 
@@ -94,36 +91,46 @@ MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
 void MeasureGUI_Skeleton::Init()
 {
   /* init variables */
-  myGeomGUI->SetActiveDialogBox((QDialog*)this);
+  if ( myGeomGUI )
+    myGeomGUI->SetActiveDialogBox( (QDialog*)this );
 
   /* signals and slots connections */
   
-  connect( buttonClose, SIGNAL( clicked() ),
-          this,         SLOT( ClickOnCancel() ) );
+  connect( buttonClose(), SIGNAL( clicked() ),
+           this,          SLOT( ClickOnCancel() ) );
+
+  connect( buttonHelp(),  SIGNAL( clicked() ), 
+           this,          SLOT( ClickOnHelp() ) );
   
-  connect( myGeomGUI,   SIGNAL( SignalDeactivateActiveDialog() ),
-           this,        SLOT  ( DeactivateActiveDialog() ) );
-           
-  connect( myGeomGUI,   SIGNAL( SignalCloseAllDialogs() ),
-           this,        SLOT  ( ClickOnCancel() ) );
-
-  connect( mySelEdit,   SIGNAL( returnPressed() ),
-           this,        SLOT( LineEditReturnPressed() ) );
-           
-  connect( mySelBtn,    SIGNAL( clicked() ),
-           this,        SLOT  ( SetEditCurrentArgument() ) );
-
-  SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
-  if ( aSel )
+  if ( myGeomGUI ) {
+    connect( myGeomGUI,   SIGNAL( SignalDeactivateActiveDialog() ),
+             this,        SLOT  ( DeactivateActiveDialog() ) );
+    
+    connect( myGeomGUI,   SIGNAL( SignalCloseAllDialogs() ),
+             this,        SLOT  ( ClickOnCancel() ) );
+  }
+  
+  if ( mySelEdit ) {
+    connect( mySelEdit,   SIGNAL( returnPressed() ),
+             this,        SLOT( LineEditReturnPressed() ) );
+  }
+   
+  if ( mySelBtn ) {
+    connect( mySelBtn,    SIGNAL( clicked() ),
+             this,        SLOT  ( SetEditCurrentArgument() ) );
+  }
+
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
+  if ( aSel ) {
     connect( aSel, SIGNAL( currentSelectionChanged() ), 
-            this, SLOT  ( SelectionIntoArgument() ) ) ;
+             this, SLOT  ( SelectionIntoArgument() ) ) ;
+  }
 
   /* displays Dialog */
-  RadioButton1->setChecked( TRUE );
+  mainFrame()->RadioButton1->setChecked( true );
 
   activateSelection();
   SelectionIntoArgument();
-  show();
 }
 
 
@@ -136,6 +143,28 @@ void MeasureGUI_Skeleton::ClickOnCancel()
   close();
 }
 
+//=================================================================================
+// function : ClickOnHelp()
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::ClickOnHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
+  if ( app ) {
+    app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString( "" ), myHelpFileName );
+  }
+  else {
+    QString platform;
+#ifdef WIN32
+    platform = "winapplication";
+#else
+    platform = "application";
+#endif
+    SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
+                              tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
+                              arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ) );
+  }
+}
 
 //=================================================================================
 // function : LineEditReturnPressed()
@@ -147,11 +176,17 @@ void MeasureGUI_Skeleton::LineEditReturnPressed()
   /* If successfull the selection is changed and signal emitted... */
   /* so SelectionIntoArgument() is automatically called.           */
   
-  const QString objectUserName = mySelEdit->text();
-  QWidget* thisWidget = ( QWidget* )this;
-  
-  if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
-    mySelEdit->setText( objectUserName );
+  if ( mySelEdit ) {
+    const QString objectUserName = mySelEdit->text();
+    QWidget* thisWidget = ( QWidget* )this;
+    
+    LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+    SALOME_ListIO aSelList;
+    aSelMgr->selectedObjects(aSelList);
+
+    if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
+      mySelEdit->setText(objectUserName);
+  }
 }
 
 
@@ -163,7 +198,7 @@ void MeasureGUI_Skeleton::DeactivateActiveDialog()
 {
   setEnabled( false );
   
-  SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
   if ( aSel )
     disconnect( aSel, 0, this, 0 );
   
@@ -185,10 +220,10 @@ void MeasureGUI_Skeleton::ActivateThisDialog()
   
   myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
 
-  SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
   if ( aSel )
     connect( aSel, SIGNAL( currentSelectionChanged() ), 
-            this, SLOT  ( SelectionIntoArgument() ) ) ;
+             this, SLOT  ( SelectionIntoArgument() ) ) ;
   
   redisplayPreview();
   activateSelection();
@@ -210,22 +245,24 @@ void MeasureGUI_Skeleton::SetEditCurrentArgument()
 //=================================================================================
 void MeasureGUI_Skeleton::SelectionIntoArgument()
 {
-  myObj = GEOM::GEOM_Object::_nil();
-  
-  Standard_Boolean testResult = Standard_False;
-  GEOM::GEOM_Object_var aSelectedObject =
-    GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
-  
-  if( !testResult || aSelectedObject->_is_nil() )
-  {
-    mySelEdit->setText( "" );
+  myObj.nullify();
+
+  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+  SALOME_ListIO aSelList;
+  aSelMgr->selectedObjects(aSelList);
+
+  if (aSelList.Extent() > 0) {
+    myObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
+  }
+
+  if ( !myObj ) {
+    mySelEdit->setText("");
     processObject();
     erasePreview();
     return;
   }
 
-  myObj = aSelectedObject;
-  mySelEdit->setText( GEOMBase::GetName( myObj ) );
+  mySelEdit->setText(GEOMBase::GetName(myObj.get()));
   processObject();
   redisplayPreview();
 }
@@ -245,7 +282,7 @@ void MeasureGUI_Skeleton::processObject()
 //=================================================================================
 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
 {
-  SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
   if ( aSel )
     disconnect( aSel, 0, this, 0 );
   QDialog::closeEvent( e );
@@ -255,9 +292,9 @@ void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
 // function : enterEvent()
 // purpose  :
 //=================================================================================
-void MeasureGUI_Skeleton::enterEvent(QEvent* e)
+void MeasureGUI_Skeleton::enterEvent( QEvent* )
 {
-  if ( GroupConstructors->isEnabled() )
+  if ( mainFrame()->GroupConstructors->isEnabled() )
     return;
     
   ActivateThisDialog();
@@ -279,17 +316,15 @@ SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
 void MeasureGUI_Skeleton::redisplayPreview()
 {
   QString aMess;
-  if ( !isValid( aMess ) )
-  {
+  if ( !isValid( aMess ) ) {
     erasePreview( true );
     return;
   }
 
   erasePreview( false );
 
-  try
-  {
-    SUIT_OverrideCursor();
+  try {
+    SUIT_OverrideCursor wc;
 
     getDisplayer()->SetColor( Quantity_NOC_VIOLET );
     getDisplayer()->SetToActivate( false );
@@ -297,8 +332,7 @@ void MeasureGUI_Skeleton::redisplayPreview()
     if ( SALOME_Prs* aPrs = buildPrs() )
       displayPreview( aPrs );
   }
-  catch( const SALOME::SALOME_Exception& e )
-  {
+  catch ( const SALOME::SALOME_Exception& e ) {
     SalomeApp_Tools::QtCatchCorbaException( e );
   }
   
@@ -319,7 +353,7 @@ void MeasureGUI_Skeleton::activateSelection()
 //=================================================================================
 bool MeasureGUI_Skeleton::isValid( QString& )
 {
-  return !myObj->_is_nil();
+  return myObj;
 }
 
 //================================================================
@@ -342,3 +376,38 @@ GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
   return getGeomEngine()->GetIMeasureOperations( getStudyId() );
 }
 
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 ) {
+    e->accept();
+    ClickOnHelp();
+  }
+}
+
+MeasureGUI_SkeletonBox* MeasureGUI_Skeleton::mainFrame() const
+{
+  return myMainFrame;
+}
+
+QWidget* MeasureGUI_Skeleton::centralWidget() const
+{
+  return mainFrame()->GroupMedium;
+}
+
+QPushButton* MeasureGUI_Skeleton::buttonClose() const
+{
+  return mainFrame()->buttonClose;
+}
+
+QPushButton* MeasureGUI_Skeleton::buttonHelp() const
+{
+  return mainFrame()->buttonHelp;
+}