1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_AddMeshElementDlg.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_AddQuadraticElementDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMDS_Mesh.hxx>
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_ViewManager.h>
46 #include <LightApp_SelectionMgr.h>
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_ViewWindow.h>
51 #include <SALOME_ListIO.hxx>
53 #include <SalomeApp_Application.h>
56 #include <SALOMEconfig.h>
57 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
60 #include <TColStd_MapOfInteger.hxx>
63 #include <vtkIdList.h>
64 #include <vtkUnstructuredGrid.h>
65 #include <vtkDataSetMapper.h>
66 #include <vtkProperty.h>
67 #include <vtkCellType.h>
73 #include <QPushButton>
74 #include <QRadioButton>
75 #include <QVBoxLayout>
76 #include <QHBoxLayout>
77 #include <QGridLayout>
79 #include <QTableWidget>
81 #include <QButtonGroup>
91 void ReverseConnectivity( std::vector<int> & ids, int type )
93 // for reverse connectivity of other types keeping the first id, see
94 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
98 case QUAD_TETRAHEDRON: {
99 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
104 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
108 case QUAD_PENTAHEDRON: {
109 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
113 case QUAD_HEXAHEDRON: {
114 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
119 static int aConn[] = {1,0,2};
123 case QUAD_TRIANGLE: {
124 static int aConn[] = {0,2,1,5,4,3};
128 case QUAD_QUADRANGLE: {
129 static int aConn[] = {0,3,2,1,7,6,5,4};
136 reverse( ids.begin(), ids.end() );
139 std::vector<int> aRevIds( ids.size() );
140 for ( int i = 0; i < ids.size(); i++)
141 aRevIds[ i ] = ids[ conn[ i ]];
146 class TElementSimulation {
147 SalomeApp_Application* myApplication;
148 SUIT_ViewWindow* myViewWindow;
149 SVTK_ViewWindow* myVTKViewWindow;
151 SALOME_Actor* myPreviewActor;
152 vtkDataSetMapper* myMapper;
153 vtkUnstructuredGrid* myGrid;
154 //vtkProperty* myBackProp, *myProp;
156 vtkFloatingPointType myRGB[3], myBackRGB[3];
159 TElementSimulation (SalomeApp_Application* theApplication)
161 myApplication = theApplication;
162 SUIT_ViewManager* mgr = theApplication->activeViewManager();
164 myViewWindow = mgr->getActiveView();
165 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
167 myGrid = vtkUnstructuredGrid::New();
169 // Create and display actor
170 myMapper = vtkDataSetMapper::New();
171 myMapper->SetInput(myGrid);
173 myPreviewActor = SALOME_Actor::New();
174 myPreviewActor->PickableOff();
175 myPreviewActor->VisibilityOff();
176 myPreviewActor->SetMapper(myMapper);
178 vtkProperty* myProp = vtkProperty::New();
179 GetColor( "SMESH", "fill_color", myRGB[0], myRGB[1], myRGB[2], QColor( 0, 170, 255 ) );
180 myProp->SetColor( myRGB[0], myRGB[1], myRGB[2] );
181 myPreviewActor->SetProperty( myProp );
184 vtkProperty* myBackProp = vtkProperty::New();
185 GetColor( "SMESH", "backface_color", myBackRGB[0], myBackRGB[1], myBackRGB[2], QColor( 0, 0, 255 ) );
186 myBackProp->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
187 myPreviewActor->SetBackfaceProperty( myBackProp );
188 myBackProp->Delete();
190 myVTKViewWindow->AddActor(myPreviewActor);
193 typedef std::vector<vtkIdType> TVTKIds;
194 void SetPosition (SMESH_Actor* theActor,
198 const bool theReverse)
200 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
201 myGrid->SetPoints(aGrid->GetPoints());
209 aType = VTK_QUADRATIC_EDGE;
212 aType = VTK_QUADRATIC_TRIANGLE;
214 case QUAD_QUADRANGLE:
215 aType = VTK_QUADRATIC_QUAD;
217 case QUAD_TETRAHEDRON:
218 aType = VTK_QUADRATIC_TETRA;
221 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
222 aType = VTK_CONVEX_POINT_SET;
224 case QUAD_PENTAHEDRON:
225 //aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2
226 aType = VTK_CONVEX_POINT_SET;
228 case QUAD_HEXAHEDRON:
229 aType = VTK_QUADRATIC_HEXAHEDRON;
233 // take care of orientation
234 if ( aType == VTK_CONVEX_POINT_SET ) {
235 if ( theReverse && theMode == VTK_SURFACE ) {
236 //myPreviewActor->GetProperty()->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
240 // VTK cell connectivity opposites the MED one for volumic elements
241 if ( theIds.size() > 8 ? !theReverse : theReverse ) {
242 ReverseConnectivity( theIds, theType );
247 vtkIdList *anIds = vtkIdList::New();
249 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
250 anIds->InsertId(i,theIds[i]);
251 //std::cout << i<< ": " << theIds[i] << std::endl;
254 myGrid->InsertNextCell(aType,anIds);
259 myPreviewActor->GetMapper()->Update();
260 myPreviewActor->SetRepresentation( theMode );
263 // restore normal orientation
264 if ( aType == VTK_CONVEX_POINT_SET ) {
265 if ( theReverse && theMode == VTK_SURFACE ) {
266 //myPreviewActor->GetProperty()->SetColor( myRGB[0], myRGB[1], myRGB[2] );
272 void SetVisibility (bool theVisibility)
274 myPreviewActor->SetVisibility(theVisibility);
275 RepaintCurrentView();
279 ~TElementSimulation()
281 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
282 myVTKViewWindow->RemoveActor(myPreviewActor);
284 myPreviewActor->Delete();
286 myMapper->RemoveAllInputs();
292 // myBackProp->Delete();
298 // Define the sequences of ids
299 static int FirstEdgeIds[] = {0};
300 static int LastEdgeIds[] = {1};
302 static int FirstTriangleIds[] = {0,1,2};
303 static int LastTriangleIds[] = {1,2,0};
305 static int FirstQuadrangleIds[] = {0,1,2,3};
306 static int LastQuadrangleIds[] = {1,2,3,0};
308 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
309 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
311 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
312 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
314 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
315 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
317 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
318 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
322 class SMESHGUI_IdEditItem: public QTableWidgetItem
325 SMESHGUI_IdEditItem(const QString& text ):
326 QTableWidgetItem(text, QTableWidgetItem::UserType+100) {};
327 ~SMESHGUI_IdEditItem() {};
329 QWidget* createEditor() const;
332 QWidget* SMESHGUI_IdEditItem::createEditor() const
334 QLineEdit *aLineEdit = new QLineEdit(text(), tableWidget());
335 aLineEdit->setValidator( new SMESHGUI_IdValidator(tableWidget(), 1) );
339 //=================================================================================
340 // function : SMESHGUI_AddQuadraticElementDlg()
341 // purpose : constructor
342 //=================================================================================
343 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
345 : QDialog( SMESH::GetDesktop( theModule ) ),
346 mySMESHGUI( theModule ),
347 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
351 setAttribute( Qt::WA_DeleteOnClose, true );
353 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
354 (SUIT_Session::session()->activeApplication());
356 mySimulation = new SMESH::TElementSimulation (anApp);
357 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
359 QString anElementName;
363 anElementName = QString("QUADRATIC_EDGE");
366 anElementName = QString("QUADRATIC_TRIANGLE");
368 case QUAD_QUADRANGLE:
369 anElementName = QString("QUADRATIC_QUADRANGLE");
371 case QUAD_TETRAHEDRON:
372 anElementName = QString("QUADRATIC_TETRAHEDRON");
375 anElementName = QString("QUADRATIC_PYRAMID");
377 case QUAD_PENTAHEDRON:
378 anElementName = QString("QUADRATIC_PENTAHEDRON");
380 case QUAD_HEXAHEDRON:
381 anElementName = QString("QUADRATIC_HEXAHEDRON");
385 anElementName = QString("QUADRATIC_EDGE");
388 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName).toLatin1().data());
389 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName).toLatin1().data());
390 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName).toLatin1().data());
391 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName).toLatin1().data());
393 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
394 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
396 setWindowTitle(caption);
398 setSizeGripEnabled(true);
400 QVBoxLayout* aDialogLayout = new QVBoxLayout(this);
401 aDialogLayout->setSpacing(SPACING);
402 aDialogLayout->setMargin(MARGIN);
404 /***************************************************************/
405 GroupConstructors = new QGroupBox(constructorGrTitle, this);
406 QButtonGroup* ButtonGroup = new QButtonGroup(this);
407 QHBoxLayout* aGroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
408 aGroupConstructorsLayout->setSpacing(SPACING);
409 aGroupConstructorsLayout->setMargin(MARGIN);
411 myRadioButton1 = new QRadioButton(GroupConstructors);
412 myRadioButton1->setIcon(image0);
413 aGroupConstructorsLayout->addWidget(myRadioButton1);
414 ButtonGroup->addButton(myRadioButton1, 0);
416 /***************************************************************/
417 GroupArguments = new QGroupBox(argumentsGrTitle, this);
418 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments);
419 aGroupArgumentsLayout->setSpacing(SPACING);
420 aGroupArgumentsLayout->setMargin(MARGIN);
422 QLabel* aCornerNodesLabel = new QLabel(tr("SMESH_CORNER_NODES"), GroupArguments);
423 mySelectButton = new QPushButton(GroupArguments);
424 mySelectButton->setIcon(image1);
425 myCornerNodes = new QLineEdit(GroupArguments);
427 myTable = new QTableWidget(GroupArguments);
429 myReverseCB = new QCheckBox(tr("SMESH_REVERSE"), GroupArguments);
431 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
432 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
433 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
434 aGroupArgumentsLayout->addWidget(myTable, 1, 0, 1, 3);
435 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0, 1, 3);
437 /***************************************************************/
438 GroupButtons = new QGroupBox(this);
439 QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons);
440 aGroupButtonsLayout->setSpacing(SPACING);
441 aGroupButtonsLayout->setMargin(MARGIN);
443 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
444 buttonOk->setAutoDefault(true);
445 buttonOk->setDefault(true);
446 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
447 buttonApply->setAutoDefault(true);
448 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
449 buttonCancel->setAutoDefault(true);
450 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
451 buttonHelp->setAutoDefault(true);
453 aGroupButtonsLayout->addWidget(buttonOk);
454 aGroupButtonsLayout->addSpacing(10);
455 aGroupButtonsLayout->addWidget(buttonApply);
456 aGroupButtonsLayout->addSpacing(10);
457 aGroupButtonsLayout->addStretch();
458 aGroupButtonsLayout->addWidget(buttonCancel);
459 aGroupButtonsLayout->addWidget(buttonHelp);
461 /***************************************************************/
462 aDialogLayout->addWidget(GroupConstructors);
463 aDialogLayout->addWidget(GroupArguments);
464 aDialogLayout->addWidget(GroupButtons);
466 Init(); /* Initialisations */
469 //=================================================================================
470 // function : ~SMESHGUI_AddQuadraticElementDlg()
471 // purpose : Destroys the object and frees any allocated resources
472 //=================================================================================
473 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
478 //=================================================================================
481 //=================================================================================
482 void SMESHGUI_AddQuadraticElementDlg::Init()
484 myRadioButton1->setChecked(true);
485 myIsEditCorners = true;
486 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
496 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
501 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
503 case QUAD_QUADRANGLE:
506 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
508 case QUAD_TETRAHEDRON:
511 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
516 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
518 case QUAD_PENTAHEDRON:
521 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
523 case QUAD_HEXAHEDRON:
526 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
530 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, myNbCorners));
532 /* initialize table */
533 myTable->setColumnCount(3);
534 myTable->setRowCount(aNumRows);
536 QStringList aColLabels;
537 aColLabels.append(tr("SMESH_FIRST"));
538 aColLabels.append(tr("SMESH_MIDDLE"));
539 aColLabels.append(tr("SMESH_LAST"));
540 myTable->setHorizontalHeaderLabels(aColLabels);
542 for ( int col = 0; col < myTable->columnCount(); col++ )
543 myTable->setColumnWidth(col, 80);
545 //myTable->setColumnReadOnly(0, true); // VSR: TODO
546 //myTable->setColumnReadOnly(2, true); // VSR: TODO
548 myTable->setEnabled( false );
550 for ( int row = 0; row < myTable->rowCount(); row++ )
552 SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( "" );
553 anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
554 myTable->setItem(row, 1, anEditItem);
557 /* signals and slots connections */
558 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
559 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
560 connect(myTable, SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int)));
561 connect(myTable, SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int)));
562 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
563 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
565 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
566 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
567 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
568 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
570 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
571 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
573 // set selection mode
574 SMESH::SetPointRepresentation(true);
576 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
577 aViewWindow->SetSelectionMode( NodeSelection );
584 //=================================================================================
585 // function : ClickOnApply()
587 //=================================================================================
588 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
590 if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
593 std::vector<int> anIds;
597 anIds.push_back(myTable->item(0, 0)->text().toInt());
598 anIds.push_back(myTable->item(0, 2)->text().toInt());
599 anIds.push_back(myTable->item(0, 1)->text().toInt());
602 case QUAD_QUADRANGLE:
603 case QUAD_TETRAHEDRON:
605 case QUAD_PENTAHEDRON:
606 case QUAD_HEXAHEDRON:
607 for ( int row = 0; row < myNbCorners; row++ )
608 anIds.push_back(myTable->item(row, 0)->text().toInt());
609 for ( int row = 0; row < myTable->rowCount(); row++ )
610 anIds.push_back(myTable->item(row, 1)->text().toInt());
613 if ( myReverseCB->isChecked())
614 SMESH::ReverseConnectivity( anIds, myType );
616 int aNumberOfIds = anIds.size();
617 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
618 anArrayOfIdeces->length( aNumberOfIds );
620 for (int i = 0; i < aNumberOfIds; i++)
621 anArrayOfIdeces[i] = anIds[ i ];
623 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
626 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
628 case QUAD_QUADRANGLE:
629 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
630 case QUAD_TETRAHEDRON:
632 case QUAD_PENTAHEDRON:
633 case QUAD_HEXAHEDRON:
634 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
637 SALOME_ListIO aList; aList.Append( myActor->getIO() );
638 mySelector->ClearIndex();
639 mySelectionMgr->setSelectedObjects( aList, false );
642 mySimulation->SetVisibility(false);
644 buttonOk->setEnabled(false);
645 buttonApply->setEnabled(false);
654 //=================================================================================
655 // function : ClickOnOk()
657 //=================================================================================
658 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
664 //=================================================================================
665 // function : ClickOnCancel()
667 //=================================================================================
668 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
670 mySelectionMgr->clearSelected();
671 mySimulation->SetVisibility(false);
672 SMESH::SetPointRepresentation(false);
673 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
674 aViewWindow->SetSelectionMode( ActorSelection );
675 disconnect(mySelectionMgr, 0, this, 0);
676 mySMESHGUI->ResetState();
680 //=================================================================================
681 // function : ClickOnHelp()
683 //=================================================================================
684 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
686 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
688 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
692 platform = "winapplication";
694 platform = "application";
696 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
697 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
698 arg(app->resourceMgr()->stringValue("ExternalBrowser",
700 arg(myHelpFileName));
704 //=================================================================================
705 // function : onTextChange()
707 //=================================================================================
708 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
713 buttonOk->setEnabled(false);
714 buttonApply->setEnabled(false);
716 mySimulation->SetVisibility(false);
718 // hilight entered nodes
719 SMDS_Mesh* aMesh = 0;
721 aMesh = myActor->GetObject()->GetMesh();
724 TColStd_MapOfInteger newIndices;
726 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
728 for (int i = 0; i < aListId.count(); i++) {
729 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
730 newIndices.Add( n->GetID() );
738 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
739 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
740 aViewWindow->highlight( myActor->getIO(), true, true );
742 if ( sender() == myCornerNodes )
743 UpdateTable( allOk );
747 buttonOk->setEnabled(true);
748 buttonApply->setEnabled(true);
751 if ( sender() == myTable )
757 //=================================================================================
758 // function : SelectionIntoArgument()
759 // purpose : Called when selection has changed
760 //=================================================================================
761 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
765 if ( myIsEditCorners )
771 myCornerNodes->setText("");
774 if (!GroupButtons->isEnabled()) // inactive
777 buttonOk->setEnabled(false);
778 buttonApply->setEnabled(false);
780 mySimulation->SetVisibility(false);
784 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
786 if (aList.Extent() != 1)
792 Handle(SALOME_InteractiveObject) anIO = aList.First();
793 myMesh = SMESH::GetMeshByIO(anIO);
794 if (myMesh->_is_nil())
797 myActor = SMESH::FindActorByEntry(anIO->getEntry());
804 // get selected nodes
805 QString aString = "";
806 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
808 if ( myIsEditCorners )
811 myCornerNodes->setText(aString);
816 else if ( myTable->isEnabled() && nbNodes == 1 )
819 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
821 myTable->item(theRow, 1)->setText(aString);
827 buttonOk->setEnabled( true );
828 buttonApply->setEnabled( true );
834 //=================================================================================
835 // function : displaySimulation()
837 //=================================================================================
838 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
840 if (!myIsEditCorners) {
841 SMESH::TElementSimulation::TVTKIds anIds;
843 // Collect ids from the dialog
846 int aDisplayMode = VTK_SURFACE;
848 if ( myType == QUAD_EDGE )
850 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) );
851 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) );
852 anID = myTable->item(0, 1)->text().toInt(&ok);
853 if (!ok) anID = myTable->item(0, 0)->text().toInt();
854 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
855 aDisplayMode = VTK_WIREFRAME;
859 for ( int row = 0; row < myNbCorners; row++ )
860 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) );
862 for ( int row = 0; row < myTable->rowCount(); row++ )
864 anID = myTable->item(row, 1)->text().toInt(&ok);
866 anID = myTable->item(row, 0)->text().toInt();
867 aDisplayMode = VTK_WIREFRAME;
869 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
873 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
878 //=================================================================================
879 // function : SetEditCorners()
881 //=================================================================================
882 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
884 myCornerNodes->setFocus();
885 myIsEditCorners = true;
887 SelectionIntoArgument();
890 //=================================================================================
891 // function : DeactivateActiveDialog()
893 //=================================================================================
894 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
896 if (GroupConstructors->isEnabled()) {
897 GroupConstructors->setEnabled(false);
898 GroupArguments->setEnabled(false);
899 GroupButtons->setEnabled(false);
900 mySimulation->SetVisibility(false);
901 mySMESHGUI->ResetState();
902 mySMESHGUI->SetActiveDialogBox(0);
906 //=================================================================================
907 // function : ActivateThisDialog()
909 //=================================================================================
910 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
912 /* Emit a signal to deactivate the active dialog */
913 mySMESHGUI->EmitSignalDeactivateDialog();
915 GroupConstructors->setEnabled(true);
916 GroupArguments->setEnabled(true);
917 GroupButtons->setEnabled(true);
919 SMESH::SetPointRepresentation(true);
921 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
922 aViewWindow->SetSelectionMode( NodeSelection );
923 SelectionIntoArgument();
926 //=================================================================================
927 // function : enterEvent()
929 //=================================================================================
930 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
932 if (GroupConstructors->isEnabled())
934 ActivateThisDialog();
937 //=================================================================================
938 // function : closeEvent()
940 //=================================================================================
941 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
943 /* same than click on cancel button */
947 //=================================================================================
948 // function : hideEvent()
949 // purpose : caused by ESC key
950 //=================================================================================
951 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
957 //=================================================================================
958 // function : onReverse()
960 //=================================================================================
961 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
967 mySimulation->SetVisibility(false);
973 //=================================================================================
974 // function : IsValid()
976 //=================================================================================
977 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
979 SMDS_Mesh* aMesh = 0;
981 aMesh = myActor->GetObject()->GetMesh();
987 for ( int row = 0; row < myTable->rowCount(); row++ )
989 int anID = myTable->item(row, 1)->text().toInt(&ok);
993 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1001 //=================================================================================
1002 // function : UpdateTable()
1004 //=================================================================================
1005 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1007 QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
1009 if ( aListCorners.count() == myNbCorners && theConersValidity )
1011 myTable->setEnabled( true );
1013 // clear the Middle column
1014 for ( int row = 0; row < myTable->rowCount(); row++ )
1015 myTable->item( row, 1 )->setText("");
1022 aFirstColIds = FirstEdgeIds;
1023 aLastColIds = LastEdgeIds;
1026 aFirstColIds = FirstTriangleIds;
1027 aLastColIds = LastTriangleIds;
1029 case QUAD_QUADRANGLE:
1030 aFirstColIds = FirstQuadrangleIds;
1031 aLastColIds = LastQuadrangleIds;
1033 case QUAD_TETRAHEDRON:
1034 aFirstColIds = FirstTetrahedronIds;
1035 aLastColIds = LastTetrahedronIds;
1038 aFirstColIds = FirstPyramidIds;
1039 aLastColIds = LastPyramidIds;
1041 case QUAD_PENTAHEDRON:
1042 aFirstColIds = FirstPentahedronIds;
1043 aLastColIds = LastPentahedronIds;
1045 case QUAD_HEXAHEDRON:
1046 aFirstColIds = FirstHexahedronIds;
1047 aLastColIds = LastHexahedronIds;
1051 // fill the First and the Last columns
1052 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1053 myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] );
1055 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1056 myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] );
1061 for ( int row = 0; row < myTable->rowCount(); row++ )
1062 for ( int col = 0; col < myTable->columnCount(); col++ )
1063 if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText("");
1065 myTable->setEnabled( false );
1070 //=================================================================================
1071 // function : onTableActivate()
1073 //=================================================================================
1074 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
1077 myIsEditCorners = false;
1079 displaySimulation();
1083 //=================================================================================
1084 // function : onCellTextChange()
1086 //=================================================================================
1087 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1089 onTextChange( myTable->item(theRow, theCol)->text() );
1092 //=================================================================================
1093 // function : keyPressEvent()
1095 //=================================================================================
1096 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1098 QDialog::keyPressEvent( e );
1099 if ( e->isAccepted() )
1102 if ( e->key() == Qt::Key_F1 ) {