Back to index

salome-smesh  6.5.0
SMESHGUI_RenumberingDlg.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_RenumberingDlg.cxx
00025 // Author : Michael ZORIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_RenumberingDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 
00034 #include <SMESH_Actor.h>
00035 #include <SMESH_TypeFilter.hxx>
00036 
00037 // SALOME GUI includes
00038 #include <SUIT_Desktop.h>
00039 #include <SUIT_Session.h>
00040 #include <SUIT_ResourceMgr.h>
00041 #include <SUIT_MessageBox.h>
00042 #include <SUIT_OverrideCursor.h>
00043 
00044 #include <LightApp_Application.h>
00045 #include <LightApp_SelectionMgr.h>
00046 
00047 #include <SALOME_ListIO.hxx>
00048 
00049 // Qt includes
00050 #include <QApplication>
00051 #include <QGroupBox>
00052 #include <QLabel>
00053 #include <QLineEdit>
00054 #include <QPushButton>
00055 #include <QRadioButton>
00056 #include <QVBoxLayout>
00057 #include <QHBoxLayout>
00058 #include <QKeyEvent>
00059 #include <QButtonGroup>
00060 
00061 // IDL includes
00062 #include <SALOMEconfig.h>
00063 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00064 
00065 #define SPACING 6
00066 #define MARGIN  11
00067 
00068 //=================================================================================
00069 // class    : SMESHGUI_RenumberingDlg()
00070 // purpose  :
00071 //=================================================================================
00072 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const int unit)
00073   : QDialog( SMESH::GetDesktop( theModule ) ),
00074     mySMESHGUI( theModule ),
00075     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00076 {
00077   myUnit = unit;
00078 
00079   setModal(false);
00080   setAttribute(Qt::WA_DeleteOnClose, true);
00081   setWindowTitle(unit == 0 ? 
00082                  tr("SMESH_RENUMBERING_NODES_TITLE") : 
00083                  tr("SMESH_RENUMBERING_ELEMENTS_TITLE"));
00084   setSizeGripEnabled(true);
00085 
00086   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( mySMESHGUI );
00087   QPixmap image0(resMgr->loadPixmap("SMESH", unit == 0 ? 
00088                                     tr("ICON_DLG_RENUMBERING_NODES") : 
00089                                     tr("ICON_DLG_RENUMBERING_ELEMENTS")));
00090   QPixmap image1(resMgr->loadPixmap("SMESH",tr("ICON_SELECT")));
00091 
00092   QVBoxLayout* SMESHGUI_RenumberingDlgLayout = new QVBoxLayout(this);
00093   SMESHGUI_RenumberingDlgLayout->setSpacing(SPACING);
00094   SMESHGUI_RenumberingDlgLayout->setMargin(MARGIN);
00095 
00096   /***************************************************************/
00097   GroupConstructors = new QGroupBox(unit == 0 ? 
00098                                     tr("SMESH_NODES") :
00099                                     tr("SMESH_ELEMENTS"), 
00100                                     this);
00101   myHelpFileName = unit == 0 ? 
00102     "renumbering_nodes_and_elements_page.html#renumbering_nodes_anchor" :
00103     "renumbering_nodes_and_elements_page.html#renumbering_elements_anchor";
00104 
00105   QButtonGroup* ButtonGroup = new QButtonGroup(this);
00106   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00107   GroupConstructorsLayout->setSpacing(SPACING);
00108   GroupConstructorsLayout->setMargin(MARGIN);
00109 
00110   Constructor1 = new QRadioButton(GroupConstructors);
00111   Constructor1->setIcon(image0);
00112   Constructor1->setChecked(true);
00113 
00114   GroupConstructorsLayout->addWidget(Constructor1);
00115   ButtonGroup->addButton(Constructor1, 0);
00116 
00117   /***************************************************************/
00118   GroupMesh = new QGroupBox(tr("SMESH_RENUMBERING"), this);
00119   QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
00120   GroupMeshLayout->setMargin(MARGIN);
00121   GroupMeshLayout->setSpacing(SPACING);
00122 
00123   TextLabelMesh = new QLabel(tr("SMESH_MESH"), GroupMesh);
00124   SelectButton = new QPushButton(GroupMesh);
00125   SelectButton->setIcon(image1);
00126   LineEditMesh = new QLineEdit(GroupMesh);
00127   LineEditMesh->setReadOnly(true);
00128 
00129   GroupMeshLayout->addWidget(TextLabelMesh);
00130   GroupMeshLayout->addWidget(SelectButton);
00131   GroupMeshLayout->addWidget(LineEditMesh);
00132 
00133   /***************************************************************/
00134   GroupButtons = new QGroupBox(this);
00135   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00136   GroupButtonsLayout->setSpacing(SPACING);
00137   GroupButtonsLayout->setMargin(MARGIN);
00138 
00139   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00140   buttonOk->setAutoDefault(true);
00141   buttonOk->setDefault(true);
00142   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00143   buttonApply->setAutoDefault(true);
00144   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00145   buttonCancel->setAutoDefault(true);
00146   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00147   buttonHelp->setAutoDefault(true);
00148 
00149   GroupButtonsLayout->addWidget(buttonOk);
00150   GroupButtonsLayout->addSpacing(10);
00151   GroupButtonsLayout->addWidget(buttonApply);
00152   GroupButtonsLayout->addSpacing(10);
00153   GroupButtonsLayout->addStretch();
00154   GroupButtonsLayout->addWidget(buttonCancel);
00155   GroupButtonsLayout->addWidget(buttonHelp);
00156 
00157   /***************************************************************/
00158   SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors);
00159   SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh);
00160   SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons);
00161 
00162   Init(); /* Initialisations */
00163 }
00164 
00165 //=================================================================================
00166 // function : ~SMESHGUI_RenumberingDlg()
00167 // purpose  : Destroys the object and frees any allocated resources
00168 //=================================================================================
00169 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
00170 {
00171 }
00172 
00173 //=================================================================================
00174 // function : Init()
00175 // purpose  :
00176 //=================================================================================
00177 void SMESHGUI_RenumberingDlg::Init()
00178 {
00179   myConstructorId = 0;
00180   Constructor1->setChecked(true);
00181   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00182 
00183   myMesh = SMESH::SMESH_Mesh::_nil();
00184 
00185   myMeshFilter = new SMESH_TypeFilter (MESH);
00186 
00187   /* signals and slots connections */
00188   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00189   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00190   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00191   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00192 
00193   connect(SelectButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00194   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00195   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00196   /* to close dialog if study change */
00197   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00198 
00199   myEditCurrentArgument = LineEditMesh;
00200   LineEditMesh->setFocus();
00201   mySelectionMgr->clearFilters();
00202   mySelectionMgr->installFilter(myMeshFilter);
00203 
00204   SelectionIntoArgument();
00205 }
00206 
00207 //=================================================================================
00208 // function : ClickOnApply()
00209 // purpose  :
00210 //=================================================================================
00211 void SMESHGUI_RenumberingDlg::ClickOnApply()
00212 {
00213   if (mySMESHGUI->isActiveStudyLocked())
00214     return;
00215 
00216   if (!myMesh->_is_nil()) {
00217     try {
00218       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00219       SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
00220       bool isUnitsLabeled = false;
00221       
00222       if (myUnit == 0 && anActor) {
00223         isUnitsLabeled = anActor->GetPointsLabeled();
00224         if (isUnitsLabeled)  anActor->SetPointsLabeled(false);
00225       }
00226       else if (myUnit == 1 && anActor) {
00227         isUnitsLabeled = anActor->GetCellsLabeled();
00228         if (isUnitsLabeled)  anActor->SetCellsLabeled(false);
00229       }
00230       
00231       SUIT_OverrideCursor aWaitCursor;
00232       if (myUnit == 0) {
00233         aMeshEditor->RenumberNodes();
00234         if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
00235       }
00236       else if (myUnit == 1) {
00237         aMeshEditor->RenumberElements();
00238         if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
00239       }
00240     }
00241     catch(...) {
00242     }
00243     
00244     //mySelectionMgr->clearSelected();
00245     SMESH::UpdateView();
00246     SMESHGUI::Modified();
00247   }
00248 }
00249 
00250 //=================================================================================
00251 // function : ClickOnOk()
00252 // purpose  :
00253 //=================================================================================
00254 void SMESHGUI_RenumberingDlg::ClickOnOk()
00255 {
00256   ClickOnApply();
00257   ClickOnCancel();
00258 }
00259 
00260 //=================================================================================
00261 // function : ClickOnCancel()
00262 // purpose  :
00263 //=================================================================================
00264 void SMESHGUI_RenumberingDlg::ClickOnCancel()
00265 {
00266   //mySelectionMgr->clearSelected();
00267   mySelectionMgr->clearFilters();
00268   disconnect(mySelectionMgr, 0, this, 0);
00269   mySMESHGUI->ResetState();
00270   reject();
00271 }
00272 
00273 //=================================================================================
00274 // function : ClickOnHelp()
00275 // purpose  :
00276 //=================================================================================
00277 void SMESHGUI_RenumberingDlg::ClickOnHelp()
00278 {
00279   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00280   if (app) 
00281     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00282   else {
00283     QString platform;
00284 #ifdef WIN32
00285     platform = "winapplication";
00286 #else
00287     platform = "application";
00288 #endif
00289     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00290                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00291                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00292                                                                  platform)).
00293                              arg(myHelpFileName));
00294   }
00295 }
00296 
00297 //=================================================================================
00298 // function : SelectionIntoArgument()
00299 // purpose  : Called when selection as changed or other case
00300 //=================================================================================
00301 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
00302 {
00303   if (!GroupButtons->isEnabled()) // inactive
00304     return;
00305 
00306   QString aString = "";
00307 
00308   SALOME_ListIO aList;
00309   mySelectionMgr->selectedObjects(aList);
00310   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00311 
00312   if (myEditCurrentArgument == LineEditMesh) {
00313     // mesh
00314     if (nbSel != 1) {
00315       myMesh = SMESH::SMESH_Mesh::_nil();
00316       aString = "";
00317     } else {
00318       Handle(SALOME_InteractiveObject) IO = aList.First();
00319       myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
00320       if (myMesh->_is_nil())
00321         aString = "";
00322     }
00323   }
00324 
00325   myEditCurrentArgument->setText(aString);
00326 
00327   bool isEnabled = (!myMesh->_is_nil());
00328   buttonOk->setEnabled(isEnabled);
00329   buttonApply->setEnabled(isEnabled);
00330 }
00331 
00332 //=================================================================================
00333 // function : SetEditCurrentArgument()
00334 // purpose  :
00335 //=================================================================================
00336 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
00337 {
00338   QPushButton* send = (QPushButton*)sender();
00339   switch (myConstructorId)
00340     {
00341     case 0: /* default constructor */
00342       {
00343         if(send == SelectButton) {
00344           LineEditMesh->setFocus();
00345           myEditCurrentArgument = LineEditMesh;
00346         }
00347         SelectionIntoArgument();
00348         break;
00349       }
00350     }
00351 }
00352 
00353 //=================================================================================
00354 // function : DeactivateActiveDialog()
00355 // purpose  :
00356 //=================================================================================
00357 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
00358 {
00359   if (GroupConstructors->isEnabled()) {
00360     GroupConstructors->setEnabled(false);
00361     GroupMesh->setEnabled(false);
00362     GroupButtons->setEnabled(false);
00363     mySMESHGUI->ResetState();
00364     mySMESHGUI->SetActiveDialogBox(0);
00365   }
00366 }
00367 
00368 //=================================================================================
00369 // function : ActivateThisDialog()
00370 // purpose  :
00371 //=================================================================================
00372 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
00373 {
00374   /* Emit a signal to deactivate the active dialog */
00375   mySMESHGUI->EmitSignalDeactivateDialog();
00376   GroupConstructors->setEnabled(true);
00377   GroupMesh->setEnabled(true);
00378   GroupButtons->setEnabled(true);
00379 
00380   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00381   SelectionIntoArgument();
00382 }
00383 
00384 //=================================================================================
00385 // function : enterEvent()
00386 // purpose  :
00387 //=================================================================================
00388 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
00389 {
00390   if (GroupConstructors->isEnabled())
00391     return;
00392   ActivateThisDialog();
00393 }
00394 
00395 //=================================================================================
00396 // function : closeEvent()
00397 // purpose  :
00398 //=================================================================================
00399 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
00400 {
00401   /* same than click on cancel button */
00402   ClickOnCancel();
00403 }
00404 
00405 //=======================================================================
00406 //function : hideEvent
00407 //purpose  : caused by ESC key
00408 //=======================================================================
00409 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)
00410 {
00411   if (!isMinimized())
00412     ClickOnCancel();
00413 }
00414 
00415 //=================================================================================
00416 // function : keyPressEvent()
00417 // purpose  :
00418 //=================================================================================
00419 void SMESHGUI_RenumberingDlg::keyPressEvent( QKeyEvent* e )
00420 {
00421   QDialog::keyPressEvent( e );
00422   if ( e->isAccepted() )
00423     return;
00424 
00425   if ( e->key() == Qt::Key_F1 ) {
00426     e->accept();
00427     ClickOnHelp();
00428   }
00429 }