Back to index

salome-geom  6.5.0
BasicGUI_LineDlg.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   : BasicGUI_LineDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "BasicGUI_LineDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_ResourceMgr.h>
00034 #include <SUIT_Session.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 
00038 #include <TopoDS_Shape.hxx>
00039 #include <TopoDS.hxx>
00040 #include <TopExp.hxx>
00041 #include <TColStd_IndexedMapOfInteger.hxx>
00042 #include <TopTools_IndexedMapOfShape.hxx>
00043 
00044 #include <GEOMImpl_Types.hxx>
00045 
00046 //=================================================================================
00047 // class    : BasicGUI_LineDlg()
00048 // purpose  : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the 
00049 //            name 'name' and widget flags set to 'f'.
00050 //            The dialog will by default be modeless, unless you set 'modal' to
00051 //            TRUE to construct a modal dialog.
00052 //=================================================================================
00053 BasicGUI_LineDlg::BasicGUI_LineDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00054                                     bool modal, Qt::WindowFlags fl )
00055   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
00056 {
00057   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P" ) ) );
00058   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00059   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2F" ) ) );
00060 
00061   setWindowTitle( tr( "GEOM_LINE_TITLE" ) );
00062  
00063   /***************************************************************/
00064   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_LINE" ) );
00065   mainFrame()->RadioButton1->setIcon( image0 );
00066   mainFrame()->RadioButton2->setIcon( image2 );
00067   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00068   mainFrame()->RadioButton3->close();
00069 
00070   GroupPoints = new DlgRef_2Sel( centralWidget() );
00071 
00072   GroupPoints->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
00073   GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
00074   GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
00075   GroupPoints->PushButton1->setIcon( image1 );
00076   GroupPoints->PushButton2->setIcon( image1 );
00077   GroupPoints->LineEdit1->setReadOnly( true );
00078   GroupPoints->LineEdit2->setReadOnly( true );
00079   GroupPoints->LineEdit1->setEnabled( true );
00080   GroupPoints->LineEdit2->setEnabled( false );
00081 
00082   GroupFaces = new DlgRef_2Sel( centralWidget() );
00083   GroupFaces->GroupBox1->setTitle( tr( "GEOM_FACES" ) );
00084   GroupFaces->TextLabel1->setText( tr( "GEOM_FACE_I" ).arg( "1" ) );
00085   GroupFaces->TextLabel2->setText( tr( "GEOM_FACE_I" ).arg( "2" ) );
00086   GroupFaces->PushButton1->setIcon( image1 );
00087   GroupFaces->PushButton2->setIcon( image1 );
00088   GroupFaces->LineEdit1->setReadOnly( true );
00089   GroupFaces->LineEdit2->setReadOnly( true );
00090   GroupFaces->LineEdit1->setEnabled( true );
00091   GroupFaces->LineEdit2->setEnabled( false );
00092 
00093   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00094   layout->setMargin( 0 ); layout->setSpacing( 6 );
00095   layout->addWidget( GroupPoints );
00096   layout->addWidget( GroupFaces );
00097 
00098   /***************************************************************/
00099 
00100   setHelpFileName( "create_line_page.html" );
00101 
00102   Init();
00103 }
00104 
00105 
00106 //=================================================================================
00107 // function : ~BasicGUI_LineDlg()
00108 // purpose  : Destroys the object and frees any allocated resources
00109 //=================================================================================
00110 BasicGUI_LineDlg::~BasicGUI_LineDlg()
00111 {  
00112 }
00113 
00114 
00115 //=================================================================================
00116 // function : Init()
00117 // purpose  :
00118 //=================================================================================
00119 void BasicGUI_LineDlg::Init()
00120 {
00121   /* init variables */
00122   myEditCurrentArgument = GroupPoints->LineEdit1;
00123   myPoint1.nullify();
00124   myPoint2.nullify();
00125   myFace1.nullify();
00126   myFace2.nullify();
00127 
00128   GroupPoints->PushButton1->setDown(true);
00129         
00130   /* signals and slots connections */
00131   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00132   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00133 
00134   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
00135 
00136   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00137   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00138 
00139   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00140   connect( GroupPoints->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00141   connect( GroupFaces->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00142   connect( GroupFaces->PushButton2,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00143 
00144   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00145            this, SLOT( SelectionIntoArgument() ) );
00146   
00147   initName( tr( "GEOM_LINE" ) );
00148 
00149   ConstructorsClicked( 0 );
00150 }
00151 
00152 
00153 //=================================================================================
00154 // function : ClickOnOk()
00155 // purpose  :
00156 //=================================================================================
00157 void BasicGUI_LineDlg::ClickOnOk()
00158 {
00159   setIsApplyAndClose( true );
00160   if ( ClickOnApply() )
00161     ClickOnCancel();
00162 }
00163 
00164 //=================================================================================
00165 // function : ClickOnApply()
00166 // purpose  :
00167 //=================================================================================
00168 bool BasicGUI_LineDlg::ClickOnApply()
00169 {
00170   if ( !onAccept() )
00171     return false;
00172   
00173   initName();
00174 
00175   myEditCurrentArgument->setText( "" );
00176   ConstructorsClicked( getConstructorId() );
00177 
00178   return true;
00179 }
00180 
00181 //=================================================================================
00182 // function : ConstructorsClicked()
00183 // purpose  : Radio button management
00184 //=================================================================================
00185 void BasicGUI_LineDlg::ConstructorsClicked( int constructorId )
00186 {  
00187   switch ( constructorId ) {
00188   case 0:
00189     {
00190       myEditCurrentArgument = GroupPoints->LineEdit1;
00191       myEditCurrentArgument->setText( "" );
00192       GroupPoints->LineEdit2->setText( "" );
00193       myPoint1.nullify();
00194       myPoint2.nullify();
00195       GroupPoints->PushButton1->setDown(true);
00196       GroupPoints->PushButton2->setDown(false);
00197       GroupPoints->LineEdit1->setEnabled(true);
00198       GroupPoints->LineEdit2->setEnabled(false);
00199       GroupPoints->show();
00200       GroupFaces->hide();
00201       break;
00202     }
00203   case 1:
00204     {
00205       myEditCurrentArgument = GroupFaces->LineEdit1;
00206       myEditCurrentArgument->setText("");
00207       myFace1.nullify();
00208       myFace2.nullify();
00209       GroupFaces->PushButton1->setDown(true);
00210       GroupFaces->PushButton2->setDown(false);
00211       GroupFaces->LineEdit1->setEnabled(true);
00212       GroupFaces->LineEdit2->setEnabled(false);
00213       GroupPoints->hide();
00214       GroupFaces->show();
00215       break;
00216     }
00217   }
00218 
00219   TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
00220                              myEditCurrentArgument == GroupFaces->LineEdit2 ) ?
00221     TopAbs_FACE : TopAbs_VERTEX;
00222   globalSelection(); // close local selection to clear it
00223   localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
00224 
00225   qApp->processEvents();
00226   updateGeometry();
00227   resize( minimumSizeHint() );
00228   SelectionIntoArgument();
00229 }
00230 
00231 //=================================================================================
00232 // function : SelectionIntoArgument()
00233 // purpose  : Called when selection as changed or other case
00234 //=================================================================================
00235 void BasicGUI_LineDlg::SelectionIntoArgument()
00236 {
00237   myEditCurrentArgument->setText( "" );
00238 
00239   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00240   SALOME_ListIO aSelList;
00241   aSelMgr->selectedObjects(aSelList);
00242 
00243   if (aSelList.Extent() != 1) {
00244     if      (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint1.nullify();
00245     else if (myEditCurrentArgument == GroupPoints->LineEdit2) myPoint2.nullify();
00246     else if (myEditCurrentArgument == GroupFaces->LineEdit1)  myFace1.nullify();
00247     else if (myEditCurrentArgument == GroupFaces->LineEdit2)  myFace2.nullify();
00248     displayPreview(true);
00249     return;
00250   }
00251 
00252   TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
00253                              myEditCurrentArgument == GroupFaces->LineEdit2 ) ?
00254     TopAbs_FACE : TopAbs_VERTEX;
00255   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
00256   TopoDS_Shape aShape;
00257   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00258     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00259     myEditCurrentArgument->setText( aName );
00260     if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00261       myPoint1 = aSelectedObject;
00262       if ( myPoint1 && !myPoint2 )
00263         GroupPoints->PushButton2->click();
00264     }
00265     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
00266       myPoint2 = aSelectedObject;
00267       if ( myPoint2 && !myPoint1 )
00268         GroupPoints->PushButton1->click();
00269     }
00270     else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) {
00271       myFace1 = aSelectedObject;
00272       if ( myFace1 && !myFace2 )
00273         GroupFaces->PushButton2->click();
00274     }
00275     else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) {
00276       myFace2 = aSelectedObject;
00277       if ( myFace2 && !myFace1 )
00278         GroupFaces->PushButton1->click();      
00279     }
00280   }
00281   
00282   displayPreview(true);
00283 }
00284 
00285 //=================================================================================
00286 // function : SetEditCurrentArgument()
00287 // purpose  :
00288 //=================================================================================
00289 void BasicGUI_LineDlg::SetEditCurrentArgument()
00290 {
00291   QPushButton* send = (QPushButton*)sender();
00292   if ( send == GroupPoints->PushButton1 ) {
00293     myEditCurrentArgument = GroupPoints->LineEdit1;
00294     GroupPoints->PushButton2->setDown(false);
00295     GroupPoints->LineEdit1->setEnabled(true);
00296     GroupPoints->LineEdit2->setEnabled(false);
00297   }
00298   else if ( send == GroupPoints->PushButton2 ) {
00299     myEditCurrentArgument = GroupPoints->LineEdit2;
00300     GroupPoints->PushButton1->setDown(false);
00301     GroupPoints->LineEdit1->setEnabled(false);
00302     GroupPoints->LineEdit2->setEnabled(true);
00303   }
00304   else if ( send == GroupFaces->PushButton1 ) {
00305     myEditCurrentArgument = GroupFaces->LineEdit1;
00306     GroupFaces->PushButton2->setDown(false);
00307     GroupFaces->LineEdit1->setEnabled(true);
00308     GroupFaces->LineEdit2->setEnabled(false);
00309   }
00310   else if ( send == GroupFaces->PushButton2 ) {
00311     myEditCurrentArgument = GroupFaces->LineEdit2;
00312     GroupFaces->PushButton1->setDown(false);
00313     GroupFaces->LineEdit1->setEnabled(false);
00314     GroupFaces->LineEdit2->setEnabled(true);
00315   }
00316 
00317   TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
00318                              myEditCurrentArgument == GroupFaces->LineEdit2 ) ?
00319     TopAbs_FACE : TopAbs_VERTEX;
00320   globalSelection(); // close local selection to clear it
00321   localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
00322 
00323   myEditCurrentArgument->setFocus();
00324   //  SelectionIntoArgument();
00325   send->setDown(true);
00326   displayPreview(true);
00327 }
00328 
00329 //=================================================================================
00330 // function : ActivateThisDialog()
00331 // purpose  :
00332 //=================================================================================
00333 void BasicGUI_LineDlg::ActivateThisDialog()
00334 {
00335   GEOMBase_Skeleton::ActivateThisDialog();
00336   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00337            this, SLOT( SelectionIntoArgument() ) );
00338 
00339   ConstructorsClicked( getConstructorId() );
00340 }
00341 
00342 //=================================================================================
00343 // function : DeactivateActiveDialog()
00344 // purpose  : public slot to deactivate if active
00345 //=================================================================================
00346 void BasicGUI_LineDlg::DeactivateActiveDialog()
00347 {
00348   GEOMBase_Skeleton::DeactivateActiveDialog();
00349 }
00350 
00351 //=================================================================================
00352 // function : enterEvent()
00353 // purpose  :
00354 //=================================================================================
00355 void BasicGUI_LineDlg::enterEvent( QEvent* )
00356 {
00357   if ( !mainFrame()->GroupConstructors->isEnabled() )
00358     ActivateThisDialog();
00359 }
00360 
00361 //=================================================================================
00362 // function : createOperation
00363 // purpose  :
00364 //=================================================================================
00365 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
00366 {
00367   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
00368 }
00369 
00370 //=================================================================================
00371 // function : isValid
00372 // purpose  :
00373 //=================================================================================
00374 bool BasicGUI_LineDlg::isValid( QString& msg )
00375 {
00376   bool ok = false;
00377   switch ( getConstructorId() ) {
00378   case 0 :
00379     ok = myPoint1 && myPoint2;
00380     break;
00381   case 1:
00382     ok = myFace1 && myFace2;
00383     break;
00384   default:
00385     break;
00386   }
00387   return ok;
00388 }
00389 
00390 //=================================================================================
00391 // function : execute
00392 // purpose  :
00393 //=================================================================================
00394 bool BasicGUI_LineDlg::execute( ObjectList& objects )
00395 {
00396   bool res = false;
00397   GEOM::GEOM_Object_var anObj;
00398   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
00399   switch ( getConstructorId() ) {
00400   case 0 :
00401     anObj = anOper->MakeLineTwoPnt( myPoint1.get(), myPoint2.get() );
00402     res = true;
00403     break;
00404   case 1 :
00405     anObj = anOper->MakeLineTwoFaces( myFace1.get(), myFace2.get() );
00406     res = true;
00407     break;
00408   }
00409   
00410   if ( !anObj->_is_nil() )
00411     objects.push_back( anObj._retn() );
00412 
00413   return res;
00414 }
00415 
00416 //=================================================================================
00417 // function : addSubshapeToStudy
00418 // purpose  : virtual method to add new SubObjects if local selection
00419 //=================================================================================
00420 void BasicGUI_LineDlg::addSubshapesToStudy()
00421 {
00422   switch ( getConstructorId() ) {
00423   case 0 :
00424     GEOMBase::PublishSubObject( myPoint1.get() );
00425     GEOMBase::PublishSubObject( myPoint2.get() );
00426     break;
00427   case 1 :
00428     GEOMBase::PublishSubObject( myFace1.get() );
00429     GEOMBase::PublishSubObject( myFace2.get() );
00430     break;
00431   default:
00432     break;
00433   }
00434 }