Back to index

salome-geom  6.5.0
BooleanGUI_Dialog.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   : BooleanGUI_Dialog.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "BooleanGUI.h"
00028 #include "BooleanGUI_Dialog.h"
00029 
00030 #include <DlgRef.h>
00031 #include <GeometryGUI.h>
00032 #include <GEOMBase.h>
00033 
00034 #include <SUIT_Session.h>
00035 #include <SUIT_ResourceMgr.h>
00036 #include <SalomeApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 
00039 //=================================================================================
00040 // class    : BooleanGUI_Dialog()
00041 // purpose  : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
00042 //            name 'name' and widget flags set to 'f'.
00043 //            The dialog will by default be modeless, unless you set 'modal' to
00044 //            TRUE to construct a modal dialog.
00045 //=================================================================================
00046 BooleanGUI_Dialog::BooleanGUI_Dialog (const int theOperation, GeometryGUI* theGeometryGUI,
00047                                       QWidget* parent, bool modal, Qt::WindowFlags fl)
00048   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
00049     myOperation(theOperation)
00050 {
00051   QPixmap image0;
00052   QString aTitle, aCaption;
00053   switch (myOperation) {
00054   case BooleanGUI::COMMON:
00055     image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
00056     aTitle = tr("GEOM_COMMON");
00057     aCaption = tr("GEOM_COMMON_TITLE");
00058     setHelpFileName("common_operation_page.html");
00059     break;
00060   case BooleanGUI::CUT:
00061     image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
00062     aTitle = tr("GEOM_CUT");
00063     aCaption = tr("GEOM_CUT_TITLE");
00064     setHelpFileName("cut_operation_page.html");
00065     break;
00066   case BooleanGUI::FUSE:
00067     image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
00068     aTitle = tr("GEOM_FUSE");
00069     aCaption = tr("GEOM_FUSE_TITLE");
00070     setHelpFileName("fuse_operation_page.html");
00071     break;
00072   case BooleanGUI::SECTION:
00073     image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SECTION")));
00074     aTitle = tr("GEOM_SECTION");
00075     aCaption = tr("GEOM_SECTION_TITLE");
00076     setHelpFileName("section_opeartion_page.html");
00077     break;
00078   }
00079   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00080 
00081   setWindowTitle(aCaption);
00082 
00083   /***************************************************************/
00084   mainFrame()->GroupConstructors->setTitle(aTitle);
00085   mainFrame()->RadioButton1->setIcon(image0);
00086   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00087   mainFrame()->RadioButton2->close();
00088   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00089   mainFrame()->RadioButton3->close();
00090 
00091   myGroup = new DlgRef_2Sel(centralWidget());
00092 
00093   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00094   if (myOperation != BooleanGUI::CUT) {
00095     myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg(1));
00096     myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg(2));
00097   }
00098   else {
00099     myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
00100     myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
00101   }
00102 
00103   myGroup->PushButton1->setIcon(image1);
00104   myGroup->PushButton2->setIcon(image1);
00105   myGroup->LineEdit1->setReadOnly(true);
00106   myGroup->LineEdit2->setReadOnly(true);
00107 
00108   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00109   layout->setMargin(0); layout->setSpacing(6);
00110   layout->addWidget(myGroup);
00111   /***************************************************************/
00112 
00113   // Initialisation
00114   Init();
00115 }
00116 
00117 //=================================================================================
00118 // function : ~BooleanGUI_Dialog()
00119 // purpose  : Destroys the object and frees any allocated resources
00120 //=================================================================================
00121 BooleanGUI_Dialog::~BooleanGUI_Dialog()
00122 {
00123 }
00124 
00125 //=================================================================================
00126 // function : Init()
00127 // purpose  :
00128 //=================================================================================
00129 void BooleanGUI_Dialog::Init()
00130 {
00131   mainFrame()->GroupBoxPublish->show();
00132 
00133   // init variables
00134   myEditCurrentArgument = myGroup->LineEdit1;
00135 
00136   myGroup->LineEdit1->setText("");
00137   myGroup->LineEdit2->setText("");
00138   myObject1.nullify();
00139   myObject2.nullify();
00140  
00141   // signals and slots connections
00142   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00143   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00144 
00145   connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00146   connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00147 
00148   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
00149            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00150 
00151   initName(mainFrame()->GroupConstructors->title());
00152 
00153   setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
00154   setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
00155   setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
00156 
00157   mainFrame()->RadioButton1->setFocus();
00158 
00159   globalSelection(GEOM_ALLSHAPES);
00160 
00161   myGroup->PushButton1->click();
00162   SelectionIntoArgument();
00163   resize(100,100);
00164 }
00165 
00166 //=================================================================================
00167 // function : ClickOnOk()
00168 // purpose  :
00169 //=================================================================================
00170 void BooleanGUI_Dialog::ClickOnOk()
00171 {
00172   setIsApplyAndClose( true );
00173   if (ClickOnApply())
00174     ClickOnCancel();
00175 }
00176 
00177 //=================================================================================
00178 // function : ClickOnApply()
00179 // purpose  :
00180 //=================================================================================
00181 bool BooleanGUI_Dialog::ClickOnApply()
00182 {
00183   if (!onAccept())
00184     return false;
00185 
00186   initName();
00187   // activate selection and connect selection manager
00188   myGroup->PushButton1->click();
00189   return true;
00190 }
00191 
00192 //=================================================================================
00193 // function : SelectionIntoArgument()
00194 // purpose  : Called when selection is changed or on dialog initialization or activation
00195 //=================================================================================
00196 void BooleanGUI_Dialog::SelectionIntoArgument()
00197 {
00198   myEditCurrentArgument->setText("");
00199 
00200   GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
00201   TopoDS_Shape aShape;
00202   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00203     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00204     myEditCurrentArgument->setText( aName );
00205 
00206     // clear selection
00207     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00208     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00209     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00210             this, SLOT(SelectionIntoArgument()));
00211 
00212     if (myEditCurrentArgument == myGroup->LineEdit1) {
00213       myObject1 = aSelectedObject;
00214       if (!myObject2)
00215         myGroup->PushButton2->click();
00216     }
00217     else if (myEditCurrentArgument == myGroup->LineEdit2) {
00218       myObject2 = aSelectedObject;
00219       if (!myObject1)
00220         myGroup->PushButton1->click();
00221     }
00222   }
00223   else {
00224     if      (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
00225     else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
00226   }
00227 }
00228 
00229 //=================================================================================
00230 // function : SetEditCurrentArgument()
00231 // purpose  :
00232 //=================================================================================
00233 void BooleanGUI_Dialog::SetEditCurrentArgument()
00234 {
00235   QPushButton* send = (QPushButton*)sender();
00236 
00237   if (send == myGroup->PushButton1) {
00238     myEditCurrentArgument = myGroup->LineEdit1;
00239 
00240     myGroup->PushButton2->setDown(false);
00241     myGroup->LineEdit2->setEnabled(false);
00242   }
00243   else if (send == myGroup->PushButton2) {
00244     myEditCurrentArgument = myGroup->LineEdit2;
00245 
00246     myGroup->PushButton1->setDown(false);
00247     myGroup->LineEdit1->setEnabled(false);
00248   }
00249 
00250   // enable line edit
00251   myEditCurrentArgument->setEnabled(true);
00252   myEditCurrentArgument->setFocus();
00253   // after setFocus(), because it will be setDown(false) when loses focus
00254   send->setDown(true);
00255 }
00256 
00257 //=================================================================================
00258 // function : ActivateThisDialog()
00259 // purpose  :
00260 //=================================================================================
00261 void BooleanGUI_Dialog::ActivateThisDialog()
00262 {
00263   GEOMBase_Skeleton::ActivateThisDialog();
00264 
00265   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00266            this, SLOT( SelectionIntoArgument() ) );
00267   processPreview();
00268 }
00269 
00270 //=================================================================================
00271 // function : enterEvent()
00272 // purpose  : when mouse enter onto the QWidget
00273 //=================================================================================
00274 void BooleanGUI_Dialog::enterEvent (QEvent*)
00275 {
00276   if (!mainFrame()->GroupConstructors->isEnabled())
00277     ActivateThisDialog();
00278 }
00279 
00280 //=================================================================================
00281 // function : createOperation
00282 // purpose  :
00283 //=================================================================================
00284 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
00285 {
00286   return getGeomEngine()->GetIBooleanOperations(getStudyId());
00287 }
00288 
00289 //=================================================================================
00290 // function : isValid
00291 // purpose  :
00292 //=================================================================================
00293 bool BooleanGUI_Dialog::isValid (QString&)
00294 {
00295   return myObject1 && myObject2;
00296 }
00297 
00298 //=================================================================================
00299 // function : execute
00300 // purpose  :
00301 //=================================================================================
00302 bool BooleanGUI_Dialog::execute (ObjectList& objects)
00303 {
00304   GEOM::GEOM_Object_var anObj;
00305 
00306   GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
00307   anObj = anOper->MakeBoolean(myObject1.get(), myObject2.get(), myOperation);
00308   if (!anObj->_is_nil())
00309     objects.push_back(anObj._retn());
00310 
00311   return true;
00312 }
00313 
00314 //=================================================================================
00315 // function : restoreSubShapes
00316 // purpose  :
00317 //=================================================================================
00318 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
00319                                           SALOMEDS::SObject_ptr theSObject)
00320 {
00321   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
00322     // empty list of arguments means that all arguments should be restored
00323     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
00324                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
00325                                          /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
00326                                          mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false
00327   }
00328 }