geom/src/RepairGUI/RepairGUI_GlueDlg.cxx

786 lines
26 KiB
C++
Raw Normal View History

2009-02-13 17:16:39 +05:00
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:39:14 +05:00
//
2009-02-13 17:16:39 +05:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2004-12-01 15:39:14 +05:00
// 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
//
2009-02-13 17:16:39 +05:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-12-01 15:39:14 +05:00
//
2009-02-13 17:16:39 +05:00
// GEOM RepairGUI : GUI for Geometry component
// File : RepairGUI_GlueDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2004-12-01 15:39:14 +05:00
//
#include "RepairGUI_GlueDlg.h"
2005-06-10 18:43:15 +06:00
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <QtxDoubleSpinBox.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Tools.h>
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_MessageBox.h>
#include <SUIT_OverrideCursor.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h>
#include <OCCViewer_ViewModel.h>
#include <SALOME_ListIteratorOfListIO.hxx>
#include <GEOMImpl_Types.hxx>
2004-12-01 15:39:14 +05:00
#include <TCollection_AsciiString.hxx>
2005-08-23 19:10:06 +06:00
#define DEFAULT_TOLERANCE_VALUE 1e-07
2004-12-01 15:39:14 +05:00
//=================================================================================
// class : RepairGUI_GlueDlg()
// purpose : Constructs a RepairGUI_GlueDlg 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.
//=================================================================================
2009-02-13 17:16:39 +05:00
RepairGUI_GlueDlg::RepairGUI_GlueDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
bool modal )
: GEOMBase_Skeleton( theGeometryGUI, parent, modal ),
myCurrConstrId( -1 )
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES" ) ) );
QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES2" ) ));
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "GEOM_GLUE_TITLE" ) );
2004-12-01 15:39:14 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_GLUE_TITLE" ) );
mainFrame()->RadioButton1->setIcon( image0 );
mainFrame()->RadioButton2->setIcon( image2 );
mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->RadioButton3->close();
GroupPoints = new DlgRef_1SelExt( centralWidget() );
GroupPoints->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
GroupPoints->PushButton1->setIcon( image1 );
2004-12-01 15:39:14 +05:00
GroupPoints->LineEdit1->setReadOnly( true );
2009-02-13 17:16:39 +05:00
QLabel* aTolLab = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
myTolEdt = new SalomeApp_DoubleSpinBox( 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, 7, 7, GroupPoints->Box );
2004-12-01 15:39:14 +05:00
myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
2009-02-13 17:16:39 +05:00
QGridLayout* boxLayout = new QGridLayout( GroupPoints->Box );
boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
boxLayout->addWidget( aTolLab, 0, 0 );
boxLayout->addWidget( myTolEdt, 0, 2 );
/***************************************************************/
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
GroupPoints2 = new DlgRef_1SelExt( centralWidget() );
GroupPoints2->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
GroupPoints2->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
GroupPoints2->PushButton1->setIcon( image1 );
GroupPoints2->LineEdit1->setReadOnly( true );
2009-02-13 17:16:39 +05:00
QLabel* aTolLab2 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints2->Box );
myTolEdt2 = new SalomeApp_DoubleSpinBox( GroupPoints2->Box );
initSpinBox( myTolEdt2, 0, 100, 1e-7, 7 );
myTolEdt2->setValue( DEFAULT_TOLERANCE_VALUE );
2009-02-13 17:16:39 +05:00
myDetectBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GLUE_FACES" ) ),
GroupPoints2->Box );
mySubShapesChk = new QCheckBox( tr( "SELECT_FACES" ), GroupPoints2->Box );
boxLayout = new QGridLayout( GroupPoints2->Box );
boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
boxLayout->addWidget( aTolLab2, 0, 0 );
boxLayout->addWidget( myTolEdt2, 0, 2 );
boxLayout->addWidget( myDetectBtn, 1, 0, 1, 3 );
boxLayout->addWidget( mySubShapesChk, 2, 0, 1, 3 );
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupPoints );
layout->addWidget( GroupPoints2 );
2004-12-01 15:39:14 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
setHelpFileName( "glue_faces_operation_page.html" );
// Disable second way of gluing if OCC viewer is not active one
2009-02-13 17:16:39 +05:00
if ( myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
!= OCCViewer_Viewer::Type() )
mainFrame()->RadioButton2->setEnabled( false );
2004-12-01 15:39:14 +05:00
Init();
}
//=================================================================================
// function : ~RepairGUI_GlueDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void RepairGUI_GlueDlg::Init()
{
/* init variables */
myEditCurrentArgument = GroupPoints->LineEdit1;
myObject = GEOM::GEOM_Object::_nil();
//myGeomGUI->SetState( 0 );
//globalSelection( GEOM_COMPOUND );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
mainFrame()->GroupBoxPublish->show();
2004-12-01 15:39:14 +05:00
/* signals and slots connections */
2009-02-13 17:16:39 +05:00
connect( buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( GroupPoints2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( GroupPoints2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
connect( myTolEdt2, SIGNAL( valueChanged( double ) ), this, SLOT( onTolerChanged( double ) ) );
connect( mySubShapesChk, SIGNAL( stateChanged( int ) ), this, SLOT( onSubShapesChk() ) );
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) );
2009-02-13 17:16:39 +05:00
connect( myDetectBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
2004-12-01 15:39:14 +05:00
initName( tr( "GLUE_NEW_OBJ_NAME" ) );
2009-02-13 17:16:39 +05:00
ConstructorsClicked( 0 );
activateSelection();
updateButtonState();
}
//=================================================================================
// function : ConstructorsClicked()
// purpose : Radio button management
//=================================================================================
void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
{
if ( myCurrConstrId == constructorId )
return;
2009-02-13 17:16:39 +05:00
disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
2009-02-13 17:16:39 +05:00
switch ( constructorId ) {
case 0:
GroupPoints2->hide();
GroupPoints->show();
GroupPoints->LineEdit1->setText( "" );
myEditCurrentArgument = GroupPoints->LineEdit1;
if ( myCurrConstrId >= 0 ) {
// i.e. it is not initialisation
// copy tolerance from previous tolerance field
myTolEdt->setValue( myTolEdt2->value() );
}
break;
case 1:
GroupPoints->hide();
GroupPoints2->show();
GroupPoints->LineEdit1->setText( "" );
myEditCurrentArgument = GroupPoints2->LineEdit1;
2009-02-13 17:16:39 +05:00
if ( myCurrConstrId >= 0 ) {
// i.e. it is not initialisation
// copy tolerance from previous tolerance field
myTolEdt2->setValue( myTolEdt->value() );
mySubShapesChk->setChecked( false );
clearTemporary();
}
2009-02-13 17:16:39 +05:00
break;
}
2009-02-13 17:16:39 +05:00
myCurrConstrId = constructorId;
myEditCurrentArgument->setFocus();
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) );
qApp->processEvents();
updateGeometry();
2009-02-13 17:16:39 +05:00
resize( minimumSizeHint() );
displayPreview();
updateButtonState();
activateSelection();
SelectionIntoArgument();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : ClickOnOk()
// purpose : Same than click on apply but close this dialog.
//=================================================================================
void RepairGUI_GlueDlg::ClickOnOk()
{
if ( ClickOnApply() )
ClickOnCancel();
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
bool RepairGUI_GlueDlg::ClickOnApply()
{
2005-01-20 11:24:17 +05:00
if ( !onAcceptLocal() )
2004-12-01 15:39:14 +05:00
return false;
initName();
//GroupPoints->LineEdit1->setText("");
//myObject = GEOM::GEOM_Object::_nil();
2004-12-01 15:39:14 +05:00
//globalSelection( GEOM_COMPOUND );
ConstructorsClicked( getConstructorId() );
2004-12-01 15:39:14 +05:00
return true;
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection
//=================================================================================
void RepairGUI_GlueDlg::SelectionIntoArgument()
{
if ( mySubShapesChk->isChecked() && getConstructorId() == 1 ) {
updateButtonState();
return;
}
2004-12-01 15:39:14 +05:00
erasePreview();
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText( "" );
2004-12-01 15:39:14 +05:00
myObject = GEOM::GEOM_Object::_nil();
2009-02-13 17:16:39 +05:00
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
if ( aSelList.Extent() == 1 ) {
Handle(SALOME_InteractiveObject) anIO = aSelList.First();
2004-12-01 15:39:14 +05:00
Standard_Boolean aRes;
myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
if ( aRes )
myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
}
updateButtonState();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void RepairGUI_GlueDlg::SetEditCurrentArgument()
{
const QObject* send = sender();
if ( send == GroupPoints->PushButton1 || send == GroupPoints2->PushButton1 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument->setFocus();
SelectionIntoArgument();
}
}
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void RepairGUI_GlueDlg::LineEditReturnPressed()
{
const QObject* send = sender();
2009-02-13 17:16:39 +05:00
if ( send == GroupPoints->LineEdit1 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = GroupPoints->LineEdit1;
GEOMBase_Skeleton::LineEditReturnPressed();
}
2009-02-13 17:16:39 +05:00
else if ( send == GroupPoints2->LineEdit1 ) {
myEditCurrentArgument = GroupPoints2->LineEdit1;
GEOMBase_Skeleton::LineEditReturnPressed();
}
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void RepairGUI_GlueDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) );
2004-12-01 15:39:14 +05:00
//GroupPoints->LineEdit1->setText("");
//GroupPoints2->LineEdit1->setText("");
//myObject = GEOM::GEOM_Object::_nil();
2004-12-01 15:39:14 +05:00
//myGeomGUI->SetState( 0 );
//globalSelection( GEOM_COMPOUND );
activateSelection();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : enterEvent()
// purpose : Mouse enter onto the dialog to activate it
//=================================================================================
2009-02-13 17:16:39 +05:00
void RepairGUI_GlueDlg::enterEvent( QEvent* )
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
if ( !mainFrame()->GroupConstructors->isEnabled() )
2004-12-01 15:39:14 +05:00
ActivateThisDialog();
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
{
return getGeomEngine()->GetIShapesOperations( getStudyId() );
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool RepairGUI_GlueDlg::isValid( QString& msg )
{
2009-02-13 17:16:39 +05:00
bool ok = true;
double v = 0;
switch ( getConstructorId() )
{
case 0:
v = myTolEdt->value();
ok = myTolEdt->isValid( msg, !IsPreview() );
break;
case 1:
v = myTolEdt2->value();
ok = myTolEdt2->isValid( msg, !IsPreview() );
break;
}
return !myObject->_is_nil() && ( IsPreview() || v > 0. ) && ok;
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
bool RepairGUI_GlueDlg::execute( ObjectList& objects )
{
bool aResult = false;
objects.clear();
2009-02-13 17:16:39 +05:00
switch ( getConstructorId() ) {
case 0:
{
GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
2009-02-13 17:16:39 +05:00
( getOperation() )->MakeGlueFaces( myObject, myTolEdt->value(), true );
aResult = !anObj->_is_nil();
2009-02-13 17:16:39 +05:00
if ( aResult && !IsPreview() )
{
QStringList aParameters;
aParameters << myTolEdt->text();
anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
objects.push_back( anObj._retn() );
2009-02-13 17:16:39 +05:00
}
break;
}
case 1:
{
2009-02-13 17:16:39 +05:00
if ( IsPreview() ) {
// if this method is used for displaying preview then we must detect glue faces only
ObjectList::iterator anIter;
2009-02-13 17:16:39 +05:00
for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
objects.push_back( GEOM::GEOM_Object::_duplicate( *anIter ) );
return myTmpObjs.size() ? true : false;
} // IsPreview
// Make glue face by list.
// Iterate through myTmpObjs and verifies where each object is currently selected or not.
QMap<QString, char> selected;
// Get names of selected objects
2009-02-13 17:16:39 +05:00
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
SALOME_ListIteratorOfListIO it (aSelList);
for (; it.More(); it.Next())
2009-02-13 17:16:39 +05:00
selected.insert(it.Value()->getName(), 0);
// Iterate through result and select objects with names from selection
// ObjectList toRemoveFromEnggine;
ObjectList toGlue;
ObjectList::iterator anIter;
2009-02-13 17:16:39 +05:00
for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
if ( selected.contains( myGeomGUI->getApp()->orb()->object_to_string(*anIter) ) )
2009-02-13 17:16:39 +05:00
toGlue.push_back( *anIter );
}
2009-02-13 17:16:39 +05:00
// make glue faces
GEOM::ListOfGO_var aListForGlue = new GEOM::ListOfGO();
aListForGlue->length( toGlue.size() );
ObjectList::iterator anIter3 = toGlue.begin();
for ( int i = 0; anIter3 != toGlue.end(); ++anIter3, ++i )
aListForGlue[ i ] = *anIter3;
GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
( getOperation() )->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
aResult = !anObj->_is_nil();
if ( aResult )
2009-02-13 17:16:39 +05:00
{
if ( !IsPreview() )
{
QStringList aParameters;
aParameters << myTolEdt2->text();
anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
}
objects.push_back( anObj._retn() );
2009-02-13 17:16:39 +05:00
}
// Remove from engine useless objects
clearTemporary();
updateButtonState();
break;
} // case 1
} // switch
2004-12-01 15:39:14 +05:00
return aResult;
}
2005-01-20 11:24:17 +05:00
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : restoreSubShapes
// purpose :
//=================================================================================
void RepairGUI_GlueDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
SALOMEDS::SObject_ptr theSObject )
{
if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
GEOM::find_shape_method aFindMethod = GEOM::FSM_GetInPlace;
if ( getConstructorId() == 0 ) // MakeGlueFaces
aFindMethod = GEOM::FSM_GetInPlaceByHistory;
// empty list of arguments means that all arguments should be restored
getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
aFindMethod, /*theInheritFirstArg=*/true );
}
}
2005-01-20 11:24:17 +05:00
//================================================================
// Function : clearShapeBufferLocal
// Purpose :
//================================================================
void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
{
if ( CORBA::is_nil( theObj ) )
return;
CORBA::String_var IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj );
TCollection_AsciiString asciiIOR( (char *)( IOR.in() ) );
myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
2005-01-20 11:24:17 +05:00
if ( !getStudy() || !( getStudy()->studyDS() ) )
2005-01-20 11:24:17 +05:00
return;
_PTR(Study) aStudy = getStudy()->studyDS();
2009-02-13 17:16:39 +05:00
_PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR.in() ) ) );
if ( !aSObj )
2005-01-20 11:24:17 +05:00
return;
_PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
2005-01-20 11:24:17 +05:00
for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
_PTR(GenericAttribute) anAttr;
2005-01-20 11:24:17 +05:00
if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
_PTR(AttributeIOR) anIOR ( anAttr );
TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
2005-01-20 11:24:17 +05:00
}
}
}
//================================================================
// Function : onAccept
// Purpose : This method should be called from dialog's slots onOk() and onApply()
// It perfroms user input validation, then it
// performs a proper operation and manages transactions, etc.
//================================================================
bool RepairGUI_GlueDlg::onAcceptLocal()
2005-01-20 11:24:17 +05:00
{
if ( !getStudy() || !( getStudy()->studyDS() ) )
return false;
_PTR(Study) aStudy = getStudy()->studyDS();
2005-01-20 11:24:17 +05:00
bool aLocked = aStudy->GetProperties()->IsLocked();
2009-02-13 17:16:39 +05:00
if ( aLocked ) {
2005-01-20 11:24:17 +05:00
MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
2009-02-13 17:16:39 +05:00
SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), tr( "WRN_STUDY_LOCKED" ), tr( "BUT_OK" ) );
2005-01-20 11:24:17 +05:00
return false;
}
QString msg;
2009-02-13 17:16:39 +05:00
if ( !isValid( msg ) ) {
2005-01-20 11:24:17 +05:00
showError( msg );
return false;
}
erasePreview( false );
2009-02-13 17:16:39 +05:00
try {
if ( openCommand() ) {
2005-06-10 18:43:15 +06:00
SUIT_OverrideCursor wc;
2009-02-13 17:16:39 +05:00
myGeomGUI->getApp()->putInfo( "" );
2005-01-20 11:24:17 +05:00
ObjectList objects;
2009-02-13 17:16:39 +05:00
if ( !execute( objects ) ) {
wc.suspend();
2005-06-10 18:43:15 +06:00
abortCommand();
showError();
2005-01-20 11:24:17 +05:00
}
2009-02-13 17:16:39 +05:00
else {
const int nbObjs = objects.size();
2009-02-13 17:16:39 +05:00
for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
QString aName = getNewObjectName();
if ( nbObjs > 1 ) {
if ( aName.isEmpty() )
aName = getPrefix( *it );
aName = GEOMBase::GetDefaultName( aName );
2005-01-20 11:24:17 +05:00
}
2009-02-13 17:16:39 +05:00
else {
// PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
if ( aName.isEmpty() )
aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
}
2009-02-13 17:16:39 +05:00
addInStudy( *it, aName.toLatin1().data() );
display( *it, false );
}
2009-02-13 17:16:39 +05:00
if ( nbObjs ) {
commitCommand();
updateObjBrowser();
2009-02-13 17:16:39 +05:00
myGeomGUI->getApp()->putInfo( QObject::tr("GEOM_PRP_DONE") );
}
2009-02-13 17:16:39 +05:00
else {
abortCommand();
2005-01-20 11:24:17 +05:00
}
// JFA 28.12.2004 BEGIN // To enable warnings
2009-02-13 17:16:39 +05:00
if ( !getOperation()->_is_nil() ) {
if ( !getOperation()->IsDone() ) {
2005-06-10 18:43:15 +06:00
wc.suspend();
QString msgw = QObject::tr( getOperation()->GetErrorCode() );
2009-02-13 17:16:39 +05:00
SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), msgw, tr( "BUT_OK" ) );
2005-01-20 11:24:17 +05:00
}
}
// JFA 28.12.2004 END
}
}
}
2009-02-13 17:16:39 +05:00
catch( const SALOME::SALOME_Exception& e ) {
SalomeApp_Tools::QtCatchCorbaException( e );
2005-01-20 11:24:17 +05:00
abortCommand();
}
updateViewer();
activateSelection();
updateButtonState();
2005-01-20 11:24:17 +05:00
return true;
}
//=================================================================================
// function : onDetect
// purpose :
//=================================================================================
void RepairGUI_GlueDlg::onDetect()
{
clearTemporary();
QString msg;
if ( !isValid( msg ) ) {
showError( msg );
return;
}
2009-02-13 17:16:39 +05:00
buttonOk()->setEnabled( false );
buttonApply()->setEnabled( false );
globalSelection( GEOM_ALLSHAPES );
GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow
( getOperation() )->GetGlueFaces( myObject, myTolEdt2->value() );
2009-02-13 17:16:39 +05:00
for ( int i = 0, n = aList->length(); i < n; i++ )
myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
2009-02-13 17:16:39 +05:00
if ( myTmpObjs.size() > 0 ) {
msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.size() );
mySubShapesChk->setChecked( true );
}
2009-02-13 17:16:39 +05:00
else {
msg = tr( "THERE_ARE_NO_FACES_FOR_GLUING" );
}
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) ) ;
SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, tr( "Close" ) );
updateButtonState();
activateSelection();
}
//=================================================================================
// function : activateSelection
// purpose : Redisplay preview and Activate selection
//=================================================================================
void RepairGUI_GlueDlg::activateSelection()
{
2009-02-13 17:16:39 +05:00
erasePreview( false );
int anId = getConstructorId();
2009-02-13 17:16:39 +05:00
if ( anId == 0 ) {
// Case of whole gluing
disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) );
globalSelection( GEOM_ALLSHAPES );
2009-02-13 17:16:39 +05:00
if ( myObject->_is_nil())
SelectionIntoArgument();
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) );
}
2009-02-13 17:16:39 +05:00
else {
// Second case of gluing
if ( !mySubShapesChk->isChecked() )
globalSelection( GEOM_ALLSHAPES );
2009-02-13 17:16:39 +05:00
else {
displayPreview( true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
2009-02-13 17:16:39 +05:00
disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) ) ;
globalSelection( GEOM_PREVIEW );
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
this, SLOT( SelectionIntoArgument() ) ) ;
}
}
updateViewer();
}
//=================================================================================
// function : updateButtonState
// purpose : Update button state
//=================================================================================
void RepairGUI_GlueDlg::updateButtonState()
{
int anId = getConstructorId();
bool hasMainObj = !myObject->_is_nil();
2009-02-13 17:16:39 +05:00
if ( anId == 0 ) {
buttonOk()->setEnabled( hasMainObj );
buttonApply()->setEnabled( hasMainObj );
}
else
{
2009-02-13 17:16:39 +05:00
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
bool wasSelected = false;
2009-02-13 17:16:39 +05:00
SALOME_ListIteratorOfListIO it (aSelList);
if (it.More() > 0)
wasSelected = true;
bool wasDetected = myTmpObjs.size() ? true : false;
2009-02-13 17:16:39 +05:00
buttonOk()->setEnabled( hasMainObj && wasDetected && wasSelected );
buttonApply()->setEnabled( hasMainObj && wasDetected && wasSelected );
mySubShapesChk->setEnabled( hasMainObj && wasDetected );
myDetectBtn->setEnabled( hasMainObj );
if ( !hasMainObj || !wasDetected )
mySubShapesChk->setChecked( false );
}
}
//=================================================================================
// function : clearTemporary
// purpose : Remove temporary objects from engine
//=================================================================================
void RepairGUI_GlueDlg::clearTemporary()
{
ObjectList::iterator anIter;
2009-02-13 17:16:39 +05:00
for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
getGeomEngine()->RemoveObject(*anIter);
myTmpObjs.clear();
}
//=================================================================================
// function : onTolerChanged
// purpose : Remove temporary objects from engine
//=================================================================================
void RepairGUI_GlueDlg::onTolerChanged( double /*theVal*/ )
{
clearTemporary();
activateSelection();
updateButtonState();
}
//=================================================================================
// function : onSubShapesChk
// purpose : Update selection mode
//=================================================================================
void RepairGUI_GlueDlg::onSubShapesChk()
{
if ( !mySubShapesChk->isChecked() )
clearTemporary();
activateSelection();
updateButtonState();
}
//=================================================================================
// function : ClickOnCancel
// purpose : Remove temporary objects from engine and call method of base class
//=================================================================================
void RepairGUI_GlueDlg::ClickOnCancel()
{
clearTemporary();
GEOMBase_Skeleton::ClickOnCancel();
}