Back to index

salome-geom  6.5.0
OperationGUI_ArchimedeDlg.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   : OperationGUI_ArchimedeDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 //
00027 #include "OperationGUI_ArchimedeDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_Desktop.h>
00034 #include <SUIT_Session.h>
00035 #include <SUIT_ResourceMgr.h>
00036 #include <SalomeApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 
00039 //=================================================================================
00040 // class    : OperationGUI_ArchimedeDlg()
00041 // purpose  : Constructs a OperationGUI_ArchimedeDlg which is a child of 'parent', with the 
00042 //            name 'name' and widget flags set to 'f'.
00043 //            The dialog will by default be modeless, unless you set 'modal' to
00044 //            TRUE to construct a modal dialog.
00045 //=================================================================================
00046 OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
00047   : GEOMBase_Skeleton( theGeometryGUI, parent, false )
00048 {
00049   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ARCHIMEDE" ) ) );
00050   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00051   
00052   setWindowTitle( tr( "GEOM_ARCHIMEDE_TITLE" ) );
00053 
00054   /***************************************************************/
00055   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ARCHIMEDE" ) );
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_1Sel3Spin( centralWidget() );
00063   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00064   GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
00065   GroupPoints->TextLabel2->setText( tr( "GEOM_WEIGHT" ) );
00066   GroupPoints->TextLabel3->setText( tr( "GEOM_WATER_DENSITY" ) );
00067   GroupPoints->TextLabel4->setText( tr( "GEOM_MESHING_DEFLECTION" ) );
00068   GroupPoints->PushButton1->setIcon( image1 );
00069   GroupPoints->LineEdit1->setReadOnly( true );
00070 
00071   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00072   layout->setMargin( 0 ); layout->setSpacing( 6 );
00073   layout->addWidget( GroupPoints );
00074 
00075   /***************************************************************/
00076 
00077   setHelpFileName( "archimede_page.html" );
00078 
00079   /* Initialisations */
00080   Init();
00081 }
00082 
00083 
00084 //=================================================================================
00085 // function : ~OperationGUI_ArchimedeDlg()
00086 // purpose  : Destroys the object and frees any allocated resources
00087 //=================================================================================
00088 OperationGUI_ArchimedeDlg::~OperationGUI_ArchimedeDlg()
00089 {
00090   // no need to delete child widgets, Qt does it all for us
00091 }
00092 
00093 
00094 //=================================================================================
00095 // function : Init()
00096 // purpose  :
00097 //=================================================================================
00098 void OperationGUI_ArchimedeDlg::Init()
00099 {
00100   /* init variables */
00101   myEditCurrentArgument = GroupPoints->LineEdit1;
00102 
00103   /* Get setting of myStep value from file configuration */
00104   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00105   double myStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
00106 
00107   double SpecificStep1 = 0.1;
00108   double SpecificStep2 = 0.01;
00109   /* min, max, myStep and decimals for spin boxes & initial values */
00110   initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, myStep, "weight_precision" );
00111   initSpinBox( GroupPoints->SpinBox_DY, 0.001, COORD_MAX, SpecificStep1, "density_precision" );
00112   initSpinBox( GroupPoints->SpinBox_DZ, 0.001, COORD_MAX, SpecificStep2, "parametric_precision" );
00113 
00114   showOnlyPreviewControl();
00115 
00116   GroupPoints->SpinBox_DX->setValue( 100.0 );
00117   GroupPoints->SpinBox_DY->setValue( 1.0 );
00118   GroupPoints->SpinBox_DZ->setValue( 0.01 );
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->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
00125 
00126   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
00127   
00128   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00129            this, SLOT( SelectionIntoArgument() ) );
00130 
00131 
00132   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
00133   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
00134   connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
00135   
00136   initName( tr( "GEOM_ARCHIMEDE" ) );
00137   
00138   globalSelection( GEOM_ALLSHAPES );
00139 
00140   SelectionIntoArgument();
00141   resize(100,100);
00142 }
00143 
00144 
00145 //=================================================================================
00146 // function : SetDoubleSpinBoxStep()
00147 // purpose  : Double spin box management
00148 //=================================================================================
00149 void OperationGUI_ArchimedeDlg::SetDoubleSpinBoxStep( double step )
00150 {
00151   GroupPoints->SpinBox_DX->setSingleStep(step);
00152   
00153   // san: Commented so as not to override specific step settings
00154   //GroupPoints->SpinBox_DY->setSingleStep(step);
00155   //GroupPoints->SpinBox_DZ->setSingleStep(step);
00156 }
00157 
00158 //=================================================================================
00159 // function : ClickOnOk()
00160 // purpose  :
00161 //=================================================================================
00162 void OperationGUI_ArchimedeDlg::ClickOnOk()
00163 {
00164   setIsApplyAndClose( true );
00165   if ( ClickOnApply() )
00166     ClickOnCancel();
00167 }
00168 
00169 
00170 //=================================================================================
00171 // function : ClickOnApply()
00172 // purpose  :
00173 //=================================================================================
00174 bool OperationGUI_ArchimedeDlg::ClickOnApply()
00175 {
00176   if ( !onAccept() )
00177     return false;
00178 
00179   initName();
00180   return true;
00181 }
00182 
00183 //=================================================================================
00184 // function : SelectionIntoArgument()
00185 // purpose  : Called when selection as changed or other case
00186 //=================================================================================
00187 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
00188 {
00189   myEditCurrentArgument->setText("");
00190   myShape = GEOM::GEOM_Object::_nil();
00191 
00192   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00193   SALOME_ListIO aSelList;
00194   aSelMgr->selectedObjects(aSelList);
00195 
00196   if (aSelList.Extent() != 1)
00197     return;
00198 
00199   myShape = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00200 
00201   if ( !GEOMBase::IsShape(myShape) ) {
00202     myShape = GEOM::GEOM_Object::_nil();
00203     return;
00204   }
00205   myEditCurrentArgument->setText(GEOMBase::GetName(myShape));
00206   processPreview();
00207 }
00208 
00209 //=================================================================================
00210 // function : LineEditReturnPressed()
00211 // purpose  :
00212 //=================================================================================
00213 void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
00214 {
00215   QLineEdit* send = (QLineEdit*)sender();
00216   if ( send == GroupPoints->LineEdit1 )
00217     myEditCurrentArgument = GroupPoints->LineEdit1;
00218   else
00219     return;
00220 
00221   GEOMBase_Skeleton::LineEditReturnPressed();
00222 }
00223 
00224 //=================================================================================
00225 // function : ActivateThisDialog()
00226 // purpose  :
00227 //=================================================================================
00228 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
00229 {
00230   GEOMBase_Skeleton::ActivateThisDialog();
00231   globalSelection( GEOM_ALLSHAPES );
00232   connect( myGeomGUI->getApp()->selectionMgr(),
00233            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00234   processPreview();
00235 }
00236 
00237 
00238 //=================================================================================
00239 // function : enterEvent()
00240 // purpose  :
00241 //=================================================================================
00242 void OperationGUI_ArchimedeDlg::enterEvent( QEvent* )
00243 {
00244   if ( mainFrame()->GroupConstructors->isEnabled() )
00245     return;
00246   this->ActivateThisDialog();
00247 }
00248 
00249 
00250 //=================================================================================
00251 // function : createOperation
00252 // purpose  :
00253 //=================================================================================
00254 GEOM::GEOM_IOperations_ptr OperationGUI_ArchimedeDlg::createOperation()
00255 {
00256   return getGeomEngine()->GetILocalOperations( getStudyId() );
00257 }
00258 
00259 //=================================================================================
00260 // function : isValid
00261 // purpose  :
00262 //=================================================================================
00263 bool OperationGUI_ArchimedeDlg::isValid( QString& msg )
00264 {
00265   bool ok = true;
00266   ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
00267   ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
00268   ok = GroupPoints->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
00269   return !myShape->_is_nil() && ok;
00270 }
00271 
00272 //=================================================================================
00273 // function : execute
00274 // purpose  :
00275 //=================================================================================
00276 bool OperationGUI_ArchimedeDlg::execute( ObjectList& objects )
00277 {
00278   double aWeight         = GroupPoints->SpinBox_DX->value();
00279   double aWaterDensity   = GroupPoints->SpinBox_DY->value();
00280   double aMeshDeflection = GroupPoints->SpinBox_DZ->value();
00281   
00282   GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
00283   GEOM::GEOM_Object_var anObj = anOper->MakeArchimede( myShape, aWeight, aWaterDensity, aMeshDeflection );
00284 
00285   if ( !anObj->_is_nil() )
00286   {
00287     if ( !IsPreview() )
00288     {
00289       QStringList aParameters;
00290       aParameters << GroupPoints->SpinBox_DX->text();
00291       aParameters << GroupPoints->SpinBox_DY->text();
00292       aParameters << GroupPoints->SpinBox_DZ->text();
00293       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00294     }
00295     objects.push_back( anObj._retn() );
00296   }
00297 
00298   return true;
00299 }
00300 
00301 //=================================================================================
00302 // function : ValueChangedInSpinBox()
00303 // purpose  :
00304 //=================================================================================
00305 void OperationGUI_ArchimedeDlg::ValueChangedInSpinBox(double newValue)
00306 {
00307   processPreview();
00308 }