Salome HOME
Bug IPAL19097 NPAL16768 is not implemented for "Normal to a face"
[modules/geom.git] / src / MeasureGUI / MeasureGUI_Skeleton.cxx
index 39498d5098da6ee76ec38e04a2e6f0ab5488de66..3109b373840568724a2aebf0096e9abd4f1228f3 100644 (file)
@@ -1,33 +1,45 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+// GEOM GEOMGUI : GUI for Geometry component
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 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 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. 
+// 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   : MeasureGUI_Skeleton.cxx
+// Author : Damine COQUERET, Open CASCADE S.A.S.
 //
-//
-//  File   : MeasureGUI_Skeleton.cxx
-//  Author : Damien COQUERET
-//  Module : GEOM
-//  $Header: 
 
-using namespace std;
 #include "MeasureGUI_Skeleton.h"
+#include "MeasureGUI_Widgets.h"
+
+#include <GEOMBase.h>
+#include <GEOM_Displayer.h>
+#include <GeometryGUI.h>
+
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Tools.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Session.h>
+#include <SUIT_OverrideCursor.h>
+
+#include <QKeyEvent>
 
 //=================================================================================
 // class    : MeasureGUI_Skeleton()
@@ -36,18 +48,26 @@ using namespace std;
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-MeasureGUI_Skeleton::MeasureGUI_Skeleton(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
-  :MeasureGUI_Skeleton_QTD(parent, name, modal, fl)
+MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI, QWidget* parent,
+                                         bool modal, Qt::WindowFlags f )
+  : QDialog( parent, f ),
+    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
+    myGeomGUI( GUI )
 {
-  if (!name)
-    setName("MeasureGUI_Skeleton");
-
-  buttonClose->setText(tr("GEOM_BUT_CLOSE"));
-
-  GroupMedium->close(TRUE);
-  resize(350, 0);
+  myMainFrame = new MeasureGUI_SkeletonBox( this );
+  QVBoxLayout* topLayout = new QVBoxLayout( this );
+  topLayout->setMargin( 9 ); topLayout->setSpacing( 0 );
+  topLayout->addWidget( myMainFrame );
 
-  Init(Sel);
+  setAttribute( Qt::WA_DeleteOnClose );
+  setModal( modal );
+  mySelBtn = 0;
+  mySelEdit = 0;
+  myDisplayer = 0;
+  myHelpFileName = "";
+  
+  buttonClose()->setText( tr( "GEOM_BUT_CLOSE" ) );
+  buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
 }
 
 
@@ -57,8 +77,9 @@ MeasureGUI_Skeleton::MeasureGUI_Skeleton(QWidget* parent, const char* name, SALO
 //=================================================================================
 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
 {
-  // no need to delete child widgets, Qt does it all for us
-  this->destroy(TRUE, TRUE);
+  if ( myGeomGUI )
+    myGeomGUI->SetActiveDialogBox( 0 );
+  delete myDisplayer;
 }
 
 
@@ -66,30 +87,49 @@ MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
 // function : Init()
 // purpose  :
 //=================================================================================
-void MeasureGUI_Skeleton::Init(SALOME_Selection* Sel)
+void MeasureGUI_Skeleton::Init()
 {
   /* init variables */
-  mySelection = Sel;
-  mySimulationTopoDs.Nullify();
-
-  myGeomBase = new GEOMBase();
-  myGeomGUI = GEOMContext::GetGeomGUI();
-  myGeomGUI->SetActiveDialogBox((QDialog*)this);
-  myGeom = myGeomGUI->myComponentGeom;
+  if ( myGeomGUI )
+    myGeomGUI->SetActiveDialogBox( (QDialog*)this );
 
   /* signals and slots connections */
-  connect(buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
-  connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
-  connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
+  
+  connect( buttonClose(), SIGNAL( clicked() ),
+          this,          SLOT( ClickOnCancel() ) );
+
+  connect( buttonHelp(),  SIGNAL( clicked() ), 
+          this,          SLOT( ClickOnHelp() ) );
+  
+  if ( myGeomGUI ) {
+    connect( myGeomGUI,   SIGNAL( SignalDeactivateActiveDialog() ),
+            this,        SLOT  ( DeactivateActiveDialog() ) );
+    
+    connect( myGeomGUI,   SIGNAL( SignalCloseAllDialogs() ),
+            this,        SLOT  ( ClickOnCancel() ) );
+  }
+  
+  if ( mySelEdit ) {
+    connect( mySelEdit,   SIGNAL( returnPressed() ),
+            this,        SLOT( LineEditReturnPressed() ) );
+  }
+   
+  if ( mySelBtn ) {
+    connect( mySelBtn,    SIGNAL( clicked() ),
+            this,        SLOT  ( SetEditCurrentArgument() ) );
+  }
 
-  /* Move widget on the botton right corner of main widget */
-//   int x, y;
-//   myGeomBase->DefineDlgPosition( this, x, y );
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
+  if ( aSel ) {
+    connect( aSel, SIGNAL( currentSelectionChanged() ), 
+            this, SLOT  ( SelectionIntoArgument() ) ) ;
+  }
 
   /* displays Dialog */
-  RadioButton1->setChecked(TRUE);
+  mainFrame()->RadioButton1->setChecked( true );
 
-  return;
+  activateSelection();
+  SelectionIntoArgument();
 }
 
 
@@ -99,16 +139,31 @@ void MeasureGUI_Skeleton::Init(SALOME_Selection* Sel)
 //=================================================================================
 void MeasureGUI_Skeleton::ClickOnCancel()
 {
-  myGeomBase->EraseSimulationShape();
-  mySimulationTopoDs.Nullify();
-
-  disconnect(mySelection, 0, this, 0);
-  //myGeomGUI->ResetState();
-  reject();
-
-  return;
+  close();
 }
 
+//=================================================================================
+// function : ClickOnHelp()
+// purpose  :
+//=================================================================================
+void MeasureGUI_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::warning( this, tr( "WRN_WARNING" ),
+                             tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
+                             arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ) );
+  }
+}
 
 //=================================================================================
 // function : LineEditReturnPressed()
@@ -119,12 +174,14 @@ void MeasureGUI_Skeleton::LineEditReturnPressed()
   /* 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);
-
-  return;
+  
+  if ( mySelEdit ) {
+    const QString objectUserName = mySelEdit->text();
+    QWidget* thisWidget = ( QWidget* )this;
+    
+    if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
+      mySelEdit->setText( objectUserName );
+  }
 }
 
 
@@ -134,12 +191,15 @@ void MeasureGUI_Skeleton::LineEditReturnPressed()
 //=================================================================================
 void MeasureGUI_Skeleton::DeactivateActiveDialog()
 {
-  this->setEnabled(false);
-  //myGeomGUI->ResetState();
-  disconnect(mySelection, 0, this, 0);
-  myGeomBase->EraseSimulationShape();
-  myGeomGUI->SetActiveDialogBox(0);
-  return;
+  setEnabled( false );
+  
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
+  if ( aSel )
+    disconnect( aSel, 0, this, 0 );
+  
+  myGeomGUI->SetActiveDialogBox( 0 );
+
+  globalSelection();
 }
 
 
@@ -149,21 +209,197 @@ void MeasureGUI_Skeleton::DeactivateActiveDialog()
 //=================================================================================
 void MeasureGUI_Skeleton::ActivateThisDialog()
 {
-  /* Emit a signal to deactivate the active dialog */
   myGeomGUI->EmitSignalDeactivateDialog();
-  this->setEnabled(true);
-  myGeomGUI->SetActiveDialogBox((QDialog*)this);
-  return;
+  
+  setEnabled( true );
+  
+  myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
+
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
+  if ( aSel )
+    connect( aSel, SIGNAL( currentSelectionChanged() ), 
+            this, SLOT  ( SelectionIntoArgument() ) ) ;
+  
+  redisplayPreview();
+  activateSelection();
+}
+
+//=================================================================================
+// function : SetEditCurrentArgument
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::SetEditCurrentArgument()
+{
+  mySelEdit->setFocus();
+  SelectionIntoArgument();
+}
+
+//=================================================================================
+// function : SelectionIntoArgument
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::SelectionIntoArgument()
+{
+  myObj = GEOM::GEOM_Object::_nil();
+  
+  Standard_Boolean testResult = Standard_False;
+  GEOM::GEOM_Object_var aSelectedObject =
+    GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
+  
+  if ( !testResult || aSelectedObject->_is_nil() ) {
+    mySelEdit->setText( "" );
+    processObject();
+    erasePreview();
+    return;
+  }
+
+  myObj = aSelectedObject;
+  mySelEdit->setText( GEOMBase::GetName( myObj ) );
+  processObject();
+  redisplayPreview();
+}
+
+//=================================================================================
+// function : processObject
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::processObject()
+{  
+}
+
+
+//=================================================================================
+// function : closeEvent
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
+{
+  LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
+  if ( aSel )
+    disconnect( aSel, 0, this, 0 );
+  QDialog::closeEvent( e );
+}
+
+//=================================================================================
+// function : enterEvent()
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::enterEvent( QEvent* )
+{
+  if ( mainFrame()->GroupConstructors->isEnabled() )
+    return;
+    
+  ActivateThisDialog();
 }
 
+//=================================================================================
+// function : buildPrs
+// purpose  : Build presentation for "preview"
+//=================================================================================
+SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
+{
+  return 0;
+}
 
 //=================================================================================
 // function : closeEvent()
+// purpose  : Build presentation for "preview"
+//=================================================================================
+void MeasureGUI_Skeleton::redisplayPreview()
+{
+  QString aMess;
+  if ( !isValid( aMess ) ) {
+    erasePreview( true );
+    return;
+  }
+
+  erasePreview( false );
+
+  try {
+    SUIT_OverrideCursor();
+
+    getDisplayer()->SetColor( Quantity_NOC_VIOLET );
+    getDisplayer()->SetToActivate( false );
+    
+    if ( SALOME_Prs* aPrs = buildPrs() )
+      displayPreview( aPrs );
+  }
+  catch ( const SALOME::SALOME_Exception& e ) {
+    SalomeApp_Tools::QtCatchCorbaException( e );
+  }
+  
+}
+
+//=================================================================================
+// function : activateSelection
+// purpose  : 
+//=================================================================================
+void MeasureGUI_Skeleton::activateSelection()
+{
+  globalSelection( GEOM_ALLSHAPES );
+}
+
+//=================================================================================
+// function : isValid
 // purpose  :
 //=================================================================================
-void MeasureGUI_Skeleton::closeEvent(QCloseEvent* e)
+bool MeasureGUI_Skeleton::isValid( QString& )
+{
+  return !myObj->_is_nil();
+}
+
+//================================================================
+// Function : getDisplayer
+// Purpose  :
+//================================================================
+GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
+{
+  if ( !myDisplayer )
+    myDisplayer = new GEOM_Displayer( getStudy() );
+  return myDisplayer;
+}
+
+//=================================================================================
+// function : createOperation
+// purpose  :
+//=================================================================================
+GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
+{
+  return getGeomEngine()->GetIMeasureOperations( getStudyId() );
+}
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 ) {
+    e->accept();
+    ClickOnHelp();
+  }
+}
+
+MeasureGUI_SkeletonBox* MeasureGUI_Skeleton::mainFrame() const
+{
+  return myMainFrame;
+}
+
+QWidget* MeasureGUI_Skeleton::centralWidget() const
+{
+  return mainFrame()->GroupMedium;
+}
+
+QPushButton* MeasureGUI_Skeleton::buttonClose() const
+{
+  return mainFrame()->buttonClose;
+}
+
+QPushButton* MeasureGUI_Skeleton::buttonHelp() const
 {
-  /* same than click on cancel button */
-  this->ClickOnCancel();
-  return;
+  return mainFrame()->buttonHelp;
 }