Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / RepairGUI / RepairGUI_FreeBoundDlg.cxx
index 2231ad6b395de2fadb98f7f76a0814beb7f32800..f20e0413021165c2abbc4bb0fb3f684bd6a7aed3 100644 (file)
@@ -1,53 +1,56 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+//  Copyright (C) 2007-2008  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  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.
 //
+//  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
+//
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : RepairGUI_FreeBoundDlg.cxx
+// Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
 //
-//  File   : RepairGUI_FreeBoundDlg.cxx
-//  Author : Sergey LITONIN
-//  Module : GEOM
-//  $Header$
-
 #include "RepairGUI_FreeBoundDlg.h"
-#include "GEOMBase.h"
-#include "GeometryGUI.h"
-#include "GEOM_Displayer.h"
-#include "GEOMImpl_Types.hxx"
 
-#include "SalomeApp_Application.h"
-#include "LightApp_Application.h"
-#include "LightApp_SelectionMgr.h"
-#include "SUIT_MessageBox.h"
-#include "SUIT_Session.h"
+#include <GEOMBase.h>
+#include <GeometryGUI.h>
+#include <GEOM_Displayer.h>
+#include <GEOMImpl_Types.hxx>
+
+#include <SalomeApp_Application.h>
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
 
 #include <TColStd_MapOfInteger.hxx>
 
-#include <qlineedit.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <qgroupbox.h>
-#include <qpushbutton.h>
+#include <QLineEdit>
+#include <QLabel>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QKeyEvent>
 
-#define SPACING 5
-#define MARGIN 10
+#define SPACING 6
+#define MARGIN  9
 
 /*!
   Class       : RepairGUI_FreeBoundDlg
 // function : RepairGUI_FreeBoundDlg
 // purpose  : Constructor
 //=================================================================================
-RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg(GeometryGUI* theGUI, QWidget* theParent, const char*)
-: QDialog( theParent, "RepairGUI_FreeBoundDlg", false,
-          WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
-  GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( theParent ) ),
-  myGeomGUI( theGUI )
+RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg( GeometryGUI* theGUI, QWidget* theParent )
+  : QDialog( theParent, false ),
+    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( theParent ) ),
+    myGeomGUI( theGUI )
 {
-  setCaption( tr( "CAPTION" ) );
+  setAttribute( Qt::WA_DeleteOnClose );
+
+  setWindowTitle( tr( "CAPTION" ) );
 
-  QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
+  QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
   
-  QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FREE_BOUND" ), this );
+  QGroupBox* aMainGrp = new QGroupBox( tr( "FREE_BOUND" ), this );
   
-  QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
-  aSelGrp->setInsideMargin( 0 );
-  aSelGrp->setFrameStyle( QFrame::NoFrame );
-  new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
-  ( new QPushButton( aSelGrp ) )->setPixmap( iconSelect );
-  myEdit = new QLineEdit( aSelGrp );
+  QLabel* lab = new QLabel( tr( "GEOM_OBJECT" ), aMainGrp );
+  QPushButton* btn = new QPushButton( aMainGrp );
+  btn->setIcon( iconSelect );
+  myEdit = new QLineEdit( aMainGrp );
   myEdit->setReadOnly( true );
   myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
 
   myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
-  myOpenLbl = new QLabel( tr( "NUMBER_OPEN" ), aMainGrp );
+  myOpenLbl   = new QLabel( tr( "NUMBER_OPEN" ),   aMainGrp );
+  myClosedLbl->setMinimumWidth( 150 );
+  myOpenLbl->setMinimumWidth( 150 );
+  
+  QGridLayout* aMainGrpLayout = new QGridLayout( aMainGrp );
+  aMainGrpLayout->setMargin( MARGIN ); aMainGrpLayout->setSpacing( SPACING );
+  aMainGrpLayout->addWidget( lab,    0, 0 );
+  aMainGrpLayout->addWidget( btn,    0, 1 );
+  aMainGrpLayout->addWidget( myEdit, 0, 2 );
+  aMainGrpLayout->addWidget( myClosedLbl, 1, 0, 1, 3 );
+  aMainGrpLayout->addWidget( myOpenLbl,   2, 0, 1, 3 );
 
   QFrame* aFrame = new QFrame( this );
   aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
   QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
   QPushButton* aHelpBtn = new QPushButton( tr( "GEOM_BUT_HELP" ), aFrame );
-  QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
+  QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame );
+  aBtnLay->setMargin( MARGIN ); aBtnLay->setSpacing( SPACING );
   aBtnLay->addWidget( aCloseBtn );
-  aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
+  aBtnLay->addSpacing( SPACING ); aBtnLay->addStretch();
   aBtnLay->addWidget( aHelpBtn );
 
   QVBoxLayout* aLay = new QVBoxLayout( this );
@@ -97,11 +110,10 @@ RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg(GeometryGUI* theGUI, QWidget* the
   aLay->addWidget( aMainGrp );
   aLay->addWidget( aFrame );
 
-  //myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#free_boundaries";
   myHelpFileName = "using_measurement_tools_page.html#boundaries_anchor";
 
   connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
-  connect( aHelpBtn, SIGNAL( clicked() ), SLOT( onHelp() ) );
+  connect( aHelpBtn,  SIGNAL( clicked() ), SLOT( onHelp() ) );
 
   Init();
 }
@@ -121,7 +133,7 @@ RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
 void RepairGUI_FreeBoundDlg::onClose()
 {
   globalSelection();
-  disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
+  disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
   myGeomGUI->SetActiveDialogBox( 0 );
   reject();
   erasePreview();
@@ -133,20 +145,21 @@ void RepairGUI_FreeBoundDlg::onClose()
 //=================================================================================
 void RepairGUI_FreeBoundDlg::onHelp()
 {
-  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
-  if (app)
-    app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
+  LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
+  if ( app )
+    app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
   else {
-               QString platform;
+    QString platform;
 #ifdef WIN32
-               platform = "winapplication";
+    platform = "winapplication";
 #else
-               platform = "application";
+    platform = "application";
 #endif
-    SUIT_MessageBox::warn1
-      (0, tr("WRN_WARNING"), tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-       arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
-       tr("BUT_OK"));
+    SUIT_MessageBox::warning( this, 
+                             tr( "WRN_WARNING" ), 
+                             tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg( app->resourceMgr()->stringValue( "ExternalBrowser", 
+                                                                   platform ) ).arg( myHelpFileName ) );
   }
 }
 
@@ -156,9 +169,9 @@ void RepairGUI_FreeBoundDlg::onHelp()
 //=================================================================================
 void RepairGUI_FreeBoundDlg::onDeactivate()
 {
-  setEnabled(false);
+  setEnabled( false );
   globalSelection();
-  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
+  disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
   myGeomGUI->SetActiveDialogBox( 0 );
 }
 
@@ -171,7 +184,7 @@ void RepairGUI_FreeBoundDlg::onActivate()
   myGeomGUI->EmitSignalDeactivateDialog();
   setEnabled( true );
   myGeomGUI->SetActiveDialogBox( this );
-  connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
+  connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
           SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
   activateSelection();
   onSelectionDone();
@@ -183,17 +196,20 @@ void RepairGUI_FreeBoundDlg::onActivate()
 //=================================================================================
 void RepairGUI_FreeBoundDlg::onSelectionDone()
 {
-  if( IObjectCount() != 1 )
+  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+  SALOME_ListIO aSelList;
+  aSelMgr->selectedObjects(aSelList);
+
+  if ( aSelList.Extent() != 1 )
     return;
 
   Standard_Boolean isOk = Standard_False;
   GEOM::GEOM_Object_var anObj =
-    GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
+    GEOMBase::ConvertIOinGEOMObject( aSelList.First(), isOk );
 
   if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
     return;
-  else
-  {
+  else {
     myObj = anObj;
     displayPreview( false, true, true, 3 );
   }
@@ -209,7 +225,7 @@ void RepairGUI_FreeBoundDlg::Init()
   myObj = GEOM::GEOM_Object::_nil();
 
   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT  ( onDeactivate() ) );
-  connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
+  connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
           SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
 
   activateSelection();
@@ -220,7 +236,7 @@ void RepairGUI_FreeBoundDlg::Init()
 // function : enterEvent
 // purpose  : Activate dialog
 //=================================================================================
-void RepairGUI_FreeBoundDlg::enterEvent( QEvent* )
+void RepairGUI_FreeBoundDlg::enterEvent( QEvent* )
 {
   onActivate();
 }
@@ -229,7 +245,7 @@ void RepairGUI_FreeBoundDlg::enterEvent( QEvent* e )
 // function : closeEvent
 // purpose  : Close dialog
 //=================================================================================
-void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* )
+void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* )
 {
   onClose();
 }
@@ -261,7 +277,7 @@ GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
 // function : isValid
 // purpose  :
 //=================================================================================
-bool RepairGUI_FreeBoundDlg::isValid( QString& msg )
+bool RepairGUI_FreeBoundDlg::isValid( QString& )
 {
   return !myObj->_is_nil();
 }
@@ -280,8 +296,7 @@ bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
   bool result = GEOM::GEOM_IHealingOperations::_narrow(
     getOperation() )->GetFreeBoundary( myObj, aClosed, anOpen );
 
-  if ( result )
-  {
+  if ( result ) {
     myNbClosed = aClosed->length();
     myNbOpen = anOpen->length();
     int i;
@@ -296,8 +311,7 @@ bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
     aLabelText = tr( "NUMBER_OPEN" ) + QString( "%1" ).arg( myNbOpen );
     myOpenLbl->setText( aLabelText );
   }
-  else
-  {
+  else {
     myEdit->setText( GEOMBase::GetName( myObj ) );
     myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
     myOpenLbl->setText( tr( "NUMBER_OPEN" ) );
@@ -316,9 +330,8 @@ void RepairGUI_FreeBoundDlg::keyPressEvent( QKeyEvent* e )
   if ( e->isAccepted() )
     return;
 
-  if ( e->key() == Key_F1 )
-    {
-      e->accept();
-      onHelp();
-    }
+  if ( e->key() == Qt::Key_F1 ) {
+    e->accept();
+    onHelp();
+  }
 }