Salome HOME
415f32f6f50782cd04134fcad40088676bcfe41a
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.cxx
1 // SMESH SMESHGUI : GUI for SMESH component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 //
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. 
10 //
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. 
15 //
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 
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_AddMeshElementDlg.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
24 //
25
26 //  SMESH includes
27 #include "SMESHGUI_AddMeshElementDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMDS_Mesh.hxx>
38
39 // SALOME GUI inclues
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_ViewManager.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <SALOME_ListIO.hxx>
47 #include <SalomeApp_Application.h>
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_ViewWindow.h>
50
51 // IDL incldues
52 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
53
54 // OCCT includes
55 #include <TColStd_MapOfInteger.hxx>
56
57 // VTK includes
58 #include <vtkCell.h>
59 #include <vtkIdList.h>
60 #include <vtkUnstructuredGrid.h>
61 #include <vtkDataSetMapper.h>
62 #include <vtkProperty.h>
63
64 // Qt includes
65 #include <QGroupBox>
66 #include <QLabel>
67 #include <QLineEdit>
68 #include <QPushButton>
69 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
73 #include <QVariant>
74 #include <QCheckBox>
75 #include <QKeyEvent>
76 #include <QButtonGroup>
77
78 #define SPACING 6
79 #define MARGIN  11
80
81 namespace SMESH
82 {
83   class TElementSimulation
84   {
85     SalomeApp_Application* myApplication;
86     SUIT_ViewWindow* myViewWindow;
87     SVTK_ViewWindow* myVTKViewWindow;
88
89     SALOME_Actor* myPreviewActor;
90     vtkDataSetMapper* myMapper;
91     vtkUnstructuredGrid* myGrid;
92
93   public:
94     TElementSimulation (SalomeApp_Application* theApplication)
95     {
96       myApplication = theApplication;
97       SUIT_ViewManager* mgr = theApplication->activeViewManager();
98       if (!mgr) return;
99       myViewWindow = mgr->getActiveView();
100       myVTKViewWindow = GetVtkViewWindow(myViewWindow);
101
102       myGrid = vtkUnstructuredGrid::New();
103
104       // Create and display actor
105       myMapper = vtkDataSetMapper::New();
106       myMapper->SetInput(myGrid);
107
108       myPreviewActor = SALOME_Actor::New();
109       myPreviewActor->PickableOff();
110       myPreviewActor->VisibilityOff();
111       myPreviewActor->SetMapper(myMapper);
112
113       vtkFloatingPointType anRGB[3];
114       vtkProperty* aProp = vtkProperty::New();
115       GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
116       aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
117       myPreviewActor->SetProperty( aProp );
118       aProp->Delete();
119
120       vtkProperty* aBackProp = vtkProperty::New();
121       GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
122       aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
123       myPreviewActor->SetBackfaceProperty( aBackProp );
124       aBackProp->Delete();
125
126       myVTKViewWindow->AddActor(myPreviewActor);
127     }
128
129     typedef std::vector<vtkIdType> TVTKIds;
130     void SetPosition (SMESH_Actor* theActor,
131                       vtkIdType theType,
132                       const TVTKIds& theIds)
133     {
134       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
135       myGrid->SetPoints(aGrid->GetPoints());
136
137       const int* aConn = NULL;
138       switch (theType) {
139       case VTK_TETRA:
140         {
141           static int anIds[] = {0,2,1,3};
142           aConn = anIds;
143           break;
144         }
145       case VTK_PYRAMID:
146         {
147           static int anIds[] = {0,3,2,1,4};
148           aConn = anIds;
149           break;
150         }
151       case VTK_HEXAHEDRON:
152         {
153           static int anIds[] = {0,3,2,1,4,7,6,5};
154           aConn = anIds;
155           break;
156         }
157       }
158
159       myGrid->Reset();
160       vtkIdList *anIds = vtkIdList::New();
161
162       if(aConn)
163         for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
164           anIds->InsertId(i,theIds[aConn[i]]);
165       else
166         for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
167           anIds->InsertId(i,theIds[i]);
168
169       myGrid->InsertNextCell(theType,anIds);
170       anIds->Delete();
171
172       myGrid->Modified();
173
174       SetVisibility(true);
175     }
176
177
178     void SetVisibility (bool theVisibility)
179     {
180       myPreviewActor->SetVisibility(theVisibility);
181       RepaintCurrentView();
182     }
183
184
185     ~TElementSimulation()
186     {
187       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
188         myVTKViewWindow->RemoveActor(myPreviewActor);
189       }
190       myPreviewActor->Delete();
191
192       myMapper->RemoveAllInputs();
193       myMapper->Delete();
194
195       myGrid->Delete();
196     }
197   };
198 }
199
200 //=================================================================================
201 // function : SMESHGUI_AddMeshElementDlg()
202 // purpose  : constructor
203 //=================================================================================
204 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
205                                                         SMDSAbs_ElementType ElementType, 
206                                                         int nbNodes )
207   : QDialog( SMESH::GetDesktop( theModule ) ),
208     mySMESHGUI( theModule ),
209     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
210 {
211   setModal( false );
212   setAttribute( Qt::WA_DeleteOnClose, true );
213
214   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
215     (SUIT_Session::session()->activeApplication());
216   myIsPoly = false;
217   mySimulation = new SMESH::TElementSimulation (anApp);
218   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
219
220   // verify nb nodes and type
221   myNbNodes = nbNodes;
222   myElementType = ElementType;
223   switch (ElementType) {
224   case SMDSAbs_Face:
225     //     if (myNbNodes != 3 && myNbNodes != 4)
226     //       myNbNodes = 3;
227     //     break;
228   case SMDSAbs_Volume:
229     //     if (myNbNodes != 4 && myNbNodes != 8) //(nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
230     //       myNbNodes = 4;
231     break;
232   default:
233     myElementType = SMDSAbs_Edge;
234     myNbNodes = 2;
235   }
236
237   QString elemName;
238   if (myNbNodes == 2) {
239     elemName = "EDGE";
240     myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
241   }
242   else if (myNbNodes == 3) {
243     elemName = "TRIANGLE";
244     myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
245   }
246   else if (myNbNodes == 4)
247     if (myElementType == SMDSAbs_Face) {
248       elemName = "QUADRANGLE";
249       myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
250     }
251     else {
252       elemName = "TETRAS";
253       myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
254     }
255   else if (myNbNodes == 8) {
256     elemName = "HEXAS";
257     myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
258   }
259   else if (myElementType == SMDSAbs_Face) {
260     elemName = "POLYGON";
261     myIsPoly = true;
262     myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
263   }
264   else if (myElementType == SMDSAbs_Volume) {
265     myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
266   }
267   
268   QString iconName      = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
269   QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
270   QString caption       = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
271   QString grBoxTitle    = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
272
273   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
274   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
275
276   setWindowTitle(caption);
277   setSizeGripEnabled(true);
278
279   QVBoxLayout* aTopLayout = new QVBoxLayout(this);
280   aTopLayout->setSpacing(SPACING);
281   aTopLayout->setMargin(MARGIN);
282
283   /***************************************************************/
284   GroupConstructors = new QGroupBox(buttonGrTitle, this);
285   QButtonGroup* ButtonGroup = new QButtonGroup(this);
286   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
287   GroupConstructorsLayout->setSpacing(SPACING);
288   GroupConstructorsLayout->setMargin(MARGIN);
289
290   Constructor1 = new QRadioButton(GroupConstructors);
291   Constructor1->setIcon(image0);
292   Constructor1->setChecked(true);
293
294   GroupConstructorsLayout->addWidget(Constructor1);
295   ButtonGroup->addButton( Constructor1, 0 );
296
297   /***************************************************************/
298   GroupC1 = new QGroupBox(grBoxTitle, this);
299   QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
300   GroupC1Layout->setSpacing(SPACING);
301   GroupC1Layout->setMargin(MARGIN);
302
303   TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
304   SelectButtonC1A1 = new QPushButton(GroupC1);
305   SelectButtonC1A1->setIcon(image1);
306   LineEditC1A1 = new QLineEdit(GroupC1);
307   //  LineEditC1A1->setReadOnly(true);
308   if (!myIsPoly)
309     LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, myNbNodes));
310
311   Reverse = myElementType == SMDSAbs_Face ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
312
313   GroupC1Layout->addWidget(TextLabelC1A1,    0, 0);
314   GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
315   GroupC1Layout->addWidget(LineEditC1A1,     0, 2);
316   if ( Reverse ) GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
317
318   /***************************************************************/
319   GroupButtons = new QGroupBox(this);
320   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
321   GroupButtonsLayout->setSpacing(SPACING);
322   GroupButtonsLayout->setMargin(MARGIN);
323
324   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
325   buttonOk->setAutoDefault(true);
326   buttonOk->setDefault(true);
327   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
328   buttonApply->setAutoDefault(true);
329   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
330   buttonCancel->setAutoDefault(true);
331   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
332   buttonHelp->setAutoDefault(true);
333
334   GroupButtonsLayout->addWidget(buttonOk);
335   GroupButtonsLayout->addSpacing(10);
336   GroupButtonsLayout->addWidget(buttonApply);
337   GroupButtonsLayout->addSpacing(10);
338   GroupButtonsLayout->addStretch();
339   GroupButtonsLayout->addWidget(buttonCancel);
340   GroupButtonsLayout->addWidget(buttonHelp);
341
342   /***************************************************************/
343   aTopLayout->addWidget(GroupConstructors);
344   aTopLayout->addWidget(GroupC1);
345   aTopLayout->addWidget(GroupButtons);
346
347   Init(); /* Initialisations */
348 }
349
350 //=================================================================================
351 // function : ~SMESHGUI_AddMeshElementDlg()
352 // purpose  : Destroys the object and frees any allocated resources
353 //=================================================================================
354 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
355 {
356   delete mySimulation;
357 }
358
359 //=================================================================================
360 // function : Init()
361 // purpose  :
362 //=================================================================================
363 void SMESHGUI_AddMeshElementDlg::Init()
364 {
365   GroupC1->show();
366   Constructor1->setChecked(true);
367   myEditCurrentArgument = LineEditC1A1;
368   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
369
370   myNbOkNodes = 0;
371   myActor = 0;
372
373   /* signals and slots connections */
374   connect(buttonOk, SIGNAL(clicked()),     SLOT(ClickOnOk()));
375   connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
376   connect(buttonApply, SIGNAL(clicked()),  SLOT(ClickOnApply()));
377   connect(buttonHelp, SIGNAL(clicked()),   SLOT(ClickOnHelp()));
378
379   connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
380   connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
381   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
382   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
383   /* to close dialog if study frame change */
384   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
385
386   if (Reverse)
387     connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
388
389   // set selection mode
390   SMESH::SetPointRepresentation(true);
391
392   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
393     aViewWindow->SetSelectionMode( NodeSelection );
394
395   myBusy = false;
396
397   SelectionIntoArgument();
398 }
399
400 //=================================================================================
401 // function : ClickOnApply()
402 // purpose  :
403 //=================================================================================
404 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
405 {
406   if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
407     myBusy = true;
408     SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
409     anArrayOfIdeces->length(myNbNodes);
410     bool reverse = (Reverse && Reverse->isChecked());
411     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
412     for (int i = 0; i < aListId.count(); i++)
413       if (reverse)
414         anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt();
415       else
416         anArrayOfIdeces[i] = aListId[ i ].toInt();
417
418     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
419     switch (myElementType) {
420     case SMDSAbs_Edge:
421       aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
422     case SMDSAbs_Face:{
423       if(myIsPoly)
424         aMeshEditor->AddPolygonalFace(anArrayOfIdeces.inout());
425       else
426         aMeshEditor->AddFace(anArrayOfIdeces.inout());
427       break;
428
429     }
430     case SMDSAbs_Volume:
431       aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
432     default:;
433     }
434
435     SALOME_ListIO aList; aList.Append( myActor->getIO() );
436     mySelector->ClearIndex();
437     mySelectionMgr->setSelectedObjects( aList, false );
438
439     SMESH::UpdateView();
440     mySimulation->SetVisibility(false);
441
442     buttonOk->setEnabled(false);
443     buttonApply->setEnabled(false);
444
445     myEditCurrentArgument->setText("");
446
447     myBusy = false;
448   }
449 }
450
451 //=================================================================================
452 // function : ClickOnOk()
453 // purpose  :
454 //=================================================================================
455 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
456 {
457   ClickOnApply();
458   ClickOnCancel();
459 }
460
461 //=================================================================================
462 // function : ClickOnCancel()
463 // purpose  :
464 //=================================================================================
465 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
466 {
467   //mySelectionMgr->clearSelected();
468   mySimulation->SetVisibility(false);
469   SMESH::SetPointRepresentation(false);
470   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
471     aViewWindow->SetSelectionMode( ActorSelection );
472   disconnect(mySelectionMgr, 0, this, 0);
473   mySMESHGUI->ResetState();
474   reject();
475 }
476
477 //=================================================================================
478 // function : ClickOnHelp()
479 // purpose  :
480 //=================================================================================
481 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
482 {
483   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
484   if (app) 
485     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
486   else {
487     QString platform;
488 #ifdef WIN32
489     platform = "winapplication";
490 #else
491     platform = "application";
492 #endif
493     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
494                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
495                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
496                                                                  platform)).
497                              arg(myHelpFileName));
498   }
499 }
500
501 //=================================================================================
502 // function : onTextChange()
503 // purpose  :
504 //=================================================================================
505 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
506 {
507   if (myBusy) return;
508   myBusy = true;
509
510   myNbOkNodes = 0;
511
512   buttonOk->setEnabled(false);
513   buttonApply->setEnabled(false);
514
515   mySimulation->SetVisibility(false);
516
517   // hilight entered nodes
518   SMDS_Mesh* aMesh = 0;
519   if (myActor)
520     aMesh = myActor->GetObject()->GetMesh();
521
522   if (aMesh) {
523     TColStd_MapOfInteger newIndices;
524     
525     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
526     bool allOk = true;
527     for (int i = 0; i < aListId.count(); i++) {
528       if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
529         {
530           newIndices.Add( n->GetID() );
531           myNbOkNodes++;
532         }
533       else
534         allOk = false;  
535     }
536     
537     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
538     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
539       aViewWindow->highlight( myActor->getIO(), true, true );
540     
541     myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
542     
543     if (myIsPoly)
544       {
545         if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
546           myNbOkNodes = 0;
547         else
548           myNbOkNodes = aListId.count();
549       }
550   }
551   
552   if(myNbOkNodes) {
553     buttonOk->setEnabled(true);
554     buttonApply->setEnabled(true);
555     displaySimulation();
556   }
557   
558   myBusy = false;
559 }
560
561 //=================================================================================
562 // function : SelectionIntoArgument()
563 // purpose  : Called when selection has changed
564 //=================================================================================
565 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
566 {
567   if (myBusy) return;
568
569   // clear
570   myNbOkNodes = 0;
571   myActor = 0;
572
573   myBusy = true;
574   myEditCurrentArgument->setText("");
575   myBusy = false;
576
577   if (!GroupButtons->isEnabled()) // inactive
578     return;
579
580   buttonOk->setEnabled(false);
581   buttonApply->setEnabled(false);
582
583   mySimulation->SetVisibility(false);
584   //  SMESH::SetPointRepresentation(true);
585
586   // get selected mesh
587   SALOME_ListIO aList;
588   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
589
590   if (aList.Extent() != 1)
591     return;
592
593   Handle(SALOME_InteractiveObject) anIO = aList.First();
594   myMesh = SMESH::GetMeshByIO(anIO);
595   if (myMesh->_is_nil())
596     return;
597
598   myActor = SMESH::FindActorByEntry(anIO->getEntry());
599   if (!myActor)
600     return;
601
602   // get selected nodes
603   QString aString = "";
604   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
605   myBusy = true;
606   myEditCurrentArgument->setText(aString);
607   myBusy = false;
608   if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
609     myNbNodes = nbNodes;
610   } else if (myNbNodes != nbNodes) {
611     return;
612   }
613
614   // OK
615   myNbOkNodes = nbNodes;
616
617   buttonOk->setEnabled(true);
618   buttonApply->setEnabled(true);
619
620   displaySimulation();
621 }
622
623 //=================================================================================
624 // function : displaySimulation()
625 // purpose  :
626 //=================================================================================
627 void SMESHGUI_AddMeshElementDlg::displaySimulation()
628 {
629   if (myNbOkNodes && GroupButtons->isEnabled()) {
630     SMESH::TElementSimulation::TVTKIds anIds;
631     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
632     for (int i = 0; i < aListId.count(); i++)
633       anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
634
635     if (Reverse && Reverse->isChecked())
636       reverse(anIds.begin(),anIds.end());
637
638     vtkIdType aType = 0;
639     if (myIsPoly)
640       switch ( myElementType ) {
641       case SMDSAbs_Face  : aType = VTK_POLYGON; break;
642       default: return;
643       }
644     else {
645       switch (myNbNodes) {
646       case 2: aType = VTK_LINE; break;
647       case 3: aType = VTK_TRIANGLE; break;
648       case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
649       case 8: aType = VTK_HEXAHEDRON; break;
650       default: return;
651       }
652     }
653
654     mySimulation->SetPosition(myActor,aType,anIds);
655     SMESH::UpdateView();
656   }
657 }
658
659 //=================================================================================
660 // function : SetEditCurrentArgument()
661 // purpose  :
662 //=================================================================================
663 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
664 {
665   QPushButton* send = (QPushButton*)sender();
666   if (send == SelectButtonC1A1) {
667     LineEditC1A1->setFocus();
668     myEditCurrentArgument = LineEditC1A1;
669   }
670   SelectionIntoArgument();
671 }
672
673 //=================================================================================
674 // function : DeactivateActiveDialog()
675 // purpose  :
676 //=================================================================================
677 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
678 {
679   if (GroupConstructors->isEnabled()) {
680     GroupConstructors->setEnabled(false);
681     GroupC1->setEnabled(false);
682     GroupButtons->setEnabled(false);
683     mySimulation->SetVisibility(false);
684     mySMESHGUI->ResetState();
685     mySMESHGUI->SetActiveDialogBox(0);
686   }
687 }
688
689 //=================================================================================
690 // function : ActivateThisDialog()
691 // purpose  :
692 //=================================================================================
693 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
694 {
695   /* Emit a signal to deactivate the active dialog */
696   mySMESHGUI->EmitSignalDeactivateDialog();
697
698   GroupConstructors->setEnabled(true);
699   GroupC1->setEnabled(true);
700   GroupButtons->setEnabled(true);
701
702   SMESH::SetPointRepresentation(true);
703
704   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
705     aViewWindow->SetSelectionMode( NodeSelection );
706   SelectionIntoArgument();
707 }
708
709 //=================================================================================
710 // function : enterEvent()
711 // purpose  :
712 //=================================================================================
713 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
714 {
715   if (GroupConstructors->isEnabled())
716     return;
717   ActivateThisDialog();
718 }
719
720 //=================================================================================
721 // function : closeEvent()
722 // purpose  :
723 //=================================================================================
724 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
725 {
726   /* same than click on cancel button */
727   ClickOnCancel();
728 }
729
730 //=================================================================================
731 // function : hideEvent()
732 // purpose  : caused by ESC key
733 //=================================================================================
734 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
735 {
736   if (!isMinimized())
737     ClickOnCancel();
738 }
739
740 //=================================================================================
741 // function : CheckBox()
742 // purpose  :
743 //=================================================================================
744 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
745 {
746   if (!myNbOkNodes)
747     return;
748
749   if (state >= 0) {
750     mySimulation->SetVisibility(false);
751     displaySimulation();
752   }
753 }
754
755 //=================================================================================
756 // function : keyPressEvent()
757 // purpose  :
758 //=================================================================================
759 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
760 {
761   QDialog::keyPressEvent( e );
762   if ( e->isAccepted() )
763     return;
764   
765   if ( e->key() == Qt::Key_F1 ) {
766     e->accept();
767     ClickOnHelp();
768   }
769 }