geom/src/OperationGUI/OperationGUI_MaterialDlg.cxx

215 lines
8.0 KiB
C++
Raw Normal View History

2012-08-09 13:58:02 +06:00
// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:39:14 +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
// version 2.1 of the License.
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.
2009-02-13 17:16:39 +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
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-13 17:16:39 +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 : OperationGUI_MaterialDlg.cxx
// Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
2004-12-01 15:39:14 +05:00
//
#include "OperationGUI_MaterialDlg.h"
#include "OperationGUI_PartitionDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GEOMBase.h>
#include <GeometryGUI.h>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
2005-08-23 19:10:06 +06:00
2004-12-01 15:39:14 +05:00
//=================================================================================
// class : OperationGUI_MaterialDlg()
// purpose : Constructs a OperationGUI_MaterialDlg 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
OperationGUI_MaterialDlg::OperationGUI_MaterialDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
GEOM::ListOfGO ListShapes, bool modal )
: GEOMBase_Skeleton( theGeometryGUI, parent, modal )
2004-12-01 15:39:14 +05:00
{
myListShapes = ListShapes;
2009-02-13 17:16:39 +05:00
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "GEOM_MATERIAL_TITLE" ) );
2004-12-01 15:39:14 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
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_1List1Spin1Btn( centralWidget() );
GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
QStringList columns;
columns << tr( "GEOM_MATERIAL_SHAPE" ) << tr( "GEOM_MATERIAL_MATERIAL" );
GroupPoints->ListView1->setHeaderLabels( columns );
GroupPoints->ListView1->setSelectionMode( QAbstractItemView::ExtendedSelection );
GroupPoints->ListView1->setSortingEnabled( false );
GroupPoints->TextLabel1->setText( tr( "GEOM_MATERIAL_ID" ) );
GroupPoints->PushButton1->setText( tr( "GEOM_MATERIAL_SET" ) );
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupPoints );
2004-12-01 15:39:14 +05:00
/***************************************************************/
setHelpFileName("partition_page.html");
2004-12-01 15:39:14 +05:00
Init();
}
//=================================================================================
// function : ~OperationGUI_MaterialDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
OperationGUI_MaterialDlg::~OperationGUI_MaterialDlg()
{
// no need to delete child widgets, Qt does it all for us
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void OperationGUI_MaterialDlg::Init()
{
// get materials list from the parent dialog
OperationGUI_PartitionDlg* aParentDlg =
2009-02-13 17:16:39 +05:00
qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
if ( aParentDlg )
2004-12-01 15:39:14 +05:00
myListMaterials = aParentDlg->GetListMaterials();
2004-12-01 15:39:14 +05:00
/* list filling */
2009-02-13 17:16:39 +05:00
for ( int ind = 0; ind < myListShapes.length(); ind++ ) {
2004-12-01 15:39:14 +05:00
GEOM::GEOM_Object_var anObject = myListShapes[ind];
2009-02-13 17:16:39 +05:00
if ( !anObject->_is_nil() ) {
QStringList labels;
labels << GEOMBase::GetName( anObject );
labels << ( ind < myListMaterials.length() ?
2012-08-09 13:58:02 +06:00
QString::number( myListMaterials[ind] ) : QString( "0" ) );
2009-02-13 17:16:39 +05:00
GroupPoints->ListView1->addTopLevelItem( new QTreeWidgetItem( labels ) );
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() ) );
buttonApply()->setAttribute( Qt::WA_DeleteOnClose );
buttonApply()->close();
buttonCancel()->setText( tr( "GEOM_BUT_CANCEL" ) );
connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetMaterial() ) );
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
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void OperationGUI_MaterialDlg::ClickOnOk()
{
2009-02-13 17:16:39 +05:00
SUIT_Session::session()->activeApplication()->putInfo( "" );
2004-12-01 15:39:14 +05:00
int nbSh = myListShapes.length();
2009-02-13 17:16:39 +05:00
myListMaterials.length( nbSh );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
QTreeWidgetItemIterator it( GroupPoints->ListView1 );
for ( int i = 0; *it; it++, i++ )
myListMaterials[i] = (*it)->text( 1 ).toInt();
2004-12-01 15:39:14 +05:00
// set materials list to the parent dialog
OperationGUI_PartitionDlg* aParentDlg =
2009-02-13 17:16:39 +05:00
qobject_cast<OperationGUI_PartitionDlg*>( parentWidget() );
if ( aParentDlg )
aParentDlg->SetListMaterials( myListMaterials );
2004-12-01 15:39:14 +05:00
ClickOnCancel();
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection as changed or other case
//=================================================================================
void OperationGUI_MaterialDlg::SelectionIntoArgument()
{
/*QString aString = ""; // name of selection
2004-12-01 15:39:14 +05:00
int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
if (nbSel < 1) {
2004-12-01 15:39:14 +05:00
return;
}
//myGeomBase->ConvertListOfIOInListOfIOR(selectedIO(), myListShapes);
2004-12-01 15:39:14 +05:00
// no simulation
return;*/
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : SetMaterial()
// purpose :
//=================================================================================
void OperationGUI_MaterialDlg::SetMaterial()
{
2009-02-13 17:16:39 +05:00
QString aMatIdStr = QString::number( GroupPoints->SpinBox1->value() );
QList<QTreeWidgetItem*> selectedItems = GroupPoints->ListView1->selectedItems();
QListIterator<QTreeWidgetItem*> it( selectedItems );
while ( it.hasNext() ) {
it.next()->setText( 1, aMatIdStr );
2004-12-01 15:39:14 +05:00
}
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void OperationGUI_MaterialDlg::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
return;
}
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
void OperationGUI_MaterialDlg::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
this->ActivateThisDialog();
}