1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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"
28 #include "GEOMBase_DlgSkeleton.h"
32 #include <GeometryGUI.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_DoubleSpinBox.h>
36 #include <SalomeApp_Study.h>
37 #include <LightApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_MessageBox.h>
46 #include <QDoubleSpinBox>
48 //=================================================================================
49 // class : GEOMBase_Skeleton()
50 // purpose : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // true to construct a modal dialog.
54 //=================================================================================
55 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl )
57 : QDialog( parent, fl ),
58 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
59 myGeomGUI( theGeometryGUI ),
62 setAttribute( Qt::WA_DeleteOnClose );
66 myMainFrame = new GEOMBase_DlgSkeleton( this );
67 QVBoxLayout* topLayout = new QVBoxLayout( this );
68 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
69 topLayout->addWidget( myMainFrame );
71 myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
72 myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
74 myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
75 myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
76 myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
77 myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
79 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
80 buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
81 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
82 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
84 myRBGroup = new QButtonGroup( this );
85 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
86 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
87 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
88 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
89 myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
91 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
96 //=================================================================================
97 // function : ~GEOMBase_Skeleton()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 GEOMBase_Skeleton::~GEOMBase_Skeleton()
103 myGeomGUI->SetActiveDialogBox( 0 );
106 //=================================================================================
109 //=================================================================================
110 void GEOMBase_Skeleton::Init()
112 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
113 if ( !myGeomGUI && app )
114 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
118 myGeomGUI->SetActiveDialogBox( this );
120 /* signals and slots connections */
121 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
123 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
124 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
127 // connect help button on a private slot that displays help information
128 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
130 connect( myMainFrame->CheckBoxPreview, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
132 /* displays Dialog */
133 myMainFrame->RadioButton1->setChecked( true );
134 myMainFrame->RadioButton4->hide();
135 myMainFrame->RadioButton5->hide();
137 myMainFrame->CheckBoxRestoreSS->setChecked( false );
138 myMainFrame->CheckBoxAddPrefix->setChecked( true );
140 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
141 bool aPrv = (resMgr == 0) ? false : resMgr->booleanValue( "Geometry", "geom_preview", false );
143 myMainFrame->CheckBoxPreview->setChecked( aPrv );
144 myMainFrame->GroupBoxPublish->hide();
147 //=================================================================================
148 // function : initSpinBox()
150 //=================================================================================
151 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
152 int min, int max, int step )
154 spinBox->setRange( min, max );
155 spinBox->setSingleStep( step );
158 //=================================================================================
159 // function : initSpinBox()
161 //=================================================================================
162 void GEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
163 double min, double max,
164 double step, const char* quantity )
166 // Obtain precision from preferences
167 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
168 int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
170 spinBox->setPrecision( aPrecision );
171 spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
172 // by default Qt rounds boundaries to 2 decimals at setRange
173 spinBox->setRange( min, max );
174 spinBox->setSingleStep( step );
176 // Add a hint for the user saying how to tune precision
177 QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
178 spinBox->setProperty( "validity_tune_hint",
179 QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
182 //=================================================================================
183 // function : updateAttributes()
184 // purpose : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
185 // In this case PublishInStudy isn't called, so we need to update object's attributes manually
186 //=================================================================================
187 void GEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
188 const QStringList& theParameters)
190 SALOMEDS::Study_var aStudy = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
191 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
192 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
193 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
194 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
196 std::string aValue = aStringAttrib->Value();
199 for( int i = 0, n = theParameters.count(); i < n; i++ ) {
200 std::string aParameter = theParameters[i].toStdString();
201 if(aStudy->IsVariable(aParameter.c_str()))
202 aValue += aParameter;
206 aStringAttrib->SetValue(aValue.c_str());
209 //=================================================================================
210 // function : ClickOnCancel()
212 //=================================================================================
213 void GEOMBase_Skeleton::ClickOnCancel()
218 //=================================================================================
219 // function : LineEditReturnPressed()
221 //=================================================================================
222 void GEOMBase_Skeleton::LineEditReturnPressed()
224 if (!myEditCurrentArgument)
227 /* User name of object input management */
228 /* If successfull the selection is changed and signal emitted... */
229 /* so SelectionIntoArgument() is automatically called. */
230 const QString objectUserName = myEditCurrentArgument->text();
231 QWidget* thisWidget = (QWidget*)this;
234 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
236 aSelMgr->selectedObjects(aList);
237 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
238 myEditCurrentArgument->setText(objectUserName);
241 //=================================================================================
242 // function : DeactivateActiveDialog()
244 //=================================================================================
245 void GEOMBase_Skeleton::DeactivateActiveDialog()
247 this->setEnabled( false );
250 myGeomGUI->SetActiveDialogBox( 0 );
251 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
256 //=================================================================================
257 // function : ActivateThisDialog()
259 //=================================================================================
260 void GEOMBase_Skeleton::ActivateThisDialog()
262 /* Emit a signal to deactivate the active dialog */
263 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
264 this->setEnabled( true );
265 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
269 //=================================================================================
270 // function : closeEvent()
271 // purpose : same than click on cancel button
272 //=================================================================================
273 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
276 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
277 myGeomGUI->getApp()->updateActions();
279 QDialog::closeEvent( e );
282 //=================================================================================
283 // function : initName()
284 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
285 //=================================================================================
286 void GEOMBase_Skeleton::initName( const QString& thePrefix )
288 if ( !thePrefix.isNull() )
289 setPrefix( thePrefix );
290 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
293 //=================================================================================
294 // function : getNewObjectName()
295 // purpose : returns contents of Name field
296 //=================================================================================
297 QString GEOMBase_Skeleton::getNewObjectName (int) const
299 return myMainFrame->ResultName->text();
302 //=================================================================================
303 // function : getConstructorId()
305 //=================================================================================
306 int GEOMBase_Skeleton::getConstructorId() const
309 return myRBGroup->checkedId();
313 //=================================================================================
314 // function : setConstructorId( id )
316 //=================================================================================
317 void GEOMBase_Skeleton::setConstructorId( const int id )
319 if ( myRBGroup && myRBGroup->button( id ) )
320 myRBGroup->button( id )->setChecked( true );
323 //=================================================================================
324 // function : unsetConstructorId
326 //=================================================================================
327 void GEOMBase_Skeleton::unsetConstructorId()
329 // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
330 // uncheck all buttons
331 // workaround, because setChecked( false ) does not result in Qt4
332 bool isExclusive = myRBGroup->exclusive();
333 myRBGroup->setExclusive( false );
334 QList<QAbstractButton*> btnList = myRBGroup->buttons();
335 for ( int j = 0; j < 2; j++ )
337 QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
338 for ( ; it != btnList.constEnd(); ++it )
339 (*it)->setCheckable( j == 1 );
341 myRBGroup->setExclusive( isExclusive );
344 //=================================================================================
345 // function : ClickOnHelp()
347 //=================================================================================
348 void GEOMBase_Skeleton::ClickOnHelp()
350 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
353 if(myHelpContext.isEmpty()) {
354 context = myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString("");
356 context = myHelpContext;
359 app->onHelpContextModule( context , myHelpFileName );
363 platform = "winapplication";
365 platform = "application";
367 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
368 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
369 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
370 QObject::tr( "BUT_OK" ) );
374 //=================================================================================
375 // function : setHelpFileName()
376 // purpose : set name for help file html
377 //=================================================================================
378 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
380 myHelpFileName = theName;
383 GEOMBase_DlgSkeleton* GEOMBase_Skeleton::mainFrame()
388 QWidget* GEOMBase_Skeleton::centralWidget()
390 return myMainFrame->GroupMedium;
393 QPushButton* GEOMBase_Skeleton::buttonCancel() const
395 return myMainFrame->buttonCancel;
398 QPushButton* GEOMBase_Skeleton::buttonOk() const
400 return myMainFrame->buttonOk;
403 QPushButton* GEOMBase_Skeleton::buttonApply() const
405 return myMainFrame->buttonApply;
408 QPushButton* GEOMBase_Skeleton::buttonHelp() const
410 return myMainFrame->buttonHelp;
413 //=================================================================================
414 // function : keyPressEvent()
416 //=================================================================================
417 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
419 QDialog::keyPressEvent( e );
420 if ( e->isAccepted() )
423 if ( e->key() == Qt::Key_F1 ) {
429 //=================================================================================
430 // function : showOnlyPreviewControl()
431 // purpose : display only CheckBoxPreview check box,
432 // hide CheckBoxRestoreSS and CheckBoxAddPrefix
433 //=================================================================================
434 void GEOMBase_Skeleton::showOnlyPreviewControl(){
435 mainFrame()->GroupBoxPublish->show();
436 mainFrame()->CheckBoxRestoreSS->hide();
437 mainFrame()->CheckBoxAddPrefix->hide();
440 //=================================================================================
441 // function : processPreview()
442 // purpose : Display preview if CheckBoxPreview is checked
443 //=================================================================================
444 void GEOMBase_Skeleton::processPreview() {
445 displayPreview(mainFrame()->CheckBoxPreview->isChecked());