]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/MeasureGUI/MeasureGUI_Skeleton.cxx
Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / MeasureGUI / MeasureGUI_Skeleton.cxx
index 39498d5098da6ee76ec38e04a2e6f0ab5488de66..39bcaf04f0112e6043af7059a66d225cf136ab14 100644 (file)
 //  File   : MeasureGUI_Skeleton.cxx
 //  Author : Damien COQUERET
 //  Module : GEOM
-//  $Header
+//  $Header$
 
-using namespace std;
 #include "MeasureGUI_Skeleton.h"
+#include "QAD_Desktop.h"
+#include "QAD_WaitCursor.h"
+#include "GEOMBase.h"
+#include "GEOM_Displayer.h"
+#include "GeometryGUI.h"
+#include "SALOMEGUI_QtCatchCorbaException.hxx"
+
+#include <qlineedit.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+#include <qbuttongroup.h>
 
 //=================================================================================
 // class    : MeasureGUI_Skeleton()
@@ -36,18 +47,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( QWidget*          parent,
+                                          const char*       name,
+                                          SALOME_Selection* Sel )
+: MeasureGUI_Skeleton_QTD( parent, name, false,
+    WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
 {
-  if (!name)
-    setName("MeasureGUI_Skeleton");
 
-  buttonClose->setText(tr("GEOM_BUT_CLOSE"));
+  mySelBtn = 0;
+  mySelEdit = 0;
+  myDisplayer = 0;
+  
+  if ( !name )
+    setName( "MeasureGUI_Skeleton" );
+
+  buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
 
-  GroupMedium->close(TRUE);
-  resize(350, 0);
+  buttonClose->setAutoDefault( false );
 
-  Init(Sel);
+  GroupMedium->close( TRUE );
+  resize( 350, 0 );
 }
 
 
@@ -57,8 +76,8 @@ 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);
+  myGeomGUI->SetActiveDialogBox( 0 );
+  delete myDisplayer;
 }
 
 
@@ -66,30 +85,42 @@ MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
 // function : Init()
 // purpose  :
 //=================================================================================
-void MeasureGUI_Skeleton::Init(SALOME_Selection* Sel)
+void MeasureGUI_Skeleton::Init( SALOME_Selection* Sel )
 {
+  myGeomGUI = GeometryGUI::GetGeomGUI();
+
   /* init variables */
   mySelection = Sel;
-  mySimulationTopoDs.Nullify();
 
-  myGeomBase = new GEOMBase();
-  myGeomGUI = GEOMContext::GetGeomGUI();
   myGeomGUI->SetActiveDialogBox((QDialog*)this);
-  myGeom = myGeomGUI->myComponentGeom;
 
   /* 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( 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( mySelEdit,   SIGNAL( returnPressed() ),
+           this,        SLOT( LineEditReturnPressed() ) );
+           
+  connect( mySelBtn,    SIGNAL( clicked() ),
+           this,        SLOT  ( SetEditCurrentArgument() ) );
+
+  if ( mySelection )
+    connect( mySelection, SIGNAL( currentSelectionChanged() ),
+             this,        SLOT  ( SelectionIntoArgument() ) );
 
   /* displays Dialog */
-  RadioButton1->setChecked(TRUE);
+  RadioButton1->setChecked( TRUE );
 
-  return;
+  activateSelection();
+  SelectionIntoArgument();
+  show();
 }
 
 
@@ -99,14 +130,7 @@ 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();
 }
 
 
@@ -119,12 +143,12 @@ 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;
+  
+  const QString objectUserName = mySelEdit->text();
+  QWidget* thisWidget = ( QWidget* )this;
+  
+  if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) )
+    mySelEdit->setText( objectUserName );
 }
 
 
@@ -134,12 +158,14 @@ 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 );
+  
+  if ( mySelection )
+    disconnect( mySelection, 0, this, 0 );
+    
+  myGeomGUI->SetActiveDialogBox( 0 );
+
+  globalSelection();
 }
 
 
@@ -149,21 +175,186 @@ 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 );
+
+  if ( mySelection )
+    connect( mySelection, 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( mySelection->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 )
+{
+  disconnect( mySelection, 0, this, 0 );
+  QDialog::closeEvent( e );
+}
+
+//=================================================================================
+// function : enterEvent()
+// purpose  :
+//=================================================================================
+void MeasureGUI_Skeleton::enterEvent(QEvent* e)
+{
+  if ( 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
+  {
+    QAD_WaitCursor wc;
+
+    getDisplayer()->SetColor( Quantity_NOC_VIOLET );
+    getDisplayer()->SetToActivate( false );
+    
+    if ( SALOME_Prs* aPrs = buildPrs() )
+      displayPreview( aPrs );
+  }
+  catch( const SALOME::SALOME_Exception& e )
+  {
+    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& )
 {
-  /* same than click on cancel button */
-  this->ClickOnCancel();
-  return;
+  return !myObj->_is_nil();
 }
+
+//================================================================
+// Function : getDisplayer
+// Purpose  :
+//================================================================
+GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
+{
+  if ( !myDisplayer )
+    myDisplayer = new GEOM_Displayer();
+  return myDisplayer;
+}
+
+//=================================================================================
+// function : createOperation
+// purpose  :
+//=================================================================================
+GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
+{
+  return getGeomEngine()->GetIMeasureOperations( getStudyId() );
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+