Salome HOME
Copyright update 2022
[modules/geom.git] / src / BlocksGUI / BlocksGUI_PropagateDlg.cxx
index de52f9992099131efe1e95368038bc89b7603678..228089eee0183542abef088b311583e5c9278e57 100644 (file)
@@ -1,43 +1,42 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+// Copyright (C) 2007-2022  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//
-//
-//  File   : BlocksGUI_PropagateDlg.cxx
-//  Author : VKN
-//  Module : GEOM
-//  $Header$
 
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : BlocksGUI_PropagateDlg.cxx
+// Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
+//
 #include "BlocksGUI_PropagateDlg.h"
-#include "GEOMImpl_Types.hxx"
 
-#include "SUIT_Session.h"
-#include "SalomeApp_Application.h"
-#include "SalomeApp_SelectionMgr.h"
+#include <DlgRef.h>
+#include <GeometryGUI.h>
+#include <GEOMBase.h>
+#include <GEOMImpl_Types.hxx>
 
-#include <TColStd_MapOfInteger.hxx>
-
-#include <qlabel.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+#include <SalomeApp_Application.h>
+#include <LightApp_SelectionMgr.h>
 
-using namespace std;
+#include <TColStd_MapOfInteger.hxx>
 
 //=================================================================================
 // class    : BlocksGUI_PropagateDlg()
@@ -46,39 +45,39 @@ using namespace std;
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-BlocksGUI_PropagateDlg::BlocksGUI_PropagateDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
-  :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+BlocksGUI_PropagateDlg::BlocksGUI_PropagateDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
+  : GEOMBase_Skeleton( theGeometryGUI, parent )
 {
-  QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PROPAGATE")));
-  QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
+  QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PROPAGATE" ) ) );
+  QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
 
-  setCaption(tr("GEOM_PROPAGATE_TITLE"));
+  setWindowTitle( tr( "GEOM_PROPAGATE_TITLE" ) );
 
   /***************************************************************/
-  GroupConstructors->setTitle(tr("GEOM_PROPAGATE_TITLE"));
-  RadioButton1->setPixmap(image0);
-  RadioButton2->close(TRUE);
-  RadioButton3->close(TRUE);
-
-  QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
-  QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, aMainGrp);
-  aSelGrp->setFrameStyle(QFrame::NoFrame);
-  aSelGrp->setInsideMargin(0);
-
-  new QLabel(tr("GEOM_OBJECT"), aSelGrp);
-  mySelBtn = new QPushButton(aSelGrp);
-  mySelBtn->setPixmap(image1);
-  mySelName = new QLineEdit(aSelGrp);
-  mySelName->setReadOnly(true);
-
-  Layout1->addWidget(aMainGrp, 1, 0);
+  mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PROPAGATE_TITLE" ) );
+  mainFrame()->RadioButton1->setIcon( image0 );
+  mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
+  mainFrame()->RadioButton2->close();
+  mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
+  mainFrame()->RadioButton3->close();
+
+  myGrp = new DlgRef_1Sel( centralWidget() );
+  myGrp->GroupBox1->setTitle( tr( "GEOM_SELECTED_SHAPE" ) );
+  myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
+  myGrp->PushButton1->setIcon( image1 );
+  myGrp->LineEdit1->setReadOnly( true );
+
+  QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
+  layout->setMargin( 0 ); layout->setSpacing( 6 );
+  layout->addWidget( myGrp );
 
   /***************************************************************/
 
+  setHelpFileName( "propagate_operation_page.html" );
+
   Init();
 }
 
-
 //=================================================================================
 // function : ~BlocksGUI_PropagateDlg()
 // purpose  : Destroys the object and frees any allocated resources
@@ -87,7 +86,6 @@ BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
 {
 }
 
-
 //=================================================================================
 // function : Init()
 // purpose  :
@@ -97,20 +95,17 @@ void BlocksGUI_PropagateDlg::Init()
   /* init variables */
 
   myObject = GEOM::GEOM_Object::_nil();
-  ResultName->setText( "" );
+  mainFrame()->ResultName->setText( "" );
+  mainFrame()->GroupBoxName->hide();
 
   //myGeomGUI->SetState( 0 );
 
   /* signals and slots connections */
-  connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
-  connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
-  connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
-
-  connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
-  connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
+  connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
+  connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
 
-  connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
-  connect(mySelName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+  connect( myGrp->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
+  connect( myGrp->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
 
   activateSelection();
 }
@@ -122,12 +117,11 @@ void BlocksGUI_PropagateDlg::Init()
 //=================================================================================
 void BlocksGUI_PropagateDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if ( ClickOnApply() )
     ClickOnCancel();
 }
 
-
-
 //=================================================================================
 // function : ClickOnApply()
 // purpose  :
@@ -139,7 +133,7 @@ bool BlocksGUI_PropagateDlg::ClickOnApply()
 
   initName();
 
-  mySelName->setText("");
+  myGrp->LineEdit1->setText( "" );
   myObject = GEOM::GEOM_Object::_nil();
 
   activateSelection();
@@ -148,31 +142,24 @@ bool BlocksGUI_PropagateDlg::ClickOnApply()
 }
 
 
-//=================================================================================
-// function : ClickOnCancel()
-// purpose  :
-//=================================================================================
-void BlocksGUI_PropagateDlg::ClickOnCancel()
-{
-  GEOMBase_Skeleton::ClickOnCancel();
-}
-
-
 //=================================================================================
 // function : SelectionIntoArgument()
 // purpose  : Called when selection
 //=================================================================================
 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
 {
-  mySelName->setText("");
+  myGrp->LineEdit1->setText( "" );
   myObject = GEOM::GEOM_Object::_nil();
 
-  if ( IObjectCount() == 1 ) {
-    Handle(SALOME_InteractiveObject) anIO = firstIObject();
-    Standard_Boolean aRes;
-    myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
-    if ( aRes )
-      mySelName->setText( GEOMBase::GetName( myObject ) );
+  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+  SALOME_ListIO aSelList;
+  aSelMgr->selectedObjects(aSelList);
+
+  if (aSelList.Extent() == 1) {
+    Handle(SALOME_InteractiveObject) anIO = aSelList.First();
+    myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
+    if ( !CORBA::is_nil( myObject ) )
+      myGrp->LineEdit1->setText( GEOMBase::GetName( myObject ) );
   }
 }
 
@@ -183,8 +170,8 @@ void BlocksGUI_PropagateDlg::SelectionIntoArgument()
 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
 {
   const QObject* send = sender();
-  if ( send == mySelBtn )  {
-    mySelName->setFocus();
+  if ( send == myGrp->PushButton1 )  {
+    myGrp->LineEdit1->setFocus();
   }
   activateSelection();
 }
@@ -197,23 +184,12 @@ void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
 {
   const QObject* send = sender();
-  if( send == mySelName ) {
+  if ( send == myGrp->LineEdit1 ) {
     GEOMBase_Skeleton::LineEditReturnPressed();
   }
 }
 
 
-//=================================================================================
-// function : DeactivateActiveDialog()
-// purpose  :
-//=================================================================================
-void BlocksGUI_PropagateDlg::DeactivateActiveDialog()
-{
-  //myGeomGUI->SetState( -1 );
-  GEOMBase_Skeleton::DeactivateActiveDialog();
-}
-
-
 //=================================================================================
 // function : ActivateThisDialog()
 // purpose  :
@@ -222,7 +198,7 @@ void BlocksGUI_PropagateDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
 
-  mySelName->setText("");
+  myGrp->LineEdit1->setText( "" );
   myObject = GEOM::GEOM_Object::_nil();
 
   //myGeomGUI->SetState( 0 );
@@ -234,37 +210,26 @@ void BlocksGUI_PropagateDlg::ActivateThisDialog()
 // function : enterEvent()
 // purpose  : Mouse enter onto the dialog to activate it
 //=================================================================================
-void BlocksGUI_PropagateDlg::enterEvent(QEvent* e)
+void BlocksGUI_PropagateDlg::enterEvent( QEvent* )
 {
-  if ( !GroupConstructors->isEnabled() )
+  if ( !mainFrame()->GroupConstructors->isEnabled() )
     ActivateThisDialog();
 }
 
-
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void BlocksGUI_PropagateDlg::closeEvent(QCloseEvent* e)
-{
-  //myGeomGUI->SetState( -1 );
-  GEOMBase_Skeleton::closeEvent( e );
-}
-
 //=================================================================================
 // function : createOperation
 // purpose  :
 //=================================================================================
 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
 {
-  return getGeomEngine()->GetIBlocksOperations( getStudyId() );
+  return getGeomEngine()->GetIBlocksOperations();
 }
 
 //=================================================================================
 // function : isValid
 // purpose  :
 //=================================================================================
-bool BlocksGUI_PropagateDlg::isValid( QString& msg )
+bool BlocksGUI_PropagateDlg::isValid( QString& )
 {
   return !myObject->_is_nil() ;
 }
@@ -275,19 +240,18 @@ bool BlocksGUI_PropagateDlg::isValid( QString& msg )
 //=================================================================================
 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
 {
-
-  GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
-  ResultName->setText( "" );
+  GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
+  GEOM::ListOfGO_var aList = anOper->Propagate( myObject );
+  mainFrame()->ResultName->setText( "" );
 
   if ( !aList->length() )
     return false;
 
-  for ( int i = 0, n = aList->length(); i < n; i++ )
-  {
-    objects.push_back(aList[i]._retn());
+  for ( int i = 0, n = aList->length(); i < n; i++ ) {
+    objects.push_back( aList[i]._retn() );
   }
 
-  return objects.size() ? true : false;
+  return objects.size() > 0;
 }
 
 //=================================================================================
@@ -297,14 +261,16 @@ bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
 void BlocksGUI_PropagateDlg::activateSelection()
 {
   TColStd_MapOfInteger aMap;
+  aMap.Add( GEOM_FACE );
+  aMap.Add( GEOM_SHELL );
   aMap.Add( GEOM_SOLID );
   aMap.Add( GEOM_COMPOUND );
   globalSelection( aMap );
-  if (myObject->_is_nil()) {
+  if ( myObject->_is_nil() ) {
     SelectionIntoArgument();
   }
-  connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
-         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
+  connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
+           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
 }
 
 //================================================================
@@ -312,8 +278,19 @@ void BlocksGUI_PropagateDlg::activateSelection()
 // Purpose  : Get father object for object to be added in study
 //            ( called with addInStudy method )
 //================================================================
-GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather (GEOM::GEOM_Object_ptr)
+GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather( GEOM::GEOM_Object_ptr )
 {
   return myObject;
 }
 
+//=================================================================================
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
+//=================================================================================
+QList<GEOM::GeomObjPtr> BlocksGUI_PropagateDlg::getSourceObjects()
+{
+  QList<GEOM::GeomObjPtr> res;
+  GEOM::GeomObjPtr aGeomObjPtr(myObject);
+  res << aGeomObjPtr;
+  return res;
+}