1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_AddMeshElementDlg.cxx
24 // 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 <SMESH_FaceOrientationFilter.h>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_ViewManager.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
54 #include <SalomeApp_Application.h>
57 #include <SALOMEconfig.h>
58 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
61 #include <TColStd_MapOfInteger.hxx>
64 #include <vtkIdList.h>
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkDataSetMapper.h>
67 #include <vtkPolyDataMapper.h>
68 #include <vtkProperty.h>
69 #include <vtkCellType.h>
75 #include <QPushButton>
76 #include <QRadioButton>
77 #include <QVBoxLayout>
78 #include <QHBoxLayout>
79 #include <QGridLayout>
81 #include <QTableWidget>
83 #include <QButtonGroup>
93 void ReverseConnectivity( std::vector<vtkIdType> & ids, int type )
95 // for reverse connectivity of other types keeping the first id, see
96 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
100 case QUAD_TETRAHEDRON: {
101 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
106 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
110 case QUAD_PENTAHEDRON: {
111 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
115 case QUAD_HEXAHEDRON: {
116 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
121 static int aConn[] = {1,0,2};
125 case QUAD_TRIANGLE: {
126 static int aConn[] = {0,2,1,5,4,3};
130 case QUAD_QUADRANGLE: {
131 static int aConn[] = {0,3,2,1,7,6,5,4};
138 reverse( ids.begin(), ids.end() );
141 std::vector<vtkIdType> aRevIds( ids.size() );
142 for ( int i = 0; i < ids.size(); i++)
143 aRevIds[ i ] = ids[ conn[ i ]];
148 class TElementSimulation {
149 SalomeApp_Application* myApplication;
150 SUIT_ViewWindow* myViewWindow;
151 SVTK_ViewWindow* myVTKViewWindow;
153 SALOME_Actor* myPreviewActor;
154 vtkDataSetMapper* myMapper;
155 vtkUnstructuredGrid* myGrid;
156 //vtkProperty* myBackProp, *myProp;
158 //vtkFloatingPointType myRGB[3], myBackRGB[3];
160 SALOME_Actor* myFaceOrientation;
161 vtkPolyDataMapper* myFaceOrientationDataMapper;
162 SMESH_FaceOrientationFilter* myFaceOrientationFilter;
165 TElementSimulation (SalomeApp_Application* theApplication)
167 myApplication = theApplication;
168 SUIT_ViewManager* mgr = theApplication->activeViewManager();
170 myViewWindow = mgr->getActiveView();
171 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
173 myGrid = vtkUnstructuredGrid::New();
175 // Create and display actor
176 myMapper = vtkDataSetMapper::New();
177 myMapper->SetInput(myGrid);
179 myPreviewActor = SALOME_Actor::New();
180 myPreviewActor->PickableOff();
181 myPreviewActor->VisibilityOff();
182 myPreviewActor->SetMapper(myMapper);
184 vtkProperty* myProp = vtkProperty::New();
185 vtkFloatingPointType aRGB[3], aBackRGB[3];
186 GetColor( "SMESH", "fill_color", aRGB[0], aRGB[1], aRGB[2], QColor( 0, 170, 255 ) );
187 myProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
188 myPreviewActor->SetProperty( myProp );
191 vtkProperty* myBackProp = vtkProperty::New();
192 GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
193 myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
194 myPreviewActor->SetBackfaceProperty( myBackProp );
195 myBackProp->Delete();
197 myVTKViewWindow->AddActor(myPreviewActor);
199 // Orientation of faces
200 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
201 myFaceOrientationFilter->SetInput(myGrid);
203 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
204 myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
206 myFaceOrientation = SALOME_Actor::New();
207 myFaceOrientation->PickableOff();
208 myFaceOrientation->VisibilityOff();
209 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
211 vtkProperty* anOrientationProp = vtkProperty::New();
212 GetColor( "SMESH", "orientation_color", aRGB[0], aRGB[1], aRGB[2], QColor( 255, 255, 255 ) );
213 anOrientationProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
214 myFaceOrientation->SetProperty( anOrientationProp );
215 anOrientationProp->Delete();
217 myVTKViewWindow->AddActor(myFaceOrientation);
220 typedef std::vector<vtkIdType> TVTKIds;
221 void SetPosition (SMESH_Actor* theActor,
225 const bool theReverse)
227 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
228 myGrid->SetPoints(aGrid->GetPoints());
236 aType = VTK_QUADRATIC_EDGE;
239 aType = VTK_QUADRATIC_TRIANGLE;
241 case QUAD_QUADRANGLE:
242 aType = VTK_QUADRATIC_QUAD;
244 case QUAD_TETRAHEDRON:
245 aType = VTK_QUADRATIC_TETRA;
248 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
249 aType = VTK_CONVEX_POINT_SET;
251 case QUAD_PENTAHEDRON:
252 aType = VTK_QUADRATIC_WEDGE;
253 //aType = VTK_CONVEX_POINT_SET;
255 case QUAD_HEXAHEDRON:
256 aType = VTK_QUADRATIC_HEXAHEDRON;
260 // take care of orientation
261 if ( aType == VTK_CONVEX_POINT_SET ) {
262 if ( theReverse && theMode == VTK_SURFACE ) {
263 //myPreviewActor->GetProperty()->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
267 // VTK cell connectivity opposites the MED one for volumic elements
268 if( aType != VTK_QUADRATIC_WEDGE) {
269 if ( theIds.size() > 8 ? !theReverse : theReverse ) {
270 ReverseConnectivity( theIds, theType );
274 ReverseConnectivity( theIds, theType );
278 vtkIdList *anIds = vtkIdList::New();
280 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
281 anIds->InsertId(i,theIds[i]);
282 //std::cout << i<< ": " << theIds[i] << std::endl;
285 myGrid->InsertNextCell(aType,anIds);
290 myPreviewActor->GetMapper()->Update();
291 myPreviewActor->SetRepresentation( theMode );
292 SetVisibility(true, theActor->GetFacesOriented());
294 // restore normal orientation
295 if ( aType == VTK_CONVEX_POINT_SET ) {
296 if ( theReverse && theMode == VTK_SURFACE ) {
297 //myPreviewActor->GetProperty()->SetColor( myRGB[0], myRGB[1], myRGB[2] );
303 void SetVisibility (bool theVisibility, bool theShowOrientation = false)
305 myPreviewActor->SetVisibility(theVisibility);
306 myFaceOrientation->SetVisibility(theShowOrientation);
307 RepaintCurrentView();
311 ~TElementSimulation()
313 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
314 myVTKViewWindow->RemoveActor(myPreviewActor);
315 myVTKViewWindow->RemoveActor(myFaceOrientation);
317 myPreviewActor->Delete();
318 myFaceOrientation->Delete();
320 myMapper->RemoveAllInputs();
323 myFaceOrientationFilter->Delete();
325 myFaceOrientationDataMapper->RemoveAllInputs();
326 myFaceOrientationDataMapper->Delete();
331 // myBackProp->Delete();
337 // Define the sequences of ids
338 static int FirstEdgeIds[] = {0};
339 static int LastEdgeIds[] = {1};
341 static int FirstTriangleIds[] = {0,1,2};
342 static int LastTriangleIds[] = {1,2,0};
344 static int FirstQuadrangleIds[] = {0,1,2,3};
345 static int LastQuadrangleIds[] = {1,2,3,0};
347 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
348 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
350 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
351 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
353 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
354 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
356 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
357 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
363 \brief Simple 'busy state' flag locker.
370 //! Constructor. Sets passed boolean flag to \c true.
371 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
372 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
373 ~BusyLocker() { myBusy = false; }
375 bool& myBusy; //! External 'busy state' boolean flag
380 \brief Simple editable table item.
384 class IdEditItem: public QTableWidgetItem
387 IdEditItem(const QString& text );
390 QWidget* createEditor() const;
393 IdEditItem::IdEditItem(const QString& text )
394 : QTableWidgetItem(text, QTableWidgetItem::UserType+100)
398 IdEditItem::~IdEditItem()
402 QWidget* IdEditItem::createEditor() const
404 QLineEdit *aLineEdit = new QLineEdit(text(), tableWidget());
405 aLineEdit->setValidator( new SMESHGUI_IdValidator(tableWidget(), 1) );
409 //=================================================================================
410 // function : SMESHGUI_AddQuadraticElementDlg()
411 // purpose : constructor
412 //=================================================================================
413 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
415 : QDialog( SMESH::GetDesktop( theModule ) ),
416 mySMESHGUI( theModule ),
417 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
422 setAttribute( Qt::WA_DeleteOnClose, true );
424 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
425 (SUIT_Session::session()->activeApplication());
427 mySimulation = new SMESH::TElementSimulation (anApp);
428 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
430 QString anElementName;
434 anElementName = QString("QUADRATIC_EDGE");
437 anElementName = QString("QUADRATIC_TRIANGLE");
439 case QUAD_QUADRANGLE:
440 anElementName = QString("QUADRATIC_QUADRANGLE");
442 case QUAD_TETRAHEDRON:
443 anElementName = QString("QUADRATIC_TETRAHEDRON");
446 anElementName = QString("QUADRATIC_PYRAMID");
448 case QUAD_PENTAHEDRON:
449 anElementName = QString("QUADRATIC_PENTAHEDRON");
451 case QUAD_HEXAHEDRON:
452 anElementName = QString("QUADRATIC_HEXAHEDRON");
456 anElementName = QString("QUADRATIC_EDGE");
459 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName).toLatin1().data());
460 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName).toLatin1().data());
461 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName).toLatin1().data());
462 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName).toLatin1().data());
464 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
465 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
467 setWindowTitle(caption);
469 setSizeGripEnabled(true);
471 QVBoxLayout* aDialogLayout = new QVBoxLayout(this);
472 aDialogLayout->setSpacing(SPACING);
473 aDialogLayout->setMargin(MARGIN);
475 /***************************************************************/
476 GroupConstructors = new QGroupBox(constructorGrTitle, this);
477 QButtonGroup* ButtonGroup = new QButtonGroup(this);
478 QHBoxLayout* aGroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
479 aGroupConstructorsLayout->setSpacing(SPACING);
480 aGroupConstructorsLayout->setMargin(MARGIN);
482 myRadioButton1 = new QRadioButton(GroupConstructors);
483 myRadioButton1->setIcon(image0);
484 aGroupConstructorsLayout->addWidget(myRadioButton1);
485 ButtonGroup->addButton(myRadioButton1, 0);
487 /***************************************************************/
488 GroupArguments = new QGroupBox(argumentsGrTitle, this);
489 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments);
490 aGroupArgumentsLayout->setSpacing(SPACING);
491 aGroupArgumentsLayout->setMargin(MARGIN);
493 QLabel* aCornerNodesLabel = new QLabel(tr("SMESH_CORNER_NODES"), GroupArguments);
494 mySelectButton = new QPushButton(GroupArguments);
495 mySelectButton->setIcon(image1);
496 myCornerNodes = new QLineEdit(GroupArguments);
498 myTable = new QTableWidget(GroupArguments);
500 myReverseCB = new QCheckBox(tr("SMESH_REVERSE"), GroupArguments);
502 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
503 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
504 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
505 aGroupArgumentsLayout->addWidget(myTable, 1, 0, 1, 3);
506 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0, 1, 3);
508 /***************************************************************/
509 GroupButtons = new QGroupBox(this);
510 QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons);
511 aGroupButtonsLayout->setSpacing(SPACING);
512 aGroupButtonsLayout->setMargin(MARGIN);
514 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
515 buttonOk->setAutoDefault(true);
516 buttonOk->setDefault(true);
517 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
518 buttonApply->setAutoDefault(true);
519 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
520 buttonCancel->setAutoDefault(true);
521 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
522 buttonHelp->setAutoDefault(true);
524 aGroupButtonsLayout->addWidget(buttonOk);
525 aGroupButtonsLayout->addSpacing(10);
526 aGroupButtonsLayout->addWidget(buttonApply);
527 aGroupButtonsLayout->addSpacing(10);
528 aGroupButtonsLayout->addStretch();
529 aGroupButtonsLayout->addWidget(buttonCancel);
530 aGroupButtonsLayout->addWidget(buttonHelp);
532 /***************************************************************/
533 aDialogLayout->addWidget(GroupConstructors);
534 aDialogLayout->addWidget(GroupArguments);
535 aDialogLayout->addWidget(GroupButtons);
537 Init(); /* Initialisations */
540 //=================================================================================
541 // function : ~SMESHGUI_AddQuadraticElementDlg()
542 // purpose : Destroys the object and frees any allocated resources
543 //=================================================================================
544 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
549 //=================================================================================
552 //=================================================================================
553 void SMESHGUI_AddQuadraticElementDlg::Init()
555 myRadioButton1->setChecked(true);
556 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
566 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
571 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
573 case QUAD_QUADRANGLE:
576 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
578 case QUAD_TETRAHEDRON:
581 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
586 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
588 case QUAD_PENTAHEDRON:
591 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
593 case QUAD_HEXAHEDRON:
596 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
600 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, myNbCorners));
602 /* initialize table */
603 myTable->setColumnCount(3);
604 myTable->setRowCount(aNumRows);
606 QStringList aColLabels;
607 aColLabels.append(tr("SMESH_FIRST"));
608 aColLabels.append(tr("SMESH_MIDDLE"));
609 aColLabels.append(tr("SMESH_LAST"));
610 myTable->setHorizontalHeaderLabels(aColLabels);
612 for ( int col = 0; col < myTable->columnCount(); col++ )
613 myTable->setColumnWidth(col, 80);
615 //myTable->setColumnReadOnly(0, true); // VSR: TODO
616 //myTable->setColumnReadOnly(2, true); // VSR: TODO
618 myTable->setEnabled( false );
620 for ( int row = 0; row < myTable->rowCount(); row++ )
622 myTable->setItem( row, 0, new QTableWidgetItem( "" ) );
623 myTable->item( row, 0 )->setFlags(0);
625 IdEditItem* anEditItem = new IdEditItem( "" );
626 anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
627 myTable->setItem(row, 1, anEditItem);
629 myTable->setItem( row, 2, new QTableWidgetItem( "" ) );
630 myTable->item( row, 2 )->setFlags(0);
633 /* signals and slots connections */
634 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
635 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
636 connect(myTable, SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int)));
637 connect(myTable, SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int)));
638 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
639 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
641 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
642 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
643 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
644 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
646 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
647 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
649 // set selection mode
650 SMESH::SetPointRepresentation(true);
652 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
653 aViewWindow->SetSelectionMode( NodeSelection );
658 //=================================================================================
659 // function : ClickOnApply()
661 //=================================================================================
662 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
664 if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
667 BusyLocker lock( myBusy );
669 std::vector<vtkIdType> anIds;
673 anIds.push_back(myTable->item(0, 0)->text().toInt());
674 anIds.push_back(myTable->item(0, 2)->text().toInt());
675 anIds.push_back(myTable->item(0, 1)->text().toInt());
678 case QUAD_QUADRANGLE:
679 case QUAD_TETRAHEDRON:
681 case QUAD_PENTAHEDRON:
682 case QUAD_HEXAHEDRON:
683 for ( int row = 0; row < myNbCorners; row++ )
684 anIds.push_back(myTable->item(row, 0)->text().toInt());
685 for ( int row = 0; row < myTable->rowCount(); row++ )
686 anIds.push_back(myTable->item(row, 1)->text().toInt());
689 if ( myReverseCB->isChecked())
690 SMESH::ReverseConnectivity( anIds, myType );
692 int aNumberOfIds = anIds.size();
693 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
694 anArrayOfIdeces->length( aNumberOfIds );
696 for (int i = 0; i < aNumberOfIds; i++)
697 anArrayOfIdeces[i] = anIds[ i ];
699 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
702 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
704 case QUAD_QUADRANGLE:
705 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
706 case QUAD_TETRAHEDRON:
708 case QUAD_PENTAHEDRON:
709 case QUAD_HEXAHEDRON:
710 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
713 SALOME_ListIO aList; aList.Append( myActor->getIO() );
714 mySelector->ClearIndex();
715 mySelectionMgr->setSelectedObjects( aList, false );
717 mySimulation->SetVisibility(false);
726 //=================================================================================
727 // function : ClickOnOk()
729 //=================================================================================
730 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
736 //=================================================================================
737 // function : ClickOnCancel()
739 //=================================================================================
740 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
742 mySelectionMgr->clearSelected();
743 mySimulation->SetVisibility(false);
744 SMESH::SetPointRepresentation(false);
745 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
746 aViewWindow->SetSelectionMode( ActorSelection );
747 disconnect(mySelectionMgr, 0, this, 0);
748 mySMESHGUI->ResetState();
752 //=================================================================================
753 // function : ClickOnHelp()
755 //=================================================================================
756 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
758 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
760 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
764 platform = "winapplication";
766 platform = "application";
768 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
769 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
770 arg(app->resourceMgr()->stringValue("ExternalBrowser",
772 arg(myHelpFileName));
776 //=================================================================================
777 // function : onTextChange()
779 //=================================================================================
780 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
783 BusyLocker lock( myBusy );
785 mySimulation->SetVisibility(false);
787 // hilight entered nodes
788 SMDS_Mesh* aMesh = 0;
790 aMesh = myActor->GetObject()->GetMesh();
793 TColStd_MapOfInteger newIndices;
795 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
797 for (int i = 0; i < aListId.count(); i++) {
798 if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
800 newIndices.Add( n->GetID() );
809 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
810 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
811 aViewWindow->highlight( myActor->getIO(), true, true );
813 if ( sender() == myCornerNodes )
814 UpdateTable( allOk );
821 //=================================================================================
822 // function : SelectionIntoArgument()
823 // purpose : Called when selection has changed
824 //=================================================================================
825 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
828 BusyLocker lock( myBusy );
830 if ( myIsEditCorners )
835 myCornerNodes->setText("");
837 if (!GroupButtons->isEnabled()) // inactive
840 mySimulation->SetVisibility(false);
844 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
846 if (aList.Extent() != 1)
853 Handle(SALOME_InteractiveObject) anIO = aList.First();
854 myMesh = SMESH::GetMeshByIO(anIO);
855 if (myMesh->_is_nil()) {
860 myActor = SMESH::FindActorByEntry(anIO->getEntry());
869 // get selected nodes
870 QString aString = "";
871 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
873 if ( myIsEditCorners )
875 myCornerNodes->setText(aString);
879 else if ( myTable->isEnabled() && nbNodes == 1 )
881 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
883 myTable->item(theRow, 1)->setText(aString);
890 //=================================================================================
891 // function : displaySimulation()
893 //=================================================================================
894 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
898 SMESH::TElementSimulation::TVTKIds anIds;
900 // Collect ids from the dialog
903 int aDisplayMode = VTK_SURFACE;
905 if ( myType == QUAD_EDGE )
907 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) );
908 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) );
909 anID = myTable->item(0, 1)->text().toInt(&ok);
910 if (!ok) anID = myTable->item(0, 0)->text().toInt();
911 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
912 aDisplayMode = VTK_WIREFRAME;
916 for ( int row = 0; row < myNbCorners; row++ )
917 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) );
919 for ( int row = 0; row < myTable->rowCount(); row++ )
921 anID = myTable->item(row, 1)->text().toInt(&ok);
923 anID = myTable->item(row, 0)->text().toInt();
924 aDisplayMode = VTK_WIREFRAME;
926 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
930 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
934 mySimulation->SetVisibility(false);
939 //=================================================================================
940 // function : SetEditCorners()
942 //=================================================================================
943 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
945 myCornerNodes->setFocus();
946 myIsEditCorners = true;
947 SelectionIntoArgument();
951 //=================================================================================
952 // function : DeactivateActiveDialog()
954 //=================================================================================
955 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
957 if (GroupConstructors->isEnabled()) {
958 GroupConstructors->setEnabled(false);
959 GroupArguments->setEnabled(false);
960 GroupButtons->setEnabled(false);
961 mySimulation->SetVisibility(false);
962 mySMESHGUI->ResetState();
963 mySMESHGUI->SetActiveDialogBox(0);
967 //=================================================================================
968 // function : ActivateThisDialog()
970 //=================================================================================
971 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
973 /* Emit a signal to deactivate the active dialog */
974 mySMESHGUI->EmitSignalDeactivateDialog();
976 GroupConstructors->setEnabled(true);
977 GroupArguments->setEnabled(true);
978 GroupButtons->setEnabled(true);
980 SMESH::SetPointRepresentation(true);
982 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
983 aViewWindow->SetSelectionMode( NodeSelection );
984 SelectionIntoArgument();
987 //=================================================================================
988 // function : enterEvent()
990 //=================================================================================
991 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
993 if (GroupConstructors->isEnabled())
995 ActivateThisDialog();
998 //=================================================================================
999 // function : closeEvent()
1001 //=================================================================================
1002 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
1004 /* same than click on cancel button */
1008 //=================================================================================
1009 // function : hideEvent()
1010 // purpose : caused by ESC key
1011 //=================================================================================
1012 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
1018 //=================================================================================
1019 // function : onReverse()
1021 //=================================================================================
1022 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
1024 mySimulation->SetVisibility(false);
1025 displaySimulation();
1030 //=================================================================================
1031 // function : IsValid()
1033 //=================================================================================
1034 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
1036 SMDS_Mesh* aMesh = 0;
1038 aMesh = myActor->GetObject()->GetMesh();
1044 for ( int row = 0; row < myTable->rowCount(); row++ )
1046 int anID = myTable->item(row, 1)->text().toInt(&ok);
1050 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1058 //=================================================================================
1059 // function : UpdateTable()
1061 //=================================================================================
1062 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1064 QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
1066 if ( aListCorners.count() == myNbCorners && theConersValidity )
1068 myTable->setEnabled( true );
1070 // clear the Middle column
1071 for ( int row = 0; row < myTable->rowCount(); row++ )
1072 myTable->item( row, 1 )->setText("");
1079 aFirstColIds = FirstEdgeIds;
1080 aLastColIds = LastEdgeIds;
1083 aFirstColIds = FirstTriangleIds;
1084 aLastColIds = LastTriangleIds;
1086 case QUAD_QUADRANGLE:
1087 aFirstColIds = FirstQuadrangleIds;
1088 aLastColIds = LastQuadrangleIds;
1090 case QUAD_TETRAHEDRON:
1091 aFirstColIds = FirstTetrahedronIds;
1092 aLastColIds = LastTetrahedronIds;
1095 aFirstColIds = FirstPyramidIds;
1096 aLastColIds = LastPyramidIds;
1098 case QUAD_PENTAHEDRON:
1099 aFirstColIds = FirstPentahedronIds;
1100 aLastColIds = LastPentahedronIds;
1102 case QUAD_HEXAHEDRON:
1103 aFirstColIds = FirstHexahedronIds;
1104 aLastColIds = LastHexahedronIds;
1108 // fill the First and the Last columns
1109 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1110 myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] );
1112 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1113 myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] );
1118 for ( int row = 0; row < myTable->rowCount(); row++ )
1119 for ( int col = 0; col < myTable->columnCount(); col++ )
1120 if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText("");
1122 myTable->setEnabled( false );
1127 //=================================================================================
1128 // function : onTableActivate()
1130 //=================================================================================
1131 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
1133 myIsEditCorners = false;
1134 displaySimulation();
1139 //=================================================================================
1140 // function : onCellTextChange()
1142 //=================================================================================
1143 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1145 myIsEditCorners = false;
1146 displaySimulation();
1150 //=================================================================================
1151 // function : keyPressEvent()
1153 //=================================================================================
1154 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1156 QDialog::keyPressEvent( e );
1157 if ( e->isAccepted() )
1160 if ( e->key() == Qt::Key_F1 ) {
1166 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
1168 bool valid = IsValid();
1169 buttonOk->setEnabled( valid );
1170 buttonApply->setEnabled( valid );