1 // Copyright (C) 2007-2011 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" ) );
76 myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
78 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
79 buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
80 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
81 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
83 myRBGroup = new QButtonGroup( this );
84 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
85 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
86 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
87 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
88 myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
90 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
95 //=================================================================================
96 // function : ~GEOMBase_Skeleton()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 GEOMBase_Skeleton::~GEOMBase_Skeleton()
102 myGeomGUI->SetActiveDialogBox( 0 );
105 //=================================================================================
108 //=================================================================================
109 void GEOMBase_Skeleton::Init()
111 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
112 if ( !myGeomGUI && app )
113 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
117 myGeomGUI->SetActiveDialogBox( this );
119 /* signals and slots connections */
120 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
122 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
123 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
126 // connect help button on a private slot that displays help information
127 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
129 connect( myMainFrame->CheckBoxPreview, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
131 /* displays Dialog */
132 myMainFrame->RadioButton1->setChecked( true );
133 myMainFrame->RadioButton4->hide();
134 myMainFrame->RadioButton5->hide();
136 myMainFrame->CheckBoxRestoreSS->setChecked( false );
137 myMainFrame->CheckBoxAddPrefix->setChecked( true );
139 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
140 bool aPrv = (resMgr == 0) ? false : resMgr->booleanValue( "Geometry", "geom_preview", false );
142 myMainFrame->CheckBoxPreview->setChecked( aPrv );
143 myMainFrame->GroupBoxPublish->hide();
146 //=================================================================================
147 // function : initSpinBox()
149 //=================================================================================
150 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
151 int min, int max, int step )
153 spinBox->setRange( min, max );
154 spinBox->setSingleStep( step );
157 //=================================================================================
158 // function : initSpinBox()
160 //=================================================================================
161 void GEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
162 double min, double max,
163 double step, const char* quantity )
165 // Obtain precision from preferences
166 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
167 int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
169 spinBox->setPrecision( aPrecision );
170 spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
171 // by default Qt rounds boundaries to 2 decimals at setRange
172 spinBox->setRange( min, max );
173 spinBox->setSingleStep( step );
175 // Add a hint for the user saying how to tune precision
176 QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
177 spinBox->setProperty( "validity_tune_hint",
178 QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
181 //=================================================================================
182 // function : updateAttributes()
183 // purpose : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
184 // In this case PublishInStudy isn't called, so we need to update object's attributes manually
185 //=================================================================================
186 void GEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
187 const QStringList& theParameters)
189 SALOMEDS::Study_var aStudy = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
190 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
191 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
192 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
193 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
195 std::string aValue = aStringAttrib->Value();
198 for( int i = 0, n = theParameters.count(); i < n; i++ ) {
199 std::string aParameter = theParameters[i].toStdString();
200 if(aStudy->IsVariable(aParameter.c_str()))
201 aValue += aParameter;
205 aStringAttrib->SetValue(aValue.c_str());
208 //=================================================================================
209 // function : ClickOnCancel()
211 //=================================================================================
212 void GEOMBase_Skeleton::ClickOnCancel()
217 //=================================================================================
218 // function : LineEditReturnPressed()
220 //=================================================================================
221 void GEOMBase_Skeleton::LineEditReturnPressed()
223 if (!myEditCurrentArgument)
226 /* User name of object input management */
227 /* If successfull the selection is changed and signal emitted... */
228 /* so SelectionIntoArgument() is automatically called. */
229 const QString objectUserName = myEditCurrentArgument->text();
230 QWidget* thisWidget = (QWidget*)this;
233 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
235 aSelMgr->selectedObjects(aList);
236 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
237 myEditCurrentArgument->setText(objectUserName);
240 //=================================================================================
241 // function : DeactivateActiveDialog()
243 //=================================================================================
244 void GEOMBase_Skeleton::DeactivateActiveDialog()
246 this->setEnabled( false );
249 myGeomGUI->SetActiveDialogBox( 0 );
250 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
255 //=================================================================================
256 // function : ActivateThisDialog()
258 //=================================================================================
259 void GEOMBase_Skeleton::ActivateThisDialog()
261 /* Emit a signal to deactivate the active dialog */
262 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
263 this->setEnabled( true );
264 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
268 //=================================================================================
269 // function : closeEvent()
270 // purpose : same than click on cancel button
271 //=================================================================================
272 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
275 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
276 myGeomGUI->getApp()->updateActions();
278 QDialog::closeEvent( e );
281 //=================================================================================
282 // function : initName()
283 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
284 //=================================================================================
285 void GEOMBase_Skeleton::initName( const QString& thePrefix )
287 if ( !thePrefix.isNull() )
288 setPrefix( thePrefix );
289 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
292 //=================================================================================
293 // function : getNewObjectName()
294 // purpose : returns contents of Name field
295 //=================================================================================
296 QString GEOMBase_Skeleton::getNewObjectName() const
298 return myMainFrame->ResultName->text();
301 //=================================================================================
302 // function : getConstructorId()
304 //=================================================================================
305 int GEOMBase_Skeleton::getConstructorId() const
308 return myRBGroup->checkedId();
312 //=================================================================================
313 // function : setConstructorId( id )
315 //=================================================================================
316 void GEOMBase_Skeleton::setConstructorId( const int id )
318 if ( myRBGroup && myRBGroup->button( id ) )
319 myRBGroup->button( id )->setChecked( true );
322 //=================================================================================
323 // function : unsetConstructorId
325 //=================================================================================
326 void GEOMBase_Skeleton::unsetConstructorId()
328 // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
329 // uncheck all buttons
330 // workaround, because setChecked( false ) does not result in Qt4
331 bool isExclusive = myRBGroup->exclusive();
332 myRBGroup->setExclusive( false );
333 QList<QAbstractButton*> btnList = myRBGroup->buttons();
334 for ( int j = 0; j < 2; j++ )
336 QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
337 for ( ; it != btnList.constEnd(); ++it )
338 (*it)->setCheckable( j == 1 );
340 myRBGroup->setExclusive( isExclusive );
343 //=================================================================================
344 // function : ClickOnHelp()
346 //=================================================================================
347 void GEOMBase_Skeleton::ClickOnHelp()
349 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
351 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
355 platform = "winapplication";
357 platform = "application";
359 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
360 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
361 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
362 QObject::tr( "BUT_OK" ) );
366 //=================================================================================
367 // function : setHelpFileName()
368 // purpose : set name for help file html
369 //=================================================================================
370 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
372 myHelpFileName = theName;
375 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
380 QWidget* GEOMBase_Skeleton::centralWidget()
382 return myMainFrame->GroupMedium;
385 QPushButton* GEOMBase_Skeleton::buttonCancel() const
387 return myMainFrame->buttonCancel;
390 QPushButton* GEOMBase_Skeleton::buttonOk() const
392 return myMainFrame->buttonOk;
395 QPushButton* GEOMBase_Skeleton::buttonApply() const
397 return myMainFrame->buttonApply;
400 QPushButton* GEOMBase_Skeleton::buttonHelp() const
402 return myMainFrame->buttonHelp;
405 //=================================================================================
406 // function : keyPressEvent()
408 //=================================================================================
409 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
411 QDialog::keyPressEvent( e );
412 if ( e->isAccepted() )
415 if ( e->key() == Qt::Key_F1 ) {
421 //=================================================================================
422 // function : showOnlyPreviewControl()
423 // purpose : display only CheckBoxPreview check box,
424 // hide CheckBoxRestoreSS and CheckBoxAddPrefix
425 //=================================================================================
426 void GEOMBase_Skeleton::showOnlyPreviewControl(){
427 mainFrame()->GroupBoxPublish->show();
428 mainFrame()->CheckBoxRestoreSS->hide();
429 mainFrame()->CheckBoxAddPrefix->hide();
432 //=================================================================================
433 // function : processPreview()
434 // purpose : Display preview if CheckBoxPreview is checked
435 //=================================================================================
436 void GEOMBase_Skeleton::processPreview() {
437 displayPreview(mainFrame()->CheckBoxPreview->isChecked());