]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Skeleton.cxx
Salome HOME
Update copyright information
[modules/geom.git] / src / GEOMBase / GEOMBase_Skeleton.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : GEOMBase_Skeleton.cxx
24 //  Author : Damien COQUERET
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "GEOMBase_Skeleton.h"
29
30 #include "GeometryGUI.h"
31
32 #include "SalomeApp_Application.h"
33 #include "LightApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_MessageBox.h"
37
38 #include <qlabel.h>
39 #include <qpushbutton.h>
40 #include <qcheckbox.h>
41
42 using namespace std;
43
44 //=================================================================================
45 // class    : GEOMBase_Skeleton()
46 // purpose  : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 GEOMBase_Skeleton::GEOMBase_Skeleton (GeometryGUI* theGeometryGUI, QWidget* parent,
52                                       const char* name, bool modal, WFlags fl)
53   : DlgRef_Skeleton_QTD( parent, name, modal, WStyle_Customize | WStyle_NormalBorder
54                          | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
55    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
56    myGeomGUI( theGeometryGUI )
57 {
58   if (!name)
59     setName("GEOMBase_Skeleton");
60
61   GroupBoxName->setTitle(tr("GEOM_RESULT_NAME_GRP"));
62   NameLabel->setText(tr("GEOM_RESULT_NAME_LBL"));
63
64   GroupBoxPublish->setTitle(tr("GEOM_PUBLISH_RESULT_GRP"));
65   CheckBoxRestoreSS->setText(tr("GEOM_RESTORE_SUB_SHAPES"));
66
67   buttonCancel->setText(tr("GEOM_BUT_CLOSE"));
68   buttonOk->setText(tr("GEOM_BUT_APPLY_AND_CLOSE"));
69   buttonApply->setText(tr("GEOM_BUT_APPLY"));
70   buttonHelp->setText(tr("GEOM_BUT_HELP"));
71
72   resize(0, 0);
73
74   Init();
75 }
76
77 //=================================================================================
78 // function : ~GEOMBase_Skeleton()
79 // purpose  : Destroys the object and frees any allocated resources
80 //=================================================================================
81 GEOMBase_Skeleton::~GEOMBase_Skeleton()
82 {
83   if (myGeomGUI)
84     myGeomGUI->SetActiveDialogBox( 0 );
85 }
86
87 //=================================================================================
88 // function : Init()
89 // purpose  :
90 //=================================================================================
91 void GEOMBase_Skeleton::Init()
92 {
93   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
94   if (!myGeomGUI && app)
95     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
96
97   /* init variables */
98   if (myGeomGUI)
99     myGeomGUI->SetActiveDialogBox(this);
100
101   /* signals and slots connections */
102   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
103   if (myGeomGUI)
104   {
105     connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
106     connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
107   }
108
109   // connect help button on a private slot that displays help information
110   connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
111
112   /* displays Dialog */
113   RadioButton1->setChecked(TRUE);
114   RadioButton4->hide();
115   RadioButton5->hide();
116
117   CheckBoxRestoreSS->setChecked(FALSE);
118   GroupBoxPublish->hide();
119 }
120
121 //=================================================================================
122 // function : ClickOnCancel()
123 // purpose  :
124 //=================================================================================
125 void GEOMBase_Skeleton::ClickOnCancel()
126 {
127   close();
128 }
129
130 //=================================================================================
131 // function : LineEditReturnPressed()
132 // purpose  :
133 //=================================================================================
134 void GEOMBase_Skeleton::LineEditReturnPressed()
135 {
136   if ( !myEditCurrentArgument )
137     return;
138
139   /* User name of object input management                          */
140   /* If successfull the selection is changed and signal emitted... */
141   /* so SelectionIntoArgument() is automatically called.           */
142   const QString objectUserName = myEditCurrentArgument->text();
143   QWidget* thisWidget = (QWidget*)this;
144
145   if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
146      myEditCurrentArgument->setText(objectUserName);
147 }
148
149 //=================================================================================
150 // function : DeactivateActiveDialog()
151 // purpose  :
152 //=================================================================================
153 void GEOMBase_Skeleton::DeactivateActiveDialog()
154 {
155   this->setEnabled(false);
156   globalSelection();
157   if (myGeomGUI) {
158     myGeomGUI->SetActiveDialogBox(0);
159     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
160   }
161 }
162
163 //=================================================================================
164 // function : ActivateThisDialog()
165 // purpose  :
166 //=================================================================================
167 void GEOMBase_Skeleton::ActivateThisDialog()
168 {
169   /* Emit a signal to deactivate the active dialog */
170   if (myGeomGUI) myGeomGUI->EmitSignalDeactivateDialog();
171   this->setEnabled(true);
172   if (myGeomGUI) myGeomGUI->SetActiveDialogBox((QDialog*)this);
173 }
174
175 //=================================================================================
176 // function : closeEvent()
177 // purpose  : same than click on cancel button
178 //=================================================================================
179 void GEOMBase_Skeleton::closeEvent(QCloseEvent* e)
180 {
181   if (myGeomGUI) {
182     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
183     myGeomGUI->getApp()->updateActions();
184   }
185   QDialog::closeEvent( e );
186 }
187
188 //=================================================================================
189 // function : initName()
190 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
191 //=================================================================================
192 void GEOMBase_Skeleton::initName( const char* thePrefix )
193 {
194   if ( thePrefix )
195     setPrefix( thePrefix );
196   ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
197 }
198
199 //=================================================================================
200 // function : getNewObjectName()
201 // purpose  : returns contents of Name field
202 //=================================================================================
203 const char* GEOMBase_Skeleton::getNewObjectName() const
204 {
205   return ResultName->text();
206 }
207
208 //=================================================================================
209 // function : getConstructorId()
210 // purpose  :
211 //=================================================================================
212 int GEOMBase_Skeleton::getConstructorId() const
213 {
214   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
215     return GroupConstructors->id( GroupConstructors->selected() );
216   return -1;
217 }
218
219 //=================================================================================
220 // function : ClickOnHelp()
221 // purpose  :
222 //=================================================================================
223 void GEOMBase_Skeleton::ClickOnHelp()
224 {
225   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
226   if (app)
227     app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
228   else {
229     QString platform;
230 #ifdef WIN32
231     platform = "winapplication";
232 #else
233     platform = "application";
234 #endif
235     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
236                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
237                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
238                            QObject::tr("BUT_OK"));
239   }
240 }
241
242 //=================================================================================
243 //  function : setHelpFileName()
244 //  purpose  : set name for help file html
245 //=================================================================================
246 void GEOMBase_Skeleton::setHelpFileName(const QString& theName)
247 {
248     myHelpFileName = theName;
249 }
250
251 //=================================================================================
252 // function : keyPressEvent()
253 // purpose  :
254 //=================================================================================
255 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
256 {
257   QDialog::keyPressEvent( e );
258   if ( e->isAccepted() )
259     return;
260
261   if ( e->key() == Key_F1 )
262   {
263     e->accept();
264     ClickOnHelp();
265   }
266 }