geom/src/BasicGUI/BasicGUI_CircleDlg.cxx

427 lines
16 KiB
C++
Raw Normal View History

2007-10-15 10:41:03 +00:00
// GEOM GEOMGUI : GUI for Geometry component
2004-01-07 15:46:21 +00:00
//
2007-10-15 10:41:03 +00:00
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2004-01-07 15:46:21 +00:00
//
2007-10-15 10:41:03 +00:00
// 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.
2004-01-07 15:46:21 +00:00
//
2007-10-15 10:41:03 +00:00
// 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.
2004-01-07 15:46:21 +00:00
//
2007-10-15 10:41:03 +00:00
// 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
2004-01-07 15:46:21 +00:00
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-01-07 15:46:21 +00:00
//
2007-10-15 10:41:03 +00:00
// File : BasicGUI_CircleDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2004-01-07 15:46:21 +00:00
//
#include "BasicGUI_CircleDlg.h"
2007-10-15 10:41:03 +00:00
#include <GEOM_DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
2007-07-09 07:39:05 +00:00
2007-10-15 10:41:03 +00:00
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
2007-10-15 10:41:03 +00:00
#include <GEOMImpl_Types.hxx>
2004-06-16 15:24:55 +00:00
2004-01-07 15:46:21 +00:00
//=================================================================================
// class : BasicGUI_CircleDlg()
// purpose : Constructs a BasicGUI_CircleDlg 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.
//=================================================================================
2007-10-15 10:41:03 +00:00
BasicGUI_CircleDlg::BasicGUI_CircleDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
2007-10-15 14:16:21 +00:00
bool modal, Qt::WindowFlags fl )
2007-10-16 14:15:43 +00:00
: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
2004-01-07 15:46:21 +00:00
{
2007-10-15 10:41:03 +00:00
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_PV" ) ) );
QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_PNTS" ) ) );
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
2004-01-07 15:46:21 +00:00
2007-10-15 10:41:03 +00:00
setWindowTitle( tr( "GEOM_CIRCLE_TITLE" ) );
2004-01-07 15:46:21 +00:00
/***************************************************************/
2007-10-15 10:41:03 +00:00
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CIRCLE" ) );
mainFrame()->RadioButton1->setIcon( image0 );
mainFrame()->RadioButton2->setIcon( image2 );
mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->RadioButton3->close();
GroupPntVecR = new DlgRef_2Sel1Spin( centralWidget() );
GroupPntVecR->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
2004-12-01 10:39:14 +00:00
2007-10-15 10:41:03 +00:00
GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
GroupPntVecR->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
GroupPntVecR->PushButton1->setIcon( image1 );
GroupPntVecR->PushButton2->setIcon( image1 );
2004-12-01 10:39:14 +00:00
GroupPntVecR->LineEdit1->setReadOnly( true );
GroupPntVecR->LineEdit2->setReadOnly( true );
2007-10-15 10:41:03 +00:00
Group3Pnts = new DlgRef_3Sel( centralWidget() );
2007-07-09 07:39:05 +00:00
2007-10-15 10:41:03 +00:00
Group3Pnts->GroupBox1->setTitle( tr( "GEOM_3_POINTS" ) );
Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) );
Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) );
Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) );
Group3Pnts->PushButton1->setIcon( image1 );
Group3Pnts->PushButton2->setIcon( image1 );
Group3Pnts->PushButton3->setIcon( image1 );
2004-12-01 10:39:14 +00:00
Group3Pnts->LineEdit1->setReadOnly( true );
Group3Pnts->LineEdit2->setReadOnly( true );
Group3Pnts->LineEdit3->setReadOnly( true );
2007-10-15 10:41:03 +00:00
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupPntVecR );
layout->addWidget( Group3Pnts );
2004-01-07 15:46:21 +00:00
/***************************************************************/
2007-10-15 10:41:03 +00:00
setHelpFileName( "circle.htm" );
2004-01-07 15:46:21 +00:00
Init();
}
//=================================================================================
// function : ~BasicGUI_CircleDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void BasicGUI_CircleDlg::Init()
{
/* init variables */
2004-12-01 10:39:14 +00:00
myEditCurrentArgument = GroupPntVecR->LineEdit1;
2004-01-07 15:46:21 +00:00
2004-12-01 10:39:14 +00:00
myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
2004-01-07 15:46:21 +00:00
// myGeomGUI->SetState( 0 );
2004-01-07 15:46:21 +00:00
/* Get setting of step value from file configuration */
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2007-10-15 10:41:03 +00:00
double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
2004-01-07 15:46:21 +00:00
/* min, max, step and decimals for spin boxes & initial values */
2007-10-15 10:41:03 +00:00
initSpinBox( GroupPntVecR->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 );
GroupPntVecR->SpinBox_DX->setValue( 100 );
2004-01-07 15:46:21 +00:00
/* signals and slots connections */
2007-10-15 10:41:03 +00:00
connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
2004-12-01 10:39:14 +00:00
2007-10-15 10:41:03 +00:00
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
2004-01-07 15:46:21 +00:00
2007-10-15 10:41:03 +00:00
connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
2004-01-07 15:46:21 +00:00
2007-10-15 10:41:03 +00:00
connect( GroupPntVecR->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( GroupPntVecR->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
2004-01-07 15:46:21 +00:00
2007-10-15 10:41:03 +00:00
connect( GroupPntVecR->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
connect( GroupPntVecR->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
connect( GroupPntVecR->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT(ValueChangedInSpinBox() ) );
// VSR: TODO ->>
connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPntVecR->SpinBox_DX, SLOT( SetStep( double ) ) );
// <<-
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) ) ;
2004-01-07 15:46:21 +00:00
2007-10-15 10:41:03 +00:00
initName( tr( "GEOM_CIRCLE" ) );
2004-01-07 15:46:21 +00:00
2004-12-01 10:39:14 +00:00
ConstructorsClicked( 0 );
2004-01-07 15:46:21 +00:00
}
2004-12-01 10:39:14 +00:00
//=================================================================================
// function : ConstructorsClicked()
// purpose : Radio button management
//=================================================================================
void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
{
2007-10-15 10:41:03 +00:00
disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
2004-12-01 10:39:14 +00:00
myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
2007-10-15 10:41:03 +00:00
switch ( constructorId ) {
case 0:
{
Group3Pnts->hide();
GroupPntVecR->show();
myEditCurrentArgument = GroupPntVecR->LineEdit1;
GroupPntVecR->LineEdit1->setText( "" );
GroupPntVecR->LineEdit2->setText( "" );
break;
}
case 1:
{
GroupPntVecR->hide();
2007-10-15 10:41:03 +00:00
Group3Pnts->show();
myEditCurrentArgument = Group3Pnts->LineEdit1;
2007-10-15 10:41:03 +00:00
Group3Pnts->LineEdit1->setText( "" );
Group3Pnts->LineEdit2->setText( "" );
Group3Pnts->LineEdit3->setText( "" );
break;
2007-10-15 10:41:03 +00:00
}
2004-12-01 10:39:14 +00:00
}
2007-10-15 10:41:03 +00:00
qApp->processEvents();
updateGeometry();
resize( minimumSize() );
2004-12-01 10:39:14 +00:00
myEditCurrentArgument->setFocus();
globalSelection( GEOM_POINT );
2007-10-15 10:41:03 +00:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
2004-12-01 10:39:14 +00:00
}
2004-01-07 15:46:21 +00:00
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void BasicGUI_CircleDlg::ClickOnOk()
{
2004-12-01 10:39:14 +00:00
if ( ClickOnApply() )
ClickOnCancel();
2004-01-07 15:46:21 +00:00
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
2004-12-01 10:39:14 +00:00
bool BasicGUI_CircleDlg::ClickOnApply()
2004-01-07 15:46:21 +00:00
{
2004-12-01 10:39:14 +00:00
if ( !onAccept() )
return false;
2004-01-07 15:46:21 +00:00
2004-12-01 10:39:14 +00:00
initName();
ConstructorsClicked( getConstructorId() );
return true;
2004-01-07 15:46:21 +00:00
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection as changed or other case
//=================================================================================
void BasicGUI_CircleDlg::SelectionIntoArgument()
{
2007-10-15 10:41:03 +00:00
myEditCurrentArgument->setText( "" );
2004-01-07 15:46:21 +00:00
2007-10-15 10:41:03 +00:00
if ( IObjectCount() != 1 ) {
2004-12-01 10:39:14 +00:00
if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
2004-01-07 15:46:21 +00:00
return;
}
2004-12-01 10:39:14 +00:00
// nbSel == 1
Standard_Boolean aRes = Standard_False;
GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
2007-10-15 10:41:03 +00:00
if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
2004-12-01 10:39:14 +00:00
myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
2004-01-07 15:46:21 +00:00
}
2004-12-01 10:39:14 +00:00
displayPreview();
2004-01-07 15:46:21 +00:00
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void BasicGUI_CircleDlg::SetEditCurrentArgument()
{
QPushButton* send = (QPushButton*)sender();
2004-12-01 10:39:14 +00:00
if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
myEditCurrentArgument->setFocus();
if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
globalSelection( GEOM_LINE );
else
globalSelection( GEOM_POINT );
SelectionIntoArgument();
2004-01-07 15:46:21 +00:00
}
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void BasicGUI_CircleDlg::LineEditReturnPressed()
{
QLineEdit* send = (QLineEdit*)sender();
2004-12-01 10:39:14 +00:00
if ( send == GroupPntVecR->LineEdit1 ||
send == GroupPntVecR->LineEdit2 ||
send == Group3Pnts->LineEdit1 ||
send == Group3Pnts->LineEdit2 ||
2007-10-15 10:41:03 +00:00
send == Group3Pnts->LineEdit3 ) {
2004-12-01 10:39:14 +00:00
myEditCurrentArgument = send;
GEOMBase_Skeleton::LineEditReturnPressed();
}
2004-01-07 15:46:21 +00:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void BasicGUI_CircleDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
2004-12-01 10:39:14 +00:00
globalSelection( GEOM_POINT );
2007-10-15 10:41:03 +00:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
2004-12-01 10:39:14 +00:00
// myGeomGUI->SetState( 0 );
2004-12-01 10:39:14 +00:00
ConstructorsClicked( getConstructorId() );
2004-01-07 15:46:21 +00:00
}
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
2007-10-15 10:41:03 +00:00
void BasicGUI_CircleDlg::enterEvent( QEvent* )
2004-01-07 15:46:21 +00:00
{
2007-10-15 10:41:03 +00:00
if ( !mainFrame()->GroupConstructors->isEnabled() )
2004-12-01 10:39:14 +00:00
ActivateThisDialog();
2004-01-07 15:46:21 +00:00
}
2004-12-01 10:39:14 +00:00
//=================================================================================
// function : DeactivateActiveDialog()
// purpose : public slot to deactivate if active
//=================================================================================
void BasicGUI_CircleDlg::DeactivateActiveDialog()
{
// myGeomGUI->SetState( -1 );
2004-12-01 10:39:14 +00:00
GEOMBase_Skeleton::DeactivateActiveDialog();
}
2004-01-07 15:46:21 +00:00
//=================================================================================
// function : ValueChangedInSpinBox()
// purpose :
//=================================================================================
2004-12-01 10:39:14 +00:00
void BasicGUI_CircleDlg::ValueChangedInSpinBox()
2004-01-07 15:46:21 +00:00
{
2004-12-01 10:39:14 +00:00
displayPreview();
2004-01-07 15:46:21 +00:00
}
2004-12-01 10:39:14 +00:00
//=================================================================================
// function : getRadius()
// purpose :
//=================================================================================
double BasicGUI_CircleDlg::getRadius() const
{
2007-10-15 10:41:03 +00:00
return GroupPntVecR->SpinBox_DX->value();
2004-12-01 10:39:14 +00:00
}
2004-01-07 15:46:21 +00:00
//=================================================================================
2004-12-01 10:39:14 +00:00
// function : createOperation
2004-01-07 15:46:21 +00:00
// purpose :
//=================================================================================
2004-12-01 10:39:14 +00:00
GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
2004-01-07 15:46:21 +00:00
{
return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
2004-12-01 10:39:14 +00:00
}
//=================================================================================
// function : isEqual
// purpose : it may also be needed to check for min distance between gp_Pnt-s...
//=================================================================================
static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
{
return thePnt1->_is_equivalent( thePnt2 );
2004-12-01 10:39:14 +00:00
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool BasicGUI_CircleDlg::isValid( QString& msg )
{
const int id = getConstructorId();
if ( id == 0 )
return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
else if ( id == 1 )
return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
!isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
return false;
2004-12-01 10:39:14 +00:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
bool BasicGUI_CircleDlg::execute( ObjectList& objects )
{
bool res = false;
2004-12-01 10:39:14 +00:00
GEOM::GEOM_Object_var anObj;
2007-10-15 10:41:03 +00:00
switch ( getConstructorId() ) {
2004-12-01 10:39:14 +00:00
case 0 :
anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
res = true;
break;
case 1 :
anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
res = true;
break;
2004-01-07 15:46:21 +00:00
}
2004-12-01 10:39:14 +00:00
if ( !anObj->_is_nil() )
objects.push_back( anObj._retn() );
2004-12-01 10:39:14 +00:00
return res;
}
//=================================================================================
// function : closeEvent
// purpose :
//=================================================================================
void BasicGUI_CircleDlg::closeEvent( QCloseEvent* e )
{
GEOMBase_Skeleton::closeEvent( e );
2004-01-07 15:46:21 +00:00
}