Salome HOME
fix for Bug IPAL9442
[modules/geom.git] / src / BuildGUI / BuildGUI_ShellDlg.cxx
index 8a33f4cf62b112fc6300b830770e43ddf5d954f8..5972e29941a50fc4c925d7cef7a848ae4f372d45 100644 (file)
 //  Module : GEOM
 //  $Header: 
 
-using namespace std;
 #include "BuildGUI_ShellDlg.h"
+#include "GEOMImpl_Types.hxx"
 
-#include "BuildGUI.h"
-#include "QAD_Desktop.h"
+#include "SUIT_Session.h"
+#include "SalomeApp_Application.h"
+#include "SalomeApp_SelectionMgr.h"
+
+#include "TColStd_MapOfInteger.hxx"
+
+#include <qlabel.h>
 
 //=================================================================================
 // class    : BuildGUI_ShellDlg()
@@ -39,11 +44,11 @@ using namespace std;
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-BuildGUI_ShellDlg::BuildGUI_ShellDlg(QWidget* parent, const char* name, BuildGUI* theBuildGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
-  :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+BuildGUI_ShellDlg::BuildGUI_ShellDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
+  :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
 {
-  QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_SHELL")));
-  QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_SELECT")));
+  QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_SHELL")));
+  QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
 
   setCaption(tr("GEOM_SHELL_TITLE"));
     
@@ -57,12 +62,12 @@ BuildGUI_ShellDlg::BuildGUI_ShellDlg(QWidget* parent, const char* name, BuildGUI
   GroupShell->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
   GroupShell->TextLabel1->setText(tr("GEOM_OBJECTS"));
   GroupShell->PushButton1->setPixmap(image1);
+  GroupShell->LineEdit1->setReadOnly( true );
   
-  Layout1->addWidget(GroupShell, 1, 0);
+  Layout1->addWidget(GroupShell, 2, 0);
   /***************************************************************/
 
   /* Initialisations */
-  myBuildGUI = theBuildGUI;
   Init();
 }
 
@@ -85,11 +90,14 @@ void BuildGUI_ShellDlg::Init()
 {
   /* init variables */
   myEditCurrentArgument = GroupShell->LineEdit1;
-  myOkListShapes = false;
-
-  myFaceFilter = new GEOM_FaceFilter(StdSelect_Plane, myGeom);
-  /* Filter for the next selection */
-  mySelection->AddFilter(myFaceFilter) ;
+  GroupShell->LineEdit1->setReadOnly( true );
+  
+  myOkFacesAndShells = false;
+  
+  TColStd_MapOfInteger aMap;
+  aMap.Add(GEOM_SHELL);
+  aMap.Add(GEOM_FACE);
+  globalSelection( aMap );
 
   /* signals and slots connections */
   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
@@ -97,13 +105,10 @@ void BuildGUI_ShellDlg::Init()
 
   connect(GroupShell->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
 
-  connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+  connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
+         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
 
-  /* displays Dialog */
-  GroupShell->show();
-  this->show();
-
-  return;
+  initName(tr("GEOM_SHELL"));
 }
 
 
@@ -113,9 +118,8 @@ void BuildGUI_ShellDlg::Init()
 //=================================================================================
 void BuildGUI_ShellDlg::ClickOnOk()
 {
-  this->ClickOnApply();
-  ClickOnCancel();
-  return ;
+  if ( ClickOnApply() )
+    ClickOnCancel();
 }
 
 
@@ -123,13 +127,13 @@ void BuildGUI_ShellDlg::ClickOnOk()
 // function : ClickOnApply()
 // purpose  :
 //=================================================================================
-void BuildGUI_ShellDlg::ClickOnApply()
+bool BuildGUI_ShellDlg::ClickOnApply()
 {
-  QAD_Application::getDesktop()->putInfo(tr(""));
+  if ( !onAccept() )
+    return false;
 
-  if(myOkListShapes) 
-    myBuildGUI->MakeShellAndDisplay(myListShapes);
-  return;
+  initName();
+  return true;
 }
 
 
@@ -139,21 +143,22 @@ void BuildGUI_ShellDlg::ClickOnApply()
 //=================================================================================
 void BuildGUI_ShellDlg::SelectionIntoArgument()
 {
-  myEditCurrentArgument->setText("");
-  QString aString = "";
+  myEditCurrentArgument->setText( "" );
+  QString aString;
 
-  myOkListShapes = false;
-  int nbSel = mySelection->IObjectCount();
-  if(nbSel == 0) 
+  myOkFacesAndShells = false;
+  int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
+  if ( nbSel == 0 )
     return;
+  if ( nbSel != 1 )
+    aString = QString( "%1_objects ").arg( nbSel );
 
-  aString = tr("%1_objects").arg(nbSel);
-
-  myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes);
-  myEditCurrentArgument->setText(aString);
-  myOkListShapes = true;
+  GEOMBase::ConvertListOfIOInListOfGO( selectedIO(),  myFacesAndShells, true );
+  if ( !myFacesAndShells.length() )
+    return;
 
-  return;
+  myEditCurrentArgument->setText( aString );
+  myOkFacesAndShells = true;
 }
 
 
@@ -164,12 +169,17 @@ void BuildGUI_ShellDlg::SelectionIntoArgument()
 void BuildGUI_ShellDlg::SetEditCurrentArgument()
 {
   QPushButton* send = (QPushButton*)sender();
-  mySelection->ClearFilters() ;
-  GroupShell->LineEdit1->setFocus();
+  if (send != GroupShell->PushButton1)
+    return;
+
+  TColStd_MapOfInteger aMap;
+  aMap.Add(GEOM_SHELL);
+  aMap.Add(GEOM_FACE);
+  globalSelection( aMap );
   myEditCurrentArgument = GroupShell->LineEdit1;
-  mySelection->AddFilter(myFaceFilter);
-  this->SelectionIntoArgument();
-  return;
+
+  myEditCurrentArgument->setFocus();
+  SelectionIntoArgument();
 }
 
 
@@ -180,9 +190,12 @@ void BuildGUI_ShellDlg::SetEditCurrentArgument()
 void BuildGUI_ShellDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
-  connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
-  mySelection->AddFilter(myFaceFilter);
-  return;
+  connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
+         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
+  TColStd_MapOfInteger aMap;
+  aMap.Add(GEOM_SHELL);
+  aMap.Add(GEOM_FACE);
+  globalSelection( aMap );
 }
 
 
@@ -192,8 +205,42 @@ void BuildGUI_ShellDlg::ActivateThisDialog()
 //=================================================================================
 void BuildGUI_ShellDlg::enterEvent(QEvent* e)
 {
-  if(GroupConstructors->isEnabled())
-    return;  
-  this->ActivateThisDialog();
-  return;
+  if ( !GroupConstructors->isEnabled() )
+    ActivateThisDialog();
+}
+
+//=================================================================================
+// function : createOperation
+// purpose  :
+//=================================================================================
+GEOM::GEOM_IOperations_ptr BuildGUI_ShellDlg::createOperation()
+{
+  return getGeomEngine()->GetIShapesOperations( getStudyId() );
 }
+
+//=================================================================================
+// function : isValid
+// purpose  :
+//=================================================================================
+bool BuildGUI_ShellDlg::isValid( QString& )
+{
+  return myOkFacesAndShells;
+}
+
+//=================================================================================
+// function : execute
+// purpose  :
+//=================================================================================
+bool BuildGUI_ShellDlg::execute( ObjectList& objects )
+{
+  GEOM::GEOM_Object_var anObj;
+
+  anObj = GEOM::GEOM_IShapesOperations::_narrow(
+    getOperation() )->MakeShell( myFacesAndShells );
+
+  if ( !anObj->_is_nil() )
+    objects.push_back( anObj._retn() );
+
+  return true;
+}
+