1 // Copyright (C) 2007-2022 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>
47 #include <QButtonGroup>
49 //=================================================================================
50 // class : GEOMBase_Skeleton()
51 // purpose : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // true to construct a modal dialog.
55 //=================================================================================
56 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
57 bool modal, Qt::WindowFlags fl )
58 : QDialog( parent, fl ),
59 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
60 myGeomGUI( theGeometryGUI ),
63 setAttribute( Qt::WA_DeleteOnClose );
67 myMainFrame = new GEOMBase_DlgSkeleton( this );
68 QVBoxLayout* topLayout = new QVBoxLayout( this );
69 topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
70 topLayout->addWidget( myMainFrame );
72 myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
73 myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
75 myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
76 myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
77 myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
78 myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
80 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
81 buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
82 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
83 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
85 myRBGroup = new QButtonGroup( this );
86 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
87 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
88 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
89 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
90 myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
92 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
97 //=================================================================================
98 // function : ~GEOMBase_Skeleton()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 GEOMBase_Skeleton::~GEOMBase_Skeleton()
104 myGeomGUI->SetActiveDialogBox( 0 );
107 //=================================================================================
110 //=================================================================================
111 void GEOMBase_Skeleton::Init()
113 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
114 if ( !myGeomGUI && app )
115 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
119 myGeomGUI->SetActiveDialogBox( this );
121 /* signals and slots connections */
122 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
124 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
125 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
128 // connect help button on a private slot that displays help information
129 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
131 connect( myMainFrame->CheckBoxPreview, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
133 /* displays Dialog */
134 myMainFrame->RadioButton1->setChecked( true );
135 myMainFrame->RadioButton4->hide();
136 myMainFrame->RadioButton5->hide();
138 myMainFrame->CheckBoxRestoreSS->setChecked( false );
139 myMainFrame->CheckBoxAddPrefix->setChecked( true );
141 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
142 bool aPrv = (resMgr == 0) ? false : resMgr->booleanValue( "Geometry", "geom_preview", false );
144 myMainFrame->CheckBoxPreview->setChecked( aPrv );
145 myMainFrame->GroupBoxPublish->hide();
148 //=================================================================================
149 // function : initSpinBox()
151 //=================================================================================
152 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
153 int min, int max, int step )
155 spinBox->setRange( min, max );
156 spinBox->setSingleStep( step );
159 //=================================================================================
160 // function : initSpinBox()
162 //=================================================================================
163 void GEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
164 double min, double max,
165 double step, const char* quantity )
167 // Obtain precision from preferences
168 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
169 int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
171 spinBox->setPrecision( aPrecision );
172 spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
173 // by default Qt rounds boundaries to 2 decimals at setRange
174 spinBox->setRange( min, max );
175 spinBox->setSingleStep( step );
177 // Add a hint for the user saying how to tune precision
178 QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
179 spinBox->setProperty( "validity_tune_hint",
180 QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
183 //=================================================================================
184 // function : updateAttributes()
185 // purpose : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
186 // In this case PublishInStudy isn't called, so we need to update object's attributes manually
187 //=================================================================================
188 void GEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
189 const QStringList& theParameters)
191 SALOMEDS::Study_var aStudy = GeometryGUI::getStudyServant();
192 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
193 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
194 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
195 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
197 std::string aValue = aStringAttrib->Value();
200 for( int i = 0, n = theParameters.count(); i < n; i++ ) {
201 std::string aParameter = theParameters[i].toStdString();
202 if(aStudy->IsVariable(aParameter.c_str()))
203 aValue += aParameter;
207 aStringAttrib->SetValue(aValue.c_str());
210 //=================================================================================
211 // function : ClickOnCancel()
213 //=================================================================================
214 void GEOMBase_Skeleton::ClickOnCancel()
219 //=================================================================================
220 // function : LineEditReturnPressed()
222 //=================================================================================
223 void GEOMBase_Skeleton::LineEditReturnPressed()
225 if (!myEditCurrentArgument)
228 /* User name of object input management */
229 /* If successful the selection is changed and signal emitted... */
230 /* so SelectionIntoArgument() is automatically called. */
231 const QString objectUserName = myEditCurrentArgument->text();
232 QWidget* thisWidget = (QWidget*)this;
235 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
237 aSelMgr->selectedObjects(aList);
238 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
239 myEditCurrentArgument->setText(objectUserName);
242 //=================================================================================
243 // function : DeactivateActiveDialog()
245 //=================================================================================
246 void GEOMBase_Skeleton::DeactivateActiveDialog()
248 this->setEnabled( false );
251 myGeomGUI->SetActiveDialogBox( 0 );
252 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
257 //=================================================================================
258 // function : ActivateThisDialog()
260 //=================================================================================
261 void GEOMBase_Skeleton::ActivateThisDialog()
263 /* Emit a signal to deactivate the active dialog */
264 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
265 this->setEnabled( true );
266 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
270 //=================================================================================
271 // function : closeEvent()
272 // purpose : same than click on cancel button
273 //=================================================================================
274 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
277 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
278 myGeomGUI->getApp()->updateActions();
280 QDialog::closeEvent( e );
283 //=================================================================================
284 // function : initName()
285 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
286 //=================================================================================
287 void GEOMBase_Skeleton::initName( const QString& thePrefix )
289 if ( !thePrefix.isNull() )
290 setPrefix( thePrefix );
291 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
294 //=================================================================================
295 // function : getNewObjectName()
296 // purpose : returns contents of Name field
297 //=================================================================================
298 QString GEOMBase_Skeleton::getNewObjectName (int) const
300 return myMainFrame->ResultName->text();
303 //=================================================================================
304 // function : getConstructorId()
306 //=================================================================================
307 int GEOMBase_Skeleton::getConstructorId() const
310 return myRBGroup->checkedId();
314 //=================================================================================
315 // function : setConstructorId( id )
317 //=================================================================================
318 void GEOMBase_Skeleton::setConstructorId( const int id )
320 if ( myRBGroup && myRBGroup->button( id ) )
321 myRBGroup->button( id )->setChecked( true );
324 //=================================================================================
325 // function : unsetConstructorId
327 //=================================================================================
328 void GEOMBase_Skeleton::unsetConstructorId()
330 // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
331 // uncheck all buttons
332 // workaround, because setChecked( false ) does not result in Qt4
333 bool isExclusive = myRBGroup->exclusive();
334 myRBGroup->setExclusive( false );
335 QList<QAbstractButton*> btnList = myRBGroup->buttons();
336 for ( int j = 0; j < 2; j++ )
338 QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
339 for ( ; it != btnList.constEnd(); ++it )
340 (*it)->setCheckable( j == 1 );
342 myRBGroup->setExclusive( isExclusive );
345 //=================================================================================
346 // function : ClickOnHelp()
348 //=================================================================================
349 void GEOMBase_Skeleton::ClickOnHelp()
351 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
354 if(myHelpContext.isEmpty()) {
355 context = myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString("");
357 context = myHelpContext;
360 app->onHelpContextModule( context , myHelpFileName );
364 platform = "winapplication";
366 platform = "application";
368 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
369 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
370 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
371 QObject::tr( "BUT_OK" ) );
375 //=================================================================================
376 // function : setHelpFileName()
377 // purpose : set name for help file html
378 //=================================================================================
379 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
381 myHelpFileName = theName;
384 GEOMBase_DlgSkeleton* GEOMBase_Skeleton::mainFrame()
389 QWidget* GEOMBase_Skeleton::centralWidget()
391 return myMainFrame->GroupMedium;
394 QPushButton* GEOMBase_Skeleton::buttonCancel() const
396 return myMainFrame->buttonCancel;
399 QPushButton* GEOMBase_Skeleton::buttonOk() const
401 return myMainFrame->buttonOk;
404 QPushButton* GEOMBase_Skeleton::buttonApply() const
406 return myMainFrame->buttonApply;
409 QPushButton* GEOMBase_Skeleton::buttonHelp() const
411 return myMainFrame->buttonHelp;
414 //=================================================================================
415 // function : keyPressEvent()
417 //=================================================================================
418 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
420 QDialog::keyPressEvent( e );
421 if ( e->isAccepted() )
424 if ( e->key() == Qt::Key_F1 ) {
430 //=================================================================================
431 // function : showOnlyPreviewControl()
432 // purpose : display only CheckBoxPreview check box,
433 // hide CheckBoxRestoreSS and CheckBoxAddPrefix
434 //=================================================================================
435 void GEOMBase_Skeleton::showOnlyPreviewControl(){
436 mainFrame()->GroupBoxPublish->show();
437 mainFrame()->CheckBoxRestoreSS->hide();
438 mainFrame()->CheckBoxAddPrefix->hide();
441 //=================================================================================
442 // function : processPreview()
443 // purpose : Display preview if CheckBoxPreview is checked
444 //=================================================================================
445 void GEOMBase_Skeleton::processPreview() {
446 displayPreview(mainFrame()->CheckBoxPreview->isChecked());