Back to index

salome-geom  6.5.0
OperationGUI_GetShapesOnShapeDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // GEOM GEOMGUI : GUI for Geometry component
00021 // File   : OperationGUI_GetShapesOnShapeDlg.cxx
00022 // Author : Sergey KUUL, Open CASCADE S.A.S. (sergey.kuul@opencascade.com)
00023 //
00024 #include "OperationGUI_GetShapesOnShapeDlg.h"
00025 
00026 #include <DlgRef.h>
00027 #include <GeometryGUI.h>
00028 #include <GEOMBase.h>
00029 
00030 #include <SUIT_Session.h>
00031 #include <SUIT_ResourceMgr.h>
00032 #include <SalomeApp_Application.h>
00033 #include <LightApp_SelectionMgr.h>
00034 
00035 //==============================================================================
00036 // class    : OperationGUI_GetShapesOnShapeDlg()
00037 // purpose  : Constructs a OperationGUI_GetShapesOnShapeDlg which is a child of
00038 //            'parent', with the name 'name' and widget flags set to 'f'.
00039 //            The dialog will by default be modeless, unless you set 'modal' to
00040 //            TRUE to construct a modal dialog.
00041 //=================================================================================
00042 OperationGUI_GetShapesOnShapeDlg::OperationGUI_GetShapesOnShapeDlg (GeometryGUI* theGeometryGUI,
00043                                                                     QWidget* parent)
00044   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
00045 {
00046   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
00047   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHAPES_ON_SHAPE")));
00048   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00049 
00050   setWindowTitle(tr("GEOM_SHAPES_ON_SHAPE_TITLE"));
00051 
00052   /***************************************************************/
00053   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SHAPES_ON_SHAPE"));
00054   mainFrame()->RadioButton1->setIcon(image0);
00055   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00056   mainFrame()->RadioButton2->close();
00057   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00058   mainFrame()->RadioButton3->close();
00059 
00060   GroupPoints = new DlgRef_2Sel2List(centralWidget());
00061   //GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
00062   GroupPoints->GroupBox1->setTitle("Input data");
00063   GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES_ON_SHAPE_ESHAPE"));
00064   GroupPoints->TextLabel2->setText(tr("GEOM_SHAPES_ON_SHAPE_CSHAPE"));
00065   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
00066   GroupPoints->TextLabel4->setText(tr("GEOM_SHAPES_ON_SHAPE_STATE"));
00067   GroupPoints->PushButton1->setIcon(image2);
00068   GroupPoints->PushButton2->setIcon(image2);
00069   GroupPoints->LineEdit1->setReadOnly(true);
00070   GroupPoints->LineEdit2->setReadOnly(true);
00071 
00072   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00073   layout->setMargin(0); layout->setSpacing(6);
00074   layout->addWidget(GroupPoints);
00075   /***************************************************************/
00076 
00077   setHelpFileName("shapesonshape_page.html");
00078 
00079   Init();
00080 }
00081 
00082 //=================================================================================
00083 // function : ~OperationGUI_GetShapesOnShapeDlg
00084 // purpose  : Destroys the object and frees any allocated resources
00085 //=================================================================================
00086 OperationGUI_GetShapesOnShapeDlg::~OperationGUI_GetShapesOnShapeDlg()
00087 {
00088 }
00089 
00090 //=================================================================================
00091 // function : Init()
00092 // purpose  :
00093 //=================================================================================
00094 void OperationGUI_GetShapesOnShapeDlg::Init()
00095 {
00096   // type for sub-shape selection
00097   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
00098   // commented by skl for IPAL19949 - finder isn't allowed such type
00099   //GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
00100   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
00101   // commented by skl for IPAL19949 - finder isn't allowed such type
00102   //GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
00103   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
00104   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
00105 
00106   // type for state selection
00107   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_IN"));
00108   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_OUT"));
00109   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ON"));
00110   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ONIN"));
00111   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ONOUT"));
00112 
00113   GroupPoints->LineEdit1->clear();
00114   GroupPoints->LineEdit2->clear();
00115   myObject1 = myObject2 = GEOM::GEOM_Object::_nil();
00116 
00117   showOnlyPreviewControl();
00118 
00119   // signals and slots connections
00120   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00121   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00122 
00123   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00124   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00125 
00126   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00127   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00128 
00129   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
00130   connect(GroupPoints->ComboBox2, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
00131 
00132   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00133           this, SLOT(SelectionIntoArgument()));
00134 
00135   initName(mainFrame()->GroupConstructors->title());
00136 
00137   GroupPoints->TextLabel3->show();
00138   GroupPoints->ComboBox1->show();
00139   GroupPoints->ComboBox1->setCurrentIndex(0);
00140   GroupPoints->ComboBox2->show();
00141   GroupPoints->ComboBox2->setCurrentIndex(0);
00142 
00143   globalSelection(GEOM_ALLSHAPES);
00144 
00145   GroupPoints->PushButton1->click();
00146   SelectionIntoArgument();
00147   resize(100,100);
00148 }
00149 
00150 //=================================================================================
00151 // function : ClickOnOk()
00152 // purpose  :
00153 //=================================================================================
00154 void OperationGUI_GetShapesOnShapeDlg::ClickOnOk()
00155 {
00156   setIsApplyAndClose( true );
00157   if (ClickOnApply())
00158     ClickOnCancel();
00159 }
00160 
00161 //=================================================================================
00162 // function : ClickOnApply()
00163 // purpose  :
00164 //=================================================================================
00165 bool OperationGUI_GetShapesOnShapeDlg::ClickOnApply()
00166 {
00167   if (!onAccept())
00168     return false;
00169 
00170   initName();
00171   // activate first line edit
00172   GroupPoints->PushButton1->click();
00173   return true;
00174 }
00175 
00176 //=================================================================================
00177 // function : SelectionIntoArgument()
00178 // purpose  : Called when selection is changed or on dialog initialization or activation
00179 //=================================================================================
00180 void OperationGUI_GetShapesOnShapeDlg::SelectionIntoArgument()
00181 {
00182   myEditCurrentArgument->setText("");
00183 
00184   if      (myEditCurrentArgument == GroupPoints->LineEdit1) myObject1 = GEOM::GEOM_Object::_nil();
00185   else if (myEditCurrentArgument == GroupPoints->LineEdit2) myObject2 = GEOM::GEOM_Object::_nil();
00186 
00187   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00188   SALOME_ListIO aSelList;
00189   aSelMgr->selectedObjects(aSelList);
00190 
00191   QString aName = "";
00192   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName, true);
00193 
00194   if (nbSel > 0) {
00195     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00196     if ( GEOMBase::IsShape(aSelectedObject) ) {
00197       myEditCurrentArgument->setText(aName);
00198 
00199       // clear selection
00200       disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00201       myGeomGUI->getApp()->selectionMgr()->clearSelected();
00202       connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00203               this, SLOT(SelectionIntoArgument()));
00204 
00205       if (myEditCurrentArgument == GroupPoints->LineEdit1) {
00206         myObject1 = aSelectedObject;
00207         if (myObject2->_is_nil())
00208           GroupPoints->PushButton2->click();
00209       }
00210       else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
00211         myObject2 = aSelectedObject;
00212         if (myObject1->_is_nil())
00213           GroupPoints->PushButton1->click();
00214       }
00215     }
00216   }
00217   processPreview();
00218 }
00219 
00220 //=================================================================================
00221 // function : SetEditCurrentArgument()
00222 // purpose  :
00223 //=================================================================================
00224 void OperationGUI_GetShapesOnShapeDlg::SetEditCurrentArgument()
00225 {
00226   QPushButton* send = (QPushButton*)sender();
00227 
00228   if      (send == GroupPoints->PushButton1) {
00229     myEditCurrentArgument = GroupPoints->LineEdit1;
00230 
00231     GroupPoints->PushButton2->setDown(false);
00232     GroupPoints->LineEdit2->setEnabled(false);
00233   }
00234   else if (send == GroupPoints->PushButton2) {
00235     myEditCurrentArgument = GroupPoints->LineEdit2;
00236 
00237     GroupPoints->PushButton1->setDown(false);
00238     GroupPoints->LineEdit1->setEnabled(false);
00239   }
00240 
00241   // enable line edit
00242   myEditCurrentArgument->setEnabled(true);
00243   myEditCurrentArgument->setFocus();
00244   // after setFocus(), because it will be setDown(false) when loses focus
00245   send->setDown(true);
00246 }
00247 
00248 //=================================================================================
00249 // function : LineEditReturnPressed()
00250 // purpose  :
00251 //=================================================================================
00252 void OperationGUI_GetShapesOnShapeDlg::LineEditReturnPressed()
00253 {
00254   QLineEdit* send = (QLineEdit*)sender();
00255   if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
00256   {
00257     myEditCurrentArgument = send;
00258     GEOMBase_Skeleton::LineEditReturnPressed();
00259   }
00260 }
00261 
00262 //=================================================================================
00263 // function : ActivateThisDialog()
00264 // purpose  :
00265 //=================================================================================
00266 void OperationGUI_GetShapesOnShapeDlg::ActivateThisDialog()
00267 {
00268   GEOMBase_Skeleton::ActivateThisDialog();
00269   globalSelection(GEOM_ALLSHAPES);
00270   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00271            this, SLOT( SelectionIntoArgument() ) );
00272   processPreview();
00273 }
00274 
00275 //=================================================================================
00276 // function : enterEvent()
00277 // purpose  : when mouse enter onto the QWidget
00278 //=================================================================================
00279 void OperationGUI_GetShapesOnShapeDlg::enterEvent (QEvent*)
00280 {
00281   if (!mainFrame()->GroupConstructors->isEnabled())
00282     ActivateThisDialog();
00283 }
00284 
00285 //=================================================================================
00286 // function : createOperation
00287 // purpose  :
00288 //=================================================================================
00289 GEOM::GEOM_IOperations_ptr OperationGUI_GetShapesOnShapeDlg::createOperation()
00290 {
00291   return getGeomEngine()->GetIShapesOperations(getStudyId());
00292 }
00293 
00294 //=================================================================================
00295 // function : isValid
00296 // purpose  :
00297 //=================================================================================
00298 bool OperationGUI_GetShapesOnShapeDlg::isValid(QString&)
00299 {
00300   //Handle(SALOME_InteractiveObject) IO = firstIObject();
00301   //GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO );
00302   //if ( anObject->_is_nil() )
00303   //  return false;
00304 
00305   return !CORBA::is_nil(myObject1) && !CORBA::is_nil(myObject2);
00306 }
00307 
00308 //=================================================================================
00309 // function : execute
00310 // purpose  :
00311 //=================================================================================
00312 bool OperationGUI_GetShapesOnShapeDlg::execute (ObjectList& objects)
00313 {
00314   int aLimit = GroupPoints->ComboBox1->currentIndex();
00315   switch (aLimit)
00316   {
00317   case 0:  aLimit = GEOM::SOLID ; break;
00318   case 1:  aLimit = GEOM::FACE  ; break;
00319   case 2:  aLimit = GEOM::EDGE  ; break;
00320   case 3:  aLimit = GEOM::VERTEX; break;
00321   default: aLimit = GEOM::SHAPE ; break;
00322   }
00323 
00324   GEOM::shape_state aState;
00325   switch (GroupPoints->ComboBox2->currentIndex())
00326   {
00327     case 0:  aState = GEOM::ST_IN;    break;
00328     case 1:  aState = GEOM::ST_OUT;   break;
00329     case 2:  aState = GEOM::ST_ON;    break;
00330     case 3:  aState = GEOM::ST_ONIN;  break;
00331     case 4:  aState = GEOM::ST_ONOUT; break;
00332     default: break;
00333   }
00334 
00335   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
00336   GEOM::GEOM_Object_var anObj = anOper->GetShapesOnShapeAsCompound(myObject2, myObject1,
00337                                                                    (CORBA::Short) aLimit,
00338                                                                    aState);
00339 
00340   if (!anObj->_is_nil())
00341     objects.push_back(anObj._retn());
00342 
00343   return objects.size();
00344 }
00345 
00346 //=======================================================================
00347 //function : ComboTextChanged
00348 //purpose  :
00349 //=======================================================================
00350 void OperationGUI_GetShapesOnShapeDlg::ComboTextChanged()
00351 {
00352   // VRS ???? What is it for ??? commented for a while...
00353   //bool IsEnabled = GroupPoints->ComboBox1->currentIndex() < 3;
00354   processPreview();
00355 }