1 // Copyright (C) 2007-2012 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOMBase_Skeleton.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "GEOMBase_Skeleton.h"
30 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <SalomeApp_DoubleSpinBox.h>
34 #include <SalomeApp_Study.h>
35 #include <LightApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
44 #include <QDoubleSpinBox>
46 //=================================================================================
47 // class : GEOMBase_Skeleton()
48 // purpose : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // true to construct a modal dialog.
52 //=================================================================================
53 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : QDialog( parent, fl ),
56 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
57 myGeomGUI( theGeometryGUI ),
60 setAttribute( Qt::WA_DeleteOnClose );
64 myMainFrame = new DlgRef_Skeleton( this );
65 QVBoxLayout* topLayout = new QVBoxLayout( this );
66 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
67 topLayout->addWidget( myMainFrame );
69 myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
70 myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
72 myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
73 myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
74 myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
75 myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
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 connect( myMainFrame->CheckBoxPreview, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
130 /* displays Dialog */
131 myMainFrame->RadioButton1->setChecked( true );
132 myMainFrame->RadioButton4->hide();
133 myMainFrame->RadioButton5->hide();
135 myMainFrame->CheckBoxRestoreSS->setChecked( false );
136 myMainFrame->CheckBoxAddPrefix->setChecked( true );
138 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
139 bool aPrv = (resMgr == 0) ? false : resMgr->booleanValue( "Geometry", "geom_preview", false );
141 myMainFrame->CheckBoxPreview->setChecked( aPrv );
142 myMainFrame->GroupBoxPublish->hide();
145 //=================================================================================
146 // function : initSpinBox()
148 //=================================================================================
149 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
150 int min, int max, int step )
152 spinBox->setRange( min, max );
153 spinBox->setSingleStep( step );
156 //=================================================================================
157 // function : initSpinBox()
159 //=================================================================================
160 void GEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
161 double min, double max,
162 double step, const char* quantity )
164 // Obtain precision from preferences
165 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
166 int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
168 spinBox->setPrecision( aPrecision );
169 spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
170 // by default Qt rounds boundaries to 2 decimals at setRange
171 spinBox->setRange( min, max );
172 spinBox->setSingleStep( step );
174 // Add a hint for the user saying how to tune precision
175 QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
176 spinBox->setProperty( "validity_tune_hint",
177 QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
180 //=================================================================================
181 // function : updateAttributes()
182 // purpose : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
183 // In this case PublishInStudy isn't called, so we need to update object's attributes manually
184 //=================================================================================
185 void GEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
186 const QStringList& theParameters)
188 SALOMEDS::Study_var aStudy = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
189 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
190 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
191 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
192 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
194 std::string aValue = aStringAttrib->Value();
197 for( int i = 0, n = theParameters.count(); i < n; i++ ) {
198 std::string aParameter = theParameters[i].toStdString();
199 if(aStudy->IsVariable(aParameter.c_str()))
200 aValue += aParameter;
204 aStringAttrib->SetValue(aValue.c_str());
207 //=================================================================================
208 // function : ClickOnCancel()
210 //=================================================================================
211 void GEOMBase_Skeleton::ClickOnCancel()
216 //=================================================================================
217 // function : LineEditReturnPressed()
219 //=================================================================================
220 void GEOMBase_Skeleton::LineEditReturnPressed()
222 if (!myEditCurrentArgument)
225 /* User name of object input management */
226 /* If successfull the selection is changed and signal emitted... */
227 /* so SelectionIntoArgument() is automatically called. */
228 const QString objectUserName = myEditCurrentArgument->text();
229 QWidget* thisWidget = (QWidget*)this;
232 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
234 aSelMgr->selectedObjects(aList);
235 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
236 myEditCurrentArgument->setText(objectUserName);
239 //=================================================================================
240 // function : DeactivateActiveDialog()
242 //=================================================================================
243 void GEOMBase_Skeleton::DeactivateActiveDialog()
245 this->setEnabled( false );
248 myGeomGUI->SetActiveDialogBox( 0 );
249 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
254 //=================================================================================
255 // function : ActivateThisDialog()
257 //=================================================================================
258 void GEOMBase_Skeleton::ActivateThisDialog()
260 /* Emit a signal to deactivate the active dialog */
261 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
262 this->setEnabled( true );
263 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
267 //=================================================================================
268 // function : closeEvent()
269 // purpose : same than click on cancel button
270 //=================================================================================
271 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
274 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
275 myGeomGUI->getApp()->updateActions();
277 QDialog::closeEvent( e );
280 //=================================================================================
281 // function : initName()
282 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
283 //=================================================================================
284 void GEOMBase_Skeleton::initName( const QString& thePrefix )
286 if ( !thePrefix.isNull() )
287 setPrefix( thePrefix );
288 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
291 //=================================================================================
292 // function : getNewObjectName()
293 // purpose : returns contents of Name field
294 //=================================================================================
295 QString GEOMBase_Skeleton::getNewObjectName (int) const
297 return myMainFrame->ResultName->text();
300 //=================================================================================
301 // function : getConstructorId()
303 //=================================================================================
304 int GEOMBase_Skeleton::getConstructorId() const
307 return myRBGroup->checkedId();
311 //=================================================================================
312 // function : setConstructorId( id )
314 //=================================================================================
315 void GEOMBase_Skeleton::setConstructorId( const int id )
317 if ( myRBGroup && myRBGroup->button( id ) )
318 myRBGroup->button( id )->setChecked( true );
321 //=================================================================================
322 // function : unsetConstructorId
324 //=================================================================================
325 void GEOMBase_Skeleton::unsetConstructorId()
327 // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
328 // uncheck all buttons
329 // workaround, because setChecked( false ) does not result in Qt4
330 bool isExclusive = myRBGroup->exclusive();
331 myRBGroup->setExclusive( false );
332 QList<QAbstractButton*> btnList = myRBGroup->buttons();
333 for ( int j = 0; j < 2; j++ )
335 QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
336 for ( ; it != btnList.constEnd(); ++it )
337 (*it)->setCheckable( j == 1 );
339 myRBGroup->setExclusive( isExclusive );
342 //=================================================================================
343 // function : ClickOnHelp()
345 //=================================================================================
346 void GEOMBase_Skeleton::ClickOnHelp()
348 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
350 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
354 platform = "winapplication";
356 platform = "application";
358 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
359 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
360 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
361 QObject::tr( "BUT_OK" ) );
365 //=================================================================================
366 // function : setHelpFileName()
367 // purpose : set name for help file html
368 //=================================================================================
369 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
371 myHelpFileName = theName;
374 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
379 QWidget* GEOMBase_Skeleton::centralWidget()
381 return myMainFrame->GroupMedium;
384 QPushButton* GEOMBase_Skeleton::buttonCancel() const
386 return myMainFrame->buttonCancel;
389 QPushButton* GEOMBase_Skeleton::buttonOk() const
391 return myMainFrame->buttonOk;
394 QPushButton* GEOMBase_Skeleton::buttonApply() const
396 return myMainFrame->buttonApply;
399 QPushButton* GEOMBase_Skeleton::buttonHelp() const
401 return myMainFrame->buttonHelp;
404 //=================================================================================
405 // function : keyPressEvent()
407 //=================================================================================
408 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
410 QDialog::keyPressEvent( e );
411 if ( e->isAccepted() )
414 if ( e->key() == Qt::Key_F1 ) {
420 //=================================================================================
421 // function : showOnlyPreviewControl()
422 // purpose : display only CheckBoxPreview check box,
423 // hide CheckBoxRestoreSS and CheckBoxAddPrefix
424 //=================================================================================
425 void GEOMBase_Skeleton::showOnlyPreviewControl(){
426 mainFrame()->GroupBoxPublish->show();
427 mainFrame()->CheckBoxRestoreSS->hide();
428 mainFrame()->CheckBoxAddPrefix->hide();
431 //=================================================================================
432 // function : processPreview()
433 // purpose : Display preview if CheckBoxPreview is checked
434 //=================================================================================
435 void GEOMBase_Skeleton::processPreview() {
436 displayPreview(mainFrame()->CheckBoxPreview->isChecked());