Back to index

salome-smesh  6.5.0
SMESHGUI_SewingDlg.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_SewingDlg.cxx
00025 // Author : Michael ZORIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_SewingDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_IdValidator.h"
00035 
00036 #include <SMESH_Actor.h>
00037 #include <SMDS_Mesh.hxx>
00038 
00039 // SALOME GUI includes
00040 #include <SUIT_Session.h>
00041 #include <SUIT_ResourceMgr.h>
00042 #include <SUIT_Desktop.h>
00043 #include <SUIT_MessageBox.h>
00044 #include <SUIT_OverrideCursor.h>
00045 
00046 #include <LightApp_Application.h>
00047 #include <LightApp_SelectionMgr.h>
00048 
00049 #include <SVTK_ViewModel.h>
00050 #include <SVTK_ViewWindow.h>
00051 #include <SALOME_ListIO.hxx>
00052 
00053 // OCCT includes
00054 #include <TColStd_MapOfInteger.hxx>
00055 
00056 // Qt includes
00057 #include <QApplication>
00058 #include <QButtonGroup>
00059 #include <QGroupBox>
00060 #include <QLabel>
00061 #include <QLineEdit>
00062 #include <QPushButton>
00063 #include <QRadioButton>
00064 #include <QCheckBox>
00065 #include <QHBoxLayout>
00066 #include <QVBoxLayout>
00067 #include <QGridLayout>
00068 #include <QKeyEvent>
00069 
00070 // IDL includes
00071 #include <SALOMEconfig.h>
00072 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00073 
00074 #define SPACING 6
00075 #define MARGIN  11
00076 
00077 //=================================================================================
00078 // class    : SMESHGUI_SewingDlg()
00079 // purpose  :
00080 //=================================================================================
00081 SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule )
00082   : QDialog( SMESH::GetDesktop( theModule ) ),
00083     mySMESHGUI( theModule ),
00084     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00085 {
00086   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
00087   QPixmap image0 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_FREEBORDERS")));
00088   QPixmap image1 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
00089   QPixmap image2 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
00090   QPixmap image3 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
00091   QPixmap image4 (mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
00092 
00093   setModal(false);
00094   setAttribute(Qt::WA_DeleteOnClose, true);
00095   setWindowTitle(tr("SMESH_SEWING"));
00096   setSizeGripEnabled(true);
00097 
00098   QVBoxLayout* SMESHGUI_SewingDlgLayout = new QVBoxLayout(this);
00099   SMESHGUI_SewingDlgLayout->setSpacing(SPACING);
00100   SMESHGUI_SewingDlgLayout->setMargin(MARGIN);
00101 
00102   /***************************************************************/
00103   ConstructorsBox = new QGroupBox(tr("SMESH_SEWING"), this);
00104   GroupConstructors = new QButtonGroup(this);
00105   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
00106   ConstructorsBoxLayout->setSpacing(SPACING);
00107   ConstructorsBoxLayout->setMargin(MARGIN);
00108 
00109   RadioButton1 = new QRadioButton(ConstructorsBox);
00110   RadioButton1->setIcon(image0);
00111   RadioButton2 = new QRadioButton(ConstructorsBox);
00112   RadioButton2->setIcon(image1);
00113   RadioButton3 = new QRadioButton(ConstructorsBox);
00114   RadioButton3->setIcon(image2);
00115   RadioButton4 = new QRadioButton(ConstructorsBox);
00116   RadioButton4->setIcon(image3);
00117 
00118   ConstructorsBoxLayout->addWidget(RadioButton1);
00119   ConstructorsBoxLayout->addWidget(RadioButton2);
00120   ConstructorsBoxLayout->addWidget(RadioButton3);
00121   ConstructorsBoxLayout->addWidget(RadioButton4);
00122   GroupConstructors->addButton(RadioButton1, 0);
00123   GroupConstructors->addButton(RadioButton2, 1);
00124   GroupConstructors->addButton(RadioButton3, 2);
00125   GroupConstructors->addButton(RadioButton4, 3);
00126 
00127   /***************************************************************/
00128   GroupArguments = new QGroupBox(this);
00129   QVBoxLayout* GroupArgumentsLayout = new QVBoxLayout(GroupArguments);
00130   GroupArgumentsLayout->setSpacing(SPACING);
00131   GroupArgumentsLayout->setMargin(MARGIN);
00132 
00133   // First subgroup
00134   SubGroup1 = new QGroupBox(GroupArguments);
00135   QGridLayout* SubGroup1Layout = new QGridLayout(SubGroup1);
00136   SubGroup1Layout->setSpacing(SPACING);
00137   SubGroup1Layout->setMargin(MARGIN);
00138 
00139   // Controls of the first subgroup
00140   TextLabel1 = new QLabel(SubGroup1);
00141   SelectButton1  = new QPushButton(SubGroup1);
00142   SelectButton1->setIcon(image4);
00143   LineEdit1 = new QLineEdit(SubGroup1);
00144 
00145   TextLabel2 = new QLabel(SubGroup1);
00146   SelectButton2  = new QPushButton(SubGroup1);
00147   SelectButton2->setIcon(image4);
00148   LineEdit2 = new QLineEdit(SubGroup1);
00149 
00150   TextLabel3 = new QLabel(SubGroup1);
00151   SelectButton3  = new QPushButton(SubGroup1);
00152   SelectButton3->setIcon(image4);
00153   LineEdit3 = new QLineEdit(SubGroup1);
00154 
00155   SubGroup1Layout->addWidget(TextLabel1,    0, 0);
00156   SubGroup1Layout->addWidget(SelectButton1, 0, 1);
00157   SubGroup1Layout->addWidget(LineEdit1,     0, 2);
00158   SubGroup1Layout->addWidget(TextLabel2,    1, 0);
00159   SubGroup1Layout->addWidget(SelectButton2, 1, 1);
00160   SubGroup1Layout->addWidget(LineEdit2,     1, 2);
00161   SubGroup1Layout->addWidget(TextLabel3,    2, 0);
00162   SubGroup1Layout->addWidget(SelectButton3, 2, 1);
00163   SubGroup1Layout->addWidget(LineEdit3,     2, 2);
00164 
00165   // Second subgroup
00166   SubGroup2 = new QGroupBox(GroupArguments);
00167   QGridLayout* SubGroup2Layout = new QGridLayout(SubGroup2);
00168   SubGroup2Layout->setSpacing(SPACING);
00169   SubGroup2Layout->setMargin(MARGIN);
00170 
00171   // Controls of the first subgroup
00172   TextLabel4 = new QLabel(SubGroup2);
00173   SelectButton4  = new QPushButton(SubGroup2);
00174   SelectButton4->setIcon(image4);
00175   LineEdit4 = new QLineEdit(SubGroup2);
00176 
00177   TextLabel5 = new QLabel(SubGroup2);
00178   SelectButton5  = new QPushButton(SubGroup2);
00179   SelectButton5->setIcon(image4);
00180   LineEdit5 = new QLineEdit(SubGroup2);
00181 
00182   TextLabel6 = new QLabel(SubGroup2);
00183   SelectButton6  = new QPushButton(SubGroup2);
00184   SelectButton6->setIcon(image4);
00185   LineEdit6 = new QLineEdit(SubGroup2);
00186 
00187   SubGroup2Layout->addWidget(TextLabel4,    0, 0);
00188   SubGroup2Layout->addWidget(SelectButton4, 0, 1);
00189   SubGroup2Layout->addWidget(LineEdit4,     0, 2);
00190   SubGroup2Layout->addWidget(TextLabel5,    1, 0);
00191   SubGroup2Layout->addWidget(SelectButton5, 1, 1);
00192   SubGroup2Layout->addWidget(LineEdit5,     1, 2);
00193   SubGroup2Layout->addWidget(TextLabel6,    2, 0);
00194   SubGroup2Layout->addWidget(SelectButton6, 2, 1);
00195   SubGroup2Layout->addWidget(LineEdit6,     2, 2);
00196 
00197   // Control for the merging equal elements
00198   CheckBoxMerge = new QCheckBox(tr("MERGE_EQUAL_ELEMENTS"), GroupArguments);
00199 
00200   // Control for the polygons creation instead of splitting
00201   CheckBoxPolygons = new QCheckBox(tr("CREATE_POLYGONS_INSTEAD_SPLITTING"), GroupArguments);
00202   
00203   // Control for the polyedres creation to obtain conform mesh
00204   CheckBoxPolyedrs = new QCheckBox(tr("CREATE_POLYEDRS_NEAR_BOUNDARY"), GroupArguments);
00205 
00206   // layout
00207   GroupArgumentsLayout->addWidget(SubGroup1);
00208   GroupArgumentsLayout->addWidget(SubGroup2);
00209   GroupArgumentsLayout->addWidget(CheckBoxMerge);
00210   GroupArgumentsLayout->addWidget(CheckBoxPolygons);
00211   GroupArgumentsLayout->addWidget(CheckBoxPolyedrs);
00212 
00213   /***************************************************************/
00214   GroupButtons = new QGroupBox(this);
00215   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00216   GroupButtonsLayout->setSpacing(SPACING);
00217   GroupButtonsLayout->setMargin(MARGIN);
00218 
00219   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00220   buttonOk->setAutoDefault(true);
00221   buttonOk->setDefault(true);
00222   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00223   buttonApply->setAutoDefault(true);
00224   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00225   buttonCancel->setAutoDefault(true);
00226   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00227   buttonHelp->setAutoDefault(true);
00228 
00229   GroupButtonsLayout->addWidget(buttonOk);
00230   GroupButtonsLayout->addSpacing(10);
00231   GroupButtonsLayout->addWidget(buttonApply);
00232   GroupButtonsLayout->addSpacing(10);
00233   GroupButtonsLayout->addStretch();
00234   GroupButtonsLayout->addWidget(buttonCancel);
00235   GroupButtonsLayout->addWidget(buttonHelp);
00236 
00237   /***************************************************************/
00238   SMESHGUI_SewingDlgLayout->addWidget(ConstructorsBox);
00239   SMESHGUI_SewingDlgLayout->addWidget(GroupArguments);
00240   SMESHGUI_SewingDlgLayout->addWidget(GroupButtons);
00241 
00242   /* Initialisations */
00243   RadioButton1->setChecked(true);
00244 
00245   LineEdit2->setValidator(new SMESHGUI_IdValidator(this, 1));
00246   LineEdit3->setValidator(new SMESHGUI_IdValidator(this, 1));
00247   LineEdit5->setValidator(new SMESHGUI_IdValidator(this, 1));
00248   LineEdit6->setValidator(new SMESHGUI_IdValidator(this, 1));
00249 
00250   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00251 
00252   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00253 
00254   myHelpFileName = "sewing_meshes_page.html";
00255 
00256   Init();
00257 
00258   /* signals and slots connections */
00259   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00260   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00261   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00262   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00263   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
00264 
00265   connect(SelectButton1, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00266   connect(SelectButton2, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00267   connect(SelectButton3, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00268   connect(SelectButton4, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00269   connect(SelectButton5, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00270   connect(SelectButton6, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
00271 
00272   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00273   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00274   /* to close dialog if study change */
00275   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00276 
00277   connect(LineEdit1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00278   connect(LineEdit2, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00279   connect(LineEdit3, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00280   connect(LineEdit4, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00281   connect(LineEdit5, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00282   connect(LineEdit6, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00283 
00284   ConstructorsClicked(0);
00285 }
00286 
00287 //=================================================================================
00288 // function : ~SMESHGUI_SewingDlg()
00289 // purpose  : Destroys the object and frees any allocated resources
00290 //=================================================================================
00291 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
00292 {
00293 }
00294 
00295 //=================================================================================
00296 // function : Init()
00297 // purpose  :
00298 //=================================================================================
00299 void SMESHGUI_SewingDlg::Init()
00300 {
00301   myBusy = false;
00302 
00303   myEditCurrentArgument = LineEdit1;
00304   LineEdit1->setFocus();
00305   myActor = 0;
00306   myMesh = SMESH::SMESH_Mesh::_nil();
00307   CheckBoxMerge->setChecked(false);
00308   CheckBoxPolygons->setChecked(false);
00309   CheckBoxPolyedrs->setChecked(false);
00310   SelectionIntoArgument();
00311 }
00312 
00313 //=================================================================================
00314 // function : ConstructorsClicked()
00315 // purpose  : Radio button management
00316 //=================================================================================
00317 void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
00318 {
00319   disconnect(mySelectionMgr, 0, this, 0);
00320   SALOME_ListIO io;
00321   mySelectionMgr->selectedObjects( io );
00322   mySelectionMgr->clearSelected();
00323   LineEdit1->setText("");
00324   LineEdit2->setText("");
00325   LineEdit3->setText("");
00326   LineEdit4->setText("");
00327   LineEdit5->setText("");
00328   LineEdit6->setText("");
00329   myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
00330   myEditCurrentArgument = LineEdit1;
00331   myEditCurrentArgument->setFocus();
00332 
00333   if (!TextLabel5->isEnabled()) {
00334     TextLabel5->setEnabled(true);
00335     SelectButton5->setEnabled(true);
00336     LineEdit5->setEnabled(true);
00337   } else if (!TextLabel6->isEnabled()) {
00338     TextLabel6->setEnabled(true);
00339     SelectButton6->setEnabled(true);
00340     LineEdit6->setEnabled(true);
00341   }
00342 
00343   if (constructorId == 1 || constructorId == 3) {
00344     if (CheckBoxPolygons->isVisible())
00345       CheckBoxPolygons->hide();
00346     if (CheckBoxPolyedrs->isVisible())
00347       CheckBoxPolyedrs->hide();
00348   }
00349 
00350   switch (constructorId) {
00351   case 0:
00352     {
00353       GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
00354       SubGroup1->setTitle(tr("BORDER_1"));
00355       SubGroup2->setTitle(tr("BORDER_2"));
00356 
00357         if (!CheckBoxPolygons->isVisible())
00358           CheckBoxPolygons->show();
00359         if (!CheckBoxPolyedrs->isVisible())
00360           CheckBoxPolyedrs->show();
00361 
00362       break;
00363     }
00364   case 1:
00365     {
00366       GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
00367       SubGroup1->setTitle(tr("BORDER_1"));
00368       SubGroup2->setTitle(tr("BORDER_2"));
00369 
00370       TextLabel6->setEnabled(false);
00371       SelectButton6->setEnabled(false);
00372       LineEdit6->setEnabled(false);
00373 
00374       myOk6 = true;
00375 
00376       break;
00377     }
00378   case 2:
00379     {
00380       GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
00381       SubGroup1->setTitle(tr("BORDER"));
00382       SubGroup2->setTitle(tr("SIDE"));
00383 
00384       TextLabel5->setEnabled(false);
00385       SelectButton5->setEnabled(false);
00386       LineEdit5->setEnabled(false);
00387 
00388       if (!CheckBoxPolygons->isVisible())
00389         CheckBoxPolygons->show();
00390       if (!CheckBoxPolyedrs->isVisible())
00391         CheckBoxPolyedrs->show();
00392       
00393       myOk5 = true;
00394 
00395       break;
00396     }
00397   case 3:
00398     {
00399       GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
00400       SubGroup1->setTitle(tr("SIDE_1"));
00401       SubGroup2->setTitle(tr("SIDE_2"));
00402 
00403       TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
00404       TextLabel2->setText(tr("NODE1_TO_MERGE"));
00405       TextLabel3->setText(tr("NODE2_TO_MERGE"));
00406       TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
00407       TextLabel5->setText(tr("NODE1_TO_MERGE"));
00408       TextLabel6->setText(tr("NODE2_TO_MERGE"));
00409 
00410       LineEdit1->setValidator(new SMESHGUI_IdValidator(this));
00411       LineEdit4->setValidator(new SMESHGUI_IdValidator(this));
00412 
00413       SMESH::SetPointRepresentation(false);
00414 
00415       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00416         aViewWindow->SetSelectionMode(CellSelection);
00417       break;
00418     }
00419   }
00420 
00421   if (constructorId != 3) {
00422     TextLabel1->setText(tr("FIRST_NODE_ID"));
00423     TextLabel2->setText(tr("SECOND_NODE_ID"));
00424     TextLabel3->setText(tr("LAST_NODE_ID"));
00425     TextLabel4->setText(tr("FIRST_NODE_ID"));
00426     TextLabel5->setText(tr("SECOND_NODE_ID"));
00427     TextLabel6->setText(tr("LAST_NODE_ID"));
00428 
00429     LineEdit1->setValidator(new SMESHGUI_IdValidator(this, 1));
00430     LineEdit4->setValidator(new SMESHGUI_IdValidator(this, 1));
00431 
00432     SMESH::SetPointRepresentation(true);
00433 
00434     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00435       aViewWindow->SetSelectionMode(NodeSelection);
00436   }
00437 
00438   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00439   mySelectionMgr->setSelectedObjects( io );
00440 
00441   QApplication::instance()->processEvents();
00442   updateGeometry();
00443   resize(100,100);
00444 }
00445 
00446 //=================================================================================
00447 // function : ClickOnApply()
00448 // purpose  :
00449 //=================================================================================
00450 bool SMESHGUI_SewingDlg::ClickOnApply()
00451 {
00452   if (mySMESHGUI->isActiveStudyLocked())
00453     return false;
00454 
00455   bool aResult = false;
00456 
00457   if (IsValid()) {
00458     bool toMerge = CheckBoxMerge->isChecked();
00459     bool toCreatePolygons = CheckBoxPolygons->isChecked();
00460     bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
00461 
00462     try {
00463       SUIT_OverrideCursor aWaitCursor;
00464       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00465 
00466       int aConstructorId = GetConstructorId();
00467       SMESH::SMESH_MeshEditor::Sew_Error anError;
00468 
00469       if (aConstructorId == 0)
00470         anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
00471                                               LineEdit2->text().toLong(),
00472                                               LineEdit3->text().toLong(),
00473                                               LineEdit4->text().toLong(),
00474                                               LineEdit5->text().toLong(),
00475                                               LineEdit6->text().toLong(),
00476                                               toCreatePolygons,
00477                                               toCreatePolyedrs);
00478       else if (aConstructorId == 1)
00479         anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
00480                                                      LineEdit2->text().toLong(),
00481                                                      LineEdit3->text().toLong(),
00482                                                      LineEdit4->text().toLong(),
00483                                                      LineEdit5->text().toLong());
00484       else if (aConstructorId == 2)
00485         anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
00486                                                LineEdit2->text().toLong(),
00487                                                LineEdit3->text().toLong(),
00488                                                LineEdit4->text().toLong(),
00489                                                LineEdit6->text().toLong(),
00490                                                toCreatePolygons,
00491                                                toCreatePolyedrs);
00492       else if (aConstructorId == 3) {
00493         QStringList aListElementsId1 = LineEdit1->text().split(" ", QString::SkipEmptyParts);
00494         QStringList aListElementsId2 = LineEdit4->text().split(" ", QString::SkipEmptyParts);
00495 
00496         SMESH::long_array_var anElementsId1 = new SMESH::long_array;
00497         SMESH::long_array_var anElementsId2 = new SMESH::long_array;
00498 
00499         anElementsId1->length(aListElementsId1.count());
00500         anElementsId2->length(aListElementsId2.count());
00501 
00502         for (int i = 0; i < aListElementsId1.count(); i++)
00503           anElementsId1[i] = aListElementsId1[i].toInt();
00504         for (int i = 0; i < aListElementsId2.count(); i++)
00505           anElementsId2[i] = aListElementsId2[i].toInt();
00506 
00507         anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
00508                                                anElementsId2.inout(),
00509                                                LineEdit2->text().toLong(),
00510                                                LineEdit5->text().toLong(),
00511                                                LineEdit3->text().toLong(),
00512                                                LineEdit6->text().toLong());
00513       }
00514       aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
00515 
00516       if (toMerge && aResult)
00517         aMeshEditor->MergeEqualElements();
00518 
00519       if (!aResult) {
00520         QString msg = tr(QString("ERROR_%1").arg(anError).toLatin1().data());
00521         SUIT_MessageBox::warning(this, tr("SMESH_WRN_WARNING"), msg);
00522       }
00523     } catch (...) {
00524     }
00525 
00526     if (aResult) {
00527       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
00528 
00529       SALOME_ListIO aList;
00530       aList.Append(anIO);
00531       mySelectionMgr->setSelectedObjects(aList, false);
00532       SMESH::UpdateView();
00533 
00534       Init();
00535       ConstructorsClicked(GetConstructorId());
00536 
00537       SMESHGUI::Modified();
00538     }
00539   }
00540 
00541   return aResult;
00542 }
00543 
00544 //=================================================================================
00545 // function : ClickOnOk()
00546 // purpose  :
00547 //=================================================================================
00548 void SMESHGUI_SewingDlg::ClickOnOk()
00549 {
00550   if (ClickOnApply())
00551     ClickOnCancel();
00552 }
00553 
00554 //=================================================================================
00555 // function : ClickOnCancel()
00556 // purpose  :
00557 //=================================================================================
00558 void SMESHGUI_SewingDlg::ClickOnCancel()
00559 {
00560   //mySelectionMgr->clearSelected();
00561   SMESH::SetPointRepresentation(false);
00562   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00563     aViewWindow->SetSelectionMode(ActorSelection);
00564   disconnect(mySelectionMgr, 0, this, 0);
00565   mySMESHGUI->ResetState();
00566   reject();
00567 }
00568 
00569 //=================================================================================
00570 // function : ClickOnHelp()
00571 // purpose  :
00572 //=================================================================================
00573 void SMESHGUI_SewingDlg::ClickOnHelp()
00574 {
00575   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00576   if (app) 
00577     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00578   else {
00579     QString platform;
00580 #ifdef WIN32
00581     platform = "winapplication";
00582 #else
00583     platform = "application";
00584 #endif
00585     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00586                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00587                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00588                                                                  platform)).
00589                              arg(myHelpFileName));
00590   }
00591 }
00592 
00593 //=======================================================================
00594 //function : onTextChange
00595 //purpose  :
00596 //=======================================================================
00597 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
00598 {
00599   QLineEdit* send = (QLineEdit*)sender();
00600 
00601   if (myBusy) return;
00602   myBusy = true;
00603 
00604   if (send)
00605     myEditCurrentArgument = send;
00606 
00607   if      (send == LineEdit1)
00608     myOk1 = false;
00609   else if (send == LineEdit2)
00610     myOk2 = false;
00611   else if (send == LineEdit3)
00612     myOk3 = false;
00613   else if (send == LineEdit4)
00614     myOk4 = false;
00615   else if (send == LineEdit5)
00616     myOk5 = false;
00617   else if (send == LineEdit6)
00618     myOk6 = false;
00619 
00620   buttonOk->setEnabled(false);
00621   buttonApply->setEnabled(false);
00622 
00623   // hilight entered elements/nodes
00624   SMDS_Mesh* aMesh = 0;
00625 
00626   if (myActor)
00627     aMesh = myActor->GetObject()->GetMesh();
00628   else
00629     send->clear();
00630 
00631   if (aMesh) {
00632     TColStd_MapOfInteger newIndices;
00633     
00634     if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
00635       SMESH::SetPointRepresentation(true);
00636 
00637       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00638         aViewWindow->SetSelectionMode(NodeSelection);
00639 
00640       const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
00641       if (n) {
00642         newIndices.Add(n->GetID());
00643         mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
00644         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00645           aViewWindow->highlight( myActor->getIO(), true, true );
00646         
00647         if      (send == LineEdit1)
00648           myOk1 = true;
00649         else if (send == LineEdit2)
00650           myOk2 = true;
00651         else if (send == LineEdit3)
00652           myOk3 = true;
00653         else if (send == LineEdit4)
00654           myOk4 = true;
00655         else if (send == LineEdit5)
00656           myOk5 = true;
00657         else if (send == LineEdit6)
00658           myOk6 = true;
00659       }
00660     } else {
00661       SMESH::SetPointRepresentation(false);
00662 
00663       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00664         aViewWindow->SetSelectionMode(CellSelection);
00665 
00666       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00667 
00668       bool isEvenOneExists = false;
00669 
00670       for (int i = 0; i < aListId.count(); i++) {
00671         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
00672         if (e) 
00673           newIndices.Add(e->GetID());
00674         
00675           if (!isEvenOneExists)
00676             isEvenOneExists = true;
00677       }
00678       
00679 
00680       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
00681       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00682         aViewWindow->highlight( myActor->getIO(), true, true );
00683       
00684       if (isEvenOneExists) {
00685         if (send == LineEdit1)
00686           myOk1 = true;
00687         else if(send == LineEdit4)
00688           myOk4 = true;
00689       } else {
00690         send->clear();
00691       }
00692     }
00693   }
00694 
00695   if (IsValid()) {
00696     buttonOk->setEnabled(true);
00697     buttonApply->setEnabled(true);
00698   }
00699 
00700   myBusy = false;
00701 }
00702 
00703 //=================================================================================
00704 // function : SelectionIntoArgument()
00705 // purpose  : Called when selection as changed or other case
00706 //=================================================================================
00707 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
00708 {
00709   if (myBusy) return;
00710 
00711   // clear
00712   if (isSelectionChanged)
00713     myActor = 0;
00714 
00715   QString aString = "";
00716 
00717   myBusy = true;
00718   myEditCurrentArgument->setText(aString);
00719   myBusy = false;
00720 
00721   if (!GroupButtons->isEnabled()) // inactive
00722     return;
00723 
00724   buttonOk->setEnabled(false);
00725   buttonApply->setEnabled(false);
00726 
00727   // get selected mesh
00728   SALOME_ListIO aList;
00729   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00730 
00731   int nbSel = aList.Extent();
00732   if (nbSel != 1)
00733     return;
00734 
00735   Handle(SALOME_InteractiveObject) IO = aList.First();
00736   myMesh = SMESH::GetMeshByIO(IO); //@ SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
00737   myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
00738 
00739   if (myMesh->_is_nil() || !myActor)
00740     return;
00741 
00742   // get selected elements/nodes
00743   int aNbUnits = 0;
00744 
00745   if (GetConstructorId() != 3 ||
00746       (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
00747     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
00748     if (aNbUnits != 1)
00749       return;
00750   } else {
00751     aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
00752     if (aNbUnits < 1)
00753       return;
00754   }
00755 
00756   myBusy = true;
00757   myEditCurrentArgument->setText(aString);
00758   myBusy = false;
00759 
00760   // OK
00761   if (myEditCurrentArgument == LineEdit1)
00762     myOk1 = true;
00763   else if (myEditCurrentArgument == LineEdit2)
00764     myOk2 = true;
00765   else if (myEditCurrentArgument == LineEdit3)
00766     myOk3 = true;
00767   else if (myEditCurrentArgument == LineEdit4)
00768     myOk4 = true;
00769   else if (myEditCurrentArgument == LineEdit5)
00770     myOk5 = true;
00771   else if (myEditCurrentArgument == LineEdit6)
00772     myOk6 = true;
00773 
00774   if (IsValid()) {
00775     buttonOk->setEnabled(true);
00776     buttonApply->setEnabled(true);
00777   }
00778 }
00779 
00780 //=================================================================================
00781 // function : SetEditCurrentArgument()
00782 // purpose  :
00783 //=================================================================================
00784 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
00785 {
00786   QPushButton* send = (QPushButton*)sender();
00787 
00788   disconnect(mySelectionMgr, 0, this, 0);
00789   mySelectionMgr->clearSelected();
00790 
00791   if (send == SelectButton1) {
00792     myEditCurrentArgument = LineEdit1;
00793     myOk1 = false;
00794   }
00795   else if (send == SelectButton2) {
00796     myEditCurrentArgument = LineEdit2;
00797     myOk2 = false;
00798   }
00799   else if (send == SelectButton3) {
00800     myEditCurrentArgument = LineEdit3;
00801     myOk3 = false;
00802   }
00803   else if (send == SelectButton4) {
00804     myEditCurrentArgument = LineEdit4;
00805     myOk4 = false;
00806   }
00807   else if (send == SelectButton5) {
00808     myEditCurrentArgument = LineEdit5;
00809     myOk5 = false;
00810   }
00811   else if (send == SelectButton6) {
00812     myEditCurrentArgument = LineEdit6;
00813     myOk6 = false;
00814   }
00815 
00816   if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
00817     SMESH::SetPointRepresentation(true);
00818 
00819     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00820       aViewWindow->SetSelectionMode(NodeSelection);
00821 
00822   } else {
00823     SMESH::SetPointRepresentation(false);
00824     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00825       aViewWindow->SetSelectionMode(CellSelection);
00826   }
00827 
00828   myEditCurrentArgument->setFocus();
00829   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00830   SelectionIntoArgument(false);
00831 }
00832 
00833 //=================================================================================
00834 // function : DeactivateActiveDialog()
00835 // purpose  :
00836 //=================================================================================
00837 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
00838 {
00839   if (ConstructorsBox->isEnabled()) {
00840     ConstructorsBox->setEnabled(false);
00841     GroupArguments->setEnabled(false);
00842     GroupButtons->setEnabled(false);
00843     mySMESHGUI->ResetState();
00844     mySMESHGUI->SetActiveDialogBox(0);
00845   }
00846 }
00847 
00848 //=================================================================================
00849 // function : ActivateThisDialog()
00850 // purpose  :
00851 //=================================================================================
00852 void SMESHGUI_SewingDlg::ActivateThisDialog()
00853 {
00854   /* Emit a signal to deactivate the active dialog */
00855   mySMESHGUI->EmitSignalDeactivateDialog();
00856   ConstructorsBox->setEnabled(true);
00857   GroupArguments->setEnabled(true);
00858   GroupButtons->setEnabled(true);
00859 
00860   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00861 
00862   ConstructorsClicked(GetConstructorId());
00863   SelectionIntoArgument();
00864 }
00865 
00866 //=================================================================================
00867 // function : enterEvent()
00868 // purpose  :
00869 //=================================================================================
00870 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
00871 {
00872   if (!ConstructorsBox->isEnabled())
00873     ActivateThisDialog();
00874 }
00875 
00876 //=================================================================================
00877 // function : closeEvent()
00878 // purpose  :
00879 //=================================================================================
00880 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
00881 {
00882   /* same than click on cancel button */
00883   ClickOnCancel();
00884 }
00885 
00886 //=======================================================================
00887 //function : hideEvent
00888 //purpose  : caused by ESC key
00889 //=======================================================================
00890 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
00891 {
00892   if (!isMinimized())
00893     ClickOnCancel();
00894 }
00895 
00896 //=================================================================================
00897 // function : GetConstructorId()
00898 // purpose  :
00899 //=================================================================================
00900 int SMESHGUI_SewingDlg::GetConstructorId()
00901 {
00902   return GroupConstructors->checkedId();
00903 }
00904 
00905 //=================================================================================
00906 // function : GetConstructorId()
00907 // purpose  :
00908 //=================================================================================
00909 bool SMESHGUI_SewingDlg::IsValid()
00910 {
00911   return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);
00912 }
00913 
00914 //=================================================================================
00915 // function : keyPressEvent()
00916 // purpose  :
00917 //=================================================================================
00918 void SMESHGUI_SewingDlg::keyPressEvent( QKeyEvent* e )
00919 {
00920   QDialog::keyPressEvent( e );
00921   if ( e->isAccepted() )
00922     return;
00923 
00924   if ( e->key() == Qt::Key_F1 ) {
00925     e->accept();
00926     ClickOnHelp();
00927   }
00928 }