Back to index

salome-smesh  6.5.0
SMESHGUI_ExtrusionAlongPathDlg.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_ExtrusionAlongPathDlg.cxx
00025 // Author : Vadim SANDLER, Open CASCADE S.A.S.
00026 // SMESH includes
00027 
00028 #include "SMESHGUI_ExtrusionAlongPathDlg.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_NumberFilter.hxx>
00042 #include <SMESH_LogicalFilter.hxx>
00043 
00044 #include <SMDS_Mesh.hxx>
00045 
00046 // SALOME GEOM includes
00047 #include <GEOMBase.h>
00048 
00049 // SALOME GUI includes
00050 #include <SUIT_ResourceMgr.h>
00051 #include <SUIT_OverrideCursor.h>
00052 #include <SUIT_Desktop.h>
00053 #include <SUIT_MessageBox.h>
00054 #include <SUIT_Session.h>
00055 
00056 #include <LightApp_Application.h>
00057 #include <LightApp_SelectionMgr.h>
00058 
00059 #include <SVTK_ViewWindow.h>
00060 
00061 // OCCT includes
00062 #include <BRep_Tool.hxx>
00063 #include <TopoDS_Vertex.hxx>
00064 #include <gp_Pnt.hxx>
00065 #include <TColStd_MapOfInteger.hxx>
00066 
00067 // Qt includes
00068 #include <QButtonGroup>
00069 #include <QGroupBox>
00070 #include <QLabel>
00071 #include <QLineEdit>
00072 #include <QPushButton>
00073 #include <QToolButton>
00074 #include <QRadioButton>
00075 #include <QCheckBox>
00076 #include <QListWidget>
00077 #include <QVBoxLayout>
00078 #include <QHBoxLayout>
00079 #include <QGridLayout>
00080 #include <QKeyEvent>
00081 
00082 // IDL includes
00083 #include <SALOMEconfig.h>
00084 #include CORBA_SERVER_HEADER(SMESH_Group)
00085 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00086 
00087 #define SPACING 6
00088 #define MARGIN  11
00089 
00090 class SMESHGUI_ExtrusionAlongPathDlg::SetBusy
00091 {
00092 public:
00093   SetBusy( SMESHGUI_ExtrusionAlongPathDlg* _dlg )
00094   {
00095     myDlg = _dlg; 
00096     myDlg->myBusy = true;
00097   }
00098   
00099   ~SetBusy()
00100   { 
00101     myDlg->myBusy = false;
00102   }
00103   
00104 private:
00105   SMESHGUI_ExtrusionAlongPathDlg* myDlg;
00106 };
00107 
00108 //=================================================================================
00109 // function : SMESHGUI_ExtrusionAlongPathDlg()
00110 // purpose  : constructor
00111 //=================================================================================
00112 SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg( SMESHGUI* theModule )
00113   : SMESHGUI_PreviewDlg( theModule ),
00114     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00115     myFilterDlg( 0 )
00116 {
00117   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
00118   QPixmap edgeImage   ( mgr->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
00119   QPixmap faceImage   ( mgr->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
00120   QPixmap selectImage ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
00121   QPixmap addImage    ( mgr->loadPixmap("SMESH", tr("ICON_APPEND")));
00122   QPixmap removeImage ( mgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
00123 
00124   myType = -1;
00125 
00126   setModal( false );
00127   setAttribute( Qt::WA_DeleteOnClose, true );
00128   setWindowTitle(tr("EXTRUSION_ALONG_PATH"));
00129   setSizeGripEnabled(true);
00130 
00131   QVBoxLayout* topLayout = new QVBoxLayout(this);
00132   topLayout->setSpacing(SPACING);
00133   topLayout->setMargin(MARGIN);
00134 
00135   /***************************************************************/
00136   // Elements type group box (1d / 2d elements)
00137   ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
00138   GroupConstructors = new QButtonGroup(this);
00139   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
00140   ConstructorsBoxLayout->setSpacing(SPACING); ConstructorsBoxLayout->setMargin(MARGIN);
00141 
00142   Elements1dRB = new QRadioButton(ConstructorsBox);
00143   Elements1dRB->setIcon(edgeImage);
00144   Elements2dRB = new QRadioButton(ConstructorsBox);
00145   Elements2dRB->setIcon(faceImage);
00146   Elements1dRB->setChecked(true);
00147 
00148   // layouting
00149   ConstructorsBoxLayout->addWidget(Elements1dRB);
00150   ConstructorsBoxLayout->addWidget(Elements2dRB);
00151   GroupConstructors->addButton(Elements1dRB,  0);
00152   GroupConstructors->addButton(Elements2dRB, 1);
00153 
00154   /***************************************************************/
00155   // Arguments group box
00156   GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
00157   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
00158   GroupArgumentsLayout->setSpacing(SPACING); GroupArgumentsLayout->setMargin(MARGIN);
00159 
00160   myIdValidator = new SMESHGUI_IdValidator(this);
00161 
00162   // Controls for elements selection
00163   ElementsLab = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
00164 
00165   SelectElementsButton = new QToolButton(GroupArguments);
00166   SelectElementsButton->setIcon(selectImage);
00167 
00168   ElementsLineEdit = new QLineEdit(GroupArguments);
00169   ElementsLineEdit->setValidator(myIdValidator);
00170   ElementsLineEdit->setMaxLength(-1);
00171   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
00172   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
00173 
00174   // Controls for the whole mesh selection
00175   MeshCheck = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
00176 
00177   // Controls for path selection
00178   PathGrp = new QGroupBox(tr("SMESH_PATH"), GroupArguments);
00179   QGridLayout* PathGrpLayout = new QGridLayout(PathGrp);
00180   PathGrpLayout->setSpacing(SPACING); PathGrpLayout->setMargin(MARGIN);
00181 
00182   // Controls for path mesh selection
00183   QLabel* PathMeshLab = new QLabel(tr("SMESH_PATH_MESH"), PathGrp);
00184 
00185   SelectPathMeshButton = new QToolButton(PathGrp);
00186   SelectPathMeshButton->setIcon(selectImage);
00187 
00188   PathMeshLineEdit = new QLineEdit(PathGrp);
00189   PathMeshLineEdit->setReadOnly(true);
00190 
00191   // Controls for path starting point selection
00192   QLabel* StartPointLab = new QLabel(tr("SMESH_PATH_START"), PathGrp);
00193 
00194   SelectStartPointButton = new QToolButton(PathGrp);
00195   SelectStartPointButton->setIcon(selectImage);
00196 
00197   StartPointLineEdit = new QLineEdit(PathGrp);
00198   StartPointLineEdit->setValidator(new QIntValidator(this));
00199 
00200   // layouting
00201   PathGrpLayout->addWidget(PathMeshLab,            0, 0);
00202   PathGrpLayout->addWidget(SelectPathMeshButton,   0, 1);
00203   PathGrpLayout->addWidget(PathMeshLineEdit,       0, 2);
00204   PathGrpLayout->addWidget(StartPointLab,          1, 0);
00205   PathGrpLayout->addWidget(SelectStartPointButton, 1, 1);
00206   PathGrpLayout->addWidget(StartPointLineEdit,     1, 2);
00207 
00208   BasePointGrp = new QGroupBox(tr("SMESH_BASE_POINT"), GroupArguments);
00209   BasePointGrp->setCheckable(true);
00210   BasePointGrp->setChecked(false);
00211   QHBoxLayout* BasePointGrpLayout = new QHBoxLayout(BasePointGrp);
00212   BasePointGrpLayout->setSpacing(SPACING); BasePointGrpLayout->setMargin(MARGIN);
00213 
00214   SelectBasePointButton = new QToolButton(BasePointGrp);
00215   SelectBasePointButton->setIcon(selectImage);
00216 
00217   QLabel* XLab  = new QLabel(tr("SMESH_X"), BasePointGrp);
00218   XSpin = new SMESHGUI_SpinBox(BasePointGrp);
00219   QLabel* YLab  = new QLabel(tr("SMESH_Y"), BasePointGrp);
00220   YSpin = new SMESHGUI_SpinBox(BasePointGrp);
00221   QLabel* ZLab  = new QLabel(tr("SMESH_Z"), BasePointGrp);
00222   ZSpin = new SMESHGUI_SpinBox(BasePointGrp);
00223 
00224   // layouting
00225   BasePointGrpLayout->addWidget(SelectBasePointButton);
00226   BasePointGrpLayout->addWidget(XLab);
00227   BasePointGrpLayout->addWidget(XSpin);
00228   BasePointGrpLayout->addWidget(YLab);
00229   BasePointGrpLayout->addWidget(YSpin);
00230   BasePointGrpLayout->addWidget(ZLab);
00231   BasePointGrpLayout->addWidget(ZSpin);
00232 
00233   AnglesGrp = new QGroupBox(tr("SMESH_ANGLES"), GroupArguments);
00234   AnglesGrp->setCheckable(true);
00235   AnglesGrp->setChecked(false);
00236   QGridLayout* AnglesGrpLayout = new QGridLayout(AnglesGrp);
00237   AnglesGrpLayout->setSpacing(SPACING); AnglesGrpLayout->setMargin(MARGIN);
00238 
00239   AnglesList = new QListWidget(AnglesGrp);
00240   AnglesList->setSelectionMode(QListWidget::ExtendedSelection);
00241 
00242   AddAngleButton = new QToolButton(AnglesGrp);
00243   AddAngleButton->setIcon(addImage);
00244 
00245   RemoveAngleButton = new QToolButton(AnglesGrp);
00246   RemoveAngleButton->setIcon(removeImage);
00247 
00248   AngleSpin = new SMESHGUI_SpinBox(AnglesGrp);
00249 
00250   LinearAnglesCheck = new QCheckBox(tr("LINEAR_ANGLES"), AnglesGrp);
00251 
00252   // layouting
00253   AnglesGrpLayout->addWidget(AnglesList,        0, 0, 4, 1);
00254   AnglesGrpLayout->addWidget(AddAngleButton,    0, 1);
00255   AnglesGrpLayout->addWidget(RemoveAngleButton, 2, 1);
00256   AnglesGrpLayout->addWidget(AngleSpin,         0, 2);
00257   AnglesGrpLayout->addWidget(LinearAnglesCheck, 4, 0);
00258   AnglesGrpLayout->setRowMinimumHeight(1, 10);
00259   AnglesGrpLayout->setRowStretch(3, 10);
00260 
00261   // CheckBox for groups generation
00262   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
00263   MakeGroupsCheck->setChecked(true);
00264 
00265   //Preview check box
00266   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
00267 
00268   // layouting
00269   GroupArgumentsLayout->addWidget(ElementsLab,          0, 0);
00270   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
00271   GroupArgumentsLayout->addWidget(ElementsLineEdit,     0, 2);
00272   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 3);
00273   GroupArgumentsLayout->addWidget(MeshCheck,            1, 0, 1, 4);
00274   GroupArgumentsLayout->addWidget(PathGrp,              2, 0, 1, 4);
00275   GroupArgumentsLayout->addWidget(BasePointGrp,         3, 0, 1, 4);
00276   GroupArgumentsLayout->addWidget(AnglesGrp,            4, 0, 1, 4);
00277   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    5, 0, 1, 4);
00278   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      6, 0, 1, 4);
00279 
00280   /***************************************************************/
00281   // common buttons group box
00282   GroupButtons = new QGroupBox(this);
00283   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00284   GroupButtonsLayout->setSpacing(SPACING); GroupButtonsLayout->setMargin(MARGIN);
00285 
00286   OkButton = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00287   OkButton->setAutoDefault(true);
00288   OkButton->setDefault(true);
00289 
00290   ApplyButton = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00291   ApplyButton->setAutoDefault(true);
00292 
00293   CloseButton = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00294   CloseButton->setAutoDefault(true);
00295 
00296   HelpButton = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00297   HelpButton->setAutoDefault(true);
00298 
00299   // layouting
00300   GroupButtonsLayout->addWidget(OkButton);
00301   GroupButtonsLayout->addSpacing(10);
00302   GroupButtonsLayout->addWidget(ApplyButton);
00303   GroupButtonsLayout->addSpacing(10);
00304   GroupButtonsLayout->addStretch();
00305   GroupButtonsLayout->addWidget(CloseButton);
00306   GroupButtonsLayout->addWidget(HelpButton);
00307 
00308   /***************************************************************/
00309   // layouting
00310   topLayout->addWidget(ConstructorsBox);
00311   topLayout->addWidget(GroupArguments);
00312   topLayout->addWidget(GroupButtons);
00313 
00314   /***************************************************************/
00315   // Initialisations
00316   XSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00317   YSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00318   ZSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00319   AngleSpin->RangeStepAndValidator(-180.0, 180.0, 5.0, "angle_precision");
00320 
00321   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00322 
00323   mySMESHGUI->SetActiveDialogBox(this);
00324 
00325   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
00326   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
00327   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
00328 
00329   QList<SUIT_SelectionFilter*> aListOfFilters;
00330   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
00331   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
00332 
00333   myElementsFilter = new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
00334   //myPathMeshFilter = new SMESH_TypeFilter (MESH);
00335   myPathMeshFilter = new SMESH_TypeFilter(MESHorSUBMESH);
00336 
00337   myHelpFileName = "extrusion_along_path_page.html";
00338 
00339   Init();
00340 
00341   /***************************************************************/
00342   // signals-slots connections
00343   connect(OkButton,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00344   connect(CloseButton,  SIGNAL(clicked()), this, SLOT(reject()));
00345   connect(ApplyButton,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00346   connect(HelpButton,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00347 
00348   connect(AddAngleButton,    SIGNAL(clicked()), this, SLOT(OnAngleAdded()));
00349   connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleRemoved()));
00350 
00351   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
00352 
00353   connect(SelectElementsButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00354   connect(SelectPathMeshButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00355   connect(SelectStartPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00356   connect(SelectBasePointButton,  SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00357 
00358   connect(mySMESHGUI,  SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00359   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
00360   connect(mySMESHGUI,  SIGNAL(SignalCloseAllDialogs()),        this, SLOT(reject()));
00361 
00362   connect(ElementsLineEdit, SIGNAL(textChanged(const QString&)),
00363           SLOT(onTextChange(const QString&)));
00364   connect(StartPointLineEdit, SIGNAL(textChanged(const QString&)),
00365           SLOT(onTextChange(const QString&)));
00366 
00367   connect(MeshCheck,      SIGNAL(toggled(bool)), SLOT(onSelectMesh()));
00368 
00369   connect(XSpin,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00370   connect(YSpin,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00371   connect(ZSpin,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00372   connect(AddAngleButton,  SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
00373   connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
00374   connect(LinearAnglesCheck, SIGNAL(toggled(bool)), SLOT(onSelectMesh()));
00375 
00376 
00377   //To Connect preview check box
00378   connectPreviewControl();
00379 
00380   AnglesList->installEventFilter(this);
00381   ElementsLineEdit->installEventFilter(this);
00382   StartPointLineEdit->installEventFilter(this);
00383   XSpin->editor()->installEventFilter(this);
00384   YSpin->editor()->installEventFilter(this);
00385   ZSpin->editor()->installEventFilter(this);
00386 }
00387 
00388 //=================================================================================
00389 // function : ~SMESHGUI_ExtrusionAlongPathDlg()
00390 // purpose  : destructor
00391 //=================================================================================
00392 SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg()
00393 {
00394   // no need to delete child widgets, Qt does it all for us
00395   if ( myFilterDlg != 0 ) {
00396     myFilterDlg->setParent( 0 );
00397     delete myFilterDlg;
00398   }
00399 }
00400 
00401 //=================================================================================
00402 // function : Init()
00403 // purpose  : initialization
00404 //=================================================================================
00405 void SMESHGUI_ExtrusionAlongPathDlg::Init (bool ResetControls)
00406 {
00407   myBusy = false;
00408   myEditCurrentArgument = 0;
00409 
00410   myMesh      = SMESH::SMESH_Mesh::_nil();
00411   myIDSource  = SMESH::SMESH_IDSource::_nil();
00412   myMeshActor = 0;
00413   myPath  = SMESH::SMESH_IDSource::_nil();
00414 
00415   ElementsLineEdit->clear();
00416   PathMeshLineEdit->clear();
00417   StartPointLineEdit->clear();
00418 
00419   if (ResetControls) {
00420     XSpin->SetValue(0.0);
00421     YSpin->SetValue(0.0);
00422     ZSpin->SetValue(0.0);
00423 
00424     AngleSpin->SetValue(45);
00425     MeshCheck->setChecked(false);
00426     ConstructorsClicked(0);
00427     onSelectMesh();
00428     myPreviewCheckBox->setChecked(false);
00429     onDisplaySimulation(false);
00430   }
00431   SetEditCurrentArgument(0);
00432 }
00433 
00434 //=================================================================================
00435 // function : ConstructorsClicked()
00436 // purpose  : Called when user changes type of elements (1d / 2d)
00437 //=================================================================================
00438 void SMESHGUI_ExtrusionAlongPathDlg::ConstructorsClicked (int type)
00439 {
00440   if (myType == type) return;
00441 
00442   disconnect(mySelectionMgr, 0, this, 0);
00443 
00444   hidePreview();
00445 
00446   if (type == 0)
00447     GroupArguments->setTitle(tr("EXTRUSION_1D"));
00448   else if (type == 1)
00449     GroupArguments->setTitle(tr("EXTRUSION_2D"));
00450 
00451   // clear elements ID list
00452   if (!MeshCheck->isChecked()) {
00453     ElementsLineEdit->clear();
00454   }
00455   // set selection mode if necessary
00456   if (myEditCurrentArgument == ElementsLineEdit) {
00457     mySelectionMgr->clearSelected();
00458     mySelectionMgr->clearFilters();
00459     SMESH::SetPickable();
00460 
00461     SMESH::SetPointRepresentation(false);
00462     if (MeshCheck->isChecked()) {
00463       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00464         aViewWindow->SetSelectionMode(ActorSelection);
00465       mySelectionMgr->installFilter(myElementsFilter);
00466     } else {
00467       if (type == 0)
00468         {
00469           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00470             aViewWindow->SetSelectionMode(EdgeSelection);
00471         }
00472       if (type == 1)
00473         {
00474           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00475             aViewWindow->SetSelectionMode(FaceSelection);
00476         }
00477     }
00478   }
00479   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00480 
00481   myType = type;
00482 }
00483 
00484 //=================================================================================
00485 // function : ClickOnApply()
00486 // purpose  : Called when user presses <Apply> button
00487 //=================================================================================
00488 bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
00489 {
00490   if (mySMESHGUI->isActiveStudyLocked())
00491     return false;
00492 
00493   //if (myMesh->_is_nil() || MeshCheck->isChecked() && myIDSource->_is_nil() ||
00494   //    !myMeshActor || myPathMesh->_is_nil() || myPathShape->_is_nil())
00495   if ( myMesh->_is_nil() || (MeshCheck->isChecked() && myIDSource->_is_nil()) || myPath->_is_nil() )
00497     return false;
00498 
00499   if (!isValid())
00500     return false;
00501 
00502   SMESH::long_array_var anElementsId = getSelectedElements();
00503 
00504   if (StartPointLineEdit->text().trimmed().isEmpty()) {
00505     return false;
00506   }
00507   
00508   bool bOk;
00509   long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
00510   if (!bOk) {
00511     return false;
00512   }
00513 
00514   QStringList aParameters;
00515   
00516   //get angles
00517   SMESH::double_array_var anAngles = getAngles();
00518   
00519   for (int i = 0; i < myAnglesList.count(); i++) 
00520     aParameters << AnglesList->item(i)->text();
00521 
00522 
00523   // get base point
00524   SMESH::PointStruct aBasePoint;
00525   if (BasePointGrp->isChecked()) {
00526     aBasePoint.x = XSpin->GetValue();
00527     aBasePoint.y = YSpin->GetValue();
00528     aBasePoint.z = ZSpin->GetValue();
00529   }
00530 
00531   aParameters << XSpin->text();
00532   aParameters << YSpin->text();
00533   aParameters << ZSpin->text();
00534 
00535   try {
00536     SUIT_OverrideCursor wc;
00537 
00538     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00539     SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
00540 
00541     myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00542 
00543     bool NeedGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
00544     SMESH::ElementType ElemType = SMESH::FACE;
00545     if( GetConstructorId() == 0 )
00546       ElemType = SMESH::EDGE;
00547     if( !MeshCheck->isChecked() ) {
00548       SMESH::ListOfGroups_var groups = 
00549         aMeshEditor->ExtrusionAlongPathX(anElementsId, myPath, aNodeStart, AnglesGrp->isChecked(),
00550                                          anAngles, LinearAnglesCheck->isChecked(),
00551                                          BasePointGrp->isChecked(), aBasePoint,
00552                                          NeedGroups, ElemType, retVal);
00553     }
00554     else {
00555       SMESH::ListOfGroups_var groups = 
00556         aMeshEditor->ExtrusionAlongPathObjX(myIDSource, myPath, aNodeStart, AnglesGrp->isChecked(),
00557                                           anAngles, LinearAnglesCheck->isChecked(),
00558                                           BasePointGrp->isChecked(), aBasePoint,
00559                                           NeedGroups, ElemType, retVal);
00560     }
00561 
00562 
00563     wc.suspend();
00564     switch (retVal) {
00565     case SMESH::SMESH_MeshEditor::EXTR_NO_ELEMENTS:
00566       SUIT_MessageBox::warning(this,
00567                                tr("SMESH_ERROR"),
00568                                tr("NO_ELEMENTS_SELECTED"));
00569       return false; break;
00570     case SMESH::SMESH_MeshEditor::EXTR_PATH_NOT_EDGE:
00571       SUIT_MessageBox::warning(this,
00572                                tr("SMESH_ERROR"),
00573                                tr("SELECTED_PATH_IS_NOT_EDGE"));
00574       return false; break;
00575     case SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE:
00576       SUIT_MessageBox::warning(this,
00577                                tr("SMESH_ERROR"),
00578                                tr("BAD_SHAPE_TYPE"));
00579       return false; break;
00580     case SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE:
00581       SUIT_MessageBox::warning(this,
00582                                tr("SMESH_ERROR"),
00583                                tr("EXTR_BAD_STARTING_NODE"));
00584       return false; break;
00585     case SMESH::SMESH_MeshEditor::EXTR_BAD_ANGLES_NUMBER:
00586       SUIT_MessageBox::warning(this,
00587                                tr("SMESH_ERROR"),
00588                                tr("WRONG_ANGLES_NUMBER"));
00589       return false; break;
00590     case SMESH::SMESH_MeshEditor::EXTR_CANT_GET_TANGENT:
00591       SUIT_MessageBox::warning(this,
00592                                tr("SMESH_ERROR"),
00593                                tr("CANT_GET_TANGENT"));
00594       return false; break;
00595     case SMESH::SMESH_MeshEditor::EXTR_OK:
00596       break;
00597     }
00598   } catch (...) {
00599     return false;
00600   }
00601 
00602   //mySelectionMgr->clearSelected();
00603   if ( myMeshActor )
00604     SMESH::Update( myMeshActor->getIO(), myMeshActor->GetVisibility() );
00605     
00606   SMESHGUI::Modified();
00607 
00608   if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
00609     mySMESHGUI->updateObjBrowser(true); // new groups may appear
00610   //SMESH::UpdateView();
00611   Init(false);
00612   ConstructorsClicked(GetConstructorId());
00613   return true;
00614 }
00615 
00616 //=================================================================================
00617 // function : ClickOnOk()
00618 // purpose  : Called when user presses <OK> button
00619 //=================================================================================
00620 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
00621 {
00622   if (ClickOnApply())
00623     reject();
00624 }
00625 
00626 //=================================================================================
00627 // function : ClickOnHelp()
00628 // purpose  :
00629 //=================================================================================
00630 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnHelp()
00631 {
00632   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00633   if (app) 
00634     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00635   else {
00636     QString platform;
00637 #ifdef WIN32
00638     platform = "winapplication";
00639 #else
00640     platform = "application";
00641 #endif
00642     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00643                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00644                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00645                                                                  platform)).
00646                              arg(myHelpFileName));
00647   }
00648 }
00649 
00650 //=================================================================================
00651 // function : reject()
00652 // purpose  : Called when dialog box is closed
00653 //=================================================================================
00654 void SMESHGUI_ExtrusionAlongPathDlg::reject()
00655 {
00656   disconnect(mySelectionMgr, 0, this, 0);
00657   mySelectionMgr->clearFilters();
00658   //mySelectionMgr->clearSelected();
00659   if (SMESH::GetCurrentVtkView()) {
00660     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
00661     SMESH::SetPointRepresentation(false);
00662     SMESH::SetPickable();
00663   }
00664   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00665     aViewWindow->SetSelectionMode(ActorSelection);
00666   mySMESHGUI->ResetState();
00667   QDialog::reject();
00668 }
00669 
00670 //=======================================================================
00671 // function : onTextChange()
00672 // purpose  :
00673 //=======================================================================
00674 void SMESHGUI_ExtrusionAlongPathDlg::onTextChange (const QString& theNewText)
00675 {
00676   QLineEdit* send = (QLineEdit*)sender();
00677 
00678   // return if busy
00679   if (myBusy) return;
00680 
00681   // set busy flag
00682   SetBusy sb (this);
00683 
00684   if (send != StartPointLineEdit && send != ElementsLineEdit)
00685     send = ElementsLineEdit;
00686 
00687   if (send == ElementsLineEdit && myEditCurrentArgument == ElementsLineEdit) {
00688     // hilight entered elements
00689     SMDS_Mesh* aMesh = 0;
00690     if (myMeshActor)
00691       aMesh = myMeshActor->GetObject()->GetMesh();
00692 
00693     if (aMesh) {
00694       //mySelectionMgr->clearSelected();
00695       //mySelectionMgr->AddIObject(myMeshActor->getIO());
00696       SALOME_ListIO aList;
00697       aList.Append(myMeshActor->getIO());
00698       mySelectionMgr->setSelectedObjects(aList, false);
00699 
00700       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00701       bool bOk;
00702       const Handle(SALOME_InteractiveObject)& anIO = myMeshActor->getIO();
00703       TColStd_MapOfInteger newIndices;
00704       for (int i = 0; i < aListId.count(); i++) {
00705         long ind = aListId[ i ].toLong(&bOk);
00706         if (bOk) {
00707           const SMDS_MeshElement* e = aMesh->FindElement(ind);
00708           if (e) {
00709             // check also type of element
00710             bool typeMatch = (Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge) ||
00711                              (Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face);
00712             if (typeMatch)
00713               newIndices.Add(e->GetID());
00714           }
00715         }
00716       }
00717       mySelector->AddOrRemoveIndex(anIO, newIndices, false);
00718       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00719         aViewWindow->highlight( anIO, true, true );
00720     }
00721   }
00722   else if (send == StartPointLineEdit &&
00723              myEditCurrentArgument == StartPointLineEdit) {
00724     if (!myPath->_is_nil()) {
00725       SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
00726       SMDS_Mesh* aMesh = 0;
00727       if (aPathActor)
00728         aMesh = aPathActor->GetObject()->GetMesh();
00729       if (aMesh) {
00730         //mySelectionMgr->clearSelected();
00731         //mySelectionMgr->AddIObject(aPathActor->getIO());
00732         SALOME_ListIO aList;
00733         aList.Append(aPathActor->getIO());
00734         mySelectionMgr->setSelectedObjects(aList, false);
00735 
00736         bool bOk;
00737         long ind = theNewText.toLong(&bOk);
00738         if (bOk) {
00739           const SMDS_MeshNode* n = aMesh->FindNode(ind);
00740           if (n) {
00741             //if (!mySelectionMgr->IsIndexSelected(aPathActor->getIO(), n->GetID())) {
00742             TColStd_MapOfInteger newIndices;
00743             newIndices.Add(n->GetID());
00744             mySelector->AddOrRemoveIndex( aPathActor->getIO(), newIndices, false );
00745             if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00746               aViewWindow->highlight( aPathActor->getIO(), true, true );
00747           }
00748         }
00749       }
00750     }
00751   }
00752 }
00753 
00754 //=================================================================================
00755 // function : SelectionIntoArgument()
00756 // purpose  : Called when selection as changed or other case
00757 //=================================================================================
00758 void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
00759 {
00760   if (myBusy) return;
00761 
00762   // return if dialog box is inactive
00763   if (!GroupButtons->isEnabled())
00764     return;
00765 
00766   // selected objects count
00767   const SALOME_ListIO& aList = mySelector->StoredIObjects();
00768   int nbSel = aList.Extent();
00769   if (nbSel != 1)
00770     return;
00771 
00772   // set busy flag
00773   SetBusy sb (this);
00774 
00775   if (myEditCurrentArgument == ElementsLineEdit) {
00776     // we are now selecting mesh elements (or whole mesh/submesh/group)
00777     // reset
00778     ElementsLineEdit->clear();
00779     myMesh      = SMESH::SMESH_Mesh::_nil();
00780     myIDSource  = SMESH::SMESH_IDSource::_nil();
00781     myMeshActor = 0;
00782 
00783     // try to get mesh from selection
00784     Handle(SALOME_InteractiveObject) IO = aList.First();
00785     myMesh = SMESH::GetMeshByIO(IO);
00786     if (myMesh->_is_nil())
00787       return;
00788 
00789     // MakeGroups is available if there are groups
00790     if ( myMesh->NbGroups() == 0 ) {
00791       MakeGroupsCheck->setChecked(false);
00792       MakeGroupsCheck->setEnabled(false);
00793     } else {
00794       MakeGroupsCheck->setEnabled(true);
00795     }
00796     // find actor
00797     myMeshActor = SMESH::FindActorByObject(myMesh);
00798     if (!myMeshActor && !MeshCheck->isChecked())
00799       return;
00800 
00801     if (MeshCheck->isChecked()) {
00802       // If "Select whole mesh, submesh or group" check box is on ->
00803       // get ID source and put it's name to the edit box
00804       QString aString;
00805       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00806 
00807       myIDSource = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
00808       ElementsLineEdit->setText(aString);
00809     } else {
00810       // If "Select whole mesh, submesh or group" check box is off ->
00811       // try to get selected elements IDs
00812       QString aString;
00813       //int aNbUnits = SMESH::GetNameOfSelectedElements(mySelectionMgr, aString);
00814       SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
00815       ElementsLineEdit->setText(aString);
00816     }
00817   }
00818   else if (myEditCurrentArgument == PathMeshLineEdit) {
00819     // we are now selecting path mesh
00820     // reset
00821     PathMeshLineEdit->clear();
00822     myPath = SMESH::SMESH_IDSource::_nil();
00823     StartPointLineEdit->clear();
00824     
00825     // try to get mesh from selection
00826     Handle(SALOME_InteractiveObject) IO = aList.First();
00827     myPath = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
00828     if( myPath->_is_nil() )
00829       return;
00830     
00831     QString aString;
00832     SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00833     PathMeshLineEdit->setText(aString);
00834   }
00835   else if (myEditCurrentArgument == StartPointLineEdit) {
00836     // we are now selecting start point of path
00837     // reset
00838     StartPointLineEdit->clear();
00839 
00840     // return if path mesh or path shape is not yet selected
00841     if( myPath->_is_nil() )
00842       return;
00843 
00844     // try to get shape from selection
00845     Handle(SALOME_InteractiveObject) IO = aList.First();
00846 
00847     SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
00848     if ( !aPathActor )
00849       return;
00850     
00851     QString aString;
00852     int aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aPathActor->getIO(), aString);
00853     if (aNbUnits == 1)
00854       StartPointLineEdit->setText(aString.trimmed());
00855 
00856   } else if (myEditCurrentArgument == XSpin) {
00857     // we are now selecting base point
00858     // reset is not performed here!
00859 
00860     // return if is not enabled
00861     if (!BasePointGrp->isChecked())
00862       return;
00863 
00864     // try to get shape from selection
00865     Handle(SALOME_InteractiveObject) IO = aList.First();
00866 
00867     // check if geom vertex is selected
00868     GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
00869     TopoDS_Vertex aVertex;
00870     if (!aGeomObj->_is_nil()) {
00871       if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
00872         gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
00873         XSpin->SetValue(aPnt.X());
00874         YSpin->SetValue(aPnt.Y());
00875         ZSpin->SetValue(aPnt.Z());
00876       }
00877       return;
00878     }
00879 
00880     // check if smesh node is selected
00881     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
00882     if (aMesh->_is_nil())
00883       return;
00884 
00885     QString aString;
00886     int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myMeshActor->getIO(), aString);
00887     // return if more than one node is selected
00888     if (aNbUnits != 1)
00889       return;
00890 
00891     SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
00892     if (!aMeshActor)
00893       return;
00894 
00895     SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
00896     if (!mesh)
00897       return;
00898 
00899     const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
00900     if (!n)
00901       return;
00902 
00903     XSpin->SetValue(n->X());
00904     YSpin->SetValue(n->Y());
00905     ZSpin->SetValue(n->Z());
00906   }
00907   onDisplaySimulation(true);
00908 }
00909 
00910 //=================================================================================
00911 // function : SetEditCurrentArgument()
00912 // purpose  :
00913 //=================================================================================
00914 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
00915 {
00916   QToolButton* send = (QToolButton*)sender();
00917   if (send != SelectElementsButton   &&
00918       send != SelectPathMeshButton   &&
00919       send != SelectStartPointButton &&
00920       send != SelectBasePointButton)
00921     return;
00922   SetEditCurrentArgument(send);
00923 }
00924 
00925 //=================================================================================
00926 // function : SetEditCurrentArgument()
00927 // purpose  :
00928 //=================================================================================
00929 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument (QToolButton* button)
00930 {
00931   disconnect(mySelectionMgr, 0, this, 0);
00932   //  mySelectionMgr->clearSelected();
00933   mySelectionMgr->clearFilters();
00934   SMESH::SetPickable();
00935 
00936   if (button == SelectElementsButton) {
00937     myEditCurrentArgument = ElementsLineEdit;
00938     SMESH::SetPointRepresentation(false);
00939     if (MeshCheck->isChecked()) {
00940       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00941         aViewWindow->SetSelectionMode(ActorSelection);
00942       mySelectionMgr->installFilter(myElementsFilter);
00943     } else {
00944       if (Elements1dRB->isChecked())
00945         {
00946           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00947             aViewWindow->SetSelectionMode(EdgeSelection);
00948         }
00949       else if (Elements2dRB->isChecked())
00950         {
00951           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00952             aViewWindow->SetSelectionMode(FaceSelection);
00953         }
00954     }
00955   } else if (button == SelectPathMeshButton) {
00956     myEditCurrentArgument = PathMeshLineEdit;
00957     SMESH::SetPointRepresentation(false);
00958     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00959       aViewWindow->SetSelectionMode(ActorSelection);
00960     mySelectionMgr->installFilter(myPathMeshFilter);
00961   }
00962   else if (button == SelectStartPointButton) {
00963     myEditCurrentArgument = StartPointLineEdit;
00964     //if (!myPathMesh->_is_nil()) {
00965     if (!myPath->_is_nil()) {
00966       SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
00967       if (aPathActor) {
00968         SMESH::SetPointRepresentation(true);
00969         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00970           aViewWindow->SetSelectionMode(NodeSelection);
00971         SMESH::SetPickable(aPathActor);
00972       }
00973     }
00974   }
00975   else if (button == SelectBasePointButton) {
00976     myEditCurrentArgument = XSpin;
00977     SMESH::SetPointRepresentation(true);
00978     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00979       aViewWindow->SetSelectionMode(NodeSelection);
00980 
00981     SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(MESHorSUBMESH);
00982     SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter(GROUP);
00983     SMESH_NumberFilter* aVertexFilter      = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE,
00984                                                                      -1, TopAbs_VERTEX);
00985     QList<SUIT_SelectionFilter*> aListOfFilters;
00986     if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
00987     if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
00988     if (aVertexFilter)        aListOfFilters.append(aVertexFilter);
00989 
00990     mySelectionMgr->installFilter(new SMESH_LogicalFilter
00991                                   (aListOfFilters, SMESH_LogicalFilter::LO_OR));
00992   }
00993 
00994   if (myEditCurrentArgument && !myEditCurrentArgument->hasFocus())
00995     myEditCurrentArgument->setFocus();
00996 
00997   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00998   SelectionIntoArgument();
00999 }
01000 
01001 //=================================================================================
01002 // function : DeactivateActiveDialog()
01003 // purpose  : Deactivates this dialog
01004 //=================================================================================
01005 void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
01006 {
01007   if (ConstructorsBox->isEnabled()) {
01008     ConstructorsBox->setEnabled(false);
01009     GroupArguments->setEnabled(false);
01010     GroupButtons->setEnabled(false);
01011     mySMESHGUI->ResetState();
01012     mySMESHGUI->SetActiveDialogBox(0);
01013   }
01014 }
01015 
01016 //=================================================================================
01017 // function : ActivateThisDialog()
01018 // purpose  : Activates this dialog
01019 //=================================================================================
01020 void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
01021 {
01022   // Emit a signal to deactivate the active dialog
01023   mySMESHGUI->EmitSignalDeactivateDialog();
01024   ConstructorsBox->setEnabled(true);
01025   GroupArguments->setEnabled(true);
01026   GroupButtons->setEnabled(true);
01027 
01028   mySMESHGUI->SetActiveDialogBox(this);
01029 
01030   ConstructorsClicked(GetConstructorId());
01031   SelectionIntoArgument();
01032 }
01033 
01034 //=================================================================================
01035 // function : enterEvent()
01036 // purpose  : Mouse enter event
01037 //=================================================================================
01038 void SMESHGUI_ExtrusionAlongPathDlg::enterEvent (QEvent*)
01039 {
01040   if (!ConstructorsBox->isEnabled())
01041     ActivateThisDialog();
01042 }
01043 
01044 //=======================================================================
01045 // function : onSelectMesh()
01046 // purpose  :
01047 //=======================================================================
01048 void SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh()
01049 {
01050   bool toSelectMesh = MeshCheck->isChecked();
01051 
01052   ElementsLineEdit->setReadOnly(toSelectMesh);
01053   ElementsLineEdit->setValidator(toSelectMesh ? 0 : myIdValidator);
01054   ElementsLab->setText(toSelectMesh ? tr("SMESH_NAME") : tr("SMESH_ID_ELEMENTS"));
01055   ElementsLineEdit->clear();
01056   myFilterBtn->setEnabled(!toSelectMesh);
01057 
01058   SetEditCurrentArgument(SelectElementsButton);
01059 }
01060 
01061 //=================================================================================
01062 // function : GetConstructorId()
01063 // purpose  :
01064 //=================================================================================
01065 int SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId()
01066 {
01067   return GroupConstructors->checkedId();
01068 }
01069 
01070 //=======================================================================
01071 // function : OnAngleAdded()
01072 // purpose  : Called when user adds angle to the list
01073 //=======================================================================
01074 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
01075 {
01076   QString msg;
01077   if( !AngleSpin->isValid( msg, true ) ) {
01078     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
01079     if ( !msg.isEmpty() )
01080       str += "\n" + msg;
01081     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
01082     return;
01083   }
01084   AnglesList->addItem(AngleSpin->text());
01085   myAnglesList.append(AngleSpin->GetValue());
01086 
01087   updateLinearAngles();
01088 }
01089 
01090 //=======================================================================
01091 // function : OnAngleRemoved()
01092 // purpose  : Called when user removes angle(s) from the list
01093 //=======================================================================
01094 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
01095 {
01096   QList<QListWidgetItem*> aList = AnglesList->selectedItems();
01097   QListWidgetItem* anItem;
01098   foreach(anItem, aList) {
01099     myAnglesList.removeAt(AnglesList->row(anItem));
01100     delete anItem;
01101   }
01102 
01103   updateLinearAngles();
01104 }
01105 
01106 //=================================================================================
01107 // function : eventFilter()
01108 // purpose  : event filter ???
01109 //=================================================================================
01110 bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter (QObject* object, QEvent* event)
01111 {
01112   if (event->type() == QEvent::KeyPress) {
01113     QKeyEvent* ke = (QKeyEvent*)event;
01114     if (object == AnglesList) {
01115       if (ke->key() == Qt::Key_Delete)
01116         OnAngleRemoved();
01117     }
01118   }
01119   else if (event->type() == QEvent::FocusIn) {
01120     if (object == ElementsLineEdit) {
01121       if (myEditCurrentArgument != ElementsLineEdit)
01122         SetEditCurrentArgument(SelectElementsButton);
01123     }
01124     else if (object == StartPointLineEdit) {
01125       if (myEditCurrentArgument != StartPointLineEdit)
01126         SetEditCurrentArgument(SelectStartPointButton);
01127     }
01128     else if (object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor()) {
01129       if (myEditCurrentArgument != XSpin)
01130         SetEditCurrentArgument(SelectBasePointButton);
01131     }
01132   }
01133   return QDialog::eventFilter(object, event);
01134 }
01135 
01136 //=================================================================================
01137 // function : keyPressEvent()
01138 // purpose  :
01139 //=================================================================================
01140 void SMESHGUI_ExtrusionAlongPathDlg::keyPressEvent( QKeyEvent* e )
01141 {
01142   QDialog::keyPressEvent( e );
01143   if ( e->isAccepted() )
01144     return;
01145 
01146   if ( e->key() == Qt::Key_F1 ) {
01147     e->accept();
01148     ClickOnHelp();
01149   }
01150 }
01151 
01152 //=================================================================================
01153 // function : setFilters()
01154 // purpose  : SLOT. Called when "Filter" button pressed.
01155 //=================================================================================
01156 void SMESHGUI_ExtrusionAlongPathDlg::setFilters()
01157 {
01158   if(myMesh->_is_nil()) {
01159     SUIT_MessageBox::critical(this,
01160                               tr("SMESH_ERROR"),
01161                               tr("NO_MESH_SELECTED"));
01162    return;
01163   }
01164   if ( !myFilterDlg )
01165   {
01166     QList<int> types;  
01167     types.append( SMESH::EDGE );
01168     types.append( SMESH::FACE );
01169     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
01170   }
01171   myFilterDlg->Init( Elements1dRB->isChecked() ? SMESH::EDGE : SMESH::FACE );
01172 
01173   myFilterDlg->SetSelection();
01174   myFilterDlg->SetMesh( myMesh );
01175   myFilterDlg->SetSourceWg( ElementsLineEdit );
01176 
01177   myFilterDlg->show();
01178 }
01179 
01180 //=================================================================================
01181 // function : isValid
01182 // purpose  :
01183 //=================================================================================
01184 bool SMESHGUI_ExtrusionAlongPathDlg::isValid()
01185 {
01186   QString msg;
01187   bool ok = true;
01188   ok = XSpin->isValid( msg, true ) && ok;
01189   ok = YSpin->isValid( msg, true ) && ok;
01190   ok = ZSpin->isValid( msg, true ) && ok;
01191 
01192   if( !ok ) {
01193     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
01194     if ( !msg.isEmpty() )
01195       str += "\n" + msg;
01196     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
01197     return false;
01198   }
01199   return true;
01200 }
01201 
01202 //=================================================================================
01203 // function : updateLinearAngles
01204 // purpose  :
01205 //=================================================================================
01206 void SMESHGUI_ExtrusionAlongPathDlg::updateLinearAngles()
01207 {
01208   bool enableLinear = true;
01209   for( int row = 0, nbRows = AnglesList->count(); row < nbRows; row++ ) {
01210     if( QListWidgetItem* anItem = AnglesList->item( row ) ) {
01211       enableLinear = false;
01212       anItem->text().toDouble(&enableLinear);
01213       if( !enableLinear )
01214         break;
01215     }
01216   }
01217   if( !enableLinear )
01218     LinearAnglesCheck->setChecked( false );
01219   LinearAnglesCheck->setEnabled( enableLinear );
01220 }
01221 
01222 //=================================================================================
01223 // function : isValuesValid()
01224 // purpose  : Return true in case if values entered into dialog are valid
01225 //=================================================================================
01226 bool SMESHGUI_ExtrusionAlongPathDlg::isValuesValid() {
01227   
01228   if ( (MeshCheck->isChecked() && myIDSource->_is_nil()) ||
01229        myMesh->_is_nil() ||
01230        myPath->_is_nil() )
01231     return false;
01232   
01233   if(!MeshCheck->isChecked()) {
01234     QStringList aListElementsId = ElementsLineEdit->text().split(" ", QString::SkipEmptyParts);
01235     if(aListElementsId.count() <= 0)
01236       return false;
01237   }
01238 
01239   bool bOk;
01240   StartPointLineEdit->text().toLong(&bOk);
01241   if (!bOk) {
01242     return false;
01243   }
01244 
01245   return true;
01246 }
01247 
01248 
01249 //=================================================================================
01250 // function : onDisplaySimulation
01251 // purpose  : Show/Hide preview
01252 //=================================================================================
01253 void SMESHGUI_ExtrusionAlongPathDlg::onDisplaySimulation( bool toDisplayPreview ) {
01254   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
01255     if(isValid() && isValuesValid()) {
01256       
01257       //Get selected elements:
01258       SMESH::long_array_var anElementsId = getSelectedElements();
01259 
01260       // get angles
01261       SMESH::double_array_var anAngles = getAngles();
01262       
01263       // get base point
01264       SMESH::PointStruct aBasePoint;
01265       if (BasePointGrp->isChecked()) {
01266         aBasePoint.x = XSpin->GetValue();
01267         aBasePoint.y = YSpin->GetValue();
01268         aBasePoint.z = ZSpin->GetValue();
01269       }
01270       bool bOk;
01271       long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
01272       if (bOk) {
01273         
01274         try {
01275           SUIT_OverrideCursor wc;
01276           
01277           SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
01278           SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
01279           bool NeedGroups = false;
01280           SMESH::ElementType ElemType = SMESH::FACE;
01281           if( GetConstructorId() == 0 )
01282             ElemType = SMESH::EDGE;
01283           if( !MeshCheck->isChecked() ) {
01284             aMeshEditor->ExtrusionAlongPathX(anElementsId, myPath, aNodeStart, AnglesGrp->isChecked(),
01285                                              anAngles, LinearAnglesCheck->isChecked(),
01286                                              BasePointGrp->isChecked(), aBasePoint,
01287                                              NeedGroups, ElemType, retVal);
01288           }
01289           else {
01290             SMESH::ListOfGroups_var groups = 
01291               aMeshEditor->ExtrusionAlongPathObjX(myIDSource, myPath, aNodeStart, AnglesGrp->isChecked(),
01292                                                   anAngles, LinearAnglesCheck->isChecked(),
01293                                                   BasePointGrp->isChecked(), aBasePoint,
01294                                                   NeedGroups, ElemType, retVal);
01295           }
01296           
01297           wc.suspend();
01298           if( retVal == SMESH::SMESH_MeshEditor::EXTR_OK ) {
01299             SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
01300             mySimulation->SetData(aMeshPreviewStruct._retn());
01301           } else {
01302             hidePreview();
01303           }
01304           
01305         } catch (...) {
01306           hidePreview();
01307         }
01308       } else {
01309         hidePreview();
01310       }
01311       
01312     } else {
01313       hidePreview();
01314     }
01315   } else {
01316     hidePreview();
01317   }
01318 }
01319 
01320 
01321 //=================================================================================
01322 // function : getSelectedElements
01323 // purpose  : return list of the selected elements
01324 //=================================================================================
01325 SMESH::long_array_var SMESHGUI_ExtrusionAlongPathDlg::getSelectedElements() {
01326 
01327   // If "Select whole mesh, submesh or group" check box is off ->
01328   // use only elements of given type selected by user
01329   SMESH::long_array_var anElementsId = new SMESH::long_array;
01330   if (!MeshCheck->isChecked()) {
01331     
01332     SMDS_Mesh* aMesh;
01333     if ( myMeshActor )
01334       aMesh = myMeshActor->GetObject()->GetMesh();
01335     
01336     if (aMesh) {
01337       QStringList aListElementsId = ElementsLineEdit->text().split(" ", QString::SkipEmptyParts);
01338       anElementsId = new SMESH::long_array;
01339       anElementsId->length(aListElementsId.count());
01340       bool bOk;
01341       int j = 0;
01342       for (int i = 0; i < aListElementsId.count(); i++) {
01343         long ind = aListElementsId[ i ].toLong(&bOk);
01344         if  (bOk) {
01345           const SMDS_MeshElement* e = aMesh->FindElement(ind);
01346           if (e) {
01347             bool typeMatch = (Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge) ||
01348                              (Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face);
01349             if (typeMatch)
01350                   anElementsId[ j++ ] = ind;
01351           }
01352         }
01353       }
01354       anElementsId->length(j);
01355     }
01356   }
01357   return anElementsId;
01358 }
01359 
01360 SMESH::double_array_var SMESHGUI_ExtrusionAlongPathDlg::getAngles() {
01361   SMESH::double_array_var anAngles = new SMESH::double_array;
01362   if (AnglesGrp->isChecked()) {
01363     anAngles->length(myAnglesList.count());
01364     int j = 0;
01365     for (int i = 0; i < myAnglesList.count(); i++) {
01366       double angle = myAnglesList[i];
01367       anAngles[ j++ ] = angle*M_PI/180.;
01368     }
01369     anAngles->length(j);
01370   }
01371   return anAngles;
01372 }