Version: 6.3.1

src/SMESHGUI/SMESHGUI_ExtrusionAlongPathDlg.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00538     //if ( LinearAnglesCheck->isChecked() ) {
00539     //  anAngles = aMeshEditor->LinearAnglesVariation( myPathMesh, myPathShape, anAngles );
00540     //}
00541 
00542     SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
00543     /*
00544     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
00545       if( MeshCheck->isChecked() ) {
00546         if( GetConstructorId() == 0 )
00547           SMESH::ListOfGroups_var groups = 
00548             aMeshEditor->ExtrusionAlongPathObject1DMakeGroups(myIDSource, myPathMesh,
00549                                                               myPathShape, aNodeStart,
00550                                                               AnglesGrp->isChecked(), anAngles,
00551                                                               BasePointGrp->isChecked(), aBasePoint, retVal);
00552         else
00553           SMESH::ListOfGroups_var groups = 
00554             aMeshEditor->ExtrusionAlongPathObject2DMakeGroups(myIDSource, myPathMesh,
00555                                                               myPathShape, aNodeStart,
00556                                                               AnglesGrp->isChecked(), anAngles,
00557                                                               BasePointGrp->isChecked(), aBasePoint, retVal);
00558       }
00559       else
00560         SMESH::ListOfGroups_var groups = 
00561           aMeshEditor->ExtrusionAlongPathMakeGroups(anElementsId, myPathMesh,
00562                                                     myPathShape, aNodeStart,
00563                                                     AnglesGrp->isChecked(), anAngles,
00564                                                     BasePointGrp->isChecked(), aBasePoint, retVal);
00565     }
00566     else {
00567       if( MeshCheck->isChecked() ) {
00568         if( GetConstructorId() == 0 )
00569           retVal = aMeshEditor->ExtrusionAlongPathObject1D(myIDSource, myPathMesh,
00570                                                            myPathShape, aNodeStart,
00571                                                            AnglesGrp->isChecked(), anAngles,
00572                                                            BasePointGrp->isChecked(), aBasePoint);
00573         else
00574           retVal = aMeshEditor->ExtrusionAlongPathObject2D(myIDSource, myPathMesh,
00575                                                            myPathShape, aNodeStart,
00576                                                            AnglesGrp->isChecked(), anAngles,
00577                                                            BasePointGrp->isChecked(), aBasePoint);
00578       }
00579       else
00580         retVal = aMeshEditor->ExtrusionAlongPath(anElementsId, myPathMesh,
00581                                                  myPathShape, aNodeStart,
00582                                                  AnglesGrp->isChecked(), anAngles,
00583                                                  BasePointGrp->isChecked(), aBasePoint);
00584     }
00585     */
00586 
00587     bool NeedGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
00588     SMESH::ElementType ElemType = SMESH::FACE;
00589     if( GetConstructorId() == 0 )
00590       ElemType = SMESH::EDGE;
00591     if( !MeshCheck->isChecked() ) {
00592       SMESH::ListOfGroups_var groups = 
00593         aMeshEditor->ExtrusionAlongPathX(anElementsId, myPath, aNodeStart, AnglesGrp->isChecked(),
00594                                          anAngles, LinearAnglesCheck->isChecked(),
00595                                          BasePointGrp->isChecked(), aBasePoint,
00596                                          NeedGroups, ElemType, retVal);
00597     }
00598     else {
00599       SMESH::ListOfGroups_var groups = 
00600         aMeshEditor->ExtrusionAlongPathObjX(myIDSource, myPath, aNodeStart, AnglesGrp->isChecked(),
00601                                           anAngles, LinearAnglesCheck->isChecked(),
00602                                           BasePointGrp->isChecked(), aBasePoint,
00603                                           NeedGroups, ElemType, retVal);
00604     }
00605 
00606 
00607     if( retVal == SMESH::SMESH_MeshEditor::EXTR_OK )
00608       myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00609 
00610     //wc.stop();
00611     wc.suspend();
00612     switch (retVal) {
00613     case SMESH::SMESH_MeshEditor::EXTR_NO_ELEMENTS:
00614       SUIT_MessageBox::warning(this,
00615                                tr("SMESH_ERROR"),
00616                                tr("NO_ELEMENTS_SELECTED"));
00617       return false; break;
00618     case SMESH::SMESH_MeshEditor::EXTR_PATH_NOT_EDGE:
00619       SUIT_MessageBox::warning(this,
00620                                tr("SMESH_ERROR"),
00621                                tr("SELECTED_PATH_IS_NOT_EDGE"));
00622       return false; break;
00623     case SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE:
00624       SUIT_MessageBox::warning(this,
00625                                tr("SMESH_ERROR"),
00626                                tr("BAD_SHAPE_TYPE"));
00627       return false; break;
00628     case SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE:
00629       SUIT_MessageBox::warning(this,
00630                                tr("SMESH_ERROR"),
00631                                tr("EXTR_BAD_STARTING_NODE"));
00632       return false; break;
00633     case SMESH::SMESH_MeshEditor::EXTR_BAD_ANGLES_NUMBER:
00634       SUIT_MessageBox::warning(this,
00635                                tr("SMESH_ERROR"),
00636                                tr("WRONG_ANGLES_NUMBER"));
00637       return false; break;
00638     case SMESH::SMESH_MeshEditor::EXTR_CANT_GET_TANGENT:
00639       SUIT_MessageBox::warning(this,
00640                                tr("SMESH_ERROR"),
00641                                tr("CANT_GET_TANGENT"));
00642       return false; break;
00643     case SMESH::SMESH_MeshEditor::EXTR_OK:
00644       break;
00645     }
00646   } catch (...) {
00647     return false;
00648   }
00649 
00650   //mySelectionMgr->clearSelected();
00651   if ( myMeshActor )
00652     SMESH::Update( myMeshActor->getIO(), myMeshActor->GetVisibility() );
00653     
00654   SMESHGUI::Modified();
00655 
00656   if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
00657     mySMESHGUI->updateObjBrowser(true); // new groups may appear
00658   //SMESH::UpdateView();
00659   Init(false);
00660   ConstructorsClicked(GetConstructorId());
00661   return true;
00662 }
00663 
00664 //=================================================================================
00665 // function : ClickOnOk()
00666 // purpose  : Called when user presses <OK> button
00667 //=================================================================================
00668 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
00669 {
00670   if (ClickOnApply())
00671     reject();
00672 }
00673 
00674 //=================================================================================
00675 // function : ClickOnHelp()
00676 // purpose  :
00677 //=================================================================================
00678 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnHelp()
00679 {
00680   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00681   if (app) 
00682     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00683   else {
00684     QString platform;
00685 #ifdef WIN32
00686     platform = "winapplication";
00687 #else
00688     platform = "application";
00689 #endif
00690     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00691                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00692                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00693                                                                  platform)).
00694                              arg(myHelpFileName));
00695   }
00696 }
00697 
00698 //=================================================================================
00699 // function : reject()
00700 // purpose  : Called when dialog box is closed
00701 //=================================================================================
00702 void SMESHGUI_ExtrusionAlongPathDlg::reject()
00703 {
00704   disconnect(mySelectionMgr, 0, this, 0);
00705   mySelectionMgr->clearFilters();
00706   //mySelectionMgr->clearSelected();
00707   if (SMESH::GetCurrentVtkView()) {
00708     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
00709     SMESH::SetPointRepresentation(false);
00710     SMESH::SetPickable();
00711   }
00712   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00713     aViewWindow->SetSelectionMode(ActorSelection);
00714   mySMESHGUI->ResetState();
00715   QDialog::reject();
00716 }
00717 
00718 //=======================================================================
00719 // function : onTextChange()
00720 // purpose  :
00721 //=======================================================================
00722 void SMESHGUI_ExtrusionAlongPathDlg::onTextChange (const QString& theNewText)
00723 {
00724   QLineEdit* send = (QLineEdit*)sender();
00725 
00726   // return if busy
00727   if (myBusy) return;
00728 
00729   // set busy flag
00730   SetBusy sb (this);
00731 
00732   if (send != StartPointLineEdit && send != ElementsLineEdit)
00733     send = ElementsLineEdit;
00734 
00735   if (send == ElementsLineEdit && myEditCurrentArgument == ElementsLineEdit) {
00736     // hilight entered elements
00737     SMDS_Mesh* aMesh = 0;
00738     if (myMeshActor)
00739       aMesh = myMeshActor->GetObject()->GetMesh();
00740 
00741     if (aMesh) {
00742       //mySelectionMgr->clearSelected();
00743       //mySelectionMgr->AddIObject(myMeshActor->getIO());
00744       SALOME_ListIO aList;
00745       aList.Append(myMeshActor->getIO());
00746       mySelectionMgr->setSelectedObjects(aList, false);
00747 
00748       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00749       bool bOk;
00750       const Handle(SALOME_InteractiveObject)& anIO = myMeshActor->getIO();
00751       TColStd_MapOfInteger newIndices;
00752       for (int i = 0; i < aListId.count(); i++) {
00753         long ind = aListId[ i ].toLong(&bOk);
00754         if (bOk) {
00755           const SMDS_MeshElement* e = aMesh->FindElement(ind);
00756           if (e) {
00757             // check also type of element
00758             bool typeMatch = (Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge) ||
00759                              (Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face);
00760             if (typeMatch)
00761               newIndices.Add(e->GetID());
00762           }
00763         }
00764       }
00765       mySelector->AddOrRemoveIndex(anIO, newIndices, false);
00766       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00767         aViewWindow->highlight( anIO, true, true );
00768     }
00769   }
00770   else if (send == StartPointLineEdit &&
00771              myEditCurrentArgument == StartPointLineEdit) {
00772     if (!myPath->_is_nil()) {
00773       SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
00774       SMDS_Mesh* aMesh = 0;
00775       if (aPathActor)
00776         aMesh = aPathActor->GetObject()->GetMesh();
00777       if (aMesh) {
00778         //mySelectionMgr->clearSelected();
00779         //mySelectionMgr->AddIObject(aPathActor->getIO());
00780         SALOME_ListIO aList;
00781         aList.Append(aPathActor->getIO());
00782         mySelectionMgr->setSelectedObjects(aList, false);
00783 
00784         bool bOk;
00785         long ind = theNewText.toLong(&bOk);
00786         if (bOk) {
00787           const SMDS_MeshNode* n = aMesh->FindNode(ind);
00788           if (n) {
00789             //if (!mySelectionMgr->IsIndexSelected(aPathActor->getIO(), n->GetID())) {
00790             TColStd_MapOfInteger newIndices;
00791             newIndices.Add(n->GetID());
00792             mySelector->AddOrRemoveIndex( aPathActor->getIO(), newIndices, false );
00793             if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00794               aViewWindow->highlight( aPathActor->getIO(), true, true );
00795           }
00796         }
00797       }
00798     }
00799   }
00800 }
00801 
00802 //=================================================================================
00803 // function : SelectionIntoArgument()
00804 // purpose  : Called when selection as changed or other case
00805 //=================================================================================
00806 void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
00807 {
00808   if (myBusy) return;
00809 
00810   // return if dialog box is inactive
00811   if (!GroupButtons->isEnabled())
00812     return;
00813 
00814   // selected objects count
00815   const SALOME_ListIO& aList = mySelector->StoredIObjects();
00816   int nbSel = aList.Extent();
00817   if (nbSel != 1)
00818     return;
00819 
00820   // set busy flag
00821   SetBusy sb (this);
00822 
00823   if (myEditCurrentArgument == ElementsLineEdit) {
00824     // we are now selecting mesh elements (or whole mesh/submesh/group)
00825     // reset
00826     ElementsLineEdit->clear();
00827     myMesh      = SMESH::SMESH_Mesh::_nil();
00828     myIDSource  = SMESH::SMESH_IDSource::_nil();
00829     myMeshActor = 0;
00830 
00831     // try to get mesh from selection
00832     Handle(SALOME_InteractiveObject) IO = aList.First();
00833     myMesh = SMESH::GetMeshByIO(IO);
00834     if (myMesh->_is_nil())
00835       return;
00836 
00837     // MakeGroups is available if there are groups
00838     if ( myMesh->NbGroups() == 0 ) {
00839       MakeGroupsCheck->setChecked(false);
00840       MakeGroupsCheck->setEnabled(false);
00841     } else {
00842       MakeGroupsCheck->setEnabled(true);
00843     }
00844     // find actor
00845     myMeshActor = SMESH::FindActorByObject(myMesh);
00846     if (!myMeshActor && !MeshCheck->isChecked())
00847       return;
00848 
00849     if (MeshCheck->isChecked()) {
00850       // If "Select whole mesh, submesh or group" check box is on ->
00851       // get ID source and put it's name to the edit box
00852       QString aString;
00853       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00854 
00855       myIDSource = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
00856       ElementsLineEdit->setText(aString);
00857     } else {
00858       // If "Select whole mesh, submesh or group" check box is off ->
00859       // try to get selected elements IDs
00860       QString aString;
00861       //int aNbUnits = SMESH::GetNameOfSelectedElements(mySelectionMgr, aString);
00862       SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
00863       ElementsLineEdit->setText(aString);
00864     }
00865   }
00866   else if (myEditCurrentArgument == PathMeshLineEdit) {
00867     // we are now selecting path mesh
00868     // reset
00869     PathMeshLineEdit->clear();
00870     myPath = SMESH::SMESH_IDSource::_nil();
00871     StartPointLineEdit->clear();
00872     
00873     // try to get mesh from selection
00874     Handle(SALOME_InteractiveObject) IO = aList.First();
00875     myPath = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
00876     if( myPath->_is_nil() )
00877       return;
00878     
00879     QString aString;
00880     SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00881     PathMeshLineEdit->setText(aString);
00882   }
00883   else if (myEditCurrentArgument == StartPointLineEdit) {
00884     // we are now selecting start point of path
00885     // reset
00886     StartPointLineEdit->clear();
00887 
00888     // return if path mesh or path shape is not yet selected
00889     if( myPath->_is_nil() )
00890       return;
00891 
00892     // try to get shape from selection
00893     Handle(SALOME_InteractiveObject) IO = aList.First();
00894 
00895     SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
00896     if ( !aPathActor )
00897       return;
00898     
00899     QString aString;
00900     int aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aPathActor->getIO(), aString);
00901     if (aNbUnits == 1)
00902       StartPointLineEdit->setText(aString.trimmed());
00903 
00904   } else if (myEditCurrentArgument == XSpin) {
00905     // we are now selecting base point
00906     // reset is not performed here!
00907 
00908     // return if is not enabled
00909     if (!BasePointGrp->isChecked())
00910       return;
00911 
00912     // try to get shape from selection
00913     Handle(SALOME_InteractiveObject) IO = aList.First();
00914 
00915     // check if geom vertex is selected
00916     GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
00917     TopoDS_Vertex aVertex;
00918     if (!aGeomObj->_is_nil()) {
00919       if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
00920         gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
00921         XSpin->SetValue(aPnt.X());
00922         YSpin->SetValue(aPnt.Y());
00923         ZSpin->SetValue(aPnt.Z());
00924       }
00925       return;
00926     }
00927 
00928     // check if smesh node is selected
00929     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
00930     if (aMesh->_is_nil())
00931       return;
00932 
00933     QString aString;
00934     int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myMeshActor->getIO(), aString);
00935     // return if more than one node is selected
00936     if (aNbUnits != 1)
00937       return;
00938 
00939     SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
00940     if (!aMeshActor)
00941       return;
00942 
00943     SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
00944     if (!mesh)
00945       return;
00946 
00947     const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
00948     if (!n)
00949       return;
00950 
00951     XSpin->SetValue(n->X());
00952     YSpin->SetValue(n->Y());
00953     ZSpin->SetValue(n->Z());
00954   }
00955   onDisplaySimulation(true);
00956 }
00957 
00958 //=================================================================================
00959 // function : SetEditCurrentArgument()
00960 // purpose  :
00961 //=================================================================================
00962 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
00963 {
00964   QToolButton* send = (QToolButton*)sender();
00965   if (send != SelectElementsButton   &&
00966       send != SelectPathMeshButton   &&
00967       send != SelectStartPointButton &&
00968       send != SelectBasePointButton)
00969     return;
00970   SetEditCurrentArgument(send);
00971 }
00972 
00973 //=================================================================================
00974 // function : SetEditCurrentArgument()
00975 // purpose  :
00976 //=================================================================================
00977 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument (QToolButton* button)
00978 {
00979   disconnect(mySelectionMgr, 0, this, 0);
00980   //  mySelectionMgr->clearSelected();
00981   mySelectionMgr->clearFilters();
00982   SMESH::SetPickable();
00983 
00984   if (button == SelectElementsButton) {
00985     myEditCurrentArgument = ElementsLineEdit;
00986     SMESH::SetPointRepresentation(false);
00987     if (MeshCheck->isChecked()) {
00988       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00989         aViewWindow->SetSelectionMode(ActorSelection);
00990       mySelectionMgr->installFilter(myElementsFilter);
00991     } else {
00992       if (Elements1dRB->isChecked())
00993         {
00994           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00995             aViewWindow->SetSelectionMode(EdgeSelection);
00996         }
00997       else if (Elements2dRB->isChecked())
00998         {
00999           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01000             aViewWindow->SetSelectionMode(FaceSelection);
01001         }
01002     }
01003   } else if (button == SelectPathMeshButton) {
01004     myEditCurrentArgument = PathMeshLineEdit;
01005     SMESH::SetPointRepresentation(false);
01006     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01007       aViewWindow->SetSelectionMode(ActorSelection);
01008     mySelectionMgr->installFilter(myPathMeshFilter);
01009   }
01010   else if (button == SelectStartPointButton) {
01011     myEditCurrentArgument = StartPointLineEdit;
01012     //if (!myPathMesh->_is_nil()) {
01013     if (!myPath->_is_nil()) {
01014       SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
01015       if (aPathActor) {
01016         SMESH::SetPointRepresentation(true);
01017         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01018           aViewWindow->SetSelectionMode(NodeSelection);
01019         SMESH::SetPickable(aPathActor);
01020       }
01021     }
01022   }
01023   else if (button == SelectBasePointButton) {
01024     myEditCurrentArgument = XSpin;
01025     SMESH::SetPointRepresentation(true);
01026     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01027       aViewWindow->SetSelectionMode(NodeSelection);
01028 
01029     SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(MESHorSUBMESH);
01030     SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter(GROUP);
01031     SMESH_NumberFilter* aVertexFilter      = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE,
01032                                                                      -1, TopAbs_VERTEX);
01033     QList<SUIT_SelectionFilter*> aListOfFilters;
01034     if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
01035     if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
01036     if (aVertexFilter)        aListOfFilters.append(aVertexFilter);
01037 
01038     mySelectionMgr->installFilter(new SMESH_LogicalFilter
01039                                   (aListOfFilters, SMESH_LogicalFilter::LO_OR));
01040   }
01041 
01042   if (myEditCurrentArgument && !myEditCurrentArgument->hasFocus())
01043     myEditCurrentArgument->setFocus();
01044 
01045   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
01046   SelectionIntoArgument();
01047 }
01048 
01049 //=================================================================================
01050 // function : DeactivateActiveDialog()
01051 // purpose  : Deactivates this dialog
01052 //=================================================================================
01053 void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
01054 {
01055   if (ConstructorsBox->isEnabled()) {
01056     ConstructorsBox->setEnabled(false);
01057     GroupArguments->setEnabled(false);
01058     GroupButtons->setEnabled(false);
01059     mySMESHGUI->ResetState();
01060     mySMESHGUI->SetActiveDialogBox(0);
01061   }
01062 }
01063 
01064 //=================================================================================
01065 // function : ActivateThisDialog()
01066 // purpose  : Activates this dialog
01067 //=================================================================================
01068 void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
01069 {
01070   // Emit a signal to deactivate the active dialog
01071   mySMESHGUI->EmitSignalDeactivateDialog();
01072   ConstructorsBox->setEnabled(true);
01073   GroupArguments->setEnabled(true);
01074   GroupButtons->setEnabled(true);
01075 
01076   mySMESHGUI->SetActiveDialogBox(this);
01077 
01078   ConstructorsClicked(GetConstructorId());
01079   SelectionIntoArgument();
01080 }
01081 
01082 //=================================================================================
01083 // function : enterEvent()
01084 // purpose  : Mouse enter event
01085 //=================================================================================
01086 void SMESHGUI_ExtrusionAlongPathDlg::enterEvent (QEvent*)
01087 {
01088   if (!ConstructorsBox->isEnabled())
01089     ActivateThisDialog();
01090 }
01091 
01092 //=======================================================================
01093 // function : onSelectMesh()
01094 // purpose  :
01095 //=======================================================================
01096 void SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh()
01097 {
01098   bool toSelectMesh = MeshCheck->isChecked();
01099 
01100   ElementsLineEdit->setReadOnly(toSelectMesh);
01101   ElementsLineEdit->setValidator(toSelectMesh ? 0 : myIdValidator);
01102   ElementsLab->setText(toSelectMesh ? tr("SMESH_NAME") : tr("SMESH_ID_ELEMENTS"));
01103   ElementsLineEdit->clear();
01104   myFilterBtn->setEnabled(!toSelectMesh);
01105 
01106   SetEditCurrentArgument(SelectElementsButton);
01107 }
01108 
01109 //=================================================================================
01110 // function : GetConstructorId()
01111 // purpose  :
01112 //=================================================================================
01113 int SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId()
01114 {
01115   return GroupConstructors->checkedId();
01116 }
01117 
01118 //=======================================================================
01119 // function : OnAngleAdded()
01120 // purpose  : Called when user adds angle to the list
01121 //=======================================================================
01122 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
01123 {
01124   QString msg;
01125   if( !AngleSpin->isValid( msg, true ) ) {
01126     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
01127     if ( !msg.isEmpty() )
01128       str += "\n" + msg;
01129     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
01130     return;
01131   }
01132   AnglesList->addItem(AngleSpin->text());
01133   myAnglesList.append(AngleSpin->GetValue());
01134 
01135   updateLinearAngles();
01136 }
01137 
01138 //=======================================================================
01139 // function : OnAngleRemoved()
01140 // purpose  : Called when user removes angle(s) from the list
01141 //=======================================================================
01142 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
01143 {
01144   QList<QListWidgetItem*> aList = AnglesList->selectedItems();
01145   QListWidgetItem* anItem;
01146   foreach(anItem, aList) {
01147     myAnglesList.removeAt(AnglesList->row(anItem));
01148     delete anItem;
01149   }
01150 
01151   updateLinearAngles();
01152 }
01153 
01154 //=================================================================================
01155 // function : eventFilter()
01156 // purpose  : event filter ???
01157 //=================================================================================
01158 bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter (QObject* object, QEvent* event)
01159 {
01160   if (event->type() == QEvent::KeyPress) {
01161     QKeyEvent* ke = (QKeyEvent*)event;
01162     if (object == AnglesList) {
01163       if (ke->key() == Qt::Key_Delete)
01164         OnAngleRemoved();
01165     }
01166   }
01167   else if (event->type() == QEvent::FocusIn) {
01168     if (object == ElementsLineEdit) {
01169       if (myEditCurrentArgument != ElementsLineEdit)
01170         SetEditCurrentArgument(SelectElementsButton);
01171     }
01172     else if (object == StartPointLineEdit) {
01173       if (myEditCurrentArgument != StartPointLineEdit)
01174         SetEditCurrentArgument(SelectStartPointButton);
01175     }
01176     else if (object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor()) {
01177       if (myEditCurrentArgument != XSpin)
01178         SetEditCurrentArgument(SelectBasePointButton);
01179     }
01180   }
01181   return QDialog::eventFilter(object, event);
01182 }
01183 
01184 //=================================================================================
01185 // function : keyPressEvent()
01186 // purpose  :
01187 //=================================================================================
01188 void SMESHGUI_ExtrusionAlongPathDlg::keyPressEvent( QKeyEvent* e )
01189 {
01190   QDialog::keyPressEvent( e );
01191   if ( e->isAccepted() )
01192     return;
01193 
01194   if ( e->key() == Qt::Key_F1 ) {
01195     e->accept();
01196     ClickOnHelp();
01197   }
01198 }
01199 
01200 //=================================================================================
01201 // function : setFilters()
01202 // purpose  : SLOT. Called when "Filter" button pressed.
01203 //=================================================================================
01204 void SMESHGUI_ExtrusionAlongPathDlg::setFilters()
01205 {
01206   if(myMesh->_is_nil()) {
01207     SUIT_MessageBox::critical(this,
01208                               tr("SMESH_ERROR"),
01209                               tr("NO_MESH_SELECTED"));
01210    return;
01211   }
01212   if ( !myFilterDlg )
01213   {
01214     QList<int> types;  
01215     types.append( SMESH::EDGE );
01216     types.append( SMESH::FACE );
01217     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
01218   }
01219   myFilterDlg->Init( Elements1dRB->isChecked() ? SMESH::EDGE : SMESH::FACE );
01220 
01221   myFilterDlg->SetSelection();
01222   myFilterDlg->SetMesh( myMesh );
01223   myFilterDlg->SetSourceWg( ElementsLineEdit );
01224 
01225   myFilterDlg->show();
01226 }
01227 
01228 //=================================================================================
01229 // function : isValid
01230 // purpose  :
01231 //=================================================================================
01232 bool SMESHGUI_ExtrusionAlongPathDlg::isValid()
01233 {
01234   QString msg;
01235   bool ok = true;
01236   ok = XSpin->isValid( msg, true ) && ok;
01237   ok = YSpin->isValid( msg, true ) && ok;
01238   ok = ZSpin->isValid( msg, true ) && ok;
01239 
01240   if( !ok ) {
01241     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
01242     if ( !msg.isEmpty() )
01243       str += "\n" + msg;
01244     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
01245     return false;
01246   }
01247   return true;
01248 }
01249 
01250 //=================================================================================
01251 // function : updateLinearAngles
01252 // purpose  :
01253 //=================================================================================
01254 void SMESHGUI_ExtrusionAlongPathDlg::updateLinearAngles()
01255 {
01256   bool enableLinear = true;
01257   for( int row = 0, nbRows = AnglesList->count(); row < nbRows; row++ ) {
01258     if( QListWidgetItem* anItem = AnglesList->item( row ) ) {
01259       enableLinear = false;
01260       anItem->text().toDouble(&enableLinear);
01261       if( !enableLinear )
01262         break;
01263     }
01264   }
01265   if( !enableLinear )
01266     LinearAnglesCheck->setChecked( false );
01267   LinearAnglesCheck->setEnabled( enableLinear );
01268 }
01269 
01270 //=================================================================================
01271 // function : isValuesValid()
01272 // purpose  : Return true in case if values entered into dialog are valid
01273 //=================================================================================
01274 bool SMESHGUI_ExtrusionAlongPathDlg::isValuesValid() {
01275   
01276   if ( (MeshCheck->isChecked() && myIDSource->_is_nil()) ||
01277        myMesh->_is_nil() ||
01278        myPath->_is_nil() )
01279     return false;
01280   
01281   if(!MeshCheck->isChecked()) {
01282     QStringList aListElementsId = ElementsLineEdit->text().split(" ", QString::SkipEmptyParts);
01283     if(aListElementsId.count() <= 0)
01284       return false;
01285   }
01286 
01287   bool bOk;
01288   StartPointLineEdit->text().toLong(&bOk);
01289   if (!bOk) {
01290     return false;
01291   }
01292 
01293   return true;
01294 }
01295 
01296 
01297 //=================================================================================
01298 // function : onDisplaySimulation
01299 // purpose  : Show/Hide preview
01300 //=================================================================================
01301 void SMESHGUI_ExtrusionAlongPathDlg::onDisplaySimulation( bool toDisplayPreview ) {
01302   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
01303     if(isValid() && isValuesValid()) {
01304       
01305       //Get selected elements:
01306       SMESH::long_array_var anElementsId = getSelectedElements();
01307 
01308       // get angles
01309       SMESH::double_array_var anAngles = getAngles();
01310       
01311       // get base point
01312       SMESH::PointStruct aBasePoint;
01313       if (BasePointGrp->isChecked()) {
01314         aBasePoint.x = XSpin->GetValue();
01315         aBasePoint.y = YSpin->GetValue();
01316         aBasePoint.z = ZSpin->GetValue();
01317       }
01318       bool bOk;
01319       long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
01320       if (bOk) {
01321         
01322         try {
01323           SUIT_OverrideCursor wc;
01324           
01325           SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
01326           SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
01327           bool NeedGroups = false;
01328           SMESH::ElementType ElemType = SMESH::FACE;
01329           if( GetConstructorId() == 0 )
01330             ElemType = SMESH::EDGE;
01331           if( !MeshCheck->isChecked() ) {
01332             aMeshEditor->ExtrusionAlongPathX(anElementsId, myPath, aNodeStart, AnglesGrp->isChecked(),
01333                                              anAngles, LinearAnglesCheck->isChecked(),
01334                                              BasePointGrp->isChecked(), aBasePoint,
01335                                              NeedGroups, ElemType, retVal);
01336           }
01337           else {
01338             SMESH::ListOfGroups_var groups = 
01339               aMeshEditor->ExtrusionAlongPathObjX(myIDSource, myPath, aNodeStart, AnglesGrp->isChecked(),
01340                                                   anAngles, LinearAnglesCheck->isChecked(),
01341                                                   BasePointGrp->isChecked(), aBasePoint,
01342                                                   NeedGroups, ElemType, retVal);
01343           }
01344           
01345           wc.suspend();
01346           if( retVal == SMESH::SMESH_MeshEditor::EXTR_OK ) {
01347             SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
01348             mySimulation->SetData(aMeshPreviewStruct._retn());
01349           } else {
01350             hidePreview();
01351           }
01352           
01353         } catch (...) {
01354           hidePreview();
01355         }
01356       } else {
01357         hidePreview();
01358       }
01359       
01360     } else {
01361       hidePreview();
01362     }
01363   } else {
01364     hidePreview();
01365   }
01366 }
01367 
01368 
01369 //=================================================================================
01370 // function : getSelectedElements
01371 // purpose  : return list of the selected elements
01372 //=================================================================================
01373 SMESH::long_array_var SMESHGUI_ExtrusionAlongPathDlg::getSelectedElements() {
01374 
01375   // If "Select whole mesh, submesh or group" check box is off ->
01376   // use only elements of given type selected by user
01377   SMESH::long_array_var anElementsId = new SMESH::long_array;
01378   if (!MeshCheck->isChecked()) {
01379     
01380     SMDS_Mesh* aMesh;
01381     if ( myMeshActor )
01382       aMesh = myMeshActor->GetObject()->GetMesh();
01383     
01384     if (aMesh) {
01385       QStringList aListElementsId = ElementsLineEdit->text().split(" ", QString::SkipEmptyParts);
01386       anElementsId = new SMESH::long_array;
01387       anElementsId->length(aListElementsId.count());
01388       bool bOk;
01389       int j = 0;
01390       for (int i = 0; i < aListElementsId.count(); i++) {
01391         long ind = aListElementsId[ i ].toLong(&bOk);
01392         if  (bOk) {
01393           const SMDS_MeshElement* e = aMesh->FindElement(ind);
01394           if (e) {
01395             bool typeMatch = (Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge) ||
01396                              (Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face);
01397             if (typeMatch)
01398                   anElementsId[ j++ ] = ind;
01399           }
01400         }
01401       }
01402       anElementsId->length(j);
01403     }
01404   }
01405   return anElementsId;
01406 }
01407 
01408 SMESH::double_array_var SMESHGUI_ExtrusionAlongPathDlg::getAngles() {
01409   SMESH::double_array_var anAngles = new SMESH::double_array;
01410   if (AnglesGrp->isChecked()) {
01411     anAngles->length(myAnglesList.count());
01412     int j = 0;
01413     for (int i = 0; i < myAnglesList.count(); i++) {
01414       double angle = myAnglesList[i];
01415       anAngles[ j++ ] = angle*PI/180;
01416     }
01417     anAngles->length(j);
01418   }
01419   return anAngles;
01420 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS