1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : GEOMBase_Skeleton.cxx
25 // Author : Damien COQUERET
29 #include "GEOMBase_Skeleton.h"
32 #include "GeometryGUI.h"
34 #include "SalomeApp_Application.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"
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 const char* name, bool modal, Qt::WindowFlags fl)
55 : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
56 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
57 myGeomGUI( theGeometryGUI ),
63 setObjectName("GEOMBase_Skeleton");
68 setAttribute( Qt::WA_DeleteOnClose );
70 buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
71 buttonOk->setText(tr("GEOM_BUT_OK"));
72 buttonApply->setText(tr("GEOM_BUT_APPLY"));
73 buttonHelp->setText(tr("GEOM_BUT_HELP"));
75 GroupMedium->setAttribute( Qt::WA_DeleteOnClose );
79 if ( GroupConstructors != NULL ) {
80 myRBGroup = new QButtonGroup(GroupConstructors);
81 QList<QObject*> aRadioButtons = GroupConstructors->children();
82 QListIterator<QObject*> it( aRadioButtons );
84 while ( it.hasNext() )
85 if ( QRadioButton* aRB = ::qobject_cast<QRadioButton*>( it.next() ) ) {
86 myRBGroup->addButton( aRB, anId );
95 //=================================================================================
96 // function : ~GEOMBase_Skeleton()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 GEOMBase_Skeleton::~GEOMBase_Skeleton()
102 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" ) );
117 myGeomGUI->SetActiveDialogBox(this);
119 /* signals and slots connections */
120 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 /* displays Dialog */
131 RadioButton1->setChecked(TRUE);
132 RadioButton4->hide();
138 //=================================================================================
139 // function : ClickOnCancel()
141 //=================================================================================
142 void GEOMBase_Skeleton::ClickOnCancel()
148 //=================================================================================
149 // function : LineEditReturnPressed()
151 //=================================================================================
152 void GEOMBase_Skeleton::LineEditReturnPressed()
154 if ( !myEditCurrentArgument )
157 /* User name of object input management */
158 /* If successfull the selection is changed and signal emitted... */
159 /* so SelectionIntoArgument() is automatically called. */
160 const QString objectUserName = myEditCurrentArgument->text();
161 QWidget* thisWidget = (QWidget*)this;
163 if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
164 myEditCurrentArgument->setText(objectUserName);
170 //=================================================================================
171 // function : DeactivateActiveDialog()
173 //=================================================================================
174 void GEOMBase_Skeleton::DeactivateActiveDialog()
176 this->setEnabled(false);
178 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
179 if (myGeomGUI) myGeomGUI->SetActiveDialogBox(0);
185 //=================================================================================
186 // function : ActivateThisDialog()
188 //=================================================================================
189 void GEOMBase_Skeleton::ActivateThisDialog()
191 /* Emit a signal to deactivate the active dialog */
192 if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
193 this->setEnabled(true);
194 if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
199 //=================================================================================
200 // function : closeEvent()
201 // purpose : same than click on cancel button
202 //=================================================================================
203 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
205 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
207 disconnect( app->selectionMgr(), 0, this, 0);
208 app->updateActions();
210 QDialog::closeEvent( e );
213 //=================================================================================
214 // function : initName()
215 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
216 //=================================================================================
217 void GEOMBase_Skeleton::initName( const char* thePrefix )
220 setPrefix( thePrefix );
221 ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
224 //=================================================================================
225 // function : getNewObjectName()
226 // purpose : returns contents of Name field
227 //=================================================================================
228 const char* GEOMBase_Skeleton::getNewObjectName() const
230 return ResultName->text().toLatin1().constData();
233 //=================================================================================
234 // function : getConstructorId()
236 //=================================================================================
237 int GEOMBase_Skeleton::getConstructorId() const
239 /*if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
240 return GroupConstructors->id( GroupConstructors->selected() );
243 if ( myRBGroup != NULL )
244 return myRBGroup->checkedId();
248 //=================================================================================
249 // function : ClickOnHelp()
251 //=================================================================================
252 void GEOMBase_Skeleton::ClickOnHelp()
254 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
256 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
260 platform = "winapplication";
262 platform = "application";
264 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
265 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
266 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
267 QObject::tr("BUT_OK"));
270 //=================================================================================
271 // function : setHelpFileName()
272 // purpose : set name for help file html
273 //=================================================================================
275 void GEOMBase_Skeleton::setHelpFileName(const QString& theName)
277 myHelpFileName = theName;
280 //=================================================================================
281 // function : keyPressEvent()
283 //=================================================================================
284 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
286 QDialog::keyPressEvent( e );
287 if ( e->isAccepted() )
290 if ( e->key() == Qt::Key_F1 )