1 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MyGEOMBase_Skeleton.hxx"
22 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
24 #include "MyDlgRef.hxx"
25 #include <GeometryGUI.h>
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_DoubleSpinBox.h>
29 #include <SalomeApp_Study.h>
30 #include <LightApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_MessageBox.h>
39 #include <QDoubleSpinBox>
41 //=================================================================================
42 // class : MyGEOMBase_Skeleton()
43 // purpose : Constructs a MyGEOMBase_Skeleton which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // true to construct a modal dialog.
47 //=================================================================================
48 MyGEOMBase_Skeleton::MyGEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
49 bool modal, Qt::WindowFlags fl )
50 : QDialog( parent, fl ),
51 MyGEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
52 myGeomGUI( theGeometryGUI ),
55 // setAttribute( Qt::WA_DeleteOnClose );
59 myMainFrame = new MyDlgRef_Skeleton( this );
60 QVBoxLayout* topLayout = new QVBoxLayout( this );
61 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
62 topLayout->addWidget( myMainFrame );
64 myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
65 myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
67 myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
68 myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
69 myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
70 myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
72 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
73 //buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
74 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
75 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
77 myRBGroup = new QButtonGroup( this );
78 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
79 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
80 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
81 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
82 myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
84 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
89 //=================================================================================
90 // function : ~MyGEOMBase_Skeleton()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 MyGEOMBase_Skeleton::~MyGEOMBase_Skeleton()
96 myGeomGUI->SetActiveDialogBox( 0 );
99 //=================================================================================
102 //=================================================================================
103 void MyGEOMBase_Skeleton::Init()
105 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
106 if ( !myGeomGUI && app )
107 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
111 myGeomGUI->SetActiveDialogBox( this );
113 /* signals and slots connections */
114 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( close() ) );
116 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
117 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( close() ) );
120 // connect help button on a private slot that displays help information
121 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
123 connect( myMainFrame->CheckBoxPreview, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
125 /* displays Dialog */
126 myMainFrame->RadioButton1->setChecked( true );
127 myMainFrame->RadioButton4->hide();
128 myMainFrame->RadioButton5->hide();
130 myMainFrame->CheckBoxRestoreSS->setChecked( false );
131 myMainFrame->CheckBoxAddPrefix->setChecked( true );
133 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
134 bool aPrv = (resMgr == 0) ? false : resMgr->booleanValue( "Geometry", "geom_preview", false );
136 myMainFrame->CheckBoxPreview->setChecked( aPrv );
137 myMainFrame->GroupBoxPublish->hide();
140 //=================================================================================
141 // function : initSpinBox()
143 //=================================================================================
144 void MyGEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
145 int min, int max, int step )
147 spinBox->setRange( min, max );
148 spinBox->setSingleStep( step );
151 //=================================================================================
152 // function : initSpinBox()
154 //=================================================================================
155 void MyGEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
156 double min, double max,
157 double step, const char* quantity )
159 // Obtain precision from preferences
160 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
161 int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
163 spinBox->setPrecision( aPrecision );
164 spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
165 // by default Qt rounds boundaries to 2 decimals at setRange
166 spinBox->setRange( min, max );
167 spinBox->setSingleStep( step );
169 // Add a hint for the user saying how to tune precision
170 QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
171 spinBox->setProperty( "validity_tune_hint",
172 QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
175 //=================================================================================
176 // function : updateAttributes()
177 // purpose : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
178 // In this case PublishInStudy isn't called, so we need to update object's attributes manually
179 //=================================================================================
180 void MyGEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
181 const QStringList& theParameters)
183 SALOMEDS::Study_var aStudy = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
184 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
185 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
186 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
187 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
189 std::string aValue = aStringAttrib->Value();
192 for( int i = 0, n = theParameters.count(); i < n; i++ ) {
193 std::string aParameter = theParameters[i].toStdString();
194 if(aStudy->IsVariable(aParameter.c_str()))
195 aValue += aParameter;
199 aStringAttrib->SetValue(aValue.c_str());
203 // ========================================================================== close
204 // function : close()
205 // purpose : close the dockwidget
206 //=================================================================================
207 void MyGEOMBase_Skeleton::close()
209 // _currentObj = NULL;
211 //Clear VTK selection //no need to test if the graphic view exist
212 HEXABLOCKGUI::currentDocGView->clearSelection();
214 //Clear OCC selection
215 if (HEXABLOCKGUI::currentOccGView != NULL)
216 HEXABLOCKGUI::currentOccGView->clearSelection();
218 //Close the dialog box
219 if (parentWidget()) parentWidget()->close();
222 //=================================================================================
223 // function : LineEditReturnPressed()
225 //=================================================================================
226 void MyGEOMBase_Skeleton::LineEditReturnPressed()
228 if (!myEditCurrentArgument)
231 /* User name of object input management */
232 /* If successfull the selection is changed and signal emitted... */
233 /* so SelectionIntoArgument() is automatically called. */
234 const QString objectUserName = myEditCurrentArgument->text();
235 QWidget* thisWidget = (QWidget*)this;
238 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
240 aSelMgr->selectedObjects(aList);
241 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
242 myEditCurrentArgument->setText(objectUserName);
245 //=================================================================================
246 // function : DeactivateActiveDialog()
248 //=================================================================================
249 void MyGEOMBase_Skeleton::DeactivateActiveDialog()
251 this->setEnabled( false );
252 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow());
254 myGeomGUI->SetActiveDialogBox( 0 );
255 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
260 //=================================================================================
261 // function : ActivateThisDialog()
263 //=================================================================================
264 void MyGEOMBase_Skeleton::ActivateThisDialog()
266 /* Emit a signal to deactivate the active dialog */
267 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
268 this->setEnabled( true );
269 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
273 //=================================================================================
274 // function : closeEvent()
275 // purpose : same than click on cancel button
276 //=================================================================================
277 void MyGEOMBase_Skeleton::closeEvent( QCloseEvent* e )
280 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
281 myGeomGUI->getApp()->updateActions();
283 QDialog::closeEvent( e );
286 //=================================================================================
287 // function : initName()
288 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
289 //=================================================================================
290 void MyGEOMBase_Skeleton::initName( const QString& thePrefix )
292 if ( !thePrefix.isNull() )
293 setPrefix( thePrefix );
294 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
297 //=================================================================================
298 // function : getNewObjectName()
299 // purpose : returns contents of Name field
300 //=================================================================================
301 QString MyGEOMBase_Skeleton::getNewObjectName() const
303 return myMainFrame->ResultName->text();
306 //=================================================================================
307 // function : getConstructorId()
309 //=================================================================================
310 int MyGEOMBase_Skeleton::getConstructorId() const
313 return myRBGroup->checkedId();
317 //=================================================================================
318 // function : setConstructorId( id )
320 //=================================================================================
321 void MyGEOMBase_Skeleton::setConstructorId( const int id )
323 if ( myRBGroup && myRBGroup->button( id ) )
324 myRBGroup->button( id )->setChecked( true );
327 //=================================================================================
328 // function : unsetConstructorId
330 //=================================================================================
331 void MyGEOMBase_Skeleton::unsetConstructorId()
333 // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
334 // uncheck all buttons
335 // workaround, because setChecked( false ) does not result in Qt4
336 bool isExclusive = myRBGroup->exclusive();
337 myRBGroup->setExclusive( false );
338 QList<QAbstractButton*> btnList = myRBGroup->buttons();
339 for ( int j = 0; j < 2; j++ )
341 QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
342 for ( ; it != btnList.constEnd(); ++it )
343 (*it)->setCheckable( j == 1 );
345 myRBGroup->setExclusive( isExclusive );
348 //=================================================================================
349 // function : ClickOnHelp()
351 //=================================================================================
352 void MyGEOMBase_Skeleton::ClickOnHelp()
354 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
356 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
360 platform = "winapplication";
362 platform = "application";
364 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
365 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
366 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
367 QObject::tr( "BUT_OK" ) );
371 //=================================================================================
372 // function : setHelpFileName()
373 // purpose : set name for help file html
374 //=================================================================================
375 void MyGEOMBase_Skeleton::setHelpFileName( const QString& theName )
377 myHelpFileName = theName;
380 MyDlgRef_Skeleton* MyGEOMBase_Skeleton::mainFrame()
385 QWidget* MyGEOMBase_Skeleton::centralWidget()
387 return myMainFrame->GroupMedium;
390 QPushButton* MyGEOMBase_Skeleton::buttonCancel() const
392 return myMainFrame->buttonCancel;
395 /*QPushButton* MyGEOMBase_Skeleton::buttonOk() const
397 return myMainFrame->buttonOk;
400 QPushButton* MyGEOMBase_Skeleton::buttonApply() const
402 return myMainFrame->buttonApply;
405 QPushButton* MyGEOMBase_Skeleton::buttonHelp() const
407 return myMainFrame->buttonHelp;
410 //=================================================================================
411 // function : keyPressEvent()
413 //=================================================================================
414 void MyGEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
416 QDialog::keyPressEvent( e );
417 if ( e->isAccepted() )
420 if ( e->key() == Qt::Key_F1 ) {
427 //=================================================================================
428 // function : showOnlyPreviewControl()
429 // purpose : display only CheckBoxPreview check box,
430 // hide CheckBoxRestoreSS and CheckBoxAddPrefix
431 //=================================================================================
432 void MyGEOMBase_Skeleton::showOnlyPreviewControl(){
433 mainFrame()->GroupBoxPublish->show();
434 mainFrame()->CheckBoxRestoreSS->hide();
435 mainFrame()->CheckBoxAddPrefix->hide();
438 //=================================================================================
439 // function : processPreview()
440 // purpose : Display preview if CheckBoxPreview is checked
441 //=================================================================================
442 void MyGEOMBase_Skeleton::processPreview() {
443 displayPreview(mainFrame()->CheckBoxPreview->isChecked());