Salome HOME
Fix usage of SUIT_OverrideCursor
[modules/geom.git] / src / RepairGUI / RepairGUI_FreeFacesDlg.cxx
index fbfce16383b221035f8622972820847012911daa..395bf5301039b266ac3e0825174d262decdd752b 100644 (file)
@@ -1,63 +1,64 @@
-//  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
+// 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 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.
+// 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
+// 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   : RepairGUI_FreeFacesDlg.cxx
-//  Author : VKN
-//  Module : GEOM
-//  $Header$
 
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : RepairGUI_FreeFacesDlg.cxx
+// Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
+//
 #include "RepairGUI_FreeFacesDlg.h"
 
-#include "LightApp_Application.h"
-#include "LightApp_SelectionMgr.h"
-#include "SalomeApp_Application.h"
-#include "SalomeApp_Tools.h"
-
-#include "SUIT_MessageBox.h"
-#include "SUIT_Session.h"
-#include "SUIT_OverrideCursor.h"
-
-#include "SALOME_ListIteratorOfListIO.hxx"
+#include <GEOMBase.h>
+#include <GeometryGUI.h>
+#include <GEOMImpl_Types.hxx>
+#include <GEOM_Constants.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Study.h>
+#include <SalomeApp_Tools.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_OverrideCursor.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#include <SUIT_ViewManager.h>
+#include <SUIT_ViewWindow.h>
 
-#include "GEOMImpl_Types.hxx"
-#include <TopTools_IndexedMapOfShape.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <TopExp.hxx>
-#include "GEOMBase.h"
-#include "GeometryGUI.h"
-#include "GEOM_Displayer.h"
-
-#include <qapplication.h>
-#include <qlineedit.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <qgroupbox.h>
-#include <qpushbutton.h>
-#define SPACING 5
-#define MARGIN 10
-#define MIN_WIDTH 200
+#include <TopTools_IndexedMapOfShape.hxx>
 
-using namespace std;
+#include <QGroupBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QVBoxLayout>
+
+
+#define SPACING 6
+#define MARGIN  9
+#define MIN_WIDTH 200
 
 //=================================================================================
 // class    : RepairGUI_FreeFacesDlg()
@@ -66,61 +67,55 @@ using namespace std;
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg(GeometryGUI* GUI, QWidget* parent,
-                                               const char* name, bool modal, WFlags fl)
-  :QDialog(parent, "RepairGUI_FreeBoundDlg", false,
-           WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
-   GEOMBase_Helper(dynamic_cast<SUIT_Desktop*>(parent)),
-   myGeomGUI(GUI)
+RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg( GeometryGUI* GUI, QWidget* parent,
+                                                bool modal)
+  : GEOMBase_Skeleton(GUI, parent, modal),
+    myDisplayer      (0),
+    myEdit           (0)
 {
-  myDisplayer = 0;
-
-  setSizeGripEnabled( TRUE );
-  QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
+  QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FREE_FACES")));
+  QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
 
-  setCaption(tr("GEOM_FREE_FACES_TITLE"));
+  setWindowTitle( tr( "GEOM_FREE_FACES_TITLE" ) );
 
   /***************************************************************/
 
-  QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
-  
+  mainFrame()->GroupConstructors->setTitle(tr("GEOM_FREE_FACES"));
+  mainFrame()->RadioButton1->setIcon(image0);
+  mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
+  mainFrame()->RadioButton2->close();
+  mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
+  mainFrame()->RadioButton3->close();
 
-  QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
+  mainFrame()->GroupBoxName->hide();
 
-  aSelGrp->setInsideMargin( 0 );
-  aSelGrp->setFrameStyle( QFrame::NoFrame );
-  new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
-  mySelBtn = new QPushButton( aSelGrp );
-  mySelBtn->setPixmap( image1 );
-  myEdit = new QLineEdit( aSelGrp );
+  QGroupBox* aMainGrp = new QGroupBox( tr( "GEOM_SELECTED_SHAPE" ), this );
+  
+  QLabel* lab = new QLabel( tr( "GEOM_OBJECT" ), aMainGrp );
+  QPushButton *aSelBtn = new QPushButton( aMainGrp );
+  aSelBtn->setIcon( image1 );
+  myEdit = new QLineEdit( aMainGrp );
   myEdit->setReadOnly( true );
   myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   myEdit->setMinimumWidth( MIN_WIDTH );
 
-  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 );
-  aBtnLay->addWidget( aCloseBtn );
-  aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
-  aBtnLay->addWidget( aHelpBtn );
-
-  QVBoxLayout* aLay = new QVBoxLayout( this );
-  aLay->setSpacing( SPACING );
-  aLay->setMargin( MARGIN );
-  aLay->addWidget( aMainGrp );
-  aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
-  aLay->addWidget( aFrame );
-  
-  myHelpFileName = "check_free_faces.htm";
+  QHBoxLayout* aMainLay = new QHBoxLayout( aMainGrp );
+  aMainLay->setSpacing( SPACING );
+  aMainLay->setMargin( MARGIN );
+  aMainLay->addWidget( lab );
+  aMainLay->addWidget( aSelBtn );
+  aMainLay->addWidget( myEdit );
 
-  connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
-  connect( aHelpBtn, SIGNAL( clicked() ), SLOT( onHelp() ) );
-  connect( mySelBtn,    SIGNAL( clicked() ),
-           this,        SLOT  ( onSetEditCurrentArgument() ) );
+  QVBoxLayout* aLay = new QVBoxLayout (centralWidget());
+  aLay->setSpacing(SPACING);
+  aLay->setMargin(MARGIN);
+  aLay->addWidget(aMainGrp);
+
+  resize(minimumSizeHint());
   /***************************************************************/
 
+  myHelpFileName = "free_faces_page.html";
+
   Init();
 }
 
@@ -135,119 +130,111 @@ RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
 
 
 //=================================================================================
-// function : onClose
-// purpose  : SLOT. Called when "close" button pressed. Close dialog
+// function : Init()
+// purpose  :
 //=================================================================================
-void RepairGUI_FreeFacesDlg::onClose()
+void RepairGUI_FreeFacesDlg::Init()
 {
-  globalSelection();
-  disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
-  myGeomGUI->SetActiveDialogBox( 0 );
-  reject();
-  erasePreview();
+  myObj = GEOM::GEOM_Object::_nil();
+  myEditCurrentArgument = myEdit;
+
+  connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
+  connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
+  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+          this, SLOT(SelectionIntoArgument()));
+
+  initName(tr("GEOM_FREE_FACES_NAME"));
+  buttonOk()->setEnabled(false);
+  buttonApply()->setEnabled(false);
+  activateSelection();
+  SelectionIntoArgument();
 }
 
 //=================================================================================
-// function : onHelp()
+// function : ClickOnOk()
 // purpose  :
 //=================================================================================
-void RepairGUI_FreeFacesDlg::onHelp()
+void RepairGUI_FreeFacesDlg::ClickOnOk()
 {
-  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
-  if (app)
-    app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
-  else {
-    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
-                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
-                          QObject::tr("BUT_OK"));
-  }
+  if (ClickOnApply())
+    ClickOnCancel();
 }
 
 //=================================================================================
-// function : onDeactivate
-// purpose  : Deactivate this dialog
+// function : ClickOnApply()
+// purpose  :
 //=================================================================================
-void RepairGUI_FreeFacesDlg::onDeactivate()
+bool RepairGUI_FreeFacesDlg::ClickOnApply()
 {
-  setEnabled(false);
-  globalSelection();
-  disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
-  myGeomGUI->SetActiveDialogBox( 0 );
+  if (!onAccept())
+    return false;
+
+  initName();
+  return true;
 }
 
 //=================================================================================
-// function : onActivate
-// purpose  : Activate this dialog
+// function : ActivateThisDialog()
+// purpose  :
 //=================================================================================
-void RepairGUI_FreeFacesDlg::onActivate()
+void RepairGUI_FreeFacesDlg::ActivateThisDialog()
 {
-  myGeomGUI->EmitSignalDeactivateDialog();
-  setEnabled( true );
-  myGeomGUI->SetActiveDialogBox( this );
-  connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), SLOT  ( onSelectionDone() ) );
+  GEOMBase_Skeleton::ActivateThisDialog();
+
+  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+          this, SLOT(SelectionIntoArgument()));
+
   activateSelection();
+  displayPreview(true);
 }
 
 //=================================================================================
-// function : Init()
+// function : enterEvent()
 // purpose  :
 //=================================================================================
-void RepairGUI_FreeFacesDlg::Init()
+void RepairGUI_FreeFacesDlg::enterEvent(QEvent*)
 {
-  myObj = GEOM::GEOM_Object::_nil();
-
-  /* signals and slots connections */
-  connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT  ( onDeactivate() ) );
-  connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), SLOT  ( onSelectionDone() ) );
-
-  activateSelection();
-  onSelectionDone();
+  if (!mainFrame()->GroupConstructors->isEnabled())
+    ActivateThisDialog();
 }
 
 //=================================================================================
-// function : onSelectionDone
+// function : SelectionIntoArgument
 // purpose  : SLOT. Called when selection changed.
 //=================================================================================
-void RepairGUI_FreeFacesDlg::onSelectionDone()
+void RepairGUI_FreeFacesDlg::SelectionIntoArgument()
 {
+  myEditCurrentArgument->setText("");
+  myObj = GEOM::GEOM_Object::_nil();
   erasePreview();
-  if( IObjectCount() != 1 )
-  {
-    myEdit->setText( "" );
+
+  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+  SALOME_ListIO aSelList;
+  aSelMgr->selectedObjects(aSelList);
+
+  if ( aSelList.Extent() != 1 ) {
+    buttonOk()->setEnabled(false);
+    buttonApply()->setEnabled(false);
     return;
   }
 
-  Standard_Boolean isOk = Standard_False;
   GEOM::GEOM_Object_var anObj =
-    GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
+    GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
 
-  if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
-  {
-    myEdit->setText( "" );
+  if ( !GEOMBase::IsShape( anObj ) ) {
+    buttonOk()->setEnabled(false);
+    buttonApply()->setEnabled(false);
     return;
-  }
-  else
-  {
+  } else {
     myObj = anObj;
-    displayPreview( false, true, true, 3 );
+    myEditCurrentArgument->setText(GEOMBase::GetName(myObj));
+    displayPreview( true, false, true, true, 3 );
   }
 }
 
-//=================================================================================
-// function : enterEvent()
-// purpose  : Mouse enter onto the dialog to activate it
-//=================================================================================
-void RepairGUI_FreeFacesDlg::enterEvent(QEvent* e)
-{
-  onActivate();
-}
-
 //=================================================================================
 // function : activateSelection
-// purpose  : activate selection of faces, shells, and solids
+// purpose  : activate selection of solids
 //=================================================================================
 void RepairGUI_FreeFacesDlg::activateSelection()
 {
@@ -257,15 +244,6 @@ void RepairGUI_FreeFacesDlg::activateSelection()
   globalSelection( aMap );
 }
 
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void RepairGUI_FreeFacesDlg::closeEvent(QCloseEvent* e)
-{
-  onClose();
-}
-
 //=================================================================================
 // function : createOperation
 // purpose  :
@@ -279,7 +257,7 @@ GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
 // function : isValid
 // purpose  :
 //=================================================================================
-bool RepairGUI_FreeFacesDlg::isValid( QString& msg )
+bool RepairGUI_FreeFacesDlg::isValid( QString& )
 {
   return !myObj->_is_nil() ;
 }
@@ -291,43 +269,91 @@ bool RepairGUI_FreeFacesDlg::isValid( QString& msg )
 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
 {
   bool aResult = false;
-  GEOM::ListOfLong_var aFaceLst = 
-    GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->GetFreeFacesIDs( myObj );
+  GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
+  GEOM::ListOfLong_var aFaceLst = anOper->GetFreeFacesIDs( myObj );
   TopoDS_Shape aSelShape;
   TopoDS_Shape aFace; 
   TopTools_IndexedMapOfShape anIndices;
-  if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
-  {
+  int aNbObj = 0;
+
+  if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
     myEdit->setText( GEOMBase::GetName( myObj ) );
     QString aMess;
-    if ( !isValid( aMess ) )
-    {
+    if ( !isValid( aMess ) ) {
       erasePreview( true );
+      buttonOk()->setEnabled(false);
+      buttonApply()->setEnabled(false);
       return false;
     }
     
-    SUIT_OverrideCursor();
+    SUIT_OverrideCursor wc;
 
     TopExp::MapShapes( aSelShape, anIndices);
     SALOME_Prs* aPrs = 0;
     
-    for ( int i = 0, n = aFaceLst->length(); i < n; i++ )
-    {
+    //Get object trancparency and set it to preview
+    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+    double transparency = 1.0;
+    if( app ) {
+      SUIT_ViewWindow* window = app->desktop( )->activeWindow( );
+      if( window && window->getViewManager() ) {
+       if ( app ) {
+         SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+         if( aStudy ) {
+           int aMgrId = window->getViewManager()->getGlobalId();
+           CORBA::String_var aMainEntry = myObj->GetStudyEntry();
+           QString anEntry = aMainEntry.in();
+           QVariant v = aStudy->getObjectProperty( aMgrId , anEntry , GEOM::propertyName( GEOM::Transparency ) , transparency );
+           if( v.canConvert( QVariant::Double ) ) {
+             transparency = v.toDouble();
+           }
+         }
+       }
+      }
+    }
+
+    int i;
+    int n = aFaceLst->length();
+
+    for (i = 0; i < n; i++ ) {
       aFace = anIndices.FindKey( aFaceLst[i] );
-      try
-      {
+      try {
         getDisplayer()->SetColor( Quantity_NOC_RED );
+       getDisplayer()->SetTransparency( transparency );
+       getDisplayer()->SetWidth( 2 );
+       getDisplayer()->SetNbIsos( 1 );
+       getDisplayer()->SetIsosWidth( 1 );
+       getDisplayer()->SetIsosColor( Quantity_NOC_RED );
+       getDisplayer()->SetDisplayMode( 0 );
         getDisplayer()->SetToActivate( false );
-       aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
+        aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
         if ( aPrs )
-         displayPreview( aPrs, true );
+          displayPreview( aPrs, true );
       }
       catch( const SALOME::SALOME_Exception& e )
       {
         SalomeApp_Tools::QtCatchCorbaException( e );
+        buttonOk()->setEnabled(false);
+        buttonApply()->setEnabled(false);
+        return false;
       }
     }
+
+    // Create sub-objects
+    GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObj, aFaceLst);
+
+    aNbObj = aList->length();
+
+    for (i = 0; i < aNbObj; i++) {
+      objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
+    }
+
+    aResult = true;
   }
+
+  buttonOk()->setEnabled(aNbObj > 0);
+  buttonApply()->setEnabled(aNbObj > 0);
+
   return aResult;
 }
 
@@ -342,13 +368,24 @@ GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
   return myDisplayer;
 }
 
+//================================================================
+// Function : getFather
+// Purpose  : Get father object for object to be added in study
+//            (called with addInStudy method)
+//================================================================
+GEOM::GEOM_Object_ptr RepairGUI_FreeFacesDlg::getFather (GEOM::GEOM_Object_ptr)
+{
+  return myObj;
+}
+
 //=================================================================================
-// function : SetEditCurrentArgument
-// purpose  :
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
 //=================================================================================
-void RepairGUI_FreeFacesDlg::onSetEditCurrentArgument()
+QList<GEOM::GeomObjPtr> RepairGUI_FreeFacesDlg::getSourceObjects()
 {
-  myEdit->setFocus();
-  onSelectionDone();
+  QList<GEOM::GeomObjPtr> res;
+  GEOM::GeomObjPtr aGeomObjPtr(myObj);
+  res << aGeomObjPtr;
+  return res;
 }
-