Back to index

salome-smesh  6.5.0
SMESHGUI_ExtrusionDlg.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_ExtrusionDlg.cxx
00025 // Author : Michael ZORIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_ExtrusionDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_SpinBox.h"
00035 #include "SMESHGUI_IdValidator.h"
00036 #include "SMESHGUI_FilterDlg.h"
00037 #include "SMESHGUI_MeshEditPreview.h"
00038 
00039 #include <SMESH_Actor.h>
00040 #include <SMESH_TypeFilter.hxx>
00041 #include <SMESH_LogicalFilter.hxx>
00042 
00043 #include <SMDS_Mesh.hxx>
00044 
00045 // SALOME GUI includes
00046 #include <SUIT_ResourceMgr.h>
00047 #include <SUIT_Desktop.h>
00048 #include <SUIT_MessageBox.h>
00049 #include <SUIT_Session.h>
00050 #include <SUIT_OverrideCursor.h>
00051 
00052 #include <LightApp_Application.h>
00053 #include <LightApp_SelectionMgr.h>
00054 
00055 #include <SVTK_ViewModel.h>
00056 #include <SVTK_ViewWindow.h>
00057 
00058 #include <SalomeApp_IntSpinBox.h>
00059 
00060 // OCCT includes
00061 #include <TColStd_MapOfInteger.hxx>
00062 #include <TColStd_IndexedMapOfInteger.hxx>
00063 #include <gp_XYZ.hxx>
00064 
00065 // Qt includes
00066 #include <QApplication>
00067 #include <QButtonGroup>
00068 #include <QGroupBox>
00069 #include <QLabel>
00070 #include <QLineEdit>
00071 #include <QPushButton>
00072 #include <QRadioButton>
00073 #include <QCheckBox>
00074 #include <QHBoxLayout>
00075 #include <QVBoxLayout>
00076 #include <QGridLayout>
00077 #include <QKeyEvent>
00078 
00079 // IDL includes
00080 #include <SALOMEconfig.h>
00081 #include CORBA_SERVER_HEADER(SMESH_Group)
00082 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00083 
00084 #define SPACING 6
00085 #define MARGIN  11
00086 
00087 //=================================================================================
00088 // function : SMESHGUI_ExtrusionDlg()
00089 // purpose  : constructor
00090 //=================================================================================
00091 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
00092   : SMESHGUI_PreviewDlg( theModule ),
00093     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00094     myFilterDlg( 0 ),
00095     mySelectedObject(SMESH::SMESH_IDSource::_nil())
00096 {
00097   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
00098   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
00099   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00100   QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_NODE")));
00101 
00102   setModal( false );
00103   setAttribute( Qt::WA_DeleteOnClose, true );
00104   setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
00105   setSizeGripEnabled(true);
00106 
00107   QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
00108   SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
00109   SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
00110 
00111   /***************************************************************/
00112   ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
00113   GroupConstructors = new QButtonGroup(this);
00114   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
00115   ConstructorsBoxLayout->setSpacing(SPACING);
00116   ConstructorsBoxLayout->setMargin(MARGIN);
00117 
00118   RadioButton0= new QRadioButton(ConstructorsBox);
00119   RadioButton0->setIcon(image3);
00120   RadioButton1= new QRadioButton(ConstructorsBox);
00121   RadioButton1->setIcon(image0);
00122   RadioButton2= new QRadioButton(ConstructorsBox);
00123   RadioButton2->setIcon(image1);
00124 
00125   ConstructorsBoxLayout->addWidget(RadioButton0);
00126   ConstructorsBoxLayout->addWidget(RadioButton1);
00127   ConstructorsBoxLayout->addWidget(RadioButton2);
00128 
00129   GroupConstructors->addButton(RadioButton0, 0);
00130   GroupConstructors->addButton(RadioButton1, 1);
00131   GroupConstructors->addButton(RadioButton2, 2);
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   GroupArguments = new QGroupBox(tr("EXTRUSION_0D"), this);
00159   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
00160   GroupArgumentsLayout->setSpacing(SPACING);
00161   GroupArgumentsLayout->setMargin(MARGIN);
00162 
00163   myIdValidator = new SMESHGUI_IdValidator(this);
00164 
00165   // Controls for elements selection
00166   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
00167 
00168   SelectElementsButton = new QPushButton(GroupArguments);
00169   SelectElementsButton->setIcon(image2);
00170 
00171   LineEditElements = new QLineEdit(GroupArguments);
00172   LineEditElements->setValidator(myIdValidator);
00173   LineEditElements->setMaxLength(-1);
00174   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
00175   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
00176 
00177   // Control for the whole mesh selection
00178   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
00179 
00180   RadioButton3 = new QRadioButton(GroupArguments);
00181   RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
00182   RadioButton4 = new QRadioButton(GroupArguments);
00183   RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
00184 
00185   //Control for the Distance selection
00186   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
00187   
00188   TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
00189   SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
00190   
00191   TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
00192   SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
00193 
00194   TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
00195   SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
00196 
00197   // Controls for vector selection
00198 
00199   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
00200 
00201   SelectVectorButton = new QPushButton(GroupArguments);
00202   SelectVectorButton->setIcon(image2);
00203 
00204   TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
00205   SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
00206 
00207   TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
00208   SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
00209 
00210   TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
00211   SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
00212 
00213   TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
00214   SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
00215 
00216   // Controls for nb. steps defining
00217   TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
00218   SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
00219 
00220   // CheckBox for groups generation
00221   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
00222 
00223   //Preview check box
00224   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
00225 
00226   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
00227   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
00228   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
00229   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
00230   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
00231   GroupArgumentsLayout->addWidget(RadioButton3,         2, 1, 1, 3);
00232   GroupArgumentsLayout->addWidget(RadioButton4,         2, 5, 1, 3);
00233   GroupArgumentsLayout->addWidget(TextLabelDistance,    3, 0);
00234   GroupArgumentsLayout->addWidget(TextLabelDx,          3, 2);
00235   GroupArgumentsLayout->addWidget(SpinBox_Dx,           3, 3);
00236   GroupArgumentsLayout->addWidget(TextLabelDy,          3, 4);
00237   GroupArgumentsLayout->addWidget(SpinBox_Dy,           3, 5);
00238   GroupArgumentsLayout->addWidget(TextLabelDz,          3, 6);
00239   GroupArgumentsLayout->addWidget(SpinBox_Dz,           3, 7);
00240   GroupArgumentsLayout->addWidget(TextLabelVector,      4, 0);
00241   GroupArgumentsLayout->addWidget(SelectVectorButton,   4, 1);
00242   GroupArgumentsLayout->addWidget(TextLabelVx,          4, 2);
00243   GroupArgumentsLayout->addWidget(SpinBox_Vx,           4, 3);
00244   GroupArgumentsLayout->addWidget(TextLabelVy,          4, 4);
00245   GroupArgumentsLayout->addWidget(SpinBox_Vy,           4, 5);
00246   GroupArgumentsLayout->addWidget(TextLabelVz,          4, 6);
00247   GroupArgumentsLayout->addWidget(SpinBox_Vz,           4, 7);
00248   GroupArgumentsLayout->addWidget(TextLabelDist,        5, 0);
00249   GroupArgumentsLayout->addWidget(SpinBox_VDist,         5, 3);
00250   GroupArgumentsLayout->addWidget(TextLabelNbSteps,     6, 0, 1, 3);
00251   GroupArgumentsLayout->addWidget(SpinBox_NbSteps,      6, 3);
00252   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    7, 0, 1, 8);
00253   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      8, 0, 1, 8);
00254   GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
00255 
00256 
00257   /***************************************************************/
00258   SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
00259   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
00260   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
00261 
00262   /* Initialisations */
00263   SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
00264   SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
00265   SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
00266 
00267   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00268   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00269   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00270   
00271   SpinBox_NbSteps->setRange(1, 999999);
00272   SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
00273 
00274   RadioButton0->setChecked(true);
00275   RadioButton3->setChecked(true);
00276   MakeGroupsCheck->setChecked(true);
00277 
00278   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00279 
00280   mySMESHGUI->SetActiveDialogBox(this);
00281 
00282   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
00283   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
00284   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
00285 
00286   QList<SUIT_SelectionFilter*> aListOfFilters;
00287   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
00288   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
00289 
00290   myMeshOrSubMeshOrGroupFilter =
00291     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
00292 
00293   myHelpFileName = "extrusion_page.html";
00294 
00295   Init();
00296 
00297   /***************************************************************/
00298   // signals and slots connections
00299   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00300   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00301   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00302   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00303 
00304   connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
00305   connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
00306 
00307   // to update state of the Ok & Apply buttons
00308   connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
00309   connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
00310   connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
00311   connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
00312   connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
00313   connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
00314 
00315   connect(GroupConstructors,    SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
00316   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00317   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00318   connect(mySMESHGUI,           SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00319   connect(mySelectionMgr,       SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00320   /* to close dialog if study change */
00321   connect(mySMESHGUI,           SIGNAL(SignalCloseAllDialogs()),   this, SLOT(ClickOnCancel()));
00322   connect(LineEditElements,     SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00323   connect(CheckBoxMesh,         SIGNAL(toggled(bool)),               SLOT(onSelectMesh(bool)));
00324 
00325   connect(SpinBox_Dx,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00326   connect(SpinBox_Dy,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00327   connect(SpinBox_Dz,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00328   connect(SpinBox_Vx,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00329   connect(SpinBox_Vy,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00330   connect(SpinBox_Vz,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00331   connect(SpinBox_VDist,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00332   connect(SpinBox_NbSteps,  SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
00333 
00334   //To Connect preview check box
00335   connectPreviewControl();
00336 
00337   /***************************************************************/
00338   
00339   ConstructorsClicked(0);
00340   ClickOnRadio();
00341   SelectionIntoArgument();
00342 }
00343 
00344 //=================================================================================
00345 // function : ~SMESHGUI_ExtrusionDlg()
00346 // purpose  : destructor
00347 //=================================================================================
00348 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
00349 {
00350   if ( myFilterDlg != 0 ) {
00351     myFilterDlg->setParent( 0 );
00352     delete myFilterDlg;
00353   }
00354 }
00355 
00356 //=================================================================================
00357 // function : Init()
00358 // purpose  : initialization
00359 //=================================================================================
00360 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
00361 {
00362   myBusy = false;
00363   myIDs.clear();
00364 
00365   LineEditElements->clear();
00366   myNbOkElements = 0;
00367 
00368   myActor = 0;
00369   myMesh = SMESH::SMESH_Mesh::_nil();
00370 
00371   if (ResetControls) {
00372     SpinBox_NbSteps->setValue(1);
00373     SpinBox_VDist->setValue(10);
00374     SpinBox_Dx->SetValue(0);
00375     SpinBox_Dy->SetValue(0);
00376     SpinBox_Dz->SetValue(0);
00377     SpinBox_Vx->SetValue(0);
00378     SpinBox_Vy->SetValue(0);
00379     SpinBox_Vz->SetValue(0);
00380 
00381     CheckBoxMesh->setChecked(false);
00382     onSelectMesh(false);
00383     myPreviewCheckBox->setChecked(false);
00384     onDisplaySimulation(false);
00385   }
00386 
00387   CheckIsEnable();
00388 }
00389 
00390 //=================================================================================
00391 // function : CheckIsEnable()
00392 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
00393 //=================================================================================
00394 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
00395 {  
00396   bool anIsEnable = myNbOkElements > 0 && isValuesValid();
00397 
00398   buttonOk->setEnabled(anIsEnable);
00399   buttonApply->setEnabled(anIsEnable);
00400 }
00401 
00402 //=================================================================================
00403 // function : isValuesValid()
00404 // purpose  : Return true in case if values entered into dialog are valid
00405 //=================================================================================
00406 bool SMESHGUI_ExtrusionDlg::isValuesValid() {
00407   double aX, aY, aZ, aModule = 0;
00408   if ( RadioButton3->isChecked() ) {
00409     aX = SpinBox_Dx->GetValue();
00410     aY = SpinBox_Dy->GetValue();
00411     aZ = SpinBox_Dz->GetValue();
00412     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
00413   } else   if ( RadioButton4->isChecked() ) {
00414     aX = SpinBox_Vx->GetValue();
00415     aY = SpinBox_Vy->GetValue();
00416     aZ = SpinBox_Vz->GetValue();
00417     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
00418   }
00419   return aModule > 1.0E-38;
00420 }
00421 
00422 //=================================================================================
00423 // function : ConstructorsClicked()
00424 // purpose  : Radio button management
00425 //=================================================================================
00426 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
00427 {
00428   disconnect(mySelectionMgr, 0, this, 0);
00429 
00430   hidePreview();
00431 
00432   TextLabelElements->setText(tr( constructorId ? "SMESH_ID_ELEMENTS" : "SMESH_ID_NODES"));
00433 
00434   switch (constructorId) {
00435   case 0:
00436     {
00437       GroupArguments->setTitle(tr("EXTRUSION_0D"));
00438       if (!CheckBoxMesh->isChecked())
00439       {
00440         LineEditElements->clear();
00441         myIDs.clear();
00442         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00443           aViewWindow->SetSelectionMode(NodeSelection);
00444       }
00445       break;
00446     }
00447   case 1:
00448     {
00449       GroupArguments->setTitle(tr("EXTRUSION_1D"));
00450       if (!CheckBoxMesh->isChecked())
00451       {
00452         LineEditElements->clear();
00453         myIDs.clear();
00454         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00455           aViewWindow->SetSelectionMode(EdgeSelection);
00456       }
00457       break;
00458     }
00459   case 2:
00460     {
00461       GroupArguments->setTitle(tr("EXTRUSION_2D"));
00462       if (!CheckBoxMesh->isChecked())
00463       {
00464         LineEditElements->clear();
00465         myIDs.clear();
00466         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00467           aViewWindow->SetSelectionMode(FaceSelection);
00468       }
00469       break;
00470     }
00471   }
00472 
00473   myEditCurrentArgument = (QWidget*)LineEditElements;
00474   LineEditElements->setFocus();
00475 
00476   if (CheckBoxMesh->isChecked())
00477     onSelectMesh(true);
00478 
00479   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00480 }
00481 
00482 //=================================================================================
00483 // function : ConstructorsClicked()
00484 // purpose  : Radio button management
00485 //=================================================================================
00486 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
00487 {
00488   if ( RadioButton3->isChecked() ) {
00489     TextLabelDistance->show();
00490     TextLabelDx->show();
00491     SpinBox_Dx->show();
00492     TextLabelDy->show();
00493     SpinBox_Dy->show();
00494     TextLabelDz->show();
00495     SpinBox_Dz->show();
00496 
00497     TextLabelVector->hide();
00498     TextLabelVx->hide();
00499     SpinBox_Vx->hide();
00500     TextLabelVy->hide();
00501     SpinBox_Vy->hide();
00502     TextLabelVz->hide();
00503     SpinBox_Vz->hide();
00504     TextLabelDist->hide();
00505     SpinBox_VDist->hide();
00506     SelectVectorButton->hide();
00507   } else if ( RadioButton4->isChecked() ) {
00508     TextLabelDistance->hide();
00509     TextLabelDx->hide();
00510     SpinBox_Dx->hide();
00511     TextLabelDy->hide();
00512     SpinBox_Dy->hide();
00513     TextLabelDz->hide();
00514     SpinBox_Dz->hide();
00515 
00516     TextLabelVector->show();
00517     TextLabelVx->show();
00518     SpinBox_Vx->show();
00519     TextLabelVy->show();
00520     SpinBox_Vy->show();
00521     TextLabelVz->show();
00522     SpinBox_Vz->show();
00523     TextLabelDist->show();
00524     SpinBox_VDist->show();
00525     SelectVectorButton->show();
00526   }
00527   onDisplaySimulation(true);
00528   // AdjustSize
00529   qApp->processEvents();
00530   updateGeometry();
00531   resize( minimumSizeHint() );
00532 }
00533 
00534 //=================================================================================
00535 // function : ClickOnApply()
00536 // purpose  : Called when user presses <Apply> button
00537 //=================================================================================
00538 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
00539 {
00540   if (mySMESHGUI->isActiveStudyLocked())
00541     return false;
00542 
00543   if (!isValid())
00544     return false;
00545 
00546   if (myNbOkElements) {
00547 
00548     SMESH::DirStruct aVector;
00549     getExtrusionVector(aVector);
00550     
00551     QStringList aParameters;
00552     if ( RadioButton3->isChecked() ) {
00553       aParameters << SpinBox_Dx->text();
00554       aParameters << SpinBox_Dy->text();
00555       aParameters << SpinBox_Dz->text();
00556     } else if ( RadioButton4->isChecked() ) {
00557       // only 3 coords in a python dump command :(
00558       // aParameters << SpinBox_Vx->text();
00559       // aParameters << SpinBox_Vy->text();
00560       // aParameters << SpinBox_Vz->text();
00561       // aParameters << SpinBox_VDist->text();
00562     }
00563 
00564     long aNbSteps = (long)SpinBox_NbSteps->value();
00565 
00566     aParameters << SpinBox_NbSteps->text();
00567 
00568     try {
00569       SUIT_OverrideCursor aWaitCursor;
00570       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00571 
00572       myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00573 
00574       if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
00575         if( CheckBoxMesh->isChecked() ) 
00576           switch (GetConstructorId() ) {
00577             case 0:
00578               {
00579                 SMESH::ListOfGroups_var groups = 
00580                   aMeshEditor->ExtrusionSweepObject0DMakeGroups(mySelectedObject, aVector, aNbSteps);
00581                 break;
00582               }
00583             case 1:
00584               {
00585                 SMESH::ListOfGroups_var groups = 
00586                   aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
00587                 break;
00588               }
00589             case 2:
00590               {
00591                 SMESH::ListOfGroups_var groups = 
00592                   aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
00593                 break;
00594               }
00595           }
00596         else
00597         {
00598           SMESH::ListOfGroups_var groups;
00599           if (GetConstructorId() == 0)
00600             groups = aMeshEditor->ExtrusionSweepMakeGroups0D(myElementsId.inout(), aVector, aNbSteps);
00601           else
00602             groups = aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
00603         }
00604 
00605       }
00606       else {
00607         if( CheckBoxMesh->isChecked() ) 
00608           switch( GetConstructorId() ) {
00609             case 0:
00610               {
00611               aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
00612                 break;
00613               }
00614             case 1:
00615               {
00616               aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
00617                 break;
00618               }
00619             case 2:
00620               {
00621               aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
00622                 break;
00623           }
00624         }
00625         else
00626           if (GetConstructorId() == 0)
00627             aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
00628           else
00629             aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
00630       }
00631 
00632     } catch (...) {
00633     }
00634 
00635     SMESH::Update(myIO, SMESH::eDisplay);
00636     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
00637       mySMESHGUI->updateObjBrowser(true); // new groups may appear
00638     Init(false);
00639     ConstructorsClicked(GetConstructorId());
00640     mySelectionMgr->clearSelected();
00641     mySelectedObject = SMESH::SMESH_IDSource::_nil();
00642     SelectionIntoArgument();
00643 
00644     SMESHGUI::Modified();
00645   }
00646   return true;
00647 }
00648 
00649 //=================================================================================
00650 // function : ClickOnOk()
00651 // purpose  : Called when user presses <OK> button
00652 //=================================================================================
00653 void SMESHGUI_ExtrusionDlg::ClickOnOk()
00654 {
00655   if (ClickOnApply())
00656     ClickOnCancel();
00657 }
00658 
00659 //=================================================================================
00660 // function : ClickOnCancel()
00661 // purpose  : Called when dialog box is closed
00662 //=================================================================================
00663 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
00664 {
00665   reject();
00666 }
00667 
00668 //=================================================================================
00669 // function : ClickOnHelp()
00670 // purpose  :
00671 //=================================================================================
00672 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
00673 {
00674   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00675   if (app) 
00676     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00677   else {
00678     QString platform;
00679 #ifdef WIN32
00680     platform = "winapplication";
00681 #else
00682     platform = "application";
00683 #endif
00684     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00685                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00686                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00687                                                                  platform)).
00688                              arg(myHelpFileName));
00689   }
00690 }
00691 
00692 //=================================================================================
00693 // function : onTextChange()
00694 // purpose  :
00695 //=================================================================================
00696 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
00697 {
00698   QLineEdit* send = (QLineEdit*)sender();
00699 
00700   // return if busy
00701   if (myBusy) return;
00702 
00703   // set busy flag
00704   myBusy = true;
00705 
00706   if (send == LineEditElements)
00707     myNbOkElements = 0;
00708 
00709   // hilight entered elements/nodes
00710 
00711   if (!myIO.IsNull()) {
00712     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00713 
00714     if (send == LineEditElements)
00715     {
00716       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
00717       SMESH::ElementType SMESHType;
00718       SMDSAbs_ElementType SMDSType;
00719       switch (GetConstructorId()) {
00720       case 0:
00721         {
00722           SMESHType = SMESH::NODE;
00723           SMDSType = SMDSAbs_Node;
00724           break;
00725         }
00726       case 1:
00727         {
00728           SMESHType = SMESH::EDGE;
00729           SMDSType = SMDSAbs_Edge;
00730           break;                  
00731         }
00732       case 2:
00733         {
00734           SMESHType = SMESH::FACE;
00735           SMDSType = SMDSAbs_Face;
00736           break;
00737         }
00738       }
00739       myElementsId = new SMESH::long_array;
00740       myElementsId->length( aListId.count() );
00741       TColStd_MapOfInteger newIndices;
00742       for (int i = 0; i < aListId.count(); i++) {
00743         int id = aListId[ i ].toInt();
00744         bool validId = false;
00745         if ( id > 0 ) {
00746           if ( aMesh ) {
00747             const SMDS_MeshElement * e;
00748             if (SMDSType == SMDSAbs_Node)
00749               e = aMesh->FindNode( id ); 
00750             else
00751               e = aMesh->FindElement( id );
00752             validId = ( e && e->GetType() == SMDSType );
00753           } else {
00754             validId = ( myMesh->GetElementType( id, true ) == SMESHType );
00755           }
00756         }
00757         if ( validId && newIndices.Add( id ))
00758           myElementsId[ newIndices.Extent()-1 ] = id;
00759       }
00760       myElementsId->length( myNbOkElements = newIndices.Extent() );
00761       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
00762       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00763         aViewWindow->highlight( myIO, true, true );
00764     }
00765   }
00766 
00767   CheckIsEnable();
00768 
00769   onDisplaySimulation(true);
00770 
00771   myBusy = false;
00772 }
00773 
00774 //=================================================================================
00775 // function : SelectionIntoArgument()
00776 // purpose  : Called when selection as changed or other case
00777 //=================================================================================
00778 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
00779 {
00780   if (myBusy) return;
00781 
00782   // return if dialog box is inactive
00783   if (!GroupButtons->isEnabled())
00784     return;
00785 
00786   // clear
00787   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
00788     myActor = 0;
00789     Handle(SALOME_InteractiveObject) resIO = myIO;
00790     myIO.Nullify();
00791   }
00792 
00793   QString aString = "";
00794   // set busy flag
00795   if(myEditCurrentArgument == (QWidget*)LineEditElements) {
00796     myBusy = true;
00797     LineEditElements->setText(aString);
00798     myNbOkElements = 0;
00799     myBusy = false;
00800   }
00801   // get selected mesh
00802   SALOME_ListIO aList;
00803   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
00804   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00805   if (nbSel != 1)
00806     return;
00807 
00808   Handle(SALOME_InteractiveObject) IO = aList.First();
00809 
00810   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
00811     myMesh = SMESH::GetMeshByIO(IO);
00812     if (myMesh->_is_nil())
00813       return;
00814     myIO = IO;
00815     myActor = SMESH::FindActorByObject(myMesh);
00816   }
00817 
00818   if (myEditCurrentArgument == (QWidget*)LineEditElements) {    
00819     int aNbElements = 0;
00820 
00821     // MakeGroups is available if there are groups
00822     if ( myMesh->NbGroups() == 0 ) {
00823       MakeGroupsCheck->setChecked(false);
00824       MakeGroupsCheck->setEnabled(false);
00825     } else {
00826       MakeGroupsCheck->setEnabled(true);
00827     }
00828 
00829     if (CheckBoxMesh->isChecked()) {
00830       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00831 
00832       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
00833         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
00834       else
00835         return;
00836     } else {
00837       // get indices of selcted elements
00838       TColStd_IndexedMapOfInteger aMapIndex;
00839       mySelector->GetIndex(IO,aMapIndex);
00840       aNbElements = aMapIndex.Extent();
00841 
00842       if (aNbElements < 1)
00843         return;
00844 
00845       myElementsId = new SMESH::long_array;
00846       myElementsId->length( aNbElements );
00847       aString = "";
00848       for ( int i = 0; i < aNbElements; ++i )
00849         aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
00850     }
00851 
00852     myNbOkElements = true;
00853 
00854     myBusy = true;
00855     ((QLineEdit*)myEditCurrentArgument)->setText(aString);
00856     myBusy = false;
00857   }
00858   else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
00859     TColStd_IndexedMapOfInteger aMapIndex;
00860     mySelector->GetIndex(IO,aMapIndex);
00861     int aNbElements = aMapIndex.Extent();
00862     SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
00863     SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
00864     SMDS_Mesh* aMesh =  anActor ? anActor->GetObject()->GetMesh() : 0;
00865 
00866     if(aNbElements != 1 || !aMesh)
00867       return;
00868     
00869     const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
00870 
00871     if (!face)
00872       return;
00873 
00874     gp_XYZ aNormale = SMESH::getNormale(face);
00875     SpinBox_Vx->SetValue(aNormale.X());
00876     SpinBox_Vy->SetValue(aNormale.Y());
00877     SpinBox_Vz->SetValue(aNormale.Z());
00878     
00879   }
00880   
00881   onDisplaySimulation(true);
00882   
00883   // OK
00884   CheckIsEnable();
00885 }
00886 
00887 //=================================================================================
00888 // function : SetEditCurrentArgument()
00889 // purpose  :
00890 //=================================================================================
00891 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
00892 {
00893   QPushButton* send = (QPushButton*)sender();
00894 
00895   disconnect(mySelectionMgr, 0, this, 0);
00896   mySelectionMgr->clearSelected();
00897   mySelectionMgr->clearFilters();
00898 
00899   if (send == SelectElementsButton) {
00900     myEditCurrentArgument = (QWidget*)LineEditElements;
00901     if (CheckBoxMesh->isChecked()) {
00902       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00903         aViewWindow->SetSelectionMode(ActorSelection);
00904       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
00905     } else {
00906       int aConstructorId = GetConstructorId();
00907       switch(aConstructorId) {
00908           case 0:
00909           {   
00910             if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00911               aViewWindow->SetSelectionMode(NodeSelection);
00912             break;
00913           }
00914           case 1:
00915           {
00916             if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00917               aViewWindow->SetSelectionMode(EdgeSelection);
00918             break;
00919           }
00920           case 2:
00921           {
00922             if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00923             aViewWindow->SetSelectionMode(FaceSelection);
00924             break;
00925           }
00926       }
00927     }
00928   }
00929   else if (send == SelectVectorButton){
00930     myEditCurrentArgument = (QWidget*)SpinBox_Vx;
00931     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00932       aViewWindow->SetSelectionMode(FaceSelection);
00933   }
00934   
00935   myEditCurrentArgument->setFocus();
00936   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00937   SelectionIntoArgument();
00938 }
00939 
00940 //=================================================================================
00941 // function : DeactivateActiveDialog()
00942 // purpose  : Deactivates this dialog
00943 //=================================================================================
00944 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
00945 {
00946   if (ConstructorsBox->isEnabled()) {
00947     ConstructorsBox->setEnabled(false);
00948     GroupArguments->setEnabled(false);
00949     GroupButtons->setEnabled(false);
00950     mySMESHGUI->ResetState();
00951     mySMESHGUI->SetActiveDialogBox(0);
00952   }
00953 }
00954 
00955 //=================================================================================
00956 // function : ActivateThisDialog()
00957 // purpose  : Activates this dialog
00958 //=================================================================================
00959 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
00960 {
00961   // Emit a signal to deactivate the active dialog
00962   mySMESHGUI->EmitSignalDeactivateDialog();
00963   ConstructorsBox->setEnabled(true);
00964   GroupArguments->setEnabled(true);
00965   GroupButtons->setEnabled(true);
00966 
00967   mySMESHGUI->SetActiveDialogBox(this);
00968 
00969   ConstructorsClicked(GetConstructorId());
00970   SelectionIntoArgument();
00971 }
00972 
00973 //=================================================================================
00974 // function : enterEvent()
00975 // purpose  : Mouse enter event
00976 //=================================================================================
00977 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
00978 {
00979   if (!ConstructorsBox->isEnabled())
00980     ActivateThisDialog();
00981 }
00982 
00983 //=================================================================================
00984 // function : closeEvent()
00985 // purpose  :
00986 //=================================================================================
00987 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
00988 {
00989   /* same than click on cancel button */
00990   disconnect(mySelectionMgr, 0, this, 0);
00991   mySelectionMgr->clearFilters();
00992   //mySelectionMgr->clearSelected();
00993   if (SMESH::GetCurrentVtkView()) {
00994     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
00995     SMESH::SetPointRepresentation(false);
00996     SMESH::SetPickable();
00997   }
00998   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00999     aViewWindow->SetSelectionMode(ActorSelection);
01000   mySMESHGUI->ResetState();
01001 }
01002 
01003 void SMESHGUI_ExtrusionDlg::reject()
01004 {
01005   QDialog::reject();
01006   close();
01007 }
01008 
01009 //=================================================================================
01010 // function : onSelectMesh()
01011 // purpose  :
01012 //=================================================================================
01013 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
01014 {
01015   if (toSelectMesh) {
01016     myIDs = LineEditElements->text();
01017     TextLabelElements->setText(tr("SMESH_NAME"));
01018   }
01019   else
01020     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
01021 
01022   myFilterBtn->setEnabled(!toSelectMesh);
01023 
01024   if (myEditCurrentArgument != LineEditElements) {
01025     LineEditElements->clear();
01026     return;
01027   }
01028 
01029   mySelectionMgr->clearFilters();
01030 
01031   if (toSelectMesh) {
01032     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01033       aViewWindow->SetSelectionMode(ActorSelection);
01034     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
01035     LineEditElements->setReadOnly(true);
01036     LineEditElements->setValidator(0);
01037   } else {
01038     int aConstructorId = GetConstructorId();
01039     switch(aConstructorId) {
01040       case 0:
01041         {
01042           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01043             aViewWindow->SetSelectionMode(NodeSelection);
01044           break;
01045         }
01046       case 1:
01047         {
01048           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01049             aViewWindow->SetSelectionMode(EdgeSelection);
01050           break;
01051         }
01052       case 2:
01053         {
01054           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01055             aViewWindow->SetSelectionMode(FaceSelection);
01056           break;
01057         }
01058     }
01059     LineEditElements->setReadOnly(false);
01060     LineEditElements->setValidator(myIdValidator);
01061     onTextChange(LineEditElements->text());
01062   }
01063 
01064   SelectionIntoArgument();
01065 
01066   if (!toSelectMesh)
01067     LineEditElements->setText( myIDs );
01068 }
01069 
01070 //=================================================================================
01071 // function : GetConstructorId()
01072 // purpose  :
01073 //=================================================================================
01074 int SMESHGUI_ExtrusionDlg::GetConstructorId()
01075 {
01076   return GroupConstructors->checkedId();
01077 }
01078 
01079 //=================================================================================
01080 // function : keyPressEvent()
01081 // purpose  :
01082 //=================================================================================
01083 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
01084 {
01085   QDialog::keyPressEvent( e );
01086   if ( e->isAccepted() )
01087     return;
01088 
01089   if ( e->key() == Qt::Key_F1 ) {
01090     e->accept();
01091     ClickOnHelp();
01092   }
01093 }
01094 
01095 //=================================================================================
01096 // function : setFilters()
01097 // purpose  : SLOT. Called when "Filter" button pressed.
01098 //=================================================================================
01099 void SMESHGUI_ExtrusionDlg::setFilters()
01100 {
01101   if(myMesh->_is_nil()) {
01102     SUIT_MessageBox::critical(this,
01103                               tr("SMESH_ERROR"),
01104                               tr("NO_MESH_SELECTED"));
01105    return;
01106   }
01107   if ( !myFilterDlg )
01108   {
01109     QList<int> types;  
01110     types.append( SMESH::NODE );
01111     types.append( SMESH::EDGE );
01112     types.append( SMESH::FACE );
01113     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
01114   }
01115   switch( GetConstructorId() ){
01116     case 0: 
01117       {
01118       myFilterDlg->Init( SMESH::NODE );
01119         break;
01120       }
01121     case 1:
01122       {
01123       myFilterDlg->Init( SMESH::EDGE );
01124         break;
01125       }
01126     case 2:
01127       {
01128       myFilterDlg->Init( SMESH::FACE );
01129         break;
01130       }
01131   }
01132   
01133 
01134   myFilterDlg->SetSelection();
01135   myFilterDlg->SetMesh( myMesh );
01136   myFilterDlg->SetSourceWg( LineEditElements );
01137 
01138   myFilterDlg->show();
01139 }
01140 
01141 //=================================================================================
01142 // function : isValid
01143 // purpose  :
01144 //=================================================================================
01145 bool SMESHGUI_ExtrusionDlg::isValid()
01146 {
01147   QString msg;
01148   bool ok = true;
01149   if ( RadioButton3->isChecked() ) {
01150     ok = SpinBox_Dx->isValid( msg, true ) && ok;
01151     ok = SpinBox_Dy->isValid( msg, true ) && ok;
01152     ok = SpinBox_Dz->isValid( msg, true ) && ok;
01153   } else if ( RadioButton4->isChecked() ) {
01154     ok = SpinBox_Vx->isValid( msg, true ) && ok;
01155     ok = SpinBox_Vy->isValid( msg, true ) && ok;
01156     ok = SpinBox_Vz->isValid( msg, true ) && ok;
01157     ok = SpinBox_VDist->isValid( msg, true ) && ok;
01158   }
01159   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
01160 
01161   if( !ok ) {
01162     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
01163     if ( !msg.isEmpty() )
01164       str += "\n" + msg;
01165     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
01166     return false;
01167   }
01168   return true;
01169 }
01170 
01171 //=================================================================================
01172 // function : onDisplaySimulation
01173 // purpose  : Show/Hide preview
01174 //=================================================================================
01175 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview ) {
01176   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
01177     if (myNbOkElements && isValid() && isValuesValid()) {
01178       //Get input vector
01179       SMESH::DirStruct aVector;
01180       getExtrusionVector(aVector);
01181 
01182       //Get Number of the steps 
01183       long aNbSteps = (long)SpinBox_NbSteps->value();
01184       
01185       try {
01186         SUIT_OverrideCursor aWaitCursor;
01187         SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
01188         if( CheckBoxMesh->isChecked() ) {
01189           switch (GetConstructorId()) {
01190             case 0:
01191               {
01192                 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
01193                                         break;
01194               }
01195             case 1:
01196               {
01197                 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
01198                                         break;
01199               }
01200             case 2:
01201               {
01202                 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
01203                                         break;
01204               }
01205           }
01206         }
01207         else
01208           if(GetConstructorId() == 0)
01209             aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
01210           else
01211             aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
01212         
01213         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
01214         mySimulation->SetData(aMeshPreviewStruct._retn());
01215       } catch (...) {
01216         hidePreview();
01217       }
01218     } else {
01219       hidePreview();
01220     }
01221   } else {
01222     hidePreview();
01223   }
01224 }
01225 
01226 //=================================================================================
01227 // function : getExtrusionVector()
01228 // purpose  : get direction of the extrusion
01229 //=================================================================================
01230 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector) {
01231   if ( RadioButton3->isChecked() ) {
01232     aVector.PS.x = SpinBox_Dx->GetValue();
01233     aVector.PS.y = SpinBox_Dy->GetValue();
01234     aVector.PS.z = SpinBox_Dz->GetValue();      
01235   } else if ( RadioButton4->isChecked() ) {
01236     gp_XYZ aNormale(SpinBox_Vx->GetValue(),
01237                     SpinBox_Vy->GetValue(),
01238                     SpinBox_Vz->GetValue());
01239     
01240     
01241     aNormale /= aNormale.Modulus();
01242     double aVDist = (double)SpinBox_VDist->value();
01243     
01244     aVector.PS.x = aNormale.X()*aVDist;
01245     aVector.PS.y = aNormale.Y()*aVDist;
01246     aVector.PS.z = aNormale.Z()*aVDist;
01247   }
01248 }