From: san Date: Wed, 15 Jun 2005 16:04:32 +0000 (+0000) Subject: - plot curves X-Git-Tag: T3_0_0_a4~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7d52bc183407f4d08f7198960d6aba6d3ee26d4d;p=modules%2Fvisu.git - plot curves - automatic curve generation after cut lines creation - Show Table operation --- diff --git a/src/VISUGUI/Makefile.in b/src/VISUGUI/Makefile.in index a2b001f1..da74603d 100644 --- a/src/VISUGUI/Makefile.in +++ b/src/VISUGUI/Makefile.in @@ -63,7 +63,8 @@ LIB_SRC = VisuGUI.cxx \ VisuGUI_CutLinesDlg.cxx \ VisuGUI_CutPlanesDlg.cxx \ VisuGUI_StreamLinesDlg.cxx \ - VisuGUI_VectorsDlg.cxx + VisuGUI_VectorsDlg.cxx \ + VisuGUI_TableDlg.cxx LIB_MOC = VisuGUI.h \ VisuGUI_Selection.h \ @@ -79,7 +80,8 @@ LIB_MOC = VisuGUI.h \ VisuGUI_CutLinesDlg.h \ VisuGUI_CutPlanesDlg.h \ VisuGUI_StreamLinesDlg.h \ - VisuGUI_VectorsDlg.h + VisuGUI_VectorsDlg.h \ + VisuGUI_TableDlg.h LIB_CLIENT_IDL = SALOME_Exception.idl \ VISU_Gen.idl \ diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index 22245b12..6fd7accb 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "POT-Creation-Date: 2002-02-22 16:56:46 CET\n" -"PO-Revision-Date: 2004-02-17 11:17+0300\n" +"PO-Revision-Date: 2005-06-15 21:15+0400\n" "Last-Translator: FULLNAME \n" "Content-Type: text/plain; charset=iso-8859-1\n" @@ -815,3 +815,50 @@ msgstr "Rename" msgid "VisuGUI_NameDlg::NAME_LBL" msgstr "Name: " + +#: VisuGUI_TableDlg.cxx + +msgid "VisuGUI_TableDlg::VIEW_TABLE_TLT" +msgstr "View Table" + +msgid "VisuGUI_TableDlg::EDIT_TABLE_TLT" +msgstr "Edit Table" + +msgid "VisuGUI_TableDlg::TABLE_OF_INTEGER_TLT" +msgstr "Table of integer" + +msgid "VisuGUI_TableDlg::TABLE_OF_REAL_TLT" +msgstr "Table of real" + +msgid "VisuGUI_TableDlg::ERR_TABLE_NOT_AVAILABLE" +msgstr "Table is not available" + +msgid "VisuGUI_TableWidget::UNITS_TLT" +msgstr "Units" + +msgid "VisuGUI_TableWidget::ADD_ROW_BTN" +msgstr "Add Row" + +msgid "VisuGUI_TableWidget::REMOVE_ROW_BTN" +msgstr "Remove Row(s)" + +msgid "VisuGUI_TableWidget::ADD_COLUMN_BTN" +msgstr "Add Column" + +msgid "VisuGUI_TableWidget::REMOVE_COLUMN_BTN" +msgstr "Remove Column(s)" + +msgid "VisuGUI_TableWidget::ADJUST_CELLS_BTN" +msgstr "Adjust Cells" + +msgid "VisuGUI_TableWidget::SELECT_ALL_BTN" +msgstr "Select All" + +msgid "VisuGUI_TableWidget::CLEAR_BTN" +msgstr "Clear" + +msgid "VisuGUI_TableWidget::SET_TITLE_TLT" +msgstr "Set title" + +msgid "VisuGUI_TableWidget::TITLE_LBL" +msgstr "Title:" diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index 984e4a60..7d113a8b 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -109,6 +109,8 @@ #include "VISU_Vectors_i.hh" #include "VisuGUI_VectorsDlg.h" +#include "VisuGUI_TableDlg.h" + #include "SALOMEconfig.h" #include CORBA_SERVER_HEADER(MED_Gen) @@ -262,6 +264,54 @@ OnExportTableToFile() if(MYDEBUG) MESSAGE("VisuGUI::OnExportTableToFile()"); } +void +CreateCurves( SalomeApp_Module* theModule, + VISU::CutLines_i* thePrs, + QDialog* theDlg, + const bool theCreate = true ) +{ + if ( !thePrs ) + return; + VisuGUI_CutLinesDlg* aCutDlg = dynamic_cast( theDlg ); + if ( !aCutDlg ) + return; + + _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) ); + _PTR(SObject) aSObject = aStudy->FindObjectID( thePrs->GetEntry() ); + + if ( !theCreate && aSObject ){ + // Remove old Table + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + for ( _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSObject ); aIter->More(); aIter->Next() ) { + _PTR(SObject) aTblObj = aIter->Value(); + if ( aTblObj ) { + _PTR(GenericAttribute) anAttr; + if (aTblObj->FindAttribute( anAttr, "AttributeName" ) ) { + aBuilder->RemoveObjectWithChildren( aIter->Value() ); // We should have only one child + break; + } + } + } + } + + if ( aCutDlg->isGenerateTable() ) { + GetVisuGen( theModule )->CreateTable( thePrs->GetEntry() ); + if ( aCutDlg->isGenerateCurves() ) { + if( aSObject ) { + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + for ( _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSObject ); aIter->More(); aIter->Next() ) { + _PTR(SObject) aTblObj = aIter->Value(); + if ( aTblObj ) { + _PTR(GenericAttribute) anAttr; + if ( aTblObj->FindAttribute( anAttr, "AttributeName" ) ) { + CreatePlot( theModule, aTblObj ); + } + } + } + } + } + } +} template TPrs3d_i* @@ -318,10 +368,12 @@ CreatePrs3d(SalomeApp_Module* theModule, SUIT_ResourceMgr* aResourceMgr = GetResourceMgr(); int aValue = aResourceMgr->integerValue("Visu:BuildDefaultPrs3d",0); if(!aValue){ - if(TDlg* aDlg = new TDlg(GetDesktop(theModule))){ + if(TDlg* aDlg = new TDlg(GetDesktop(theModule))){ // dialog box in creation mode aDlg->initFromPrsObject(aPrs3d); if(IsDlgModal) if(aDlg->exec() && (aDlg->storeToPrsObject(aPrs3d))) { + // Optionally, create table and curves for cut lines + CreateCurves( theModule, dynamic_cast( aPrs3d ), aDlg, true ); // in creation mode delete aDlg; } else { DeletePrs3d(theModule,aPrs3d,theIO); @@ -1072,6 +1124,35 @@ void VisuGUI:: OnShowTable() { + Handle(SALOME_InteractiveObject) anIO; + CORBA::Object_var anObject = GetSelectedObj( this, &anIO ); + _PTR(SObject) SO; + if ( !CORBA::is_nil( anObject ) ) { + VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject ); + if ( !CORBA::is_nil( aVisuObj ) && aVisuObj->GetType() == VISU::TTABLE ) { + CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject ); + if( !CORBA::is_nil( aTable ) ) { + VISU::Table_i* table = dynamic_cast( VISU::GetServant(aTable).in() ); + if ( table ) { + SO = GetCStudy( GetAppStudy( this ) )->FindObjectID( table->GetObjectEntry() ); + } + } + } + } else { + // possibly this is Table SObject + SO = GetCStudy( GetAppStudy( this ) )->FindObjectID( anIO->getEntry() ); + } + + if( !IsSObjectTable( SO ) ) + return; + + VisuGUI_TableDlg* dlg = new VisuGUI_TableDlg( GetDesktop( this ), + SO, + false, + //SAL2670 Orientation of show tables + VisuGUI_TableDlg::ttAuto, + Qt::Vertical ); + dlg->show(); } void @@ -2068,7 +2149,7 @@ createPopupMenus() "'VISU::TISOSURFACE' 'VISU::TDEFORMEDSHAPE' 'VISU::TCUTPLANES' " "'VISU::TCUTLINES' 'VISU::TVECTORS' 'VISU::TSTREAMLINES'}"; mgr->insert( action( 4033 ), -1, -1, -1 ); // delete presentation - mgr->setRule( action( 4033 ), aRule.arg(""), true ); + mgr->setRule( action( 4033 ), aRule, true ); // View parameters mgr->insert ( action( 4046 ), -1, -1, -1 ); // save view params diff --git a/src/VISUGUI/VisuGUI_TableDlg.cxx b/src/VISUGUI/VisuGUI_TableDlg.cxx new file mode 100644 index 00000000..1d211460 --- /dev/null +++ b/src/VISUGUI/VisuGUI_TableDlg.cxx @@ -0,0 +1,887 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VisuGUI_TableDlg.cxx +// Author : Vadim SANDLER +// Module : SALOME + +#include "VisuGUI_TableDlg.h" + +#include "SUIT_Tools.h" +#include "SUIT_MessageBox.h" + +#include "SALOMEDSClient_Study.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_AttributeTableOfInteger.hxx" +#include "SALOMEDSClient_AttributeTableOfReal.hxx" +#include "SALOMEDSClient_StudyBuilder.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include "utilities.h" +using namespace std; + +#define MARGIN_SIZE 11 +#define SPACING_SIZE 6 +#define SPACER_SIZE 5 +#define MIN_TABLE_WIDTH 200 +#define MIN_TABLE_HEIGHT 200 + + +class VisuGUI_Table : public QTable { +public: + VisuGUI_Table( Orientation orient, QWidget* parent = 0, const char* name = 0 ) + : QTable( parent, name ), myValidator( 0 ), myOrientation( orient ) {} + VisuGUI_Table( Orientation orient, int numRows, int numCols, QWidget* parent = 0, const char* name = 0 ) + : QTable( numRows, numCols, parent, name ), myValidator( 0 ), myOrientation( orient ) {} + + void setValidator( QValidator* v = 0 ) { myValidator = v; } + bool isEditing() const { return QTable::isEditing(); } + +protected: + QWidget* createEditor ( int row, int col, bool initFromCell ) const + { + bool testUnits = ( myOrientation == Horizontal && col == 0 ) || ( myOrientation == Vertical && row == 0 ); + QWidget* wg = QTable::createEditor( row, col, initFromCell ); + if ( wg && wg->inherits("QLineEdit") && myValidator && !testUnits ) + (( QLineEdit*)wg)->setValidator( myValidator ); + return wg; + } + +protected: + QValidator* myValidator; + Orientation myOrientation; +}; + +/*! + Constructor +*/ +VisuGUI_TableDlg::VisuGUI_TableDlg( QWidget* parent, + _PTR(SObject) obj, + bool edit, + int which, + Orientation orient, + bool showColumnTitles ) + : QDialog( parent, "", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), + myIntTable( 0 ), myRealTable( 0 ) +{ + setCaption( edit ? tr( "EDIT_TABLE_TLT" ) : tr( "VIEW_TABLE_TLT" ) ); + setSizeGripEnabled( true ); + + myObject = obj; + bool bHasIntTable = false; + bool bHasRealTable = false; + if ( myObject ) { + _PTR(GenericAttribute) anAttr; + bHasIntTable = myObject->FindAttribute( anAttr, "AttributeTableOfInteger"); + bHasRealTable = myObject->FindAttribute( anAttr, "AttributeTableOfReal"); + } + + QVBoxLayout* mainLayout = new QVBoxLayout( this ); + mainLayout->setMargin( MARGIN_SIZE ); + mainLayout->setSpacing( SPACING_SIZE ); + + bool bDoInt = which == ttInt || which == ttBoth || which == ttAuto && bHasIntTable; + bool bDoReal = which == ttReal || which == ttBoth || which == ttAuto && bHasRealTable; + + QWidget* top; + QVBoxLayout* tl; + if ( bDoInt && bDoReal ) { + top = new QTabWidget( this, "TabWidget" ); + ( ( QTabWidget* ) top) ->setMargin( MARGIN_SIZE ); + } + else { + top = new QWidget( this, "DumbWidget" ); + tl = new QVBoxLayout( top ); tl->setMargin( 0 ); tl->setSpacing( SPACING_SIZE ); + } + + if ( bDoInt ) { + myIntTable = new VisuGUI_TableWidget( top, "myIntTable", edit, orient, showColumnTitles ); + myIntTable->getTable()->setValidator( new QIntValidator( this ) ); + if ( bDoInt && bDoReal ) + ( ( QTabWidget* )top )->addTab( myIntTable, tr( "TABLE_OF_INTEGER_TLT" ) ); + else + tl->addWidget( myIntTable ); + } + if ( bDoReal ) { + myRealTable = new VisuGUI_TableWidget( top, "myRealTable", edit, orient, showColumnTitles ); + myRealTable->getTable()->setValidator( new QDoubleValidator( this ) ); + if ( bDoInt && bDoReal ) + ( ( QTabWidget* )top )->addTab( myRealTable, tr( "TABLE_OF_REAL_TLT" ) ); + else + tl->addWidget( myRealTable ); + } + if ( !bDoInt && !bDoReal ) { + QLabel *dumbLabel = new QLabel( tr( "ERR_TABLE_NOT_AVAILABLE" ), top, "DumbLabel" ); + dumbLabel->setAlignment( AlignCenter ); + tl->addWidget( dumbLabel ); + } + + QHBoxLayout* btnLayout = new QHBoxLayout; + btnLayout->setMargin( 0 ); btnLayout->setSpacing( SPACING_SIZE ); + + myOKBtn = new QPushButton( tr( "BUT_OK" ), this ); + if ( edit ) { + myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this ); + btnLayout->addWidget( myOKBtn ); + btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + btnLayout->addWidget( myCancelBtn ); + connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( onOK() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + } + else { + btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + btnLayout->addWidget( myOKBtn ); + btnLayout->addItem( new QSpacerItem( SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) ); + } + + mainLayout->addWidget( top ); + mainLayout->addLayout( btnLayout ); + + initDlg(); + resize( 500, 400 ); + SUIT_Tools::centerWidget( this, parent ); +} + +/*! + Destructor +*/ +VisuGUI_TableDlg::~VisuGUI_TableDlg() +{ +} + +/*! + button slot, saves table(s) + Called only in create/edit mode ( parameter for constructor is true ) +*/ +void VisuGUI_TableDlg::onOK() +{ + myOKBtn->setFocus(); // accept possible changes + bool done = true; + + if ( myObject ) { + _PTR(Study) study = myObject->GetStudy(); + _PTR(AttributeTableOfInteger) tblIntAttr; + _PTR(AttributeTableOfReal) tblRealAttr; + + if ( study ) { + _PTR(StudyBuilder) builder = study->NewBuilder(); + builder->NewCommand(); // start transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!!! + try { + if ( myIntTable ) { + builder->RemoveAttribute( myObject, "AttributeTableOfInteger" ); + tblIntAttr = builder->FindOrCreateAttribute( myObject, "AttributeTableOfInteger" ); + + int i; + int nbRows = myIntTable->getNumRows(); + int nbCols = myIntTable->getNumCols(); + QString tlt = myIntTable->getTableTitle(); + QStringList rowTitles, colTitles, units; + myIntTable->getRowTitles( rowTitles ); + myIntTable->getColTitles( colTitles ); + myIntTable->getUnits( units ); + + if ( nbRows > 0) { + // data + int nRow = 0; + tblIntAttr->SetNbColumns( nbCols ); + for ( i = 0; i < nbRows; i++ ) { + QStringList data; + myIntTable->getRowData( i, data ); + bool bEmptyRow = true; + for ( int j = 0; j < data.count(); j++ ) { + if ( !data[ j ].isNull() ) { + tblIntAttr->PutValue( data[ j ].toInt(), nRow+1, j+1 ); + bEmptyRow = false; + } + } + if ( !bEmptyRow ) { // Skip rows with no data !!! + // set row title + tblIntAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? QString( "" ) : QString( rowTitles[ i ] ) ); + // set row unit + tblIntAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? QString( "" ) : QString( units[ i ] ) ); + nRow++; + } + } + if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!! + // column titles + for ( i = 0; i < colTitles.count(); i++ ) + tblIntAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? QString( "" ) : QString( colTitles[ i ] ) ); + } + } + // title + tblIntAttr->SetTitle( myIntTable->getTableTitle().latin1() ); + } + if ( myRealTable ) { + builder->RemoveAttribute( myObject, "AttributeTableOfReal" ); + tblRealAttr = builder->FindOrCreateAttribute( myObject, "AttributeTableOfReal" ); + + int i; + int nbRows = myRealTable->getNumRows(); + int nbCols = myRealTable->getNumCols(); + QString tlt = myRealTable->getTableTitle(); + QStringList rowTitles, colTitles, units; + myRealTable->getRowTitles( rowTitles ); + myRealTable->getColTitles( colTitles ); + myRealTable->getUnits( units ); + + if ( nbRows > 0) { + // data + int nRow = 0; + tblRealAttr->SetNbColumns( nbCols ); + for ( i = 0; i < nbRows; i++ ) { + QStringList data; + myRealTable->getRowData( i, data ); + bool bEmptyRow = true; + for ( int j = 0; j < data.count(); j++ ) { + if ( !data[ j ].isNull() ) { + tblRealAttr->PutValue( data[ j ].toDouble(), nRow+1, j+1 ); + bEmptyRow = false; + } + } + if ( !bEmptyRow ) { // Skip rows with no data !!! + // set row title + tblRealAttr->SetRowTitle( nRow+1, rowTitles[ i ].isNull() ? QString( "" ) : QString( rowTitles[ i ] ) ); + // set row unit + tblRealAttr->SetRowUnit( nRow+1, units[ i ].isNull() ? QString( "" ) : QString( units[ i ] ) ); + nRow++; + } + } + if ( nRow > 0 ) { // Set columns only if table is not empty, otherwise exception is raised !!! + // column titles + for ( i = 0; i < colTitles.count(); i++ ) + tblRealAttr->SetColumnTitle( i+1, colTitles[ i ].isNull() ? QString( "" ) : QString( colTitles[ i ] ) ); + } + } + // title + tblRealAttr->SetTitle( myRealTable->getTableTitle().latin1() ); + } + if ( myIntTable || myRealTable) + builder->CommitCommand(); // commit transaction !!!!!!!!!!!!!!!!!!!!!!!!!!! + else + builder->AbortCommand(); // abort transaction !!!!!!!!!!!!!!!!!!!!!!!!!!! + } + catch( ... ) { + MESSAGE("VisuGUI_TableDlg::onOK : Exception has been caught !!!"); + builder->AbortCommand(); // abort transaction !!!!!!!!!!!!!!!!!!!!!!!!!!! + done = false; + SUIT_MessageBox::error1 ( this, tr("ERR_ERROR"), tr("ERR_APP_EXCEPTION"), tr ("BUT_OK") ); + } + } + } + if ( done ) + accept(); +} + +/*! + Populates table with data +*/ +void VisuGUI_TableDlg::initDlg() +{ + int i, j; + if ( myObject ) { + _PTR(GenericAttribute) anAttr; + _PTR(AttributeTableOfInteger) tblIntAttr; + _PTR(AttributeTableOfReal) tblRealAttr; + if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger") ) { + tblIntAttr = anAttr; + } + if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal") ) { + tblRealAttr = anAttr; + } + // Table of integer + if ( tblIntAttr && myIntTable ) { + try { + VisuGUI_Table* tbl = myIntTable->getTable(); + // title + myIntTable->setTableTitle( tblIntAttr->GetTitle().c_str() ); + // nb of rows & cols + int nbRows = tblIntAttr->GetNbRows() ; + int nbCols = tblIntAttr->GetNbColumns(); + myIntTable->setNumRows( nbRows ); + myIntTable->setNumCols( nbCols ); + // rows titles + QStringList strlist; + vector rowTitles = tblIntAttr->GetRowTitles(); + for ( i = 0; i < nbRows; i++ ) { + if ( rowTitles.size() > 0 ) + strlist.append( rowTitles[i].c_str() ); + else + strlist.append( "" ); + } + myIntTable->setRowTitles( strlist ); + // columns titles + strlist.clear(); + vector colTitles = tblIntAttr->GetColumnTitles(); + for ( i = 0; i < nbCols; i++ ) { + if ( colTitles.size() > 0 ) + strlist.append( colTitles[i].c_str() ); + else + strlist.append( "" ); + } + myIntTable->setColTitles( strlist ); + // units + strlist.clear(); + vector rowUnits = tblIntAttr->GetRowUnits(); + if ( rowUnits.size() > 0 ) { + for ( i = 0; i < nbRows; i++ ) + strlist.append( rowUnits[i] ); + myIntTable->setUnits( strlist ); + } + // data + for ( i = 1; i <= nbRows; i++ ) { + strlist.clear(); + for ( j = 1; j <= nbCols; j++ ) { + if ( tblIntAttr->HasValue( i, j ) ) + strlist.append( QString::number( tblIntAttr->GetValue( i, j ) ) ); + else + strlist.append( QString::null ); + } + myIntTable->setRowData( i-1, strlist ); + } + myIntTable->adjustTable(); + } + catch( ... ) { + MESSAGE("VisuGUI_TableDlg::initDlg : Exception has been caught !!!"); + } + } + // Table of real + if ( tblRealAttr && myRealTable ) { + try { + VisuGUI_Table* tbl = myRealTable->getTable(); + // title + myRealTable->setTableTitle( tblRealAttr->GetTitle().c_str() ); + // nb of rows & cols + int nbRows = tblRealAttr->GetNbRows() ; + int nbCols = tblRealAttr->GetNbColumns(); + myRealTable->setNumRows( nbRows ); + myRealTable->setNumCols( nbCols ); + // rows titles + QStringList strlist; + vector rowTitles = tblRealAttr->GetRowTitles(); + for ( i = 0; i < nbRows; i++ ) { + if ( rowTitles.size() > 0 ) + strlist.append( rowTitles[i].c_str() ); + else + strlist.append( "" ); + } + myRealTable->setRowTitles( strlist ); + // columns titles + strlist.clear(); + vector colTitles = tblRealAttr->GetColumnTitles(); + for ( i = 0; i < nbCols; i++ ) { + if ( colTitles.size() > 0 ) + strlist.append( colTitles[i].c_str() ); + else + strlist.append( "" ); + } + myRealTable->setColTitles( strlist ); + // units + strlist.clear(); + vector rowUnits = tblRealAttr->GetRowUnits(); + if ( rowUnits.size() > 0 ) { + for ( i = 0; i < nbRows; i++ ) + strlist.append( rowUnits[i].c_str() ); + myRealTable->setUnits( strlist ); + } + // data + for ( i = 1; i <= nbRows; i++ ) { + strlist.clear(); + for ( j = 1; j <= nbCols; j++ ) { + if ( tblRealAttr->HasValue( i, j ) ) + strlist.append( QString::number( tblRealAttr->GetValue( i, j ) ) ); + else + strlist.append( QString::null ); + } + myRealTable->setRowData( i-1, strlist ); + } + myRealTable->adjustTable(); + } + catch( ... ) { + MESSAGE("VisuGUI_TableDlg::initDlg : Exception has been caught !!!"); + } + } + } +} + +/*! + Constructor +*/ +VisuGUI_TableWidget::VisuGUI_TableWidget( QWidget* parent, + const char* name, + bool edit, + Orientation orient, + bool showColumnTitles ) + : QWidget( parent, name ), myOrientation( orient ) +{ + QGridLayout* mainLayout = new QGridLayout( this ); + mainLayout->setMargin( 0 ); + mainLayout->setSpacing( SPACING_SIZE ); + + myTitleEdit = new QLineEdit( this, "TitleEdit" ); + myTitleEdit->setAlignment( AlignCenter ); + myTitleEdit->setReadOnly( !edit ); + QFont fnt = myTitleEdit->font(); + fnt.setBold( true ); + myTitleEdit->setFont( fnt ); + + myTable = new VisuGUI_Table( orient, this, "Table" ); + myTable->setNumRows( 5 ); + myTable->setNumCols( 5 ); + myTable->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); + myTable->setMinimumSize( MIN_TABLE_WIDTH, MIN_TABLE_HEIGHT ); + myTable->setSelectionMode( QTable::Single ); + myTable->setShowGrid( true ); + myTable->setColumnMovingEnabled( false ); + myTable->setRowMovingEnabled( false ); + myTable->setReadOnly( !edit ); + myTable->setDragEnabled( false ); + setUnitsTitle( tr( "UNITS_TLT" ) ); + + if ( !showColumnTitles ) { + if ( myOrientation == Horizontal ) { + myTable->horizontalHeader()->hide(); + myTable->setTopMargin( 0 ); + } + else { + myTable->verticalHeader()->hide(); + myTable->setLeftMargin( 0 ); + } + } + + mainLayout->addWidget( myTitleEdit, 0, 0 ); + mainLayout->addWidget( myTable, 1, 0 ); + + if ( edit ) { + myAddRowBtn = new QPushButton( tr( "ADD_ROW_BTN" ), this, "AddRowBtn" ); + myDelRowBtn = new QPushButton( tr( "REMOVE_ROW_BTN" ), this, "DelRowBtn" ); + myAddColBtn = new QPushButton( tr( "ADD_COLUMN_BTN" ), this, "AddColBtn" ); + myDelColBtn = new QPushButton( tr( "REMOVE_COLUMN_BTN" ), this, "DelColBtn" ); + myAdjustBtn = new QPushButton( tr( "ADJUST_CELLS_BTN" ), this, "AdjustBtn" ); + mySelectAllBtn = new QPushButton( tr( "SELECT_ALL_BTN" ), this, "SelectAllBtn" ); + myClearBtn = new QPushButton( tr( "CLEAR_BTN"), this, "ClearBtn" ); + QVBoxLayout* btnLayout = new QVBoxLayout; btnLayout->setMargin( 0 ); btnLayout->setSpacing( SPACING_SIZE ); + btnLayout->addWidget( myAddRowBtn ); + btnLayout->addWidget( myDelRowBtn ); + btnLayout->addWidget( myAddColBtn ); + btnLayout->addWidget( myDelColBtn ); + btnLayout->addStretch(); + btnLayout->addWidget( myAdjustBtn ); + btnLayout->addStretch(); + btnLayout->addWidget( mySelectAllBtn ); + btnLayout->addWidget( myClearBtn ); + mainLayout->addLayout( btnLayout, 1, 1 ); + connect( myTable, SIGNAL( selectionChanged() ), this, SLOT( updateButtonsState() ) ); + connect( myTable, SIGNAL( currentChanged( int, int) ), this, SLOT( updateButtonsState() ) ); + connect( myAddRowBtn, SIGNAL( clicked() ), this, SLOT( addRow() ) ); + connect( myAddColBtn, SIGNAL( clicked() ), this, SLOT( addCol() ) ); + connect( myDelRowBtn, SIGNAL( clicked() ), this, SLOT( delRow() ) ); + connect( myDelColBtn, SIGNAL( clicked() ), this, SLOT( delCol() ) ); + connect( myAdjustBtn, SIGNAL( clicked() ), this, SLOT( adjustTable() ) ); + connect( mySelectAllBtn, SIGNAL( clicked() ), this, SLOT( selectAll() ) ); + connect( myClearBtn, SIGNAL( clicked() ), this, SLOT( clearTable() ) ); + myTable->horizontalHeader()->installEventFilter( this ); + myTable->verticalHeader()->installEventFilter( this ); + myTable->installEventFilter( this ); + } + updateButtonsState(); +} +/*! + Destructor +*/ +VisuGUI_TableWidget::~VisuGUI_TableWidget() +{ +} +/*! + Sets table title +*/ +void VisuGUI_TableWidget::setTableTitle( const QString& title ) +{ + myTitleEdit->setText( title ); +} +/*! + Gets table title +*/ +QString VisuGUI_TableWidget::getTableTitle() +{ + return myTitleEdit->text(); +} +/*! + Sets total number of rows +*/ +void VisuGUI_TableWidget::setNumRows( const int num ) +{ + myOrientation == Horizontal ? myTable->setNumRows( num ) : myTable->setNumCols( num ); +} +/*! + Gets total number of rows +*/ +int VisuGUI_TableWidget::getNumRows() +{ + return myOrientation == Horizontal ? myTable->numRows() : myTable->numCols(); +} +/*! + Sets total number of columns +*/ +void VisuGUI_TableWidget::setNumCols( const int num ) +{ + // !!! first column contains units !!! + myOrientation == Horizontal ? myTable->setNumCols( num+1 ) : myTable->setNumRows( num+1 ); +// myOrientation == Horizontal ? myTable->setColumnReadOnly( 0, true ) : myTable->setRowReadOnly( 0, true ); +} +/*! + Gets total number of columns +*/ +int VisuGUI_TableWidget::getNumCols() +{ + // !!! first column contains units !!! + return myOrientation == Horizontal ? myTable->numCols()-1 : myTable->numRows()-1; +} +/*! + Sets rows titles +*/ +void VisuGUI_TableWidget::setRowTitles( QStringList& tlts ) +{ + for ( int i = 0; i < tlts.count(); i++ ) { + myOrientation == Horizontal ? + myTable->verticalHeader()->setLabel( i, tlts[i] ) : + myTable->horizontalHeader()->setLabel( i, tlts[i] ); + } +} +/*! + Gets rows titles +*/ +void VisuGUI_TableWidget::getRowTitles( QStringList& tlts ) +{ + tlts.clear(); + if ( myOrientation == Horizontal ) { + for ( int i = 0; i < myTable->numRows(); i++ ) { + tlts.append( myTable->verticalHeader()->label( i ) ); + } + } + else { + for ( int i = 0; i < myTable->numCols(); i++ ) { + tlts.append( myTable->horizontalHeader()->label( i ) ); + } + } +} +/*! + Sets columns titles +*/ +void VisuGUI_TableWidget::setColTitles( QStringList& tlts ) +{ + // !!! first column contains units !!! + for ( int i = 0; i < tlts.count(); i++ ) { + myOrientation == Horizontal ? + myTable->horizontalHeader()->setLabel( i+1, tlts[i].isNull() ? "" : tlts[i] ) : + myTable->verticalHeader()->setLabel( i+1, tlts[i].isNull() ? "" : tlts[i] ); + } + setUnitsTitle( tr( "UNITS_TLT" ) ); +} +/*! + Sets columns titles +*/ +void VisuGUI_TableWidget::getColTitles( QStringList& tlts ) +{ + // !!! first column contains units !!! + tlts.clear(); + if ( myOrientation == Horizontal ) { + for ( int i = 1; i < myTable->numCols(); i++ ) { + tlts.append( myTable->horizontalHeader()->label( i ) ); + } + } + else { + for ( int i = 1; i < myTable->numRows(); i++ ) { + tlts.append( myTable->verticalHeader()->label( i ) ); + } + } +} +/*! + Sets units title +*/ +void VisuGUI_TableWidget::setUnitsTitle( const QString& tlt ) { + // !!! first column contains units !!! + myOrientation == Horizontal ? myTable->horizontalHeader()->setLabel( 0, tlt.isNull() ? "" : tlt ) : myTable->verticalHeader()->setLabel( 0, tlt.isNull() ? "" : tlt ); +} +/*! + Sets units +*/ +void VisuGUI_TableWidget::setUnits( QStringList& units ) +{ + for ( int i = 0; i < units.count(); i++ ) { + myOrientation == Horizontal ? myTable->setText( i, 0, units[i].isNull() ? "" : units[i] ) : myTable->setText( 0, i, units[i].isNull() ? "" : units[i] ); + } +} +/*! + Gets units +*/ +void VisuGUI_TableWidget::getUnits( QStringList& units ) +{ + units.clear(); + if ( myOrientation == Horizontal ) { + for ( int i = 0; i < myTable->numRows(); i++ ) + units.append( myTable->text( i, 0 ).isNull() ? QString("") : myTable->text( i, 0 ) ); + } + else { + for ( int i = 0; i < myTable->numCols(); i++ ) + units.append( myTable->text( 0, i ).isNull() ? QString("") : myTable->text( 0, i ) ); + } +} +/*! + Sets row data +*/ +void VisuGUI_TableWidget::setRowData( int row, QStringList& data ) +{ + if ( row >= 0 && row < getNumRows() ) { + for ( int i = 0; i < data.count(); i++ ) { + if ( data[i].isNull() ) { + myOrientation == Horizontal ? myTable->clearCell( row, i+1 ) : + myTable->clearCell( i+1, row ); + } + else { + myOrientation == Horizontal ? myTable->setText( row, i+1, data[i] ) : + myTable->setText( i+1, row, data[i] ); + } + } + } +} +/*! + Gets row data +*/ +void VisuGUI_TableWidget::getRowData( int row, QStringList& data ) +{ + data.clear(); + if ( row >= 0 && row < getNumRows() ) { + if ( myOrientation == Horizontal ) { + for ( int i = 1; i < myTable->numCols(); i++ ) + data.append( myTable->text( row, i ) ); + } + else { + for ( int i = 1; i < myTable->numRows(); i++ ) + data.append( myTable->text( i, row ) ); + } + } +} +/*! + Adjusts table cell to see contents, button slot +*/ +void VisuGUI_TableWidget::adjustTable() +{ + int i; + for ( i = 0; i < myTable->numRows(); i++ ) + myTable->adjustRow( i ); + for ( i = 0; i < myTable->numCols(); i++ ) + myTable->adjustColumn( i ); +} +/*! + Called when selection changed in table +*/ +void VisuGUI_TableWidget::updateButtonsState() +{ + if ( myTable->isReadOnly() ) + return; + bool bDR = false; // + bool bDC = false; // + bool bSA = false; // button slot +*/ +void VisuGUI_TableWidget::selectAll() +{ + myTable->clearSelection(); + QTableSelection ts; + ts.init( 0, 0 ); ts.expandTo( myTable->numRows()-1, myTable->numCols()-1 ); + myTable->addSelection( ts ); + updateButtonsState(); +} +/*! + button slot +*/ +void VisuGUI_TableWidget::clearTable() +{ + int nbSel = myTable->numSelections(); + for ( int i = 0; i < nbSel; i++ ) { + QTableSelection ts = myTable->selection( i ); + for ( int j = ts.topRow(); j < ts.bottomRow()+1; j++) { + if ( myOrientation == Vertical && j == 0 ) { +// continue; // UNITS + } + for ( int k = ts.leftCol(); k < ts.rightCol()+1; k++) { + if ( myOrientation == Horizontal && k == 0 ) { +// continue; // UNITS + } + myTable->clearCell( j, k ); + } + } + } + if ( nbSel == 0 ) + myTable->clearCell( myTable->currentRow(), myTable->currentColumn() ); + myTable->clearSelection(); + updateButtonsState(); +} +/*! + Event filter - handles titles editing +*/ +bool VisuGUI_TableWidget::eventFilter( QObject* o, QEvent* e ) +{ + if ( e->type() == QEvent::MouseButtonDblClick) { + QMouseEvent* me = ( QMouseEvent* )e; + if ( me->button() == LeftButton && !myTable->isReadOnly() ) { + if ( o == myTable->horizontalHeader() ) { + for ( int i = 0; i < myTable->horizontalHeader()->count(); i++ ) { + QRect rect = myTable->horizontalHeader()->sectionRect( i ); + rect.addCoords( 1, 1, -1, -1 ); + if ( rect.contains( myTable->horizontalHeader()->mapFromGlobal( me->globalPos() ) ) ) { + if ( myOrientation == Vertical || i != 0 ) { + bool bOk; + QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ), + tr( "TITLE_LBL" ), + QLineEdit::Normal, + myTable->horizontalHeader()->label( i ), + &bOk, + this ); + if ( bOk && !tlt.isNull() ) + myTable->horizontalHeader()->setLabel( i, tlt ); + break; + } + } + } + } + if ( o == myTable->verticalHeader() ) { + for ( int i = 0; i < myTable->verticalHeader()->count(); i++ ) { + QRect rect = myTable->verticalHeader()->sectionRect( i ); + rect.addCoords( 1, 1, -1, -1 ); + if ( rect.contains( myTable->verticalHeader()->mapFromGlobal( me->globalPos() ) ) ) { + if ( myOrientation == Horizontal || i != 0 ) { + bool bOk; + QString tlt = QInputDialog::getText( tr( "SET_TITLE_TLT" ), + tr( "TITLE_LBL" ), + QLineEdit::Normal, + myTable->verticalHeader()->label( i ), + &bOk, + this ); + if ( bOk && !tlt.isNull() ) + myTable->verticalHeader()->setLabel( i, tlt ); + break; + } + } + } + } + } + } + else if ( e->type() == QEvent::KeyRelease && o == myTable ) { + QKeyEvent* ke = (QKeyEvent*)e; + if ( ke->key() == Key_Delete && !myTable->isEditing() ) { + clearTable(); + } + else if ( ke->key() == Key_Backspace && !myTable->isEditing() ) { + clearTable(); + int i = myTable->currentRow(); + int j = myTable->currentColumn() - 1; + if ( j < 0 ) { j = myTable->numCols()-1; i--; } + if ( i >= 0 && j >= 0 ) + myTable->setCurrentCell( i, j ); + } + } + return QWidget::eventFilter( o, e ); +} + + + diff --git a/src/VISUGUI/VisuGUI_TableDlg.h b/src/VISUGUI/VisuGUI_TableDlg.h new file mode 100644 index 00000000..82481f9e --- /dev/null +++ b/src/VISUGUI/VisuGUI_TableDlg.h @@ -0,0 +1,110 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VisuGUI_TableDlg.h +// Author : Vadim SANDLER +// Module : VISU + +#ifndef VisuGUI_TABLE_DLG_H +#define VisuGUI_TABLE_DLG_H + +#include +#include +#include + +class VisuGUI_Table; +class VisuGUI_TableWidget; + +#include + +class VisuGUI_TableDlg : public QDialog +{ + Q_OBJECT + +public: + + enum { ttNone, ttInt, ttReal, ttBoth, ttAuto }; + + VisuGUI_TableDlg( QWidget* parent, + _PTR(SObject) obj, + bool edit = false, + int which = ttAuto, + Orientation orient = Horizontal, + bool showColumnTitles = true ); + ~VisuGUI_TableDlg(); + +public slots: + void onOK(); + +private: + void initDlg(); + +private: + VisuGUI_TableWidget* myIntTable; + VisuGUI_TableWidget* myRealTable; + QPushButton* myOKBtn; + QPushButton* myCancelBtn; + + _PTR(SObject) myObject; +}; + +class VisuGUI_TableWidget : public QWidget +{ + Q_OBJECT +public: + VisuGUI_TableWidget( QWidget* parent = 0, + const char* name = 0, + bool edit = false, + Orientation orient = Horizontal, + bool showColumnTitles = true ); + ~VisuGUI_TableWidget(); + + void setTableTitle( const QString& title ); + QString getTableTitle(); + void setNumRows( const int num ); + int getNumRows(); + void setNumCols( const int num ); + int getNumCols(); + void setRowTitles( QStringList& tlts ); + void getRowTitles( QStringList& tlts ); + void setColTitles( QStringList& tlts ); + void getColTitles( QStringList& tlts ); + void setUnitsTitle( const QString& tlt ); + void setUnits( QStringList& units ); + void getUnits( QStringList& units ); + void setRowData( int row, QStringList& data ); + void getRowData( int row, QStringList& data ); + + VisuGUI_Table* getTable() { return myTable; } + QLineEdit* getTitleEdit() { return myTitleEdit; } + + bool eventFilter( QObject* o, QEvent* e); + +public slots: + void updateButtonsState(); + void addRow(); + void addCol(); + void delRow(); + void delCol(); + void adjustTable(); + void selectAll(); + void clearTable(); + +private: + QLineEdit* myTitleEdit; + VisuGUI_Table* myTable; + QPushButton* myAddRowBtn; + QPushButton* myAddColBtn; + QPushButton* myDelRowBtn; + QPushButton* myDelColBtn; + QPushButton* myAdjustBtn; + QPushButton* mySelectAllBtn; + QPushButton* myClearBtn; + Orientation myOrientation; +}; + +#endif // VisuGUI_TABLE_DLG_H + diff --git a/src/VISUGUI/VisuGUI_Tools.cxx b/src/VISUGUI/VisuGUI_Tools.cxx index 9b3516c5..3b89ae5d 100644 --- a/src/VISUGUI/VisuGUI_Tools.cxx +++ b/src/VISUGUI/VisuGUI_Tools.cxx @@ -306,10 +306,10 @@ namespace VISU } SVTK_ViewWindow* - GetViewWindow(const SalomeApp_Module* theModule) + GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate ) { if(SalomeApp_Application* anApp = theModule->getApp()){ - if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), true )){ + if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){ if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){ return dynamic_cast(aViewWindow); } @@ -543,10 +543,10 @@ namespace VISU } SPlot2d_Viewer* - GetPlot2dViewer(const SalomeApp_Module* theModule) + GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate) { if(SalomeApp_Application* anApp = theModule->getApp()){ - if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), true )){ + if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){ return dynamic_cast(aViewManager->getViewModel()); } } @@ -608,7 +608,7 @@ namespace VISU VISU::Table_i* table, int theDisplaying) { - SPlot2d_Viewer* aView = GetPlot2dViewer( theModule ); + SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary if ( !aView ) return; Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); @@ -656,7 +656,7 @@ namespace VISU VISU::Curve_i* theCurve, int theDisplaying) { - SPlot2d_Viewer* aView = GetPlot2dViewer( theModule ); + SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); if ( !aView ) return; Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); @@ -689,7 +689,7 @@ namespace VISU VISU::Container_i* container, int theDisplaying) { - SPlot2d_Viewer* aView = GetPlot2dViewer( theModule ); + SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); if ( !aView ) return; Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); @@ -717,4 +717,32 @@ namespace VISU } aPlot->Repaint(); } + + void + CreatePlot(SalomeApp_Module* theModule, + _PTR(SObject) theTableSO) + { + if ( IsSObjectTable(theTableSO) ) { + CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO); + CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer(); + if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) { + VISU::Table_i* pTable = dynamic_cast( VISU::GetServant(aTable).in() ); + VISU::Container_i* pContainer = dynamic_cast( VISU::GetServant(aContainer).in() ); + + if ( pContainer && pTable ) { + for ( int i = 2; i <= pTable->GetNbRows(); i++ ) { + CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i ); + if( !CORBA::is_nil( aNewCurve ) ) { + VISU::Curve_i* pCrv = dynamic_cast( VISU::GetServant(aNewCurve).in() ); + if ( pCrv ) { + pContainer->AddCurve( pCrv->_this() ); + } + } + } + theModule->updateObjBrowser(); + PlotContainer( theModule, pContainer, VISU::eDisplay ); + } + } + } + } } diff --git a/src/VISUGUI/VisuGUI_Tools.h b/src/VISUGUI/VisuGUI_Tools.h index 0f2ac85c..91034aeb 100644 --- a/src/VISUGUI/VisuGUI_Tools.h +++ b/src/VISUGUI/VisuGUI_Tools.h @@ -67,7 +67,7 @@ namespace VISU{ VISU::Storable::TRestoringMap getMapOfValue(_PTR(SObject) theSObject); QString getValue(SALOMEDS::SObject_var theSObject, QString theKey); QString getValue(_PTR(SObject) theSObject, QString theKey); - SVTK_ViewWindow* GetViewWindow(const SalomeApp_Module* theModule); + SVTK_ViewWindow* GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate = false ); SVTK_ViewWindow* GetViewWindow(); VISU_Actor* PublishInView(const SalomeApp_Module* theModule, VISU::Prs3d_i* thePrs); @@ -110,7 +110,7 @@ namespace VISU{ void ErasePrs3d(SalomeApp_Module* theModule, VISU::Prs3d_i* thePrs); - SPlot2d_Viewer* GetPlot2dViewer(const SalomeApp_Module* theModule); + SPlot2d_Viewer* GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate = false); void PlotTable( const SalomeApp_Module* theModule, VISU::Table_i* table, int theDisplaying ); @@ -120,6 +120,8 @@ namespace VISU{ void PlotContainer( const SalomeApp_Module* theModule, VISU::Container_i* container, int theDisplaying ); + void CreatePlot( SalomeApp_Module* theModule, + _PTR(SObject) theSobj ); } bool VISU::IsSObjectTable( _PTR(SObject) theSObject )