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 : BasicGUI_ArcDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_ArcDlg.h"
28 #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_ArcDlg()
41 // purpose : Constructs a BasicGUI_ArcDlg 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_ArcDlg::BasicGUI_ArcDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47 bool modal, Qt::WindowFlags fl )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, "BasicGUI_ArcDlg", modal, fl )
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ARC" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ARC_CENTER" ) ) );
52 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_ARC_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ARC" ) );
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setIcon( image1 );
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 Group3Pnts = new DlgRef_3Sel( centralWidget() );
65 Group3Pnts->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
66 Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
67 Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
68 Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 3 ) );
70 Group3Pnts->LineEdit1->setReadOnly( true );
71 Group3Pnts->LineEdit2->setReadOnly( true );
72 Group3Pnts->LineEdit3->setReadOnly( true );
74 Group3Pnts->PushButton1->setIcon(image2);
75 Group3Pnts->PushButton2->setIcon(image2);
76 Group3Pnts->PushButton3->setIcon(image2);
79 Group3Pnts2 = new DlgRef_3Sel1Check( centralWidget() );
81 Group3Pnts2->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
82 Group3Pnts2->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
83 Group3Pnts2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( "Start" ) );
84 Group3Pnts2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( "End" ) );
86 Group3Pnts2->LineEdit1->setReadOnly( true );
87 Group3Pnts2->LineEdit2->setReadOnly( true );
88 Group3Pnts2->LineEdit3->setReadOnly( true );
90 Group3Pnts2->PushButton1->setIcon( image2 );
91 Group3Pnts2->PushButton2->setIcon( image2 );
92 Group3Pnts2->PushButton3->setIcon( image2 );
94 Group3Pnts2->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
96 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
97 layout->setMargin( 0 ); layout->setSpacing( 6 );
98 layout->addWidget( Group3Pnts );
99 layout->addWidget( Group3Pnts2 );
101 setHelpFileName( "arc.htm" );
107 //=================================================================================
108 // function : ~BasicGUI_ArcDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
116 //=================================================================================
119 //=================================================================================
120 void BasicGUI_ArcDlg::Init()
123 // myGeomGUI->SetState( 0 );
124 globalSelection( GEOM_POINT );
126 myConstructorId = -1;
127 myEditCurrentArgument = Group3Pnts->LineEdit1;
128 myEditCurrentArgument->setFocus();
130 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
131 Group3Pnts2->CheckButton1->setChecked( false );
133 /* signals and slots connections */
134 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
135 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
137 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
139 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
140 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
142 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
143 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
147 connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
148 connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
150 connect( Group3Pnts2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
151 connect( Group3Pnts2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152 connect( Group3Pnts2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect( Group3Pnts2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
155 connect( Group3Pnts2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
156 connect( Group3Pnts2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158 connect( Group3Pnts2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseSense() ) );
160 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
161 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
163 initName( tr( "GEOM_ARC" ) );
166 ConstructorsClicked( 0 );
170 //=================================================================================
171 // function : ClickOnOk()
173 //=================================================================================
174 void BasicGUI_ArcDlg::ClickOnOk()
176 if ( ClickOnApply() )
180 //=================================================================================
181 // function : ClickOnApply()
183 //=================================================================================
184 bool BasicGUI_ArcDlg::ClickOnApply()
192 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
193 Group3Pnts->LineEdit1->setText( "" );
194 Group3Pnts->LineEdit2->setText( "" );
195 Group3Pnts->LineEdit3->setText( "" );
196 Group3Pnts2->LineEdit1->setText( "" );
197 Group3Pnts2->LineEdit2->setText( "" );
198 Group3Pnts2->LineEdit3->setText( "" );
199 if ( getConstructorId() == 0 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
200 if ( getConstructorId() == 1 ) myEditCurrentArgument = Group3Pnts2->LineEdit1;
202 ConstructorsClicked( getConstructorId() );
207 //=================================================================================
208 // function : SelectionIntoArgument()
209 // purpose : Called when selection as changed or other case
210 //=================================================================================
211 void BasicGUI_ArcDlg::SelectionIntoArgument()
213 if ( getConstructorId() != 0 && getConstructorId() != 1 )
216 myEditCurrentArgument->setText( "" );
217 if ( IObjectCount() != 1 ) {
218 switch ( getConstructorId() ) {
220 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
221 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
222 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
226 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
227 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
228 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
234 Standard_Boolean aRes = Standard_False;
235 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
236 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
237 switch ( getConstructorId() ) {
239 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
240 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
241 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
242 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
245 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
246 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1 = aSelectedObject;
247 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2 = aSelectedObject;
248 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3 = aSelectedObject;
257 //=================================================================================
258 // function : SetEditCurrentArgument()
260 //=================================================================================
261 void BasicGUI_ArcDlg::SetEditCurrentArgument()
263 QPushButton* send = (QPushButton*)sender();
264 switch ( getConstructorId() ) {
266 if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
267 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
268 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
271 if ( send == Group3Pnts2->PushButton1 ) myEditCurrentArgument = Group3Pnts2->LineEdit1;
272 else if ( send == Group3Pnts2->PushButton2 ) myEditCurrentArgument = Group3Pnts2->LineEdit2;
273 else if ( send == Group3Pnts2->PushButton3 ) myEditCurrentArgument = Group3Pnts2->LineEdit3;
276 myEditCurrentArgument->setFocus();
277 SelectionIntoArgument();
281 //=================================================================================
282 // function : LineEditReturnPressed()
284 //=================================================================================
285 void BasicGUI_ArcDlg::LineEditReturnPressed()
287 QLineEdit* send = (QLineEdit*)sender();
288 if ( send == Group3Pnts->LineEdit1 || send == Group3Pnts->LineEdit2 || send == Group3Pnts->LineEdit3 ||
289 send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3 ) {
290 myEditCurrentArgument = send;
291 GEOMBase_Skeleton::LineEditReturnPressed();
296 //=================================================================================
297 // function : ActivateThisDialog()
299 //=================================================================================
300 void BasicGUI_ArcDlg::ActivateThisDialog()
302 GEOMBase_Skeleton::ActivateThisDialog();
303 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
304 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
306 // myGeomGUI->SetState( 0 );
307 globalSelection( GEOM_POINT );
309 myEditCurrentArgument = Group3Pnts->LineEdit1;
310 myEditCurrentArgument->setFocus();
312 Group3Pnts->LineEdit1->setText( "" );
313 Group3Pnts->LineEdit2->setText( "" );
314 Group3Pnts->LineEdit3->setText( "" );
315 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
317 ConstructorsClicked( getConstructorId() );
321 //=================================================================================
322 // function : DeactivateActiveDialog()
323 // purpose : public slot to deactivate if active
324 //=================================================================================
325 void BasicGUI_ArcDlg::DeactivateActiveDialog()
327 // myGeomGUI->SetState( -1 );
328 GEOMBase_Skeleton::DeactivateActiveDialog();
331 //=================================================================================
332 // function : enterEvent()
334 //=================================================================================
335 void BasicGUI_ArcDlg::enterEvent( QEvent* )
337 if ( !mainFrame()->GroupConstructors->isEnabled() )
338 ActivateThisDialog();
341 //=================================================================================
342 // function : createOperation
344 //=================================================================================
345 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
347 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
350 //=================================================================================
351 // function : isEqual
352 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
353 //=================================================================================
354 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
356 return thePnt1->_is_equivalent( thePnt2 );
359 //=================================================================================
360 // function : isValid
362 //=================================================================================
363 bool BasicGUI_ArcDlg::isValid( QString& msg )
365 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
366 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
369 //=================================================================================
370 // function : execute
372 //=================================================================================
373 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
376 GEOM::GEOM_Object_var anObj;
378 switch ( getConstructorId() ) {
381 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
382 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArc( myPoint1, myPoint2, myPoint3 );
389 bool Sense = Group3Pnts2->CheckButton1->isChecked();
390 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
391 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArcCenter( myPoint1, myPoint2, myPoint3, Sense );
397 if ( !anObj->_is_nil() ) {
398 objects.push_back( anObj._retn() );
403 //=================================================================================
404 // function : closeEvent
406 //=================================================================================
407 void BasicGUI_ArcDlg::closeEvent( QCloseEvent* e )
409 GEOMBase_Skeleton::closeEvent( e );
412 //=================================================================================
413 // function : ConstructorsClicked()
414 // purpose : Radio button management
415 //=================================================================================
416 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
418 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
420 switch ( constructorId ) {
426 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
427 SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
434 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
435 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
441 qApp->processEvents();
443 resize( minimumSize() );
448 //=================================================================================
449 // function : ReverseSense()
450 // purpose : Orientation of the arc
451 //=================================================================================
452 void BasicGUI_ArcDlg::ReverseSense()