1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMBase_Skeleton.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "GEOMBase_Skeleton.h"
31 #include <GeometryGUI.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_DoubleSpinBox.h>
35 #include <SalomeApp_Study.h>
36 #include <LightApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
45 #include <QDoubleSpinBox>
47 //=================================================================================
48 // class : GEOMBase_Skeleton()
49 // purpose : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // true to construct a modal dialog.
53 //=================================================================================
54 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
55 bool modal, Qt::WindowFlags fl )
56 : QDialog( parent, fl ),
57 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
58 myGeomGUI( theGeometryGUI ),
61 setAttribute( Qt::WA_DeleteOnClose );
65 myMainFrame = new DlgRef_Skeleton( this );
66 QVBoxLayout* topLayout = new QVBoxLayout( this );
67 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
68 topLayout->addWidget( myMainFrame );
70 myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
71 myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
73 myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
74 myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
75 myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
77 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
78 buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
79 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
80 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
82 myRBGroup = new QButtonGroup( this );
83 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
84 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
85 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
86 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
87 myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
89 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
94 //=================================================================================
95 // function : ~GEOMBase_Skeleton()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 GEOMBase_Skeleton::~GEOMBase_Skeleton()
101 myGeomGUI->SetActiveDialogBox( 0 );
104 //=================================================================================
107 //=================================================================================
108 void GEOMBase_Skeleton::Init()
110 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
111 if ( !myGeomGUI && app )
112 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
116 myGeomGUI->SetActiveDialogBox( this );
118 /* signals and slots connections */
119 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
121 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
122 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
125 // connect help button on a private slot that displays help information
126 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
128 /* displays Dialog */
129 myMainFrame->RadioButton1->setChecked( true );
130 myMainFrame->RadioButton4->hide();
131 myMainFrame->RadioButton5->hide();
133 myMainFrame->CheckBoxRestoreSS->setChecked( false );
134 myMainFrame->CheckBoxAddPrefix->setChecked( true );
135 myMainFrame->GroupBoxPublish->hide();
138 //=================================================================================
139 // function : initSpinBox()
141 //=================================================================================
142 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
143 int min, int max, int step )
145 spinBox->setRange( min, max );
146 spinBox->setSingleStep( step );
149 //=================================================================================
150 // function : initSpinBox()
152 //=================================================================================
153 void GEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
154 double min, double max,
155 double step, const char* quantity )
157 // Obtain precision from preferences
158 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
159 int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
161 spinBox->setPrecision( aPrecision );
162 spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
163 // by default Qt rounds boundaries to 2 decimals at setRange
164 spinBox->setRange( min, max );
165 spinBox->setSingleStep( step );
167 // Add a hint for the user saying how to tune precision
168 QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
169 spinBox->setProperty( "validity_tune_hint",
170 QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
173 //=================================================================================
174 // function : updateAttributes()
175 // purpose : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
176 // In this case PublishInStudy isn't called, so we need to update object's attributes manually
177 //=================================================================================
178 void GEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
179 const QStringList& theParameters)
181 SALOMEDS::Study_var aStudy = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
182 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
183 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
184 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
185 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
187 std::string aValue = aStringAttrib->Value();
190 for( int i = 0, n = theParameters.count(); i < n; i++ ) {
191 std::string aParameter = theParameters[i].toStdString();
192 if(aStudy->IsVariable(aParameter.c_str()))
193 aValue += aParameter;
197 aStringAttrib->SetValue(aValue.c_str());
200 //=================================================================================
201 // function : ClickOnCancel()
203 //=================================================================================
204 void GEOMBase_Skeleton::ClickOnCancel()
209 //=================================================================================
210 // function : LineEditReturnPressed()
212 //=================================================================================
213 void GEOMBase_Skeleton::LineEditReturnPressed()
215 if (!myEditCurrentArgument)
218 /* User name of object input management */
219 /* If successfull the selection is changed and signal emitted... */
220 /* so SelectionIntoArgument() is automatically called. */
221 const QString objectUserName = myEditCurrentArgument->text();
222 QWidget* thisWidget = (QWidget*)this;
225 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
227 aSelMgr->selectedObjects(aList);
228 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
229 myEditCurrentArgument->setText(objectUserName);
232 //=================================================================================
233 // function : DeactivateActiveDialog()
235 //=================================================================================
236 void GEOMBase_Skeleton::DeactivateActiveDialog()
238 this->setEnabled( false );
241 myGeomGUI->SetActiveDialogBox( 0 );
242 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
247 //=================================================================================
248 // function : ActivateThisDialog()
250 //=================================================================================
251 void GEOMBase_Skeleton::ActivateThisDialog()
253 /* Emit a signal to deactivate the active dialog */
254 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
255 this->setEnabled( true );
256 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
260 //=================================================================================
261 // function : closeEvent()
262 // purpose : same than click on cancel button
263 //=================================================================================
264 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
267 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
268 myGeomGUI->getApp()->updateActions();
270 QDialog::closeEvent( e );
273 //=================================================================================
274 // function : initName()
275 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
276 //=================================================================================
277 void GEOMBase_Skeleton::initName( const QString& thePrefix )
279 if ( !thePrefix.isNull() )
280 setPrefix( thePrefix );
281 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
284 //=================================================================================
285 // function : getNewObjectName()
286 // purpose : returns contents of Name field
287 //=================================================================================
288 QString GEOMBase_Skeleton::getNewObjectName() const
290 return myMainFrame->ResultName->text();
293 //=================================================================================
294 // function : getConstructorId()
296 //=================================================================================
297 int GEOMBase_Skeleton::getConstructorId() const
300 return myRBGroup->checkedId();
304 //=================================================================================
305 // function : setConstructorId( id )
307 //=================================================================================
308 void GEOMBase_Skeleton::setConstructorId( const int id )
310 if ( myRBGroup && myRBGroup->button( id ) )
311 myRBGroup->button( id )->setChecked( true );
314 //=================================================================================
315 // function : unsetConstructorId
317 //=================================================================================
318 void GEOMBase_Skeleton::unsetConstructorId()
320 // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
321 // uncheck all buttons
322 // workaround, because setChecked( false ) does not result in Qt4
323 bool isExclusive = myRBGroup->exclusive();
324 myRBGroup->setExclusive( false );
325 QList<QAbstractButton*> btnList = myRBGroup->buttons();
326 for ( int j = 0; j < 2; j++ )
328 QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
329 for ( ; it != btnList.constEnd(); ++it )
330 (*it)->setCheckable( j == 1 );
332 myRBGroup->setExclusive( isExclusive );
335 //=================================================================================
336 // function : ClickOnHelp()
338 //=================================================================================
339 void GEOMBase_Skeleton::ClickOnHelp()
341 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
343 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
347 platform = "winapplication";
349 platform = "application";
351 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
352 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
353 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
354 QObject::tr( "BUT_OK" ) );
358 //=================================================================================
359 // function : setHelpFileName()
360 // purpose : set name for help file html
361 //=================================================================================
362 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
364 myHelpFileName = theName;
367 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
372 QWidget* GEOMBase_Skeleton::centralWidget()
374 return myMainFrame->GroupMedium;
377 QPushButton* GEOMBase_Skeleton::buttonCancel() const
379 return myMainFrame->buttonCancel;
382 QPushButton* GEOMBase_Skeleton::buttonOk() const
384 return myMainFrame->buttonOk;
387 QPushButton* GEOMBase_Skeleton::buttonApply() const
389 return myMainFrame->buttonApply;
392 QPushButton* GEOMBase_Skeleton::buttonHelp() const
394 return myMainFrame->buttonHelp;
397 //=================================================================================
398 // function : keyPressEvent()
400 //=================================================================================
401 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
403 QDialog::keyPressEvent( e );
404 if ( e->isAccepted() )
407 if ( e->key() == Qt::Key_F1 ) {