1 // Copyright (C) 2007-2008 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" ) );
75 buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
76 buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
77 buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
78 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
80 myRBGroup = new QButtonGroup( this );
81 myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
82 myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
83 myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
84 myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
85 myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
87 connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
92 //=================================================================================
93 // function : ~GEOMBase_Skeleton()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 GEOMBase_Skeleton::~GEOMBase_Skeleton()
99 myGeomGUI->SetActiveDialogBox( 0 );
102 //=================================================================================
105 //=================================================================================
106 void GEOMBase_Skeleton::Init()
108 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
109 if ( !myGeomGUI && app )
110 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
114 myGeomGUI->SetActiveDialogBox( this );
116 /* signals and slots connections */
117 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
119 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
120 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
123 // connect help button on a private slot that displays help information
124 connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
126 /* displays Dialog */
127 myMainFrame->RadioButton1->setChecked( true );
128 myMainFrame->RadioButton4->hide();
129 myMainFrame->RadioButton5->hide();
131 myMainFrame->CheckBoxRestoreSS->setChecked( false );
132 myMainFrame->GroupBoxPublish->hide();
135 //=================================================================================
136 // function : initSpinBox()
138 //=================================================================================
139 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
140 int min, int max, int step )
142 spinBox->setRange( min, max );
143 spinBox->setSingleStep( step );
146 //=================================================================================
147 // function : initSpinBox()
149 //=================================================================================
150 void GEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
151 double min, double max,
152 double step, int decimals )
154 spinBox->setPrecision( decimals );
155 spinBox->setDecimals( decimals ); // it's necessary to set decimals before the range setting,
156 // by default Qt rounds boundaries to 2 decimals at setRange
157 spinBox->setRange( min, max );
158 spinBox->setSingleStep( step );
161 //=================================================================================
162 // function : updateAttributes()
163 // purpose : Workaround for Translation and Rotation operations with unchecked option "Create a copy".
164 // In this case PublishInStudy isn't called, so we need to update object's attributes manually
165 //=================================================================================
166 void GEOMBase_Skeleton::updateAttributes( GEOM::GEOM_Object_ptr theObj,
167 const QStringList& theParameters)
169 SALOMEDS::Study_var aStudy = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
170 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
171 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theObj->GetStudyEntry());
172 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
173 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
175 std::string aValue = aStringAttrib->Value();
178 for( int i = 0, n = theParameters.count(); i < n; i++ ) {
179 std::string aParameter = theParameters[i].toStdString();
180 if(aStudy->IsVariable(aParameter.c_str()))
181 aValue += aParameter;
185 aStringAttrib->SetValue(aValue.c_str());
188 //=================================================================================
189 // function : ClickOnCancel()
191 //=================================================================================
192 void GEOMBase_Skeleton::ClickOnCancel()
197 //=================================================================================
198 // function : LineEditReturnPressed()
200 //=================================================================================
201 void GEOMBase_Skeleton::LineEditReturnPressed()
203 if (!myEditCurrentArgument)
206 /* User name of object input management */
207 /* If successfull the selection is changed and signal emitted... */
208 /* so SelectionIntoArgument() is automatically called. */
209 const QString objectUserName = myEditCurrentArgument->text();
210 QWidget* thisWidget = (QWidget*)this;
213 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
215 aSelMgr->selectedObjects(aList);
216 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aList))
217 myEditCurrentArgument->setText(objectUserName);
220 //=================================================================================
221 // function : DeactivateActiveDialog()
223 //=================================================================================
224 void GEOMBase_Skeleton::DeactivateActiveDialog()
226 this->setEnabled( false );
229 myGeomGUI->SetActiveDialogBox( 0 );
230 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
235 //=================================================================================
236 // function : ActivateThisDialog()
238 //=================================================================================
239 void GEOMBase_Skeleton::ActivateThisDialog()
241 /* Emit a signal to deactivate the active dialog */
242 if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
243 this->setEnabled( true );
244 if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
248 //=================================================================================
249 // function : closeEvent()
250 // purpose : same than click on cancel button
251 //=================================================================================
252 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
255 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
256 myGeomGUI->getApp()->updateActions();
258 QDialog::closeEvent( e );
261 //=================================================================================
262 // function : initName()
263 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
264 //=================================================================================
265 void GEOMBase_Skeleton::initName( const QString& thePrefix )
267 if ( !thePrefix.isNull() )
268 setPrefix( thePrefix );
269 myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
272 //=================================================================================
273 // function : getNewObjectName()
274 // purpose : returns contents of Name field
275 //=================================================================================
276 QString GEOMBase_Skeleton::getNewObjectName() const
278 return myMainFrame->ResultName->text();
281 //=================================================================================
282 // function : getConstructorId()
284 //=================================================================================
285 int GEOMBase_Skeleton::getConstructorId() const
288 return myRBGroup->checkedId();
292 //=================================================================================
293 // function : setConstructorId( id )
295 //=================================================================================
296 void GEOMBase_Skeleton::setConstructorId( const int id )
298 if ( myRBGroup && myRBGroup->button( id ) )
299 myRBGroup->button( id )->setChecked( true );
302 //=================================================================================
303 // function : unsetConstructorId
305 //=================================================================================
306 void GEOMBase_Skeleton::unsetConstructorId()
308 // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
309 // uncheck all buttons
310 // workaround, because setChecked( false ) does not result in Qt4
311 bool isExclusive = myRBGroup->exclusive();
312 myRBGroup->setExclusive( false );
313 QList<QAbstractButton*> btnList = myRBGroup->buttons();
314 for ( int j = 0; j < 2; j++ )
316 QList<QAbstractButton*>::const_iterator it = btnList.constBegin();
317 for ( ; it != btnList.constEnd(); ++it )
318 (*it)->setCheckable( j == 1 );
320 myRBGroup->setExclusive( isExclusive );
323 //=================================================================================
324 // function : ClickOnHelp()
326 //=================================================================================
327 void GEOMBase_Skeleton::ClickOnHelp()
329 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
331 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
335 platform = "winapplication";
337 platform = "application";
339 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
340 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
341 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
342 QObject::tr( "BUT_OK" ) );
346 //=================================================================================
347 // function : setHelpFileName()
348 // purpose : set name for help file html
349 //=================================================================================
350 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
352 myHelpFileName = theName;
355 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
360 QWidget* GEOMBase_Skeleton::centralWidget()
362 return myMainFrame->GroupMedium;
365 QPushButton* GEOMBase_Skeleton::buttonCancel() const
367 return myMainFrame->buttonCancel;
370 QPushButton* GEOMBase_Skeleton::buttonOk() const
372 return myMainFrame->buttonOk;
375 QPushButton* GEOMBase_Skeleton::buttonApply() const
377 return myMainFrame->buttonApply;
380 QPushButton* GEOMBase_Skeleton::buttonHelp() const
382 return myMainFrame->buttonHelp;
385 //=================================================================================
386 // function : keyPressEvent()
388 //=================================================================================
389 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
391 QDialog::keyPressEvent( e );
392 if ( e->isAccepted() )
395 if ( e->key() == Qt::Key_F1 ) {