Back to index

salome-geom  6.5.0
TransformationGUI_OffsetDlg.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   : TransformationGUI_OffsetDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "TransformationGUI_OffsetDlg.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 //=================================================================================
00039 // class    : TransformationGUI_OffsetDlg()
00040 // purpose  : Constructs a TransformationGUI_OffsetDlg which is a child of 'parent', with the 
00041 //            name 'name' and widget flags set to 'f'.
00042 //            The dialog will by default be modeless, unless you set 'modal' to
00043 //            TRUE to construct a modal dialog.
00044 //=================================================================================
00045 TransformationGUI_OffsetDlg::TransformationGUI_OffsetDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00046                                                           bool modal, Qt::WindowFlags fl )
00047   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
00048 {
00049   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_OFFSET" ) ) );
00050   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00051 
00052   setWindowTitle( tr( "GEOM_OFFSET_TITLE" ) );
00053 
00054   /***************************************************************/
00055   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_OFFSET" ) );
00056   mainFrame()->RadioButton1->setIcon( image0 );
00057   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00058   mainFrame()->RadioButton2->close();
00059   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00060   mainFrame()->RadioButton3->close();
00061  
00062   GroupPoints = new DlgRef_1Sel1Spin1Check( centralWidget() );
00063   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00064   GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
00065   GroupPoints->TextLabel2->setText( tr( "GEOM_OFFSET" ) );
00066   GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
00067 
00068   // san -- modification of an exisitng object by offset is not allowed
00069   GroupPoints->CheckButton1->hide();
00070 
00071   GroupPoints->PushButton1->setIcon( image1 );
00072   
00073   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00074   layout->setMargin( 0 ); layout->setSpacing( 6 );
00075   layout->addWidget( GroupPoints );
00076   
00077   /***************************************************************/
00078 
00079   setHelpFileName( "offset_operation_page.html" );
00080   
00081   Init();
00082 }
00083 
00084 
00085 //=================================================================================
00086 // function : ~TransformationGUI_OffsetDlg()
00087 // purpose  : Destroys the object and frees any allocated resources
00088 //=================================================================================
00089 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
00090 {  
00091   /* no need to delete child widgets, Qt does it all for us */
00092 }
00093 
00094 
00095 //=================================================================================
00096 // function : Init()
00097 // purpose  :
00098 //=================================================================================
00099 void TransformationGUI_OffsetDlg::Init()
00100 {  
00101   /* init variables */
00102   myEditCurrentArgument = GroupPoints->LineEdit1;
00103   GroupPoints->LineEdit1->setReadOnly( true );
00104 
00105   myObjects.clear();
00106   
00107   /* Get setting of step value from file configuration */
00108   double step = 1;
00109    
00110   /* min, max, step and decimals for spin boxes & initial values */
00111   initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00112   GroupPoints->SpinBox_DX->setValue( 1e-05 );
00113   
00114   // Activate Create a Copy mode
00115   GroupPoints->CheckButton1->setChecked( true );
00116   CreateCopyModeChanged();
00117 
00118   mainFrame()->GroupBoxPublish->show();
00119 
00120   /* signals and slots connections */
00121   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00122   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00123   
00124   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
00125   connect( myGeomGUI->getApp()->selectionMgr(), 
00126            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00127 
00128   connect( GroupPoints->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
00129   connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ),        this, SLOT( CreateCopyModeChanged() ) );
00130   
00131   initName( tr( "GEOM_OFFSET" ) );
00132 
00133   globalSelection( GEOM_ALLSHAPES );
00134   resize(100,100);
00135   SelectionIntoArgument();
00136 }
00137 
00138 
00139 //=================================================================================
00140 // function : ClickOnOk()
00141 // purpose  :
00142 //=================================================================================
00143 void TransformationGUI_OffsetDlg::ClickOnOk()
00144 {
00145   setIsApplyAndClose( true );
00146   if ( ClickOnApply() )
00147     ClickOnCancel();
00148 }
00149 
00150 
00151 //=================================================================================
00152 // function : ClickOnApply()
00153 // purpose  :
00154 //=================================================================================
00155 bool TransformationGUI_OffsetDlg::ClickOnApply()
00156 {
00157   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
00158     return false;
00159   
00160   initName();
00161   return true;
00162 }
00163 
00164 
00165 //=================================================================================
00166 // function : SelectionIntoArgument()
00167 // purpose  : Called when selection has changed
00168 //=================================================================================
00169 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
00170 {
00171   myObjects = getSelected( TopAbs_SHAPE, -1 );
00172   if ( !myObjects.isEmpty() ) {
00173     QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
00174     myEditCurrentArgument->setText( aName );
00175   }
00176   else {
00177     myEditCurrentArgument->setText("");
00178   }
00179 
00180   processPreview();
00181 }
00182 
00183 
00184 //=================================================================================
00185 // function : SetEditCurrentArgument()
00186 // purpose  :
00187 //=================================================================================
00188 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
00189 {
00190   QPushButton* send = (QPushButton*)sender();
00191   
00192   if ( send == GroupPoints->PushButton1 ) {
00193     GroupPoints->PushButton1->setDown(true);
00194     myEditCurrentArgument = GroupPoints->LineEdit1;
00195     myEditCurrentArgument->setFocus();
00196     SelectionIntoArgument();
00197   }
00198 }
00199 
00200 
00201 //=================================================================================
00202 // function : enterEvent()
00203 // purpose  : when mouse enter onto the QWidget
00204 //=================================================================================
00205 void TransformationGUI_OffsetDlg::enterEvent( QEvent* )
00206 {
00207   if ( !mainFrame()->GroupConstructors->isEnabled() )
00208     ActivateThisDialog();
00209 }
00210 
00211 
00212 //=================================================================================
00213 // function : ActivateThisDialog()
00214 // purpose  :
00215 //=================================================================================
00216 void TransformationGUI_OffsetDlg::ActivateThisDialog()
00217 {
00218   GEOMBase_Skeleton::ActivateThisDialog();
00219   connect( myGeomGUI->getApp()->selectionMgr(), 
00220            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00221   globalSelection( GEOM_ALLSHAPES );
00222   myEditCurrentArgument = GroupPoints->LineEdit1;
00223   myEditCurrentArgument->setFocus();
00224 }
00225 
00226 
00227 //=================================================================================
00228 // function : ValueChangedInSpinBox()
00229 // purpose  :
00230 //=================================================================================
00231 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
00232 {
00233   processPreview();
00234 }
00235 
00236 
00237 //=================================================================================
00238 // function : createOperation
00239 // purpose  :
00240 //=================================================================================
00241 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
00242 {
00243   return getGeomEngine()->GetITransformOperations( getStudyId() );
00244 }
00245 
00246 //=================================================================================
00247 // function : isValid
00248 // purpose  :
00249 //=================================================================================
00250 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
00251 {
00252   bool ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myObjects.isEmpty();
00253   for ( int i = 0; i < myObjects.count() && ok; i++ ) {
00254     GEOM::shape_type aType = myObjects[i]->GetShapeType();
00255     ok = aType == GEOM::FACE || aType == GEOM::SHELL || aType == GEOM::SOLID;
00256     if ( !ok )
00257       msg = tr( "ERROR_SHAPE_TYPE" );
00258   }
00259   return ok;
00260 }
00261 
00262 //=================================================================================
00263 // function : execute
00264 // purpose  :
00265 //=================================================================================
00266 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
00267 {
00268   bool res = false;
00269   
00270   GEOM::GEOM_Object_var anObj;
00271   
00272   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
00273 
00274   if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
00275     for ( int i = 0; i < myObjects.count(); i++ ) {
00276       
00277       anObj = anOper->OffsetShapeCopy( myObjects[i].get(), GetOffset() );
00278       if ( !anObj->_is_nil() ) {
00279         if(!IsPreview()) {
00280           anObj->SetParameters(GroupPoints->SpinBox_DX->text().toLatin1().constData());
00281         }
00282         objects.push_back( anObj._retn() );
00283       }
00284     }
00285   }
00286   else {
00287     for ( int i = 0; i < myObjects.count(); i++ ) {
00288       anObj = anOper->OffsetShape( myObjects[i].get(), GetOffset() );
00289       if ( !anObj->_is_nil() )
00290         objects.push_back( anObj._retn() );
00291     }
00292   }
00293   res = true;
00294     
00295   return res;
00296 }
00297 
00298 //=================================================================================
00299 // function : restoreSubShapes
00300 // purpose  :
00301 //=================================================================================
00302 void TransformationGUI_OffsetDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
00303                                                     SALOMEDS::SObject_ptr theSObject )
00304 {
00305   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
00306     // empty list of arguments means that all arguments should be restored
00307     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
00308                                          /*theFindMethod=*/GEOM::FSM_Transformed,
00309                                          /*theInheritFirstArg=*/true,
00310                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
00311   }
00312 }
00313 
00314 //=================================================================================
00315 // function : GetOffset()
00316 // purpose  :
00317 //=================================================================================
00318 double TransformationGUI_OffsetDlg::GetOffset() const
00319 {
00320   return GroupPoints->SpinBox_DX->value();
00321 }
00322 
00323 //=================================================================================
00324 // function :  CreateCopyModeChanged()
00325 // purpose  :
00326 //=================================================================================
00327 void TransformationGUI_OffsetDlg::CreateCopyModeChanged()
00328 {
00329   mainFrame()->GroupBoxName->setEnabled( GroupPoints->CheckButton1->isChecked() );
00330 }