Back to index

salome-smesh  6.5.0
SMESHGUI_AddQuadraticElementDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_AddMeshElementDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_AddQuadraticElementDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_GroupUtils.h"
00035 #include "SMESHGUI_IdValidator.h"
00036 
00037 #include <SMESH_Actor.h>
00038 #include <SMESH_ActorUtils.h>
00039 #include <SMESH_FaceOrientationFilter.h>
00040 #include <SMDS_Mesh.hxx>
00041 
00042 // SALOME GUI includes
00043 #include <SUIT_Desktop.h>
00044 #include <SUIT_Session.h>
00045 #include <SUIT_MessageBox.h>
00046 #include <SUIT_ResourceMgr.h>
00047 #include <SUIT_ViewManager.h>
00048 
00049 #include <LightApp_SelectionMgr.h>
00050 
00051 #include <SVTK_ViewModel.h>
00052 #include <SVTK_ViewWindow.h>
00053 
00054 #include <SALOME_ListIO.hxx>
00055 
00056 #include <SalomeApp_Application.h>
00057 
00058 // IDL includes
00059 #include <SALOMEconfig.h>
00060 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00061 
00062 // OCCT includes
00063 #include <TColStd_MapOfInteger.hxx>
00064 
00065 // VTK includes
00066 #include <vtkIdList.h>
00067 #include <vtkUnstructuredGrid.h>
00068 #include <vtkDataSetMapper.h>
00069 #include <vtkPolyDataMapper.h>
00070 #include <vtkProperty.h>
00071 #include <vtkCellType.h>
00072 
00073 // Qt includes
00074 #include <QComboBox>
00075 #include <QGroupBox>
00076 #include <QLabel>
00077 #include <QLineEdit>
00078 #include <QPushButton>
00079 #include <QRadioButton>
00080 #include <QVBoxLayout>
00081 #include <QHBoxLayout>
00082 #include <QGridLayout>
00083 #include <QCheckBox>
00084 #include <QTableWidget>
00085 #include <QKeyEvent>
00086 #include <QButtonGroup>
00087 
00088 // STL includes
00089 #include <vector>
00090 
00091 #define SPACING 6
00092 #define MARGIN  11
00093 
00094 namespace
00095 {
00096   void ReverseConnectivity( std::vector<vtkIdType> & ids, SMDSAbs_EntityType type,
00097                             bool toReverse, // inverse element
00098                             bool toVtkOrder ) // smds connectivity to vtk one
00099   {
00100     if ( toReverse ) // first reverse smds order
00101     {
00102       const std::vector<int>& index = SMDS_MeshCell::reverseSmdsOrder(type);
00103       SMDS_MeshCell::applyInterlace( index, ids );
00104     }
00105     if ( toVtkOrder ) // from smds to vtk connectivity
00106     {
00107       const std::vector<int>& index = SMDS_MeshCell::toVtkOrder(type);
00108       SMDS_MeshCell::applyInterlace( index, ids );
00109     }
00110   }
00111 }
00112 namespace SMESH
00113 {
00114   class TElementSimulation {
00115     SalomeApp_Application* myApplication;
00116     SUIT_ViewWindow* myViewWindow;
00117     SVTK_ViewWindow* myVTKViewWindow;
00118 
00119     SALOME_Actor* myPreviewActor;
00120     vtkDataSetMapper* myMapper;
00121     vtkUnstructuredGrid* myGrid;
00122     //vtkProperty* myBackProp, *myProp;
00123 
00124     //vtkFloatingPointType myRGB[3], myBackRGB[3];
00125 
00126     SALOME_Actor* myFaceOrientation;
00127     vtkPolyDataMapper* myFaceOrientationDataMapper;
00128     SMESH_FaceOrientationFilter* myFaceOrientationFilter;
00129 
00130   public:
00131     TElementSimulation (SalomeApp_Application* theApplication)
00132     {
00133       myApplication = theApplication;
00134       SUIT_ViewManager* mgr = theApplication->activeViewManager();
00135       if (!mgr) return;
00136       myViewWindow = mgr->getActiveView();
00137       myVTKViewWindow = GetVtkViewWindow(myViewWindow);
00138 
00139       myGrid = vtkUnstructuredGrid::New();
00140 
00141       // Create and display actor
00142       myMapper = vtkDataSetMapper::New();
00143       myMapper->SetInput(myGrid);
00144 
00145       myPreviewActor = SALOME_Actor::New();
00146       myPreviewActor->PickableOff();
00147       myPreviewActor->VisibilityOff();
00148       myPreviewActor->SetMapper(myMapper);
00149 
00150       vtkProperty* myProp = vtkProperty::New();
00151       vtkFloatingPointType aRGB[3], aBackRGB[3];
00152       GetColor( "SMESH", "fill_color", aRGB[0], aRGB[1], aRGB[2], QColor( 0, 170, 255 ) );
00153       myProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
00154       myPreviewActor->SetProperty( myProp );
00155       myProp->Delete();
00156 
00157       vtkProperty* myBackProp = vtkProperty::New();
00158       GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
00159       myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
00160       myPreviewActor->SetBackfaceProperty( myBackProp );
00161       myBackProp->Delete();
00162 
00163       myVTKViewWindow->AddActor(myPreviewActor);
00164 
00165       // Orientation of faces
00166       myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
00167       myFaceOrientationFilter->SetInput(myGrid);
00168 
00169       myFaceOrientationDataMapper = vtkPolyDataMapper::New();
00170       myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
00171 
00172       myFaceOrientation = SALOME_Actor::New();
00173       myFaceOrientation->PickableOff();
00174       myFaceOrientation->VisibilityOff();
00175       myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
00176 
00177       vtkProperty* anOrientationProp = vtkProperty::New();
00178       GetColor( "SMESH", "orientation_color", aRGB[0], aRGB[1], aRGB[2], QColor( 255, 255, 255 ) );
00179       anOrientationProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
00180       myFaceOrientation->SetProperty( anOrientationProp );
00181       anOrientationProp->Delete();
00182 
00183       myVTKViewWindow->AddActor(myFaceOrientation);
00184     }
00185 
00186     typedef std::vector<vtkIdType> TVTKIds;
00187     void SetPosition (SMESH_Actor*       theActor,
00188                       SMDSAbs_EntityType theType,
00189                       TVTKIds&           theIds,
00190                       const int          theMode,
00191                       const bool         theReverse)
00192     {
00193       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
00194       myGrid->SetPoints(aGrid->GetPoints());
00195 
00196       //add points
00197 
00198       ReverseConnectivity( theIds, theType, theReverse, /*toVtkOrder=*/true);
00199 
00200       myGrid->Reset();
00201       vtkIdList *anIds = vtkIdList::New();
00202 
00203       for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
00204         anIds->InsertId(i,theIds[i]);
00205         //std::cout << i<< ": " << theIds[i] << std::endl;
00206       }
00207 
00208       vtkIdType aType = SMDS_MeshCell::toVtkType(theType);
00209       myGrid->InsertNextCell(aType,anIds);
00210       anIds->Delete();
00211 
00212       myGrid->Modified();
00213 
00214       myPreviewActor->GetMapper()->Update();
00215       myPreviewActor->SetRepresentation( theMode );
00216       SetVisibility(true, theActor->GetFacesOriented());
00217     }
00218 
00219 
00220     void SetVisibility (bool theVisibility, bool theShowOrientation = false)
00221     {
00222       myPreviewActor->SetVisibility(theVisibility);
00223       myFaceOrientation->SetVisibility(theShowOrientation);
00224       RepaintCurrentView();
00225     }
00226 
00227 
00228     ~TElementSimulation()
00229     {
00230       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
00231         myVTKViewWindow->RemoveActor(myPreviewActor);
00232         myVTKViewWindow->RemoveActor(myFaceOrientation);
00233       }
00234       myPreviewActor->Delete();
00235       myFaceOrientation->Delete();
00236 
00237       myMapper->RemoveAllInputs();
00238       myMapper->Delete();
00239 
00240       myFaceOrientationFilter->Delete();
00241 
00242       myFaceOrientationDataMapper->RemoveAllInputs();
00243       myFaceOrientationDataMapper->Delete();
00244 
00245       myGrid->Delete();
00246 
00247 //       myProp->Delete();
00248 //       myBackProp->Delete();
00249     }
00250   };
00251 }
00252 
00253 
00254 // Define the sequences of ids
00255 static int FirstEdgeIds[] = {0};
00256 static int LastEdgeIds[] =  {1};
00257 
00258 static int FirstTriangleIds[] = {0,1,2};
00259 static int LastTriangleIds[] =  {1,2,0};
00260 
00261 static int FirstQuadrangleIds[] = {0,1,2,3};
00262 static int LastQuadrangleIds[] =  {1,2,3,0};
00263 
00264 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
00265 static int LastTetrahedronIds[] =  {1,2,0,0,1,2};
00266 
00267 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
00268 static int LastPyramidIds[] =  {1,2,3,0,0,1,2,3};
00269 
00270 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
00271 static int LastPentahedronIds[] =  {1,2,0,4,5,3,3,4,5};
00272 
00273 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
00274 static int LastHexahedronIds[] =  {1,2,3,0,5,6,7,4,4,5,6,7};
00275 
00282 class BusyLocker
00283 {
00284 public:
00286   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
00288   ~BusyLocker() { myBusy = false; }
00289 private:
00290   bool& myBusy; 
00291 };
00292 
00299 class IdEditItem: public QTableWidgetItem
00300 {
00301 public:
00302   IdEditItem(const QString& text );
00303   ~IdEditItem();
00304 
00305   QWidget* createEditor() const;
00306 };
00307 
00308 IdEditItem::IdEditItem(const QString& text )
00309   : QTableWidgetItem(text, QTableWidgetItem::UserType+100)
00310 {
00311 }
00312 
00313 IdEditItem::~IdEditItem()
00314 {
00315 }
00316 
00317 QWidget* IdEditItem::createEditor() const
00318 {
00319   QLineEdit *aLineEdit = new QLineEdit(text(), tableWidget());
00320   aLineEdit->setValidator( new SMESHGUI_IdValidator(tableWidget(), 1) );
00321   return aLineEdit;
00322 }
00323 
00324 //=================================================================================
00325 // function : SMESHGUI_AddQuadraticElementDlg()
00326 // purpose  : constructor
00327 //=================================================================================
00328 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
00329                                                                   const SMDSAbs_EntityType theType )
00330   : QDialog( SMESH::GetDesktop( theModule ) ),
00331     mySMESHGUI( theModule ),
00332     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00333     myGeomType( theType ),
00334     //myType( theType ),
00335     myBusy( false )
00336 {
00337   setModal( false );
00338   setAttribute( Qt::WA_DeleteOnClose, true );
00339 
00340   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
00341     (SUIT_Session::session()->activeApplication());
00342 
00343   mySimulation = new SMESH::TElementSimulation (anApp);
00344   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00345 
00346   QString anElementName;
00347 
00348   switch ( myGeomType ) {
00349   case SMDSEntity_Quad_Edge:
00350     anElementName = QString("QUADRATIC_EDGE");
00351     break;
00352   case SMDSEntity_Quad_Triangle:
00353     anElementName = QString("QUADRATIC_TRIANGLE");
00354     break;
00355   case SMDSEntity_Quad_Quadrangle:
00356     anElementName = QString("QUADRATIC_QUADRANGLE");
00357     break;
00358   case SMDSEntity_BiQuad_Quadrangle:
00359     anElementName = QString("BIQUADRATIC_QUADRANGLE");
00360     break;
00361   case SMDSEntity_Quad_Tetra:
00362     anElementName = QString("QUADRATIC_TETRAHEDRON");
00363     break;
00364   case SMDSEntity_Quad_Pyramid:
00365     anElementName = QString("QUADRATIC_PYRAMID");
00366     break;
00367   case SMDSEntity_Quad_Penta:
00368     anElementName = QString("QUADRATIC_PENTAHEDRON");
00369     break;
00370   case SMDSEntity_Quad_Hexa:
00371     anElementName = QString("QUADRATIC_HEXAHEDRON");
00372     break;
00373   case SMDSEntity_TriQuad_Hexa:
00374     anElementName = QString("TRIQUADRATIC_HEXAHEDRON");
00375     break;
00376   default:
00377     myGeomType = SMDSEntity_Quad_Edge;
00378     anElementName = QString("QUADRATIC_EDGE");
00379   }
00380 
00381   QString iconName           = tr(QString("ICON_DLG_%1").arg(anElementName).toLatin1().data());
00382   QString caption            = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName).toLatin1().data());
00383   QString argumentsGrTitle   = tr(QString("SMESH_ADD_%1").arg(anElementName).toLatin1().data());
00384   QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName).toLatin1().data());
00385 
00386   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
00387   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00388 
00389   setWindowTitle(caption);
00390 
00391   setSizeGripEnabled(true);
00392 
00393   QVBoxLayout* aDialogLayout = new QVBoxLayout(this);
00394   aDialogLayout->setSpacing(SPACING);
00395   aDialogLayout->setMargin(MARGIN);
00396 
00397   /***************************************************************/
00398   GroupConstructors = new QGroupBox(constructorGrTitle, this);
00399   QButtonGroup* ButtonGroup = new QButtonGroup(this);
00400   QHBoxLayout* aGroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00401   aGroupConstructorsLayout->setSpacing(SPACING);
00402   aGroupConstructorsLayout->setMargin(MARGIN);
00403 
00404   myRadioButton1 = new QRadioButton(GroupConstructors);
00405   myRadioButton1->setIcon(image0);
00406   aGroupConstructorsLayout->addWidget(myRadioButton1);
00407   ButtonGroup->addButton(myRadioButton1, 0);
00408 
00409   /***************************************************************/
00410   GroupArguments = new QGroupBox(argumentsGrTitle, this);
00411   QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments);
00412   aGroupArgumentsLayout->setSpacing(SPACING);
00413   aGroupArgumentsLayout->setMargin(MARGIN);
00414 
00415   // Corner nodes
00416   QLabel* aCornerNodesLabel = new QLabel(tr("SMESH_CORNER_NODES"), GroupArguments);
00417   myCornerSelectButton = new QPushButton(GroupArguments);
00418   myCornerSelectButton->setIcon(image1);
00419   myCornerNodes = new QLineEdit(GroupArguments);
00420 
00421   // Mid-edge nodes
00422   myTable = new QTableWidget(GroupArguments);
00423 
00424   // Mid-face nodes
00425   myMidFaceLabel = new QLabel(tr("SMESH_MIDFACE_NODES"), GroupArguments);
00426   myMidFaceSelectButton = new QPushButton(GroupArguments);
00427   myMidFaceSelectButton->setIcon(image1);
00428   myMidFaceNodes = new QLineEdit(GroupArguments);
00429   myMidFaceNodes->setValidator(new SMESHGUI_IdValidator(this, 6));
00430 
00431   // Central node
00432   myCenterLabel = new QLabel(tr("SMESH_CENTER_NODE"), GroupArguments);
00433   myCenterSelectButton = new QPushButton(GroupArguments);
00434   myCenterSelectButton->setIcon(image1);
00435   myCenterNode = new QLineEdit(GroupArguments);
00436   myCenterNode->setValidator(new SMESHGUI_IdValidator(this, 1));
00437 
00438   myReverseCB = new QCheckBox(tr("SMESH_REVERSE"), GroupArguments);
00439 
00440   aGroupArgumentsLayout->addWidget(aCornerNodesLabel,     0, 0);
00441   aGroupArgumentsLayout->addWidget(myCornerSelectButton,  0, 1);
00442   aGroupArgumentsLayout->addWidget(myCornerNodes,         0, 2);
00443   aGroupArgumentsLayout->addWidget(myTable,               1, 0, 1, 3);
00444   aGroupArgumentsLayout->addWidget(myMidFaceLabel,        2, 0);
00445   aGroupArgumentsLayout->addWidget(myMidFaceSelectButton, 2, 1);
00446   aGroupArgumentsLayout->addWidget(myMidFaceNodes,        2, 2);
00447   aGroupArgumentsLayout->addWidget(myCenterLabel,         3, 0);
00448   aGroupArgumentsLayout->addWidget(myCenterSelectButton,  3, 1);
00449   aGroupArgumentsLayout->addWidget(myCenterNode,          3, 2);
00450   aGroupArgumentsLayout->addWidget(myReverseCB,           4, 0, 1, 3);
00451 
00452     /***************************************************************/
00453   GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
00454   GroupGroups->setCheckable( true );
00455   QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
00456   GroupGroupsLayout->setSpacing(SPACING);
00457   GroupGroupsLayout->setMargin(MARGIN);
00458 
00459   TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
00460   ComboBox_GroupName = new QComboBox( GroupGroups );
00461   ComboBox_GroupName->setEditable( true );
00462   ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
00463 
00464   GroupGroupsLayout->addWidget( TextLabel_GroupName );
00465   GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
00466 
00467   /***************************************************************/
00468   GroupButtons = new QGroupBox(this);
00469   QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons);
00470   aGroupButtonsLayout->setSpacing(SPACING);
00471   aGroupButtonsLayout->setMargin(MARGIN);
00472 
00473   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00474   buttonOk->setAutoDefault(true);
00475   buttonOk->setDefault(true);
00476   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00477   buttonApply->setAutoDefault(true);
00478   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00479   buttonCancel->setAutoDefault(true);
00480   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00481   buttonHelp->setAutoDefault(true);
00482 
00483   aGroupButtonsLayout->addWidget(buttonOk);
00484   aGroupButtonsLayout->addSpacing(10);
00485   aGroupButtonsLayout->addWidget(buttonApply);
00486   aGroupButtonsLayout->addSpacing(10);
00487   aGroupButtonsLayout->addStretch();
00488   aGroupButtonsLayout->addWidget(buttonCancel);
00489   aGroupButtonsLayout->addWidget(buttonHelp);
00490 
00491   /***************************************************************/
00492   aDialogLayout->addWidget(GroupConstructors);
00493   aDialogLayout->addWidget(GroupArguments);
00494   aDialogLayout->addWidget(GroupGroups);
00495   aDialogLayout->addWidget(GroupButtons);
00496 
00497   Init(); /* Initialisations */
00498 }
00499 
00500 //=================================================================================
00501 // function : ~SMESHGUI_AddQuadraticElementDlg()
00502 // purpose  : Destroys the object and frees any allocated resources
00503 //=================================================================================
00504 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
00505 {
00506   delete mySimulation;
00507 }
00508 
00509 //=================================================================================
00510 // function : Init()
00511 // purpose  :
00512 //=================================================================================
00513 void SMESHGUI_AddQuadraticElementDlg::Init()
00514 {
00515   myRadioButton1->setChecked(true);
00516   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00517 
00518   /* reset "Add to group" control */
00519   GroupGroups->setChecked( false );
00520 
00521   myActor = 0;
00522   myNbMidFaceNodes = 0;
00523   myNbCenterNodes = 0;
00524 
00525   int aNumRows;
00526 
00527   switch (myGeomType) {
00528   case SMDSEntity_Quad_Edge:
00529     aNumRows = 1;
00530     myNbCorners = 2;
00531     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
00532     break;
00533   case SMDSEntity_Quad_Triangle:
00534     aNumRows = 3;
00535     myNbCorners = 3;
00536     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
00537     break;
00538   case SMDSEntity_Quad_Quadrangle:
00539     aNumRows = 4;
00540     myNbCorners = 4;
00541     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
00542     break;
00543   case SMDSEntity_BiQuad_Quadrangle:
00544     aNumRows = 4;
00545     myNbCorners = 4;
00546     myNbCenterNodes = 1;
00547     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
00548     break;
00549   case SMDSEntity_Quad_Tetra:
00550     aNumRows = 6;
00551     myNbCorners = 4;
00552     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
00553     break;
00554   case SMDSEntity_Quad_Pyramid:
00555     aNumRows = 8;
00556     myNbCorners = 5;
00557     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
00558     break;
00559   case SMDSEntity_Quad_Penta:
00560     aNumRows = 9;
00561     myNbCorners = 6;
00562     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
00563     break;
00564   case SMDSEntity_Quad_Hexa:
00565     aNumRows = 12;
00566     myNbCorners = 8;
00567     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
00568     break;
00569   case SMDSEntity_TriQuad_Hexa:
00570     aNumRows = 12;
00571     myNbCorners = 8;
00572     myNbMidFaceNodes = 6;
00573     myNbCenterNodes = 1;
00574     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
00575     break;
00576   }
00577 
00578   myMidFaceLabel       ->setVisible( myNbMidFaceNodes );
00579   myMidFaceSelectButton->setVisible( myNbMidFaceNodes );
00580   myMidFaceNodes       ->setVisible( myNbMidFaceNodes );
00581   myCenterLabel        ->setVisible( myNbCenterNodes );
00582   myCenterSelectButton ->setVisible( myNbCenterNodes );
00583   myCenterNode         ->setVisible( myNbCenterNodes );
00584 
00585   myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, myNbCorners));
00586 
00587   /* initialize table */
00588   myTable->setColumnCount(3);
00589   myTable->setRowCount(aNumRows);
00590 
00591   QStringList aColLabels;
00592   aColLabels.append(tr("SMESH_FIRST"));
00593   aColLabels.append(tr("SMESH_MIDDLE"));
00594   aColLabels.append(tr("SMESH_LAST"));
00595   myTable->setHorizontalHeaderLabels(aColLabels);
00596 
00597   for ( int col = 0; col < myTable->columnCount(); col++ )
00598     myTable->setColumnWidth(col, 80);
00599 
00600   //myTable->setColumnReadOnly(0, true); // VSR: TODO
00601   //myTable->setColumnReadOnly(2, true); // VSR: TODO
00602 
00603   myTable->setEnabled( false );
00604 
00605   for ( int row = 0; row < myTable->rowCount(); row++ )
00606   {
00607     myTable->setItem( row, 0, new QTableWidgetItem( "" ) );
00608     myTable->item( row, 0 )->setFlags(0);
00609 
00610     IdEditItem* anEditItem = new IdEditItem( "" );
00611     anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
00612     myTable->setItem(row, 1, anEditItem);
00613 
00614     myTable->setItem( row, 2, new QTableWidgetItem( "" ) );
00615     myTable->item( row, 2 )->setFlags(0);
00616   }
00617 
00618   /* signals and slots connections */
00619   connect(myCornerSelectButton, SIGNAL(clicked()), SLOT(SetCurrentSelection()));
00620   connect(myMidFaceSelectButton, SIGNAL(clicked()), SLOT(SetCurrentSelection()));
00621   connect(myCenterSelectButton, SIGNAL(clicked()), SLOT(SetCurrentSelection()));
00622   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
00623   connect(myTable,        SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int)));
00624   connect(myTable,        SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int)));
00625   connect(myCornerNodes,  SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00626   connect(myMidFaceNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00627   connect(myCenterNode,  SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00628   connect(myReverseCB,    SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
00629 
00630   connect(buttonOk, SIGNAL(clicked()),     SLOT(ClickOnOk()));
00631   connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
00632   connect(buttonApply, SIGNAL(clicked()),  SLOT(ClickOnApply()));
00633   connect(buttonHelp, SIGNAL(clicked()),   SLOT(ClickOnHelp()));
00634 
00635   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
00636   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
00637   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel()));
00638 
00639   myCurrentLineEdit = myCornerNodes;
00640 
00641   // set selection mode
00642   SMESH::SetPointRepresentation(true);
00643 
00644   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00645     aViewWindow->SetSelectionMode( NodeSelection );
00646 
00647   SelectionIntoArgument();
00648 }
00649 
00650 //=================================================================================
00651 // function : ClickOnApply()
00652 // purpose  :
00653 //=================================================================================
00654 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
00655 {
00656   if( !isValid() )
00657     return;
00658 
00659   if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
00660     return;
00661 
00662   BusyLocker lock( myBusy );
00663 
00664   std::vector<vtkIdType> anIds;
00665 
00666   switch (myGeomType) {
00667   case SMDSEntity_Quad_Edge:
00668     anIds.push_back(myTable->item(0, 0)->text().toInt());
00669     anIds.push_back(myTable->item(0, 2)->text().toInt());
00670     anIds.push_back(myTable->item(0, 1)->text().toInt());
00671     break;
00672   case SMDSEntity_Quad_Triangle:
00673   case SMDSEntity_Quad_Quadrangle:
00674   case SMDSEntity_BiQuad_Quadrangle:
00675   case SMDSEntity_Quad_Tetra:
00676   case SMDSEntity_Quad_Pyramid:
00677   case SMDSEntity_Quad_Penta:
00678   case SMDSEntity_Quad_Hexa:
00679   case SMDSEntity_TriQuad_Hexa:
00680     for ( int row = 0; row < myNbCorners; row++ )
00681       anIds.push_back(myTable->item(row, 0)->text().toInt());
00682     for ( int row = 0; row < myTable->rowCount(); row++ )
00683       anIds.push_back(myTable->item(row, 1)->text().toInt());
00684     if ( myNbMidFaceNodes )
00685     {
00686       QStringList aListId = myMidFaceNodes->text().split(" ", QString::SkipEmptyParts);
00687       for (int i = 0; i < aListId.count(); i++)
00688         anIds.push_back( aListId[ i ].toInt() );
00689     }
00690     if ( myNbCenterNodes )
00691     {
00692       QStringList aListId = myCenterNode->text().split(" ", QString::SkipEmptyParts);
00693       anIds.push_back( aListId[ 0 ].toInt() );
00694     }
00695     break;
00696   }
00697   if ( myReverseCB->isChecked())
00698     ReverseConnectivity( anIds, myGeomType, /*toReverse=*/true, /*toVtkOrder=*/false );
00699 
00700   int aNumberOfIds =  anIds.size();
00701   SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
00702   anArrayOfIdeces->length( aNumberOfIds );
00703 
00704   for (int i = 0; i < aNumberOfIds; i++)
00705     anArrayOfIdeces[i] = anIds[ i ];
00706 
00707   bool addToGroup = GroupGroups->isChecked();
00708   QString aGroupName;
00709 
00710   SMESH::SMESH_GroupBase_var aGroup;
00711   int idx = 0;
00712   if( addToGroup ) {
00713     aGroupName = ComboBox_GroupName->currentText();
00714     for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
00715       QString aName = ComboBox_GroupName->itemText( i );
00716       if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
00717         idx = i;
00718     }
00719     if ( idx > 0 && idx < myGroups.count() ) {
00720       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
00721       if ( !aGeomGroup->_is_nil() ) {
00722         int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
00723                                              tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
00724                                              tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
00725         if ( res == 1 ) return;
00726       }
00727       aGroup = myGroups[idx-1];
00728     }
00729   }
00730 
00731   SMESH::ElementType anElementType;
00732   long anElemId = -1;
00733   SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00734   switch (myGeomType) {
00735   case SMDSEntity_Quad_Edge:
00736     anElementType = SMESH::EDGE;
00737     anElemId = aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
00738   case SMDSEntity_Quad_Triangle:
00739   case SMDSEntity_Quad_Quadrangle:
00740   case SMDSEntity_BiQuad_Quadrangle:
00741     anElementType = SMESH::FACE;
00742     anElemId = aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
00743   case SMDSEntity_Quad_Tetra:
00744   case SMDSEntity_Quad_Pyramid:
00745   case SMDSEntity_Quad_Penta:
00746   case SMDSEntity_Quad_Hexa:
00747   case SMDSEntity_TriQuad_Hexa:
00748     anElementType = SMESH::VOLUME;
00749     anElemId = aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
00750   default: break;
00751   }
00752 
00753   if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
00754     SMESH::SMESH_Group_var aGroupUsed;
00755     if ( aGroup->_is_nil() ) {
00756       // create new group
00757       aGroupUsed = SMESH::AddGroup( myMesh, anElementType, aGroupName );
00758       if ( !aGroupUsed->_is_nil() ) {
00759         myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
00760         ComboBox_GroupName->addItem( aGroupName );
00761       }
00762     }
00763     else {
00764       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
00765       if ( !aGeomGroup->_is_nil() ) {
00766         aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
00767         if ( !aGroupUsed->_is_nil() && idx > 0 ) {
00768           myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
00769           SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
00770         }
00771       }
00772       else
00773         aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
00774     }
00775 
00776     if ( !aGroupUsed->_is_nil() ) {
00777       SMESH::long_array_var anIdList = new SMESH::long_array;
00778       anIdList->length( 1 );
00779       anIdList[0] = anElemId;
00780       aGroupUsed->Add( anIdList.inout() );
00781     }
00782   }
00783 
00784   SALOME_ListIO aList; aList.Append( myActor->getIO() );
00785   mySelector->ClearIndex();
00786   mySelectionMgr->setSelectedObjects( aList, false );
00787 
00788   mySimulation->SetVisibility(false);
00789   SMESH::UpdateView();
00790 
00791   UpdateTable();
00792   SetCurrentSelection();
00793 
00794   updateButtons();
00795 
00796   SMESHGUI::Modified();
00797 }
00798 
00799 //=================================================================================
00800 // function : ClickOnOk()
00801 // purpose  :
00802 //=================================================================================
00803 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
00804 {
00805   ClickOnApply();
00806   ClickOnCancel();
00807 }
00808 
00809 //=================================================================================
00810 // function : ClickOnCancel()
00811 // purpose  :
00812 //=================================================================================
00813 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
00814 {
00815   mySelectionMgr->clearSelected();
00816   mySimulation->SetVisibility(false);
00817   SMESH::SetPointRepresentation(false);
00818   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00819     aViewWindow->SetSelectionMode( ActorSelection );
00820   disconnect(mySelectionMgr, 0, this, 0);
00821   mySMESHGUI->ResetState();
00822   reject();
00823 }
00824 
00825 //=================================================================================
00826 // function : ClickOnHelp()
00827 // purpose  :
00828 //=================================================================================
00829 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
00830 {
00831   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00832   if (app)
00833     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00834   else {
00835     QString platform;
00836 #ifdef WIN32
00837     platform = "winapplication";
00838 #else
00839     platform = "application";
00840 #endif
00841     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00842                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00843                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
00844                                                                  platform)).
00845                              arg(myHelpFileName));
00846   }
00847 }
00848 
00849 //=================================================================================
00850 // function : onTextChange()
00851 // purpose  :
00852 //=================================================================================
00853 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
00854 {
00855   if (myBusy) return;
00856   BusyLocker lock( myBusy );
00857 
00858   mySimulation->SetVisibility(false);
00859 
00860   // hilight entered nodes
00861   SMDS_Mesh* aMesh = 0;
00862   if (myActor)
00863     aMesh = myActor->GetObject()->GetMesh();
00864 
00865   QLineEdit* send = (QLineEdit*)sender();
00866   if (send == myCornerNodes ||
00867       send == myMidFaceNodes ||
00868       send == myCenterNode)
00869     myCurrentLineEdit = send;
00870 
00871   if (aMesh) {
00872     TColStd_MapOfInteger newIndices;
00873 
00874     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00875     bool allOk = true;
00876     for (int i = 0; i < aListId.count(); i++) {
00877       if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
00878       {
00879         newIndices.Add( n->GetID() );
00880       }
00881       else
00882       {
00883         allOk = false;
00884         break;
00885       }
00886     }
00887 
00888     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
00889     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00890       aViewWindow->highlight( myActor->getIO(), true, true );
00891 
00892     if ( myCurrentLineEdit == myCornerNodes )
00893       UpdateTable( allOk );
00894   }
00895 
00896   updateButtons();
00897   displaySimulation();
00898 }
00899 
00900 //=================================================================================
00901 // function : SelectionIntoArgument()
00902 // purpose  : Called when selection has changed
00903 //=================================================================================
00904 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
00905 {
00906   if (myBusy) return;
00907   BusyLocker lock( myBusy );
00908 
00909   QString aCurrentEntry = myEntry;
00910 
00911   if ( myCurrentLineEdit )
00912   {
00913     // clear
00914     myActor = 0;
00915 
00916     myCurrentLineEdit->setText("");
00917 
00918     if (!GroupButtons->isEnabled()) // inactive
00919       return;
00920 
00921     mySimulation->SetVisibility(false);
00922 
00923     // get selected mesh
00924     SALOME_ListIO aList;
00925     mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00926 
00927     if (aList.Extent() != 1)
00928     {
00929       UpdateTable();
00930       updateButtons();
00931       return;
00932     }
00933 
00934     Handle(SALOME_InteractiveObject) anIO = aList.First();
00935     myEntry = anIO->getEntry();
00936     myMesh = SMESH::GetMeshByIO(anIO);
00937     if (myMesh->_is_nil()) {
00938       updateButtons();
00939       return;
00940     }
00941 
00942     myActor = SMESH::FindActorByEntry(anIO->getEntry());
00943 
00944   }
00945 
00946   // process groups
00947   if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
00948     SMESH::ElementType anElementType;
00949     switch ( myGeomType ) {
00950     case SMDSEntity_Quad_Edge:
00951       anElementType = SMESH::EDGE; break;
00952     case SMDSEntity_Quad_Triangle:
00953     case SMDSEntity_Quad_Quadrangle:
00954     case SMDSEntity_BiQuad_Quadrangle:
00955       anElementType = SMESH::FACE; break;
00956     case SMDSEntity_Quad_Tetra:
00957     case SMDSEntity_Quad_Pyramid:
00958     case SMDSEntity_Quad_Penta:
00959     case SMDSEntity_Quad_Hexa:
00960     case SMDSEntity_TriQuad_Hexa:
00961       anElementType = SMESH::VOLUME; break;
00962     }
00963     myGroups.clear();
00964     ComboBox_GroupName->clear();
00965     ComboBox_GroupName->addItem( QString() );
00966     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
00967     for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
00968       SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
00969       if ( !aGroup->_is_nil() && aGroup->GetType() == anElementType ) {
00970         QString aGroupName( aGroup->GetName() );
00971         if ( !aGroupName.isEmpty() ) {
00972           myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
00973           ComboBox_GroupName->addItem( aGroupName );
00974         }
00975       }
00976     }
00977   }
00978 
00979   if (!myActor) {
00980     updateButtons();
00981     return;
00982   }
00983 
00984   // get selected nodes
00985   QString aString = "";
00986   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
00987 
00988   if ( myCurrentLineEdit )
00989   {
00990     if ( myCurrentLineEdit != myCenterNode || nbNodes == 1 )
00991       myCurrentLineEdit->setText(aString);
00992 
00993     if ( myCurrentLineEdit == myCornerNodes )
00994       UpdateTable();
00995   }
00996   else if ( myTable->isEnabled() && nbNodes == 1 )
00997   {
00998     int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
00999     if ( theCol == 1 )
01000       myTable->item(theRow, 1)->setText(aString);
01001   }
01002 
01003   updateButtons();
01004   displaySimulation();
01005 }
01006 
01007 //=================================================================================
01008 // function : displaySimulation()
01009 // purpose  :
01010 //=================================================================================
01011 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
01012 {
01013   if ( IsValid() )
01014   {
01015     SMESH::TElementSimulation::TVTKIds anIds;
01016 
01017     // Collect ids from the dialog
01018     int anID;
01019     bool ok;
01020     int aDisplayMode = VTK_SURFACE;
01021 
01022     if ( myGeomType == SMDSEntity_Quad_Edge )
01023     {
01024       anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) );
01025       anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) );
01026       anID = myTable->item(0, 1)->text().toInt(&ok);
01027       if (!ok) anID = myTable->item(0, 0)->text().toInt();
01028       anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
01029       aDisplayMode = VTK_WIREFRAME;
01030     }
01031     else
01032     {
01033       for ( int row = 0; row < myNbCorners; row++ )
01034         anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) );
01035 
01036       for ( int row = 0; row < myTable->rowCount(); row++ )
01037       {
01038         anID = myTable->item(row, 1)->text().toInt(&ok);
01039         if (!ok) {
01040           anID = myTable->item(row, 0)->text().toInt();
01041           aDisplayMode = VTK_WIREFRAME;
01042         }
01043         anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
01044       }
01045       if ( myNbMidFaceNodes )
01046       {
01047         QStringList aListId = myMidFaceNodes->text().split(" ", QString::SkipEmptyParts);
01048         for (int i = 0; i < aListId.count(); i++)
01049           anIds.push_back( myActor->GetObject()->GetNodeVTKId( aListId[ i ].toInt() ));
01050       }
01051       if ( myNbCenterNodes )
01052       {
01053         QStringList aListId = myCenterNode->text().split(" ", QString::SkipEmptyParts);
01054         anIds.push_back( myActor->GetObject()->GetNodeVTKId( aListId[ 0 ].toInt() ));
01055       }
01056     }
01057 
01058     mySimulation->SetPosition(myActor,myGeomType,anIds,aDisplayMode,myReverseCB->isChecked());
01059   }
01060   else
01061   {
01062     mySimulation->SetVisibility(false);
01063   }
01064   SMESH::UpdateView();
01065 }
01066 
01067 //=================================================================================
01068 // function : SetCurrentSelection()
01069 // purpose  :
01070 //=================================================================================
01071 void SMESHGUI_AddQuadraticElementDlg::SetCurrentSelection()
01072 {
01073   QPushButton* send = (QPushButton*)sender();
01074   myCurrentLineEdit = 0;
01075 
01076   if (send == myCornerSelectButton)
01077     myCurrentLineEdit = myCornerNodes;
01078   else if ( send == myMidFaceSelectButton )
01079     myCurrentLineEdit = myMidFaceNodes;
01080   else if ( send == myCenterSelectButton )
01081     myCurrentLineEdit = myCenterNode;
01082 
01083   if ( myCurrentLineEdit )
01084   {
01085     myCurrentLineEdit->setFocus();
01086     SelectionIntoArgument();
01087   }
01088 }
01089 
01090 //=================================================================================
01091 // function : DeactivateActiveDialog()
01092 // purpose  :
01093 //=================================================================================
01094 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
01095 {
01096   if (GroupConstructors->isEnabled()) {
01097     GroupConstructors->setEnabled(false);
01098     GroupArguments->setEnabled(false);
01099     GroupButtons->setEnabled(false);
01100     mySimulation->SetVisibility(false);
01101     mySMESHGUI->ResetState();
01102     mySMESHGUI->SetActiveDialogBox(0);
01103   }
01104 }
01105 
01106 //=================================================================================
01107 // function : ActivateThisDialog()
01108 // purpose  :
01109 //=================================================================================
01110 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
01111 {
01112   /* Emit a signal to deactivate the active dialog */
01113   mySMESHGUI->EmitSignalDeactivateDialog();
01114 
01115   GroupConstructors->setEnabled(true);
01116   GroupArguments->setEnabled(true);
01117   GroupButtons->setEnabled(true);
01118 
01119   SMESH::SetPointRepresentation(true);
01120 
01121   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01122     aViewWindow->SetSelectionMode( NodeSelection );
01123   SelectionIntoArgument();
01124 }
01125 
01126 //=================================================================================
01127 // function : enterEvent()
01128 // purpose  :
01129 //=================================================================================
01130 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
01131 {
01132   if (GroupConstructors->isEnabled())
01133     return;
01134   ActivateThisDialog();
01135 }
01136 
01137 //=================================================================================
01138 // function : closeEvent()
01139 // purpose  :
01140 //=================================================================================
01141 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
01142 {
01143   /* same than click on cancel button */
01144   ClickOnCancel();
01145 }
01146 
01147 //=================================================================================
01148 // function : hideEvent()
01149 // purpose  : caused by ESC key
01150 //=================================================================================
01151 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
01152 {
01153   if (!isMinimized())
01154     ClickOnCancel();
01155 }
01156 
01157 //=================================================================================
01158 // function : onReverse()
01159 // purpose  :
01160 //=================================================================================
01161 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
01162 {
01163   mySimulation->SetVisibility(false);
01164   displaySimulation();
01165   updateButtons();
01166 }
01167 
01168 
01169 //=================================================================================
01170 // function : IsValid()
01171 // purpose  :
01172 //=================================================================================
01173 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
01174 {
01175   SMDS_Mesh* aMesh = 0;
01176   if (myActor)
01177     aMesh = myActor->GetObject()->GetMesh();
01178   if (!aMesh)
01179     return false;
01180 
01181   bool ok;
01182   std::set< int > okIDs;
01183   for ( int row = 0; row < myTable->rowCount(); row++ )
01184   {
01185     int anID =  myTable->item(row, 1)->text().toInt(&ok);
01186     if ( !ok )
01187       return false;
01188 
01189     const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
01190     if ( !aNode )
01191       return false;
01192     okIDs.insert( anID );
01193   }
01194 
01195   QStringList aListId;
01196   if ( myNbMidFaceNodes )
01197     aListId += myMidFaceNodes->text().split(" ", QString::SkipEmptyParts);
01198   if ( myNbCenterNodes )
01199     aListId += myCenterNode->text().split(" ", QString::SkipEmptyParts);
01200 
01201   for (int i = 0; i < aListId.count(); i++)
01202   {
01203     int anID = aListId[ i ].toInt(&ok);
01204     if ( !ok )
01205       return false;
01206 
01207     if ( !aMesh->FindNode(anID) )
01208       return false;
01209     okIDs.insert( anID );
01210   }
01211 
01212   return okIDs.size() == myTable->rowCount() + myNbMidFaceNodes + myNbCenterNodes;
01213 }
01214 
01215 //=================================================================================
01216 // function : UpdateTable()
01217 // purpose  :
01218 //=================================================================================
01219 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
01220 {
01221   QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
01222 
01223   if ( aListCorners.count() == myNbCorners && theConersValidity )
01224   {
01225     myTable->setEnabled( true );
01226 
01227     // clear the Middle column
01228     for ( int row = 0; row < myTable->rowCount(); row++ )
01229       myTable->item( row, 1 )->setText("");
01230 
01231     int* aFirstColIds;
01232     int* aLastColIds;
01233 
01234     switch (myGeomType) {
01235     case SMDSEntity_Quad_Edge:
01236       aFirstColIds = FirstEdgeIds;
01237       aLastColIds  = LastEdgeIds;
01238       break;
01239     case SMDSEntity_Quad_Triangle:
01240       aFirstColIds = FirstTriangleIds;
01241       aLastColIds  = LastTriangleIds;
01242       break;
01243     case SMDSEntity_Quad_Quadrangle:
01244     case SMDSEntity_BiQuad_Quadrangle:
01245       aFirstColIds = FirstQuadrangleIds;
01246       aLastColIds  = LastQuadrangleIds;
01247       break;
01248     case SMDSEntity_Quad_Tetra:
01249       aFirstColIds = FirstTetrahedronIds;
01250       aLastColIds  = LastTetrahedronIds;
01251       break;
01252     case SMDSEntity_Quad_Pyramid:
01253       aFirstColIds = FirstPyramidIds;
01254       aLastColIds  = LastPyramidIds;
01255       break;
01256     case SMDSEntity_Quad_Penta:
01257       aFirstColIds = FirstPentahedronIds;
01258       aLastColIds  = LastPentahedronIds;
01259       break;
01260     case SMDSEntity_Quad_Hexa:
01261     case SMDSEntity_TriQuad_Hexa:
01262       aFirstColIds = FirstHexahedronIds;
01263       aLastColIds  = LastHexahedronIds;
01264       break;
01265     }
01266 
01267     // fill the First and the Last columns
01268     for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
01269       myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] );
01270 
01271     for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
01272       myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] );
01273   }
01274   else
01275   {
01276     // clear table
01277     for ( int row = 0; row < myTable->rowCount(); row++ )
01278       for ( int col = 0; col < myTable->columnCount(); col++ )
01279         if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText("");
01280 
01281     myTable->setEnabled( false );
01282   }
01283 }
01284 
01285 
01286 //=================================================================================
01287 // function : onTableActivate()
01288 // purpose  :
01289 //=================================================================================
01290 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
01291 {
01292   myCurrentLineEdit = 0;
01293   displaySimulation();
01294   updateButtons();
01295 }
01296 
01297 
01298 //=================================================================================
01299 // function : onCellTextChange()
01300 // purpose  :
01301 //=================================================================================
01302 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
01303 {
01304   myCurrentLineEdit = 0;
01305   displaySimulation();
01306   updateButtons();
01307 }
01308 
01309 //=================================================================================
01310 // function : keyPressEvent()
01311 // purpose  :
01312 //=================================================================================
01313 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
01314 {
01315   QDialog::keyPressEvent( e );
01316   if ( e->isAccepted() )
01317     return;
01318 
01319   if ( e->key() == Qt::Key_F1 ) {
01320     e->accept();
01321     ClickOnHelp();
01322   }
01323 }
01324 
01325 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
01326 {
01327   bool valid = IsValid();
01328   buttonOk->setEnabled( valid );
01329   buttonApply->setEnabled( valid );
01330 }
01331 
01332 //=================================================================================
01333 // function : isValid
01334 // purpose  :
01335 //=================================================================================
01336 bool SMESHGUI_AddQuadraticElementDlg::isValid()
01337 {
01338   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
01339     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
01340     return false;
01341   }
01342   return true;
01343 }