geom/src/RepairGUI/RepairGUI_SewingDlg.cxx

361 lines
12 KiB
C++
Raw Normal View History

2014-02-18 12:44:41 +06:00
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06: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
2014-02-18 12:44:41 +06:00
// version 2.1 of the License, or (at your option) any later version.
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06: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-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06: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-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : RepairGUI_SewingDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2004-01-07 20:46:21 +05:00
//
#include "RepairGUI_SewingDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
2012-08-09 13:58:02 +06:00
#include <SalomeApp_DoubleSpinBox.h>
2009-02-13 17:16:39 +05:00
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <SUIT_Session.h>
#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_Types.hxx>
2004-12-01 15:39:14 +05:00
#include <TopAbs.hxx>
#include <TColStd_MapOfInteger.hxx>
2004-12-01 15:39:14 +05:00
#define DEFAULT_TOLERANCE_VALUE 1e-07
2004-01-07 20:46:21 +05:00
//=================================================================================
// class : RepairGUI_SewingDlg()
2004-12-01 15:39:14 +05:00
// purpose : Constructs a RepairGUI_SewingDlg which is a child of 'parent', with the
2004-01-07 20:46:21 +05:00
// 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_SewingDlg::RepairGUI_SewingDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
2012-08-09 13:58:02 +06:00
bool modal )
2009-02-13 17:16:39 +05:00
: GEOMBase_Skeleton( theGeometryGUI, parent, modal )
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SEWING" ) ) );
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "GEOM_SEWING_TITLE" ) );
2004-01-07 20:46:21 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SEWING_TITLE" ) );
mainFrame()->RadioButton1->setIcon( image0 );
mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->RadioButton3->close();
GroupPoints = new DlgRef_1SelExt( centralWidget() );
GroupPoints->GroupBox1->setTitle( tr( "GEOM_SEWING" ) );
GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPES" ) );
2009-02-13 17:16:39 +05:00
GroupPoints->PushButton1->setIcon( image1 );
2004-12-01 15:39:14 +05:00
GroupPoints->LineEdit1->setReadOnly( true );
2009-02-13 17:16:39 +05:00
QGridLayout* aLay = new QGridLayout( GroupPoints->Box );
aLay->setMargin( 0 ); aLay->setSpacing( 6 );
myAllowNonManifoldChk = new QCheckBox (tr("GEOM_ALLOW_NON_MANIFOLD"), GroupPoints->Box);
2012-08-09 13:58:02 +06:00
myTolEdt = new SalomeApp_DoubleSpinBox( GroupPoints->Box );
initSpinBox( myTolEdt, 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, "len_tol_precision" );
2004-12-01 15:39:14 +05:00
myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
2009-02-13 17:16:39 +05:00
QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GEOM_FREE_BOUNDARIES" ) ),
2012-08-09 13:58:02 +06:00
GroupPoints->Box );
aLay->addWidget( myAllowNonManifoldChk, 0, 0 );
aLay->addWidget( aLbl1, 1, 0 );
aLay->addWidget( myTolEdt, 1, 1 );
aLay->addWidget( myFreeBoundBtn, 2, 0, 1, 2 );
2009-02-13 17:16:39 +05:00
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupPoints );
2004-01-07 20:46:21 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
setHelpFileName( "sewing_operation_page.html" );
2004-01-07 20:46:21 +05:00
Init();
}
//=================================================================================
// function : ~RepairGUI_SewingDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
RepairGUI_SewingDlg::~RepairGUI_SewingDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void RepairGUI_SewingDlg::Init()
{
/* init variables */
myEditCurrentArgument = GroupPoints->LineEdit1;
myObjects.clear();
2004-01-07 20:46:21 +05:00
//myGeomGUI->SetState( 0 );
2004-12-01 15:39:14 +05:00
initSelection();
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
myClosed = -1;
myOpen = -1;
2012-08-09 13:58:02 +06:00
2004-01-07 20:46:21 +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() ) );
2004-01-07 20:46:21 +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-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
2012-08-09 13:58:02 +06:00
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
connect( myFreeBoundBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
initName( tr( "SEWING_NEW_OBJ_NAME" ) );
2012-08-09 13:58:02 +06:00
resize(100,100);
SelectionIntoArgument();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ClickOnOk()
2004-12-01 15:39:14 +05:00
// purpose : Same than click on apply but close this dialog.
2004-01-07 20:46:21 +05:00
//=================================================================================
void RepairGUI_SewingDlg::ClickOnOk()
{
2012-08-09 13:58:02 +06:00
setIsApplyAndClose( true );
2004-12-01 15:39:14 +05:00
if ( ClickOnApply() )
ClickOnCancel();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
bool RepairGUI_SewingDlg::ClickOnApply()
2004-01-07 20:46:21 +05:00
{
2004-12-01 15:39:14 +05:00
if ( !onAccept() )
2012-08-09 13:58:02 +06:00
return false;
2004-12-01 15:39:14 +05:00
initName();
2009-02-13 17:16:39 +05:00
GroupPoints->LineEdit1->setText( "" );
myObjects.clear();
2004-12-01 15:39:14 +05:00
initSelection();
return true;
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : SelectionIntoArgument()
2004-12-01 15:39:14 +05:00
// purpose : Called when selection
2004-01-07 20:46:21 +05:00
//=================================================================================
void RepairGUI_SewingDlg::SelectionIntoArgument()
{
2004-12-01 15:39:14 +05:00
erasePreview();
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText( "" );
myObjects.clear();
2004-12-01 15:39:14 +05:00
myObjects = getSelected( TopAbs_SHAPE, -1 );
2009-02-13 17:16:39 +05:00
if ( !myObjects.isEmpty() ) {
QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
myEditCurrentArgument->setText( aName );
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void RepairGUI_SewingDlg::SetEditCurrentArgument()
{
2004-12-01 15:39:14 +05:00
const QObject* send = sender();
2009-02-13 17:16:39 +05:00
if ( send == GroupPoints->PushButton1 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument->setFocus();
SelectionIntoArgument();
}
}
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void RepairGUI_SewingDlg::LineEditReturnPressed()
{
const QObject* send = sender();
2009-02-13 17:16:39 +05:00
if( send == GroupPoints->LineEdit1 ) {
2004-01-07 20:46:21 +05:00
myEditCurrentArgument = GroupPoints->LineEdit1;
2004-12-01 15:39:14 +05:00
GEOMBase_Skeleton::LineEditReturnPressed();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void RepairGUI_SewingDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
2009-02-13 17:16:39 +05:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
2012-08-09 13:58:02 +06:00
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
GroupPoints->LineEdit1->setText( "" );
myObjects.clear();
2004-12-01 15:39:14 +05:00
myClosed = -1;
myOpen = -1;
//myGeomGUI->SetState( 0 );
2004-12-01 15:39:14 +05:00
initSelection();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : enterEvent()
2004-12-01 15:39:14 +05:00
// purpose : Mouse enter onto the dialog to activate it
2004-01-07 20:46:21 +05:00
//=================================================================================
2009-02-13 17:16:39 +05:00
void RepairGUI_SewingDlg::enterEvent( QEvent* )
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
if ( !mainFrame()->GroupConstructors->isEnabled() )
2004-12-01 15:39:14 +05:00
ActivateThisDialog();
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr RepairGUI_SewingDlg::createOperation()
{
return getGeomEngine()->GetIHealingOperations( getStudyId() );
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool RepairGUI_SewingDlg::isValid( QString& msg )
{
myClosed = -1;
2009-02-13 17:16:39 +05:00
bool ok = myTolEdt->isValid( msg, !IsPreview() );
return !myObjects.isEmpty() && ( IsPreview() || myTolEdt->value() > 0. ) && ok;
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
bool RepairGUI_SewingDlg::execute( ObjectList& objects )
{
bool aResult = false;
2012-08-09 13:58:02 +06:00
GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
objList->length( myObjects.count() );
for ( int i = 0; i < myObjects.count(); ++i )
objList[i] = myObjects[i].copy();
2009-02-13 17:16:39 +05:00
if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
2004-12-01 15:39:14 +05:00
GEOM::ListOfGO_var aClosed, anOpen;
aResult = anOper->GetFreeBoundary( objList, aClosed, anOpen );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if ( aResult ) {
2004-12-01 15:39:14 +05:00
myClosed = aClosed->length();
myOpen = anOpen->length();
int i;
for ( i = 0; i < myClosed; i++ )
2012-08-09 13:58:02 +06:00
objects.push_back( aClosed[i]._retn() );
2004-12-01 15:39:14 +05:00
for ( i = 0; i < myOpen; i++ )
2012-08-09 13:58:02 +06:00
objects.push_back( anOpen[i]._retn() );
2004-12-01 15:39:14 +05:00
}
else
myClosed = -1;
}
2009-02-13 17:16:39 +05:00
else {
GEOM::GEOM_Object_var anObj;
if (myAllowNonManifoldChk->isChecked()) {
anObj = anOper->SewAllowNonManifold( objList, myTolEdt->value() );
} else {
anObj = anOper->Sew( objList, myTolEdt->value() );
}
2004-12-01 15:39:14 +05:00
aResult = !anObj->_is_nil();
if ( aResult )
2009-02-13 17:16:39 +05:00
{
if ( !IsPreview() )
{
2012-08-09 13:58:02 +06:00
QStringList aParameters;
aParameters << myTolEdt->text();
anObj->SetParameters(aParameters.join(":").toLatin1().constData());
2009-02-13 17:16:39 +05:00
}
2004-12-01 15:39:14 +05:00
objects.push_back( anObj._retn() );
2009-02-13 17:16:39 +05:00
}
2004-12-01 15:39:14 +05:00
}
return aResult;
}
//=================================================================================
// function : initSelection
// purpose :
//=================================================================================
void RepairGUI_SewingDlg::initSelection()
{
TColStd_MapOfInteger aTypes;
aTypes.Add( GEOM_FACE );
2004-12-01 15:39:14 +05:00
aTypes.Add( GEOM_SHELL );
aTypes.Add( GEOM_SOLID );
aTypes.Add( GEOM_COMPOUND );
globalSelection( aTypes );
}
2004-01-07 20:46:21 +05:00
//=================================================================================
2004-12-01 15:39:14 +05:00
// function : onDetect
2004-01-07 20:46:21 +05:00
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
void RepairGUI_SewingDlg::onDetect()
2004-01-07 20:46:21 +05:00
{
2012-08-09 13:58:02 +06:00
displayPreview( true, false, true, true, 3 );
2004-12-01 15:39:14 +05:00
// field myClosed,myOpen is initialized in execute() method, called by displayPreview().
QString msg;
if ( myClosed != -1 )
msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
else
msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
2009-02-13 17:16:39 +05:00
SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );
2004-01-07 20:46:21 +05:00
}