Back to index

salome-geom  6.5.0
BlocksGUI_QuadFaceDlg.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_QuadFaceDlg.cxx
00025 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
00026 //
00027 #include "BlocksGUI_QuadFaceDlg.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 // QT Includes
00039 #include <qlabel.h>
00040 
00041 // OCCT Includes
00042 #include <TopAbs.hxx>
00043 #include <TColStd_IndexedMapOfInteger.hxx>
00044 
00045 #include <GEOMImpl_Types.hxx>
00046 
00047 //=================================================================================
00048 // class    : BlocksGUI_QuadFaceDlg()
00049 // purpose  : Constructs a BlocksGUI_QuadFaceDlg which is a child of 'parent'.
00050 //=================================================================================
00051 BlocksGUI_QuadFaceDlg::BlocksGUI_QuadFaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
00052   : GEOMBase_Skeleton(theGeometryGUI, parent),
00053     myInitial(true)
00054 {
00055   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
00056   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_4_VERT")));
00057   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_2_EDGE")));
00058   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_4_EDGE")));
00059   QPixmap imageS (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00060 
00061   setWindowTitle(tr("GEOM_QUAD_FACE_TITLE"));
00062 
00063   /***************************************************************/
00064   mainFrame()->GroupConstructors->setTitle(tr("GEOM_QUAD_FACE"));
00065 
00066   mainFrame()->RadioButton1->setIcon(image1);
00067   mainFrame()->RadioButton2->setIcon(image2);
00068   mainFrame()->RadioButton3->setIcon(image3);
00069 
00070   // Create first group
00071   myGrp1 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
00072 
00073   createSelWg(tr("VERTEX_1"), imageS, myGrp1, Vertex1);
00074   createSelWg(tr("VERTEX_2"), imageS, myGrp1, Vertex2);
00075   createSelWg(tr("VERTEX_3"), imageS, myGrp1, Vertex3);
00076   createSelWg(tr("VERTEX_4"), imageS, myGrp1, Vertex4);
00077 
00078   // Create second group
00079   myGrp2 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
00080 
00081   createSelWg(tr("EDGE_1"), imageS, myGrp2, Edge12);
00082   createSelWg(tr("EDGE_2"), imageS, myGrp2, Edge22);
00083 
00084   // Create fird group
00085   myGrp3 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
00086 
00087   createSelWg(tr("EDGE_1"), imageS, myGrp3, Edge14);
00088   createSelWg(tr("EDGE_2"), imageS, myGrp3, Edge24);
00089   createSelWg(tr("EDGE_3"), imageS, myGrp3, Edge34);
00090   createSelWg(tr("EDGE_4"), imageS, myGrp3, Edge44);
00091 
00092   // Add groups to layout
00093   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00094   layout->setMargin(0); layout->setSpacing(6);
00095   layout->addWidget(myGrp1);
00096   layout->addWidget(myGrp2);
00097   layout->addWidget(myGrp3);
00098   /***************************************************************/
00099 
00100   setHelpFileName("build_by_blocks_page.html#quad_face_anchor");
00101 
00102   Init();
00103 }
00104 
00105 //=================================================================================
00106 // function : ~BlocksGUI_QuadFaceDlg()
00107 // purpose  : Destroys the object and frees any allocated resources
00108 //=================================================================================
00109 BlocksGUI_QuadFaceDlg::~BlocksGUI_QuadFaceDlg()
00110 {
00111   // no need to delete child widgets, Qt does it all for us
00112 }
00113 
00114 //=================================================================================
00115 // function : Init()
00116 // purpose  :
00117 //=================================================================================
00118 void BlocksGUI_QuadFaceDlg::Init()
00119 {
00120   // signals and slots connections
00121   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00122   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00123 
00124   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00125 
00126   QMap<int, QPushButton*>::iterator anIterBtn;
00127   for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
00128     connect(anIterBtn.value(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00129 
00130   // init controls and fields
00131   initName(tr("GEOM_QUAD_FACE"));
00132 
00133   myConstructorId = -1;
00134   ConstructorsClicked(0);
00135 }
00136 
00137 //=================================================================================
00138 // function : ConstructorsClicked()
00139 // purpose  : Radio button management
00140 //=================================================================================
00141 void BlocksGUI_QuadFaceDlg::ConstructorsClicked (int constructorId)
00142 {
00143   if (myConstructorId == constructorId)
00144     return;
00145 
00146   myConstructorId = constructorId;
00147 
00148   // init fields
00149   myShape1.nullify();
00150   myShape2.nullify();
00151   myShape3.nullify();
00152   myShape4.nullify();
00153 
00154   // clear line edits
00155   QMap<int, QLineEdit*>::iterator anIterLE;
00156   for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
00157     anIterLE.value()->setText("");
00158 
00159   switch (constructorId) {
00160   case 0:
00161     myGrp2->hide();
00162     myGrp3->hide();
00163     myGrp1->show();
00164     mySelBtn[Vertex1]->click();
00165     break;
00166   case 1:
00167     myGrp1->hide();
00168     myGrp3->hide();
00169     myGrp2->show();
00170     mySelBtn[Edge12]->click();
00171     break;
00172   case 2:
00173     myGrp1->hide();
00174     myGrp2->hide();
00175     myGrp3->show();
00176     mySelBtn[Edge14]->click();
00177     break;
00178   default:
00179     break;
00180   }
00181 
00182   qApp->processEvents();
00183   updateGeometry();
00184   resize(minimumSizeHint());
00185 
00186   // on dialog initialization we init the first field with a selected object (if any)
00187   SelectionIntoArgument();
00188 }
00189 
00190 //=================================================================================
00191 // function : ClickOnOk()
00192 // purpose  :
00193 //=================================================================================
00194 void BlocksGUI_QuadFaceDlg::ClickOnOk()
00195 {
00196   setIsApplyAndClose( true );
00197   if (ClickOnApply())
00198     ClickOnCancel();
00199 }
00200 
00201 //=================================================================================
00202 // function : ClickOnApply()
00203 // purpose  :
00204 //=================================================================================
00205 bool BlocksGUI_QuadFaceDlg::ClickOnApply()
00206 {
00207   if (!onAccept())
00208     return false;
00209 
00210   initName();
00211   return true;
00212 }
00213 
00214 //=================================================================================
00215 // function : SelectionIntoArgument()
00216 // purpose  : Called when selection is changed or on dialog initialization or activation
00217 //=================================================================================
00218 void BlocksGUI_QuadFaceDlg::SelectionIntoArgument()
00219 {
00220   erasePreview();
00221 
00222   // Get index of current selection focus
00223   int aCurrFocus = -1;
00224   QMap<int, QLineEdit*>::iterator anIter;
00225   for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
00226     if (myEditCurrentArgument == anIter.value()) {
00227       aCurrFocus = anIter.key();
00228       break;
00229     }
00230   }
00231 
00232   TopAbs_ShapeEnum aType = TopAbs_EDGE;
00233   if (aCurrFocus == Vertex1 || aCurrFocus == Vertex2 ||
00234       aCurrFocus == Vertex3 || aCurrFocus == Vertex4)
00235     aType = TopAbs_VERTEX;
00236 
00237   GEOM::GeomObjPtr aSelectedObject = getSelected( aType );
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     switch (aCurrFocus) {
00243       // four vertices
00244     case Vertex1:
00245       myShape1 = aSelectedObject;
00246       if      (!myShape2) mySelBtn[Vertex2]->click();
00247       else if (!myShape3) mySelBtn[Vertex3]->click();
00248       else if (!myShape4) mySelBtn[Vertex4]->click();
00249       break;
00250     case Vertex2:
00251       myShape2 = aSelectedObject;
00252       if      (!myShape3) mySelBtn[Vertex3]->click();
00253       else if (!myShape4) mySelBtn[Vertex4]->click();
00254       else if (!myShape1) mySelBtn[Vertex1]->click();
00255       break;
00256     case Vertex3:
00257       myShape3 = aSelectedObject;
00258       if      (!myShape4) mySelBtn[Vertex4]->click();
00259       else if (!myShape1) mySelBtn[Vertex1]->click();
00260       else if (!myShape2) mySelBtn[Vertex2]->click();
00261       break;
00262     case Vertex4:
00263       myShape4 = aSelectedObject;
00264       if      (!myShape1) mySelBtn[Vertex1]->click();
00265       else if (!myShape2) mySelBtn[Vertex2]->click();
00266       else if (!myShape3) mySelBtn[Vertex3]->click();
00267       break;
00268       // two edges
00269     case Edge12:
00270       myShape1 = aSelectedObject;
00271       if      (!myShape2) mySelBtn[Edge22]->click();
00272       break;
00273     case Edge22:
00274       myShape2 = aSelectedObject;
00275       if      (!myShape1) mySelBtn[Edge12]->click();
00276       break;
00277       // four edges
00278     case Edge14:
00279       myShape1 = aSelectedObject;
00280       if      (!myShape2) mySelBtn[Edge24]->click();
00281       else if (!myShape3) mySelBtn[Edge34]->click();
00282       else if (!myShape4) mySelBtn[Edge44]->click();
00283       break;
00284     case Edge24:
00285       myShape2 = aSelectedObject;
00286       if      (!myShape3) mySelBtn[Edge34]->click();
00287       else if (!myShape4) mySelBtn[Edge44]->click();
00288       else if (!myShape1) mySelBtn[Edge14]->click();
00289       break;
00290     case Edge34:
00291       myShape3 = aSelectedObject;
00292       if      (!myShape4) mySelBtn[Edge44]->click();
00293       else if (!myShape1) mySelBtn[Edge14]->click();
00294       else if (!myShape2) mySelBtn[Edge24]->click();
00295       break;
00296     case Edge44:
00297       myShape4 = aSelectedObject;
00298       if      (!myShape1) mySelBtn[Edge14]->click();
00299       else if (!myShape2) mySelBtn[Edge24]->click();
00300       else if (!myShape3) mySelBtn[Edge34]->click();
00301       break;
00302     default:
00303       break;
00304     }
00305   }
00306   else {
00307     switch (aCurrFocus) {
00308     case Vertex1:
00309     case Edge12:
00310     case Edge14:
00311       myShape1.nullify();
00312       break;
00313     case Vertex2:
00314     case Edge22:
00315     case Edge24:
00316       myShape2.nullify();
00317       break;
00318     case Vertex3:
00319     case Edge34:
00320       myShape3.nullify();
00321       break;
00322     case Vertex4:
00323     case Edge44:
00324       myShape4.nullify();
00325       break;
00326     default:
00327       break;
00328     }
00329     myEditCurrentArgument->setText( "" );
00330   }
00331 
00332   displayPreview(true);
00333 }
00334 
00335 //=================================================================================
00336 // function : SetEditCurrentArgument()
00337 // purpose  :
00338 //=================================================================================
00339 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
00340 {
00341   QPushButton* aSender = (QPushButton*)sender();
00342 
00343   // clear selection
00344   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00345   if (myInitial)
00346     myInitial = false;
00347   else
00348     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00349 
00350   // disable all
00351   switch (myConstructorId) {
00352   case 0:
00353     mySelBtn[Vertex1]->setDown(false);
00354     mySelBtn[Vertex2]->setDown(false);
00355     mySelBtn[Vertex3]->setDown(false);
00356     mySelBtn[Vertex4]->setDown(false);
00357 
00358     mySelName[Vertex1]->setEnabled(false);
00359     mySelName[Vertex2]->setEnabled(false);
00360     mySelName[Vertex3]->setEnabled(false);
00361     mySelName[Vertex4]->setEnabled(false);
00362     break;
00363   case 1:
00364     mySelBtn[Edge12]->setDown(false);
00365     mySelBtn[Edge22]->setDown(false);
00366 
00367     mySelName[Edge12]->setEnabled(false);
00368     mySelName[Edge22]->setEnabled(false);
00369     break;
00370   case 2:
00371     mySelBtn[Edge14]->setDown(false);
00372     mySelBtn[Edge24]->setDown(false);
00373     mySelBtn[Edge34]->setDown(false);
00374     mySelBtn[Edge44]->setDown(false);
00375 
00376     mySelName[Edge14]->setEnabled(false);
00377     mySelName[Edge24]->setEnabled(false);
00378     mySelName[Edge34]->setEnabled(false);
00379     mySelName[Edge44]->setEnabled(false);
00380     break;
00381   default:
00382     break;
00383   }
00384 
00385   // set line edit as current argument
00386   QMap<int, QPushButton*>::iterator anIter;
00387   for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
00388     if (anIter.value() == aSender) {
00389       myEditCurrentArgument = mySelName[anIter.key()];
00390       break;
00391     }
00392   }
00393 
00394   // enable line edit
00395   myEditCurrentArgument->setEnabled(true);
00396   myEditCurrentArgument->setFocus();
00397 
00398   // enable push button
00399   // after setFocus(), because it will be setDown(false) when loses focus
00400   aSender->setDown(true);
00401 
00402   activateSelection();
00403 }
00404 
00405 //=================================================================================
00406 // function : ActivateThisDialog()
00407 // purpose  :
00408 //=================================================================================
00409 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
00410 {
00411   GEOMBase_Skeleton::ActivateThisDialog();
00412   activateSelection();
00413 
00414   // ??
00415   displayPreview(true);
00416 }
00417 
00418 //=================================================================================
00419 // function : enterEvent()
00420 // purpose  :
00421 //=================================================================================
00422 void BlocksGUI_QuadFaceDlg::enterEvent (QEvent*)
00423 {
00424   if (!mainFrame()->GroupConstructors->isEnabled())
00425     ActivateThisDialog();
00426 }
00427 
00428 //=================================================================================
00429 // function : createSelWg()
00430 // purpose  :
00431 //=================================================================================
00432 void BlocksGUI_QuadFaceDlg::createSelWg (const QString& theLbl,
00433                                          QPixmap&       thePix,
00434                                          QWidget*       theParent,
00435                                          const int      theId)
00436 {
00437   QLabel* lab = new QLabel(theLbl, theParent);
00438   mySelBtn[theId] = new QPushButton(theParent);
00439   mySelBtn[theId]->setIcon(thePix);
00440   mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00441   mySelName[theId] = new QLineEdit(theParent);
00442   mySelName[theId]->setReadOnly(true);
00443   QGridLayout* l = 0;
00444   if (!theParent->layout()) {
00445     l = new QGridLayout(theParent);
00446     l->setMargin(9); l->setSpacing(6);
00447   }
00448   else {
00449     l = qobject_cast<QGridLayout*>(theParent->layout());
00450   }
00451   int row = l->rowCount();
00452   l->addWidget(lab,              row, 0);
00453   l->addWidget(mySelBtn[theId],  row, 1);
00454   l->addWidget(mySelName[theId], row, 2);
00455 }
00456 
00457 //=================================================================================
00458 // function : activateSelection
00459 // purpose  : Activate selection in accordance with myEditCurrentArgument
00460 //=================================================================================
00461 void BlocksGUI_QuadFaceDlg::activateSelection()
00462 {
00463   globalSelection(); // close local contexts, if any
00464   if (myEditCurrentArgument == mySelName[Vertex1] ||
00465       myEditCurrentArgument == mySelName[Vertex2] ||
00466       myEditCurrentArgument == mySelName[Vertex3] ||
00467       myEditCurrentArgument == mySelName[Vertex4])
00468   {
00469     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertices on All Shapes
00470   }
00471   else
00472   {
00473     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); //Select Edges on All Shapes
00474   }
00475   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00476           this, SLOT(SelectionIntoArgument()));
00477 }
00478 
00479 //=================================================================================
00480 // function : createOperation
00481 // purpose  :
00482 //=================================================================================
00483 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
00484 {
00485   return getGeomEngine()->GetIBlocksOperations(getStudyId());
00486 }
00487 
00488 //=================================================================================
00489 // function : isValid
00490 // purpose  : Verify validity of input data
00491 //=================================================================================
00492 bool BlocksGUI_QuadFaceDlg::isValid (QString&)
00493 {
00494   bool ok = false;
00495   switch (getConstructorId()) {
00496   case 0:
00497     ok = myShape1 && myShape2 && myShape3 && myShape4;
00498     break;
00499   case 1:
00500     ok = myShape1 && myShape2;
00501     break;
00502   case 2:
00503     ok = myShape1 && myShape2 && myShape3 && myShape4;
00504     break;
00505   default:
00506     break;
00507   }
00508   return ok;
00509 }
00510 
00511 //=================================================================================
00512 // function : execute
00513 // purpose  :
00514 //=================================================================================
00515 bool BlocksGUI_QuadFaceDlg::execute (ObjectList& objects)
00516 {
00517   bool res = false;
00518 
00519   GEOM::GEOM_Object_var anObj;
00520 
00521   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
00522 
00523   switch (getConstructorId()) {
00524   case 0:
00525     anObj = anOper->MakeQuad4Vertices(myShape1.get(), myShape2.get(), myShape3.get(), myShape4.get());
00526     res = true;
00527     break;
00528   case 1:
00529     anObj = anOper->MakeQuad2Edges(myShape1.get(), myShape2.get());
00530     res = true;
00531     break;
00532   case 2:
00533     anObj = anOper->MakeQuad(myShape1.get(), myShape2.get(), myShape3.get(), myShape4.get());
00534     res = true;
00535     break;
00536   default:
00537     break;
00538   }
00539 
00540   if (!anObj->_is_nil())
00541     objects.push_back(anObj._retn());
00542 
00543   return res;
00544 }
00545 
00546 //=================================================================================
00547 // function : addSubshapeToStudy
00548 // purpose  : virtual method to add new SubObjects if local selection
00549 //=================================================================================
00550 void BlocksGUI_QuadFaceDlg::addSubshapesToStudy()
00551 {
00552   switch (getConstructorId()) {
00553   case 0:
00554     GEOMBase::PublishSubObject( myShape1.get() );
00555     GEOMBase::PublishSubObject( myShape2.get() );
00556     GEOMBase::PublishSubObject( myShape3.get() );
00557     GEOMBase::PublishSubObject( myShape4.get() );
00558     break;
00559   case 1:
00560     GEOMBase::PublishSubObject( myShape1.get() );
00561     GEOMBase::PublishSubObject( myShape2.get() );
00562     break;
00563   case 2:
00564     GEOMBase::PublishSubObject( myShape1.get() );
00565     GEOMBase::PublishSubObject( myShape2.get() );
00566     GEOMBase::PublishSubObject( myShape3.get() );
00567     GEOMBase::PublishSubObject( myShape4.get() );
00568     break;
00569   default:
00570     break;
00571   }
00572 }