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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI_LineDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_LineDlg.h"
32 #include "GeometryGUI.h"
34 #include <Precision.hxx>
36 #include "QAD_Application.h"
37 #include "QAD_Desktop.h"
38 #include "utilities.h"
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
54 //=================================================================================
55 // class : GeometryGUI_LineDlg()
56 // purpose : Constructs a GeometryGUI_LineDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 GeometryGUI_LineDlg::GeometryGUI_LineDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
62 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
65 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
66 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_PV")));
68 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_EDGE")));
71 setName( "GeometryGUI_LineDlg" );
73 setCaption( tr( "GEOM_LINE_TITLE" ) );
74 setSizeGripEnabled( TRUE );
75 GeometryGUI_LineDlgLayout = new QGridLayout( this );
76 GeometryGUI_LineDlgLayout->setSpacing( 6 );
77 GeometryGUI_LineDlgLayout->setMargin( 11 );
79 /***************************************************************/
80 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
81 GroupConstructors->setTitle( tr( "GEOM_LINE" ) );
82 GroupConstructors->setExclusive( TRUE );
83 GroupConstructors->setColumnLayout(0, Qt::Vertical );
84 GroupConstructors->layout()->setSpacing( 0 );
85 GroupConstructors->layout()->setMargin( 0 );
86 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
87 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
88 GroupConstructorsLayout->setSpacing( 6 );
89 GroupConstructorsLayout->setMargin( 11 );
90 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
91 Constructor1->setText( tr( "" ) );
92 Constructor1->setPixmap( image0 );
93 Constructor1->setChecked( TRUE );
94 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
95 Constructor1->setMinimumSize( QSize( 50, 0 ) );
96 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
97 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
100 GroupConstructorsLayout->addItem( spacer_3, 0, 5 );
101 GeometryGUI_LineDlgLayout->addWidget( GroupConstructors, 0, 0 );
103 /***************************************************************/
104 GroupC1 = new QGroupBox( this, "GroupC1" );
105 GroupC1->setTitle( tr( "GEOM_POINTS" ) );
106 GroupC1->setMinimumSize( QSize( 0, 0 ) );
107 GroupC1->setFrameShape( QGroupBox::Box );
108 GroupC1->setFrameShadow( QGroupBox::Sunken );
109 GroupC1->setColumnLayout(0, Qt::Vertical );
110 GroupC1->layout()->setSpacing( 0 );
111 GroupC1->layout()->setMargin( 0 );
112 GroupC1Layout = new QGridLayout( GroupC1->layout() );
113 GroupC1Layout->setAlignment( Qt::AlignTop );
114 GroupC1Layout->setSpacing( 6 );
115 GroupC1Layout->setMargin( 11 );
116 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
117 SelectButtonC1A2->setText( tr( "" ) );
118 SelectButtonC1A2->setPixmap( image1 );
119 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
120 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
121 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
122 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
123 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
124 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
125 SelectButtonC1A1->setText( tr( "" ) );
126 SelectButtonC1A1->setPixmap( image1 );
127 SelectButtonC1A1->setToggleButton( FALSE );
128 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
129 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
130 TextLabelC1A1->setText( tr( "GEOM_POINT_I" ).arg("1") );
131 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
132 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
133 TextLabelC1A1->setFrameShadow( QLabel::Plain );
134 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
135 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
136 TextLabelC1A2->setText( tr( "GEOM_POINT_I" ).arg("2") );
137 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
138 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
139 GeometryGUI_LineDlgLayout->addWidget( GroupC1, 1, 0 );
141 /***************************************************************/
142 GroupButtons = new QGroupBox( this, "GroupButtons" );
143 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
144 GroupButtons->setTitle( tr( "" ) );
145 GroupButtons->setColumnLayout(0, Qt::Vertical );
146 GroupButtons->layout()->setSpacing( 0 );
147 GroupButtons->layout()->setMargin( 0 );
148 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
149 GroupButtonsLayout->setAlignment( Qt::AlignTop );
150 GroupButtonsLayout->setSpacing( 6 );
151 GroupButtonsLayout->setMargin( 11 );
152 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
153 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
154 buttonCancel->setAutoDefault( TRUE );
155 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
156 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
157 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
158 buttonApply->setAutoDefault( TRUE );
159 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
160 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
161 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
162 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
163 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
164 buttonOk->setAutoDefault( TRUE );
165 buttonOk->setDefault( TRUE );
166 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
167 GeometryGUI_LineDlgLayout->addWidget( GroupButtons, 2, 0 );
169 Init(Sel) ; /* Initialisations */
173 //=================================================================================
174 // function : ~GeometryGUI_LineDlg()
175 // purpose : Destroys the object and frees any allocated resources
176 //=================================================================================
177 GeometryGUI_LineDlg::~GeometryGUI_LineDlg()
179 /* no need to delete child widgets, Qt does it all for us */
183 //=================================================================================
186 //=================================================================================
187 void GeometryGUI_LineDlg::Init( SALOME_Selection* Sel )
193 myConstructorId = 0 ;
194 Constructor1->setChecked( TRUE );
195 myEditCurrentArgument = LineEditC1A1 ;
197 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
198 myPoint1.SetCoord( 0.0, 0.0, 0.0 );
199 myPoint2.SetCoord( 0.0, 0.0, 0.0 );
200 myOkPoint1 = myOkPoint2 = false ;
201 mySimulationTopoDs.Nullify() ;
202 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
204 // TODO : previous selection into argument ?
206 /* Filters definition */
207 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
208 myGeom = GEOM::GEOM_Gen::_narrow(comp);
209 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
210 myEdgeFilter = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
211 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
213 /* signals and slots connections */
214 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
215 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
216 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
217 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
218 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
219 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
221 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
222 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
224 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
225 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
226 /* to close dialog if study change */
227 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
229 /* Move widget on the botton right corner of main widget */
231 myGeomGUI->DefineDlgPosition( this, x, y ) ;
233 this->show() ; /* displays Dialog */
239 //=================================================================================
240 // function : ConstructorsClicked()
241 // purpose : Radio button management
242 //=================================================================================
243 void GeometryGUI_LineDlg::ConstructorsClicked(int constructorId)
245 myGeomGUI->EraseSimulationShape() ;
247 switch (constructorId)
254 myConstructorId = constructorId ;
255 myEditCurrentArgument = LineEditC1A1 ;
256 Constructor1->setChecked( TRUE );
257 LineEditC1A1->setText(tr("")) ;
258 LineEditC1A2->setText(tr("")) ;
259 myOkPoint1 = myOkPoint2 = false ;
260 /* filter for next selections */
261 mySelection->ClearFilters() ;
262 mySelection->AddFilter( myVertexFilter );
263 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
278 //=================================================================================
279 // function : ClickOnOk()
281 //=================================================================================
282 void GeometryGUI_LineDlg::ClickOnOk()
284 this->ClickOnApply() ;
285 this->ClickOnCancel() ;
290 //=================================================================================
291 // function : ClickOnApply()
293 //=================================================================================
294 void GeometryGUI_LineDlg::ClickOnApply()
296 myGeomGUI->EraseSimulationShape() ;
297 mySimulationTopoDs.Nullify() ;
298 switch(myConstructorId)
302 if(myOkPoint1 && myOkPoint2)
303 myGeomGUI->MakeLineAndDisplay( myPoint1, myPoint2 ) ;
320 //=================================================================================
321 // function : ClickOnCancel()
323 //=================================================================================
324 void GeometryGUI_LineDlg::ClickOnCancel()
326 mySelection->ClearFilters() ;
327 myGeomGUI->EraseSimulationShape() ;
328 mySimulationTopoDs.Nullify() ;
329 disconnect( mySelection, 0, this, 0 );
330 myGeomGUI->ResetState() ;
335 //=================================================================================
336 // function : LineEditReturnPressed()
338 //=================================================================================
339 void GeometryGUI_LineDlg::LineEditReturnPressed()
341 QLineEdit* send = (QLineEdit*)sender() ;
342 if( send == LineEditC1A1 )
343 myEditCurrentArgument = LineEditC1A1 ;
344 else if ( send == LineEditC1A2 )
345 myEditCurrentArgument = LineEditC1A2 ;
349 /* User name of object input management */
350 /* If successfull the selection is changed and signal emitted... */
351 /* so SelectionIntoArgument() is automatically called. */
352 const QString objectUserName = myEditCurrentArgument->text() ;
353 QWidget* thisWidget = (QWidget*)this ;
354 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
355 myEditCurrentArgument->setText( objectUserName ) ;
361 //=================================================================================
362 // function : SelectionIntoArgument()
363 // purpose : Called when selection as changed or other case
364 //=================================================================================
365 void GeometryGUI_LineDlg::SelectionIntoArgument()
368 myGeomGUI->EraseSimulationShape() ;
369 mySimulationTopoDs.Nullify() ;
370 QString aString = ""; /* name of selection */
372 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
374 if ( myEditCurrentArgument == LineEditC1A1 ) {
375 myEditCurrentArgument->setText("") ;
378 else if ( myEditCurrentArgument == LineEditC1A2 ) {
379 myEditCurrentArgument->setText("") ;
387 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
390 /* Constructor 1 treatment */
391 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
392 myEditCurrentArgument->setText(aString) ;
395 else if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint(S, myPoint2) ) {
396 myEditCurrentArgument->setText(aString) ;
400 if( myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion() ) {
401 mySimulationTopoDs = BRepBuilderAPI_MakeEdge( myPoint1, myPoint2 ).Shape();
402 /* Try to add an arrow at simulation shape */
403 bool notNeedToTest = this->AddArrowToSimulation(mySimulationTopoDs) ;
404 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
409 //=================================================================================
410 // function : SetEditCurrentArgument()
412 //=================================================================================
413 void GeometryGUI_LineDlg::SetEditCurrentArgument()
415 QPushButton* send = (QPushButton*)sender();
416 mySelection->ClearFilters() ;
417 switch (myConstructorId)
419 case 0: /* default constructor */
421 if(send == SelectButtonC1A1) {
422 LineEditC1A1->setFocus() ;
423 myEditCurrentArgument = LineEditC1A1;
425 else if(send == SelectButtonC1A2) {
426 LineEditC1A2->setFocus() ;
427 myEditCurrentArgument = LineEditC1A2;
429 mySelection->AddFilter(myVertexFilter) ;
430 SelectionIntoArgument() ;
438 //=================================================================================
439 // function : DeactivateActiveDialog()
441 //=================================================================================
442 void GeometryGUI_LineDlg::DeactivateActiveDialog()
444 if ( GroupConstructors->isEnabled() ) {
445 GroupConstructors->setEnabled(false) ;
446 GroupC1->setEnabled(false) ;
447 GroupButtons->setEnabled(false) ;
448 disconnect( mySelection, 0, this, 0 );
449 myGeomGUI->EraseSimulationShape() ;
450 mySelection->ClearFilters() ;
456 //=================================================================================
457 // function : ActivateThisDialog()
459 //=================================================================================
460 void GeometryGUI_LineDlg::ActivateThisDialog()
462 /* Emit a signal to deactivate the active dialog */
463 myGeomGUI->EmitSignalDeactivateDialog() ;
464 GroupConstructors->setEnabled(true) ;
465 GroupC1->setEnabled(true) ;
466 GroupButtons->setEnabled(true) ;
468 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
469 if( !mySimulationTopoDs.IsNull() )
470 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
476 //=================================================================================
477 // function : enterEvent()
479 //=================================================================================
480 void GeometryGUI_LineDlg::enterEvent(QEvent* e)
482 if ( GroupConstructors->isEnabled() )
484 ActivateThisDialog() ;
488 //=================================================================================
489 // function : closeEvent()
491 //=================================================================================
492 void GeometryGUI_LineDlg::closeEvent( QCloseEvent* e )
494 this->ClickOnCancel() ; /* same than click on cancel button */
497 //=================================================================================
498 // function : AddArrowToSimulation()
499 // purpose : An arrow (cone topology) is added to 'modifiedShape'
500 // : to simulate a vector or an 'oriented line' display. The result is in 'modifiedShape'.
501 // : If an arrow can't be added returns false and 'modifiedShape' isn't modified !
502 //=================================================================================
503 bool GeometryGUI_LineDlg::AddArrowToSimulation( TopoDS_Shape& modifiedShape )
506 /* Try to add a cone simulation shape to show direction of a linear edge */
507 if( myGeomGUI->CreateArrowForLinearEdge( modifiedShape, arrow ) ) {
508 TopoDS_Compound Comp ;
510 B.MakeCompound (Comp);
511 B.Add( Comp, modifiedShape ) ;
512 B.Add( Comp, arrow ) ;
513 modifiedShape = Comp ;