Back to index

salome-smesh  6.5.0
SMESHGUI_AddMeshElementDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_AddMeshElementDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 //  SMESH includes
00027 //
00028 #include "SMESHGUI_AddMeshElementDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_GroupUtils.h"
00035 #include "SMESHGUI_IdValidator.h"
00036 
00037 #include <SMESH_Actor.h>
00038 #include <SMESH_ActorUtils.h>
00039 #include <SMESH_FaceOrientationFilter.h>
00040 #include <SMDS_Mesh.hxx>
00041 
00042 // SALOME GUI inclues
00043 #include <SUIT_Desktop.h>
00044 #include <SUIT_Session.h>
00045 #include <SUIT_ResourceMgr.h>
00046 #include <SUIT_MessageBox.h>
00047 #include <SUIT_ViewManager.h>
00048 #include <LightApp_SelectionMgr.h>
00049 #include <SALOME_ListIO.hxx>
00050 #include <SalomeApp_Application.h>
00051 #include <SVTK_ViewModel.h>
00052 #include <SVTK_ViewWindow.h>
00053 
00054 // IDL incldues
00055 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00056 
00057 // OCCT includes
00058 #include <TColStd_MapOfInteger.hxx>
00059 
00060 // VTK includes
00061 #include <vtkCell.h>
00062 #include <vtkIdList.h>
00063 #include <vtkUnstructuredGrid.h>
00064 #include <vtkDataSetMapper.h>
00065 #include <vtkPolyDataMapper.h>
00066 #include <vtkProperty.h>
00067 
00068 // Qt includes
00069 #include <QComboBox>
00070 #include <QGroupBox>
00071 #include <QLabel>
00072 #include <QLineEdit>
00073 #include <QPushButton>
00074 #include <QRadioButton>
00075 #include <QHBoxLayout>
00076 #include <QVBoxLayout>
00077 #include <QGridLayout>
00078 #include <QVariant>
00079 #include <QCheckBox>
00080 #include <QKeyEvent>
00081 #include <QButtonGroup>
00082 
00083 #define SPACING 6
00084 #define MARGIN  11
00085 
00086 namespace SMESH
00087 {
00088   class TElementSimulation
00089   {
00090     SalomeApp_Application* myApplication;
00091     SUIT_ViewWindow* myViewWindow;
00092     SVTK_ViewWindow* myVTKViewWindow;
00093 
00094     SALOME_Actor* myPreviewActor;
00095     vtkDataSetMapper* myMapper;
00096     vtkUnstructuredGrid* myGrid;
00097 
00098     SALOME_Actor* myFaceOrientation;
00099     vtkPolyDataMapper* myFaceOrientationDataMapper;
00100     SMESH_FaceOrientationFilter* myFaceOrientationFilter;
00101 
00102   public:
00103     TElementSimulation (SalomeApp_Application* theApplication)
00104     {
00105       myApplication = theApplication;
00106       SUIT_ViewManager* mgr = theApplication->activeViewManager();
00107       if (!mgr) return;
00108       myViewWindow = mgr->getActiveView();
00109       myVTKViewWindow = GetVtkViewWindow(myViewWindow);
00110 
00111       myGrid = vtkUnstructuredGrid::New();
00112 
00113       // Create and display actor
00114       myMapper = vtkDataSetMapper::New();
00115       myMapper->SetInput(myGrid);
00116 
00117       myPreviewActor = SALOME_Actor::New();
00118       myPreviewActor->PickableOff();
00119       myPreviewActor->VisibilityOff();
00120       myPreviewActor->SetMapper(myMapper);
00121 
00122       vtkFloatingPointType anRGB[3];
00123       vtkProperty* aProp = vtkProperty::New();
00124       GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
00125       aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
00126       myPreviewActor->SetProperty( aProp );
00127       aProp->Delete();
00128 
00129       vtkProperty* aBackProp = vtkProperty::New();
00130       GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
00131       aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
00132       myPreviewActor->SetBackfaceProperty( aBackProp );
00133       aBackProp->Delete();
00134 
00135       myVTKViewWindow->AddActor(myPreviewActor);
00136 
00137       // Orientation of faces
00138       myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
00139       myFaceOrientationFilter->SetInput(myGrid);
00140 
00141       myFaceOrientationDataMapper = vtkPolyDataMapper::New();
00142       myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
00143 
00144       myFaceOrientation = SALOME_Actor::New();
00145       myFaceOrientation->PickableOff();
00146       myFaceOrientation->VisibilityOff();
00147       myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
00148 
00149       vtkProperty* anOrientationProp = vtkProperty::New();
00150       GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
00151       anOrientationProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
00152       myFaceOrientation->SetProperty( anOrientationProp );
00153       anOrientationProp->Delete();
00154 
00155       myVTKViewWindow->AddActor(myFaceOrientation);
00156     }
00157 
00158     typedef std::vector<vtkIdType> TVTKIds;
00159     void SetPosition (SMESH_Actor* theActor,
00160                       vtkIdType    theType,
00161                       TVTKIds&     theIds)
00162     {
00163       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
00164       myGrid->SetPoints(aGrid->GetPoints());
00165       myGrid->Reset();
00166 
00167       const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType ));
00168       SMDS_MeshCell::applyInterlace( interlace, theIds );
00169 
00170       vtkIdList *anIds = vtkIdList::New();
00171       for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
00172         anIds->InsertId(i,theIds[i]);
00173 
00174       myGrid->InsertNextCell(theType,anIds);
00175       anIds->Delete();
00176 
00177       myGrid->Modified();
00178 
00179       SetVisibility(true, theActor->GetFacesOriented());
00180     }
00181 
00182 
00183     void SetVisibility (bool theVisibility, bool theShowOrientation = false)
00184     {
00185       myPreviewActor->SetVisibility(theVisibility);
00186       myFaceOrientation->SetVisibility(theShowOrientation);
00187       RepaintCurrentView();
00188     }
00189 
00190 
00191     ~TElementSimulation()
00192     {
00193       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
00194         myVTKViewWindow->RemoveActor(myPreviewActor);
00195         myVTKViewWindow->RemoveActor(myFaceOrientation);
00196       }
00197       myPreviewActor->Delete();
00198       myFaceOrientation->Delete();
00199 
00200       myMapper->RemoveAllInputs();
00201       myMapper->Delete();
00202 
00203       myFaceOrientationFilter->Delete();
00204 
00205       myFaceOrientationDataMapper->RemoveAllInputs();
00206       myFaceOrientationDataMapper->Delete();
00207 
00208       myGrid->Delete();
00209     }
00210   };
00211 }
00212 
00213 //=================================================================================
00214 // function : SMESHGUI_AddMeshElementDlg()
00215 // purpose  : constructor
00216 //=================================================================================
00217 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI*          theModule,
00218                                                         SMDSAbs_EntityType ElementType)
00219   : QDialog( SMESH::GetDesktop( theModule ) ),
00220     mySMESHGUI( theModule ),
00221     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00222     myBusy ( false )
00223 {
00224   setModal( false );
00225   setAttribute( Qt::WA_DeleteOnClose, true );
00226 
00227   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
00228     (SUIT_Session::session()->activeApplication());
00229   myIsPoly = false;
00230   mySimulation = new SMESH::TElementSimulation (anApp);
00231   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00232   myGeomType = ElementType;
00233   myElementType = SMDSAbs_Volume;
00234 
00235   // verify nb nodes and type
00236   QString elemName;
00237   switch ( myGeomType ) {
00238   case SMDSEntity_0D:
00239     myNbNodes = 1;
00240     myElementType = SMDSAbs_0DElement;
00241     elemName = "ELEM0D";
00242     myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor";
00243     break;
00244   case SMDSEntity_Edge:
00245     myNbNodes = 2;
00246     myElementType = SMDSAbs_Edge;
00247     elemName = "EDGE";
00248     myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
00249     break;
00250   case SMDSEntity_Triangle:
00251     myNbNodes = 3;
00252     elemName = "TRIANGLE";
00253     myElementType = SMDSAbs_Face;
00254     myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
00255     break;
00256   case SMDSEntity_Quadrangle:
00257     myNbNodes = 4;
00258     myElementType = SMDSAbs_Face;
00259     elemName = "QUADRANGLE";
00260     myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
00261     break;
00262   case SMDSEntity_Polygon:
00263     myNbNodes = 0;
00264     myElementType = SMDSAbs_Face;
00265     elemName = "POLYGON";
00266     myIsPoly = true;
00267     myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
00268     break;
00269   case SMDSEntity_Tetra:
00270     myNbNodes = 4;
00271     elemName = "TETRAS";
00272     myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
00273     break;
00274   case SMDSEntity_Pyramid:
00275     myNbNodes = 5;
00276     elemName = "PYRAMID";
00277     myHelpFileName = "adding_nodes_and_elements_page.html#adding_pyramids_anchor";
00278     break;
00279   case SMDSEntity_Hexa:
00280     myNbNodes = 8;
00281     elemName = "HEXAS";
00282     myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
00283     break;
00284   case SMDSEntity_Penta:
00285     myNbNodes = 6;
00286     elemName = "PENTA";
00287     myHelpFileName = "adding_nodes_and_elements_page.html#adding_pentahedrons_anchor";
00288     break;
00289   case SMDSEntity_Hexagonal_Prism:
00290     myNbNodes = 12;
00291     elemName = "OCTA";
00292     myHelpFileName = "adding_nodes_and_elements_page.html#adding_octahedrons_anchor";
00293     break;
00294   default:
00295     myNbNodes = 2;
00296     elemName = "EDGE";
00297     myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
00298   }
00299 
00300   QString iconName      = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
00301   QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
00302   QString caption       = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
00303   QString grBoxTitle    = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
00304 
00305   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
00306   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00307 
00308   setWindowTitle(caption);
00309   setSizeGripEnabled(true);
00310 
00311   QVBoxLayout* aTopLayout = new QVBoxLayout(this);
00312   aTopLayout->setSpacing(SPACING);
00313   aTopLayout->setMargin(MARGIN);
00314 
00315   /***************************************************************/
00316   GroupConstructors = new QGroupBox(buttonGrTitle, this);
00317   QButtonGroup* ButtonGroup = new QButtonGroup(this);
00318   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00319   GroupConstructorsLayout->setSpacing(SPACING);
00320   GroupConstructorsLayout->setMargin(MARGIN);
00321 
00322   Constructor1 = new QRadioButton(GroupConstructors);
00323   Constructor1->setIcon(image0);
00324   Constructor1->setChecked(true);
00325 
00326   GroupConstructorsLayout->addWidget(Constructor1);
00327   ButtonGroup->addButton( Constructor1, 0 );
00328 
00329   /***************************************************************/
00330   GroupC1 = new QGroupBox(grBoxTitle, this);
00331   QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
00332   GroupC1Layout->setSpacing(SPACING);
00333   GroupC1Layout->setMargin(MARGIN);
00334 
00335   TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
00336   SelectButtonC1A1 = new QPushButton(GroupC1);
00337   SelectButtonC1A1->setIcon(image1);
00338   LineEditC1A1 = new QLineEdit(GroupC1);
00339   LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, myIsPoly ? 1000 : myNbNodes));
00340 
00341   Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
00342 
00343   GroupC1Layout->addWidget(TextLabelC1A1,    0, 0);
00344   GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
00345   GroupC1Layout->addWidget(LineEditC1A1,     0, 2);
00346   if ( Reverse ) GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
00347 
00348   /***************************************************************/
00349   GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
00350   GroupGroups->setCheckable( true );
00351   QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
00352   GroupGroupsLayout->setSpacing(SPACING);
00353   GroupGroupsLayout->setMargin(MARGIN);
00354 
00355   TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
00356   ComboBox_GroupName = new QComboBox( GroupGroups );
00357   ComboBox_GroupName->setEditable( true );
00358   ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
00359 
00360   GroupGroupsLayout->addWidget( TextLabel_GroupName );
00361   GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
00362 
00363   /***************************************************************/
00364   GroupButtons = new QGroupBox(this);
00365   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00366   GroupButtonsLayout->setSpacing(SPACING);
00367   GroupButtonsLayout->setMargin(MARGIN);
00368 
00369   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00370   buttonOk->setAutoDefault(true);
00371   buttonOk->setDefault(true);
00372   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00373   buttonApply->setAutoDefault(true);
00374   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00375   buttonCancel->setAutoDefault(true);
00376   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00377   buttonHelp->setAutoDefault(true);
00378 
00379   GroupButtonsLayout->addWidget(buttonOk);
00380   GroupButtonsLayout->addSpacing(10);
00381   GroupButtonsLayout->addWidget(buttonApply);
00382   GroupButtonsLayout->addSpacing(10);
00383   GroupButtonsLayout->addStretch();
00384   GroupButtonsLayout->addWidget(buttonCancel);
00385   GroupButtonsLayout->addWidget(buttonHelp);
00386 
00387   /***************************************************************/
00388   aTopLayout->addWidget(GroupConstructors);
00389   aTopLayout->addWidget(GroupC1);
00390   aTopLayout->addWidget(GroupGroups);
00391   aTopLayout->addWidget(GroupButtons);
00392 
00393   Init(); /* Initialisations */
00394 }
00395 
00396 //=================================================================================
00397 // function : ~SMESHGUI_AddMeshElementDlg()
00398 // purpose  : Destroys the object and frees any allocated resources
00399 //=================================================================================
00400 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
00401 {
00402   delete mySimulation;
00403 }
00404 
00405 //=================================================================================
00406 // function : Init()
00407 // purpose  :
00408 //=================================================================================
00409 void SMESHGUI_AddMeshElementDlg::Init()
00410 {
00411   GroupC1->show();
00412   Constructor1->setChecked(true);
00413   myEditCurrentArgument = LineEditC1A1;
00414   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00415 
00416   /* reset "Add to group" control */
00417   GroupGroups->setChecked( false );
00418   GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
00419 
00420   myNbOkNodes = 0;
00421   myActor = 0;
00422 
00423   /* signals and slots connections */
00424   connect(buttonOk, SIGNAL(clicked()),     SLOT(ClickOnOk()));
00425   connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
00426   connect(buttonApply, SIGNAL(clicked()),  SLOT(ClickOnApply()));
00427   connect(buttonHelp, SIGNAL(clicked()),   SLOT(ClickOnHelp()));
00428 
00429   connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
00430   connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00431   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
00432   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
00433   /* to close dialog if study frame change */
00434   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
00435   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel()));    
00436 
00437   if (Reverse)
00438     connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
00439 
00440   // set selection mode
00441   SMESH::SetPointRepresentation(true);
00442 
00443   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00444     aViewWindow->SetSelectionMode( NodeSelection );
00445 
00446   myBusy = false;
00447 
00448   SelectionIntoArgument();
00449 }
00450 
00451 //=================================================================================
00452 // function : ClickOnApply()
00453 // purpose  :
00454 //=================================================================================
00455 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
00456 {
00457   if( !isValid() )
00458     return;
00459 
00460   if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
00461     myBusy = true;
00462     SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
00463     anArrayOfIndices->length(myNbNodes);
00464     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
00465     const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
00466     if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
00467       for (int i = 0; i < aListId.count(); i++)
00468         anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
00469     else if ( Reverse && Reverse->isChecked() && revIndex.empty() ) // polygon
00470       for (int i = 0; i < aListId.count(); i++)
00471         anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
00472     else
00473       for (int i = 0; i < aListId.count(); i++)
00474         anArrayOfIndices[i] = aListId[ i ].toInt();
00475 
00476     bool addToGroup = GroupGroups->isChecked();
00477     QString aGroupName;
00478 
00479     SMESH::SMESH_GroupBase_var aGroup;
00480     int idx = 0;
00481     if( addToGroup ) {
00482       aGroupName = ComboBox_GroupName->currentText();
00483       for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
00484         QString aName = ComboBox_GroupName->itemText( i );
00485         if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
00486           idx = i;
00487       }
00488       if ( idx > 0 && idx < myGroups.count() ) {
00489         SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
00490         if ( !aGeomGroup->_is_nil() ) {
00491           int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
00492                                                tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
00493                                                tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
00494           if ( res == 1 ) return;
00495         }
00496         aGroup = myGroups[idx-1];
00497       }
00498     }
00499 
00500     long anElemId = -1;
00501     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00502     switch (myElementType) {
00503     case SMDSAbs_0DElement:
00504       anElemId = aMeshEditor->Add0DElement(anArrayOfIndices[0]); break;
00505     case SMDSAbs_Edge:
00506       anElemId = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
00507     case SMDSAbs_Face:
00508       if ( myIsPoly )
00509         anElemId = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
00510       else
00511         anElemId = aMeshEditor->AddFace(anArrayOfIndices.inout());
00512       break;
00513     default:
00514       anElemId = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
00515     }
00516 
00517     if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
00518       SMESH::SMESH_Group_var aGroupUsed;
00519       if ( aGroup->_is_nil() ) {
00520         // create new group 
00521         aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
00522         if ( !aGroupUsed->_is_nil() ) {
00523           myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
00524           ComboBox_GroupName->addItem( aGroupName );
00525         }
00526       }
00527       else {
00528         SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
00529         if ( !aGeomGroup->_is_nil() ) {
00530           aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
00531           if ( !aGroupUsed->_is_nil() && idx > 0 ) {
00532             myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
00533             SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
00534           }
00535         }
00536         else
00537           aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
00538       }
00539 
00540       if ( !aGroupUsed->_is_nil() ) {
00541         SMESH::long_array_var anIdList = new SMESH::long_array;
00542         anIdList->length( 1 );
00543         anIdList[0] = anElemId;
00544         aGroupUsed->Add( anIdList.inout() );
00545       }
00546     }
00547 
00548     SALOME_ListIO aList; aList.Append( myActor->getIO() );
00549     mySelector->ClearIndex();
00550     mySelectionMgr->setSelectedObjects( aList, false );
00551 
00552     SMESH::UpdateView();
00553     mySimulation->SetVisibility(false);
00554 
00555     buttonOk->setEnabled(false);
00556     buttonApply->setEnabled(false);
00557 
00558     myEditCurrentArgument->setText("");
00559 
00560     myBusy = false;
00561 
00562     SMESHGUI::Modified();
00563   }
00564 }
00565 
00566 //=================================================================================
00567 // function : ClickOnOk()
00568 // purpose  :
00569 //=================================================================================
00570 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
00571 {
00572   ClickOnApply();
00573   ClickOnCancel();
00574 }
00575 
00576 //=================================================================================
00577 // function : ClickOnCancel()
00578 // purpose  :
00579 //=================================================================================
00580 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
00581 {
00582   //mySelectionMgr->clearSelected();
00583   mySimulation->SetVisibility(false);
00584   SMESH::SetPointRepresentation(false);
00585   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00586     aViewWindow->SetSelectionMode( ActorSelection );
00587   disconnect(mySelectionMgr, 0, this, 0);
00588   mySMESHGUI->ResetState();
00589   reject();
00590 }
00591 
00592 //=================================================================================
00593 // function : ClickOnHelp()
00594 // purpose  :
00595 //=================================================================================
00596 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
00597 {
00598   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00599   if (app)
00600     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
00601                              myHelpFileName);
00602   else {
00603     QString platform;
00604 #ifdef WIN32
00605     platform = "winapplication";
00606 #else
00607     platform = "application";
00608 #endif
00609     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00610                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00611                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
00612                                                                  platform)).
00613                              arg(myHelpFileName));
00614   }
00615 }
00616 
00617 //=================================================================================
00618 // function : onTextChange()
00619 // purpose  :
00620 //=================================================================================
00621 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
00622 {
00623   if (myBusy) return;
00624   myBusy = true;
00625 
00626   myNbOkNodes = 0;
00627 
00628   buttonOk->setEnabled(false);
00629   buttonApply->setEnabled(false);
00630 
00631   mySimulation->SetVisibility(false);
00632 
00633   // hilight entered nodes
00634   SMDS_Mesh* aMesh = 0;
00635   if (myActor)
00636     aMesh = myActor->GetObject()->GetMesh();
00637 
00638   if (aMesh) {
00639     TColStd_MapOfInteger newIndices;
00640 
00641     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00642     bool allOk = true;
00643     for (int i = 0; i < aListId.count(); i++) {
00644       if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
00645         {
00646           newIndices.Add( n->GetID() );
00647           myNbOkNodes++;
00648         }
00649       else
00650         allOk = false;  
00651     }
00652 
00653     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
00654     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00655       aViewWindow->highlight( myActor->getIO(), true, true );
00656 
00657     myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
00658 
00659     if (myIsPoly)
00660       {
00661         if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
00662           myNbOkNodes = 0;
00663         else
00664           myNbOkNodes = aListId.count();
00665       }
00666   }
00667 
00668   if(myNbOkNodes) {
00669     buttonOk->setEnabled(true);
00670     buttonApply->setEnabled(true);
00671     displaySimulation();
00672   }
00673 
00674   myBusy = false;
00675 }
00676 
00677 //=================================================================================
00678 // function : SelectionIntoArgument()
00679 // purpose  : Called when selection has changed
00680 //=================================================================================
00681 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
00682 {
00683   if (myBusy) return;
00684 
00685   // clear
00686   myNbOkNodes = 0;
00687   myActor = 0;
00688 
00689   myBusy = true;
00690   myEditCurrentArgument->setText("");
00691   myBusy = false;
00692 
00693   if (!GroupButtons->isEnabled()) // inactive
00694     return;
00695 
00696   buttonOk->setEnabled(false);
00697   buttonApply->setEnabled(false);
00698 
00699   mySimulation->SetVisibility(false);
00700   //  SMESH::SetPointRepresentation(true);
00701 
00702   QString aCurrentEntry = myEntry;
00703 
00704   // get selected mesh
00705   SALOME_ListIO aList;
00706   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00707 
00708   if (aList.Extent() != 1)
00709     return;
00710 
00711   Handle(SALOME_InteractiveObject) anIO = aList.First();
00712   myEntry = anIO->getEntry();
00713   myMesh = SMESH::GetMeshByIO(anIO);
00714   if (myMesh->_is_nil())
00715     return;
00716 
00717   // process groups
00718   if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
00719     myGroups.clear();
00720     ComboBox_GroupName->clear();
00721     ComboBox_GroupName->addItem( QString() );
00722     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
00723     for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
00724       SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
00725       if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
00726         QString aGroupName( aGroup->GetName() );
00727         if ( !aGroupName.isEmpty() ) {
00728           myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
00729           ComboBox_GroupName->addItem( aGroupName );
00730         }
00731       }
00732     }
00733   }
00734 
00735   myActor = SMESH::FindActorByEntry(anIO->getEntry());
00736   if (!myActor)
00737     return;
00738 
00739   // get selected nodes
00740   QString aString = "";
00741   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
00742   myBusy = true;
00743   myEditCurrentArgument->setText(aString);
00744   myBusy = false;
00745   if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
00746     myNbNodes = nbNodes;
00747   } else if (myNbNodes != nbNodes) {
00748     return;
00749   }
00750 
00751   // OK
00752   myNbOkNodes = nbNodes;
00753 
00754   buttonOk->setEnabled(true);
00755   buttonApply->setEnabled(true);
00756 
00757   displaySimulation();
00758 }
00759 
00760 //=================================================================================
00761 // function : displaySimulation()
00762 // purpose  :
00763 //=================================================================================
00764 void SMESHGUI_AddMeshElementDlg::displaySimulation()
00765 {
00766   if (myNbOkNodes && GroupButtons->isEnabled()) {
00767     SMESH::TElementSimulation::TVTKIds anIds;
00768     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
00769     for (int i = 0; i < aListId.count(); i++)
00770       anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
00771 
00772     if (Reverse && Reverse->isChecked())
00773     {
00774       const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
00775       if ( i.empty() ) // polygon
00776         std::reverse( anIds.begin(), anIds.end() );
00777       else
00778         SMDS_MeshCell::applyInterlace( i, anIds );
00779     }
00780 
00781     vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
00782     mySimulation->SetPosition(myActor,aType,anIds);
00783     SMESH::UpdateView();
00784   }
00785 }
00786 
00787 //=================================================================================
00788 // function : SetEditCurrentArgument()
00789 // purpose  :
00790 //=================================================================================
00791 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
00792 {
00793   QPushButton* send = (QPushButton*)sender();
00794   if (send == SelectButtonC1A1) {
00795     LineEditC1A1->setFocus();
00796     myEditCurrentArgument = LineEditC1A1;
00797   }
00798   SelectionIntoArgument();
00799 }
00800 
00801 //=================================================================================
00802 // function : DeactivateActiveDialog()
00803 // purpose  :
00804 //=================================================================================
00805 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
00806 {
00807   if (GroupConstructors->isEnabled()) {
00808     GroupConstructors->setEnabled(false);
00809     GroupC1->setEnabled(false);
00810     GroupButtons->setEnabled(false);
00811     mySimulation->SetVisibility(false);
00812     mySMESHGUI->ResetState();
00813     mySMESHGUI->SetActiveDialogBox(0);
00814   }
00815 }
00816 
00817 //=================================================================================
00818 // function : ActivateThisDialog()
00819 // purpose  :
00820 //=================================================================================
00821 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
00822 {
00823   /* Emit a signal to deactivate the active dialog */
00824   mySMESHGUI->EmitSignalDeactivateDialog();
00825 
00826   GroupConstructors->setEnabled(true);
00827   GroupC1->setEnabled(true);
00828   GroupButtons->setEnabled(true);
00829 
00830   SMESH::SetPointRepresentation(true);
00831 
00832   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00833     aViewWindow->SetSelectionMode( NodeSelection );
00834   SelectionIntoArgument();
00835 }
00836 
00837 //=================================================================================
00838 // function : enterEvent()
00839 // purpose  :
00840 //=================================================================================
00841 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
00842 {
00843   if (GroupConstructors->isEnabled())
00844     return;
00845   ActivateThisDialog();
00846 }
00847 
00848 //=================================================================================
00849 // function : closeEvent()
00850 // purpose  :
00851 //=================================================================================
00852 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
00853 {
00854   /* same than click on cancel button */
00855   ClickOnCancel();
00856 }
00857 
00858 //=================================================================================
00859 // function : hideEvent()
00860 // purpose  : caused by ESC key
00861 //=================================================================================
00862 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
00863 {
00864   if (!isMinimized())
00865     ClickOnCancel();
00866 }
00867 
00868 //=================================================================================
00869 // function : CheckBox()
00870 // purpose  :
00871 //=================================================================================
00872 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
00873 {
00874   if (!myNbOkNodes)
00875     return;
00876 
00877   if (state >= 0) {
00878     mySimulation->SetVisibility(false);
00879     displaySimulation();
00880   }
00881 }
00882 
00883 //=================================================================================
00884 // function : keyPressEvent()
00885 // purpose  :
00886 //=================================================================================
00887 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
00888 {
00889   QDialog::keyPressEvent( e );
00890   if ( e->isAccepted() )
00891     return;
00892 
00893   if ( e->key() == Qt::Key_F1 ) {
00894     e->accept();
00895     ClickOnHelp();
00896   }
00897 }
00898 
00899 //=================================================================================
00900 // function : isValid
00901 // purpose  :
00902 //=================================================================================
00903 bool SMESHGUI_AddMeshElementDlg::isValid()
00904 {
00905   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
00906     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
00907     return false;
00908   }
00909   return true;
00910 }