1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BasicGUI_EllipseDlg.cxx
22 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 #include "BasicGUI_EllipseDlg.h"
27 #include <GEOM_DlgRef.h>
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : BasicGUI_EllipseDlg()
41 // purpose : Constructs a BasicGUI_EllipseDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 BasicGUI_EllipseDlg::BasicGUI_EllipseDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47 bool modal, Qt::WindowFlags fl )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ELLIPSE_PV" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53 setWindowTitle( tr( "GEOM_ELLIPSE_TITLE" ) );
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ELLIPSE" ) );
57 mainFrame()->RadioButton1->setIcon( image0 );
58 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupPoints = new DlgRef_2Sel2Spin( centralWidget() );
64 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
65 GroupPoints->TextLabel1->setText( tr( "GEOM_CENTER" ) );
66 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
67 GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_MAJOR" ) );
68 GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_MINOR" ) );
69 GroupPoints->PushButton1->setIcon( image1 );
70 GroupPoints->PushButton2->setIcon( image1 );
72 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->LineEdit2->setReadOnly( true );
75 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76 layout->setMargin( 0 ); layout->setSpacing( 6 );
77 layout->addWidget( GroupPoints );
78 /***************************************************************/
80 setHelpFileName( "ellipse.htm" );
86 //=================================================================================
87 // function : ~BasicGUI_EllipseDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
95 //=================================================================================
98 //=================================================================================
99 void BasicGUI_EllipseDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 globalSelection( GEOM_POINT );
105 myPoint = myDir = GEOM::GEOM_Object::_nil();
107 // myGeomGUI->SetState( 0 );
109 /* Get setting of step value from file configuration */
110 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
111 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
113 double aMajorR( 200. ), aMinorR( 100. );
115 /* min, max, step and decimals for spin boxes & initial values */
116 initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 );
117 initSpinBox( GroupPoints->SpinBox_DY, 0.001, COORD_MAX, step, 3 );
118 GroupPoints->SpinBox_DX->setValue( aMajorR );
119 GroupPoints->SpinBox_DY->setValue( aMinorR );
121 /* signals and slots connections */
122 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
123 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
125 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
126 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
128 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
129 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
131 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
132 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
134 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
135 connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
138 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
139 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DY, SLOT( SetStep( double ) ) );
142 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
143 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
145 initName( tr( "GEOM_ELLIPSE" ) );
149 //=================================================================================
150 // function : ClickOnOk()
152 //=================================================================================
153 void BasicGUI_EllipseDlg::ClickOnOk()
155 if ( ClickOnApply() )
160 //=================================================================================
161 // function : ClickOnApply()
163 //=================================================================================
164 bool BasicGUI_EllipseDlg::ClickOnApply()
172 myPoint = myDir = GEOM::GEOM_Object::_nil();
173 GroupPoints->LineEdit1->setText( "" );
174 GroupPoints->LineEdit2->setText( "" );
175 myEditCurrentArgument = GroupPoints->LineEdit1;
176 globalSelection( GEOM_POINT );
181 //=================================================================================
182 // function : SelectionIntoArgument()
183 // purpose : Called when selection as changed or other case
184 //=================================================================================
185 void BasicGUI_EllipseDlg::SelectionIntoArgument()
187 myEditCurrentArgument->setText( "" );
189 if ( IObjectCount() != 1 ) {
190 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
191 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
195 Standard_Boolean aRes = Standard_False;
196 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
197 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
198 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
199 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
200 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
207 //=================================================================================
208 // function : SetEditCurrentArgument()
210 //=================================================================================
211 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
213 QPushButton* send = (QPushButton*)sender();
215 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
216 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
218 myEditCurrentArgument->setFocus();
219 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
220 globalSelection( GEOM_LINE );
222 globalSelection( GEOM_POINT );
223 SelectionIntoArgument();
226 //=================================================================================
227 // function : LineEditReturnPressed()
229 //=================================================================================
230 void BasicGUI_EllipseDlg::LineEditReturnPressed()
232 QLineEdit* send = (QLineEdit*)sender();
233 if ( send == GroupPoints->LineEdit1 ||
234 send == GroupPoints->LineEdit2 ) {
235 myEditCurrentArgument = send;
236 GEOMBase_Skeleton::LineEditReturnPressed();
241 //=================================================================================
242 // function : ActivateThisDialog()
244 //=================================================================================
245 void BasicGUI_EllipseDlg::ActivateThisDialog()
247 GEOMBase_Skeleton::ActivateThisDialog();
248 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
249 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
251 GroupPoints->LineEdit1->setFocus();
252 myEditCurrentArgument = GroupPoints->LineEdit1;
254 GroupPoints->LineEdit1->setText( "" );
255 GroupPoints->LineEdit2->setText( "" );
257 myPoint = myDir = GEOM::GEOM_Object::_nil();
258 globalSelection( GEOM_POINT );
261 //=================================================================================
262 // function : DeactivateActiveDialog()
263 // purpose : public slot to deactivate if active
264 //=================================================================================
265 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
267 // myGeomGUI->SetState( -1 );
268 GEOMBase_Skeleton::DeactivateActiveDialog();
271 //=================================================================================
272 // function : enterEvent()
274 //=================================================================================
275 void BasicGUI_EllipseDlg::enterEvent( QEvent* )
277 if ( !mainFrame()->GroupConstructors->isEnabled() )
278 ActivateThisDialog();
281 //=================================================================================
282 // function : ValueChangedInSpinBox()
284 //=================================================================================
285 void BasicGUI_EllipseDlg::ValueChangedInSpinBox( double newValue )
290 //=================================================================================
291 // function : createOperation
293 //=================================================================================
294 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
296 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
299 //=================================================================================
300 // function : isValid
302 //=================================================================================
303 bool BasicGUI_EllipseDlg::isValid( QString& msg )
305 double aMajorR = GroupPoints->SpinBox_DX->value();
306 double aMinorR = GroupPoints->SpinBox_DY->value();
307 if ( aMajorR < aMinorR ) {
308 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
311 return !myPoint->_is_nil() && !myDir->_is_nil();
314 //=================================================================================
315 // function : execute
317 //=================================================================================
318 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
320 double aMajorR = GroupPoints->SpinBox_DX->value();
321 double aMinorR = GroupPoints->SpinBox_DY->value();
322 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
324 if ( !anObj->_is_nil() )
325 objects.push_back( anObj._retn() );
330 //=================================================================================
331 // function : closeEvent
333 //=================================================================================
334 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
336 GEOMBase_Skeleton::closeEvent( e );