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>
90 void ReverseConnectivity( std::vector<int> & ids, int type )
92 // for reverse connectivity of other types keeping the first id, see
93 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
97 case QUAD_TETRAHEDRON: {
98 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
103 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
107 case QUAD_PENTAHEDRON: {
108 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
112 case QUAD_HEXAHEDRON: {
113 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
118 static int aConn[] = {1,0,2};
122 case QUAD_TRIANGLE: {
123 static int aConn[] = {0,2,1,5,4,3};
127 case QUAD_QUADRANGLE: {
128 static int aConn[] = {0,3,2,1,7,6,5,4};
135 reverse( ids.begin(), ids.end() );
138 std::vector<int> aRevIds( ids.size() );
139 for ( int i = 0; i < ids.size(); i++)
140 aRevIds[ i ] = ids[ conn[ i ]];
145 class TElementSimulation {
146 SalomeApp_Application* myApplication;
147 SUIT_ViewWindow* myViewWindow;
148 SVTK_ViewWindow* myVTKViewWindow;
150 SALOME_Actor* myPreviewActor;
151 vtkDataSetMapper* myMapper;
152 vtkUnstructuredGrid* myGrid;
153 //vtkProperty* myBackProp, *myProp;
155 vtkFloatingPointType myRGB[3], myBackRGB[3];
158 TElementSimulation (SalomeApp_Application* theApplication)
160 myApplication = theApplication;
161 SUIT_ViewManager* mgr = theApplication->activeViewManager();
163 myViewWindow = mgr->getActiveView();
164 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
166 myGrid = vtkUnstructuredGrid::New();
168 // Create and display actor
169 myMapper = vtkDataSetMapper::New();
170 myMapper->SetInput(myGrid);
172 myPreviewActor = SALOME_Actor::New();
173 myPreviewActor->PickableOff();
174 myPreviewActor->VisibilityOff();
175 myPreviewActor->SetMapper(myMapper);
177 vtkProperty* myProp = vtkProperty::New();
178 GetColor( "SMESH", "fill_color", myRGB[0], myRGB[1], myRGB[2], QColor( 0, 170, 255 ) );
179 myProp->SetColor( myRGB[0], myRGB[1], myRGB[2] );
180 myPreviewActor->SetProperty( myProp );
183 vtkProperty* myBackProp = vtkProperty::New();
184 GetColor( "SMESH", "backface_color", myBackRGB[0], myBackRGB[1], myBackRGB[2], QColor( 0, 0, 255 ) );
185 myBackProp->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
186 myPreviewActor->SetBackfaceProperty( myBackProp );
187 myBackProp->Delete();
189 myVTKViewWindow->AddActor(myPreviewActor);
192 typedef std::vector<vtkIdType> TVTKIds;
193 void SetPosition (SMESH_Actor* theActor,
197 const bool theReverse)
199 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
200 myGrid->SetPoints(aGrid->GetPoints());
208 aType = VTK_QUADRATIC_EDGE;
211 aType = VTK_QUADRATIC_TRIANGLE;
213 case QUAD_QUADRANGLE:
214 aType = VTK_QUADRATIC_QUAD;
216 case QUAD_TETRAHEDRON:
217 aType = VTK_QUADRATIC_TETRA;
220 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
221 aType = VTK_CONVEX_POINT_SET;
223 case QUAD_PENTAHEDRON:
224 //aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2
225 aType = VTK_CONVEX_POINT_SET;
227 case QUAD_HEXAHEDRON:
228 aType = VTK_QUADRATIC_HEXAHEDRON;
232 // take care of orientation
233 if ( aType == VTK_CONVEX_POINT_SET ) {
234 if ( theReverse && theMode == VTK_SURFACE ) {
235 //myPreviewActor->GetProperty()->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
239 // VTK cell connectivity opposites the MED one for volumic elements
240 if ( theIds.size() > 8 ? !theReverse : theReverse ) {
241 ReverseConnectivity( theIds, theType );
246 vtkIdList *anIds = vtkIdList::New();
248 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
249 anIds->InsertId(i,theIds[i]);
250 //std::cout << i<< ": " << theIds[i] << std::endl;
253 myGrid->InsertNextCell(aType,anIds);
258 myPreviewActor->GetMapper()->Update();
259 myPreviewActor->SetRepresentation( theMode );
262 // restore normal orientation
263 if ( aType == VTK_CONVEX_POINT_SET ) {
264 if ( theReverse && theMode == VTK_SURFACE ) {
265 //myPreviewActor->GetProperty()->SetColor( myRGB[0], myRGB[1], myRGB[2] );
271 void SetVisibility (bool theVisibility)
273 myPreviewActor->SetVisibility(theVisibility);
274 RepaintCurrentView();
278 ~TElementSimulation()
280 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
281 myVTKViewWindow->RemoveActor(myPreviewActor);
283 myPreviewActor->Delete();
285 myMapper->RemoveAllInputs();
291 // myBackProp->Delete();
297 // Define the sequences of ids
298 static int FirstEdgeIds[] = {0};
299 static int LastEdgeIds[] = {1};
301 static int FirstTriangleIds[] = {0,1,2};
302 static int LastTriangleIds[] = {1,2,0};
304 static int FirstQuadrangleIds[] = {0,1,2,3};
305 static int LastQuadrangleIds[] = {1,2,3,0};
307 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
308 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
310 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
311 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
313 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
314 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
316 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
317 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
321 class SMESHGUI_IdEditItem: public QTableWidgetItem
324 SMESHGUI_IdEditItem(const QString& text ):
325 QTableWidgetItem(text, QTableWidgetItem::UserType+100) {};
326 ~SMESHGUI_IdEditItem() {};
328 QWidget* createEditor() const;
331 QWidget* SMESHGUI_IdEditItem::createEditor() const
333 QLineEdit *aLineEdit = new QLineEdit(text(), tableWidget());
334 aLineEdit->setValidator( new SMESHGUI_IdValidator(tableWidget(), 1) );
338 //=================================================================================
339 // function : SMESHGUI_AddQuadraticElementDlg()
340 // purpose : constructor
341 //=================================================================================
342 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
344 : QDialog( SMESH::GetDesktop( theModule ) ),
345 mySMESHGUI( theModule ),
346 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
350 setAttribute( Qt::WA_DeleteOnClose, true );
352 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
353 (SUIT_Session::session()->activeApplication());
355 mySimulation = new SMESH::TElementSimulation (anApp);
356 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
358 QString anElementName;
362 anElementName = QString("QUADRATIC_EDGE");
365 anElementName = QString("QUADRATIC_TRIANGLE");
367 case QUAD_QUADRANGLE:
368 anElementName = QString("QUADRATIC_QUADRANGLE");
370 case QUAD_TETRAHEDRON:
371 anElementName = QString("QUADRATIC_TETRAHEDRON");
374 anElementName = QString("QUADRATIC_PYRAMID");
376 case QUAD_PENTAHEDRON:
377 anElementName = QString("QUADRATIC_PENTAHEDRON");
379 case QUAD_HEXAHEDRON:
380 anElementName = QString("QUADRATIC_HEXAHEDRON");
384 anElementName = QString("QUADRATIC_EDGE");
387 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName).toLatin1().data());
388 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName).toLatin1().data());
389 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName).toLatin1().data());
390 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName).toLatin1().data());
392 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
393 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
395 setWindowTitle(caption);
397 setSizeGripEnabled(true);
399 QVBoxLayout* aDialogLayout = new QVBoxLayout(this);
400 aDialogLayout->setSpacing(SPACING);
401 aDialogLayout->setMargin(MARGIN);
403 /***************************************************************/
404 GroupConstructors = new QGroupBox(constructorGrTitle, this);
405 QHBoxLayout* aGroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
406 aGroupConstructorsLayout->setSpacing(SPACING);
407 aGroupConstructorsLayout->setMargin(MARGIN);
409 myRadioButton1 = new QRadioButton(GroupConstructors);
410 myRadioButton1->setIcon(image0);
411 aGroupConstructorsLayout->addWidget(myRadioButton1);
412 aGroupConstructorsLayout->addStretch();
414 /***************************************************************/
415 GroupArguments = new QGroupBox(argumentsGrTitle, this);
416 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments);
417 aGroupArgumentsLayout->setSpacing(SPACING);
418 aGroupArgumentsLayout->setMargin(MARGIN);
420 QLabel* aCornerNodesLabel = new QLabel(tr("SMESH_CORNER_NODES"), GroupArguments);
421 mySelectButton = new QPushButton(GroupArguments);
422 mySelectButton->setIcon(image1);
423 myCornerNodes = new QLineEdit(GroupArguments);
425 myTable = new QTableWidget(GroupArguments);
427 myReverseCB = new QCheckBox(tr("SMESH_REVERSE"), GroupArguments);
429 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
430 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
431 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
432 aGroupArgumentsLayout->addWidget(myTable, 1, 0, 1, 3);
433 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0, 1, 3);
435 /***************************************************************/
436 GroupButtons = new QGroupBox(this);
437 QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons);
438 aGroupButtonsLayout->setSpacing(SPACING);
439 aGroupButtonsLayout->setMargin(MARGIN);
441 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
442 buttonOk->setAutoDefault(true);
443 buttonOk->setDefault(true);
444 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
445 buttonApply->setAutoDefault(true);
446 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
447 buttonCancel->setAutoDefault(true);
448 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
449 buttonHelp->setAutoDefault(true);
451 aGroupButtonsLayout->addWidget(buttonOk);
452 aGroupButtonsLayout->addSpacing(10);
453 aGroupButtonsLayout->addWidget(buttonApply);
454 aGroupButtonsLayout->addSpacing(10);
455 aGroupButtonsLayout->addStretch();
456 aGroupButtonsLayout->addWidget(buttonCancel);
457 aGroupButtonsLayout->addWidget(buttonHelp);
459 /***************************************************************/
460 aDialogLayout->addWidget(GroupConstructors);
461 aDialogLayout->addWidget(GroupArguments);
462 aDialogLayout->addWidget(GroupButtons);
464 Init(); /* Initialisations */
467 //=================================================================================
468 // function : ~SMESHGUI_AddQuadraticElementDlg()
469 // purpose : Destroys the object and frees any allocated resources
470 //=================================================================================
471 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
476 //=================================================================================
479 //=================================================================================
480 void SMESHGUI_AddQuadraticElementDlg::Init()
482 myRadioButton1->setChecked(true);
483 myIsEditCorners = true;
484 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
494 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
499 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
501 case QUAD_QUADRANGLE:
504 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
506 case QUAD_TETRAHEDRON:
509 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
514 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
516 case QUAD_PENTAHEDRON:
519 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
521 case QUAD_HEXAHEDRON:
524 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
528 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, myNbCorners));
530 /* initialize table */
531 myTable->setColumnCount(3);
532 myTable->setRowCount(aNumRows);
534 QStringList aColLabels;
535 aColLabels.append(tr("SMESH_FIRST"));
536 aColLabels.append(tr("SMESH_MIDDLE"));
537 aColLabels.append(tr("SMESH_LAST"));
538 myTable->setHorizontalHeaderLabels(aColLabels);
540 for ( int col = 0; col < myTable->columnCount(); col++ )
541 myTable->setColumnWidth(col, 80);
543 //myTable->setColumnReadOnly(0, true); // VSR: TODO
544 //myTable->setColumnReadOnly(2, true); // VSR: TODO
546 myTable->setEnabled( false );
548 for ( int row = 0; row < myTable->rowCount(); row++ )
550 SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( "" );
551 anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
552 myTable->setItem(row, 1, anEditItem);
555 /* signals and slots connections */
556 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
557 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
558 connect(myTable, SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int)));
559 connect(myTable, SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int)));
560 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
561 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
563 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
564 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
565 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
566 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
568 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
569 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
571 // set selection mode
572 SMESH::SetPointRepresentation(true);
574 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
575 aViewWindow->SetSelectionMode( NodeSelection );
582 //=================================================================================
583 // function : ClickOnApply()
585 //=================================================================================
586 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
588 if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
591 std::vector<int> anIds;
595 anIds.push_back(myTable->item(0, 0)->text().toInt());
596 anIds.push_back(myTable->item(0, 2)->text().toInt());
597 anIds.push_back(myTable->item(0, 1)->text().toInt());
600 case QUAD_QUADRANGLE:
601 case QUAD_TETRAHEDRON:
603 case QUAD_PENTAHEDRON:
604 case QUAD_HEXAHEDRON:
605 for ( int row = 0; row < myNbCorners; row++ )
606 anIds.push_back(myTable->item(row, 0)->text().toInt());
607 for ( int row = 0; row < myTable->rowCount(); row++ )
608 anIds.push_back(myTable->item(row, 1)->text().toInt());
611 if ( myReverseCB->isChecked())
612 SMESH::ReverseConnectivity( anIds, myType );
614 int aNumberOfIds = anIds.size();
615 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
616 anArrayOfIdeces->length( aNumberOfIds );
618 for (int i = 0; i < aNumberOfIds; i++)
619 anArrayOfIdeces[i] = anIds[ i ];
621 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
624 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
626 case QUAD_QUADRANGLE:
627 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
628 case QUAD_TETRAHEDRON:
630 case QUAD_PENTAHEDRON:
631 case QUAD_HEXAHEDRON:
632 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
635 SALOME_ListIO aList; aList.Append( myActor->getIO() );
636 mySelector->ClearIndex();
637 mySelectionMgr->setSelectedObjects( aList, false );
640 mySimulation->SetVisibility(false);
642 buttonOk->setEnabled(false);
643 buttonApply->setEnabled(false);
652 //=================================================================================
653 // function : ClickOnOk()
655 //=================================================================================
656 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
662 //=================================================================================
663 // function : ClickOnCancel()
665 //=================================================================================
666 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
668 mySelectionMgr->clearSelected();
669 mySimulation->SetVisibility(false);
670 SMESH::SetPointRepresentation(false);
671 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
672 aViewWindow->SetSelectionMode( ActorSelection );
673 disconnect(mySelectionMgr, 0, this, 0);
674 mySMESHGUI->ResetState();
678 //=================================================================================
679 // function : ClickOnHelp()
681 //=================================================================================
682 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
684 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
686 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
690 platform = "winapplication";
692 platform = "application";
694 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
695 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
696 arg(app->resourceMgr()->stringValue("ExternalBrowser",
698 arg(myHelpFileName));
702 //=================================================================================
703 // function : onTextChange()
705 //=================================================================================
706 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
711 buttonOk->setEnabled(false);
712 buttonApply->setEnabled(false);
714 mySimulation->SetVisibility(false);
716 // hilight entered nodes
717 SMDS_Mesh* aMesh = 0;
719 aMesh = myActor->GetObject()->GetMesh();
722 TColStd_MapOfInteger newIndices;
724 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
726 for (int i = 0; i < aListId.count(); i++) {
727 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
728 newIndices.Add( n->GetID() );
736 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
737 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
738 aViewWindow->highlight( myActor->getIO(), true, true );
740 if ( sender() == myCornerNodes )
741 UpdateTable( allOk );
745 buttonOk->setEnabled(true);
746 buttonApply->setEnabled(true);
749 if ( sender() == myTable )
755 //=================================================================================
756 // function : SelectionIntoArgument()
757 // purpose : Called when selection has changed
758 //=================================================================================
759 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
763 if ( myIsEditCorners )
769 myCornerNodes->setText("");
772 if (!GroupButtons->isEnabled()) // inactive
775 buttonOk->setEnabled(false);
776 buttonApply->setEnabled(false);
778 mySimulation->SetVisibility(false);
782 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
784 if (aList.Extent() != 1)
790 Handle(SALOME_InteractiveObject) anIO = aList.First();
791 myMesh = SMESH::GetMeshByIO(anIO);
792 if (myMesh->_is_nil())
795 myActor = SMESH::FindActorByEntry(anIO->getEntry());
802 // get selected nodes
803 QString aString = "";
804 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
806 if ( myIsEditCorners )
809 myCornerNodes->setText(aString);
814 else if ( myTable->isEnabled() && nbNodes == 1 )
817 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
819 myTable->item(theRow, 1)->setText(aString);
825 buttonOk->setEnabled( true );
826 buttonApply->setEnabled( true );
832 //=================================================================================
833 // function : displaySimulation()
835 //=================================================================================
836 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
838 if (!myIsEditCorners) {
839 SMESH::TElementSimulation::TVTKIds anIds;
841 // Collect ids from the dialog
844 int aDisplayMode = VTK_SURFACE;
846 if ( myType == QUAD_EDGE )
848 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) );
849 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) );
850 anID = myTable->item(0, 1)->text().toInt(&ok);
851 if (!ok) anID = myTable->item(0, 0)->text().toInt();
852 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
853 aDisplayMode = VTK_WIREFRAME;
857 for ( int row = 0; row < myNbCorners; row++ )
858 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) );
860 for ( int row = 0; row < myTable->rowCount(); row++ )
862 anID = myTable->item(row, 1)->text().toInt(&ok);
864 anID = myTable->item(row, 0)->text().toInt();
865 aDisplayMode = VTK_WIREFRAME;
867 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
871 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
876 //=================================================================================
877 // function : SetEditCorners()
879 //=================================================================================
880 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
882 myCornerNodes->setFocus();
883 myIsEditCorners = true;
885 SelectionIntoArgument();
888 //=================================================================================
889 // function : DeactivateActiveDialog()
891 //=================================================================================
892 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
894 if (GroupConstructors->isEnabled()) {
895 GroupConstructors->setEnabled(false);
896 GroupArguments->setEnabled(false);
897 GroupButtons->setEnabled(false);
898 mySimulation->SetVisibility(false);
899 mySMESHGUI->ResetState();
900 mySMESHGUI->SetActiveDialogBox(0);
904 //=================================================================================
905 // function : ActivateThisDialog()
907 //=================================================================================
908 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
910 /* Emit a signal to deactivate the active dialog */
911 mySMESHGUI->EmitSignalDeactivateDialog();
913 GroupConstructors->setEnabled(true);
914 GroupArguments->setEnabled(true);
915 GroupButtons->setEnabled(true);
917 SMESH::SetPointRepresentation(true);
919 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
920 aViewWindow->SetSelectionMode( NodeSelection );
921 SelectionIntoArgument();
924 //=================================================================================
925 // function : enterEvent()
927 //=================================================================================
928 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
930 if (GroupConstructors->isEnabled())
932 ActivateThisDialog();
935 //=================================================================================
936 // function : closeEvent()
938 //=================================================================================
939 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
941 /* same than click on cancel button */
945 //=================================================================================
946 // function : hideEvent()
947 // purpose : caused by ESC key
948 //=================================================================================
949 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
955 //=================================================================================
956 // function : onReverse()
958 //=================================================================================
959 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
965 mySimulation->SetVisibility(false);
971 //=================================================================================
972 // function : IsValid()
974 //=================================================================================
975 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
977 SMDS_Mesh* aMesh = 0;
979 aMesh = myActor->GetObject()->GetMesh();
985 for ( int row = 0; row < myTable->rowCount(); row++ )
987 int anID = myTable->item(row, 1)->text().toInt(&ok);
991 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
999 //=================================================================================
1000 // function : UpdateTable()
1002 //=================================================================================
1003 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1005 QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
1007 if ( aListCorners.count() == myNbCorners && theConersValidity )
1009 myTable->setEnabled( true );
1011 // clear the Middle column
1012 for ( int row = 0; row < myTable->rowCount(); row++ )
1013 myTable->item( row, 1 )->setText("");
1020 aFirstColIds = FirstEdgeIds;
1021 aLastColIds = LastEdgeIds;
1024 aFirstColIds = FirstTriangleIds;
1025 aLastColIds = LastTriangleIds;
1027 case QUAD_QUADRANGLE:
1028 aFirstColIds = FirstQuadrangleIds;
1029 aLastColIds = LastQuadrangleIds;
1031 case QUAD_TETRAHEDRON:
1032 aFirstColIds = FirstTetrahedronIds;
1033 aLastColIds = LastTetrahedronIds;
1036 aFirstColIds = FirstPyramidIds;
1037 aLastColIds = LastPyramidIds;
1039 case QUAD_PENTAHEDRON:
1040 aFirstColIds = FirstPentahedronIds;
1041 aLastColIds = LastPentahedronIds;
1043 case QUAD_HEXAHEDRON:
1044 aFirstColIds = FirstHexahedronIds;
1045 aLastColIds = LastHexahedronIds;
1049 // fill the First and the Last columns
1050 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1051 myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] );
1053 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1054 myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] );
1059 for ( int row = 0; row < myTable->rowCount(); row++ )
1060 for ( int col = 0; col < myTable->columnCount(); col++ )
1061 myTable->item(row, col)->setText("");
1063 myTable->setEnabled( false );
1068 //=================================================================================
1069 // function : onTableActivate()
1071 //=================================================================================
1072 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
1075 myIsEditCorners = false;
1077 displaySimulation();
1081 //=================================================================================
1082 // function : onCellTextChange()
1084 //=================================================================================
1085 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1087 onTextChange( myTable->item(theRow, theCol)->text() );
1090 //=================================================================================
1091 // function : keyPressEvent()
1093 //=================================================================================
1094 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1096 QDialog::keyPressEvent( e );
1097 if ( e->isAccepted() )
1100 if ( e->key() == Qt::Key_F1 ) {