Back to index

salome-smesh  6.5.0
SMESHGUI_MultiEditDlg.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 // File   : SMESHGUI_MultiEditDlg.cxx
00024 // Author : Sergey LITONIN, Open CASCADE S.A.S.
00025 // SMESH includes
00026 
00027 #include "SMESHGUI_MultiEditDlg.h"
00028 
00029 #include "SMESHGUI.h"
00030 #include "SMESHGUI_Filter.h"
00031 #include "SMESHGUI_FilterDlg.h"
00032 #include "SMESHGUI_Utils.h"
00033 #include "SMESHGUI_VTKUtils.h"
00034 #include "SMESHGUI_MeshUtils.h"
00035 #include "SMESHGUI_FilterUtils.h"
00036 #include "SMESHGUI_SpinBox.h"
00037 
00038 #include <SMESH_Actor.h>
00039 #include <SMESH_TypeFilter.hxx>
00040 #include <SMDS_Mesh.hxx>
00041 
00042 // SALOME GUI includes
00043 #include <SUIT_Desktop.h>
00044 #include <SUIT_MessageBox.h>
00045 #include <SUIT_OverrideCursor.h>
00046 #include <SUIT_ResourceMgr.h>
00047 #include <SUIT_Session.h>
00048 
00049 #include <LightApp_SelectionMgr.h>
00050 #include <LightApp_Application.h>
00051 #include <SALOME_ListIO.hxx>
00052 #include <SALOME_ListIteratorOfListIO.hxx>
00053 #include <SalomeApp_Tools.h>
00054 
00055 #include <SVTK_Selector.h>
00056 #include <SVTK_ViewWindow.h>
00057 #include <VTKViewer_CellLocationsArray.h>
00058 
00059 // OCCT includes
00060 #include <TColStd_IndexedMapOfInteger.hxx>
00061 #include <TColStd_DataMapOfIntegerInteger.hxx>
00062 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
00063 
00064 // VTK includes
00065 #include <vtkIdList.h>
00066 #include <vtkCellArray.h>
00067 #include <vtkUnsignedCharArray.h>
00068 #include <vtkUnstructuredGrid.h>
00069 #include <vtkDataSetMapper.h>
00070 #include <vtkProperty.h>
00071 
00072 // Qt includes
00073 #include <QLabel>
00074 #include <QVBoxLayout>
00075 #include <QHBoxLayout>
00076 #include <QGridLayout>
00077 #include <QListWidget>
00078 #include <QCheckBox>
00079 #include <QComboBox>
00080 #include <QGroupBox>
00081 #include <QLineEdit>
00082 #include <QPushButton>
00083 #include <QButtonGroup>
00084 #include <QRadioButton>
00085 #include <QKeyEvent>
00086 
00087 // IDL includes
00088 #include <SALOMEconfig.h>
00089 #include CORBA_SERVER_HEADER(SMESH_Group)
00090 
00091 #define SPACING 6
00092 #define MARGIN  11
00093 
00100 //=======================================================================
00101 // name    : SMESHGUI_MultiEditDlg::SMESHGUI_MultiEditDlg
00102 // Purpose : Constructor
00103 //=======================================================================
00104 SMESHGUI_MultiEditDlg
00105 ::SMESHGUI_MultiEditDlg(SMESHGUI* theModule,
00106                         const int theMode,
00107                         const bool the3d2d):
00108   QDialog(SMESH::GetDesktop(theModule)),
00109   mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
00110   mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
00111   mySMESHGUI(theModule)
00112 {
00113   setModal(false);
00114   setAttribute(Qt::WA_DeleteOnClose, true);
00115 
00116   myFilterDlg = 0;
00117   myEntityType = 0;
00118 
00119   myFilterType = theMode;
00120   QVBoxLayout* aDlgLay = new QVBoxLayout(this);
00121   aDlgLay->setMargin(MARGIN);
00122   aDlgLay->setSpacing(SPACING);
00123 
00124   QWidget* aMainFrame = createMainFrame  (this, the3d2d);
00125   QWidget* aBtnFrame  = createButtonFrame(this);
00126 
00127   aDlgLay->addWidget(aMainFrame);
00128   aDlgLay->addWidget(aBtnFrame);
00129 
00130   Init();
00131 }
00132 
00133 //=======================================================================
00134 // name    : SMESHGUI_MultiEditDlg::createMainFrame
00135 // Purpose : Create frame containing dialog's input fields
00136 //=======================================================================
00137 QWidget* SMESHGUI_MultiEditDlg::createMainFrame (QWidget* theParent, const bool the3d2d)
00138 {
00139   QWidget* aMainGrp = new QWidget(theParent);
00140   QVBoxLayout* aMainGrpLayout = new QVBoxLayout(aMainGrp);
00141   aMainGrpLayout->setMargin(0);
00142   aMainGrpLayout->setSpacing(SPACING);
00143 
00144   QPixmap aPix (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00145 
00146   // "Selected cells" group
00147   mySelGrp = new QGroupBox(aMainGrp);
00148   
00149   QGridLayout* mySelGrpLayout = new QGridLayout(mySelGrp);
00150   mySelGrpLayout->setMargin(MARGIN);
00151   mySelGrpLayout->setSpacing(SPACING);
00152 
00153   myEntityTypeGrp = 0;
00154   if (the3d2d) {
00155     QGroupBox* aEntityTypeGrp = new QGroupBox(tr("SMESH_ELEMENTS_TYPE"), mySelGrp);
00156     myEntityTypeGrp = new QButtonGroup(mySelGrp);
00157     QHBoxLayout* aEntityLayout = new QHBoxLayout(aEntityTypeGrp);
00158     aEntityLayout->setMargin(MARGIN);
00159     aEntityLayout->setSpacing(SPACING);
00160 
00161     QRadioButton* aFaceRb = new QRadioButton(tr("SMESH_FACE"), aEntityTypeGrp);
00162     QRadioButton* aVolumeRb = new QRadioButton(tr("SMESH_VOLUME"), aEntityTypeGrp);
00163 
00164     aEntityLayout->addWidget(aFaceRb);
00165     aEntityLayout->addWidget(aVolumeRb);
00166 
00167     myEntityTypeGrp->addButton(aFaceRb, 0);
00168     myEntityTypeGrp->addButton(aVolumeRb, 1);
00169     aFaceRb->setChecked(true);
00170     myEntityType = myEntityTypeGrp->checkedId();
00171 
00172     mySelGrpLayout->addWidget(aEntityTypeGrp, 0, 0, 1, 2);
00173   }
00174 
00175   myListBox = new QListWidget(mySelGrp);
00176   myListBox->setSelectionMode(QListWidget::ExtendedSelection);
00177   myListBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
00178   myListBox->installEventFilter(this);
00179 
00180   myFilterBtn = new QPushButton(tr("FILTER"),    mySelGrp);
00181   myAddBtn    = new QPushButton(tr("ADD"),       mySelGrp);
00182   myRemoveBtn = new QPushButton(tr("REMOVE"),    mySelGrp);
00183   mySortBtn   = new QPushButton(tr("SORT_LIST"), mySelGrp);
00184 
00185   int row = mySelGrpLayout->rowCount();
00186   mySelGrpLayout->addWidget(myListBox,   row,   0, 6, 1);
00187   mySelGrpLayout->addWidget(myFilterBtn, row,   1);
00188   mySelGrpLayout->addWidget(myAddBtn,    row+2, 1);
00189   mySelGrpLayout->addWidget(myRemoveBtn, row+3, 1);
00190   mySelGrpLayout->addWidget(mySortBtn,   row+5, 1);
00191   mySelGrpLayout->setRowMinimumHeight(row+1, 10);
00192   mySelGrpLayout->setRowMinimumHeight(row+4, 10);
00193   mySelGrpLayout->setRowStretch(row+1, 5);
00194   mySelGrpLayout->setRowStretch(row+4, 5);
00195 
00196   myToAllChk = new QCheckBox(tr("TO_ALL"), mySelGrp);
00197   mySelGrpLayout->addWidget(myToAllChk, mySelGrpLayout->rowCount(), 0, 
00198                             1, mySelGrpLayout->columnCount());
00199 
00200   // Split/Join criterion group
00201   myCriterionGrp = new QGroupBox(tr("SPLIT_JOIN_CRITERION"), aMainGrp);
00202   QVBoxLayout* aCriterionLayout = new QVBoxLayout(myCriterionGrp);
00203   aCriterionLayout->setMargin(MARGIN);
00204   aCriterionLayout->setSpacing(SPACING);
00205   
00206   myChoiceWidget = new QWidget(myCriterionGrp);
00207   myGroupChoice = new QButtonGroup(myChoiceWidget);
00208   QVBoxLayout* aGroupChoiceLayout = new QVBoxLayout(myChoiceWidget);
00209   aGroupChoiceLayout->setMargin(0);
00210   aGroupChoiceLayout->setSpacing(SPACING);
00211 
00212   QRadioButton* aDiag13RB  = new QRadioButton(tr("USE_DIAGONAL_1_3"), myChoiceWidget);
00213   QRadioButton* aDiag24RB  = new QRadioButton(tr("USE_DIAGONAL_2_4"), myChoiceWidget);
00214   QRadioButton* aNumFuncRB = new QRadioButton(tr("USE_NUMERIC_FUNC"), myChoiceWidget);
00215 
00216   aGroupChoiceLayout->addWidget(aDiag13RB);
00217   aGroupChoiceLayout->addWidget(aDiag24RB);
00218   aGroupChoiceLayout->addWidget(aNumFuncRB);
00219   myGroupChoice->addButton(aDiag13RB,  0);
00220   myGroupChoice->addButton(aDiag24RB,  1);
00221   myGroupChoice->addButton(aNumFuncRB, 2);
00222   aDiag13RB->setChecked(true);
00223 
00224   myComboBoxFunctor = new QComboBox(myCriterionGrp);
00225   myComboBoxFunctor->addItem(tr("ASPECTRATIO_ELEMENTS"));
00226   myComboBoxFunctor->addItem(tr("MINIMUMANGLE_ELEMENTS"));
00227   myComboBoxFunctor->addItem(tr("SKEW_ELEMENTS"));
00228   myComboBoxFunctor->addItem(tr("AREA_ELEMENTS"));
00229   //myComboBoxFunctor->addItem(tr("LENGTH2D_EDGES")); // for existing elements only
00230   //myComboBoxFunctor->addItem(tr("MULTI2D_BORDERS")); // for existing elements only
00231   myComboBoxFunctor->setCurrentIndex(0);
00232 
00233   aCriterionLayout->addWidget(myChoiceWidget);
00234   aCriterionLayout->addWidget(myComboBoxFunctor);
00235 
00236   myCriterionGrp->hide();
00237   myChoiceWidget->hide();
00238   myComboBoxFunctor->setEnabled(false);
00239 
00240   // "Select from" group
00241   QGroupBox* aGrp = new QGroupBox(tr("SELECT_FROM"), aMainGrp);
00242   QGridLayout* aGrpLayout = new QGridLayout(aGrp);
00243   aGrpLayout->setMargin(MARGIN);
00244   aGrpLayout->setSpacing(SPACING);
00245 
00246   mySubmeshChk = new QCheckBox(tr("SMESH_SUBMESH"), aGrp);
00247   mySubmeshBtn = new QPushButton(aGrp);
00248   mySubmesh = new QLineEdit(aGrp);
00249   mySubmesh->setReadOnly(true);
00250   mySubmeshBtn->setIcon(aPix);
00251 
00252   myGroupChk = new QCheckBox(tr("SMESH_GROUP"), aGrp);
00253   myGroupBtn = new QPushButton(aGrp);
00254   myGroup = new QLineEdit(aGrp);
00255   myGroup->setReadOnly(true);
00256   myGroupBtn->setIcon(aPix);
00257 
00258   aGrpLayout->addWidget(mySubmeshChk,0,0);
00259   aGrpLayout->addWidget(mySubmeshBtn,0,1);
00260   aGrpLayout->addWidget(mySubmesh,0,2);
00261   aGrpLayout->addWidget(myGroupChk,1,0);
00262   aGrpLayout->addWidget(myGroupBtn,1,1);
00263   aGrpLayout->addWidget(myGroup,1,2);
00264   
00265   aMainGrpLayout->addWidget(mySelGrp);
00266   aMainGrpLayout->addWidget(myCriterionGrp);
00267   aMainGrpLayout->addWidget(aGrp);
00268 
00269   return aMainGrp;
00270 }
00271 
00272 //=======================================================================
00273 // name    : SMESHGUI_MultiEditDlg::createButtonFrame
00274 // Purpose : Create frame containing buttons
00275 //=======================================================================
00276 QWidget* SMESHGUI_MultiEditDlg::createButtonFrame (QWidget* theParent)
00277 {
00278   QGroupBox* aFrame = new QGroupBox(theParent);
00279 
00280   myOkBtn     = new QPushButton (tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
00281   myApplyBtn  = new QPushButton (tr("SMESH_BUT_APPLY"), aFrame);
00282   myCloseBtn  = new QPushButton (tr("SMESH_BUT_CLOSE"), aFrame);
00283   myHelpBtn   = new QPushButton (tr("SMESH_BUT_HELP"),  aFrame);
00284 
00285   QHBoxLayout* aLay = new QHBoxLayout (aFrame);
00286   aLay->setMargin(MARGIN);
00287   aLay->setSpacing(SPACING);
00288 
00289   aLay->addWidget(myOkBtn);
00290   aLay->addSpacing(10);
00291   aLay->addWidget(myApplyBtn);
00292   aLay->addSpacing(10);
00293   aLay->addStretch();
00294   aLay->addWidget(myCloseBtn);
00295   aLay->addWidget(myHelpBtn);
00296 
00297   return aFrame;
00298 }
00299 
00300 //=======================================================================
00301 // name    : SMESHGUI_MultiEditDlg::isValid
00302 // Purpose : Verify validity of input data
00303 //=======================================================================
00304 bool SMESHGUI_MultiEditDlg::isValid (const bool /*theMess*/)
00305 {
00306   return (!myMesh->_is_nil() &&
00307           (myListBox->count() > 0 || (myToAllChk->isChecked()/* && myActor*/)));
00308 }
00309 
00310 //=======================================================================
00311 // name    : SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg
00312 // Purpose : Destructor
00313 //=======================================================================
00314 SMESHGUI_MultiEditDlg::~SMESHGUI_MultiEditDlg()
00315 {
00316   if (myFilterDlg != 0)
00317   {
00318     myFilterDlg->setParent(0);
00319     delete myFilterDlg;
00320   }
00321 }
00322 
00323 //=======================================================================
00324 // name    : SMESHGUI_MultiEditDlg::eventFilter
00325 // Purpose : event filter
00326 //=======================================================================
00327 bool SMESHGUI_MultiEditDlg::eventFilter (QObject* object, QEvent* event)
00328 {
00329   if (object == myListBox && event->type() == QEvent::KeyPress) {
00330     QKeyEvent* ke = (QKeyEvent*)event;
00331     if (ke->key() == Qt::Key_Delete)
00332       onRemoveBtn();
00333   }
00334   return QDialog::eventFilter(object, event);
00335 }
00336 
00337 //=======================================================================
00338 // name    : SMESHGUI_MultiEditDlg::getNumericalFunctor
00339 // Purpose :
00340 //=======================================================================
00341 SMESH::NumericalFunctor_ptr SMESHGUI_MultiEditDlg::getNumericalFunctor()
00342 {
00343   SMESH::NumericalFunctor_var aNF = SMESH::NumericalFunctor::_nil();
00344 
00345   SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
00346   if (aFilterMgr->_is_nil())
00347     return aNF._retn();
00348 
00349   if (myComboBoxFunctor->currentText() == tr("ASPECTRATIO_ELEMENTS"))
00350     aNF = aFilterMgr->CreateAspectRatio();
00351   else if (myComboBoxFunctor->currentText() == tr("WARP_ELEMENTS"))
00352     aNF = aFilterMgr->CreateWarping();
00353   else if (myComboBoxFunctor->currentText() == tr("MINIMUMANGLE_ELEMENTS"))
00354     aNF = aFilterMgr->CreateMinimumAngle();
00355   else if (myComboBoxFunctor->currentText() == tr("TAPER_ELEMENTS"))
00356     aNF = aFilterMgr->CreateTaper();
00357   else if (myComboBoxFunctor->currentText() == tr("SKEW_ELEMENTS"))
00358     aNF = aFilterMgr->CreateSkew();
00359   else if (myComboBoxFunctor->currentText() == tr("AREA_ELEMENTS"))
00360     aNF = aFilterMgr->CreateArea();
00361   else if (myComboBoxFunctor->currentText() == tr("LENGTH2D_EDGES"))
00362     aNF = aFilterMgr->CreateLength2D();
00363   else if (myComboBoxFunctor->currentText() == tr("MULTI2D_BORDERS"))
00364     aNF = aFilterMgr->CreateMultiConnection2D();
00365   else;
00366 
00367   return aNF._retn();
00368 }
00369 
00370 //=======================================================================
00371 // name    : SMESHGUI_MultiEditDlg::Init
00372 // Purpose : Init dialog fields, connect signals and slots, show dialog
00373 //=======================================================================
00374 void SMESHGUI_MultiEditDlg::Init()
00375 {
00376   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00377   myListBox->clear();
00378   myIds.Clear();
00379   myBusy = false;
00380   myActor = 0;
00381   emit ListContensChanged();
00382 
00383   // main buttons
00384   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
00385   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
00386   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
00387   connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
00388 
00389   // selection and SMESHGUI
00390   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
00391   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
00392   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
00393 
00394   // dialog controls
00395   connect(myFilterBtn, SIGNAL(clicked()), SLOT(onFilterBtn()  ));
00396   connect(myAddBtn,    SIGNAL(clicked()), SLOT(onAddBtn()     ));
00397   connect(myRemoveBtn, SIGNAL(clicked()), SLOT(onRemoveBtn()  ));
00398   connect(mySortBtn,   SIGNAL(clicked()), SLOT(onSortListBtn()));
00399 
00400   connect(mySubmeshChk, SIGNAL(stateChanged(int)), SLOT(onSubmeshChk()));
00401   connect(myGroupChk,   SIGNAL(stateChanged(int)), SLOT(onGroupChk()  ));
00402   connect(myToAllChk,   SIGNAL(stateChanged(int)), SLOT(onToAllChk()  ));
00403 
00404   if (myEntityTypeGrp)
00405     connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), SLOT(on3d2dChanged(int)));
00406 
00407   connect(myListBox, SIGNAL(itemSelectionChanged()), SLOT(onListSelectionChanged()));
00408 
00409   onSelectionDone();
00410 
00411   // set selection mode
00412   setSelectionMode();
00413   updateButtons();
00414 }
00415 
00416 //=======================================================================
00417 // name    : SMESHGUI_MultiEditDlg::onOk
00418 // Purpose : SLOT called when "Ok" button pressed.
00419 //           Assign filters VTK viewer and close dialog
00420 //=======================================================================
00421 void SMESHGUI_MultiEditDlg::onOk()
00422 {
00423   if (onApply())
00424     onClose();
00425 }
00426 
00427 //=======================================================================
00428 // name    : SMESHGUI_MultiEditDlg::getIds
00429 // Purpose : Retrive identifiers from list box or the whole object
00430 //=======================================================================
00431 
00432 SMESH::long_array_var SMESHGUI_MultiEditDlg::getIds(SMESH::SMESH_IDSource_var& obj)
00433 {
00434   SMESH::long_array_var anIds = new SMESH::long_array;
00435 
00436   if (myToAllChk->isChecked())
00437   {
00438     myIds.Clear();
00439     obj = SMESH::SMESH_IDSource::_narrow( myMesh );
00440 //     SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
00441 //     if (!anActor)
00442 //       anActor = myActor;
00443 //     if (anActor != 0)
00444 //     {
00445 //       // skl 07.02.2006
00446 //       SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
00447 //       if( myFilterType == SMESH::TriaFilter || 
00448 //           myFilterType == SMESH::QuadFilter ||
00449 //           myFilterType == SMESH::FaceFilter ) {
00450 //         SMDS_FaceIteratorPtr it = aMesh->facesIterator();
00451 //         while(it->more()) {
00452 //           const SMDS_MeshFace* f = it->next();
00453 //           if(myFilterType == SMESH::FaceFilter) {
00454 //             myIds.Add(f->GetID());
00455 //           }
00456 //           else if( myFilterType==SMESH::TriaFilter &&
00457 //                    ( f->NbNodes()==3 || f->NbNodes()==6 ) ) {
00458 //             myIds.Add(f->GetID());
00459 //           }
00460 //           else if( myFilterType==SMESH::QuadFilter &&
00461 //                    ( f->NbNodes()==4 || f->NbNodes()==8 ) ) {
00462 //             myIds.Add(f->GetID());
00463 //           }
00464 //         }
00465 //       }
00466 //       else if(myFilterType == SMESH::VolumeFilter) {
00467 //         SMDS_VolumeIteratorPtr it = aMesh->volumesIterator();
00468 //         while(it->more()) {
00469 //           const SMDS_MeshVolume* f = it->next();
00470 //           myIds.Add(f->GetID());
00471 //         }
00472 //       }
00473       /* commented by skl 07.02.2006 - to work with quadratic elements
00474       TVisualObjPtr aVisualObj = anActor->GetObject();
00475       vtkUnstructuredGrid* aGrid = aVisualObj->GetUnstructuredGrid();
00476       if (aGrid != 0) {
00477         for (int i = 0, n = aGrid->GetNumberOfCells(); i < n; i++) {
00478           vtkCell* aCell = aGrid->GetCell(i);
00479           if (aCell != 0) {
00480             vtkTriangle* aTri = vtkTriangle::SafeDownCast(aCell);
00481             vtkQuad*     aQua = vtkQuad::SafeDownCast(aCell);
00482             vtkPolygon*  aPG  = vtkPolygon::SafeDownCast(aCell);
00483 
00484             vtkCell3D*   a3d  = vtkCell3D::SafeDownCast(aCell);
00485             vtkConvexPointSet* aPH = vtkConvexPointSet::SafeDownCast(aCell);
00486 
00487             if (aTri && myFilterType == SMESHGUI_TriaFilter ||
00488                 aQua && myFilterType == SMESHGUI_QuadFilter ||
00489                 (aTri || aQua || aPG) && myFilterType == SMESHGUI_FaceFilter ||
00490                 (a3d || aPH) && myFilterType == SMESHGUI_VolumeFilter) {
00491               int anObjId = aVisualObj->GetElemObjId(i);
00492               myIds.Add(anObjId);
00493             }
00494           }
00495         }
00496       }
00497       */
00498     //}
00499   }
00500 
00501   anIds->length(myIds.Extent());
00502   TColStd_MapIteratorOfMapOfInteger anIter(myIds);
00503   for (int i = 0; anIter.More(); anIter.Next() )
00504   {
00505     anIds[ i++ ] = anIter.Key();
00506   }
00507   return anIds._retn();
00508 }
00509 
00510 //=======================================================================
00511 // name    : SMESHGUI_MultiEditDlg::onClose
00512 // Purpose : SLOT called when "Close" button pressed. Close dialog
00513 //=======================================================================
00514 void SMESHGUI_MultiEditDlg::onClose()
00515 {
00516   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00517     aViewWindow->SetSelectionMode(ActorSelection);
00518   disconnect(mySelectionMgr, 0, this, 0);
00519   disconnect(mySMESHGUI, 0, this, 0);
00520   mySMESHGUI->ResetState();
00521 
00522   SMESH::RemoveFilters();
00523   SMESH::SetPickable();
00524 
00525   //mySelectionMgr->clearSelected();
00526   mySelectionMgr->clearFilters();
00527 
00528   reject();
00529 }
00530 
00531 //=================================================================================
00532 // function : onHelp()
00533 // purpose  :
00534 //=================================================================================
00535 void SMESHGUI_MultiEditDlg::onHelp()
00536 {
00537   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00538   if (app) 
00539     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00540   else {
00541     QString platform;
00542 #ifdef WIN32
00543     platform = "winapplication";
00544 #else
00545     platform = "application";
00546 #endif
00547     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00548                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00549                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00550                                                                  platform)).
00551                              arg(myHelpFileName));
00552   }
00553 }
00554 
00555 //=======================================================================
00556 // name    : SMESHGUI_MultiEditDlg::onSelectionDone
00557 // Purpose : SLOT called when selection changed
00558 //=======================================================================
00559 void SMESHGUI_MultiEditDlg::onSelectionDone()
00560 {
00561   if (myBusy || !isEnabled()) return;
00562   myBusy = true;
00563 
00564   const SALOME_ListIO& aList = mySelector->StoredIObjects();
00565 
00566   int nbSel = aList.Extent();
00567   myListBox->clearSelection();
00568 
00569   if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
00570     QLineEdit* aNameEdit = mySubmeshChk->isChecked() ? mySubmesh : myGroup;
00571     if (nbSel == 1) {
00572       Handle(SALOME_InteractiveObject) anIO = aList.First();
00573       QString aName = "";
00574       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
00575       anIO.IsNull() ? aNameEdit->clear() : aNameEdit->setText(aName);
00576 
00577       if (mySubmeshChk->isChecked()) {
00578         SMESH::SMESH_subMesh_var aSubMesh =
00579           SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIO);
00580         if (!aSubMesh->_is_nil())
00581           myMesh = aSubMesh->GetFather();
00582       } else {
00583         SMESH::SMESH_GroupBase_var aGroup =
00584           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIO);
00585         if (!aGroup->_is_nil())
00586           myMesh = aGroup->GetMesh();
00587       }
00588     } else if (nbSel > 1) {
00589       QString aStr = mySubmeshChk->isChecked() ?
00590         tr("SMESH_SUBMESH_SELECTED") : tr("SMESH_GROUP_SELECTED");
00591       aNameEdit->setText(aStr.arg(nbSel));
00592     } else {
00593       aNameEdit->clear();
00594     }
00595   } else if (nbSel > 0) {
00596     QString aListStr = "";
00597     Handle(SALOME_InteractiveObject) anIO = aList.First();
00598     int aNbItems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aListStr);
00599     if (aNbItems > 0) {
00600       QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
00601       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
00602         QList<QListWidgetItem*> items = myListBox->findItems(*it, Qt::MatchExactly);
00603         QListWidgetItem* anItem;
00604         foreach(anItem, items)
00605           anItem->setSelected(true);
00606       }
00607     }
00608     myMesh = SMESH::GetMeshByIO(anIO);
00609   }
00610 
00611   if (nbSel > 0) {
00612     myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
00613     if (!myActor)
00614       myActor = SMESH::FindActorByObject(myMesh);
00615     SVTK_Selector* aSelector = SMESH::GetSelector();
00616     Handle(VTKViewer_Filter) aFilter = aSelector->GetFilter(myFilterType);
00617     if (!aFilter.IsNull())
00618       aFilter->SetActor(myActor);
00619   }
00620   myBusy = false;
00621 
00622   updateButtons();
00623 }
00624 
00625 //=======================================================================
00626 // name    : SMESHGUI_MultiEditDlg::onDeactivate
00627 // Purpose : SLOT called when dialog must be deativated
00628 //=======================================================================
00629 void SMESHGUI_MultiEditDlg::onDeactivate()
00630 {
00631   setEnabled(false);
00632 }
00633 
00634 //=======================================================================
00635 // name    : SMESHGUI_MultiEditDlg::enterEvent
00636 // Purpose : Event filter
00637 //=======================================================================
00638 void SMESHGUI_MultiEditDlg::enterEvent (QEvent*)
00639 {
00640   if (!isEnabled()) {
00641     mySMESHGUI->EmitSignalDeactivateDialog();
00642     setEnabled(true);
00643     setSelectionMode();
00644   }
00645 }
00646 
00647 //=======================================================================
00648 // name    : SMESHGUI_MultiEditDlg::closeEvent
00649 // Purpose :
00650 //=======================================================================
00651 void SMESHGUI_MultiEditDlg::closeEvent (QCloseEvent*)
00652 {
00653   onClose();
00654 }
00655 //=======================================================================
00656 // name    : SMESHGUI_MultiEditDlg::hideEvent
00657 // Purpose : caused by ESC key
00658 //=======================================================================
00659 void SMESHGUI_MultiEditDlg::hideEvent (QHideEvent*)
00660 {
00661   if (!isMinimized())
00662     onClose();
00663 }
00664 
00665 //=======================================================================
00666 // name    : SMESHGUI_MultiEditDlg::onFilterBtn
00667 // Purpose : SLOT. Called when "Filter" button pressed.
00668 //           Start "Selection filters" dialog
00669 //=======================================================================
00670 void SMESHGUI_MultiEditDlg::onFilterBtn()
00671 {
00672   if (myFilterDlg == 0) {
00673     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, entityType() ? SMESH::VOLUME : SMESH::FACE);
00674     connect(myFilterDlg, SIGNAL(Accepted()), SLOT(onFilterAccepted()));
00675   } else {
00676     myFilterDlg->Init(entityType() ? SMESH::VOLUME : SMESH::FACE);
00677   }
00678 
00679   myFilterDlg->SetSelection();
00680   myFilterDlg->SetMesh(myMesh);
00681   myFilterDlg->SetSourceWg(myListBox);
00682 
00683   myFilterDlg->show();
00684 }
00685 
00686 //=======================================================================
00687 // name    : onFilterAccepted()
00688 // Purpose : SLOT. Called when Filter dlg closed with OK button.
00689 //            Uncheck "Select submesh" and "Select group" checkboxes
00690 //=======================================================================
00691 void SMESHGUI_MultiEditDlg::onFilterAccepted()
00692 {
00693   myIds.Clear();
00694   for (int i = 0, n = myListBox->count(); i < n; i++)
00695     myIds.Add(myListBox->item(i)->text().toInt());
00696 
00697   emit ListContensChanged();
00698 
00699   if (mySubmeshChk->isChecked() || myGroupChk->isChecked()) {
00700     mySubmeshChk->blockSignals(true);
00701     myGroupChk->blockSignals(true);
00702     mySubmeshChk->setChecked(false);
00703     myGroupChk->setChecked(false);
00704     mySubmeshChk->blockSignals(false);
00705     myGroupChk->blockSignals(false);
00706   }
00707   updateButtons();
00708 }
00709 
00710 //=======================================================================
00711 // name    : SMESHGUI_MultiEditDlg::isIdValid
00712 // Purpose : Verify whether Id of element satisfies to filters from viewer
00713 //=======================================================================
00714 bool SMESHGUI_MultiEditDlg::isIdValid (const int theId) const
00715 {
00716   SVTK_Selector* aSelector = SMESH::GetSelector();
00717   Handle(SMESHGUI_Filter) aFilter =
00718     Handle(SMESHGUI_Filter)::DownCast(aSelector->GetFilter(myFilterType));
00719 
00720   return (!aFilter.IsNull() && aFilter->IsObjValid(theId));
00721 }
00722 
00723 //=======================================================================
00724 // name    : SMESHGUI_MultiEditDlg::onAddBtn
00725 // Purpose : SLOT. Called when "Add" button pressed.
00726 //           Add selected in viewer entities in list box
00727 //=======================================================================
00728 void SMESHGUI_MultiEditDlg::onAddBtn()
00729 {
00730   const SALOME_ListIO& aList = mySelector->StoredIObjects();
00731 
00732   int nbSelected = aList.Extent();
00733   if (nbSelected == 0)
00734     return;
00735 
00736   TColStd_IndexedMapOfInteger toBeAdded;
00737 
00738   if (!mySubmeshChk->isChecked() && !myGroupChk->isChecked()) {
00739     if (nbSelected > 0)
00740       mySelector->GetIndex(aList.First(),toBeAdded);
00741   } else if (mySubmeshChk->isChecked()) {
00742     SALOME_ListIteratorOfListIO anIter(aList);
00743     for ( ; anIter.More(); anIter.Next()) {
00744       SMESH::SMESH_subMesh_var aSubMesh =
00745         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Value());
00746       if (!aSubMesh->_is_nil()) {
00747         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
00748           SMESH::long_array_var anIds = aSubMesh->GetElementsId();
00749           for (int i = 0, n = anIds->length(); i < n; i++) {
00750             if (isIdValid(anIds[ i ]))
00751               toBeAdded.Add(anIds[ i ]);
00752           }
00753         }
00754       }
00755     }
00756   } else if (myGroupChk->isChecked()) {
00757     SALOME_ListIteratorOfListIO anIter(aList);
00758     for ( ; anIter.More(); anIter.Next()) {
00759       SMESH::SMESH_GroupBase_var aGroup =
00760         SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
00761       if (!aGroup->_is_nil() && ((aGroup->GetType() == SMESH::FACE && entityType() == 0) || 
00762                                  (aGroup->GetType() == SMESH::VOLUME && entityType() == 1))) {
00763         if (aGroup->GetMesh()->GetId() == myMesh->GetId()) {
00764           SMESH::long_array_var anIds = aGroup->GetListOfID();
00765           for (int i = 0, n = anIds->length(); i < n; i++) {
00766             if (isIdValid(anIds[ i ]))
00767               toBeAdded.Add(anIds[ i ]);
00768           }
00769         }
00770       }
00771     }
00772   } else {
00773   }
00774 
00775   myBusy = true;
00776   bool isGroupOrSubmesh = (mySubmeshChk->isChecked() || myGroupChk->isChecked());
00777   mySubmeshChk->setChecked(false);
00778   myGroupChk->setChecked(false);
00779   QStringList items;
00780   for(int i = 1; i <= toBeAdded.Extent(); i++)
00781     if (myIds.Add(toBeAdded(i))) {
00782       items.append(QString("%1").arg(toBeAdded(i)));
00783     }
00784   myListBox->addItems(items);
00785   myListBox->selectAll();
00786   myBusy = false;
00787 
00788   emit ListContensChanged();
00789 
00790   if (isGroupOrSubmesh)
00791     onListSelectionChanged();
00792 
00793   updateButtons();
00794 }
00795 
00796 //=======================================================================
00797 // name    : SMESHGUI_MultiEditDlg::updateButtons
00798 // Purpose : Enable/disable buttons of dialog in accordance with current state
00799 //=======================================================================
00800 void SMESHGUI_MultiEditDlg::updateButtons()
00801 {
00802   bool isOk = isValid(false);
00803   myOkBtn->setEnabled(isOk);
00804   myApplyBtn->setEnabled(isOk);
00805 
00806   bool isListBoxNonEmpty = myListBox->count() > 0;
00807   bool isToAll = myToAllChk->isChecked();
00808   myFilterBtn->setEnabled(!isToAll);
00809   myRemoveBtn->setEnabled(isListBoxNonEmpty && !isToAll);
00810   mySortBtn->setEnabled(isListBoxNonEmpty &&!isToAll);
00811 
00812   const SALOME_ListIO& aList = mySelector->StoredIObjects();
00813 
00814   if (isToAll ||
00815       myMesh->_is_nil() ||
00816       aList.Extent() < 1 ||
00817       (SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(aList.First())->_is_nil() &&
00818        SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(aList.First())->_is_nil() &&
00819        SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First())->_is_nil()))
00820     myAddBtn->setEnabled(false);
00821   else
00822     myAddBtn->setEnabled(true);
00823 
00824   mySubmeshChk->setEnabled(!isToAll);
00825   mySubmeshBtn->setEnabled(mySubmeshChk->isChecked());
00826   mySubmesh->setEnabled(mySubmeshChk->isChecked());
00827 
00828   myGroupChk->setEnabled(!isToAll);
00829   myGroupBtn->setEnabled(myGroupChk->isChecked());
00830   myGroup->setEnabled(myGroupChk->isChecked());
00831 
00832   if (!mySubmeshChk->isChecked())
00833     mySubmesh->clear();
00834   if (!myGroupChk->isChecked())
00835     myGroup->clear();
00836 
00837 }
00838 
00839 //=======================================================================
00840 // name    : SMESHGUI_MultiEditDlg::onRemoveBtn
00841 // Purpose : SLOT. Called when "Remove" button pressed.
00842 //           Remove selected in list box entities
00843 //=======================================================================
00844 void SMESHGUI_MultiEditDlg::onRemoveBtn()
00845 {
00846   myBusy = true;
00847 
00848   QList<QListWidgetItem*> selItems = myListBox->selectedItems();
00849   QListWidgetItem* item;
00850   foreach(item, selItems)
00851   {
00852     myIds.Remove(item->text().toInt());
00853     delete item;
00854   }
00855 
00856   myBusy = false;
00857 
00858   emit ListContensChanged();
00859   updateButtons();
00860 }
00861 
00862 //=======================================================================
00863 // name    : SMESHGUI_MultiEditDlg::onSortListBtn
00864 // Purpose : SLOT. Called when "Sort list" button pressed.
00865 //           Sort entities of list box
00866 //=======================================================================
00867 void SMESHGUI_MultiEditDlg::onSortListBtn()
00868 {
00869   myBusy = true;
00870 
00871   int i, k = myListBox->count();
00872   if (k > 0)
00873   {
00874     QList<int> aSelected;
00875     std::vector<int> anArray(k);
00876     for (i = 0; i < k; i++)
00877     {
00878       int id = myListBox->item(i)->text().toInt();
00879       anArray[ i ] = id;
00880       if (myListBox->item(i)->isSelected())
00881         aSelected.append(id);
00882     }
00883 
00884     std::sort(anArray.begin(), anArray.end());
00885 
00886     myListBox->clear();
00887     for (i = 0; i < k; i++) {
00888       QListWidgetItem* item = new QListWidgetItem(QString::number(anArray[i]));
00889       myListBox->addItem(item);
00890       item->setSelected(aSelected.contains(anArray[i]));
00891     }
00892   }
00893   myBusy = false;
00894 }
00895 
00896 //=======================================================================
00897 // name    : SMESHGUI_MultiEditDlg::onListSelectionChanged
00898 // Purpose : SLOT. Called when selection in list box changed.
00899 //           Highlight in selected entities
00900 //=======================================================================
00901 void SMESHGUI_MultiEditDlg::onListSelectionChanged()
00902 {
00903   if (myActor == 0 || myBusy)
00904     return;
00905 
00906   if (mySubmeshChk->isChecked() || myGroupChk->isChecked())
00907     return;
00908 
00909   SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
00910   if (!anActor)
00911     anActor = myActor;
00912   TVisualObjPtr anObj = anActor->GetObject();
00913 
00914   TColStd_MapOfInteger anIndexes;
00915   int total = myListBox->count();
00916   for (int i = 0; i < total; i++)
00917   {
00918     if (myListBox->item(i)->isSelected())
00919     {
00920       int anId = myListBox->item(i)->text().toInt();
00921       if (anObj->GetElemVTKId(anId) >= 0) // avoid exception in hilight
00922         anIndexes.Add(anId);
00923     }
00924   }
00925 
00926   mySelector->AddOrRemoveIndex(anActor->getIO(),anIndexes,false);
00927   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00928     aViewWindow->highlight(anActor->getIO(),true,true);
00929 }
00930 
00931 //=======================================================================
00932 // name    : SMESHGUI_MultiEditDlg::onSubmeshChk
00933 // Purpose : SLOT. Called when state of "SubMesh" check box changed.
00934 //           Activate/deactivate selection of submeshes
00935 //=======================================================================
00936 void SMESHGUI_MultiEditDlg::onSubmeshChk()
00937 {
00938   bool isChecked = mySubmeshChk->isChecked();
00939   mySubmeshBtn->setEnabled(isChecked);
00940   mySubmesh->setEnabled(isChecked);
00941   if (!isChecked)
00942     mySubmesh->clear();
00943   if (isChecked && myGroupChk->isChecked())
00944       myGroupChk->setChecked(false);
00945 
00946   setSelectionMode();
00947 }
00948 
00949 //=======================================================================
00950 // name    : SMESHGUI_MultiEditDlg::onGroupChk
00951 // Purpose : SLOT. Called when state of "Group" check box changed.
00952 //           Activate/deactivate selection of groupes
00953 //=======================================================================
00954 void SMESHGUI_MultiEditDlg::onGroupChk()
00955 {
00956   bool isChecked = myGroupChk->isChecked();
00957   myGroupBtn->setEnabled(isChecked);
00958   myGroup->setEnabled(isChecked);
00959   if (!isChecked)
00960     myGroup->clear();
00961   if (isChecked && mySubmeshChk->isChecked())
00962       mySubmeshChk->setChecked(false);
00963 
00964   setSelectionMode();
00965 }
00966 
00967 //=======================================================================
00968 // name    : SMESHGUI_MultiEditDlg::onToAllChk
00969 // Purpose : SLOT. Called when state of "Apply to all" check box changed.
00970 //           Activate/deactivate selection
00971 //=======================================================================
00972 void SMESHGUI_MultiEditDlg::onToAllChk()
00973 {
00974   bool isChecked = myToAllChk->isChecked();
00975 
00976   if (isChecked)
00977     myListBox->clear();
00978 
00979   myIds.Clear();
00980 
00981   emit ListContensChanged();
00982 
00983   updateButtons();
00984   setSelectionMode();
00985 }
00986 
00987 //=======================================================================
00988 // name    : SMESHGUI_MultiEditDlg::setSelectionMode
00989 // Purpose : Set selection mode
00990 //=======================================================================
00991 void SMESHGUI_MultiEditDlg::setSelectionMode()
00992 {
00993   SMESH::RemoveFilters();
00994 
00995   mySelectionMgr->clearSelected();
00996   mySelectionMgr->clearFilters();
00997 
00998   if (mySubmeshChk->isChecked()) {
00999     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01000       aViewWindow->SetSelectionMode(ActorSelection);
01001     mySelectionMgr->installFilter(new SMESH_TypeFilter(SUBMESH));
01002   }
01003   else if (myGroupChk->isChecked()) {
01004     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01005       aViewWindow->SetSelectionMode(ActorSelection);
01006     mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
01007   }
01008 
01009   if (entityType()) {
01010     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01011       aViewWindow->SetSelectionMode(VolumeSelection);
01012     SMESH::SetFilter(new SMESHGUI_VolumesFilter());
01013   } else {
01014     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01015       aViewWindow->SetSelectionMode(FaceSelection);
01016     if (myFilterType == SMESH::TriaFilter)
01017       SMESH::SetFilter(new SMESHGUI_TriangleFilter());
01018     else if (myFilterType == SMESH::QuadFilter)
01019       SMESH::SetFilter(new SMESHGUI_QuadrangleFilter());
01020     else
01021       SMESH::SetFilter(new SMESHGUI_FacesFilter());
01022   }
01023 }
01024 
01025 //=======================================================================
01026 // name    : SMESHGUI_MultiEditDlg::onApply
01027 // Purpose : SLOT. Called when "Apply" button clicked.
01028 //=======================================================================
01029 bool SMESHGUI_MultiEditDlg::onApply()
01030 {
01031   if (mySMESHGUI->isActiveStudyLocked())
01032     return false;
01033   if (!isValid(true))
01034     return false;
01035 
01036   SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
01037   if (aMeshEditor->_is_nil())
01038     return false;
01039 
01040   myBusy = true;
01041 
01042   SUIT_OverrideCursor aWaitCursor;
01043 
01044   SMESH::SMESH_IDSource_var obj;
01045   SMESH::long_array_var anIds = getIds(obj);
01046 
01047   bool aResult = process(aMeshEditor, anIds.inout(), obj);
01048   if (aResult) {
01049     if (myActor) {
01050       SALOME_ListIO sel;
01051       mySelectionMgr->selectedObjects( sel );
01052       mySelector->ClearIndex();
01053       mySelectionMgr->setSelectedObjects( sel );
01054       SMESH::UpdateView();
01055       SMESHGUI::Modified();
01056     }
01057 
01058     myListBox->clear();
01059     myIds.Clear();
01060     emit ListContensChanged();
01061 
01062     updateButtons();
01063   }
01064 
01065   myBusy = false;
01066   return aResult;
01067 }
01068 
01069 //=======================================================================
01070 // name    : SMESHGUI_MultiEditDlg::on3d2dChanged
01071 // Purpose :
01072 //=======================================================================
01073 void SMESHGUI_MultiEditDlg::on3d2dChanged (int type)
01074 {
01075   if (myEntityType != type) {
01076     myEntityType = type;
01077 
01078     myListBox->clear();
01079     myIds.Clear();
01080 
01081     emit ListContensChanged();
01082 
01083     if (type)
01084       myFilterType = SMESH::VolumeFilter;
01085     else
01086       myFilterType = SMESH::FaceFilter;
01087 
01088     updateButtons();
01089     setSelectionMode();
01090   }
01091 }
01092 
01093 //=======================================================================
01094 // name    : SMESHGUI_MultiEditDlg::entityType
01095 // Purpose :
01096 //=======================================================================
01097 int SMESHGUI_MultiEditDlg::entityType()
01098 {
01099   return myEntityType;
01100 }
01101 
01102 //=================================================================================
01103 // function : keyPressEvent()
01104 // purpose  :
01105 //=================================================================================
01106 void SMESHGUI_MultiEditDlg::keyPressEvent( QKeyEvent* e )
01107 {
01108   QDialog::keyPressEvent( e );
01109   if ( e->isAccepted() )
01110     return;
01111 
01112   if ( e->key() == Qt::Key_F1 ) {
01113     e->accept();
01114     onHelp();
01115   }
01116 }
01117 
01123 SMESHGUI_ChangeOrientationDlg
01124 ::SMESHGUI_ChangeOrientationDlg(SMESHGUI* theModule):
01125   SMESHGUI_MultiEditDlg(theModule, SMESH::FaceFilter, true)
01126 {
01127   setWindowTitle(tr("CAPTION"));
01128   myHelpFileName = "changing_orientation_of_elements_page.html";
01129 }
01130 
01131 SMESHGUI_ChangeOrientationDlg::~SMESHGUI_ChangeOrientationDlg()
01132 {
01133 }
01134 
01135 bool SMESHGUI_ChangeOrientationDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
01136                                              const SMESH::long_array&    theIds,
01137                                              SMESH::SMESH_IDSource_ptr   obj)
01138 {
01139   if ( CORBA::is_nil( obj ))
01140     return theEditor->Reorient(theIds);
01141   else
01142     return theEditor->ReorientObject( obj );
01143 }
01144 
01150 SMESHGUI_UnionOfTrianglesDlg
01151 ::SMESHGUI_UnionOfTrianglesDlg(SMESHGUI* theModule):
01152   SMESHGUI_MultiEditDlg(theModule, SMESH::TriaFilter, false)
01153 {
01154   setWindowTitle(tr("CAPTION"));
01155 
01156   myComboBoxFunctor->setEnabled(true);
01157   myComboBoxFunctor->addItem(tr("WARP_ELEMENTS")); // for quadrangles only
01158   myComboBoxFunctor->addItem(tr("TAPER_ELEMENTS")); // for quadrangles only
01159 
01160   // Maximum angle
01161   QWidget* aMaxAngleGrp = new QWidget(myCriterionGrp);
01162   QHBoxLayout* aMaxAngleGrpLayout = new QHBoxLayout(aMaxAngleGrp);
01163   aMaxAngleGrpLayout->setMargin(0);
01164   aMaxAngleGrpLayout->setSpacing(SPACING);
01165 
01166   QLabel* aLab = new QLabel (tr("MAXIMUM_ANGLE"), aMaxAngleGrp);
01167   myMaxAngleSpin = new SMESHGUI_SpinBox (aMaxAngleGrp);
01168   myMaxAngleSpin->RangeStepAndValidator(0, 180.0, 1.0, "angle_precision");
01169   myMaxAngleSpin->SetValue(30.0);
01170 
01171   aMaxAngleGrpLayout->addWidget(aLab);
01172   aMaxAngleGrpLayout->addWidget(myMaxAngleSpin);
01173 
01174   ((QVBoxLayout*)(myCriterionGrp->layout()))->addWidget(aMaxAngleGrp);
01175   myCriterionGrp->show();
01176 
01177   myHelpFileName = "uniting_set_of_triangles_page.html";
01178 }
01179 
01180 SMESHGUI_UnionOfTrianglesDlg::~SMESHGUI_UnionOfTrianglesDlg()
01181 {
01182 }
01183 
01184 bool SMESHGUI_UnionOfTrianglesDlg::isValid (const bool theMess)
01185 {
01186   bool ok = SMESHGUI_MultiEditDlg::isValid( theMess );
01187   if( !ok )
01188     return false;
01189 
01190   QString msg;
01191   ok = myMaxAngleSpin->isValid( msg, theMess );
01192   if( !ok ) {
01193     if( theMess ) {
01194       QString str( tr( "SMESH_INCORRECT_INPUT" ) );
01195       if ( !msg.isEmpty() )
01196         str += "\n" + msg;
01197       SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
01198     }
01199     return false;
01200   }
01201 
01202   return ok;
01203 }
01204 
01205 bool SMESHGUI_UnionOfTrianglesDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
01206                                             const SMESH::long_array&    theIds,
01207                                             SMESH::SMESH_IDSource_ptr   obj)
01208 {
01209   {
01210     QStringList aParameters;
01211     aParameters << myMaxAngleSpin->text();
01212     myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
01213   }
01214   SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
01215   double aMaxAngle = myMaxAngleSpin->GetValue() * M_PI / 180.0;
01216   bool ok;
01217   if ( CORBA::is_nil( obj ))
01218     ok = theEditor->TriToQuad(theIds, aCriterion, aMaxAngle);
01219   else
01220     ok = theEditor->TriToQuadObject(obj, aCriterion, aMaxAngle);
01221   return ok;
01222 }
01223 
01224 
01230 SMESHGUI_CuttingOfQuadsDlg
01231 ::SMESHGUI_CuttingOfQuadsDlg(SMESHGUI* theModule):
01232   SMESHGUI_MultiEditDlg(theModule, SMESH::QuadFilter, false)
01233 {
01234   setWindowTitle(tr("CAPTION"));
01235   myPreviewActor = 0;
01236 
01237   myPreviewChk = new QCheckBox (tr("PREVIEW"), mySelGrp);
01238   QGridLayout* aLay = (QGridLayout*)(mySelGrp->layout());
01239   aLay->addWidget(myPreviewChk, aLay->rowCount(), 0, 1, aLay->columnCount());
01240 
01241   myCriterionGrp->show();
01242   myChoiceWidget->show();
01243   myComboBoxFunctor->setEnabled(false);
01244 
01245   connect(myPreviewChk,      SIGNAL(stateChanged(int)),    this, SLOT(onPreviewChk()));
01246   connect(myGroupChoice,     SIGNAL(buttonClicked(int)),   this, SLOT(onCriterionRB()));
01247   connect(myComboBoxFunctor, SIGNAL(activated(int)),       this, SLOT(onPreviewChk()));
01248   connect(this,              SIGNAL(ListContensChanged()), this, SLOT(onPreviewChk()));
01249 
01250   myHelpFileName = "cutting_quadrangles_page.html";
01251 }
01252 
01253 SMESHGUI_CuttingOfQuadsDlg::~SMESHGUI_CuttingOfQuadsDlg()
01254 {
01255 }
01256 
01257 void SMESHGUI_CuttingOfQuadsDlg::onClose()
01258 {
01259   erasePreview();
01260   SMESHGUI_MultiEditDlg::onClose();
01261 }
01262 
01263 bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
01264                                           const SMESH::long_array&    theIds,
01265                                           SMESH::SMESH_IDSource_ptr   obj)
01266 {
01267   bool hasObj = (! CORBA::is_nil( obj ));
01268   switch (myGroupChoice->checkedId()) {
01269   case 0: // use diagonal 1-3
01270     return hasObj ? theEditor->SplitQuadObject(obj, true) : theEditor->SplitQuad(theIds, true);
01271   case 1: // use diagonal 2-4
01272     return hasObj ? theEditor->SplitQuadObject(obj, false) : theEditor->SplitQuad(theIds, false);
01273   default: // use numeric functor
01274     break;
01275   }
01276 
01277   SMESH::NumericalFunctor_var aCrit = getNumericalFunctor();
01278   return hasObj ? theEditor->QuadToTriObject(obj, aCrit) : theEditor->QuadToTri(theIds, aCrit);
01279 }
01280 
01281 void SMESHGUI_CuttingOfQuadsDlg::onCriterionRB()
01282 {
01283   if (myGroupChoice->checkedId() == 2) // Use numeric functor
01284     myComboBoxFunctor->setEnabled(true);
01285   else
01286     myComboBoxFunctor->setEnabled(false);
01287 
01288   onPreviewChk();
01289 }
01290 
01291 void SMESHGUI_CuttingOfQuadsDlg::onPreviewChk()
01292 {
01293   myPreviewChk->isChecked() ? displayPreview() : erasePreview();
01294 }
01295 
01296 void SMESHGUI_CuttingOfQuadsDlg::erasePreview()
01297 {
01298   if (myPreviewActor == 0)
01299     return;
01300 
01301   if (SVTK_ViewWindow* vf = SMESH::GetCurrentVtkView()) {
01302     vf->RemoveActor(myPreviewActor);
01303     vf->Repaint();
01304   }
01305   myPreviewActor->Delete();
01306   myPreviewActor = 0;
01307 }
01308   
01309 void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
01310 {
01311   if (myActor == 0)
01312     return;
01313 
01314   if (myPreviewActor != 0)
01315     erasePreview();
01316 
01317   // get Ids of elements
01318   SMESH::SMESH_IDSource_var obj;
01319   SMESH::long_array_var anElemIds = getIds(obj);
01320   if (anElemIds->length() == 0 && obj->_is_nil() )
01321     return;
01322 
01323   SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
01324   if (aMesh == 0)
01325     return;
01326 
01327   // 0 - use diagonal 1-3, 1 - use diagonal 2-4, 2 - use numerical functor
01328   int aChoice = myGroupChoice->checkedId();
01329   SMESH::NumericalFunctor_var aCriterion  = SMESH::NumericalFunctor::_nil();
01330   SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH::SMESH_MeshEditor::_nil();
01331   if (aChoice == 2) {
01332     aCriterion  = getNumericalFunctor();
01333     aMeshEditor = myMesh->GetMeshEditor();
01334     if (aMeshEditor->_is_nil())
01335       return;
01336   }
01337 
01338   //Create grid
01339   vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
01340 
01341   vtkIdType aNbCells = anElemIds->length() * 2;
01342   vtkIdType aCellsSize = 4 * aNbCells;
01343   vtkCellArray* aConnectivity = vtkCellArray::New();
01344   aConnectivity->Allocate(aCellsSize, 0);
01345 
01346   vtkPoints* aPoints = vtkPoints::New();
01347   aPoints->SetNumberOfPoints(anElemIds->length() * 4);
01348 
01349   vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
01350   aCellTypesArray->SetNumberOfComponents(1);
01351   aCellTypesArray->Allocate(aNbCells * aCellTypesArray->GetNumberOfComponents());
01352 
01353   vtkIdList *anIdList = vtkIdList::New();
01354   anIdList->SetNumberOfIds(3);
01355 
01356   TColStd_DataMapOfIntegerInteger anIdToVtk;
01357 
01358   int aNodes[ 4 ];
01359   int nbPoints = -1;
01360   for (int i = 0, n = anElemIds->length(); i < n; i++)
01361   {
01362     const SMDS_MeshElement* anElem = aMesh->FindElement(anElemIds[ i ]);
01363     if (anElem == 0 || anElem->NbNodes() != 4)
01364       continue;
01365 
01366     SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
01367     int k = 0;
01368     while (anIter->more()) {
01369       const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIter->next());
01370       if (aNode)
01371       {
01372         if (!anIdToVtk.IsBound(aNode->GetID()))
01373         {
01374           aPoints->SetPoint(++nbPoints, aNode->X(), aNode->Y(), aNode->Z());
01375           anIdToVtk.Bind(aNode->GetID(), nbPoints);
01376         }
01377 
01378         aNodes[ k++ ] = aNode->GetID();
01379       }
01380     }
01381 
01382     if (k != 4)
01383       continue;
01384 
01385     bool isDiag13 = true;
01386     if (aChoice == 0) // use diagonal 1-3
01387     {
01388       isDiag13 = true;
01389     }
01390     else if (aChoice == 1) // use diagonal 2-4
01391     {
01392       isDiag13 = false;
01393     }
01394     else // use numerical functor
01395     {
01396       // compare two sets of possible triangles
01397       int diag = aMeshEditor->BestSplit(anElemIds[i], aCriterion);
01398       if (diag == 1) // 1-3
01399         isDiag13 = true;
01400       else if (diag == 2) // 2-4
01401         isDiag13 = false;
01402       else // error
01403         continue;
01404     }
01405 
01406     if (isDiag13)
01407     {
01408       anIdList->SetId(0, anIdToVtk(aNodes[ 0 ]));
01409       anIdList->SetId(1, anIdToVtk(aNodes[ 1 ]));
01410       anIdList->SetId(2, anIdToVtk(aNodes[ 2 ]));
01411       aConnectivity->InsertNextCell(anIdList);
01412       aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
01413 
01414       anIdList->SetId(0, anIdToVtk(aNodes[ 2 ]));
01415       anIdList->SetId(1, anIdToVtk(aNodes[ 3 ]));
01416       anIdList->SetId(2, anIdToVtk(aNodes[ 0 ]));
01417       aConnectivity->InsertNextCell(anIdList);
01418       aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
01419     }
01420     else
01421     {
01422       anIdList->SetId(0, anIdToVtk(aNodes[ 1 ]));
01423       anIdList->SetId(1, anIdToVtk(aNodes[ 2 ]));
01424       anIdList->SetId(2, anIdToVtk(aNodes[ 3 ]));
01425       aConnectivity->InsertNextCell(anIdList);
01426       aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
01427 
01428       anIdList->SetId(0, anIdToVtk(aNodes[ 3 ]));
01429       anIdList->SetId(1, anIdToVtk(aNodes[ 0 ]));
01430       anIdList->SetId(2, anIdToVtk(aNodes[ 1 ]));
01431       aConnectivity->InsertNextCell(anIdList);
01432       aCellTypesArray->InsertNextValue(VTK_TRIANGLE);
01433     }
01434   }
01435 
01436   VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
01437   aCellLocationsArray->SetNumberOfComponents(1);
01438   aCellLocationsArray->SetNumberOfTuples(aNbCells);
01439 
01440   aConnectivity->InitTraversal();
01441   for(vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell(npts, pts); idType++)
01442     aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
01443 
01444   aGrid->SetPoints(aPoints);
01445   aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aConnectivity);
01446 
01447   // Create and display actor
01448   vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
01449   aMapper->SetInput(aGrid);
01450 
01451   myPreviewActor = SALOME_Actor::New();
01452   myPreviewActor->PickableOff();
01453   myPreviewActor->SetMapper(aMapper);
01454 
01455   vtkProperty* aProp = vtkProperty::New();
01456   aProp->SetRepresentationToWireframe();
01457   aProp->SetColor(250, 0, 250);
01458   aProp->SetLineWidth(myActor->GetLineWidth() + 1);
01459   myPreviewActor->SetProperty(aProp);
01460 
01461   SMESH::GetCurrentVtkView()->AddActor(myPreviewActor);
01462   SMESH::GetCurrentVtkView()->Repaint();
01463 
01464   aProp->Delete();
01465   aPoints->Delete();
01466   aConnectivity->Delete();
01467   aGrid->Delete();
01468   aMapper->Delete();
01469   anIdList->Delete();
01470   aCellTypesArray->Delete();
01471   aCellLocationsArray->Delete();
01472 }
01473 
01479 SMESHGUI_CuttingIntoTetraDlg::SMESHGUI_CuttingIntoTetraDlg(SMESHGUI* theModule)
01480   : SMESHGUI_MultiEditDlg(theModule, SMESH::VolumeFilter, false)
01481 {
01482   setWindowTitle(tr("CAPTION"));
01483   myHelpFileName = "split_to_tetra_page.html";
01484   myEntityType = 1;
01485 
01486   myToAllChk->setChecked( true ); //aplly to the whole mesh by default
01487 
01488   bool hasHexa = true;//myMesh->_is_nil() ? false : myMesh->NbHexas();
01489 
01490   if ( hasHexa )
01491   {
01492     myGroupChoice->button(0)->setText( tr("SPLIT_HEX_TO_5_TETRA"));
01493     myGroupChoice->button(1)->setText( tr("SPLIT_HEX_TO_6_TETRA"));
01494     myGroupChoice->button(2)->setText( tr("SPLIT_HEX_TO_24_TETRA"));
01495 
01496     myCriterionGrp->setTitle( tr("SPLIT_METHOD"));
01497     myCriterionGrp->show();
01498     myComboBoxFunctor->hide();
01499     myChoiceWidget->show();
01500   }
01501   setSelectionMode();
01502   updateButtons();
01503 }
01504 
01505 SMESHGUI_CuttingIntoTetraDlg::~SMESHGUI_CuttingIntoTetraDlg()
01506 {
01507 }
01508 
01509 bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
01510                                             const SMESH::long_array&    theIds,
01511                                             SMESH::SMESH_IDSource_ptr   theObj)
01512 {
01513   SMESH::SMESH_IDSource_var obj = theObj;
01514   if ( CORBA::is_nil( obj ))
01515     obj = theEditor->MakeIDSource( theIds, myEntityType ? SMESH::VOLUME : SMESH::FACE );
01516   try {
01517     theEditor->SplitVolumesIntoTetra( obj, myGroupChoice->checkedId()+1 );
01518   }
01519   catch ( const SALOME::SALOME_Exception& S_ex ) {
01520     SalomeApp_Tools::QtCatchCorbaException( S_ex );
01521     return false;
01522   }
01523   return true;
01524 }