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_GroupUtils.h"
34 #include "SMESHGUI_IdValidator.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_ActorUtils.h>
38 #include <SMESH_FaceOrientationFilter.h>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_ViewManager.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
55 #include <SalomeApp_Application.h>
58 #include <SALOMEconfig.h>
59 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
62 #include <TColStd_MapOfInteger.hxx>
65 #include <vtkIdList.h>
66 #include <vtkUnstructuredGrid.h>
67 #include <vtkDataSetMapper.h>
68 #include <vtkPolyDataMapper.h>
69 #include <vtkProperty.h>
70 #include <vtkCellType.h>
77 #include <QPushButton>
78 #include <QRadioButton>
79 #include <QVBoxLayout>
80 #include <QHBoxLayout>
81 #include <QGridLayout>
83 #include <QTableWidget>
85 #include <QButtonGroup>
95 void ReverseConnectivity( std::vector<vtkIdType> & ids, int type )
97 // for reverse connectivity of other types keeping the first id, see
98 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
102 case QUAD_TETRAHEDRON: {
103 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
108 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
112 case QUAD_PENTAHEDRON: {
113 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
117 case QUAD_HEXAHEDRON: {
118 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
123 static int aConn[] = {1,0,2};
127 case QUAD_TRIANGLE: {
128 static int aConn[] = {0,2,1,5,4,3};
132 case QUAD_QUADRANGLE: {
133 static int aConn[] = {0,3,2,1,7,6,5,4};
140 reverse( ids.begin(), ids.end() );
143 std::vector<vtkIdType> aRevIds( ids.size() );
144 for ( int i = 0; i < ids.size(); i++)
145 aRevIds[ i ] = ids[ conn[ i ]];
150 class TElementSimulation {
151 SalomeApp_Application* myApplication;
152 SUIT_ViewWindow* myViewWindow;
153 SVTK_ViewWindow* myVTKViewWindow;
155 SALOME_Actor* myPreviewActor;
156 vtkDataSetMapper* myMapper;
157 vtkUnstructuredGrid* myGrid;
158 //vtkProperty* myBackProp, *myProp;
160 //vtkFloatingPointType myRGB[3], myBackRGB[3];
162 SALOME_Actor* myFaceOrientation;
163 vtkPolyDataMapper* myFaceOrientationDataMapper;
164 SMESH_FaceOrientationFilter* myFaceOrientationFilter;
167 TElementSimulation (SalomeApp_Application* theApplication)
169 myApplication = theApplication;
170 SUIT_ViewManager* mgr = theApplication->activeViewManager();
172 myViewWindow = mgr->getActiveView();
173 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
175 myGrid = vtkUnstructuredGrid::New();
177 // Create and display actor
178 myMapper = vtkDataSetMapper::New();
179 myMapper->SetInput(myGrid);
181 myPreviewActor = SALOME_Actor::New();
182 myPreviewActor->PickableOff();
183 myPreviewActor->VisibilityOff();
184 myPreviewActor->SetMapper(myMapper);
186 vtkProperty* myProp = vtkProperty::New();
187 vtkFloatingPointType aRGB[3], aBackRGB[3];
188 GetColor( "SMESH", "fill_color", aRGB[0], aRGB[1], aRGB[2], QColor( 0, 170, 255 ) );
189 myProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
190 myPreviewActor->SetProperty( myProp );
193 vtkProperty* myBackProp = vtkProperty::New();
194 GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
195 myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
196 myPreviewActor->SetBackfaceProperty( myBackProp );
197 myBackProp->Delete();
199 myVTKViewWindow->AddActor(myPreviewActor);
201 // Orientation of faces
202 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
203 myFaceOrientationFilter->SetInput(myGrid);
205 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
206 myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
208 myFaceOrientation = SALOME_Actor::New();
209 myFaceOrientation->PickableOff();
210 myFaceOrientation->VisibilityOff();
211 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
213 vtkProperty* anOrientationProp = vtkProperty::New();
214 GetColor( "SMESH", "orientation_color", aRGB[0], aRGB[1], aRGB[2], QColor( 255, 255, 255 ) );
215 anOrientationProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
216 myFaceOrientation->SetProperty( anOrientationProp );
217 anOrientationProp->Delete();
219 myVTKViewWindow->AddActor(myFaceOrientation);
222 typedef std::vector<vtkIdType> TVTKIds;
223 void SetPosition (SMESH_Actor* theActor,
227 const bool theReverse)
229 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
230 myGrid->SetPoints(aGrid->GetPoints());
238 aType = VTK_QUADRATIC_EDGE;
241 aType = VTK_QUADRATIC_TRIANGLE;
243 case QUAD_QUADRANGLE:
244 aType = VTK_QUADRATIC_QUAD;
246 case QUAD_TETRAHEDRON:
247 aType = VTK_QUADRATIC_TETRA;
250 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
251 aType = VTK_CONVEX_POINT_SET;
253 case QUAD_PENTAHEDRON:
254 aType = VTK_QUADRATIC_WEDGE;
255 //aType = VTK_CONVEX_POINT_SET;
257 case QUAD_HEXAHEDRON:
258 aType = VTK_QUADRATIC_HEXAHEDRON;
262 // take care of orientation
263 if ( aType == VTK_CONVEX_POINT_SET ) {
264 if ( theReverse && theMode == VTK_SURFACE ) {
265 //myPreviewActor->GetProperty()->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
269 // VTK cell connectivity opposites the MED one for volumic elements
270 if( aType != VTK_QUADRATIC_WEDGE) {
271 if ( theIds.size() > 8 ? !theReverse : theReverse ) {
272 ReverseConnectivity( theIds, theType );
276 ReverseConnectivity( theIds, theType );
280 vtkIdList *anIds = vtkIdList::New();
282 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
283 anIds->InsertId(i,theIds[i]);
284 //std::cout << i<< ": " << theIds[i] << std::endl;
287 myGrid->InsertNextCell(aType,anIds);
292 myPreviewActor->GetMapper()->Update();
293 myPreviewActor->SetRepresentation( theMode );
294 SetVisibility(true, theActor->GetFacesOriented());
296 // restore normal orientation
297 if ( aType == VTK_CONVEX_POINT_SET ) {
298 if ( theReverse && theMode == VTK_SURFACE ) {
299 //myPreviewActor->GetProperty()->SetColor( myRGB[0], myRGB[1], myRGB[2] );
305 void SetVisibility (bool theVisibility, bool theShowOrientation = false)
307 myPreviewActor->SetVisibility(theVisibility);
308 myFaceOrientation->SetVisibility(theShowOrientation);
309 RepaintCurrentView();
313 ~TElementSimulation()
315 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
316 myVTKViewWindow->RemoveActor(myPreviewActor);
317 myVTKViewWindow->RemoveActor(myFaceOrientation);
319 myPreviewActor->Delete();
320 myFaceOrientation->Delete();
322 myMapper->RemoveAllInputs();
325 myFaceOrientationFilter->Delete();
327 myFaceOrientationDataMapper->RemoveAllInputs();
328 myFaceOrientationDataMapper->Delete();
333 // myBackProp->Delete();
339 // Define the sequences of ids
340 static int FirstEdgeIds[] = {0};
341 static int LastEdgeIds[] = {1};
343 static int FirstTriangleIds[] = {0,1,2};
344 static int LastTriangleIds[] = {1,2,0};
346 static int FirstQuadrangleIds[] = {0,1,2,3};
347 static int LastQuadrangleIds[] = {1,2,3,0};
349 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
350 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
352 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
353 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
355 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
356 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
358 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
359 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
365 \brief Simple 'busy state' flag locker.
372 //! Constructor. Sets passed boolean flag to \c true.
373 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
374 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
375 ~BusyLocker() { myBusy = false; }
377 bool& myBusy; //! External 'busy state' boolean flag
382 \brief Simple editable table item.
386 class IdEditItem: public QTableWidgetItem
389 IdEditItem(const QString& text );
392 QWidget* createEditor() const;
395 IdEditItem::IdEditItem(const QString& text )
396 : QTableWidgetItem(text, QTableWidgetItem::UserType+100)
400 IdEditItem::~IdEditItem()
404 QWidget* IdEditItem::createEditor() const
406 QLineEdit *aLineEdit = new QLineEdit(text(), tableWidget());
407 aLineEdit->setValidator( new SMESHGUI_IdValidator(tableWidget(), 1) );
411 //=================================================================================
412 // function : SMESHGUI_AddQuadraticElementDlg()
413 // purpose : constructor
414 //=================================================================================
415 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
417 : QDialog( SMESH::GetDesktop( theModule ) ),
418 mySMESHGUI( theModule ),
419 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
424 setAttribute( Qt::WA_DeleteOnClose, true );
426 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
427 (SUIT_Session::session()->activeApplication());
429 mySimulation = new SMESH::TElementSimulation (anApp);
430 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
432 QString anElementName;
436 anElementName = QString("QUADRATIC_EDGE");
439 anElementName = QString("QUADRATIC_TRIANGLE");
441 case QUAD_QUADRANGLE:
442 anElementName = QString("QUADRATIC_QUADRANGLE");
444 case QUAD_TETRAHEDRON:
445 anElementName = QString("QUADRATIC_TETRAHEDRON");
448 anElementName = QString("QUADRATIC_PYRAMID");
450 case QUAD_PENTAHEDRON:
451 anElementName = QString("QUADRATIC_PENTAHEDRON");
453 case QUAD_HEXAHEDRON:
454 anElementName = QString("QUADRATIC_HEXAHEDRON");
458 anElementName = QString("QUADRATIC_EDGE");
461 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName).toLatin1().data());
462 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName).toLatin1().data());
463 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName).toLatin1().data());
464 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName).toLatin1().data());
466 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
467 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
469 setWindowTitle(caption);
471 setSizeGripEnabled(true);
473 QVBoxLayout* aDialogLayout = new QVBoxLayout(this);
474 aDialogLayout->setSpacing(SPACING);
475 aDialogLayout->setMargin(MARGIN);
477 /***************************************************************/
478 GroupConstructors = new QGroupBox(constructorGrTitle, this);
479 QButtonGroup* ButtonGroup = new QButtonGroup(this);
480 QHBoxLayout* aGroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
481 aGroupConstructorsLayout->setSpacing(SPACING);
482 aGroupConstructorsLayout->setMargin(MARGIN);
484 myRadioButton1 = new QRadioButton(GroupConstructors);
485 myRadioButton1->setIcon(image0);
486 aGroupConstructorsLayout->addWidget(myRadioButton1);
487 ButtonGroup->addButton(myRadioButton1, 0);
489 /***************************************************************/
490 GroupArguments = new QGroupBox(argumentsGrTitle, this);
491 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments);
492 aGroupArgumentsLayout->setSpacing(SPACING);
493 aGroupArgumentsLayout->setMargin(MARGIN);
495 QLabel* aCornerNodesLabel = new QLabel(tr("SMESH_CORNER_NODES"), GroupArguments);
496 mySelectButton = new QPushButton(GroupArguments);
497 mySelectButton->setIcon(image1);
498 myCornerNodes = new QLineEdit(GroupArguments);
500 myTable = new QTableWidget(GroupArguments);
502 myReverseCB = new QCheckBox(tr("SMESH_REVERSE"), GroupArguments);
504 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
505 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
506 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
507 aGroupArgumentsLayout->addWidget(myTable, 1, 0, 1, 3);
508 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0, 1, 3);
510 /***************************************************************/
511 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
512 GroupGroups->setCheckable( true );
513 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
514 GroupGroupsLayout->setSpacing(SPACING);
515 GroupGroupsLayout->setMargin(MARGIN);
517 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
518 ComboBox_GroupName = new QComboBox( GroupGroups );
519 ComboBox_GroupName->setEditable( true );
521 GroupGroupsLayout->addWidget( TextLabel_GroupName );
522 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
524 /***************************************************************/
525 GroupButtons = new QGroupBox(this);
526 QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons);
527 aGroupButtonsLayout->setSpacing(SPACING);
528 aGroupButtonsLayout->setMargin(MARGIN);
530 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
531 buttonOk->setAutoDefault(true);
532 buttonOk->setDefault(true);
533 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
534 buttonApply->setAutoDefault(true);
535 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
536 buttonCancel->setAutoDefault(true);
537 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
538 buttonHelp->setAutoDefault(true);
540 aGroupButtonsLayout->addWidget(buttonOk);
541 aGroupButtonsLayout->addSpacing(10);
542 aGroupButtonsLayout->addWidget(buttonApply);
543 aGroupButtonsLayout->addSpacing(10);
544 aGroupButtonsLayout->addStretch();
545 aGroupButtonsLayout->addWidget(buttonCancel);
546 aGroupButtonsLayout->addWidget(buttonHelp);
548 /***************************************************************/
549 aDialogLayout->addWidget(GroupConstructors);
550 aDialogLayout->addWidget(GroupArguments);
551 aDialogLayout->addWidget(GroupGroups);
552 aDialogLayout->addWidget(GroupButtons);
554 Init(); /* Initialisations */
557 //=================================================================================
558 // function : ~SMESHGUI_AddQuadraticElementDlg()
559 // purpose : Destroys the object and frees any allocated resources
560 //=================================================================================
561 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
566 //=================================================================================
569 //=================================================================================
570 void SMESHGUI_AddQuadraticElementDlg::Init()
572 myRadioButton1->setChecked(true);
573 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
575 /* reset "Add to group" control */
576 GroupGroups->setChecked( false );
586 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
591 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
593 case QUAD_QUADRANGLE:
596 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
598 case QUAD_TETRAHEDRON:
601 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
606 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
608 case QUAD_PENTAHEDRON:
611 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
613 case QUAD_HEXAHEDRON:
616 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
620 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, myNbCorners));
622 /* initialize table */
623 myTable->setColumnCount(3);
624 myTable->setRowCount(aNumRows);
626 QStringList aColLabels;
627 aColLabels.append(tr("SMESH_FIRST"));
628 aColLabels.append(tr("SMESH_MIDDLE"));
629 aColLabels.append(tr("SMESH_LAST"));
630 myTable->setHorizontalHeaderLabels(aColLabels);
632 for ( int col = 0; col < myTable->columnCount(); col++ )
633 myTable->setColumnWidth(col, 80);
635 //myTable->setColumnReadOnly(0, true); // VSR: TODO
636 //myTable->setColumnReadOnly(2, true); // VSR: TODO
638 myTable->setEnabled( false );
640 for ( int row = 0; row < myTable->rowCount(); row++ )
642 myTable->setItem( row, 0, new QTableWidgetItem( "" ) );
643 myTable->item( row, 0 )->setFlags(0);
645 IdEditItem* anEditItem = new IdEditItem( "" );
646 anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
647 myTable->setItem(row, 1, anEditItem);
649 myTable->setItem( row, 2, new QTableWidgetItem( "" ) );
650 myTable->item( row, 2 )->setFlags(0);
653 /* signals and slots connections */
654 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
655 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
656 connect(myTable, SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int)));
657 connect(myTable, SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int)));
658 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
659 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
661 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
662 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
663 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
664 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
666 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
667 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
669 // set selection mode
670 SMESH::SetPointRepresentation(true);
672 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
673 aViewWindow->SetSelectionMode( NodeSelection );
678 //=================================================================================
679 // function : ClickOnApply()
681 //=================================================================================
682 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
687 if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
690 BusyLocker lock( myBusy );
692 std::vector<vtkIdType> anIds;
696 anIds.push_back(myTable->item(0, 0)->text().toInt());
697 anIds.push_back(myTable->item(0, 2)->text().toInt());
698 anIds.push_back(myTable->item(0, 1)->text().toInt());
701 case QUAD_QUADRANGLE:
702 case QUAD_TETRAHEDRON:
704 case QUAD_PENTAHEDRON:
705 case QUAD_HEXAHEDRON:
706 for ( int row = 0; row < myNbCorners; row++ )
707 anIds.push_back(myTable->item(row, 0)->text().toInt());
708 for ( int row = 0; row < myTable->rowCount(); row++ )
709 anIds.push_back(myTable->item(row, 1)->text().toInt());
712 if ( myReverseCB->isChecked())
713 SMESH::ReverseConnectivity( anIds, myType );
715 int aNumberOfIds = anIds.size();
716 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
717 anArrayOfIdeces->length( aNumberOfIds );
719 for (int i = 0; i < aNumberOfIds; i++)
720 anArrayOfIdeces[i] = anIds[ i ];
722 SMESH::ElementType anElementType;
724 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
727 anElementType = SMESH::EDGE;
728 anElemId = aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
730 case QUAD_QUADRANGLE:
731 anElementType = SMESH::FACE;
732 anElemId = aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
733 case QUAD_TETRAHEDRON:
735 case QUAD_PENTAHEDRON:
736 case QUAD_HEXAHEDRON:
737 anElementType = SMESH::VOLUME;
738 anElemId = aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
741 if( anElemId != -1 && GroupGroups->isChecked() ) {
742 SMESH::SMESH_Group_var aGroup;
743 QString aGroupName = ComboBox_GroupName->currentText();
744 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
745 for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
746 SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i];
747 if( !aGroupBase->_is_nil() ) {
748 SMESH::SMESH_Group_var aRefGroup = SMESH::SMESH_Group::_narrow( aGroupBase );
749 if( !aRefGroup->_is_nil() ) {
750 QString aRefGroupName( aRefGroup->GetName() );
751 if( aRefGroupName == aGroupName ) {
752 aGroup = aRefGroup; // // add node to existing group
758 if( aGroup->_is_nil() ) // create new group
759 aGroup = SMESH::AddGroup( myMesh, anElementType, aGroupName );
761 if( !aGroup->_is_nil() ) {
762 SMESH::long_array_var anIdList = new SMESH::long_array;
763 anIdList->length( 1 );
764 anIdList[0] = anElemId;
765 aGroup->Add( anIdList.inout() );
769 SALOME_ListIO aList; aList.Append( myActor->getIO() );
770 mySelector->ClearIndex();
771 mySelectionMgr->setSelectedObjects( aList, false );
773 mySimulation->SetVisibility(false);
782 //=================================================================================
783 // function : ClickOnOk()
785 //=================================================================================
786 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
792 //=================================================================================
793 // function : ClickOnCancel()
795 //=================================================================================
796 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
798 mySelectionMgr->clearSelected();
799 mySimulation->SetVisibility(false);
800 SMESH::SetPointRepresentation(false);
801 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
802 aViewWindow->SetSelectionMode( ActorSelection );
803 disconnect(mySelectionMgr, 0, this, 0);
804 mySMESHGUI->ResetState();
808 //=================================================================================
809 // function : ClickOnHelp()
811 //=================================================================================
812 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
814 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
816 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
820 platform = "winapplication";
822 platform = "application";
824 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
825 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
826 arg(app->resourceMgr()->stringValue("ExternalBrowser",
828 arg(myHelpFileName));
832 //=================================================================================
833 // function : onTextChange()
835 //=================================================================================
836 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
839 BusyLocker lock( myBusy );
841 mySimulation->SetVisibility(false);
843 // hilight entered nodes
844 SMDS_Mesh* aMesh = 0;
846 aMesh = myActor->GetObject()->GetMesh();
849 TColStd_MapOfInteger newIndices;
851 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
853 for (int i = 0; i < aListId.count(); i++) {
854 if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
856 newIndices.Add( n->GetID() );
865 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
866 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
867 aViewWindow->highlight( myActor->getIO(), true, true );
869 if ( sender() == myCornerNodes )
870 UpdateTable( allOk );
877 //=================================================================================
878 // function : SelectionIntoArgument()
879 // purpose : Called when selection has changed
880 //=================================================================================
881 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
884 BusyLocker lock( myBusy );
886 QString aCurrentEntry = myEntry;
888 if ( myIsEditCorners )
893 myCornerNodes->setText("");
895 if (!GroupButtons->isEnabled()) // inactive
898 mySimulation->SetVisibility(false);
902 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
904 if (aList.Extent() != 1)
911 Handle(SALOME_InteractiveObject) anIO = aList.First();
912 myEntry = anIO->getEntry();
913 myMesh = SMESH::GetMeshByIO(anIO);
914 if (myMesh->_is_nil()) {
919 myActor = SMESH::FindActorByEntry(anIO->getEntry());
924 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
925 SMESH::ElementType anElementType;
928 anElementType = SMESH::EDGE; break;
930 case QUAD_QUADRANGLE:
931 anElementType = SMESH::FACE; break;
932 case QUAD_TETRAHEDRON:
934 case QUAD_PENTAHEDRON:
935 case QUAD_HEXAHEDRON:
936 anElementType = SMESH::VOLUME; break;
938 ComboBox_GroupName->clear();
939 ComboBox_GroupName->addItem( QString() );
940 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
941 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
942 SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i];
943 if ( !aGroupBase->_is_nil() && aGroupBase->GetType() == anElementType ) {
944 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupBase );
945 if ( !aGroup->_is_nil() ) {
946 QString aGroupName( aGroup->GetName() );
947 if ( !aGroupName.isEmpty() )
948 ComboBox_GroupName->addItem( aGroupName );
959 // get selected nodes
960 QString aString = "";
961 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
963 if ( myIsEditCorners )
965 myCornerNodes->setText(aString);
969 else if ( myTable->isEnabled() && nbNodes == 1 )
971 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
973 myTable->item(theRow, 1)->setText(aString);
980 //=================================================================================
981 // function : displaySimulation()
983 //=================================================================================
984 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
988 SMESH::TElementSimulation::TVTKIds anIds;
990 // Collect ids from the dialog
993 int aDisplayMode = VTK_SURFACE;
995 if ( myType == QUAD_EDGE )
997 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) );
998 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) );
999 anID = myTable->item(0, 1)->text().toInt(&ok);
1000 if (!ok) anID = myTable->item(0, 0)->text().toInt();
1001 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
1002 aDisplayMode = VTK_WIREFRAME;
1006 for ( int row = 0; row < myNbCorners; row++ )
1007 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) );
1009 for ( int row = 0; row < myTable->rowCount(); row++ )
1011 anID = myTable->item(row, 1)->text().toInt(&ok);
1013 anID = myTable->item(row, 0)->text().toInt();
1014 aDisplayMode = VTK_WIREFRAME;
1016 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
1020 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
1024 mySimulation->SetVisibility(false);
1026 SMESH::UpdateView();
1029 //=================================================================================
1030 // function : SetEditCorners()
1032 //=================================================================================
1033 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
1035 myCornerNodes->setFocus();
1036 myIsEditCorners = true;
1037 SelectionIntoArgument();
1041 //=================================================================================
1042 // function : DeactivateActiveDialog()
1044 //=================================================================================
1045 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
1047 if (GroupConstructors->isEnabled()) {
1048 GroupConstructors->setEnabled(false);
1049 GroupArguments->setEnabled(false);
1050 GroupButtons->setEnabled(false);
1051 mySimulation->SetVisibility(false);
1052 mySMESHGUI->ResetState();
1053 mySMESHGUI->SetActiveDialogBox(0);
1057 //=================================================================================
1058 // function : ActivateThisDialog()
1060 //=================================================================================
1061 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
1063 /* Emit a signal to deactivate the active dialog */
1064 mySMESHGUI->EmitSignalDeactivateDialog();
1066 GroupConstructors->setEnabled(true);
1067 GroupArguments->setEnabled(true);
1068 GroupButtons->setEnabled(true);
1070 SMESH::SetPointRepresentation(true);
1072 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1073 aViewWindow->SetSelectionMode( NodeSelection );
1074 SelectionIntoArgument();
1077 //=================================================================================
1078 // function : enterEvent()
1080 //=================================================================================
1081 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
1083 if (GroupConstructors->isEnabled())
1085 ActivateThisDialog();
1088 //=================================================================================
1089 // function : closeEvent()
1091 //=================================================================================
1092 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
1094 /* same than click on cancel button */
1098 //=================================================================================
1099 // function : hideEvent()
1100 // purpose : caused by ESC key
1101 //=================================================================================
1102 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
1108 //=================================================================================
1109 // function : onReverse()
1111 //=================================================================================
1112 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
1114 mySimulation->SetVisibility(false);
1115 displaySimulation();
1120 //=================================================================================
1121 // function : IsValid()
1123 //=================================================================================
1124 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
1126 SMDS_Mesh* aMesh = 0;
1128 aMesh = myActor->GetObject()->GetMesh();
1134 for ( int row = 0; row < myTable->rowCount(); row++ )
1136 int anID = myTable->item(row, 1)->text().toInt(&ok);
1140 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1148 //=================================================================================
1149 // function : UpdateTable()
1151 //=================================================================================
1152 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1154 QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
1156 if ( aListCorners.count() == myNbCorners && theConersValidity )
1158 myTable->setEnabled( true );
1160 // clear the Middle column
1161 for ( int row = 0; row < myTable->rowCount(); row++ )
1162 myTable->item( row, 1 )->setText("");
1169 aFirstColIds = FirstEdgeIds;
1170 aLastColIds = LastEdgeIds;
1173 aFirstColIds = FirstTriangleIds;
1174 aLastColIds = LastTriangleIds;
1176 case QUAD_QUADRANGLE:
1177 aFirstColIds = FirstQuadrangleIds;
1178 aLastColIds = LastQuadrangleIds;
1180 case QUAD_TETRAHEDRON:
1181 aFirstColIds = FirstTetrahedronIds;
1182 aLastColIds = LastTetrahedronIds;
1185 aFirstColIds = FirstPyramidIds;
1186 aLastColIds = LastPyramidIds;
1188 case QUAD_PENTAHEDRON:
1189 aFirstColIds = FirstPentahedronIds;
1190 aLastColIds = LastPentahedronIds;
1192 case QUAD_HEXAHEDRON:
1193 aFirstColIds = FirstHexahedronIds;
1194 aLastColIds = LastHexahedronIds;
1198 // fill the First and the Last columns
1199 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1200 myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] );
1202 for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1203 myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] );
1208 for ( int row = 0; row < myTable->rowCount(); row++ )
1209 for ( int col = 0; col < myTable->columnCount(); col++ )
1210 if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText("");
1212 myTable->setEnabled( false );
1217 //=================================================================================
1218 // function : onTableActivate()
1220 //=================================================================================
1221 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
1223 myIsEditCorners = false;
1224 displaySimulation();
1229 //=================================================================================
1230 // function : onCellTextChange()
1232 //=================================================================================
1233 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1235 myIsEditCorners = false;
1236 displaySimulation();
1240 //=================================================================================
1241 // function : keyPressEvent()
1243 //=================================================================================
1244 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1246 QDialog::keyPressEvent( e );
1247 if ( e->isAccepted() )
1250 if ( e->key() == Qt::Key_F1 ) {
1256 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
1258 bool valid = IsValid();
1259 buttonOk->setEnabled( valid );
1260 buttonApply->setEnabled( valid );
1263 //=================================================================================
1264 // function : isValid
1266 //=================================================================================
1267 bool SMESHGUI_AddQuadraticElementDlg::isValid()
1269 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
1270 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );