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
22 // File : GEOMBase_Skeleton.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "GEOMBase_Skeleton.h"
29 #include <GeometryGUI.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_MessageBox.h>
43 //=================================================================================
44 // class : GEOMBase_Skeleton()
45 // purpose : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 GEOMBase_Skeleton::GEOMBase_Skeleton(GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, Qt::WindowFlags fl)
52 : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
53 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
54 myGeomGUI( theGeometryGUI ),
60 setObjectName("GEOMBase_Skeleton");
65 setAttribute( Qt::WA_DeleteOnClose );
67 buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
68 buttonOk->setText(tr("GEOM_BUT_OK"));
69 buttonApply->setText(tr("GEOM_BUT_APPLY"));
70 buttonHelp->setText(tr("GEOM_BUT_HELP"));
72 GroupMedium->setAttribute( Qt::WA_DeleteOnClose );
76 if ( GroupConstructors != NULL ) {
77 myRBGroup = new QButtonGroup(GroupConstructors);
78 QList<QObject*> aRadioButtons = GroupConstructors->children();
79 QListIterator<QObject*> it( aRadioButtons );
81 while ( it.hasNext() )
82 if ( QRadioButton* aRB = ::qobject_cast<QRadioButton*>( it.next() ) ) {
83 myRBGroup->addButton( aRB, anId );
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 );
103 //=================================================================================
106 //=================================================================================
107 void GEOMBase_Skeleton::Init()
109 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
110 if (!myGeomGUI && app)
111 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
114 myGeomGUI->SetActiveDialogBox(this);
116 /* signals and slots connections */
117 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
120 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
121 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
124 // connect help button on a private slot that displays help information
125 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
127 /* displays Dialog */
128 RadioButton1->setChecked(TRUE);
129 RadioButton4->hide();
135 //=================================================================================
136 // function : ClickOnCancel()
138 //=================================================================================
139 void GEOMBase_Skeleton::ClickOnCancel()
145 //=================================================================================
146 // function : LineEditReturnPressed()
148 //=================================================================================
149 void GEOMBase_Skeleton::LineEditReturnPressed()
151 if ( !myEditCurrentArgument )
154 /* User name of object input management */
155 /* If successfull the selection is changed and signal emitted... */
156 /* so SelectionIntoArgument() is automatically called. */
157 const QString objectUserName = myEditCurrentArgument->text();
158 QWidget* thisWidget = (QWidget*)this;
160 if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
161 myEditCurrentArgument->setText(objectUserName);
167 //=================================================================================
168 // function : DeactivateActiveDialog()
170 //=================================================================================
171 void GEOMBase_Skeleton::DeactivateActiveDialog()
173 this->setEnabled(false);
175 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
176 if (myGeomGUI) myGeomGUI->SetActiveDialogBox(0);
182 //=================================================================================
183 // function : ActivateThisDialog()
185 //=================================================================================
186 void GEOMBase_Skeleton::ActivateThisDialog()
188 /* Emit a signal to deactivate the active dialog */
189 if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
190 this->setEnabled(true);
191 if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
196 //=================================================================================
197 // function : closeEvent()
198 // purpose : same than click on cancel button
199 //=================================================================================
200 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
202 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
204 disconnect( app->selectionMgr(), 0, this, 0);
205 app->updateActions();
207 QDialog::closeEvent( e );
210 //=================================================================================
211 // function : initName()
212 // purpose : initialize the Name field with a string "thePrefix_X" (Vertex_3)
213 //=================================================================================
214 void GEOMBase_Skeleton::initName( const char* thePrefix )
217 setPrefix( thePrefix );
218 ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
221 //=================================================================================
222 // function : getNewObjectName()
223 // purpose : returns contents of Name field
224 //=================================================================================
225 const char* GEOMBase_Skeleton::getNewObjectName() const
227 return ResultName->text().toLatin1().constData();
230 //=================================================================================
231 // function : getConstructorId()
233 //=================================================================================
234 int GEOMBase_Skeleton::getConstructorId() const
236 /*if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
237 return GroupConstructors->id( GroupConstructors->selected() );
240 if ( myRBGroup != NULL )
241 return myRBGroup->checkedId();
245 //=================================================================================
246 // function : ClickOnHelp()
248 //=================================================================================
249 void GEOMBase_Skeleton::ClickOnHelp()
251 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
253 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
257 platform = "winapplication";
259 platform = "application";
261 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
262 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
263 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
264 QObject::tr("BUT_OK"));
267 //=================================================================================
268 // function : setHelpFileName()
269 // purpose : set name for help file html
270 //=================================================================================
272 void GEOMBase_Skeleton::setHelpFileName(const QString& theName)
274 myHelpFileName = theName;
277 //=================================================================================
278 // function : keyPressEvent()
280 //=================================================================================
281 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
283 QDialog::keyPressEvent( e );
284 if ( e->isAccepted() )
287 if ( e->key() == Qt::Key_F1 )