Back to index

salome-geom  6.5.0
RepairGUI_ChangeOrientationDlg.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   : RepairGUI_ChangeOrientationDlg.cxx
00025 // Author : Sergey KUUL, Open CASCADE S.A.S. (sergey.kuul@opencascade.com)
00026 //
00027 #include "RepairGUI_ChangeOrientationDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SalomeApp_Application.h>
00034 #include <LightApp_SelectionMgr.h>
00035 #include <SUIT_Session.h>
00036 #include <SUIT_ResourceMgr.h>
00037 
00038 #include <GEOMImpl_Types.hxx>
00039 
00040 #include <TopAbs.hxx>
00041 
00042 //=================================================================================
00043 // class    : RepairGUI_ChangeOrientationDlg()
00044 // purpose  : Constructs a RepairGUI_ChangeOrientationDlg  which is a child of 'parent',
00045 //            with the name 'name' and widget flags set to 'f'.
00046 //            The dialog will by default be modeless, unless you set 'modal' to
00047 //            TRUE to construct a modal dialog.
00048 //=================================================================================
00049 RepairGUI_ChangeOrientationDlg::RepairGUI_ChangeOrientationDlg( GeometryGUI* theGeometryGUI,
00050                                                                 QWidget* parent,
00051                                                                 bool modal )
00052   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
00053 {
00054   //QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
00055   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CHANGE_ORIENTATION" ) ));
00056   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00057     
00058   setWindowTitle( tr( "GEOM_CHANGE_ORIENTATION_TITLE" ) );
00059 
00060   /***************************************************************/
00061   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHANGE_ORIENTATION_TITLE" ) );
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_1Sel1Check( centralWidget() );
00069   GroupPoints->GroupBox1->setTitle( tr( "GEOM_CHANGE_ORIENTATION" ) );
00070   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
00071   GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
00072   GroupPoints->PushButton1->setIcon( image1 );
00073 //  GroupPoints->LineEdit1->setReadOnly( true );
00074   
00075   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00076   layout->setMargin( 0 ); layout->setSpacing( 6 );
00077   layout->addWidget( GroupPoints );
00078 
00079   setHelpFileName( "change_orientation_operation_page.html" );
00080 
00081   Init();
00082 }
00083 
00084 
00085 //=================================================================================
00086 // function : ~RepairGUI_ChangeOrientationDlg()
00087 // purpose  : Destroys the object and frees any allocated resources
00088 //=================================================================================
00089 RepairGUI_ChangeOrientationDlg::~RepairGUI_ChangeOrientationDlg()
00090 {
00091 }
00092 
00093 
00094 //=================================================================================
00095 // function : Init()
00096 // purpose  :
00097 //=================================================================================
00098 void RepairGUI_ChangeOrientationDlg::Init()
00099 {
00100   /* init variables */
00101   myEditCurrentArgument = GroupPoints->LineEdit1;
00102 
00103   GroupPoints->CheckButton1->setChecked( true );
00104 
00105   myOkObject = false;
00106 
00107   /* signals and slots connections */
00108   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00109   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00110 
00111   connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00112   connect( GroupPoints->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
00113 
00114   connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
00115 
00116   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
00117            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00118 
00119   initName( tr( "CHANGE_ORIENTATION_NEW_OBJ_NAME" ) );
00120   resize(100,100);
00121   SelectionIntoArgument();
00122 }
00123 
00124 
00125 //=================================================================================
00126 // function : ClickOnOk()
00127 // purpose  : Same than click on apply but close this dialog.
00128 //=================================================================================
00129 void RepairGUI_ChangeOrientationDlg::ClickOnOk()
00130 {
00131   setIsApplyAndClose( true );
00132   if ( ClickOnApply() )
00133     ClickOnCancel();
00134 }
00135 
00136 
00137 //=================================================================================
00138 // function : ClickOnApply()
00139 // purpose  :
00140 //=================================================================================
00141 bool RepairGUI_ChangeOrientationDlg::ClickOnApply()
00142 {
00143 //  if ( !onAccept() )
00144   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
00145     return false;
00146 
00147   initName();
00148 
00149   myEditCurrentArgument->setText( "" );
00150   
00151   return true;
00152 }
00153 
00154 
00155 //=================================================================================
00156 // function : SelectionIntoArgument()
00157 // purpose  : Called when selection as changed or other case
00158 //=================================================================================
00159 void RepairGUI_ChangeOrientationDlg::SelectionIntoArgument()
00160 {
00161   myEditCurrentArgument->setText( "" );
00162   QString aName;
00163   
00164   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00165   SALOME_ListIO aSelList;
00166   aSelMgr->selectedObjects(aSelList);
00167 
00168   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00169     if ( aSelList.Extent() != 1 ) {
00170       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
00171         myOkObject = false;
00172       return;
00173     }
00174   }
00175 
00176   // nbSel == 1
00177   GEOM::GEOM_Object_ptr aSelectedObject =
00178     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00179   
00180   if ( CORBA::is_nil( aSelectedObject ) )
00181     return;
00182 
00183   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00184     myObject = aSelectedObject;
00185     myOkObject = true;
00186   }
00187 
00188   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
00189 }
00190 
00191 
00192 //=================================================================================
00193 // function : SetEditCurrentArgument()
00194 // purpose  :
00195 //=================================================================================
00196 void RepairGUI_ChangeOrientationDlg::SetEditCurrentArgument()
00197 {
00198   QPushButton* send = (QPushButton*)sender();
00199 
00200   if ( send == GroupPoints->PushButton1 ) {
00201     GroupPoints->LineEdit1->setFocus();
00202     myEditCurrentArgument = GroupPoints->LineEdit1;
00203   }
00204   SelectionIntoArgument();
00205 }
00206 
00207 
00208 //=================================================================================
00209 // function : LineEditReturnPressed()
00210 // purpose  :
00211 //=================================================================================
00212 void RepairGUI_ChangeOrientationDlg::LineEditReturnPressed()
00213 {
00214   QLineEdit* send = (QLineEdit*)sender();
00215   if ( send == GroupPoints->LineEdit1 ) {
00216     myEditCurrentArgument = GroupPoints->LineEdit1;
00217     GEOMBase_Skeleton::LineEditReturnPressed();
00218   }
00219 }
00220 
00221 
00222 //=================================================================================
00223 // function : ActivateThisDialog()
00224 // purpose  :
00225 //=================================================================================
00226 void RepairGUI_ChangeOrientationDlg::ActivateThisDialog()
00227 {
00228   GEOMBase_Skeleton::ActivateThisDialog();
00229   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
00230            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00231 }
00232 
00233 
00234 //=================================================================================
00235 // function : enterEvent()
00236 // purpose  : Mouse enter onto the dialog to activate it
00237 //=================================================================================
00238 void RepairGUI_ChangeOrientationDlg::enterEvent( QEvent* )
00239 {
00240   if ( !mainFrame()->GroupConstructors->isEnabled() )
00241     ActivateThisDialog();
00242 }
00243 
00244 
00245 //=================================================================================
00246 // function : createOperation
00247 // purpose  :
00248 //=================================================================================
00249 GEOM::GEOM_IOperations_ptr RepairGUI_ChangeOrientationDlg::createOperation()
00250 {
00251   return getGeomEngine()->GetIHealingOperations( getStudyId() );
00252 }
00253 
00254 
00255 //=================================================================================
00256 // function : isValid
00257 // purpose  :
00258 //=================================================================================
00259 bool RepairGUI_ChangeOrientationDlg::isValid( QString& )
00260 {
00261   return myOkObject;
00262 }
00263 
00264 
00265 //=================================================================================
00266 // function : execute
00267 // purpose  :
00268 //=================================================================================
00269 bool RepairGUI_ChangeOrientationDlg::execute( ObjectList& objects )
00270 {
00271   bool toCreateCopy = GroupPoints->CheckButton1->isChecked();
00272 
00273   GEOM::GEOM_Object_var anObj;
00274   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
00275   if ( toCreateCopy ) {
00276     anObj = anOper->ChangeOrientationCopy( myObject );
00277   }
00278   else {
00279     anObj = anOper->ChangeOrientation( myObject );
00280   }
00281 
00282   if ( !anObj->_is_nil() )
00283     objects.push_back( anObj._retn() );
00284 
00285   return true;
00286 }
00287 
00288 
00289 //=================================================================================
00290 // function :  CreateCopyModeChanged()
00291 // purpose  :
00292 //=================================================================================
00293 void RepairGUI_ChangeOrientationDlg::CreateCopyModeChanged( bool isCreateCopy )
00294 {
00295   mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
00296 }