Back to index

salome-geom  6.5.0
OperationGUI_GetSharedShapesDlg.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 //  File   : OperationGUI_GetSharedShapesDlg.cxx
00023 //  Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00024 
00025 #include "OperationGUI_GetSharedShapesDlg.h"
00026 
00027 #include <DlgRef.h>
00028 #include <GeometryGUI.h>
00029 #include <GEOMBase.h>
00030 
00031 #include <GEOMImpl_Types.hxx>
00032 
00033 #include <SUIT_Desktop.h>
00034 #include <SUIT_Session.h>
00035 #include <SUIT_ResourceMgr.h>
00036 #include <SUIT_MessageBox.h>
00037 #include <SalomeApp_Application.h>
00038 #include <LightApp_SelectionMgr.h>
00039 
00040 #include <TopoDS_Iterator.hxx>
00041 #include <TopoDS_Shape.hxx>
00042 
00043 //=================================================================================
00044 // class    : OperationGUI_GetSharedShapesDlg()
00045 // purpose  : Constructs a OperationGUI_GetSharedShapesDlg which is a child of 'parent', with the
00046 //            name 'name' and widget flags set to 'f'.
00047 //            The dialog will by default be modeless, unless you set 'modal' to
00048 //            TRUE to construct a modal dialog.
00049 //=================================================================================
00050 OperationGUI_GetSharedShapesDlg::OperationGUI_GetSharedShapesDlg
00051 (GeometryGUI* theGeometryGUI, QWidget* parent)
00052   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
00053 {
00054   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
00055   QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHARED_SHAPES")));
00056   QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00057 
00058   setWindowTitle(tr("GEOM_SHARED_SHAPES_TITLE"));
00059 
00060   /***************************************************************/
00061   mainFrame()->GroupConstructors->setTitle(tr("GEOM_GET_SHARED_SHAPES"));
00062   mainFrame()->RadioButton1->setIcon(image0);
00063   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00064   mainFrame()->RadioButton2->close();
00065   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00066   mainFrame()->RadioButton3->close();
00067 
00068   GroupPoints = new DlgRef_2Sel1List1Check(centralWidget());
00069   GroupPoints->GroupBox1->setTitle(tr("GEOM_SHARED_SHAPES_INPUT"));
00070   GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES"));
00071   GroupPoints->TextLabel2->hide();
00072   GroupPoints->TextLabel3->setText(tr("GEOM_SUBSHAPE_TYPE"));
00073   GroupPoints->PushButton1->setIcon(image2);
00074   GroupPoints->PushButton2->hide();
00075   GroupPoints->LineEdit1->setReadOnly(true);
00076   GroupPoints->LineEdit2->hide();
00077   GroupPoints->LineEdit1->setEnabled(true);
00078   GroupPoints->CheckButton1->hide();
00079 
00080   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00081   layout->setMargin(0); layout->setSpacing(6);
00082   layout->addWidget(GroupPoints);
00083 
00084   /***************************************************************/
00085 
00086   setHelpFileName("shared_shapes_page.html");
00087 
00088   Init();
00089 }
00090 
00091 //=================================================================================
00092 // function : ~OperationGUI_GetSharedShapesDlg()
00093 // purpose  : Destroys the object and frees any allocated resources
00094 //=================================================================================
00095 OperationGUI_GetSharedShapesDlg::~OperationGUI_GetSharedShapesDlg()
00096 {
00097   // no need to delete child widgets, Qt does it all for us
00098 }
00099 
00100 //=================================================================================
00101 // function : Init()
00102 // purpose  :
00103 //=================================================================================
00104 void OperationGUI_GetSharedShapesDlg::Init()
00105 {
00106   /* type for sub-shape selection */
00107   GroupPoints->ComboBox1->addItem(tr("GEOM_SOLID"));
00108   GroupPoints->ComboBox1->addItem(tr("GEOM_SHELL"));
00109   GroupPoints->ComboBox1->addItem(tr("GEOM_FACE"));
00110   GroupPoints->ComboBox1->addItem(tr("GEOM_WIRE"));
00111   GroupPoints->ComboBox1->addItem(tr("GEOM_EDGE"));
00112   GroupPoints->ComboBox1->addItem(tr("GEOM_VERTEX"));
00113 
00114   GroupPoints->ComboBox1->setCurrentIndex(0);
00115 
00116   showOnlyPreviewControl();
00117 
00118   /* signals and slots connections */
00119   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00120   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00121 
00122   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00123 
00124   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00125 
00126   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00127 
00128   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
00129 
00130   connect(myGeomGUI->getApp()->selectionMgr(),
00131            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00132 
00133   //initName(getNewObjectName());
00134   initName(getPrefixByType());
00135 
00136   ConstructorsClicked(0);
00137   GroupPoints->PushButton1->click();
00138 }
00139 
00140 //=================================================================================
00141 // function : ConstructorsClicked()
00142 // purpose  : Radio button management
00143 //=================================================================================
00144 void OperationGUI_GetSharedShapesDlg::ConstructorsClicked (int constructorId)
00145 {
00146   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00147   globalSelection();
00148 
00149   myListShapes.length(0);
00150 
00151   GroupPoints->ComboBox1->setCurrentIndex(0);
00152   GroupPoints->PushButton1->setDown(true);
00153 
00154   myEditCurrentArgument = GroupPoints->LineEdit1;
00155   GroupPoints->LineEdit1->clear();
00156 
00157   qApp->processEvents();
00158   updateGeometry();
00159   resize(minimumSizeHint());
00160 
00161   myEditCurrentArgument->setFocus();
00162   connect(myGeomGUI->getApp()->selectionMgr(),
00163           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00164   SelectionIntoArgument();
00165 }
00166 
00167 //=================================================================================
00168 // function : ClickOnOk()
00169 // purpose  :
00170 //=================================================================================
00171 void OperationGUI_GetSharedShapesDlg::ClickOnOk()
00172 {
00173   setIsApplyAndClose( true );
00174   if (ClickOnApply())
00175     ClickOnCancel();
00176 }
00177 
00178 //=================================================================================
00179 // function : ClickOnApply()
00180 // purpose  :
00181 //=================================================================================
00182 bool OperationGUI_GetSharedShapesDlg::ClickOnApply()
00183 {
00184   if (!onAccept())
00185     return false;
00186 
00187   //initName(getNewObjectName());
00188   initName(getPrefixByType());
00189 
00190   return true;
00191 }
00192 
00193 //=================================================================================
00194 // function : SelectionIntoArgument()
00195 // purpose  : Called when selection as changed or other case
00196 //=================================================================================
00197 void OperationGUI_GetSharedShapesDlg::SelectionIntoArgument()
00198 {
00199   myEditCurrentArgument->setText("");
00200   QString aString = "";
00201 
00202   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00203   SALOME_ListIO aSelList;
00204   aSelMgr->selectedObjects(aSelList);
00205 
00206   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
00207 
00208   if (nbSel < 1) {
00209     myListShapes.length(0);
00210   }
00211 
00212   GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
00213   if (!myListShapes.length())
00214     return;
00215 
00216   myEditCurrentArgument->setText(aString);
00217   processPreview();
00218 }
00219 
00220 //=================================================================================
00221 // function : SetEditCurrentArgument()
00222 // purpose  :
00223 //=================================================================================
00224 void OperationGUI_GetSharedShapesDlg::SetEditCurrentArgument()
00225 {
00226   QPushButton* send = (QPushButton*)sender();
00227 
00228   if (send == GroupPoints->PushButton1) {
00229     myEditCurrentArgument = GroupPoints->LineEdit1;
00230     GroupPoints->LineEdit1->setEnabled(true);
00231   }
00232 
00233   globalSelection(GEOM_ALLSHAPES);
00234 
00235   myEditCurrentArgument->setFocus();
00236   SelectionIntoArgument();
00237   send->setDown(true);
00238 }
00239 
00240 //=================================================================================
00241 // function : ActivateThisDialog()
00242 // purpose  :
00243 //=================================================================================
00244 void OperationGUI_GetSharedShapesDlg::ActivateThisDialog()
00245 {
00246   GEOMBase_Skeleton::ActivateThisDialog();
00247   connect(myGeomGUI->getApp()->selectionMgr(),
00248           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00249 
00250   ConstructorsClicked(getConstructorId());
00251   processPreview();
00252 }
00253 
00254 //=================================================================================
00255 // function : enterEvent()
00256 // purpose  :
00257 //=================================================================================
00258 void OperationGUI_GetSharedShapesDlg::enterEvent(QEvent*)
00259 {
00260   if (!mainFrame()->GroupConstructors->isEnabled())
00261     this->ActivateThisDialog();
00262 }
00263 
00264 //=======================================================================
00265 //function : ComboTextChanged
00266 //purpose  :
00267 //=======================================================================
00268 void OperationGUI_GetSharedShapesDlg::ComboTextChanged()
00269 {
00270   //initName(getNewObjectName());
00271   initName(getPrefixByType());
00272   processPreview();
00273 }
00274 
00275 //=================================================================================
00276 // function : GetType()
00277 // purpose  :
00278 //=================================================================================
00279 int OperationGUI_GetSharedShapesDlg::GetType() const
00280 {
00281   int aLimit = GroupPoints->ComboBox1->currentIndex();
00282 
00283   switch (aLimit) {
00284   case 0:  aLimit = GEOM::SOLID ; break;
00285   case 1:  aLimit = GEOM::SHELL ; break;
00286   case 2:  aLimit = GEOM::FACE  ; break;
00287   case 3:  aLimit = GEOM::WIRE  ; break;
00288   case 4:  aLimit = GEOM::EDGE  ; break;
00289   case 5:  aLimit = GEOM::VERTEX; break;
00290   default: aLimit = GEOM::SHAPE ;
00291   }
00292 
00293   return aLimit;
00294 }
00295 
00296 //=================================================================================
00297 // function : createOperation
00298 // purpose  :
00299 //=================================================================================
00300 GEOM::GEOM_IOperations_ptr OperationGUI_GetSharedShapesDlg::createOperation()
00301 {
00302   return getGeomEngine()->GetIShapesOperations(getStudyId());
00303 }
00304 
00305 //=================================================================================
00306 // function : isValid
00307 // purpose  :
00308 //=================================================================================
00309 bool OperationGUI_GetSharedShapesDlg::isValid (QString& msg)
00310 {
00311   if (myListShapes.length() < 2) {
00312     msg = tr("MSG_SHARED_SHAPES_TOO_FEW_SHAPES");
00313     return false;
00314   }
00315   return true;
00316 }
00317 
00318 //=================================================================================
00319 // function : execute
00320 // purpose  :
00321 //=================================================================================
00322 bool OperationGUI_GetSharedShapesDlg::execute (ObjectList& objects)
00323 {
00324   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
00325   GEOM::ListOfGO_var aList = anOper->GetSharedShapesMulti(myListShapes, GetType());
00326 
00327   if (!aList->length())
00328     return false;
00329 
00330   if (aList->length() > 1)
00331     myMainFrame->ResultName->setText(getPrefixByType());
00332 
00333   for (int i = 0, n = aList->length(); i < n; i++)
00334     objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
00335 
00336   return objects.size();
00337 }
00338 
00339 //================================================================
00340 // Function : getFather
00341 // Purpose  : Get father object for object to be added in study
00342 //            ( called with addInStudy method )
00343 //================================================================
00344 GEOM::GEOM_Object_ptr OperationGUI_GetSharedShapesDlg::getFather (GEOM::GEOM_Object_ptr)
00345 {
00346   if (myListShapes.length() > 0)
00347     //return myListShapes[0]._retn();
00348     return myListShapes[0];
00349   return NULL;
00350 }
00351 
00352 //================================================================
00353 // Function : getPrefixByType
00354 // Purpose  :
00355 //================================================================
00356 QString OperationGUI_GetSharedShapesDlg::getPrefixByType () const
00357 {
00358   QString aPref;
00359 
00360   int aLimit = GroupPoints->ComboBox1->currentIndex();
00361 
00362   switch (aLimit) {
00363   case 0:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SOLID")) ; break;
00364   case 1:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHELL")) ; break;
00365   case 2:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_FACE"))  ; break;
00366   case 3:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_WIRE"))  ; break;
00367   case 4:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_EDGE"))  ; break;
00368   case 5:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_VERTEX")); break;
00369   default: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHAPE")) ;
00370   }
00371 
00372   return aPref;
00373 }