Back to index

salome-geom  6.5.0
BlocksGUI_BlockDlg.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 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : BlocksGUI_BlockDlg.cxx
00025 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
00026 //
00027 #include "BlocksGUI_BlockDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_Session.h>
00034 #include <SUIT_ResourceMgr.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 
00038 #include <GEOMImpl_Types.hxx>
00039 
00040 // OCCT Includes
00041 #include <TColStd_IndexedMapOfInteger.hxx>
00042 
00043 //=================================================================================
00044 // class    : BlocksGUI_BlockDlg()
00045 // purpose  : Constructs a BlocksGUI_BlockDlg which is a child of 'parent'.
00046 //=================================================================================
00047 BlocksGUI_BlockDlg::BlocksGUI_BlockDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
00048   : GEOMBase_Skeleton(theGeometryGUI, parent),
00049     myInitial(true)
00050 {
00051   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_2F")));
00052   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_6F")));
00053   QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00054 
00055   setWindowTitle(tr("GEOM_BLOCK_TITLE"));
00056 
00057   /***************************************************************/
00058   mainFrame()->GroupConstructors->setTitle(tr("GEOM_BLOCK"));
00059 
00060   mainFrame()->RadioButton1->setIcon(image0);
00061   mainFrame()->RadioButton2->setIcon(image1);
00062   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00063   mainFrame()->RadioButton3->close();
00064 
00065   // Create first group
00066   Group2F = new DlgRef_2Sel (centralWidget());
00067   Group2F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00068   Group2F->TextLabel1->setText(tr("FACE_1"));
00069   Group2F->TextLabel2->setText(tr("FACE_2"));
00070   Group2F->PushButton1->setIcon(imageS);
00071   Group2F->PushButton2->setIcon(imageS);
00072 
00073   // Create second group
00074   Group6F = new DlgRef_6Sel (centralWidget());
00075   Group6F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00076   Group6F->TextLabel1->setText(tr("FACE_1"));
00077   Group6F->TextLabel2->setText(tr("FACE_2"));
00078   Group6F->TextLabel3->setText(tr("FACE_3"));
00079   Group6F->TextLabel4->setText(tr("FACE_4"));
00080   Group6F->TextLabel5->setText(tr("FACE_5"));
00081   Group6F->TextLabel6->setText(tr("FACE_6"));
00082   Group6F->PushButton1->setIcon(imageS);
00083   Group6F->PushButton2->setIcon(imageS);
00084   Group6F->PushButton3->setIcon(imageS);
00085   Group6F->PushButton4->setIcon(imageS);
00086   Group6F->PushButton5->setIcon(imageS);
00087   Group6F->PushButton6->setIcon(imageS);
00088 
00089   // Add groups to layout
00090   QVBoxLayout* layout = new QVBoxLayout (centralWidget());
00091   layout->setMargin(0);
00092   layout->setSpacing(6);
00093   layout->addWidget(Group2F);
00094   layout->addWidget(Group6F);
00095   /***************************************************************/
00096 
00097   setHelpFileName("build_by_blocks_page.html#hexa_solid_anchor");
00098 
00099   Init();
00100 }
00101 
00102 //=================================================================================
00103 // function : ~BlocksGUI_BlockDlg()
00104 // purpose  : Destroys the object and frees any allocated resources
00105 //=================================================================================
00106 BlocksGUI_BlockDlg::~BlocksGUI_BlockDlg()
00107 {
00108   // no need to delete child widgets, Qt does it all for us
00109 }
00110 
00111 //=================================================================================
00112 // function : Init()
00113 // purpose  :
00114 //=================================================================================
00115 void BlocksGUI_BlockDlg::Init()
00116 {
00117   // init variables
00118   Group2F->LineEdit1->setReadOnly(true);
00119   Group2F->LineEdit2->setReadOnly(true);
00120 
00121   Group6F->LineEdit1->setReadOnly(true);
00122   Group6F->LineEdit2->setReadOnly(true);
00123   Group6F->LineEdit3->setReadOnly(true);
00124   Group6F->LineEdit4->setReadOnly(true);
00125   Group6F->LineEdit5->setReadOnly(true);
00126   Group6F->LineEdit6->setReadOnly(true);
00127 
00128   // signals and slots connections
00129   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00130   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00131 
00132   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00133 
00134   connect(Group2F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00135   connect(Group2F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00136 
00137   connect(Group6F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00138   connect(Group6F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00139   connect(Group6F->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00140   connect(Group6F->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00141   connect(Group6F->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00142   connect(Group6F->PushButton6, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00143 
00144   // init controls and fields
00145   initName(tr("GEOM_BLOCK"));
00146 
00147   myConstructorId = -1;
00148   ConstructorsClicked(0);
00149 }
00150 
00151 //=================================================================================
00152 // function : ConstructorsClicked()
00153 // purpose  : Radio button management
00154 //=================================================================================
00155 void BlocksGUI_BlockDlg::ConstructorsClicked (int constructorId)
00156 {
00157   if (myConstructorId == constructorId)
00158     return;
00159 
00160   myConstructorId = constructorId;
00161 
00162   // init fields
00163   myFace1.nullify();
00164   myFace2.nullify();
00165   myFace3.nullify();
00166   myFace4.nullify();
00167   myFace5.nullify();
00168   myFace6.nullify();
00169 
00170   switch (constructorId) {
00171   case 0:
00172     Group6F->hide();
00173     Group2F->show();
00174 
00175     Group2F->LineEdit1->setText(tr(""));
00176     Group2F->LineEdit2->setText(tr(""));
00177 
00178     Group2F->PushButton1->click();
00179     break;
00180   case 1:
00181     Group2F->hide();
00182     Group6F->show();
00183 
00184     Group6F->LineEdit1->setText(tr(""));
00185     Group6F->LineEdit2->setText(tr(""));
00186     Group6F->LineEdit3->setText(tr(""));
00187     Group6F->LineEdit4->setText(tr(""));
00188     Group6F->LineEdit5->setText(tr(""));
00189     Group6F->LineEdit6->setText(tr(""));
00190 
00191     Group6F->PushButton1->click();
00192     break;
00193   default:
00194     break;
00195   }
00196 
00197   qApp->processEvents();
00198   updateGeometry();
00199   resize(minimumSizeHint());
00200 
00201   // on dialog initialization we init the first field with a selected object (if any)
00202   SelectionIntoArgument();
00203 }
00204 
00205 //=================================================================================
00206 // function : ClickOnOk()
00207 // purpose  :
00208 //=================================================================================
00209 void BlocksGUI_BlockDlg::ClickOnOk()
00210 {
00211   setIsApplyAndClose( true );
00212   if (ClickOnApply())
00213     ClickOnCancel();
00214 }
00215 
00216 //=================================================================================
00217 // function : ClickOnApply()
00218 // purpose  :
00219 //=================================================================================
00220 bool BlocksGUI_BlockDlg::ClickOnApply()
00221 {
00222   if (!onAccept())
00223     return false;
00224 
00225   initName();
00226   return true;
00227 }
00228 
00229 //=================================================================================
00230 // function : SelectionIntoArgument()
00231 // purpose  : Called when selection is changed or on dialog initialization or activation
00232 //=================================================================================
00233 void BlocksGUI_BlockDlg::SelectionIntoArgument()
00234 {
00235   erasePreview();
00236 
00237   GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_FACE );
00238   TopoDS_Shape aShape;
00239   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00240     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00241     myEditCurrentArgument->setText( aName );
00242     if ( myEditCurrentArgument == Group2F->LineEdit1 ) {
00243       myFace1 = aSelectedObject;
00244       if (!myFace2) Group2F->PushButton2->click();
00245     }
00246     else if ( myEditCurrentArgument == Group2F->LineEdit2 ) {
00247       myFace2 = aSelectedObject;
00248       if (!myFace1) Group2F->PushButton1->click();
00249     }
00250     else if ( myEditCurrentArgument == Group6F->LineEdit1 ) {
00251       myFace1 = aSelectedObject;
00252       if      (!myFace2) Group6F->PushButton2->click();
00253       else if (!myFace3) Group6F->PushButton3->click();
00254       else if (!myFace4) Group6F->PushButton4->click();
00255       else if (!myFace5) Group6F->PushButton5->click();
00256       else if (!myFace6) Group6F->PushButton6->click();
00257     }
00258     else if ( myEditCurrentArgument == Group6F->LineEdit2 ) {
00259       myFace2 = aSelectedObject;
00260       if      (!myFace3) Group6F->PushButton3->click();
00261       else if (!myFace4) Group6F->PushButton4->click();
00262       else if (!myFace5) Group6F->PushButton5->click();
00263       else if (!myFace6) Group6F->PushButton6->click();
00264       else if (!myFace1) Group6F->PushButton1->click();
00265     }
00266     else if ( myEditCurrentArgument == Group6F->LineEdit3 ) {
00267       myFace3 = aSelectedObject;
00268       if      (!myFace4) Group6F->PushButton4->click();
00269       else if (!myFace5) Group6F->PushButton5->click();
00270       else if (!myFace6) Group6F->PushButton6->click();
00271       else if (!myFace1) Group6F->PushButton1->click();
00272       else if (!myFace2) Group6F->PushButton2->click();
00273     }
00274     else if ( myEditCurrentArgument == Group6F->LineEdit4 ) {
00275       myFace4 = aSelectedObject;
00276       if      (!myFace5) Group6F->PushButton5->click();
00277       else if (!myFace6) Group6F->PushButton6->click();
00278       else if (!myFace1) Group6F->PushButton1->click();
00279       else if (!myFace2) Group6F->PushButton2->click();
00280       else if (!myFace3) Group6F->PushButton3->click();
00281     }
00282     else if ( myEditCurrentArgument == Group6F->LineEdit5 ) {
00283       myFace5 = aSelectedObject;
00284       if      (!myFace6) Group6F->PushButton6->click();
00285       else if (!myFace1) Group6F->PushButton1->click();
00286       else if (!myFace2) Group6F->PushButton2->click();
00287       else if (!myFace3) Group6F->PushButton3->click();
00288       else if (!myFace4) Group6F->PushButton4->click();
00289     }
00290     else if ( myEditCurrentArgument == Group6F->LineEdit6 ) {
00291       myFace6 = aSelectedObject;
00292       if      (!myFace1) Group6F->PushButton1->click();
00293       else if (!myFace2) Group6F->PushButton2->click();
00294       else if (!myFace3) Group6F->PushButton3->click();
00295       else if (!myFace4) Group6F->PushButton4->click();
00296       else if (!myFace5) Group6F->PushButton5->click();
00297     }
00298   }
00299   else {
00300     if      (myEditCurrentArgument == Group2F->LineEdit1) myFace1.nullify();
00301     else if (myEditCurrentArgument == Group2F->LineEdit2) myFace2.nullify();
00302     else if (myEditCurrentArgument == Group6F->LineEdit1) myFace1.nullify();
00303     else if (myEditCurrentArgument == Group6F->LineEdit2) myFace2.nullify();
00304     else if (myEditCurrentArgument == Group6F->LineEdit3) myFace3.nullify();
00305     else if (myEditCurrentArgument == Group6F->LineEdit4) myFace4.nullify();
00306     else if (myEditCurrentArgument == Group6F->LineEdit5) myFace5.nullify();
00307     else if (myEditCurrentArgument == Group6F->LineEdit6) myFace6.nullify();
00308     myEditCurrentArgument->setText( "" );
00309   }
00310 
00311   displayPreview(true);
00312 }
00313 
00314 //=================================================================================
00315 // function : SetEditCurrentArgument()
00316 // purpose  :
00317 //=================================================================================
00318 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
00319 {
00320   QPushButton* aSender = (QPushButton*)sender();
00321 
00322   // clear selection
00323   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00324   if (myInitial)
00325     myInitial = false;
00326   else
00327     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00328 
00329   // disable all
00330   switch (myConstructorId) {
00331   case 0:
00332     Group2F->PushButton1->setDown(false);
00333     Group2F->PushButton2->setDown(false);
00334 
00335     Group2F->LineEdit1->setEnabled(false);
00336     Group2F->LineEdit2->setEnabled(false);
00337     break;
00338   case 1:
00339     Group6F->PushButton1->setDown(false);
00340     Group6F->PushButton2->setDown(false);
00341     Group6F->PushButton3->setDown(false);
00342     Group6F->PushButton4->setDown(false);
00343     Group6F->PushButton5->setDown(false);
00344     Group6F->PushButton6->setDown(false);
00345 
00346     Group6F->LineEdit1->setEnabled(false);
00347     Group6F->LineEdit2->setEnabled(false);
00348     Group6F->LineEdit3->setEnabled(false);
00349     Group6F->LineEdit4->setEnabled(false);
00350     Group6F->LineEdit5->setEnabled(false);
00351     Group6F->LineEdit6->setEnabled(false);
00352     break;
00353   default:
00354     break;
00355   }
00356 
00357   // set line edit as current argument
00358   if (aSender == Group2F->PushButton1) {
00359     myEditCurrentArgument = Group2F->LineEdit1;
00360   }
00361   else if (aSender == Group2F->PushButton2) {
00362     myEditCurrentArgument = Group2F->LineEdit2;
00363   }
00364   else if (aSender == Group6F->PushButton1) {
00365     myEditCurrentArgument = Group6F->LineEdit1;
00366   }
00367   else if (aSender == Group6F->PushButton2) {
00368     myEditCurrentArgument = Group6F->LineEdit2;
00369   }
00370   else if (aSender == Group6F->PushButton3) {
00371     myEditCurrentArgument = Group6F->LineEdit3;
00372   }
00373   else if (aSender == Group6F->PushButton4) {
00374     myEditCurrentArgument = Group6F->LineEdit4;
00375   }
00376   else if (aSender == Group6F->PushButton5) {
00377     myEditCurrentArgument = Group6F->LineEdit5;
00378   }
00379   else if (aSender == Group6F->PushButton6) {
00380     myEditCurrentArgument = Group6F->LineEdit6;
00381   }
00382 
00383   // enable push button and line edit
00384   myEditCurrentArgument->setEnabled(true);
00385   myEditCurrentArgument->setFocus();
00386   // after setFocus(), because it will be setDown(false) when loses focus
00387   aSender->setDown(true);
00388 
00389   globalSelection(); // close local contexts, if any
00390   localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); //Select Faces on All Shapes
00391   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00392           this, SLOT(SelectionIntoArgument()));
00393 }
00394 
00395 //=================================================================================
00396 // function : ActivateThisDialog()
00397 // purpose  :
00398 //=================================================================================
00399 void BlocksGUI_BlockDlg::ActivateThisDialog()
00400 {
00401   GEOMBase_Skeleton::ActivateThisDialog();
00402   globalSelection(); // close local contexts, if any
00403   localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); //Select Faces on All Shapes
00404   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00405           this, SLOT(SelectionIntoArgument()));
00406   displayPreview(true);
00407 }
00408 
00409 //=================================================================================
00410 // function : enterEvent()
00411 // purpose  :
00412 //=================================================================================
00413 void BlocksGUI_BlockDlg::enterEvent (QEvent*)
00414 {
00415   if (!mainFrame()->GroupConstructors->isEnabled())
00416     ActivateThisDialog();
00417 }
00418 
00419 //=================================================================================
00420 // function : createOperation
00421 // purpose  :
00422 //=================================================================================
00423 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
00424 {
00425   return getGeomEngine()->GetIBlocksOperations(getStudyId());
00426 }
00427 
00428 //=================================================================================
00429 // function : isValid
00430 // purpose  :
00431 //=================================================================================
00432 bool BlocksGUI_BlockDlg::isValid(QString&)
00433 {
00434   bool ok = false;
00435   switch (getConstructorId()) {
00436   case 0:
00437     ok = myFace1 && myFace2;
00438     break;
00439   case 1:
00440     ok = myFace1 && myFace2 && myFace3 && myFace4 && myFace5 && myFace6;
00441     break;
00442   default:
00443     break;
00444   }
00445   return ok;
00446 }
00447 
00448 //=================================================================================
00449 // function : execute
00450 // purpose  :
00451 //=================================================================================
00452 bool BlocksGUI_BlockDlg::execute (ObjectList& objects)
00453 {
00454   bool res = false;
00455 
00456   GEOM::GEOM_Object_var anObj;
00457 
00458   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
00459 
00460   switch (getConstructorId()) {
00461   case 0:
00462     if ( myFace1 && myFace2 ) {
00463       anObj = anOper->MakeHexa2Faces(myFace1.get(), myFace2.get());
00464       res = true;
00465     }
00466     break;
00467   case 1:
00468     if ( myFace1 && myFace2 && myFace3 && myFace4 && myFace5 && myFace6 ) {
00469       anObj = anOper->MakeHexa(myFace1.get(), myFace2.get(), myFace3.get(), myFace4.get(), myFace5.get(), myFace6.get());
00470       res = true;
00471     }
00472     break;
00473   }
00474 
00475   if (!anObj->_is_nil())
00476     objects.push_back(anObj._retn());
00477 
00478   return res;
00479 }
00480 
00481 //=================================================================================
00482 // function : addSubshapesToStudy
00483 // purpose  : virtual method to add new SubObjects if local selection
00484 //=================================================================================
00485 void BlocksGUI_BlockDlg::addSubshapesToStudy()
00486 {
00487   switch (getConstructorId()) {
00488   case 0:
00489     GEOMBase::PublishSubObject( myFace1.get() );
00490     GEOMBase::PublishSubObject( myFace2.get() );
00491     break;
00492   case 1:
00493     GEOMBase::PublishSubObject( myFace1.get() );
00494     GEOMBase::PublishSubObject( myFace2.get() );
00495     GEOMBase::PublishSubObject( myFace3.get() );
00496     GEOMBase::PublishSubObject( myFace4.get() );
00497     GEOMBase::PublishSubObject( myFace5.get() );
00498     GEOMBase::PublishSubObject( myFace6.get() );
00499     break;
00500   default:
00501     break;
00502   }
00503 }