1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SMESHGUI_AddQuadraticElementDlg.h"
23 #include "SMESHGUI_Utils.h"
24 #include "SMESHGUI_VTKUtils.h"
25 #include "SMESHGUI_MeshUtils.h"
26 #include "SMESHGUI_IdValidator.h"
27 #include "SMESH_ActorUtils.h"
29 #include "SMDS_Mesh.hxx"
30 #include "SMESH_Actor.h"
32 #include "SUIT_Session.h"
33 #include "SUIT_MessageBox.h"
34 #include "LightApp_Application.h"
36 #include "SVTK_Selection.h"
37 #include "SVTK_Selector.h"
38 #include "SALOME_ListIO.hxx"
39 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "SalomeApp_Study.h"
42 #include "SalomeApp_Application.h"
44 #include "SVTK_ViewModel.h"
45 #include "SVTK_ViewWindow.h"
47 #include "utilities.h"
49 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
52 #include <TColStd_MapOfInteger.hxx>
53 #include <TColStd_IndexedMapOfInteger.hxx>
57 #include <vtkIdList.h>
58 #include <vtkIntArray.h>
59 #include <vtkCellArray.h>
60 #include <vtkUnsignedCharArray.h>
61 #include <vtkUnstructuredGrid.h>
62 #include <vtkDataSetMapper.h>
63 #include <vtkProperty.h>
65 #include <vtkQuadraticEdge.h>
66 #include <vtkQuadraticTriangle.h>
67 #include <vtkQuadraticQuad.h>
68 #include <vtkQuadraticHexahedron.h>
69 #include <vtkQuadraticTetra.h>
72 #include <qbuttongroup.h>
73 #include <qgroupbox.h>
75 #include <qlineedit.h>
76 #include <qpushbutton.h>
77 #include <qradiobutton.h>
80 #include <qcheckbox.h>
89 void ReverseConnectivity( vector<int> & ids, int type )
91 // for reverse connectivity of other types keeping the first id, see
92 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
96 case QUAD_TETRAHEDRON: {
97 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
102 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
106 case QUAD_PENTAHEDRON: {
107 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
111 case QUAD_HEXAHEDRON: {
112 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
117 static int aConn[] = {1,0,2};
121 case QUAD_TRIANGLE: {
122 static int aConn[] = {0,2,1,5,4,3};
126 case QUAD_QUADRANGLE: {
127 static int aConn[] = {0,3,2,1,7,6,5,4};
134 reverse( ids.begin(), ids.end() );
137 vector<int> aRevIds( ids.size() );
138 for ( int i = 0; i < ids.size(); i++)
139 aRevIds[ i ] = ids[ conn[ i ]];
144 class TElementSimulation {
145 SalomeApp_Application* myApplication;
146 SUIT_ViewWindow* myViewWindow;
147 SVTK_ViewWindow* myVTKViewWindow;
149 SALOME_Actor* myPreviewActor;
150 vtkDataSetMapper* myMapper;
151 vtkUnstructuredGrid* myGrid;
152 //vtkProperty* myBackProp, *myProp;
154 vtkFloatingPointType myRGB[3], myBackRGB[3];
157 TElementSimulation (SalomeApp_Application* theApplication)
159 myApplication = theApplication;
160 SUIT_ViewManager* mgr = theApplication->activeViewManager();
162 myViewWindow = mgr->getActiveView();
163 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
165 myGrid = vtkUnstructuredGrid::New();
167 // Create and display actor
168 myMapper = vtkDataSetMapper::New();
169 myMapper->SetInput(myGrid);
171 myPreviewActor = SALOME_Actor::New();
172 myPreviewActor->PickableOff();
173 myPreviewActor->VisibilityOff();
174 myPreviewActor->SetMapper(myMapper);
176 vtkProperty* myProp = vtkProperty::New();
177 GetColor( "SMESH", "fill_color", myRGB[0], myRGB[1], myRGB[2], QColor( 0, 170, 255 ) );
178 myProp->SetColor( myRGB[0], myRGB[1], myRGB[2] );
179 myPreviewActor->SetProperty( myProp );
182 vtkProperty* myBackProp = vtkProperty::New();
183 GetColor( "SMESH", "backface_color", myBackRGB[0], myBackRGB[1], myBackRGB[2], QColor( 0, 0, 255 ) );
184 myBackProp->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
185 myPreviewActor->SetBackfaceProperty( myBackProp );
186 myBackProp->Delete();
188 myVTKViewWindow->AddActor(myPreviewActor);
191 typedef std::vector<vtkIdType> TVTKIds;
192 void SetPosition (SMESH_Actor* theActor,
196 const bool theReverse)
198 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
199 myGrid->SetPoints(aGrid->GetPoints());
207 aType = VTK_QUADRATIC_EDGE;
210 aType = VTK_QUADRATIC_TRIANGLE;
212 case QUAD_QUADRANGLE:
213 aType = VTK_QUADRATIC_QUAD;
215 case QUAD_TETRAHEDRON:
216 aType = VTK_QUADRATIC_TETRA;
219 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
220 aType = VTK_CONVEX_POINT_SET;
222 case QUAD_PENTAHEDRON:
223 aType = VTK_QUADRATIC_WEDGE;
224 //aType = VTK_CONVEX_POINT_SET;
226 case QUAD_HEXAHEDRON:
227 aType = VTK_QUADRATIC_HEXAHEDRON;
231 // take care of orientation
232 if ( aType == VTK_CONVEX_POINT_SET ) {
233 if ( theReverse && theMode == VTK_SURFACE ) {
234 //myPreviewActor->GetProperty()->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
238 // VTK cell connectivity opposites the MED one for volumic elements
239 if( aType != VTK_QUADRATIC_WEDGE) {
240 if ( theIds.size() > 8 ? !theReverse : theReverse ) {
241 ReverseConnectivity( theIds, theType );
245 ReverseConnectivity( theIds, theType );
249 vtkIdList *anIds = vtkIdList::New();
251 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
252 anIds->InsertId(i,theIds[i]);
253 //std::cout << i<< ": " << theIds[i] << std::endl;
256 myGrid->InsertNextCell(aType,anIds);
261 myPreviewActor->GetMapper()->Update();
262 myPreviewActor->SetRepresentation( theMode );
265 // restore normal orientation
266 if ( aType == VTK_CONVEX_POINT_SET ) {
267 if ( theReverse && theMode == VTK_SURFACE ) {
268 //myPreviewActor->GetProperty()->SetColor( myRGB[0], myRGB[1], myRGB[2] );
274 void SetVisibility (bool theVisibility)
276 myPreviewActor->SetVisibility(theVisibility);
277 RepaintCurrentView();
281 ~TElementSimulation()
283 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
284 myVTKViewWindow->RemoveActor(myPreviewActor);
286 myPreviewActor->Delete();
288 myMapper->RemoveAllInputs();
294 // myBackProp->Delete();
300 // Define the sequences of ids
301 static int FirstEdgeIds[] = {0};
302 static int LastEdgeIds[] = {1};
304 static int FirstTriangleIds[] = {0,1,2};
305 static int LastTriangleIds[] = {1,2,0};
307 static int FirstQuadrangleIds[] = {0,1,2,3};
308 static int LastQuadrangleIds[] = {1,2,3,0};
310 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
311 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
313 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
314 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
316 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
317 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
319 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
320 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
325 \brief Simple 'busy state' flag locker.
332 //! Constructor. Sets passed boolean flag to \c true.
333 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
334 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
335 ~BusyLocker() { myBusy = false; }
337 bool& myBusy; //! External 'busy state' boolean flag
342 \brief Simple editable table item.
346 class IdEditItem: public QTableItem
349 IdEditItem(QTable*, EditType, const QString& );
352 QWidget* createEditor() const;
356 IdEditItem::IdEditItem(QTable* table, EditType et, const QString& text )
357 : QTableItem( table, et, text )
361 IdEditItem::~IdEditItem()
365 QWidget* IdEditItem::createEditor() const
367 QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
368 aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );
372 //=================================================================================
373 // function : SMESHGUI_AddQuadraticElementDlg()
374 // purpose : constructor
375 //=================================================================================
376 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
379 bool modal, WFlags fl)
380 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
381 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
382 mySMESHGUI( theModule ),
383 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
387 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
388 (SUIT_Session::session()->activeApplication());
390 mySimulation = new SMESH::TElementSimulation (anApp);
391 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
393 QString anElementName;
397 anElementName = QString("QUADRATIC_EDGE");
400 anElementName = QString("QUADRATIC_TRIANGLE");
402 case QUAD_QUADRANGLE:
403 anElementName = QString("QUADRATIC_QUADRANGLE");
405 case QUAD_TETRAHEDRON:
406 anElementName = QString("QUADRATIC_TETRAHEDRON");
409 anElementName = QString("QUADRATIC_PYRAMID");
411 case QUAD_PENTAHEDRON:
412 anElementName = QString("QUADRATIC_PENTAHEDRON");
414 case QUAD_HEXAHEDRON:
415 anElementName = QString("QUADRATIC_HEXAHEDRON");
419 anElementName = QString("QUADRATIC_EDGE");
422 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName));
423 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName));
424 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName));
425 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName));
427 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
428 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
431 setName("SMESHGUI_AddQuadraticElementDlg");
434 setSizeGripEnabled(TRUE);
435 QGridLayout* aDialogLayout = new QGridLayout(this);
436 aDialogLayout->setSpacing(6);
437 aDialogLayout->setMargin(11);
439 /***************************************************************/
440 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
441 GroupConstructors->setTitle(constructorGrTitle);
443 GroupConstructors->setExclusive(TRUE);
444 GroupConstructors->setColumnLayout(0, Qt::Vertical);
445 GroupConstructors->layout()->setSpacing(0);
446 GroupConstructors->layout()->setMargin(0);
447 GroupConstructors->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
448 QGridLayout* aGroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
449 aGroupConstructorsLayout->setAlignment(Qt::AlignTop);
450 aGroupConstructorsLayout->setSpacing(6);
451 aGroupConstructorsLayout->setMargin(11);
452 myRadioButton1 = new QRadioButton(GroupConstructors, "myRadioButton1");
453 myRadioButton1->setText(tr("" ));
454 myRadioButton1->setPixmap(image0);
455 myRadioButton1->setChecked(TRUE);
456 myRadioButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, myRadioButton1->sizePolicy().hasHeightForWidth()));
457 aGroupConstructorsLayout->addWidget(myRadioButton1, 0, 0);
458 aGroupConstructorsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
459 aDialogLayout->addWidget(GroupConstructors, 0, 0);
461 /***************************************************************/
462 GroupArguments = new QGroupBox(this, "GroupArguments");
463 GroupArguments->setTitle(argumentsGrTitle);
464 GroupArguments->setColumnLayout(0, Qt::Vertical);
465 GroupArguments->layout()->setSpacing(0);
466 GroupArguments->layout()->setMargin(0);
467 GroupArguments->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding));
468 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
469 aGroupArgumentsLayout->setAlignment(Qt::AlignTop);
470 aGroupArgumentsLayout->setSpacing(6);
471 aGroupArgumentsLayout->setMargin(11);
472 QLabel* aCornerNodesLabel = new QLabel(GroupArguments, "aCornerNodesLabel");
473 aCornerNodesLabel->setText(tr("SMESH_CORNER_NODES" ));
474 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
475 mySelectButton = new QPushButton(GroupArguments, "mySelectButton");
476 mySelectButton->setPixmap(image1);
477 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
478 myCornerNodes = new QLineEdit(GroupArguments, "myCornerNodes");
479 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
481 myTable = new QTable(GroupArguments);
482 aGroupArgumentsLayout->addMultiCellWidget(myTable, 1, 1, 0, 2);
484 myReverseCB = new QCheckBox(GroupArguments, "myReverseCB");
485 myReverseCB->setText(tr("SMESH_REVERSE" ));
486 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0);
488 aDialogLayout->addWidget(GroupArguments, 1, 0);
491 /***************************************************************/
492 GroupButtons = new QGroupBox(this, "GroupButtons");
493 GroupButtons->setColumnLayout(0, Qt::Vertical);
494 GroupButtons->layout()->setSpacing(0);
495 GroupButtons->layout()->setMargin(0);
496 GroupButtons->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
497 QGridLayout* aGroupButtonsLayout = new QGridLayout(GroupButtons->layout());
498 aGroupButtonsLayout->setAlignment(Qt::AlignTop);
499 aGroupButtonsLayout->setSpacing(6);
500 aGroupButtonsLayout->setMargin(11);
501 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
502 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
503 buttonCancel->setAutoDefault(TRUE);
504 aGroupButtonsLayout->addWidget(buttonCancel, 0, 3);
505 buttonApply = new QPushButton(GroupButtons, "buttonApply");
506 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
507 buttonApply->setAutoDefault(TRUE);
508 aGroupButtonsLayout->addWidget(buttonApply, 0, 1);
509 aGroupButtonsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
510 buttonOk = new QPushButton(GroupButtons, "buttonOk");
511 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
512 buttonOk->setAutoDefault(TRUE);
513 buttonOk->setDefault(TRUE);
514 aGroupButtonsLayout->addWidget(buttonOk, 0, 0);
515 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
516 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
517 buttonHelp->setAutoDefault(TRUE);
518 aGroupButtonsLayout->addWidget(buttonHelp, 0, 4);
520 aDialogLayout->addWidget(GroupButtons, 2, 0);
522 Init(); /* Initialisations */
525 //=================================================================================
526 // function : ~SMESHGUI_AddQuadraticElementDlg()
527 // purpose : Destroys the object and frees any allocated resources
528 //=================================================================================
529 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
531 // no need to delete child widgets, Qt does it all for us
535 //=================================================================================
538 //=================================================================================
539 void SMESHGUI_AddQuadraticElementDlg::Init()
541 GroupArguments->show();
542 myRadioButton1->setChecked(TRUE);
543 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
553 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
558 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
560 case QUAD_QUADRANGLE:
563 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
565 case QUAD_TETRAHEDRON:
568 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
573 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
575 case QUAD_PENTAHEDRON:
578 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
580 case QUAD_HEXAHEDRON:
583 myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
587 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, "validator", myNbCorners));
589 /* initialize table */
590 myTable->setNumCols(3);
591 myTable->setNumRows(aNumRows);
593 QStringList aColLabels;
594 aColLabels.append(tr("SMESH_FIRST"));
595 aColLabels.append(tr("SMESH_MIDDLE"));
596 aColLabels.append(tr("SMESH_LAST"));
597 myTable->setColumnLabels(aColLabels);
599 for ( int col = 0; col < myTable->numCols(); col++ )
600 myTable->setColumnWidth(col, 80);
602 myTable->setColumnReadOnly(0, true);
603 myTable->setColumnReadOnly(2, true);
605 myTable->setEnabled( false );
607 for ( int row = 0; row < myTable->numRows(); row++ )
609 IdEditItem* anEditItem = new IdEditItem( myTable, QTableItem::OnTyping, "" );
610 anEditItem->setReplaceable(true);
611 myTable->setItem(row, 1, anEditItem);
614 /* signals and slots connections */
615 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
616 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
617 connect(myTable, SIGNAL(doubleClicked(int, int, int, const QPoint&)), SLOT(onCellDoubleClicked(int, int, int, const QPoint&)));
618 connect(myTable, SIGNAL(valueChanged (int, int)), SLOT(onCellTextChange(int, int)));
619 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
620 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
622 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
623 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
624 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
625 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
627 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
628 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
630 this->show(); // displays Dialog
632 // set selection mode
633 SMESH::SetPointRepresentation(true);
635 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
636 aViewWindow->SetSelectionMode( NodeSelection );
641 //=================================================================================
642 // function : ClickOnApply()
644 //=================================================================================
645 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
647 if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
650 BusyLocker lock( myBusy );
656 anIds.push_back(myTable->text(0, 0).toInt());
657 anIds.push_back(myTable->text(0, 2).toInt());
658 anIds.push_back(myTable->text(0, 1).toInt());
661 case QUAD_QUADRANGLE:
662 case QUAD_TETRAHEDRON:
664 case QUAD_PENTAHEDRON:
665 case QUAD_HEXAHEDRON:
666 for ( int row = 0; row < myNbCorners; row++ )
667 anIds.push_back(myTable->text(row, 0).toInt());
668 for ( int row = 0; row < myTable->numRows(); row++ )
669 anIds.push_back(myTable->text(row, 1).toInt());
672 if ( myReverseCB->isChecked())
673 SMESH::ReverseConnectivity( anIds, myType );
675 int aNumberOfIds = anIds.size();
676 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
677 anArrayOfIdeces->length( aNumberOfIds );
679 for (int i = 0; i < aNumberOfIds; i++)
680 anArrayOfIdeces[i] = anIds[ i ];
682 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
685 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
687 case QUAD_QUADRANGLE:
688 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
689 case QUAD_TETRAHEDRON:
691 case QUAD_PENTAHEDRON:
692 case QUAD_HEXAHEDRON:
693 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
696 SALOME_ListIO aList; aList.Append( myActor->getIO() );
697 mySelector->ClearIndex();
698 mySelectionMgr->setSelectedObjects( aList, false );
700 mySimulation->SetVisibility(false);
709 //=================================================================================
710 // function : ClickOnOk()
712 //=================================================================================
713 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
719 //=================================================================================
720 // function : ClickOnCancel()
722 //=================================================================================
723 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
725 mySelectionMgr->clearSelected();
726 mySimulation->SetVisibility(false);
727 SMESH::SetPointRepresentation(false);
728 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
729 aViewWindow->SetSelectionMode( ActorSelection );
730 disconnect(mySelectionMgr, 0, this, 0);
731 mySMESHGUI->ResetState();
735 //=================================================================================
736 // function : ClickOnHelp()
738 //=================================================================================
739 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
741 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
743 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
747 platform = "winapplication";
749 platform = "application";
751 SUIT_MessageBox::warn1(this, QObject::tr("WRN_WARNING"),
752 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
753 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
754 QObject::tr("BUT_OK"));
758 //=================================================================================
759 // function : onTextChange()
761 //=================================================================================
762 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
765 BusyLocker lock( myBusy );
767 mySimulation->SetVisibility(false);
769 // hilight entered nodes
770 SMDS_Mesh* aMesh = 0;
772 aMesh = myActor->GetObject()->GetMesh();
775 TColStd_MapOfInteger newIndices;
777 QStringList aListId = QStringList::split(" ", theNewText, false);
779 for (int i = 0; i < aListId.count(); i++) {
780 if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
782 newIndices.Add( n->GetID() );
791 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
792 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
793 aViewWindow->highlight( myActor->getIO(), true, true );
795 if ( sender() == myCornerNodes )
796 UpdateTable( allOk );
803 //=================================================================================
804 // function : SelectionIntoArgument()
805 // purpose : Called when selection has changed
806 //=================================================================================
807 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
810 BusyLocker lock( myBusy );
812 if ( myIsEditCorners )
817 myCornerNodes->setText("");
819 if (!GroupButtons->isEnabled()) // inactive
822 mySimulation->SetVisibility(false);
826 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
828 if (aList.Extent() != 1)
835 Handle(SALOME_InteractiveObject) anIO = aList.First();
836 myMesh = SMESH::GetMeshByIO(anIO);
837 if (myMesh->_is_nil()) {
842 myActor = SMESH::FindActorByEntry(anIO->getEntry());
851 // get selected nodes
852 QString aString = "";
853 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
855 if ( myIsEditCorners )
857 myCornerNodes->setText(aString);
861 else if ( myTable->isEnabled() && nbNodes == 1 )
863 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
865 myTable->setText(theRow, 1, aString);
872 //=================================================================================
873 // function : displaySimulation()
875 //=================================================================================
876 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
880 SMESH::TElementSimulation::TVTKIds anIds;
882 // Collect ids from the dialog
885 int aDisplayMode = VTK_SURFACE;
887 if ( myType == QUAD_EDGE )
889 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) );
890 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
891 anID = (myTable->text(0, 1)).toInt(&ok);
892 if (!ok) anID = (myTable->text(0, 0)).toInt();
893 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
894 aDisplayMode = VTK_WIREFRAME;
898 for ( int row = 0; row < myNbCorners; row++ )
899 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(row, 0).toInt() ) );
901 for ( int row = 0; row < myTable->numRows(); row++ )
903 anID = (myTable->text(row, 1)).toInt(&ok);
905 anID = (myTable->text(row, 0)).toInt();
906 aDisplayMode = VTK_WIREFRAME;
908 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
912 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
916 mySimulation->SetVisibility(false);
921 //=================================================================================
922 // function : SetEditCorners()
924 //=================================================================================
925 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
927 myCornerNodes->setFocus();
928 myIsEditCorners = true;
929 SelectionIntoArgument();
933 //=================================================================================
934 // function : DeactivateActiveDialog()
936 //=================================================================================
937 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
939 if (GroupConstructors->isEnabled()) {
940 GroupConstructors->setEnabled(false);
941 GroupArguments->setEnabled(false);
942 GroupButtons->setEnabled(false);
943 mySimulation->SetVisibility(false);
944 mySMESHGUI->ResetState();
945 mySMESHGUI->SetActiveDialogBox(0);
949 //=================================================================================
950 // function : ActivateThisDialog()
952 //=================================================================================
953 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
955 /* Emit a signal to deactivate the active dialog */
956 mySMESHGUI->EmitSignalDeactivateDialog();
958 GroupConstructors->setEnabled(true);
959 GroupArguments->setEnabled(true);
960 GroupButtons->setEnabled(true);
962 SMESH::SetPointRepresentation(true);
964 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
965 aViewWindow->SetSelectionMode( NodeSelection );
966 SelectionIntoArgument();
969 //=================================================================================
970 // function : enterEvent()
972 //=================================================================================
973 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
975 if (GroupConstructors->isEnabled())
977 ActivateThisDialog();
980 //=================================================================================
981 // function : closeEvent()
983 //=================================================================================
984 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
986 /* same than click on cancel button */
990 //=================================================================================
991 // function : hideEvent()
992 // purpose : caused by ESC key
993 //=================================================================================
994 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
1000 //=================================================================================
1001 // function : onReverse()
1003 //=================================================================================
1004 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
1006 mySimulation->SetVisibility(false);
1007 displaySimulation();
1012 //=================================================================================
1013 // function : IsValid()
1015 //=================================================================================
1016 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
1018 SMDS_Mesh* aMesh = 0;
1020 aMesh = myActor->GetObject()->GetMesh();
1026 for ( int row = 0; row < myTable->numRows(); row++ )
1028 int anID = (myTable->text(row, 1)).toInt(&ok);
1032 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1040 //=================================================================================
1041 // function : UpdateTable()
1043 //=================================================================================
1044 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1046 QStringList aListCorners = QStringList::split(" ", myCornerNodes->text(), false);
1048 if ( aListCorners.count() == myNbCorners && theConersValidity )
1050 myTable->setEnabled( true );
1052 // clear the Middle column
1053 for ( int row = 0; row < myTable->numRows(); row++ )
1054 myTable->setText( row, 1, "");
1061 aFirstColIds = FirstEdgeIds;
1062 aLastColIds = LastEdgeIds;
1065 aFirstColIds = FirstTriangleIds;
1066 aLastColIds = LastTriangleIds;
1068 case QUAD_QUADRANGLE:
1069 aFirstColIds = FirstQuadrangleIds;
1070 aLastColIds = LastQuadrangleIds;
1072 case QUAD_TETRAHEDRON:
1073 aFirstColIds = FirstTetrahedronIds;
1074 aLastColIds = LastTetrahedronIds;
1077 aFirstColIds = FirstPyramidIds;
1078 aLastColIds = LastPyramidIds;
1080 case QUAD_PENTAHEDRON:
1081 aFirstColIds = FirstPentahedronIds;
1082 aLastColIds = LastPentahedronIds;
1084 case QUAD_HEXAHEDRON:
1085 aFirstColIds = FirstHexahedronIds;
1086 aLastColIds = LastHexahedronIds;
1090 // fill the First and the Last columns
1091 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
1092 myTable->setText( i, 0, aListCorners[ aFirstColIds[i] ] );
1094 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
1095 myTable->setText( i, 2, aListCorners[ aLastColIds[i] ] );
1100 for ( int row = 0; row < myTable->numRows(); row++ )
1101 for ( int col = 0; col < myTable->numCols(); col++ )
1102 myTable->setText(row, col, "");
1104 myTable->setEnabled( false );
1109 //=================================================================================
1110 // function : onTableActivate()
1112 //=================================================================================
1113 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol, int theButton, const QPoint& theMousePos )
1115 myIsEditCorners = false;
1116 displaySimulation();
1121 //=================================================================================
1122 // function : onCellTextChange()
1124 //=================================================================================
1125 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1127 myIsEditCorners = false;
1128 displaySimulation();
1133 //=================================================================================
1134 // function : keyPressEvent()
1136 //=================================================================================
1137 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1139 QDialog::keyPressEvent( e );
1140 if ( e->isAccepted() )
1143 if ( e->key() == Key_F1 )
1150 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
1152 bool valid = IsValid();
1153 buttonOk->setEnabled( valid );
1154 buttonApply->setEnabled( valid );