Back to index

salome-geom  6.5.0
GEOMBase_Skeleton.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   : GEOMBase_Skeleton.cxx
00025 // Author : Damien COQUERET, Open CASCADE S.A.S.
00026 //
00027 #include "GEOMBase_Skeleton.h"
00028 #include "GEOMBase.h"
00029 
00030 #include <DlgRef.h>
00031 #include <GeometryGUI.h>
00032 
00033 #include <SalomeApp_Application.h>
00034 #include <SalomeApp_DoubleSpinBox.h>
00035 #include <SalomeApp_Study.h>
00036 #include <LightApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 #include <SUIT_Desktop.h>
00039 #include <SUIT_ResourceMgr.h>
00040 #include <SUIT_Session.h>
00041 #include <SUIT_MessageBox.h>
00042 
00043 #include <QKeyEvent>
00044 #include <QSpinBox>
00045 #include <QDoubleSpinBox>
00046 
00047 //=================================================================================
00048 // class    : GEOMBase_Skeleton()
00049 // purpose  : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the 
00050 //            name 'name' and widget flags set to 'f'.
00051 //            The dialog will by default be modeless, unless you set 'modal' to
00052 //            true to construct a modal dialog.
00053 //=================================================================================
00054 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
00055                                       bool modal, Qt::WindowFlags fl )
00056   : QDialog( parent, fl ), 
00057     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
00058     myGeomGUI( theGeometryGUI ),
00059     myRBGroup( 0 )
00060 {
00061   setAttribute( Qt::WA_DeleteOnClose );
00062 
00063   setModal( modal );
00064 
00065   myMainFrame = new DlgRef_Skeleton( this );
00066   QVBoxLayout* topLayout = new QVBoxLayout( this );
00067   topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
00068   topLayout->addWidget( myMainFrame );
00069 
00070   myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
00071   myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
00072 
00073   myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
00074   myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
00075   myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
00076   myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
00077 
00078   buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
00079   buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
00080   buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
00081   buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
00082 
00083   myRBGroup = new QButtonGroup( this );
00084   myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
00085   myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
00086   myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
00087   myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
00088   myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
00089 
00090   connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
00091 
00092   Init();
00093 }
00094 
00095 //=================================================================================
00096 // function : ~GEOMBase_Skeleton()
00097 // purpose  : Destroys the object and frees any allocated resources
00098 //=================================================================================
00099 GEOMBase_Skeleton::~GEOMBase_Skeleton()
00100 {
00101   if ( myGeomGUI )
00102     myGeomGUI->SetActiveDialogBox( 0 );
00103 }
00104 
00105 //=================================================================================
00106 // function : Init()
00107 // purpose  :
00108 //=================================================================================
00109 void GEOMBase_Skeleton::Init()
00110 {
00111   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
00112   if ( !myGeomGUI && app )
00113     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
00114 
00115   /* init variables */
00116   if ( myGeomGUI )
00117     myGeomGUI->SetActiveDialogBox( this );
00118 
00119   /* signals and slots connections */
00120   connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
00121   if ( myGeomGUI ) {
00122     connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00123     connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00124   }
00125 
00126   // connect help button on a private slot that displays help information
00127   connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
00128 
00129   connect( myMainFrame->CheckBoxPreview, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
00130 
00131   /* displays Dialog */
00132   myMainFrame->RadioButton1->setChecked( true );
00133   myMainFrame->RadioButton4->hide();
00134   myMainFrame->RadioButton5->hide();
00135 
00136   myMainFrame->CheckBoxRestoreSS->setChecked( false );
00137   myMainFrame->CheckBoxAddPrefix->setChecked( true );
00138 
00139   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00140   bool aPrv = (resMgr == 0) ? false : resMgr->booleanValue( "Geometry", "geom_preview", false );
00141   
00142   myMainFrame->CheckBoxPreview->setChecked( aPrv );
00143   myMainFrame->GroupBoxPublish->hide();
00144 }
00145 
00146 //=================================================================================
00147 // function : initSpinBox()
00148 // purpose  : 
00149 //=================================================================================
00150 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox, 
00151                                      int min,  int max, int step )
00152 {
00153   spinBox->setRange( min, max );
00154   spinBox->setSingleStep( step );
00155 }
00156 
00157 //=================================================================================
00158 // function : initSpinBox()
00159 // purpose  : 
00160 //=================================================================================
00161 void GEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox, 
00162                                      double min,  double max, 
00163                                      double step, const char* quantity )
00164 {
00165   // Obtain precision from preferences
00166   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00167   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
00168   
00169   spinBox->setPrecision( aPrecision );
00170   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
00171                                     // by default Qt rounds boundaries to 2 decimals at setRange
00172   spinBox->setRange( min, max );
00173   spinBox->setSingleStep( step );
00174   
00175   // Add a hint for the user saying how to tune precision
00176   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
00177   spinBox->setProperty( "validity_tune_hint", 
00178                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
00179 }
00180 
00181 //=================================================================================
00182 // function : updateAttributes()
00183 // purpose  : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
00184 //            In this case PublishInStudy isn't called, so we need to update object's attributes manually
00185 //=================================================================================
00186 void GEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
00187                                           const QStringList& theParameters)
00188 {
00189   SALOMEDS::Study_var aStudy = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
00190   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
00191   SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
00192   SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
00193   SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
00194 
00195   std::string aValue = aStringAttrib->Value();
00196   if( aValue != "" )
00197     aValue += "|";
00198   for( int i = 0, n = theParameters.count(); i < n; i++ ) {
00199     std::string aParameter = theParameters[i].toStdString();
00200     if(aStudy->IsVariable(aParameter.c_str()))
00201       aValue += aParameter;
00202     if(i != n-1)
00203       aValue += ":";
00204   }
00205   aStringAttrib->SetValue(aValue.c_str());
00206 }
00207 
00208 //=================================================================================
00209 // function : ClickOnCancel()
00210 // purpose  :
00211 //=================================================================================
00212 void GEOMBase_Skeleton::ClickOnCancel()
00213 {
00214   close();
00215 }
00216 
00217 //=================================================================================
00218 // function : LineEditReturnPressed()
00219 // purpose  :
00220 //=================================================================================
00221 void GEOMBase_Skeleton::LineEditReturnPressed()
00222 {
00223   if (!myEditCurrentArgument)
00224     return;
00225 
00226   /* User name of object input management                          */
00227   /* If successfull the selection is changed and signal emitted... */
00228   /* so SelectionIntoArgument() is automatically called.           */
00229   const QString objectUserName = myEditCurrentArgument->text();
00230   QWidget* thisWidget = (QWidget*)this;
00231 
00232   SALOME_ListIO aList;
00233   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00234   if (aSelMgr)
00235     aSelMgr->selectedObjects(aList);
00236   if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
00237     myEditCurrentArgument->setText(objectUserName);
00238 }
00239 
00240 //=================================================================================
00241 // function : DeactivateActiveDialog()
00242 // purpose  :
00243 //=================================================================================
00244 void GEOMBase_Skeleton::DeactivateActiveDialog()
00245 {
00246   this->setEnabled( false );
00247   globalSelection();
00248   if ( myGeomGUI ) {
00249     myGeomGUI->SetActiveDialogBox( 0 );
00250     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
00251   }
00252   erasePreview();
00253 }
00254 
00255 //=================================================================================
00256 // function : ActivateThisDialog()
00257 // purpose  :
00258 //=================================================================================
00259 void GEOMBase_Skeleton::ActivateThisDialog()
00260 {
00261   /* Emit a signal to deactivate the active dialog */
00262   if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
00263   this->setEnabled( true );
00264   if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
00265   return;
00266 }
00267 
00268 //=================================================================================
00269 // function : closeEvent()
00270 // purpose  : same than click on cancel button
00271 //=================================================================================
00272 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
00273 {
00274   if ( myGeomGUI ) {
00275     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
00276     myGeomGUI->getApp()->updateActions();
00277   }
00278   QDialog::closeEvent( e );
00279 }
00280 
00281 //=================================================================================
00282 // function : initName()
00283 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
00284 //=================================================================================
00285 void GEOMBase_Skeleton::initName( const QString& thePrefix )
00286 {
00287   if ( !thePrefix.isNull() )
00288     setPrefix( thePrefix );
00289   myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
00290 }
00291 
00292 //=================================================================================
00293 // function : getNewObjectName()
00294 // purpose  : returns contents of Name field
00295 //=================================================================================
00296 QString GEOMBase_Skeleton::getNewObjectName() const
00297 {
00298   return myMainFrame->ResultName->text();
00299 }
00300 
00301 //=================================================================================
00302 // function : getConstructorId()
00303 // purpose  :
00304 //=================================================================================
00305 int GEOMBase_Skeleton::getConstructorId() const
00306 {
00307   if ( myRBGroup )
00308     return myRBGroup->checkedId();
00309   return -1;
00310 }
00311 
00312 //=================================================================================
00313 // function : setConstructorId( id )
00314 // purpose  :
00315 //=================================================================================
00316 void GEOMBase_Skeleton::setConstructorId( const int id )
00317 {
00318   if ( myRBGroup && myRBGroup->button( id ) )
00319     myRBGroup->button( id )->setChecked( true );
00320 }
00321 
00322 //=================================================================================
00323 // function : unsetConstructorId
00324 // purpose  :
00325 //=================================================================================
00326 void GEOMBase_Skeleton::unsetConstructorId()
00327 {
00328   // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
00329   // uncheck all buttons
00330   // workaround, because setChecked( false ) does not result in Qt4
00331   bool isExclusive = myRBGroup->exclusive();
00332   myRBGroup->setExclusive( false );
00333   QList<QAbstractButton*> btnList = myRBGroup->buttons();
00334   for ( int j = 0; j < 2; j++ )
00335   {
00336     QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
00337     for ( ; it != btnList.constEnd(); ++it )
00338       (*it)->setCheckable( j == 1 );
00339   }
00340   myRBGroup->setExclusive( isExclusive );
00341 }
00342 
00343 //=================================================================================
00344 // function : ClickOnHelp()
00345 // purpose  :
00346 //=================================================================================
00347 void GEOMBase_Skeleton::ClickOnHelp()
00348 {
00349   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
00350   if ( app ) 
00351     app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
00352   else {
00353     QString platform;
00354 #ifdef WIN32
00355     platform = "winapplication";
00356 #else
00357     platform = "application";
00358 #endif
00359     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
00360                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
00361                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
00362                               QObject::tr( "BUT_OK" ) );
00363   }
00364 }
00365 
00366 //=================================================================================
00367 //  function : setHelpFileName()
00368 //  purpose  : set name for help file html
00369 //=================================================================================
00370 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
00371 {
00372   myHelpFileName = theName;
00373 }
00374 
00375 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
00376 {
00377   return myMainFrame;
00378 }
00379 
00380 QWidget* GEOMBase_Skeleton::centralWidget()
00381 {
00382   return myMainFrame->GroupMedium;
00383 }
00384 
00385 QPushButton* GEOMBase_Skeleton::buttonCancel() const
00386 {
00387   return myMainFrame->buttonCancel;
00388 }
00389 
00390 QPushButton* GEOMBase_Skeleton::buttonOk() const
00391 {
00392   return myMainFrame->buttonOk;
00393 }
00394 
00395 QPushButton* GEOMBase_Skeleton::buttonApply() const
00396 {
00397   return myMainFrame->buttonApply;
00398 }
00399 
00400 QPushButton* GEOMBase_Skeleton::buttonHelp() const
00401 {
00402   return myMainFrame->buttonHelp;
00403 }
00404 
00405 //=================================================================================
00406 // function : keyPressEvent()
00407 // purpose  :
00408 //=================================================================================
00409 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
00410 {
00411   QDialog::keyPressEvent( e );
00412   if ( e->isAccepted() )
00413     return;
00414 
00415   if ( e->key() == Qt::Key_F1 ) {
00416     e->accept();
00417     ClickOnHelp();
00418   }
00419 }
00420 
00421 //=================================================================================
00422 // function : showOnlyPreviewControl()
00423 // purpose  : display only CheckBoxPreview check box,
00424 //            hide CheckBoxRestoreSS and CheckBoxAddPrefix 
00425 //=================================================================================
00426 void GEOMBase_Skeleton::showOnlyPreviewControl(){
00427   mainFrame()->GroupBoxPublish->show();
00428   mainFrame()->CheckBoxRestoreSS->hide();
00429   mainFrame()->CheckBoxAddPrefix->hide();
00430 }
00431 
00432 //=================================================================================
00433 // function : processPreview()
00434 // purpose  : Display preview if CheckBoxPreview is checked
00435 //=================================================================================
00436 void GEOMBase_Skeleton::processPreview() {
00437   displayPreview(mainFrame()->CheckBoxPreview->isChecked());
00438 }