Salome HOME
Merging with WPdev
[modules/geom.git] / src / GEOMBase / GEOMBase_Skeleton.cxx
index 85b4f326f0e368940d16467c7ba40e2c1e16a405..33a6fe5ac79534454f0ce18980ae13571ce535ad 100644 (file)
 //  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   : GEOMBase_Skeleton.cxx
 //  Author : Damien COQUERET
 //  Module : GEOM
-//  $Header
+//  $Header$
 
-using namespace std;
 #include "GEOMBase_Skeleton.h"
 
+#include "GeometryGUI.h"
+
+#include "SalomeApp_Application.h"
+#include "LightApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+#include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
+
+#include <qpushbutton.h>
+
+using namespace std;
+
 //=================================================================================
 // class    : GEOMBase_Skeleton()
 // purpose  : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the 
@@ -36,8 +47,12 @@ using namespace std;
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-GEOMBase_Skeleton::GEOMBase_Skeleton(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
-  :DlgRef_Skeleton_QTD(parent, name, modal, fl)
+GEOMBase_Skeleton::GEOMBase_Skeleton(GeometryGUI* theGeometryGUI, QWidget* parent,
+                                     const char* name, bool modal, WFlags fl)
+  : DlgRef_Skeleton_QTD( parent, name, modal, WStyle_Customize | WStyle_NormalBorder
+                         | WStyle_Title | WStyle_SysMenu | WDestructiveClose ), 
+   GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
+   myGeomGUI( theGeometryGUI )
 {
   if (!name)
     setName("GEOMBase_Skeleton");
@@ -45,11 +60,12 @@ GEOMBase_Skeleton::GEOMBase_Skeleton(QWidget* parent, const char* name, SALOME_S
   buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
   buttonOk->setText(tr("GEOM_BUT_OK"));
   buttonApply->setText(tr("GEOM_BUT_APPLY"));
+  buttonHelp->setText(tr("GEOM_BUT_HELP"));
 
   GroupMedium->close(TRUE);
   resize(0, 0);
 
-  Init(Sel);
+  Init();
 }
 
 
@@ -59,8 +75,8 @@ GEOMBase_Skeleton::GEOMBase_Skeleton(QWidget* parent, const char* name, SALOME_S
 //=================================================================================
 GEOMBase_Skeleton::~GEOMBase_Skeleton()
 {
-  // no need to delete child widgets, Qt does it all for us
-  this->destroy(TRUE, TRUE);
+  if (myGeomGUI)
+    myGeomGUI->SetActiveDialogBox( 0 );
 }
 
 
@@ -68,28 +84,29 @@ GEOMBase_Skeleton::~GEOMBase_Skeleton()
 // function : Init()
 // purpose  :
 //=================================================================================
-void GEOMBase_Skeleton::Init(SALOME_Selection* Sel)
+void GEOMBase_Skeleton::Init()
 {
-  /* init variables */
-  mySelection = Sel;
-  mySimulationTopoDs.Nullify();
+  SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (!myGeomGUI && app)
+    myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
 
-  myGeomBase = new GEOMBase();
-  myGeomGUI = GEOMContext::GetGeomGUI();
-  myGeomGUI->SetActiveDialogBox((QDialog*)this);
-  myGeom = myGeomGUI->myComponentGeom;
+  /* init variables */
+  myGeomGUI->SetActiveDialogBox(this);
 
   /* 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()));
+  if (myGeomGUI) 
+  {
+    connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
+    connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
+  }
 
-  /* Move widget on the botton right corner of main widget */
-//   int x, y;
-//   myGeomBase->DefineDlgPosition( this, x, y );
+  // connect help button on a private slot that displays help information
+  connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
 
   /* displays Dialog */
   RadioButton1->setChecked(TRUE);
+  RadioButton4->hide();
 
   return;
 }
@@ -101,16 +118,7 @@ void GEOMBase_Skeleton::Init(SALOME_Selection* Sel)
 //=================================================================================
 void GEOMBase_Skeleton::ClickOnCancel()
 {
-  myGeomBase->EraseSimulationShape();
-  mySimulationTopoDs.Nullify();
-
-  mySelection->ClearFilters();
-  disconnect(mySelection, 0, this, 0);
-
-  //myGeomGUI->ResetState();
-  reject();
-
-  return;
+  close();
 }
 
 
@@ -120,13 +128,17 @@ void GEOMBase_Skeleton::ClickOnCancel()
 //=================================================================================
 void GEOMBase_Skeleton::LineEditReturnPressed()
 {
+  if ( !myEditCurrentArgument )
+    return;
+
   /* User name of object input management                          */
   /* If successfull the selection is changed and signal emitted... */
   /* so SelectionIntoArgument() is automatically called.           */
   const QString objectUserName = myEditCurrentArgument->text();
   QWidget* thisWidget = (QWidget*)this;
-  if(myGeomBase->SelectionByNameInDialogs(thisWidget, objectUserName, mySelection))
-    myEditCurrentArgument->setText(objectUserName);
+  
+  if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
+     myEditCurrentArgument->setText(objectUserName);
 
   return;
 }
@@ -139,11 +151,10 @@ void GEOMBase_Skeleton::LineEditReturnPressed()
 void GEOMBase_Skeleton::DeactivateActiveDialog()
 {
   this->setEnabled(false);
-  mySelection->ClearFilters();
-  //myGeomGUI->ResetState();
-  disconnect(mySelection, 0, this, 0);
-  myGeomBase->EraseSimulationShape();
-  myGeomGUI->SetActiveDialogBox(0);
+  globalSelection();
+  disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
+  if (myGeomGUI) myGeomGUI->SetActiveDialogBox(0);
+    
   return;
 }
 
@@ -155,20 +166,103 @@ void GEOMBase_Skeleton::DeactivateActiveDialog()
 void GEOMBase_Skeleton::ActivateThisDialog()
 {
   /* Emit a signal to deactivate the active dialog */
-  myGeomGUI->EmitSignalDeactivateDialog();
+  if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
   this->setEnabled(true);
-  myGeomGUI->SetActiveDialogBox((QDialog*)this);
+  if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
   return;
 }
 
 
 //=================================================================================
 // function : closeEvent()
-// purpose  :
+// purpose  : same than click on cancel button
 //=================================================================================
 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
 {
-  /* same than click on cancel button */
-  this->ClickOnCancel();
-  return;
+  SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
+  if(app) {
+    disconnect( app->selectionMgr(), 0, this, 0);
+    app->updateActions();
+  }
+  QDialog::closeEvent( e );
+}
+
+//=================================================================================
+// function : initName()
+// purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
+//=================================================================================
+void GEOMBase_Skeleton::initName( const char* thePrefix )
+{
+  if ( thePrefix )
+    setPrefix( thePrefix );
+  ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
+}
+
+//=================================================================================
+// function : getNewObjectName()
+// purpose  : returns contents of Name field
+//=================================================================================
+const char* GEOMBase_Skeleton::getNewObjectName() const
+{
+  return ResultName->text();
+}
+
+//=================================================================================
+// function : getConstructorId()
+// purpose  :
+//=================================================================================
+int GEOMBase_Skeleton::getConstructorId() const
+{
+  if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
+    return GroupConstructors->id( GroupConstructors->selected() );
+  return -1;
+}
+
+//=================================================================================
+// function : ClickOnHelp()
+// purpose  :
+//=================================================================================
+void GEOMBase_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::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
+                          QObject::tr("BUT_OK"));
+  }
+}
+//=================================================================================
+//  function : setHelpFileName()
+//  purpose  : set name for help file html
+//=================================================================================
+
+void GEOMBase_Skeleton::setHelpFileName(const QString& theName)
+{
+    myHelpFileName = theName;
+}
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Key_F1 )
+    {
+      e->accept();
+      ClickOnHelp();
+    }
 }