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 myTable->setItem( row, 0, new QTableWidgetItem( "" ) );
554 SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( "" );
555 anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
556 myTable->setItem(row, 1, anEditItem);
558 myTable->setItem( row, 2, new QTableWidgetItem( "" ) );
561 /* signals and slots connections */
562 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
563 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
564 connect(myTable, SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int)));
565 connect(myTable, SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int)));
566 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
567 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
569 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
570 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
571 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
572 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
574 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
575 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
577 // set selection mode
578 SMESH::SetPointRepresentation(true);
580 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
581 aViewWindow->SetSelectionMode( NodeSelection );
588 //=================================================================================
589 // function : ClickOnApply()
591 //=================================================================================
592 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
594 if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
597 std::vector<int> anIds;
601 anIds.push_back(myTable->item(0, 0)->text().toInt());
602 anIds.push_back(myTable->item(0, 2)->text().toInt());
603 anIds.push_back(myTable->item(0, 1)->text().toInt());
606 case QUAD_QUADRANGLE:
607 case QUAD_TETRAHEDRON:
609 case QUAD_PENTAHEDRON:
610 case QUAD_HEXAHEDRON:
611 for ( int row = 0; row < myNbCorners; row++ )
612 anIds.push_back(myTable->item(row, 0)->text().toInt());
613 for ( int row = 0; row < myTable->rowCount(); row++ )
614 anIds.push_back(myTable->item(row, 1)->text().toInt());
617 if ( myReverseCB->isChecked())
618 SMESH::ReverseConnectivity( anIds, myType );
620 int aNumberOfIds = anIds.size();
621 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
622 anArrayOfIdeces->length( aNumberOfIds );
624 for (int i = 0; i < aNumberOfIds; i++)
625 anArrayOfIdeces[i] = anIds[ i ];
627 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
630 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
632 case QUAD_QUADRANGLE:
633 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
634 case QUAD_TETRAHEDRON:
636 case QUAD_PENTAHEDRON:
637 case QUAD_HEXAHEDRON:
638 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
641 SALOME_ListIO aList; aList.Append( myActor->getIO() );
642 mySelector->ClearIndex();
643 mySelectionMgr->setSelectedObjects( aList, false );
646 mySimulation->SetVisibility(false);
648 buttonOk->setEnabled(false);
649 buttonApply->setEnabled(false);
658 //=================================================================================
659 // function : ClickOnOk()
661 //=================================================================================
662 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
668 //=================================================================================
669 // function : ClickOnCancel()
671 //=================================================================================
672 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
674 mySelectionMgr->clearSelected();
675 mySimulation->SetVisibility(false);
676 SMESH::SetPointRepresentation(false);
677 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
678 aViewWindow->SetSelectionMode( ActorSelection );
679 disconnect(mySelectionMgr, 0, this, 0);
680 mySMESHGUI->ResetState();
684 //=================================================================================
685 // function : ClickOnHelp()
687 //=================================================================================
688 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
690 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
692 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
696 platform = "winapplication";
698 platform = "application";
700 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
701 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
702 arg(app->resourceMgr()->stringValue("ExternalBrowser",
704 arg(myHelpFileName));
708 //=================================================================================
709 // function : onTextChange()
711 //=================================================================================
712 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
717 buttonOk->setEnabled(false);
718 buttonApply->setEnabled(false);
720 mySimulation->SetVisibility(false);
722 // hilight entered nodes
723 SMDS_Mesh* aMesh = 0;
725 aMesh = myActor->GetObject()->GetMesh();
728 TColStd_MapOfInteger newIndices;
730 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
732 for (int i = 0; i < aListId.count(); i++) {
733 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
734 newIndices.Add( n->GetID() );
742 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
743 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
744 aViewWindow->highlight( myActor->getIO(), true, true );
746 if ( sender() == myCornerNodes )
747 UpdateTable( allOk );
751 buttonOk->setEnabled(true);
752 buttonApply->setEnabled(true);
755 if ( sender() == myTable )
761 //=================================================================================
762 // function : SelectionIntoArgument()
763 // purpose : Called when selection has changed
764 //=================================================================================
765 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
769 if ( myIsEditCorners )
775 myCornerNodes->setText("");
778 if (!GroupButtons->isEnabled()) // inactive
781 buttonOk->setEnabled(false);
782 buttonApply->setEnabled(false);
784 mySimulation->SetVisibility(false);
788 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
790 if (aList.Extent() != 1)
796 Handle(SALOME_InteractiveObject) anIO = aList.First();
797 myMesh = SMESH::GetMeshByIO(anIO);
798 if (myMesh->_is_nil())
801 myActor = SMESH::FindActorByEntry(anIO->getEntry());
808 // get selected nodes
809 QString aString = "";
810 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
812 if ( myIsEditCorners )
815 myCornerNodes->setText(aString);
820 else if ( myTable->isEnabled() && nbNodes == 1 )
823 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
825 myTable->item(theRow, 1)->setText(aString);
831 buttonOk->setEnabled( true );
832 buttonApply->setEnabled( true );
838 //=================================================================================
839 // function : displaySimulation()
841 //=================================================================================
842 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
844 if (!myIsEditCorners) {
845 SMESH::TElementSimulation::TVTKIds anIds;
847 // Collect ids from the dialog
850 int aDisplayMode = VTK_SURFACE;
852 if ( myType == QUAD_EDGE )
854 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) );
855 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) );
856 anID = myTable->item(0, 1)->text().toInt(&ok);
857 if (!ok) anID = myTable->item(0, 0)->text().toInt();
858 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
859 aDisplayMode = VTK_WIREFRAME;
863 for ( int row = 0; row < myNbCorners; row++ )
864 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) );
866 for ( int row = 0; row < myTable->rowCount(); row++ )
868 anID = myTable->item(row, 1)->text().toInt(&ok);
870 anID = myTable->item(row, 0)->text().toInt();
871 aDisplayMode = VTK_WIREFRAME;
873 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
877 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
882 //=================================================================================
883 // function : SetEditCorners()
885 //=================================================================================
886 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
888 myCornerNodes->setFocus();
889 myIsEditCorners = true;
891 SelectionIntoArgument();
894 //=================================================================================
895 // function : DeactivateActiveDialog()
897 //=================================================================================
898 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
900 if (GroupConstructors->isEnabled()) {
901 GroupConstructors->setEnabled(false);
902 GroupArguments->setEnabled(false);
903 GroupButtons->setEnabled(false);
904 mySimulation->SetVisibility(false);
905 mySMESHGUI->ResetState();
906 mySMESHGUI->SetActiveDialogBox(0);
910 //=================================================================================
911 // function : ActivateThisDialog()
913 //=================================================================================
914 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
916 /* Emit a signal to deactivate the active dialog */
917 mySMESHGUI->EmitSignalDeactivateDialog();
919 GroupConstructors->setEnabled(true);
920 GroupArguments->setEnabled(true);
921 GroupButtons->setEnabled(true);
923 SMESH::SetPointRepresentation(true);
925 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
926 aViewWindow->SetSelectionMode( NodeSelection );
927 SelectionIntoArgument();
930 //=================================================================================
931 // function : enterEvent()
933 //=================================================================================
934 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
936 if (GroupConstructors->isEnabled())
938 ActivateThisDialog();
941 //=================================================================================
942 // function : closeEvent()
944 //=================================================================================
945 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
947 /* same than click on cancel button */
951 //=================================================================================
952 // function : hideEvent()
953 // purpose : caused by ESC key
954 //=================================================================================
955 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
961 //=================================================================================
962 // function : onReverse()
964 //=================================================================================
965 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
971 mySimulation->SetVisibility(false);
977 //=================================================================================
978 // function : IsValid()
980 //=================================================================================
981 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
983 SMDS_Mesh* aMesh = 0;
985 aMesh = myActor->GetObject()->GetMesh();
991 for ( int row = 0; row < myTable->rowCount(); row++ )
993 int anID = myTable->item(row, 1)->text().toInt(&ok);
997 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1005 //=================================================================================
1006 // function : UpdateTable()
1008 //=================================================================================
1009 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1011 QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
1013 if ( aListCorners.count() == myNbCorners && theConersValidity )
1015 myTable->setEnabled( true );
1017 // clear the Middle column
1018 for ( int row = 0; row < myTable->rowCount(); row++ )
1019 myTable->item( row, 1 )->setText("");
1026 aFirstColIds = FirstEdgeIds;
1027 aLastColIds = LastEdgeIds;
1030 aFirstColIds = FirstTriangleIds;
1031 aLastColIds = LastTriangleIds;
1033 case QUAD_QUADRANGLE:
1034 aFirstColIds = FirstQuadrangleIds;
1035 aLastColIds = LastQuadrangleIds;
1037 case QUAD_TETRAHEDRON:
1038 aFirstColIds = FirstTetrahedronIds;
1039 aLastColIds = LastTetrahedronIds;
1042 aFirstColIds = FirstPyramidIds;
1043 aLastColIds = LastPyramidIds;
1045 case QUAD_PENTAHEDRON:
1046 aFirstColIds = FirstPentahedronIds;
1047 aLastColIds = LastPentahedronIds;
1049 case QUAD_HEXAHEDRON:
1050 aFirstColIds = FirstHexahedronIds;
1051 aLastColIds = LastHexahedronIds;
1055 // fill the First and the Last columns
1056 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1057 myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] );
1059 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1060 myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] );
1065 for ( int row = 0; row < myTable->rowCount(); row++ )
1066 for ( int col = 0; col < myTable->columnCount(); col++ )
1067 if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText("");
1069 myTable->setEnabled( false );
1074 //=================================================================================
1075 // function : onTableActivate()
1077 //=================================================================================
1078 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
1081 myIsEditCorners = false;
1083 displaySimulation();
1087 //=================================================================================
1088 // function : onCellTextChange()
1090 //=================================================================================
1091 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1093 onTextChange( myTable->item(theRow, theCol)->text() );
1096 //=================================================================================
1097 // function : keyPressEvent()
1099 //=================================================================================
1100 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1102 QDialog::keyPressEvent( e );
1103 if ( e->isAccepted() )
1106 if ( e->key() == Qt::Key_F1 ) {