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/
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"
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_IndexedMapOfInteger.hxx>
55 #include <vtkIdList.h>
56 #include <vtkIntArray.h>
57 #include <vtkCellArray.h>
58 #include <vtkUnsignedCharArray.h>
59 #include <vtkUnstructuredGrid.h>
60 #include <vtkDataSetMapper.h>
61 #include <vtkProperty.h>
63 #include <vtkQuadraticEdge.h>
64 #include <vtkQuadraticTriangle.h>
65 #include <vtkQuadraticQuad.h>
66 #include <vtkQuadraticHexahedron.h>
67 #include <vtkQuadraticTetra.h>
70 #include <qbuttongroup.h>
71 #include <qgroupbox.h>
73 #include <qlineedit.h>
74 #include <qpushbutton.h>
75 #include <qradiobutton.h>
78 #include <qcheckbox.h>
87 void ReverseConnectivity( vector<int> & ids, int type )
89 // for reverse connectivity of other types keeping the first id, see
90 // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
94 case QUAD_TETRAHEDRON: {
95 static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
100 static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
104 case QUAD_PENTAHEDRON: {
105 static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
109 case QUAD_HEXAHEDRON: {
110 static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
115 static int aConn[] = {1,0,2};
119 case QUAD_TRIANGLE: {
120 static int aConn[] = {0,2,1,5,4,3};
124 case QUAD_QUADRANGLE: {
125 static int aConn[] = {0,3,2,1,7,6,5,4};
132 reverse( ids.begin(), ids.end() );
135 vector<int> aRevIds( ids.size() );
136 for ( int i = 0; i < ids.size(); i++)
137 aRevIds[ i ] = ids[ conn[ i ]];
142 class TElementSimulation {
143 SalomeApp_Application* myApplication;
144 SUIT_ViewWindow* myViewWindow;
145 SVTK_ViewWindow* myVTKViewWindow;
147 SALOME_Actor* myPreviewActor;
148 vtkDataSetMapper* myMapper;
149 vtkUnstructuredGrid* myGrid;
150 //vtkProperty* myBackProp, *myProp;
152 vtkFloatingPointType myRGB[3], myBackRGB[3];
155 TElementSimulation (SalomeApp_Application* theApplication)
157 myApplication = theApplication;
158 SUIT_ViewManager* mgr = theApplication->activeViewManager();
160 myViewWindow = mgr->getActiveView();
161 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
163 myGrid = vtkUnstructuredGrid::New();
165 // Create and display actor
166 myMapper = vtkDataSetMapper::New();
167 myMapper->SetInput(myGrid);
169 myPreviewActor = SALOME_Actor::New();
170 myPreviewActor->PickableOff();
171 myPreviewActor->VisibilityOff();
172 myPreviewActor->SetMapper(myMapper);
174 vtkProperty* myProp = vtkProperty::New();
175 GetColor( "SMESH", "fill_color", myRGB[0], myRGB[1], myRGB[2], QColor( 0, 170, 255 ) );
176 myProp->SetColor( myRGB[0], myRGB[1], myRGB[2] );
177 myPreviewActor->SetProperty( myProp );
180 vtkProperty* myBackProp = vtkProperty::New();
181 GetColor( "SMESH", "backface_color", myBackRGB[0], myBackRGB[1], myBackRGB[2], QColor( 0, 0, 255 ) );
182 myBackProp->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
183 myPreviewActor->SetBackfaceProperty( myBackProp );
184 myBackProp->Delete();
186 myVTKViewWindow->AddActor(myPreviewActor);
189 typedef std::vector<vtkIdType> TVTKIds;
190 void SetPosition (SMESH_Actor* theActor,
194 const bool theReverse)
196 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
197 myGrid->SetPoints(aGrid->GetPoints());
205 aType = VTK_QUADRATIC_EDGE;
208 aType = VTK_QUADRATIC_TRIANGLE;
210 case QUAD_QUADRANGLE:
211 aType = VTK_QUADRATIC_QUAD;
213 case QUAD_TETRAHEDRON:
214 aType = VTK_QUADRATIC_TETRA;
217 //aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
218 aType = VTK_CONVEX_POINT_SET;
220 case QUAD_PENTAHEDRON:
221 //aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2
222 aType = VTK_CONVEX_POINT_SET;
224 case QUAD_HEXAHEDRON:
225 aType = VTK_QUADRATIC_HEXAHEDRON;
229 // take care of orientation
230 if ( aType == VTK_CONVEX_POINT_SET ) {
231 if ( theReverse && theMode == VTK_SURFACE ) {
232 //myPreviewActor->GetProperty()->SetColor( myBackRGB[0], myBackRGB[1], myBackRGB[2] );
236 // VTK cell connectivity opposites the MED one for volumic elements
237 if ( theIds.size() > 8 ? !theReverse : theReverse ) {
238 ReverseConnectivity( theIds, theType );
243 vtkIdList *anIds = vtkIdList::New();
245 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
246 anIds->InsertId(i,theIds[i]);
247 //std::cout << i<< ": " << theIds[i] << std::endl;
250 myGrid->InsertNextCell(aType,anIds);
255 myPreviewActor->GetMapper()->Update();
256 myPreviewActor->SetRepresentation( theMode );
259 // restore normal orientation
260 if ( aType == VTK_CONVEX_POINT_SET ) {
261 if ( theReverse && theMode == VTK_SURFACE ) {
262 //myPreviewActor->GetProperty()->SetColor( myRGB[0], myRGB[1], myRGB[2] );
268 void SetVisibility (bool theVisibility)
270 myPreviewActor->SetVisibility(theVisibility);
271 RepaintCurrentView();
275 ~TElementSimulation()
277 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
278 myVTKViewWindow->RemoveActor(myPreviewActor);
280 myPreviewActor->Delete();
282 myMapper->RemoveAllInputs();
288 // myBackProp->Delete();
294 // Define the sequences of ids
295 static int FirstEdgeIds[] = {0};
296 static int LastEdgeIds[] = {1};
298 static int FirstTriangleIds[] = {0,1,2};
299 static int LastTriangleIds[] = {1,2,0};
301 static int FirstQuadrangleIds[] = {0,1,2,3};
302 static int LastQuadrangleIds[] = {1,2,3,0};
304 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
305 static int LastTetrahedronIds[] = {1,2,0,0,1,2};
307 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
308 static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
310 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
311 static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
313 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
314 static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
318 //=================================================================================
319 // function : SMESHGUI_AddQuadraticElementDlg()
320 // purpose : constructor
321 //=================================================================================
322 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
325 bool modal, WFlags fl)
326 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
327 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
328 mySMESHGUI( theModule ),
329 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
332 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
333 (SUIT_Session::session()->activeApplication());
335 mySimulation = new SMESH::TElementSimulation (anApp);
336 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
338 QString anElementName;
342 anElementName = QString("QUADRATIC_EDGE");
345 anElementName = QString("QUADRATIC_TRIANGLE");
347 case QUAD_QUADRANGLE:
348 anElementName = QString("QUADRATIC_QUADRANGLE");
350 case QUAD_TETRAHEDRON:
351 anElementName = QString("QUADRATIC_TETRAHEDRON");
354 anElementName = QString("QUADRATIC_PYRAMID");
356 case QUAD_PENTAHEDRON:
357 anElementName = QString("QUADRATIC_PENTAHEDRON");
359 case QUAD_HEXAHEDRON:
360 anElementName = QString("QUADRATIC_HEXAHEDRON");
364 anElementName = QString("QUADRATIC_EDGE");
367 QString iconName = tr(QString("ICON_DLG_%1").arg(anElementName));
368 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName));
369 QString argumentsGrTitle = tr(QString("SMESH_ADD_%1").arg(anElementName));
370 QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName));
372 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
373 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
376 setName("SMESHGUI_AddQuadraticElementDlg");
379 setSizeGripEnabled(TRUE);
380 QGridLayout* aDialogLayout = new QGridLayout(this);
381 aDialogLayout->setSpacing(6);
382 aDialogLayout->setMargin(11);
384 /***************************************************************/
385 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
386 GroupConstructors->setTitle(constructorGrTitle);
388 GroupConstructors->setExclusive(TRUE);
389 GroupConstructors->setColumnLayout(0, Qt::Vertical);
390 GroupConstructors->layout()->setSpacing(0);
391 GroupConstructors->layout()->setMargin(0);
392 GroupConstructors->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
393 QGridLayout* aGroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
394 aGroupConstructorsLayout->setAlignment(Qt::AlignTop);
395 aGroupConstructorsLayout->setSpacing(6);
396 aGroupConstructorsLayout->setMargin(11);
397 myRadioButton1 = new QRadioButton(GroupConstructors, "myRadioButton1");
398 myRadioButton1->setText(tr("" ));
399 myRadioButton1->setPixmap(image0);
400 myRadioButton1->setChecked(TRUE);
401 myRadioButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, myRadioButton1->sizePolicy().hasHeightForWidth()));
402 aGroupConstructorsLayout->addWidget(myRadioButton1, 0, 0);
403 aGroupConstructorsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
404 aDialogLayout->addWidget(GroupConstructors, 0, 0);
406 /***************************************************************/
407 GroupArguments = new QGroupBox(this, "GroupArguments");
408 GroupArguments->setTitle(argumentsGrTitle);
409 GroupArguments->setColumnLayout(0, Qt::Vertical);
410 GroupArguments->layout()->setSpacing(0);
411 GroupArguments->layout()->setMargin(0);
412 GroupArguments->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding));
413 QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
414 aGroupArgumentsLayout->setAlignment(Qt::AlignTop);
415 aGroupArgumentsLayout->setSpacing(6);
416 aGroupArgumentsLayout->setMargin(11);
417 QLabel* aCornerNodesLabel = new QLabel(GroupArguments, "aCornerNodesLabel");
418 aCornerNodesLabel->setText(tr("SMESH_CORNER_NODES" ));
419 aGroupArgumentsLayout->addWidget(aCornerNodesLabel, 0, 0);
420 mySelectButton = new QPushButton(GroupArguments, "mySelectButton");
421 mySelectButton->setPixmap(image1);
422 aGroupArgumentsLayout->addWidget(mySelectButton, 0, 1);
423 myCornerNodes = new QLineEdit(GroupArguments, "myCornerNodes");
424 aGroupArgumentsLayout->addWidget(myCornerNodes, 0, 2);
426 myTable = new QTable(GroupArguments);
427 aGroupArgumentsLayout->addMultiCellWidget(myTable, 1, 1, 0, 2);
429 myReverseCB = new QCheckBox(GroupArguments, "myReverseCB");
430 myReverseCB->setText(tr("SMESH_REVERSE" ));
431 aGroupArgumentsLayout->addWidget(myReverseCB, 2, 0);
433 aDialogLayout->addWidget(GroupArguments, 1, 0);
436 /***************************************************************/
437 GroupButtons = new QGroupBox(this, "GroupButtons");
438 GroupButtons->setColumnLayout(0, Qt::Vertical);
439 GroupButtons->layout()->setSpacing(0);
440 GroupButtons->layout()->setMargin(0);
441 GroupButtons->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
442 QGridLayout* aGroupButtonsLayout = new QGridLayout(GroupButtons->layout());
443 aGroupButtonsLayout->setAlignment(Qt::AlignTop);
444 aGroupButtonsLayout->setSpacing(6);
445 aGroupButtonsLayout->setMargin(11);
446 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
447 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
448 buttonCancel->setAutoDefault(TRUE);
449 aGroupButtonsLayout->addWidget(buttonCancel, 0, 3);
450 buttonApply = new QPushButton(GroupButtons, "buttonApply");
451 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
452 buttonApply->setAutoDefault(TRUE);
453 aGroupButtonsLayout->addWidget(buttonApply, 0, 1);
454 aGroupButtonsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
455 buttonOk = new QPushButton(GroupButtons, "buttonOk");
456 buttonOk->setText(tr("SMESH_BUT_OK" ));
457 buttonOk->setAutoDefault(TRUE);
458 buttonOk->setDefault(TRUE);
459 aGroupButtonsLayout->addWidget(buttonOk, 0, 0);
460 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
461 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
462 buttonHelp->setAutoDefault(TRUE);
463 aGroupButtonsLayout->addWidget(buttonHelp, 0, 4);
465 aDialogLayout->addWidget(GroupButtons, 2, 0);
467 Init(); /* Initialisations */
470 //=================================================================================
471 // function : ~SMESHGUI_AddQuadraticElementDlg()
472 // purpose : Destroys the object and frees any allocated resources
473 //=================================================================================
474 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
476 // no need to delete child widgets, Qt does it all for us
480 //=================================================================================
483 //=================================================================================
484 void SMESHGUI_AddQuadraticElementDlg::Init()
486 GroupArguments->show();
487 myRadioButton1->setChecked(TRUE);
488 myIsEditCorners = true;
489 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
499 myHelpFileName = "/adding_quadratic_nodes_and_elements.htm#?"; //Adding_edges
504 myHelpFileName = "/adding_quadratic_nodes_and_elements.htm#?"; //Adding_triangles
506 case QUAD_QUADRANGLE:
509 myHelpFileName = "/adding_quadratic_nodes_and_elements.htm#?"; //Adding_quadrangles
511 case QUAD_TETRAHEDRON:
514 myHelpFileName = "/adding_quadratic_nodes_and_elements.htm#?"; //Adding_tetrahedrons
519 myHelpFileName = "/adding_quadratic_nodes_and_elements.htm#?"; //Adding_pyramids
521 case QUAD_PENTAHEDRON:
524 myHelpFileName = "/adding_quadratic_nodes_and_elements.htm#?"; //Adding_pentahedrons
526 case QUAD_HEXAHEDRON:
529 myHelpFileName = "/adding_quadratic_nodes_and_elements.htm#?"; //Adding_hexahedrons
533 myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, "validator", myNbCorners));
535 /* initialize table */
536 myTable->setNumCols(3);
537 myTable->setNumRows(aNumRows);
539 QStringList aColLabels;
540 aColLabels.append(tr("SMESH_FIRST"));
541 aColLabels.append(tr("SMESH_MIDDLE"));
542 aColLabels.append(tr("SMESH_LAST"));
543 myTable->setColumnLabels(aColLabels);
545 for ( int col = 0; col < myTable->numCols(); col++ )
546 myTable->setColumnWidth(col, 80);
548 myTable->setColumnReadOnly(0, true);
549 myTable->setColumnReadOnly(2, true);
551 myTable->setEnabled( false );
553 for ( int row = 0; row < myTable->numRows(); row++ )
555 SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( myTable, QTableItem::OnTyping, "" );
556 anEditItem->setReplaceable(false);
557 myTable->setItem(row, 1, anEditItem);
560 /* signals and slots connections */
561 connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
562 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
563 connect(myTable, SIGNAL(doubleClicked(int, int, int, const QPoint&)), SLOT(onCellDoubleClicked(int, int, int, const QPoint&)));
564 connect(myTable, SIGNAL(valueChanged (int, int)), SLOT(onCellTextChange(int, int)));
565 connect(myCornerNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
566 connect(myReverseCB, SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
568 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
569 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
570 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
571 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
573 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
574 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
576 this->show(); // displays Dialog
578 // set selection mode
579 SMESH::SetPointRepresentation(true);
581 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
582 aViewWindow->SetSelectionMode( NodeSelection );
589 //=================================================================================
590 // function : ClickOnApply()
592 //=================================================================================
593 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
595 if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
602 anIds.push_back(myTable->text(0, 0).toInt());
603 anIds.push_back(myTable->text(0, 2).toInt());
604 anIds.push_back(myTable->text(0, 1).toInt());
607 case QUAD_QUADRANGLE:
608 case QUAD_TETRAHEDRON:
610 case QUAD_PENTAHEDRON:
611 case QUAD_HEXAHEDRON:
612 for ( int row = 0; row < myNbCorners; row++ )
613 anIds.push_back(myTable->text(row, 0).toInt());
614 for ( int row = 0; row < myTable->numRows(); row++ )
615 anIds.push_back(myTable->text(row, 1).toInt());
618 if ( myReverseCB->isChecked())
619 SMESH::ReverseConnectivity( anIds, myType );
621 int aNumberOfIds = anIds.size();
622 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
623 anArrayOfIdeces->length( aNumberOfIds );
625 for (int i = 0; i < aNumberOfIds; i++)
626 anArrayOfIdeces[i] = anIds[ i ];
628 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
631 aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
633 case QUAD_QUADRANGLE:
634 aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
635 case QUAD_TETRAHEDRON:
637 case QUAD_PENTAHEDRON:
638 case QUAD_HEXAHEDRON:
639 aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
642 SALOME_ListIO aList; aList.Append( myActor->getIO() );
643 mySelector->ClearIndex();
644 mySelectionMgr->setSelectedObjects( aList, false );
647 mySimulation->SetVisibility(false);
649 buttonOk->setEnabled(false);
650 buttonApply->setEnabled(false);
659 //=================================================================================
660 // function : ClickOnOk()
662 //=================================================================================
663 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
670 //=================================================================================
671 // function : ClickOnCancel()
673 //=================================================================================
674 void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
676 mySelectionMgr->clearSelected();
677 mySimulation->SetVisibility(false);
678 SMESH::SetPointRepresentation(false);
679 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
680 aViewWindow->SetSelectionMode( ActorSelection );
681 disconnect(mySelectionMgr, 0, this, 0);
682 mySMESHGUI->ResetState();
687 //=================================================================================
688 // function : ClickOnHelp()
690 //=================================================================================
691 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
693 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
695 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
697 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
698 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
699 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
700 QObject::tr("BUT_OK"));
704 //=================================================================================
705 // function : onTextChange()
707 //=================================================================================
708 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
713 buttonOk->setEnabled(false);
714 buttonApply->setEnabled(false);
716 mySimulation->SetVisibility(false);
718 // hilight entered nodes
719 SMDS_Mesh* aMesh = 0;
721 aMesh = myActor->GetObject()->GetMesh();
724 TColStd_MapOfInteger newIndices;
726 QStringList aListId = QStringList::split(" ", theNewText, false);
728 for (int i = 0; i < aListId.count(); i++) {
729 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
730 newIndices.Add( n->GetID() );
738 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
739 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
740 aViewWindow->highlight( myActor->getIO(), true, true );
742 if ( sender() == myCornerNodes )
743 UpdateTable( allOk );
747 buttonOk->setEnabled(true);
748 buttonApply->setEnabled(true);
751 if ( sender() == myTable )
757 //=================================================================================
758 // function : SelectionIntoArgument()
759 // purpose : Called when selection has changed
760 //=================================================================================
761 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
765 if ( myIsEditCorners )
771 myCornerNodes->setText("");
774 if (!GroupButtons->isEnabled()) // inactive
777 buttonOk->setEnabled(false);
778 buttonApply->setEnabled(false);
780 mySimulation->SetVisibility(false);
784 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
786 if (aList.Extent() != 1)
792 Handle(SALOME_InteractiveObject) anIO = aList.First();
793 myMesh = SMESH::GetMeshByIO(anIO);
794 if (myMesh->_is_nil())
797 myActor = SMESH::FindActorByEntry(anIO->getEntry());
804 // get selected nodes
805 QString aString = "";
806 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
808 if ( myIsEditCorners )
811 myCornerNodes->setText(aString);
816 else if ( myTable->isEnabled() && nbNodes == 1 )
819 int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
821 myTable->setText(theRow, 1, aString);
827 buttonOk->setEnabled( true );
828 buttonApply->setEnabled( true );
834 //=================================================================================
835 // function : displaySimulation()
837 //=================================================================================
838 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
840 if (!myIsEditCorners) {
841 SMESH::TElementSimulation::TVTKIds anIds;
843 // Collect ids from the dialog
846 int aDisplayMode = VTK_SURFACE;
848 if ( myType == QUAD_EDGE )
850 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) );
851 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
852 anID = (myTable->text(0, 1)).toInt(&ok);
853 if (!ok) anID = (myTable->text(0, 0)).toInt();
854 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
855 aDisplayMode = VTK_WIREFRAME;
859 for ( int row = 0; row < myNbCorners; row++ )
860 anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(row, 0).toInt() ) );
862 for ( int row = 0; row < myTable->numRows(); row++ )
864 anID = (myTable->text(row, 1)).toInt(&ok);
866 anID = (myTable->text(row, 0)).toInt();
867 aDisplayMode = VTK_WIREFRAME;
869 anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
873 mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
878 //=================================================================================
879 // function : SetEditCorners()
881 //=================================================================================
882 void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
884 myCornerNodes->setFocus();
885 myIsEditCorners = true;
887 SelectionIntoArgument();
890 //=================================================================================
891 // function : DeactivateActiveDialog()
893 //=================================================================================
894 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
896 if (GroupConstructors->isEnabled()) {
897 GroupConstructors->setEnabled(false);
898 GroupArguments->setEnabled(false);
899 GroupButtons->setEnabled(false);
900 mySimulation->SetVisibility(false);
901 mySMESHGUI->ResetState();
902 mySMESHGUI->SetActiveDialogBox(0);
906 //=================================================================================
907 // function : ActivateThisDialog()
909 //=================================================================================
910 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
912 /* Emit a signal to deactivate the active dialog */
913 mySMESHGUI->EmitSignalDeactivateDialog();
915 GroupConstructors->setEnabled(true);
916 GroupArguments->setEnabled(true);
917 GroupButtons->setEnabled(true);
919 SMESH::SetPointRepresentation(true);
921 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
922 aViewWindow->SetSelectionMode( NodeSelection );
923 SelectionIntoArgument();
926 //=================================================================================
927 // function : enterEvent()
929 //=================================================================================
930 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
932 if (GroupConstructors->isEnabled())
934 ActivateThisDialog();
938 //=================================================================================
939 // function : closeEvent()
941 //=================================================================================
942 void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
944 /* same than click on cancel button */
949 //=================================================================================
950 // function : hideEvent()
951 // purpose : caused by ESC key
952 //=================================================================================
953 void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
959 //=================================================================================
960 // function : onReverse()
962 //=================================================================================
963 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
969 mySimulation->SetVisibility(false);
975 //=================================================================================
976 // function : IsValid()
978 //=================================================================================
979 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
981 SMDS_Mesh* aMesh = 0;
983 aMesh = myActor->GetObject()->GetMesh();
989 for ( int row = 0; row < myTable->numRows(); row++ )
991 int anID = (myTable->text(row, 1)).toInt(&ok);
995 const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1003 //=================================================================================
1004 // function : UpdateTable()
1006 //=================================================================================
1007 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1009 QStringList aListCorners = QStringList::split(" ", myCornerNodes->text(), false);
1011 if ( aListCorners.count() == myNbCorners && theConersValidity )
1013 myTable->setEnabled( true );
1015 // clear the Middle column
1016 for ( int row = 0; row < myTable->numRows(); row++ )
1017 myTable->setText( row, 1, "");
1024 aFirstColIds = FirstEdgeIds;
1025 aLastColIds = LastEdgeIds;
1028 aFirstColIds = FirstTriangleIds;
1029 aLastColIds = LastTriangleIds;
1031 case QUAD_QUADRANGLE:
1032 aFirstColIds = FirstQuadrangleIds;
1033 aLastColIds = LastQuadrangleIds;
1035 case QUAD_TETRAHEDRON:
1036 aFirstColIds = FirstTetrahedronIds;
1037 aLastColIds = LastTetrahedronIds;
1040 aFirstColIds = FirstPyramidIds;
1041 aLastColIds = LastPyramidIds;
1043 case QUAD_PENTAHEDRON:
1044 aFirstColIds = FirstPentahedronIds;
1045 aLastColIds = LastPentahedronIds;
1047 case QUAD_HEXAHEDRON:
1048 aFirstColIds = FirstHexahedronIds;
1049 aLastColIds = LastHexahedronIds;
1053 // fill the First and the Last columns
1054 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
1055 myTable->setText( i, 0, aListCorners[ aFirstColIds[i] ] );
1057 for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
1058 myTable->setText( i, 2, aListCorners[ aLastColIds[i] ] );
1063 for ( int row = 0; row < myTable->numRows(); row++ )
1064 for ( int col = 0; col < myTable->numCols(); col++ )
1065 myTable->setText(row, col, "");
1067 myTable->setEnabled( false );
1072 //=================================================================================
1073 // function : onTableActivate()
1075 //=================================================================================
1076 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol, int theButton, const QPoint& theMousePos )
1078 if ( theButton == 1 && theCol == 1 )
1079 myIsEditCorners = false;
1081 displaySimulation();
1086 //=================================================================================
1087 // function : onCellTextChange()
1089 //=================================================================================
1090 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1092 onTextChange( myTable->text(theRow, theCol) );
1096 QWidget* SMESHGUI_IdEditItem::createEditor() const
1098 QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
1099 aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );