X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_AddQuadraticElementDlg.cxx;h=1c3106e735eb3c1ed149aceebfa603bd56d8d136;hp=1f1e5bd1427b7f3bcea6ad5879f0f6f78e2a051c;hb=0635c9fc80f67d1e5dc0e94ec85f487286a92070;hpb=79b1ac2b6df9117f16f11d444b1f165d477a1813 diff --git a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx index 1f1e5bd14..1c3106e73 100644 --- a/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddQuadraticElementDlg.cxx @@ -1,21 +1,28 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// 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. +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// 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. +// 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. // -// 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 +// 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. // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// 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 +// +// SMESH SMESHGUI : GUI for SMESH component +// File : SMESHGUI_AddMeshElementDlg.cxx +// Author : Nicolas REJNERI, Open CASCADE S.A.S. +// SMESH includes // #include "SMESHGUI_AddQuadraticElementDlg.h" @@ -24,69 +31,66 @@ #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" #include "SMESHGUI_IdValidator.h" -#include "SMESH_ActorUtils.h" -#include "SMDS_Mesh.hxx" -#include "SMESH_Actor.h" +#include +#include +#include +#include -#include "SUIT_Session.h" -#include "SUIT_MessageBox.h" -#include "LightApp_Application.h" +// SALOME GUI includes +#include +#include +#include +#include +#include -#include "SVTK_Selection.h" -#include "SVTK_Selector.h" -#include "SALOME_ListIO.hxx" -#include "SALOME_ListIteratorOfListIO.hxx" +#include -#include "SalomeApp_Study.h" -#include "SalomeApp_Application.h" +#include +#include -#include "SVTK_ViewModel.h" -#include "SVTK_ViewWindow.h" +#include -#include "utilities.h" +#include +// IDL includes +#include #include CORBA_SERVER_HEADER(SMESH_MeshEditor) -// OCCT Includes +// OCCT includes #include -#include -// VTK Includes -#include +// VTK includes #include -#include -#include -#include #include #include +#include #include - -#include -#include -#include -#include -#include - -// QT Includes -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // STL includes -#include - -using namespace std; +#include -namespace SMESH { +#define SPACING 6 +#define MARGIN 11 - void ReverseConnectivity( vector & ids, int type ) +namespace SMESH +{ + void ReverseConnectivity( std::vector & ids, int type ) { // for reverse connectivity of other types keeping the first id, see // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900 @@ -134,7 +138,7 @@ namespace SMESH { reverse( ids.begin(), ids.end() ); } else { - vector aRevIds( ids.size() ); + std::vector aRevIds( ids.size() ); for ( int i = 0; i < ids.size(); i++) aRevIds[ i ] = ids[ conn[ i ]]; ids = aRevIds; @@ -151,7 +155,11 @@ namespace SMESH { vtkUnstructuredGrid* myGrid; //vtkProperty* myBackProp, *myProp; - vtkFloatingPointType myRGB[3], myBackRGB[3]; + //vtkFloatingPointType myRGB[3], myBackRGB[3]; + + SALOME_Actor* myFaceOrientation; + vtkPolyDataMapper* myFaceOrientationDataMapper; + SMESH_FaceOrientationFilter* myFaceOrientationFilter; public: TElementSimulation (SalomeApp_Application* theApplication) @@ -174,18 +182,39 @@ namespace SMESH { myPreviewActor->SetMapper(myMapper); vtkProperty* myProp = vtkProperty::New(); - GetColor( "SMESH", "fill_color", myRGB[0], myRGB[1], myRGB[2], QColor( 0, 170, 255 ) ); - myProp->SetColor( myRGB[0], myRGB[1], myRGB[2] ); + vtkFloatingPointType aRGB[3], aBackRGB[3]; + GetColor( "SMESH", "fill_color", aRGB[0], aRGB[1], aRGB[2], QColor( 0, 170, 255 ) ); + myProp->SetColor( aRGB[0], aRGB[1], aRGB[2] ); myPreviewActor->SetProperty( myProp ); myProp->Delete(); vtkProperty* myBackProp = vtkProperty::New(); - GetColor( "SMESH", "backface_color", myBackRGB[0], myBackRGB[1], myBackRGB[2], QColor( 0, 0, 255 ) ); - myBackProp->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] ); + GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) ); + myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] ); myPreviewActor->SetBackfaceProperty( myBackProp ); myBackProp->Delete(); myVTKViewWindow->AddActor(myPreviewActor); + + // Orientation of faces + myFaceOrientationFilter = SMESH_FaceOrientationFilter::New(); + myFaceOrientationFilter->SetInput(myGrid); + + myFaceOrientationDataMapper = vtkPolyDataMapper::New(); + myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput()); + + myFaceOrientation = SALOME_Actor::New(); + myFaceOrientation->PickableOff(); + myFaceOrientation->VisibilityOff(); + myFaceOrientation->SetMapper(myFaceOrientationDataMapper); + + vtkProperty* anOrientationProp = vtkProperty::New(); + GetColor( "SMESH", "orientation_color", aRGB[0], aRGB[1], aRGB[2], QColor( 255, 255, 255 ) ); + anOrientationProp->SetColor( aRGB[0], aRGB[1], aRGB[2] ); + myFaceOrientation->SetProperty( anOrientationProp ); + anOrientationProp->Delete(); + + myVTKViewWindow->AddActor(myFaceOrientation); } typedef std::vector TVTKIds; @@ -220,8 +249,8 @@ namespace SMESH { aType = VTK_CONVEX_POINT_SET; break; case QUAD_PENTAHEDRON: - //aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2 - aType = VTK_CONVEX_POINT_SET; + aType = VTK_QUADRATIC_WEDGE; + //aType = VTK_CONVEX_POINT_SET; break; case QUAD_HEXAHEDRON: aType = VTK_QUADRATIC_HEXAHEDRON; @@ -236,9 +265,13 @@ namespace SMESH { } else { // VTK cell connectivity opposites the MED one for volumic elements - if ( theIds.size() > 8 ? !theReverse : theReverse ) { - ReverseConnectivity( theIds, theType ); + if( aType != VTK_QUADRATIC_WEDGE) { + if ( theIds.size() > 8 ? !theReverse : theReverse ) { + ReverseConnectivity( theIds, theType ); + } } + else if(theReverse) + ReverseConnectivity( theIds, theType ); } myGrid->Reset(); @@ -256,7 +289,7 @@ namespace SMESH { myPreviewActor->GetMapper()->Update(); myPreviewActor->SetRepresentation( theMode ); - SetVisibility(true); + SetVisibility(true, theActor->GetFacesOriented()); // restore normal orientation if ( aType == VTK_CONVEX_POINT_SET ) { @@ -267,9 +300,10 @@ namespace SMESH { } - void SetVisibility (bool theVisibility) + void SetVisibility (bool theVisibility, bool theShowOrientation = false) { myPreviewActor->SetVisibility(theVisibility); + myFaceOrientation->SetVisibility(theShowOrientation); RepaintCurrentView(); } @@ -278,12 +312,19 @@ namespace SMESH { { if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) { myVTKViewWindow->RemoveActor(myPreviewActor); + myVTKViewWindow->RemoveActor(myFaceOrientation); } myPreviewActor->Delete(); + myFaceOrientation->Delete(); myMapper->RemoveAllInputs(); myMapper->Delete(); + myFaceOrientationFilter->Delete(); + + myFaceOrientationDataMapper->RemoveAllInputs(); + myFaceOrientationDataMapper->Delete(); + myGrid->Delete(); // myProp->Delete(); @@ -317,20 +358,69 @@ static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7}; +/*! + \class BusyLocker + \brief Simple 'busy state' flag locker. + \internal +*/ + +class BusyLocker +{ +public: + //! Constructor. Sets passed boolean flag to \c true. + BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; } + //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false. + ~BusyLocker() { myBusy = false; } +private: + bool& myBusy; //! External 'busy state' boolean flag +}; + +/*! + \class IdEditItem + \brief Simple editable table item. + \internal +*/ + +class IdEditItem: public QTableWidgetItem +{ +public: + IdEditItem(const QString& text ); + ~IdEditItem(); + + QWidget* createEditor() const; +}; + +IdEditItem::IdEditItem(const QString& text ) + : QTableWidgetItem(text, QTableWidgetItem::UserType+100) +{ +} + +IdEditItem::~IdEditItem() +{ +} + +QWidget* IdEditItem::createEditor() const +{ + QLineEdit *aLineEdit = new QLineEdit(text(), tableWidget()); + aLineEdit->setValidator( new SMESHGUI_IdValidator(tableWidget(), 1) ); + return aLineEdit; +} + //================================================================================= // function : SMESHGUI_AddQuadraticElementDlg() // purpose : constructor //================================================================================= SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule, - const int theType, - const char* name, - bool modal, WFlags fl) - : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | - WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose), - mySMESHGUI( theModule ), - mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), - myType( theType ) + const int theType ) + : QDialog( SMESH::GetDesktop( theModule ) ), + mySMESHGUI( theModule ), + mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), + myType( theType ), + myBusy( false ) { + setModal( false ); + setAttribute( Qt::WA_DeleteOnClose, true ); + SalomeApp_Application* anApp = dynamic_cast (SUIT_Session::session()->activeApplication()); @@ -366,105 +456,83 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM anElementName = QString("QUADRATIC_EDGE"); } - QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName)); - QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName)); - QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName)); - QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName)); + QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName).toLatin1().data()); + QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName).toLatin1().data()); + QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName).toLatin1().data()); + QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName).toLatin1().data()); QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName)); QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT"))); - if (!name) - setName("SMESHGUI_AddQuadraticElementDlg"); - setCaption(caption); + setWindowTitle(caption); - setSizeGripEnabled(TRUE); - QGridLayout* aDialogLayout = new QGridLayout(this); - aDialogLayout->setSpacing(6); - aDialogLayout->setMargin(11); + setSizeGripEnabled(true); + + QVBoxLayout* aDialogLayout = new QVBoxLayout(this); + aDialogLayout->setSpacing(SPACING); + aDialogLayout->setMargin(MARGIN); /***************************************************************/ - GroupConstructors = new QButtonGroup(this, "GroupConstructors"); - GroupConstructors->setTitle(constructorGrTitle); - - GroupConstructors->setExclusive(TRUE); - GroupConstructors->setColumnLayout(0, Qt::Vertical); - GroupConstructors->layout()->setSpacing(0); - GroupConstructors->layout()->setMargin(0); - GroupConstructors->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); - QGridLayout* aGroupConstructorsLayout = new QGridLayout(GroupConstructors->layout()); - aGroupConstructorsLayout->setAlignment(Qt::AlignTop); - aGroupConstructorsLayout->setSpacing(6); - aGroupConstructorsLayout->setMargin(11); - myRadioButton1 = new QRadioButton(GroupConstructors, "myRadioButton1"); - myRadioButton1->setText(tr("" )); - myRadioButton1->setPixmap(image0); - myRadioButton1->setChecked(TRUE); - myRadioButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, myRadioButton1->sizePolicy().hasHeightForWidth())); - aGroupConstructorsLayout->addWidget(myRadioButton1, 0, 0); - aGroupConstructorsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1); - aDialogLayout->addWidget(GroupConstructors, 0, 0); + GroupConstructors = new QGroupBox(constructorGrTitle, this); + QButtonGroup* ButtonGroup = new QButtonGroup(this); + QHBoxLayout* aGroupConstructorsLayout = new QHBoxLayout(GroupConstructors); + aGroupConstructorsLayout->setSpacing(SPACING); + aGroupConstructorsLayout->setMargin(MARGIN); + + myRadioButton1 = new QRadioButton(GroupConstructors); + myRadioButton1->setIcon(image0); + aGroupConstructorsLayout->addWidget(myRadioButton1); + ButtonGroup->addButton(myRadioButton1, 0); /***************************************************************/ - GroupArguments = new QGroupBox(this, "GroupArguments"); - GroupArguments->setTitle(argumentsGrTitle); - GroupArguments->setColumnLayout(0, Qt::Vertical); - GroupArguments->layout()->setSpacing(0); - GroupArguments->layout()->setMargin(0); - GroupArguments->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding)); - QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments->layout()); - aGroupArgumentsLayout->setAlignment(Qt::AlignTop); - aGroupArgumentsLayout->setSpacing(6); - aGroupArgumentsLayout->setMargin(11); - QLabel* aCornerNodesLabel = new QLabel(GroupArguments, "aCornerNodesLabel"); - aCornerNodesLabel->setText(tr("SMESH_CORNER_NODES" )); - aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0); - mySelectButton = new QPushButton(GroupArguments, "mySelectButton"); - mySelectButton->setPixmap(image1); - aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1); - myCornerNodes = new QLineEdit(GroupArguments, "myCornerNodes"); - aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2); - - myTable = new QTable(GroupArguments); - aGroupArgumentsLayout->addMultiCellWidget(myTable, 1, 1, 0, 2); - - myReverseCB = new QCheckBox(GroupArguments, "myReverseCB"); - myReverseCB->setText(tr("SMESH_REVERSE" )); - aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0); - - aDialogLayout->addWidget(GroupArguments, 1, 0); + GroupArguments = new QGroupBox(argumentsGrTitle, this); + QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments); + aGroupArgumentsLayout->setSpacing(SPACING); + aGroupArgumentsLayout->setMargin(MARGIN); + + QLabel* aCornerNodesLabel = new QLabel(tr("SMESH_CORNER_NODES"), GroupArguments); + mySelectButton = new QPushButton(GroupArguments); + mySelectButton->setIcon(image1); + myCornerNodes = new QLineEdit(GroupArguments); + myTable = new QTableWidget(GroupArguments); + + myReverseCB = new QCheckBox(tr("SMESH_REVERSE"), GroupArguments); + + aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0); + aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1); + aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2); + aGroupArgumentsLayout->addWidget(myTable, 1, 0, 1, 3); + aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0, 1, 3); /***************************************************************/ - GroupButtons = new QGroupBox(this, "GroupButtons"); - GroupButtons->setColumnLayout(0, Qt::Vertical); - GroupButtons->layout()->setSpacing(0); - GroupButtons->layout()->setMargin(0); - GroupButtons->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); - QGridLayout* aGroupButtonsLayout = new QGridLayout(GroupButtons->layout()); - aGroupButtonsLayout->setAlignment(Qt::AlignTop); - aGroupButtonsLayout->setSpacing(6); - aGroupButtonsLayout->setMargin(11); - buttonCancel = new QPushButton(GroupButtons, "buttonCancel"); - buttonCancel->setText(tr("SMESH_BUT_CLOSE" )); - buttonCancel->setAutoDefault(TRUE); - aGroupButtonsLayout->addWidget(buttonCancel, 0, 3); - buttonApply = new QPushButton(GroupButtons, "buttonApply"); - buttonApply->setText(tr("SMESH_BUT_APPLY" )); - buttonApply->setAutoDefault(TRUE); - aGroupButtonsLayout->addWidget(buttonApply, 0, 1); - aGroupButtonsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2); - buttonOk = new QPushButton(GroupButtons, "buttonOk"); - buttonOk->setText(tr("SMESH_BUT_OK" )); - buttonOk->setAutoDefault(TRUE); - buttonOk->setDefault(TRUE); - aGroupButtonsLayout->addWidget(buttonOk, 0, 0); - buttonHelp = new QPushButton(GroupButtons, "buttonHelp"); - buttonHelp->setText(tr("SMESH_BUT_HELP" )); - buttonHelp->setAutoDefault(TRUE); - aGroupButtonsLayout->addWidget(buttonHelp, 0, 4); - - aDialogLayout->addWidget(GroupButtons, 2, 0); + GroupButtons = new QGroupBox(this); + QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons); + aGroupButtonsLayout->setSpacing(SPACING); + aGroupButtonsLayout->setMargin(MARGIN); + + buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons); + buttonOk->setAutoDefault(true); + buttonOk->setDefault(true); + buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons); + buttonApply->setAutoDefault(true); + buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons); + buttonCancel->setAutoDefault(true); + buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons); + buttonHelp->setAutoDefault(true); + + aGroupButtonsLayout->addWidget(buttonOk); + aGroupButtonsLayout->addSpacing(10); + aGroupButtonsLayout->addWidget(buttonApply); + aGroupButtonsLayout->addSpacing(10); + aGroupButtonsLayout->addStretch(); + aGroupButtonsLayout->addWidget(buttonCancel); + aGroupButtonsLayout->addWidget(buttonHelp); + + /***************************************************************/ + aDialogLayout->addWidget(GroupConstructors); + aDialogLayout->addWidget(GroupArguments); + aDialogLayout->addWidget(GroupButtons); Init(); /* Initialisations */ } @@ -475,7 +543,6 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM //================================================================================= SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg() { - // no need to delete child widgets, Qt does it all for us delete mySimulation; } @@ -485,9 +552,7 @@ SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg() //================================================================================= void SMESHGUI_AddQuadraticElementDlg::Init() { - GroupArguments->show(); - myRadioButton1->setChecked(TRUE); - myIsEditCorners = true; + myRadioButton1->setChecked(true); mySMESHGUI->SetActiveDialogBox((QDialog*)this); myActor = 0; @@ -532,38 +597,44 @@ void SMESHGUI_AddQuadraticElementDlg::Init() break; } - myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, "validator", myNbCorners)); + myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, myNbCorners)); /* initialize table */ - myTable->setNumCols(3); - myTable->setNumRows(aNumRows); + myTable->setColumnCount(3); + myTable->setRowCount(aNumRows); QStringList aColLabels; aColLabels.append(tr("SMESH_FIRST")); aColLabels.append(tr("SMESH_MIDDLE")); aColLabels.append(tr("SMESH_LAST")); - myTable->setColumnLabels(aColLabels); + myTable->setHorizontalHeaderLabels(aColLabels); - for ( int col = 0; col < myTable->numCols(); col++ ) + for ( int col = 0; col < myTable->columnCount(); col++ ) myTable->setColumnWidth(col, 80); - myTable->setColumnReadOnly(0, true); - myTable->setColumnReadOnly(2, true); + //myTable->setColumnReadOnly(0, true); // VSR: TODO + //myTable->setColumnReadOnly(2, true); // VSR: TODO myTable->setEnabled( false ); - for ( int row = 0; row < myTable->numRows(); row++ ) - { - SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( myTable, QTableItem::OnTyping, "" ); - anEditItem->setReplaceable(false); - myTable->setItem(row, 1, anEditItem); - } + for ( int row = 0; row < myTable->rowCount(); row++ ) + { + myTable->setItem( row, 0, new QTableWidgetItem( "" ) ); + myTable->item( row, 0 )->setFlags(0); + + IdEditItem* anEditItem = new IdEditItem( "" ); + anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); + myTable->setItem(row, 1, anEditItem); + + myTable->setItem( row, 2, new QTableWidgetItem( "" ) ); + myTable->item( row, 2 )->setFlags(0); + } /* signals and slots connections */ connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners())); connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument())); - connect(myTable, SIGNAL(doubleClicked(int, int, int, const QPoint&)), SLOT(onCellDoubleClicked(int, int, int, const QPoint&))); - connect(myTable, SIGNAL(valueChanged (int, int)), SLOT(onCellTextChange(int, int))); + connect(myTable, SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int))); + connect(myTable, SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int))); connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&))); connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int))); @@ -575,16 +646,12 @@ void SMESHGUI_AddQuadraticElementDlg::Init() connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog())); connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel())); - this->show(); // displays Dialog - // set selection mode SMESH::SetPointRepresentation(true); if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode( NodeSelection ); - myBusy = false; - SetEditCorners(); } @@ -594,68 +661,66 @@ void SMESHGUI_AddQuadraticElementDlg::Init() //================================================================================= void SMESHGUI_AddQuadraticElementDlg::ClickOnApply() { - if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) { - myBusy = true; - - vector anIds; + if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() ) + return; - switch (myType) { - case QUAD_EDGE: - anIds.push_back(myTable->text(0, 0).toInt()); - anIds.push_back(myTable->text(0, 2).toInt()); - anIds.push_back(myTable->text(0, 1).toInt()); - break; - case QUAD_TRIANGLE: - case QUAD_QUADRANGLE: - case QUAD_TETRAHEDRON: - case QUAD_PYRAMID: - case QUAD_PENTAHEDRON: - case QUAD_HEXAHEDRON: - for ( int row = 0; row < myNbCorners; row++ ) - anIds.push_back(myTable->text(row, 0).toInt()); - for ( int row = 0; row < myTable->numRows(); row++ ) - anIds.push_back(myTable->text(row, 1).toInt()); - break; - } - if ( myReverseCB->isChecked()) - SMESH::ReverseConnectivity( anIds, myType ); + BusyLocker lock( myBusy ); + + std::vector anIds; + + switch (myType) { + case QUAD_EDGE: + anIds.push_back(myTable->item(0, 0)->text().toInt()); + anIds.push_back(myTable->item(0, 2)->text().toInt()); + anIds.push_back(myTable->item(0, 1)->text().toInt()); + break; + case QUAD_TRIANGLE: + case QUAD_QUADRANGLE: + case QUAD_TETRAHEDRON: + case QUAD_PYRAMID: + case QUAD_PENTAHEDRON: + case QUAD_HEXAHEDRON: + for ( int row = 0; row < myNbCorners; row++ ) + anIds.push_back(myTable->item(row, 0)->text().toInt()); + for ( int row = 0; row < myTable->rowCount(); row++ ) + anIds.push_back(myTable->item(row, 1)->text().toInt()); + break; + } + if ( myReverseCB->isChecked()) + SMESH::ReverseConnectivity( anIds, myType ); - int aNumberOfIds = anIds.size(); - SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array; - anArrayOfIdeces->length( aNumberOfIds ); + int aNumberOfIds = anIds.size(); + SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array; + anArrayOfIdeces->length( aNumberOfIds ); - for (int i = 0; i < aNumberOfIds; i++) - anArrayOfIdeces[i] = anIds[ i ]; + for (int i = 0; i < aNumberOfIds; i++) + anArrayOfIdeces[i] = anIds[ i ]; - SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); - switch (myType) { - case QUAD_EDGE: - aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break; - case QUAD_TRIANGLE: - case QUAD_QUADRANGLE: - aMeshEditor->AddFace(anArrayOfIdeces.inout()); break; - case QUAD_TETRAHEDRON: - case QUAD_PYRAMID: - case QUAD_PENTAHEDRON: - case QUAD_HEXAHEDRON: - aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break; - } + SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); + switch (myType) { + case QUAD_EDGE: + aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break; + case QUAD_TRIANGLE: + case QUAD_QUADRANGLE: + aMeshEditor->AddFace(anArrayOfIdeces.inout()); break; + case QUAD_TETRAHEDRON: + case QUAD_PYRAMID: + case QUAD_PENTAHEDRON: + case QUAD_HEXAHEDRON: + aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break; + } - SALOME_ListIO aList; aList.Append( myActor->getIO() ); - mySelector->ClearIndex(); - mySelectionMgr->setSelectedObjects( aList, false ); + SALOME_ListIO aList; aList.Append( myActor->getIO() ); + mySelector->ClearIndex(); + mySelectionMgr->setSelectedObjects( aList, false ); - SMESH::UpdateView(); - mySimulation->SetVisibility(false); + mySimulation->SetVisibility(false); + SMESH::UpdateView(); - buttonOk->setEnabled(false); - buttonApply->setEnabled(false); - - UpdateTable(); - SetEditCorners(); + UpdateTable(); + SetEditCorners(); - myBusy = false; - } + updateButtons(); } //================================================================================= @@ -666,7 +731,6 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnOk() { ClickOnApply(); ClickOnCancel(); - return; } //================================================================================= @@ -683,7 +747,6 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel() disconnect(mySelectionMgr, 0, this, 0); mySMESHGUI->ResetState(); reject(); - return; } //================================================================================= @@ -696,16 +759,17 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp() if (app) app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName); else { - QString platform; + QString platform; #ifdef WIN32 - platform = "winapplication"; + platform = "winapplication"; #else - platform = "application"; + platform = "application"; #endif - SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"), - QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName), - QObject::tr("BUT_OK")); + SUIT_MessageBox::warning(this, tr("WRN_WARNING"), + tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser", + platform)). + arg(myHelpFileName)); } } @@ -716,11 +780,8 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp() void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText) { if (myBusy) return; - myBusy = true; + BusyLocker lock( myBusy ); - buttonOk->setEnabled(false); - buttonApply->setEnabled(false); - mySimulation->SetVisibility(false); // hilight entered nodes @@ -731,16 +792,18 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText) if (aMesh) { TColStd_MapOfInteger newIndices; - QStringList aListId = QStringList::split(" ", theNewText, false); + QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts); bool allOk = true; for (int i = 0; i < aListId.count(); i++) { - if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) ) + if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) ) + { newIndices.Add( n->GetID() ); + } else - { - allOk = false; - break; - } + { + allOk = false; + break; + } } mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false ); @@ -751,15 +814,8 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText) UpdateTable( allOk ); } - if( IsValid() ) { - buttonOk->setEnabled(true); - buttonApply->setEnabled(true); - } - - if ( sender() == myTable ) - displaySimulation(); - - myBusy = false; + updateButtons(); + displaySimulation(); } //================================================================================= @@ -769,73 +825,65 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText) void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument() { if (myBusy) return; + BusyLocker lock( myBusy ); if ( myIsEditCorners ) - { - // clear - myActor = 0; - - myBusy = true; - myCornerNodes->setText(""); - myBusy = false; - - if (!GroupButtons->isEnabled()) // inactive - return; - - buttonOk->setEnabled(false); - buttonApply->setEnabled(false); - - mySimulation->SetVisibility(false); - - // get selected mesh - SALOME_ListIO aList; - mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type()); + { + // clear + myActor = 0; + + myCornerNodes->setText(""); + + if (!GroupButtons->isEnabled()) // inactive + return; + + mySimulation->SetVisibility(false); - if (aList.Extent() != 1) - { - UpdateTable(); - return; - } + // get selected mesh + SALOME_ListIO aList; + mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type()); + + if (aList.Extent() != 1) + { + UpdateTable(); + updateButtons(); + return; + } - Handle(SALOME_InteractiveObject) anIO = aList.First(); - myMesh = SMESH::GetMeshByIO(anIO); - if (myMesh->_is_nil()) - return; + Handle(SALOME_InteractiveObject) anIO = aList.First(); + myMesh = SMESH::GetMeshByIO(anIO); + if (myMesh->_is_nil()) { + updateButtons(); + return; + } - myActor = SMESH::FindActorByEntry(anIO->getEntry()); + myActor = SMESH::FindActorByEntry(anIO->getEntry()); - } + } - if (!myActor) + if (!myActor) { + updateButtons(); return; + } // get selected nodes QString aString = ""; int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString); if ( myIsEditCorners ) - { - myBusy = true; - myCornerNodes->setText(aString); - myBusy = false; - - UpdateTable(); - } + { + myCornerNodes->setText(aString); + + UpdateTable(); + } else if ( myTable->isEnabled() && nbNodes == 1 ) - { - myBusy = true; - int theRow = myTable->currentRow(), theCol = myTable->currentColumn(); - if ( theCol == 1 ) - myTable->setText(theRow, 1, aString); - myBusy = false; - } + { + int theRow = myTable->currentRow(), theCol = myTable->currentColumn(); + if ( theCol == 1 ) + myTable->item(theRow, 1)->setText(aString); + } - if ( IsValid() ) - { - buttonOk->setEnabled( true ); - buttonApply->setEnabled( true ); - } - + updateButtons(); displaySimulation(); } @@ -845,42 +893,47 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument() //================================================================================= void SMESHGUI_AddQuadraticElementDlg::displaySimulation() { - if (!myIsEditCorners) { + if ( IsValid() ) + { SMESH::TElementSimulation::TVTKIds anIds; // Collect ids from the dialog int anID; bool ok; int aDisplayMode = VTK_SURFACE; - + if ( myType == QUAD_EDGE ) - { - anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) ); - anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) ); - anID = (myTable->text(0, 1)).toInt(&ok); - if (!ok) anID = (myTable->text(0, 0)).toInt(); - anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) ); - aDisplayMode = VTK_WIREFRAME; - } + { + anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) ); + anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) ); + anID = myTable->item(0, 1)->text().toInt(&ok); + if (!ok) anID = myTable->item(0, 0)->text().toInt(); + anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) ); + aDisplayMode = VTK_WIREFRAME; + } else + { + for ( int row = 0; row < myNbCorners; row++ ) + anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) ); + + for ( int row = 0; row < myTable->rowCount(); row++ ) { - for ( int row = 0; row < myNbCorners; row++ ) - anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(row, 0).toInt() ) ); - - for ( int row = 0; row < myTable->numRows(); row++ ) - { - anID = (myTable->text(row, 1)).toInt(&ok); - if (!ok) { - anID = (myTable->text(row, 0)).toInt(); - aDisplayMode = VTK_WIREFRAME; - } - anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) ); - } + anID = myTable->item(row, 1)->text().toInt(&ok); + if (!ok) { + anID = myTable->item(row, 0)->text().toInt(); + aDisplayMode = VTK_WIREFRAME; + } + anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) ); } + } mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked()); - SMESH::UpdateView(); } + else + { + mySimulation->SetVisibility(false); + } + SMESH::UpdateView(); } //================================================================================= @@ -891,8 +944,8 @@ void SMESHGUI_AddQuadraticElementDlg::SetEditCorners() { myCornerNodes->setFocus(); myIsEditCorners = true; - SelectionIntoArgument(); + updateButtons(); } //================================================================================= @@ -940,7 +993,6 @@ void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*) if (GroupConstructors->isEnabled()) return; ActivateThisDialog(); - return; } //================================================================================= @@ -951,7 +1003,6 @@ void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*) { /* same than click on cancel button */ ClickOnCancel(); - return; } //================================================================================= @@ -970,13 +1021,9 @@ void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*) //================================================================================= void SMESHGUI_AddQuadraticElementDlg::onReverse (int state) { - if (!IsValid()) - return; - - if (state >= 0) { - mySimulation->SetVisibility(false); - displaySimulation(); - } + mySimulation->SetVisibility(false); + displaySimulation(); + updateButtons(); } @@ -994,16 +1041,16 @@ bool SMESHGUI_AddQuadraticElementDlg::IsValid() bool ok; - for ( int row = 0; row < myTable->numRows(); row++ ) - { - int anID = (myTable->text(row, 1)).toInt(&ok); - if ( !ok ) - return false; - - const SMDS_MeshNode * aNode = aMesh->FindNode(anID); - if ( !aNode ) - return false; - } + for ( int row = 0; row < myTable->rowCount(); row++ ) + { + int anID = myTable->item(row, 1)->text().toInt(&ok); + if ( !ok ) + return false; + + const SMDS_MeshNode * aNode = aMesh->FindNode(anID); + if ( !aNode ) + return false; + } return true; } @@ -1014,66 +1061,66 @@ bool SMESHGUI_AddQuadraticElementDlg::IsValid() //================================================================================= void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity ) { - QStringList aListCorners = QStringList::split(" ", myCornerNodes->text(), false); + QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts); if ( aListCorners.count() == myNbCorners && theConersValidity ) - { - myTable->setEnabled( true ); - - // clear the Middle column - for ( int row = 0; row < myTable->numRows(); row++ ) - myTable->setText( row, 1, ""); - - int* aFirstColIds; - int* aLastColIds; - - switch (myType) { - case QUAD_EDGE: - aFirstColIds = FirstEdgeIds; - aLastColIds = LastEdgeIds; - break; - case QUAD_TRIANGLE: - aFirstColIds = FirstTriangleIds; - aLastColIds = LastTriangleIds; - break; - case QUAD_QUADRANGLE: - aFirstColIds = FirstQuadrangleIds; - aLastColIds = LastQuadrangleIds; - break; - case QUAD_TETRAHEDRON: - aFirstColIds = FirstTetrahedronIds; - aLastColIds = LastTetrahedronIds; - break; - case QUAD_PYRAMID: - aFirstColIds = FirstPyramidIds; - aLastColIds = LastPyramidIds; - break; - case QUAD_PENTAHEDRON: - aFirstColIds = FirstPentahedronIds; - aLastColIds = LastPentahedronIds; - break; - case QUAD_HEXAHEDRON: - aFirstColIds = FirstHexahedronIds; - aLastColIds = LastHexahedronIds; - break; - } - - // fill the First and the Last columns - for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++) - myTable->setText( i, 0, aListCorners[ aFirstColIds[i] ] ); - - for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++) - myTable->setText( i, 2, aListCorners[ aLastColIds[i] ] ); + { + myTable->setEnabled( true ); + + // clear the Middle column + for ( int row = 0; row < myTable->rowCount(); row++ ) + myTable->item( row, 1 )->setText(""); + + int* aFirstColIds; + int* aLastColIds; + + switch (myType) { + case QUAD_EDGE: + aFirstColIds = FirstEdgeIds; + aLastColIds = LastEdgeIds; + break; + case QUAD_TRIANGLE: + aFirstColIds = FirstTriangleIds; + aLastColIds = LastTriangleIds; + break; + case QUAD_QUADRANGLE: + aFirstColIds = FirstQuadrangleIds; + aLastColIds = LastQuadrangleIds; + break; + case QUAD_TETRAHEDRON: + aFirstColIds = FirstTetrahedronIds; + aLastColIds = LastTetrahedronIds; + break; + case QUAD_PYRAMID: + aFirstColIds = FirstPyramidIds; + aLastColIds = LastPyramidIds; + break; + case QUAD_PENTAHEDRON: + aFirstColIds = FirstPentahedronIds; + aLastColIds = LastPentahedronIds; + break; + case QUAD_HEXAHEDRON: + aFirstColIds = FirstHexahedronIds; + aLastColIds = LastHexahedronIds; + break; } + + // fill the First and the Last columns + for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++) + myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] ); + + for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++) + myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] ); + } else - { - // clear table - for ( int row = 0; row < myTable->numRows(); row++ ) - for ( int col = 0; col < myTable->numCols(); col++ ) - myTable->setText(row, col, ""); - - myTable->setEnabled( false ); - } + { + // clear table + for ( int row = 0; row < myTable->rowCount(); row++ ) + for ( int col = 0; col < myTable->columnCount(); col++ ) + if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText(""); + + myTable->setEnabled( false ); + } } @@ -1081,13 +1128,11 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity ) // function : onTableActivate() // purpose : //================================================================================= -void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol, int theButton, const QPoint& theMousePos ) +void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol ) { - if ( theButton == 1 && theCol == 1 ) - myIsEditCorners = false; - + myIsEditCorners = false; displaySimulation(); - return; + updateButtons(); } @@ -1097,15 +1142,9 @@ void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCo //================================================================================= void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol) { - onTextChange( myTable->text(theRow, theCol) ); -} - - -QWidget* SMESHGUI_IdEditItem::createEditor() const -{ - QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport()); - aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) ); - return aLineEdit; + myIsEditCorners = false; + displaySimulation(); + updateButtons(); } //================================================================================= @@ -1118,9 +1157,15 @@ void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e ) if ( e->isAccepted() ) return; - if ( e->key() == Key_F1 ) - { - e->accept(); - ClickOnHelp(); - } + if ( e->key() == Qt::Key_F1 ) { + e->accept(); + ClickOnHelp(); + } +} + +void SMESHGUI_AddQuadraticElementDlg::updateButtons() +{ + bool valid = IsValid(); + buttonOk->setEnabled( valid ); + buttonApply->setEnabled( valid ); }