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 #include "SMESHGUI_AddQuadraticElementDlg.h"
25 #include "SMESHGUI_Utils.h"
26 #include "SMESHGUI_VTKUtils.h"
27 #include "SMESHGUI_MeshUtils.h"
28 #include "SMESHGUI_IdValidator.h"
29 #include "SMESH_ActorUtils.h"
31 #include "SMDS_Mesh.hxx"
32 #include "SMESH_Actor.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_MessageBox.h"
36 #include "LightApp_Application.h"
38 #include "SVTK_Selection.h"
39 #include "SVTK_Selector.h"
40 #include "SALOME_ListIO.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "SalomeApp_Study.h"
44 #include "SalomeApp_Application.h"
46 #include "SVTK_ViewModel.h"
47 #include "SVTK_ViewWindow.h"
49 #include "utilities.h"
51 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_IndexedMapOfInteger.hxx>
59 #include <vtkIdList.h>
60 #include <vtkIntArray.h>
61 #include <vtkCellArray.h>
62 #include <vtkUnsignedCharArray.h>
63 #include <vtkUnstructuredGrid.h>
64 #include <vtkDataSetMapper.h>
65 #include <vtkProperty.h>
67 #include <vtkQuadraticEdge.h>
68 #include <vtkQuadraticTriangle.h>
69 #include <vtkQuadraticQuad.h>
70 #include <vtkQuadraticHexahedron.h>
71 #include <vtkQuadraticTetra.h>
74 #include <qbuttongroup.h>
75 #include <qgroupbox.h>
77 #include <qlineedit.h>
78 #include <qpushbutton.h>
79 #include <qradiobutton.h>
82 #include <qcheckbox.h>
91 void ReverseConnectivity( vector<vtkIdType> & ids, int type )
93 // for reverse connectivity of other types keeping the first id, see
94 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
98 case QUAD_TETRAHEDRON: {
99 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
104 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
108 case QUAD_PENTAHEDRON: {
109 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
113 case QUAD_HEXAHEDRON: {
114 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
119 static int aConn[] = {1,0,2};
123 case QUAD_TRIANGLE: {
124 static int aConn[] = {0,2,1,5,4,3};
128 case QUAD_QUADRANGLE: {
129 static int aConn[] = {0,3,2,1,7,6,5,4};
136 reverse( ids.begin(), ids.end() );
139 vector<vtkIdType> aRevIds( ids.size() );
140 for ( int i = 0; i < ids.size(); i++)
141 aRevIds[ i ] = ids[ conn[ i ]];
146 class TElementSimulation {
147 SalomeApp_Application* myApplication;
148 SUIT_ViewWindow* myViewWindow;
149 SVTK_ViewWindow* myVTKViewWindow;
151 SALOME_Actor* myPreviewActor;
152 vtkDataSetMapper* myMapper;
153 vtkUnstructuredGrid* myGrid;
154 //vtkProperty* myBackProp, *myProp;
156 vtkFloatingPointType myRGB[3], myBackRGB[3];
159 TElementSimulation (SalomeApp_Application* theApplication)
161 myApplication = theApplication;
162 SUIT_ViewManager* mgr = theApplication->activeViewManager();
164 myViewWindow = mgr->getActiveView();
165 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
167 myGrid = vtkUnstructuredGrid::New();
169 // Create and display actor
170 myMapper = vtkDataSetMapper::New();
171 myMapper->SetInput(myGrid);
173 myPreviewActor = SALOME_Actor::New();
174 myPreviewActor->PickableOff();
175 myPreviewActor->VisibilityOff();
176 myPreviewActor->SetMapper(myMapper);
178 vtkProperty* myProp = vtkProperty::New();
179 GetColor( "SMESH", "fill_color", myRGB[0], myRGB[1], myRGB[2], QColor( 0, 170, 255 ) );
180 myProp->SetColor( myRGB[0], myRGB[1], myRGB[2] );
181 myPreviewActor->SetProperty( myProp );
184 vtkProperty* myBackProp = vtkProperty::New();
185 GetColor( "SMESH", "backface_color", myBackRGB[0], myBackRGB[1], myBackRGB[2], QColor( 0, 0, 255 ) );
186 myBackProp->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
187 myPreviewActor->SetBackfaceProperty( myBackProp );
188 myBackProp->Delete();
190 myVTKViewWindow->AddActor(myPreviewActor);
193 typedef std::vector<vtkIdType> TVTKIds;
194 void SetPosition (SMESH_Actor* theActor,
198 const bool theReverse)
200 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
201 myGrid->SetPoints(aGrid->GetPoints());
209 aType = VTK_QUADRATIC_EDGE;
212 aType = VTK_QUADRATIC_TRIANGLE;
214 case QUAD_QUADRANGLE:
215 aType = VTK_QUADRATIC_QUAD;
217 case QUAD_TETRAHEDRON:
218 aType = VTK_QUADRATIC_TETRA;
221 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
222 aType = VTK_CONVEX_POINT_SET;
224 case QUAD_PENTAHEDRON:
225 aType = VTK_QUADRATIC_WEDGE;
226 //aType = VTK_CONVEX_POINT_SET;
228 case QUAD_HEXAHEDRON:
229 aType = VTK_QUADRATIC_HEXAHEDRON;
233 // take care of orientation
234 if ( aType == VTK_CONVEX_POINT_SET ) {
235 if ( theReverse && theMode == VTK_SURFACE ) {
236 //myPreviewActor->GetProperty()->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
240 // VTK cell connectivity opposites the MED one for volumic elements
241 if( aType != VTK_QUADRATIC_WEDGE) {
242 if ( theIds.size() > 8 ? !theReverse : theReverse ) {
243 ReverseConnectivity( theIds, theType );
247 ReverseConnectivity( theIds, theType );
251 vtkIdList *anIds = vtkIdList::New();
253 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
254 anIds->InsertId(i,theIds[i]);
255 //std::cout << i<< ": " << theIds[i] << std::endl;
258 myGrid->InsertNextCell(aType,anIds);
263 myPreviewActor->GetMapper()->Update();
264 myPreviewActor->SetRepresentation( theMode );
267 // restore normal orientation
268 if ( aType == VTK_CONVEX_POINT_SET ) {
269 if ( theReverse && theMode == VTK_SURFACE ) {
270 //myPreviewActor->GetProperty()->SetColor( myRGB[0], myRGB[1], myRGB[2] );
276 void SetVisibility (bool theVisibility)
278 myPreviewActor->SetVisibility(theVisibility);
279 RepaintCurrentView();
283 ~TElementSimulation()
285 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
286 myVTKViewWindow->RemoveActor(myPreviewActor);
288 myPreviewActor->Delete();
290 myMapper->RemoveAllInputs();
296 // myBackProp->Delete();
302 // Define the sequences of ids
303 static int FirstEdgeIds[] = {0};
304 static int LastEdgeIds[] = {1};
306 static int FirstTriangleIds[] = {0,1,2};
307 static int LastTriangleIds[] = {1,2,0};
309 static int FirstQuadrangleIds[] = {0,1,2,3};
310 static int LastQuadrangleIds[] = {1,2,3,0};
312 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
313 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
315 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
316 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
318 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
319 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
321 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
322 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
327 \brief Simple 'busy state' flag locker.
334 //! Constructor. Sets passed boolean flag to \c true.
335 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
336 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
337 ~BusyLocker() { myBusy = false; }
339 bool& myBusy; //! External 'busy state' boolean flag
344 \brief Simple editable table item.
348 class IdEditItem: public QTableItem
351 IdEditItem(QTable*, EditType, const QString& );
354 QWidget* createEditor() const;
358 IdEditItem::IdEditItem(QTable* table, EditType et, const QString& text )
359 : QTableItem( table, et, text )
363 IdEditItem::~IdEditItem()
367 QWidget* IdEditItem::createEditor() const
369 QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
370 aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );
374 //=================================================================================
375 // function : SMESHGUI_AddQuadraticElementDlg()
376 // purpose : constructor
377 //=================================================================================
378 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
381 bool modal, WFlags fl)
382 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
383 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
384 mySMESHGUI( theModule ),
385 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
389 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
390 (SUIT_Session::session()->activeApplication());
392 mySimulation = new SMESH::TElementSimulation (anApp);
393 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
395 QString anElementName;
399 anElementName = QString("QUADRATIC_EDGE");
402 anElementName = QString("QUADRATIC_TRIANGLE");
404 case QUAD_QUADRANGLE:
405 anElementName = QString("QUADRATIC_QUADRANGLE");
407 case QUAD_TETRAHEDRON:
408 anElementName = QString("QUADRATIC_TETRAHEDRON");
411 anElementName = QString("QUADRATIC_PYRAMID");
413 case QUAD_PENTAHEDRON:
414 anElementName = QString("QUADRATIC_PENTAHEDRON");
416 case QUAD_HEXAHEDRON:
417 anElementName = QString("QUADRATIC_HEXAHEDRON");
421 anElementName = QString("QUADRATIC_EDGE");
424 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName));
425 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName));
426 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName));
427 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName));
429 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
430 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
433 setName("SMESHGUI_AddQuadraticElementDlg");
436 setSizeGripEnabled(TRUE);
437 QGridLayout* aDialogLayout = new QGridLayout(this);
438 aDialogLayout->setSpacing(6);
439 aDialogLayout->setMargin(11);
441 /***************************************************************/
442 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
443 GroupConstructors->setTitle(constructorGrTitle);
445 GroupConstructors->setExclusive(TRUE);
446 GroupConstructors->setColumnLayout(0, Qt::Vertical);
447 GroupConstructors->layout()->setSpacing(0);
448 GroupConstructors->layout()->setMargin(0);
449 GroupConstructors->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
450 QGridLayout* aGroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
451 aGroupConstructorsLayout->setAlignment(Qt::AlignTop);
452 aGroupConstructorsLayout->setSpacing(6);
453 aGroupConstructorsLayout->setMargin(11);
454 myRadioButton1 = new QRadioButton(GroupConstructors, "myRadioButton1");
455 myRadioButton1->setText(tr("" ));
456 myRadioButton1->setPixmap(image0);
457 myRadioButton1->setChecked(TRUE);
458 myRadioButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, myRadioButton1->sizePolicy().hasHeightForWidth()));
459 aGroupConstructorsLayout->addWidget(myRadioButton1, 0, 0);
460 aGroupConstructorsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
461 aDialogLayout->addWidget(GroupConstructors, 0, 0);
463 /***************************************************************/
464 GroupArguments = new QGroupBox(this, "GroupArguments");
465 GroupArguments->setTitle(argumentsGrTitle);
466 GroupArguments->setColumnLayout(0, Qt::Vertical);
467 GroupArguments->layout()->setSpacing(0);
468 GroupArguments->layout()->setMargin(0);
469 GroupArguments->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding));
470 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
471 aGroupArgumentsLayout->setAlignment(Qt::AlignTop);
472 aGroupArgumentsLayout->setSpacing(6);
473 aGroupArgumentsLayout->setMargin(11);
474 QLabel* aCornerNodesLabel = new QLabel(GroupArguments, "aCornerNodesLabel");
475 aCornerNodesLabel->setText(tr("SMESH_CORNER_NODES" ));
476 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
477 mySelectButton = new QPushButton(GroupArguments, "mySelectButton");
478 mySelectButton->setPixmap(image1);
479 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
480 myCornerNodes = new QLineEdit(GroupArguments, "myCornerNodes");
481 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
483 myTable = new QTable(GroupArguments);
484 aGroupArgumentsLayout->addMultiCellWidget(myTable, 1, 1, 0, 2);
486 myReverseCB = new QCheckBox(GroupArguments, "myReverseCB");
487 myReverseCB->setText(tr("SMESH_REVERSE" ));
488 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0);
490 aDialogLayout->addWidget(GroupArguments, 1, 0);
493 /***************************************************************/
494 GroupButtons = new QGroupBox(this, "GroupButtons");
495 GroupButtons->setColumnLayout(0, Qt::Vertical);
496 GroupButtons->layout()->setSpacing(0);
497 GroupButtons->layout()->setMargin(0);
498 GroupButtons->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
499 QGridLayout* aGroupButtonsLayout = new QGridLayout(GroupButtons->layout());
500 aGroupButtonsLayout->setAlignment(Qt::AlignTop);
501 aGroupButtonsLayout->setSpacing(6);
502 aGroupButtonsLayout->setMargin(11);
503 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
504 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
505 buttonCancel->setAutoDefault(TRUE);
506 aGroupButtonsLayout->addWidget(buttonCancel, 0, 3);
507 buttonApply = new QPushButton(GroupButtons, "buttonApply");
508 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
509 buttonApply->setAutoDefault(TRUE);
510 aGroupButtonsLayout->addWidget(buttonApply, 0, 1);
511 aGroupButtonsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
512 buttonOk = new QPushButton(GroupButtons, "buttonOk");
513 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
514 buttonOk->setAutoDefault(TRUE);
515 buttonOk->setDefault(TRUE);
516 aGroupButtonsLayout->addWidget(buttonOk, 0, 0);
517 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
518 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
519 buttonHelp->setAutoDefault(TRUE);
520 aGroupButtonsLayout->addWidget(buttonHelp, 0, 4);
522 aDialogLayout->addWidget(GroupButtons, 2, 0);
524 Init(); /* Initialisations */
527 //=================================================================================
528 // function : ~SMESHGUI_AddQuadraticElementDlg()
529 // purpose : Destroys the object and frees any allocated resources
530 //=================================================================================
531 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
533 // no need to delete child widgets, Qt does it all for us
537 //=================================================================================
540 //=================================================================================
541 void SMESHGUI_AddQuadraticElementDlg::Init()
543 GroupArguments->show();
544 myRadioButton1->setChecked(TRUE);
545 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
555 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
560 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
562 case QUAD_QUADRANGLE:
565 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
567 case QUAD_TETRAHEDRON:
570 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
575 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
577 case QUAD_PENTAHEDRON:
580 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
582 case QUAD_HEXAHEDRON:
585 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
589 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, "validator", myNbCorners));
591 /* initialize table */
592 myTable->setNumCols(3);
593 myTable->setNumRows(aNumRows);
595 QStringList aColLabels;
596 aColLabels.append(tr("SMESH_FIRST"));
597 aColLabels.append(tr("SMESH_MIDDLE"));
598 aColLabels.append(tr("SMESH_LAST"));
599 myTable->setColumnLabels(aColLabels);
601 for ( int col = 0; col < myTable->numCols(); col++ )
602 myTable->setColumnWidth(col, 80);
604 myTable->setColumnReadOnly(0, true);
605 myTable->setColumnReadOnly(2, true);
607 myTable->setEnabled( false );
609 for ( int row = 0; row < myTable->numRows(); row++ )
611 IdEditItem* anEditItem = new IdEditItem( myTable, QTableItem::OnTyping, "" );
612 anEditItem->setReplaceable(true);
613 myTable->setItem(row, 1, anEditItem);
616 /* signals and slots connections */
617 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
618 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
619 connect(myTable, SIGNAL(doubleClicked(int, int, int, const QPoint&)), SLOT(onCellDoubleClicked(int, int, int, const QPoint&)));
620 connect(myTable, SIGNAL(valueChanged (int, int)), SLOT(onCellTextChange(int, int)));
621 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
622 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
624 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
625 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
626 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
627 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
629 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
630 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
632 this->show(); // displays Dialog
634 // set selection mode
635 SMESH::SetPointRepresentation(true);
637 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
638 aViewWindow->SetSelectionMode( NodeSelection );
643 //=================================================================================
644 // function : ClickOnApply()
646 //=================================================================================
647 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
649 if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
652 BusyLocker lock( myBusy );
654 vector<vtkIdType> anIds;
658 anIds.push_back(myTable->text(0, 0).toInt());
659 anIds.push_back(myTable->text(0, 2).toInt());
660 anIds.push_back(myTable->text(0, 1).toInt());
663 case QUAD_QUADRANGLE:
664 case QUAD_TETRAHEDRON:
666 case QUAD_PENTAHEDRON:
667 case QUAD_HEXAHEDRON:
668 for ( int row = 0; row < myNbCorners; row++ )
669 anIds.push_back(myTable->text(row, 0).toInt());
670 for ( int row = 0; row < myTable->numRows(); row++ )
671 anIds.push_back(myTable->text(row, 1).toInt());
674 if ( myReverseCB->isChecked())
675 SMESH::ReverseConnectivity( anIds, myType );
677 int aNumberOfIds = anIds.size();
678 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
679 anArrayOfIdeces->length( aNumberOfIds );
681 for (int i = 0; i < aNumberOfIds; i++)
682 anArrayOfIdeces[i] = anIds[ i ];
684 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
687 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
689 case QUAD_QUADRANGLE:
690 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
691 case QUAD_TETRAHEDRON:
693 case QUAD_PENTAHEDRON:
694 case QUAD_HEXAHEDRON:
695 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
698 SALOME_ListIO aList; aList.Append( myActor->getIO() );
699 mySelector->ClearIndex();
700 mySelectionMgr->setSelectedObjects( aList, false );
702 mySimulation->SetVisibility(false);
711 //=================================================================================
712 // function : ClickOnOk()
714 //=================================================================================
715 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
721 //=================================================================================
722 // function : ClickOnCancel()
724 //=================================================================================
725 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
727 mySelectionMgr->clearSelected();
728 mySimulation->SetVisibility(false);
729 SMESH::SetPointRepresentation(false);
730 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
731 aViewWindow->SetSelectionMode( ActorSelection );
732 disconnect(mySelectionMgr, 0, this, 0);
733 mySMESHGUI->ResetState();
737 //=================================================================================
738 // function : ClickOnHelp()
740 //=================================================================================
741 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
743 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
745 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
749 platform = "winapplication";
751 platform = "application";
753 SUIT_MessageBox::warn1(this, QObject::tr("WRN_WARNING"),
754 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
755 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
756 QObject::tr("BUT_OK"));
760 //=================================================================================
761 // function : onTextChange()
763 //=================================================================================
764 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
767 BusyLocker lock( myBusy );
769 mySimulation->SetVisibility(false);
771 // hilight entered nodes
772 SMDS_Mesh* aMesh = 0;
774 aMesh = myActor->GetObject()->GetMesh();
777 TColStd_MapOfInteger newIndices;
779 QStringList aListId = QStringList::split(" ", theNewText, false);
781 for (int i = 0; i < aListId.count(); i++) {
782 if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
784 newIndices.Add( n->GetID() );
793 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
794 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
795 aViewWindow->highlight( myActor->getIO(), true, true );
797 if ( sender() == myCornerNodes )
798 UpdateTable( allOk );
805 //=================================================================================
806 // function : SelectionIntoArgument()
807 // purpose : Called when selection has changed
808 //=================================================================================
809 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
812 BusyLocker lock( myBusy );
814 if ( myIsEditCorners )
819 myCornerNodes->setText("");
821 if (!GroupButtons->isEnabled()) // inactive
824 mySimulation->SetVisibility(false);
828 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
830 if (aList.Extent() != 1)
837 Handle(SALOME_InteractiveObject) anIO = aList.First();
838 myMesh = SMESH::GetMeshByIO(anIO);
839 if (myMesh->_is_nil()) {
844 myActor = SMESH::FindActorByEntry(anIO->getEntry());
853 // get selected nodes
854 QString aString = "";
855 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
857 if ( myIsEditCorners )
859 myCornerNodes->setText(aString);
863 else if ( myTable->isEnabled() && nbNodes == 1 )
865 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
867 myTable->setText(theRow, 1, aString);
874 //=================================================================================
875 // function : displaySimulation()
877 //=================================================================================
878 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
882 SMESH::TElementSimulation::TVTKIds anIds;
884 // Collect ids from the dialog
887 int aDisplayMode = VTK_SURFACE;
889 if ( myType == QUAD_EDGE )
891 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) );
892 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
893 anID = (myTable->text(0, 1)).toInt(&ok);
894 if (!ok) anID = (myTable->text(0, 0)).toInt();
895 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
896 aDisplayMode = VTK_WIREFRAME;
900 for ( int row = 0; row < myNbCorners; row++ )
901 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(row, 0).toInt() ) );
903 for ( int row = 0; row < myTable->numRows(); row++ )
905 anID = (myTable->text(row, 1)).toInt(&ok);
907 anID = (myTable->text(row, 0)).toInt();
908 aDisplayMode = VTK_WIREFRAME;
910 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
914 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
918 mySimulation->SetVisibility(false);
923 //=================================================================================
924 // function : SetEditCorners()
926 //=================================================================================
927 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
929 myCornerNodes->setFocus();
930 myIsEditCorners = true;
931 SelectionIntoArgument();
935 //=================================================================================
936 // function : DeactivateActiveDialog()
938 //=================================================================================
939 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
941 if (GroupConstructors->isEnabled()) {
942 GroupConstructors->setEnabled(false);
943 GroupArguments->setEnabled(false);
944 GroupButtons->setEnabled(false);
945 mySimulation->SetVisibility(false);
946 mySMESHGUI->ResetState();
947 mySMESHGUI->SetActiveDialogBox(0);
951 //=================================================================================
952 // function : ActivateThisDialog()
954 //=================================================================================
955 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
957 /* Emit a signal to deactivate the active dialog */
958 mySMESHGUI->EmitSignalDeactivateDialog();
960 GroupConstructors->setEnabled(true);
961 GroupArguments->setEnabled(true);
962 GroupButtons->setEnabled(true);
964 SMESH::SetPointRepresentation(true);
966 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
967 aViewWindow->SetSelectionMode( NodeSelection );
968 SelectionIntoArgument();
971 //=================================================================================
972 // function : enterEvent()
974 //=================================================================================
975 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
977 if (GroupConstructors->isEnabled())
979 ActivateThisDialog();
982 //=================================================================================
983 // function : closeEvent()
985 //=================================================================================
986 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
988 /* same than click on cancel button */
992 //=================================================================================
993 // function : hideEvent()
994 // purpose : caused by ESC key
995 //=================================================================================
996 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
1002 //=================================================================================
1003 // function : onReverse()
1005 //=================================================================================
1006 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
1008 mySimulation->SetVisibility(false);
1009 displaySimulation();
1014 //=================================================================================
1015 // function : IsValid()
1017 //=================================================================================
1018 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
1020 SMDS_Mesh* aMesh = 0;
1022 aMesh = myActor->GetObject()->GetMesh();
1028 for ( int row = 0; row < myTable->numRows(); row++ )
1030 int anID = (myTable->text(row, 1)).toInt(&ok);
1034 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1042 //=================================================================================
1043 // function : UpdateTable()
1045 //=================================================================================
1046 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1048 QStringList aListCorners = QStringList::split(" ", myCornerNodes->text(), false);
1050 if ( aListCorners.count() == myNbCorners && theConersValidity )
1052 myTable->setEnabled( true );
1054 // clear the Middle column
1055 for ( int row = 0; row < myTable->numRows(); row++ )
1056 myTable->setText( row, 1, "");
1063 aFirstColIds = FirstEdgeIds;
1064 aLastColIds = LastEdgeIds;
1067 aFirstColIds = FirstTriangleIds;
1068 aLastColIds = LastTriangleIds;
1070 case QUAD_QUADRANGLE:
1071 aFirstColIds = FirstQuadrangleIds;
1072 aLastColIds = LastQuadrangleIds;
1074 case QUAD_TETRAHEDRON:
1075 aFirstColIds = FirstTetrahedronIds;
1076 aLastColIds = LastTetrahedronIds;
1079 aFirstColIds = FirstPyramidIds;
1080 aLastColIds = LastPyramidIds;
1082 case QUAD_PENTAHEDRON:
1083 aFirstColIds = FirstPentahedronIds;
1084 aLastColIds = LastPentahedronIds;
1086 case QUAD_HEXAHEDRON:
1087 aFirstColIds = FirstHexahedronIds;
1088 aLastColIds = LastHexahedronIds;
1092 // fill the First and the Last columns
1093 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
1094 myTable->setText( i, 0, aListCorners[ aFirstColIds[i] ] );
1096 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
1097 myTable->setText( i, 2, aListCorners[ aLastColIds[i] ] );
1102 for ( int row = 0; row < myTable->numRows(); row++ )
1103 for ( int col = 0; col < myTable->numCols(); col++ )
1104 myTable->setText(row, col, "");
1106 myTable->setEnabled( false );
1111 //=================================================================================
1112 // function : onTableActivate()
1114 //=================================================================================
1115 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol, int theButton, const QPoint& theMousePos )
1117 myIsEditCorners = false;
1118 displaySimulation();
1123 //=================================================================================
1124 // function : onCellTextChange()
1126 //=================================================================================
1127 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1129 myIsEditCorners = false;
1130 displaySimulation();
1135 //=================================================================================
1136 // function : keyPressEvent()
1138 //=================================================================================
1139 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1141 QDialog::keyPressEvent( e );
1142 if ( e->isAccepted() )
1145 if ( e->key() == Key_F1 )
1152 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
1154 bool valid = IsValid();
1155 buttonOk->setEnabled( valid );
1156 buttonApply->setEnabled( valid );