mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2024-12-28 18:30:36 +05:00
348 lines
12 KiB
C++
348 lines
12 KiB
C++
// 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
|
|
//
|
|
// File : RepairGUI_CloseContourDlg.cxx
|
|
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
|
|
//
|
|
|
|
#include "RepairGUI_CloseContourDlg.h"
|
|
|
|
#include <DlgRef.h>
|
|
#include <GeometryGUI.h>
|
|
#include <GEOMBase.h>
|
|
|
|
#include <SalomeApp_Application.h>
|
|
#include <LightApp_SelectionMgr.h>
|
|
#include <SUIT_Session.h>
|
|
#include <SUIT_ResourceMgr.h>
|
|
|
|
#include <GEOMImpl_Types.hxx>
|
|
|
|
#include <TopAbs.hxx>
|
|
#include <TColStd_IndexedMapOfInteger.hxx>
|
|
#include <TColStd_MapOfInteger.hxx>
|
|
|
|
//=================================================================================
|
|
// class : RepairGUI_CloseContourDlg()
|
|
// purpose : Constructs a RepairGUI_CloseContourDlg 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.
|
|
//=================================================================================
|
|
RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
|
|
bool modal )
|
|
: GEOMBase_Skeleton( theGeometryGUI, parent, modal )
|
|
{
|
|
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CLOSECONTOUR" ) ) );
|
|
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
|
|
|
|
setWindowTitle( tr( "GEOM_CLOSECONTOUR_TITLE" ) );
|
|
|
|
/***************************************************************/
|
|
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CLOSECONTOUR_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_2SelExt( centralWidget() );
|
|
GroupPoints->GroupBox1->setTitle( tr( "Contour to close" ) );
|
|
GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
|
|
GroupPoints->PushButton1->setIcon( image1 );
|
|
GroupPoints->LineEdit1->setReadOnly( true );
|
|
|
|
GroupPoints->TextLabel2->setText( tr( "Contour to close" ) );
|
|
GroupPoints->PushButton2->setIcon( image1 );
|
|
GroupPoints->LineEdit2->setReadOnly( true );
|
|
|
|
QRadioButton* rb1 = new QRadioButton( tr( "Close by common vertex" ), GroupPoints->Box );
|
|
QRadioButton* rb2 = new QRadioButton( tr( "Close by new edge" ), GroupPoints->Box );
|
|
|
|
myIsVertexGr = new QButtonGroup( GroupPoints->Box );
|
|
myIsVertexGr->addButton( rb1, 0 );
|
|
myIsVertexGr->addButton( rb2, 1 );
|
|
rb1->setChecked( true );
|
|
|
|
QVBoxLayout* l = new QVBoxLayout( GroupPoints->Box );
|
|
l->setMargin( 0 ); l->setSpacing( 6 );
|
|
l->addWidget( rb1 );
|
|
l->addWidget( rb2 );
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
|
|
layout->setMargin( 0 ); layout->setSpacing( 6 );
|
|
layout->addWidget( GroupPoints );
|
|
|
|
/***************************************************************/
|
|
|
|
setHelpFileName( "close_contour_operation_page.html" );
|
|
|
|
Init();
|
|
}
|
|
|
|
|
|
//=================================================================================
|
|
// function : ~RepairGUI_CloseContourDlg()
|
|
// purpose : Destroys the object and frees any allocated resources
|
|
//=================================================================================
|
|
RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
|
|
{
|
|
}
|
|
|
|
|
|
//=================================================================================
|
|
// function : Init()
|
|
// purpose :
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::Init()
|
|
{
|
|
/* init variables */
|
|
myEditCurrentArgument = GroupPoints->LineEdit1;
|
|
|
|
myObject = GEOM::GEOM_Object::_nil();
|
|
myWiresInd = new GEOM::short_array();
|
|
myWiresInd->length( 0 );
|
|
|
|
//myGeomGUI->SetState( 0 );
|
|
initSelection();
|
|
|
|
/* signals and slots connections */
|
|
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
|
|
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
|
|
|
|
connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
|
|
connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
|
|
connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
|
|
connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
|
|
|
|
connect( myGeomGUI->getApp()->selectionMgr(),
|
|
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
|
|
|
|
initName( tr( "CLOSE_CONTOUR_NEW_OBJ_NAME" ) );
|
|
}
|
|
|
|
|
|
//=================================================================================
|
|
// function : ClickOnOk()
|
|
// purpose : Same than click on apply but close this dialog.
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::ClickOnOk()
|
|
{
|
|
if ( ClickOnApply() )
|
|
ClickOnCancel();
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
// function : ClickOnApply()
|
|
// purpose :
|
|
//=================================================================================
|
|
bool RepairGUI_CloseContourDlg::ClickOnApply()
|
|
{
|
|
if ( !onAccept() )
|
|
return false;
|
|
|
|
initName();
|
|
|
|
myEditCurrentArgument = GroupPoints->LineEdit1;
|
|
myEditCurrentArgument->setText( "" );
|
|
myObject = GEOM::GEOM_Object::_nil();
|
|
myWiresInd->length( 0 );
|
|
|
|
initSelection();
|
|
|
|
return true;
|
|
}
|
|
|
|
//=================================================================================
|
|
// function : SelectionIntoArgument()
|
|
// purpose : Called when selection as changed or other case
|
|
// : used only by SelectButtonC1A1 (LineEditC1A1)
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::SelectionIntoArgument()
|
|
{
|
|
erasePreview();
|
|
myEditCurrentArgument->setText( "" );
|
|
GroupPoints->LineEdit2->setText( "" );
|
|
|
|
if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
|
|
myObject = GEOM::GEOM_Object::_nil();
|
|
else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
|
|
myWiresInd->length( 0 );
|
|
|
|
if ( IObjectCount() == 1 ) {
|
|
Handle(SALOME_InteractiveObject) anIO = firstIObject();
|
|
|
|
if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) { // face selection
|
|
Standard_Boolean aRes;
|
|
myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
|
|
if ( aRes && GEOMBase::IsShape( myObject ) ) {
|
|
myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
|
|
TopoDS_Shape aShape;
|
|
if ( GEOMBase::GetShape( myObject, aShape, TopAbs_WIRE ) )
|
|
GroupPoints->LineEdit2->setText( myEditCurrentArgument->text() );
|
|
}
|
|
else
|
|
myObject = GEOM::GEOM_Object::_nil();
|
|
}
|
|
else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
|
|
TColStd_IndexedMapOfInteger aMap;
|
|
myGeomGUI->getApp()->selectionMgr()->GetIndexes( anIO, aMap );
|
|
const int n = aMap.Extent();
|
|
myWiresInd->length( n );
|
|
for ( int i = 1; i <= n; i++ )
|
|
myWiresInd[ i-1 ] = aMap( i );
|
|
if ( n )
|
|
myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
|
|
}
|
|
}
|
|
}
|
|
|
|
//=================================================================================
|
|
// function : SetEditCurrentArgument()
|
|
// purpose :
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
|
|
{
|
|
const QObject* send = sender();
|
|
if ( send == GroupPoints->PushButton1 )
|
|
myEditCurrentArgument = GroupPoints->LineEdit1;
|
|
else if ( send == GroupPoints->PushButton2 && !myObject->_is_nil() )
|
|
myEditCurrentArgument = GroupPoints->LineEdit2;
|
|
if ( myEditCurrentArgument ) {
|
|
initSelection();
|
|
myEditCurrentArgument->setFocus();
|
|
SelectionIntoArgument();
|
|
}
|
|
}
|
|
|
|
|
|
//=================================================================================
|
|
// function : LineEditReturnPressed()
|
|
// purpose :
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::LineEditReturnPressed()
|
|
{
|
|
const QObject* send = sender();
|
|
if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
|
|
myEditCurrentArgument = (QLineEdit*)send;
|
|
GEOMBase_Skeleton::LineEditReturnPressed();
|
|
}
|
|
}
|
|
|
|
|
|
//=================================================================================
|
|
// function : ActivateThisDialog()
|
|
// purpose :
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::ActivateThisDialog()
|
|
{
|
|
GEOMBase_Skeleton::ActivateThisDialog();
|
|
connect( myGeomGUI->getApp()->selectionMgr(),
|
|
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
|
|
|
|
myEditCurrentArgument = GroupPoints->LineEdit1;
|
|
myEditCurrentArgument->setText( "" );
|
|
GroupPoints->LineEdit2->setText( "" );
|
|
myObject = GEOM::GEOM_Object::_nil();
|
|
myWiresInd->length( 0 );
|
|
|
|
//myGeomGUI->SetState( 0 );
|
|
initSelection();
|
|
}
|
|
|
|
|
|
//=================================================================================
|
|
// function : enterEvent()
|
|
// purpose : Mouse enter onto the dialog to activate it
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::enterEvent( QEvent* )
|
|
{
|
|
if ( !mainFrame()->GroupConstructors->isEnabled() )
|
|
ActivateThisDialog();
|
|
}
|
|
|
|
|
|
//=================================================================================
|
|
// function : createOperation
|
|
// purpose :
|
|
//=================================================================================
|
|
GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
|
|
{
|
|
return getGeomEngine()->GetIHealingOperations( getStudyId() );
|
|
}
|
|
|
|
//=================================================================================
|
|
// function : isValid
|
|
// purpose :
|
|
//=================================================================================
|
|
bool RepairGUI_CloseContourDlg::isValid( QString& )
|
|
{
|
|
TopoDS_Shape aTmpShape;
|
|
return !myObject->_is_nil() && ( myWiresInd->length() || GEOMBase::GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
|
|
}
|
|
|
|
//=================================================================================
|
|
// function : execute
|
|
// purpose :
|
|
//=================================================================================
|
|
bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
|
|
{
|
|
GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
|
|
bool aResult = !anObj->_is_nil();
|
|
if ( aResult )
|
|
objects.push_back( anObj._retn() );
|
|
|
|
return aResult;
|
|
}
|
|
|
|
//=================================================================================
|
|
// function : getIsByVertex
|
|
// purpose :
|
|
//=================================================================================
|
|
bool RepairGUI_CloseContourDlg::getIsByVertex() const
|
|
{
|
|
return myIsVertexGr->button( 0 )->isChecked();
|
|
}
|
|
|
|
//=================================================================================
|
|
// function : initSelection
|
|
// purpose :
|
|
//=================================================================================
|
|
void RepairGUI_CloseContourDlg::initSelection()
|
|
{
|
|
if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
|
|
TColStd_MapOfInteger aTypes;
|
|
aTypes.Add( GEOM_COMPOUND );
|
|
aTypes.Add( GEOM_SOLID );
|
|
aTypes.Add( GEOM_SHELL );
|
|
aTypes.Add( GEOM_FACE );
|
|
aTypes.Add( GEOM_WIRE );
|
|
|
|
globalSelection( aTypes );
|
|
}
|
|
else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
|
|
localSelection( myObject, TopAbs_EDGE );
|
|
localSelection( myObject, TopAbs_WIRE );
|
|
}
|
|
}
|