1 #include "SMESHGUI_AddQuadraticElementDlg.h"
4 #include "SMESHGUI_Utils.h"
5 #include "SMESHGUI_VTKUtils.h"
6 #include "SMESHGUI_MeshUtils.h"
7 #include "SMESHGUI_IdValidator.h"
8 #include "SMESH_ActorUtils.h"
10 #include "SMDS_Mesh.hxx"
11 #include "SMESH_Actor.h"
13 #include "SUIT_Session.h"
15 #include "SVTK_Selection.h"
16 #include "SVTK_Selector.h"
17 #include "SALOME_ListIO.hxx"
18 #include "SALOME_ListIteratorOfListIO.hxx"
20 #include "SalomeApp_Study.h"
21 #include "SalomeApp_Application.h"
23 #include "SVTK_ViewModel.h"
24 #include "SVTK_ViewWindow.h"
26 #include "utilities.h"
29 #include <TColStd_MapOfInteger.hxx>
30 #include <TColStd_IndexedMapOfInteger.hxx>
34 #include <vtkIdList.h>
35 #include <vtkIntArray.h>
36 #include <vtkCellArray.h>
37 #include <vtkUnsignedCharArray.h>
38 #include <vtkUnstructuredGrid.h>
39 #include <vtkDataSetMapper.h>
40 #include <vtkProperty.h>
42 #include <vtkQuadraticEdge.h>
43 #include <vtkQuadraticTriangle.h>
44 #include <vtkQuadraticQuad.h>
45 #include <vtkQuadraticHexahedron.h>
46 #include <vtkQuadraticTetra.h>
49 #include <qbuttongroup.h>
50 #include <qgroupbox.h>
52 #include <qlineedit.h>
53 #include <qpushbutton.h>
54 #include <qradiobutton.h>
57 #include <qcheckbox.h>
66 void ReverseConnectivity( vector<int> & ids, int type )
68 // for reverse connectivity of other types keeping the first id, see
69 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
73 case QUAD_TETRAHEDRON: {
74 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
79 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
83 case QUAD_PENTAHEDRON: {
84 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
88 case QUAD_HEXAHEDRON: {
89 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
96 reverse( ids.begin(), ids.end() );
99 vector<int> aRevIds( ids.size() );
100 for ( int i = 0; i < ids.size(); i++)
101 aRevIds[ i ] = ids[ conn[ i ]];
106 class TElementSimulation {
107 SalomeApp_Application* myApplication;
108 SUIT_ViewWindow* myViewWindow;
109 SVTK_ViewWindow* myVTKViewWindow;
111 SALOME_Actor* myPreviewActor;
112 vtkDataSetMapper* myMapper;
113 vtkUnstructuredGrid* myGrid;
114 //vtkProperty* myBackProp, *myProp;
116 float anRGB[3], aBackRGB[3];
119 TElementSimulation (SalomeApp_Application* theApplication)
121 myApplication = theApplication;
122 SUIT_ViewManager* mgr = theApplication->activeViewManager();
124 myViewWindow = mgr->getActiveView();
125 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
127 myGrid = vtkUnstructuredGrid::New();
129 // Create and display actor
130 myMapper = vtkDataSetMapper::New();
131 myMapper->SetInput(myGrid);
133 myPreviewActor = SALOME_Actor::New();
134 myPreviewActor->PickableOff();
135 myPreviewActor->VisibilityOff();
136 myPreviewActor->SetMapper(myMapper);
138 vtkProperty* myProp = vtkProperty::New();
139 GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
140 myProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
141 myPreviewActor->SetProperty( myProp );
144 vtkProperty* myBackProp = vtkProperty::New();
145 GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
146 myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
147 myPreviewActor->SetBackfaceProperty( myBackProp );
148 myBackProp->Delete();
150 myVTKViewWindow->AddActor(myPreviewActor);
153 typedef std::vector<vtkIdType> TVTKIds;
154 void SetPosition (SMESH_Actor* theActor,
158 const bool theReverse)
160 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
161 myGrid->SetPoints(aGrid->GetPoints());
169 aType = VTK_QUADRATIC_EDGE;
172 aType = VTK_QUADRATIC_TRIANGLE;
174 case QUAD_QUADRANGLE:
175 aType = VTK_QUADRATIC_QUAD;
177 case QUAD_TETRAHEDRON:
178 aType = VTK_QUADRATIC_TETRA;
181 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
182 aType = VTK_CONVEX_POINT_SET;
184 case QUAD_PENTAHEDRON:
185 //aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2
186 aType = VTK_CONVEX_POINT_SET;
188 case QUAD_HEXAHEDRON:
189 aType = VTK_QUADRATIC_HEXAHEDRON;
193 // take care of orientation
194 if ( aType == VTK_CONVEX_POINT_SET ) {
195 if ( theReverse && theMode == VTK_SURFACE ) {
196 //myPreviewActor->GetProperty()->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
200 // VTK cell connectivity opposites the MED one
202 ReverseConnectivity( theIds, theType );
207 vtkIdList *anIds = vtkIdList::New();
209 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
210 anIds->InsertId(i,theIds[i]);
211 //std::cout << i<< ": " << theIds[i] << std::endl;
214 myGrid->InsertNextCell(aType,anIds);
219 myPreviewActor->GetMapper()->Update();
220 myPreviewActor->SetRepresentation( theMode );
223 // restore normal orientation
224 if ( aType == VTK_CONVEX_POINT_SET ) {
225 if ( theReverse && theMode == VTK_SURFACE ) {
226 //myPreviewActor->GetProperty()->SetColor( anRGB[0], anRGB[1], anRGB[2] );
232 void SetVisibility (bool theVisibility)
234 myPreviewActor->SetVisibility(theVisibility);
235 RepaintCurrentView();
239 ~TElementSimulation()
241 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
242 myVTKViewWindow->RemoveActor(myPreviewActor);
244 myPreviewActor->Delete();
246 myMapper->RemoveAllInputs();
252 // myBackProp->Delete();
258 // Define the sequences of ids
259 static int FirstEdgeIds[] = {0};
260 static int LastEdgeIds[] = {1};
262 static int FirstTriangleIds[] = {0,1,2};
263 static int LastTriangleIds[] = {1,2,0};
265 static int FirstQuadrangleIds[] = {0,1,2,3};
266 static int LastQuadrangleIds[] = {1,2,3,0};
268 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
269 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
271 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
272 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
274 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
275 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
277 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
278 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
282 //=================================================================================
283 // function : SMESHGUI_AddQuadraticElementDlg()
284 // purpose : constructor
285 //=================================================================================
286 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
289 bool modal, WFlags fl)
290 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
291 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
292 mySMESHGUI( theModule ),
293 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
296 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
297 (SUIT_Session::session()->activeApplication());
299 mySimulation = new SMESH::TElementSimulation (anApp);
300 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
302 QString anElementName;
306 anElementName = QString("QUADRATIC_EDGE");
309 anElementName = QString("QUADRATIC_TRIANGLE");
311 case QUAD_QUADRANGLE:
312 anElementName = QString("QUADRATIC_QUADRANGLE");
314 case QUAD_TETRAHEDRON:
315 anElementName = QString("QUADRATIC_TETRAHEDRON");
318 anElementName = QString("QUADRATIC_PYRAMID");
320 case QUAD_PENTAHEDRON:
321 anElementName = QString("QUADRATIC_PENTAHEDRON");
323 case QUAD_HEXAHEDRON:
324 anElementName = QString("QUADRATIC_HEXAHEDRON");
328 anElementName = QString("QUADRATIC_EDGE");
331 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName));
332 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName));
333 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName));
334 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName));
336 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
337 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
340 setName("SMESHGUI_AddQuadraticElementDlg");
343 setSizeGripEnabled(TRUE);
344 QGridLayout* aDialogLayout = new QGridLayout(this);
345 aDialogLayout->setSpacing(6);
346 aDialogLayout->setMargin(11);
348 /***************************************************************/
349 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
350 GroupConstructors->setTitle(constructorGrTitle);
352 GroupConstructors->setExclusive(TRUE);
353 GroupConstructors->setColumnLayout(0, Qt::Vertical);
354 GroupConstructors->layout()->setSpacing(0);
355 GroupConstructors->layout()->setMargin(0);
356 GroupConstructors->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
357 QGridLayout* aGroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
358 aGroupConstructorsLayout->setAlignment(Qt::AlignTop);
359 aGroupConstructorsLayout->setSpacing(6);
360 aGroupConstructorsLayout->setMargin(11);
361 myRadioButton1 = new QRadioButton(GroupConstructors, "myRadioButton1");
362 myRadioButton1->setText(tr("" ));
363 myRadioButton1->setPixmap(image0);
364 myRadioButton1->setChecked(TRUE);
365 myRadioButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, myRadioButton1->sizePolicy().hasHeightForWidth()));
366 aGroupConstructorsLayout->addWidget(myRadioButton1, 0, 0);
367 aGroupConstructorsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
368 aDialogLayout->addWidget(GroupConstructors, 0, 0);
370 /***************************************************************/
371 GroupArguments = new QGroupBox(this, "GroupArguments");
372 GroupArguments->setTitle(argumentsGrTitle);
373 GroupArguments->setColumnLayout(0, Qt::Vertical);
374 GroupArguments->layout()->setSpacing(0);
375 GroupArguments->layout()->setMargin(0);
376 GroupArguments->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding));
377 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
378 aGroupArgumentsLayout->setAlignment(Qt::AlignTop);
379 aGroupArgumentsLayout->setSpacing(6);
380 aGroupArgumentsLayout->setMargin(11);
381 QLabel* aCornerNodesLabel = new QLabel(GroupArguments, "aCornerNodesLabel");
382 aCornerNodesLabel->setText(tr("SMESH_CORNER_NODES" ));
383 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
384 mySelectButton = new QPushButton(GroupArguments, "mySelectButton");
385 mySelectButton->setPixmap(image1);
386 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
387 myCornerNodes = new QLineEdit(GroupArguments, "myCornerNodes");
388 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
390 myTable = new QTable(GroupArguments);
391 aGroupArgumentsLayout->addMultiCellWidget(myTable, 1, 1, 0, 2);
393 myReverseCB = new QCheckBox(GroupArguments, "myReverseCB");
394 myReverseCB->setText(tr("SMESH_REVERSE" ));
395 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0);
397 aDialogLayout->addWidget(GroupArguments, 1, 0);
400 /***************************************************************/
401 GroupButtons = new QGroupBox(this, "GroupButtons");
402 GroupButtons->setColumnLayout(0, Qt::Vertical);
403 GroupButtons->layout()->setSpacing(0);
404 GroupButtons->layout()->setMargin(0);
405 GroupButtons->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
406 QGridLayout* aGroupButtonsLayout = new QGridLayout(GroupButtons->layout());
407 aGroupButtonsLayout->setAlignment(Qt::AlignTop);
408 aGroupButtonsLayout->setSpacing(6);
409 aGroupButtonsLayout->setMargin(11);
410 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
411 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
412 buttonCancel->setAutoDefault(TRUE);
413 aGroupButtonsLayout->addWidget(buttonCancel, 0, 3);
414 buttonApply = new QPushButton(GroupButtons, "buttonApply");
415 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
416 buttonApply->setAutoDefault(TRUE);
417 aGroupButtonsLayout->addWidget(buttonApply, 0, 1);
418 aGroupButtonsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
419 buttonOk = new QPushButton(GroupButtons, "buttonOk");
420 buttonOk->setText(tr("SMESH_BUT_OK" ));
421 buttonOk->setAutoDefault(TRUE);
422 buttonOk->setDefault(TRUE);
423 aGroupButtonsLayout->addWidget(buttonOk, 0, 0);
425 aDialogLayout->addWidget(GroupButtons, 2, 0);
427 Init(); /* Initialisations */
430 //=================================================================================
431 // function : ~SMESHGUI_AddQuadraticElementDlg()
432 // purpose : Destroys the object and frees any allocated resources
433 //=================================================================================
434 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
436 // no need to delete child widgets, Qt does it all for us
440 //=================================================================================
443 //=================================================================================
444 void SMESHGUI_AddQuadraticElementDlg::Init()
446 GroupArguments->show();
447 myRadioButton1->setChecked(TRUE);
448 myIsEditCorners = true;
449 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
464 case QUAD_QUADRANGLE:
468 case QUAD_TETRAHEDRON:
476 case QUAD_PENTAHEDRON:
480 case QUAD_HEXAHEDRON:
486 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, "validator", myNbCorners));
488 /* initialize table */
489 myTable->setNumCols(3);
490 myTable->setNumRows(aNumRows);
492 QStringList aColLabels;
493 aColLabels.append(tr("SMESH_FIRST"));
494 aColLabels.append(tr("SMESH_MIDDLE"));
495 aColLabels.append(tr("SMESH_LAST"));
496 myTable->setColumnLabels(aColLabels);
498 for ( int col = 0; col < myTable->numCols(); col++ )
499 myTable->setColumnWidth(col, 80);
501 myTable->setColumnReadOnly(0, true);
502 myTable->setColumnReadOnly(2, true);
504 myTable->setEnabled( false );
506 for ( int row = 0; row < myTable->numRows(); row++ )
508 SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( myTable, QTableItem::OnTyping, "" );
509 anEditItem->setReplaceable(false);
510 myTable->setItem(row, 1, anEditItem);
513 /* signals and slots connections */
514 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
515 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
516 connect(myTable, SIGNAL(doubleClicked(int, int, int, const QPoint&)), SLOT(onCellDoubleClicked(int, int, int, const QPoint&)));
517 connect(myTable, SIGNAL(valueChanged (int, int)), SLOT(onCellTextChange(int, int)));
518 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
519 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
521 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
522 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
523 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
525 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
526 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
528 this->show(); // displays Dialog
530 // set selection mode
531 SMESH::SetPointRepresentation(true);
533 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
534 aViewWindow->SetSelectionMode( NodeSelection );
541 //=================================================================================
542 // function : ClickOnApply()
544 //=================================================================================
545 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
547 if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
554 anIds.push_back(myTable->text(0, 0).toInt());
555 anIds.push_back(myTable->text(0, 2).toInt());
556 anIds.push_back(myTable->text(0, 1).toInt());
559 case QUAD_QUADRANGLE:
560 case QUAD_TETRAHEDRON:
562 case QUAD_PENTAHEDRON:
563 case QUAD_HEXAHEDRON:
564 for ( int row = 0; row < myNbCorners; row++ )
565 anIds.push_back(myTable->text(row, 0).toInt());
566 for ( int row = 0; row < myTable->numRows(); row++ )
567 anIds.push_back(myTable->text(row, 1).toInt());
570 if ( myReverseCB->isChecked())
571 SMESH::ReverseConnectivity( anIds, myType );
573 int aNumberOfIds = anIds.size();
574 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
575 anArrayOfIdeces->length( aNumberOfIds );
577 for (int i = 0; i < aNumberOfIds; i++)
578 anArrayOfIdeces[i] = anIds[ i ];
580 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
583 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
585 case QUAD_QUADRANGLE:
586 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
587 case QUAD_TETRAHEDRON:
589 case QUAD_PENTAHEDRON:
590 case QUAD_HEXAHEDRON:
591 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
594 SALOME_ListIO aList; aList.Append( myActor->getIO() );
595 mySelector->ClearIndex();
596 mySelectionMgr->setSelectedObjects( aList, false );
599 mySimulation->SetVisibility(false);
601 buttonOk->setEnabled(false);
602 buttonApply->setEnabled(false);
611 //=================================================================================
612 // function : ClickOnOk()
614 //=================================================================================
615 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
622 //=================================================================================
623 // function : ClickOnCancel()
625 //=================================================================================
626 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
628 mySelectionMgr->clearSelected();
629 mySimulation->SetVisibility(false);
630 SMESH::SetPointRepresentation(false);
631 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632 aViewWindow->SetSelectionMode( ActorSelection );
633 disconnect(mySelectionMgr, 0, this, 0);
634 mySMESHGUI->ResetState();
639 //=================================================================================
640 // function : onTextChange()
642 //=================================================================================
643 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
648 buttonOk->setEnabled(false);
649 buttonApply->setEnabled(false);
651 mySimulation->SetVisibility(false);
653 // hilight entered nodes
654 SMDS_Mesh* aMesh = 0;
656 aMesh = myActor->GetObject()->GetMesh();
659 TColStd_MapOfInteger newIndices;
661 QStringList aListId = QStringList::split(" ", theNewText, false);
663 for (int i = 0; i < aListId.count(); i++) {
664 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
665 newIndices.Add( n->GetID() );
673 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
674 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
675 aViewWindow->highlight( myActor->getIO(), true, true );
677 if ( sender() == myCornerNodes )
678 UpdateTable( allOk );
682 buttonOk->setEnabled(true);
683 buttonApply->setEnabled(true);
686 if ( sender() == myTable )
692 //=================================================================================
693 // function : SelectionIntoArgument()
694 // purpose : Called when selection has changed
695 //=================================================================================
696 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
700 if ( myIsEditCorners )
706 myCornerNodes->setText("");
709 if (!GroupButtons->isEnabled()) // inactive
712 buttonOk->setEnabled(false);
713 buttonApply->setEnabled(false);
715 mySimulation->SetVisibility(false);
719 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
721 if (aList.Extent() != 1)
727 Handle(SALOME_InteractiveObject) anIO = aList.First();
728 myMesh = SMESH::GetMeshByIO(anIO);
729 if (myMesh->_is_nil())
732 myActor = SMESH::FindActorByEntry(anIO->getEntry());
739 // get selected nodes
740 QString aString = "";
741 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
743 if ( myIsEditCorners )
746 myCornerNodes->setText(aString);
751 else if ( myTable->isEnabled() && nbNodes == 1 )
754 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
756 myTable->setText(theRow, 1, aString);
762 buttonOk->setEnabled( true );
763 buttonApply->setEnabled( true );
769 //=================================================================================
770 // function : displaySimulation()
772 //=================================================================================
773 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
775 if (!myIsEditCorners) {
776 SMESH::TElementSimulation::TVTKIds anIds;
778 // Collect ids from the dialog
781 int aDisplayMode = VTK_SURFACE;
783 if ( myType == QUAD_EDGE )
785 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) );
786 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
787 anID = (myTable->text(0, 1)).toInt(&ok);
788 if (!ok) anID = (myTable->text(0, 0)).toInt();
789 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
790 aDisplayMode = VTK_WIREFRAME;
794 for ( int row = 0; row < myNbCorners; row++ )
795 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(row, 0).toInt() ) );
797 for ( int row = 0; row < myTable->numRows(); row++ )
799 anID = (myTable->text(row, 1)).toInt(&ok);
801 anID = (myTable->text(row, 0)).toInt();
802 aDisplayMode = VTK_WIREFRAME;
804 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
808 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
813 //=================================================================================
814 // function : SetEditCorners()
816 //=================================================================================
817 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
819 myCornerNodes->setFocus();
820 myIsEditCorners = true;
822 SelectionIntoArgument();
825 //=================================================================================
826 // function : DeactivateActiveDialog()
828 //=================================================================================
829 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
831 if (GroupConstructors->isEnabled()) {
832 GroupConstructors->setEnabled(false);
833 GroupArguments->setEnabled(false);
834 GroupButtons->setEnabled(false);
835 mySimulation->SetVisibility(false);
836 mySMESHGUI->ResetState();
837 mySMESHGUI->SetActiveDialogBox(0);
841 //=================================================================================
842 // function : ActivateThisDialog()
844 //=================================================================================
845 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
847 /* Emit a signal to deactivate the active dialog */
848 mySMESHGUI->EmitSignalDeactivateDialog();
850 GroupConstructors->setEnabled(true);
851 GroupArguments->setEnabled(true);
852 GroupButtons->setEnabled(true);
854 SMESH::SetPointRepresentation(true);
856 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
857 aViewWindow->SetSelectionMode( NodeSelection );
858 SelectionIntoArgument();
861 //=================================================================================
862 // function : enterEvent()
864 //=================================================================================
865 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
867 if (GroupConstructors->isEnabled())
869 ActivateThisDialog();
873 //=================================================================================
874 // function : closeEvent()
876 //=================================================================================
877 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
879 /* same than click on cancel button */
884 //=================================================================================
885 // function : hideEvent()
886 // purpose : caused by ESC key
887 //=================================================================================
888 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
894 //=================================================================================
895 // function : onReverse()
897 //=================================================================================
898 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
904 mySimulation->SetVisibility(false);
910 //=================================================================================
911 // function : IsValid()
913 //=================================================================================
914 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
916 SMDS_Mesh* aMesh = 0;
918 aMesh = myActor->GetObject()->GetMesh();
924 for ( int row = 0; row < myTable->numRows(); row++ )
926 int anID = (myTable->text(row, 1)).toInt(&ok);
930 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
938 //=================================================================================
939 // function : UpdateTable()
941 //=================================================================================
942 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
944 QStringList aListCorners = QStringList::split(" ", myCornerNodes->text(), false);
946 if ( aListCorners.count() == myNbCorners && theConersValidity )
948 myTable->setEnabled( true );
950 // clear the Middle column
951 for ( int row = 0; row < myTable->numRows(); row++ )
952 myTable->setText( row, 1, "");
959 aFirstColIds = FirstEdgeIds;
960 aLastColIds = LastEdgeIds;
963 aFirstColIds = FirstTriangleIds;
964 aLastColIds = LastTriangleIds;
966 case QUAD_QUADRANGLE:
967 aFirstColIds = FirstQuadrangleIds;
968 aLastColIds = LastQuadrangleIds;
970 case QUAD_TETRAHEDRON:
971 aFirstColIds = FirstTetrahedronIds;
972 aLastColIds = LastTetrahedronIds;
975 aFirstColIds = FirstPyramidIds;
976 aLastColIds = LastPyramidIds;
978 case QUAD_PENTAHEDRON:
979 aFirstColIds = FirstPentahedronIds;
980 aLastColIds = LastPentahedronIds;
982 case QUAD_HEXAHEDRON:
983 aFirstColIds = FirstHexahedronIds;
984 aLastColIds = LastHexahedronIds;
988 // fill the First and the Last columns
989 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
990 myTable->setText( i, 0, aListCorners[ aFirstColIds[i] ] );
992 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
993 myTable->setText( i, 2, aListCorners[ aLastColIds[i] ] );
998 for ( int row = 0; row < myTable->numRows(); row++ )
999 for ( int col = 0; col < myTable->numCols(); col++ )
1000 myTable->setText(row, col, "");
1002 myTable->setEnabled( false );
1007 //=================================================================================
1008 // function : onTableActivate()
1010 //=================================================================================
1011 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol, int theButton, const QPoint& theMousePos )
1013 if ( theButton == 1 && theCol == 1 )
1014 myIsEditCorners = false;
1016 displaySimulation();
1021 //=================================================================================
1022 // function : onCellTextChange()
1024 //=================================================================================
1025 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1027 onTextChange( myTable->text(theRow, theCol) );
1031 QWidget* SMESHGUI_IdEditItem::createEditor() const
1033 QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
1034 aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );