geom/src/MeasureGUI/MeasureGUI_Skeleton.cxx

368 lines
12 KiB
C++
Raw Normal View History

2004-01-07 20:46:21 +05:00
// 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
//
// 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.
//
// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-01-07 20:46:21 +05:00
//
//
//
// File : MeasureGUI_Skeleton.cxx
// Author : Damien COQUERET
// Module : GEOM
2004-12-01 15:39:14 +05:00
// $Header$
2004-01-07 20:46:21 +05:00
#include "MeasureGUI_Skeleton.h"
2004-12-01 15:39:14 +05:00
#include "GEOMBase.h"
#include "GEOM_Displayer.h"
#include "GeometryGUI.h"
#include "LightApp_Application.h"
#include "LightApp_SelectionMgr.h"
#include "SalomeApp_Application.h"
#include "SalomeApp_Tools.h"
#include "SUIT_MessageBox.h"
#include "SUIT_Session.h"
2005-06-10 18:43:15 +06:00
#include "SUIT_OverrideCursor.h"
2004-12-01 15:39:14 +05:00
#include <qlineedit.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qapplication.h>
2004-01-07 20:46:21 +05:00
//=================================================================================
// class : MeasureGUI_Skeleton()
// purpose : Constructs a MeasureGUI_Skeleton which is a child of 'parent', with the
// name 'name' and widget flags set to 'f'.
// The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog.
//=================================================================================
MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI,
QWidget* parent,
const char* name )
2004-12-01 15:39:14 +05:00
: MeasureGUI_Skeleton_QTD( parent, name, false,
WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
myGeomGUI( GUI )
2004-01-07 20:46:21 +05:00
{
2004-12-01 15:39:14 +05:00
mySelBtn = 0;
mySelEdit = 0;
myDisplayer = 0;
myHelpFileName = "";
2004-12-01 15:39:14 +05:00
if ( !name )
setName( "MeasureGUI_Skeleton" );
buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
buttonHelp->setText(tr("GEOM_BUT_HELP"));
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
buttonClose->setAutoDefault( false );
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
GroupMedium->close( TRUE );
resize( 350, 0 );
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ~MeasureGUI_Skeleton()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
{
2004-12-01 15:39:14 +05:00
myGeomGUI->SetActiveDialogBox( 0 );
delete myDisplayer;
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void MeasureGUI_Skeleton::Init()
2004-01-07 20:46:21 +05:00
{
/* init variables */
myGeomGUI->SetActiveDialogBox((QDialog*)this);
/* signals and slots connections */
2004-12-01 15:39:14 +05:00
connect( buttonClose, SIGNAL( clicked() ),
this, SLOT( ClickOnCancel() ) );
connect( buttonHelp, SIGNAL( clicked() ),
this, SLOT( ClickOnHelp() ) );
2004-12-01 15:39:14 +05:00
connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
this, SLOT ( DeactivateActiveDialog() ) );
connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
this, SLOT ( ClickOnCancel() ) );
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
connect( mySelEdit, SIGNAL( returnPressed() ),
this, SLOT( LineEditReturnPressed() ) );
connect( mySelBtn, SIGNAL( clicked() ),
this, SLOT ( SetEditCurrentArgument() ) );
LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
if ( aSel )
connect( aSel, SIGNAL( currentSelectionChanged() ),
this, SLOT ( SelectionIntoArgument() ) ) ;
2004-01-07 20:46:21 +05:00
/* displays Dialog */
2004-12-01 15:39:14 +05:00
RadioButton1->setChecked( TRUE );
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
activateSelection();
SelectionIntoArgument();
show();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ClickOnCancel()
// purpose :
//=================================================================================
void MeasureGUI_Skeleton::ClickOnCancel()
{
2004-12-01 15:39:14 +05:00
close();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// 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 {
SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
QObject::tr("BUT_OK"));
}
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void MeasureGUI_Skeleton::LineEditReturnPressed()
{
/* User name of object input management */
/* If successfull the selection is changed and signal emitted... */
/* so SelectionIntoArgument() is automatically called. */
2004-12-01 15:39:14 +05:00
const QString objectUserName = mySelEdit->text();
QWidget* thisWidget = ( QWidget* )this;
if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
2004-12-01 15:39:14 +05:00
mySelEdit->setText( objectUserName );
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : DeactivateActiveDialog()
// purpose :
//=================================================================================
void MeasureGUI_Skeleton::DeactivateActiveDialog()
{
2004-12-01 15:39:14 +05:00
setEnabled( false );
LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
if ( aSel )
disconnect( aSel, 0, this, 0 );
2004-12-01 15:39:14 +05:00
myGeomGUI->SetActiveDialogBox( 0 );
globalSelection();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void MeasureGUI_Skeleton::ActivateThisDialog()
{
myGeomGUI->EmitSignalDeactivateDialog();
2004-12-01 15:39:14 +05:00
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() ) ) ;
2004-12-01 15:39:14 +05:00
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 );
2004-12-01 15:39:14 +05:00
if( !testResult || aSelectedObject->_is_nil() )
{
mySelEdit->setText( "" );
processObject();
erasePreview();
return;
}
myObj = aSelectedObject;
mySelEdit->setText( GEOMBase::GetName( myObj ) );
processObject();
redisplayPreview();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// 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 );
2004-12-01 15:39:14 +05:00
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;
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : closeEvent()
2004-12-01 15:39:14 +05:00
// purpose : Build presentation for "preview"
//=================================================================================
void MeasureGUI_Skeleton::redisplayPreview()
{
QString aMess;
if ( !isValid( aMess ) )
{
erasePreview( true );
return;
}
erasePreview( false );
try
{
2005-06-10 18:43:15 +06:00
SUIT_OverrideCursor();
2004-12-01 15:39:14 +05:00
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 );
2004-12-01 15:39:14 +05:00
}
}
//=================================================================================
// function : activateSelection
// purpose :
//=================================================================================
void MeasureGUI_Skeleton::activateSelection()
{
globalSelection( GEOM_ALLSHAPES );
}
//=================================================================================
// function : isValid
2004-01-07 20:46:21 +05:00
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
bool MeasureGUI_Skeleton::isValid( QString& )
2004-01-07 20:46:21 +05:00
{
2004-12-01 15:39:14 +05:00
return !myObj->_is_nil();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
//================================================================
// Function : getDisplayer
// Purpose :
//================================================================
GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
{
if ( !myDisplayer )
myDisplayer = new GEOM_Displayer( getStudy() );
2004-12-01 15:39:14 +05:00
return myDisplayer;
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
{
return getGeomEngine()->GetIMeasureOperations( getStudyId() );
}