2 // File : GeometryGUI_LineDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_LineDlg.h"
12 #include "GeometryGUI.h"
14 #include <Precision.hxx>
16 #include "QAD_Application.h"
17 #include "QAD_Desktop.h"
18 #include "utilities.h"
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
29 #include <qwhatsthis.h>
34 //=================================================================================
35 // class : GeometryGUI_LineDlg()
36 // purpose : Constructs a GeometryGUI_LineDlg which is a child of 'parent', with the
37 // name 'name' and widget flags set to 'f'.
38 // The dialog will by default be modeless, unless you set 'modal' to
39 // TRUE to construct a modal dialog.
40 //=================================================================================
41 GeometryGUI_LineDlg::GeometryGUI_LineDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
47 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_PV")));
48 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_EDGE")));
51 setName( "GeometryGUI_LineDlg" );
53 setCaption( tr( "GEOM_LINE_TITLE" ) );
54 setSizeGripEnabled( TRUE );
55 GeometryGUI_LineDlgLayout = new QGridLayout( this );
56 GeometryGUI_LineDlgLayout->setSpacing( 6 );
57 GeometryGUI_LineDlgLayout->setMargin( 11 );
59 /***************************************************************/
60 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
61 GroupConstructors->setTitle( tr( "GEOM_LINE" ) );
62 GroupConstructors->setExclusive( TRUE );
63 GroupConstructors->setColumnLayout(0, Qt::Vertical );
64 GroupConstructors->layout()->setSpacing( 0 );
65 GroupConstructors->layout()->setMargin( 0 );
66 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
67 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
68 GroupConstructorsLayout->setSpacing( 6 );
69 GroupConstructorsLayout->setMargin( 11 );
70 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
71 Constructor1->setText( tr( "" ) );
72 Constructor1->setPixmap( image0 );
73 Constructor1->setChecked( TRUE );
74 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
75 Constructor1->setMinimumSize( QSize( 50, 0 ) );
76 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
77 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
79 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
80 GroupConstructorsLayout->addItem( spacer_3, 0, 5 );
81 GeometryGUI_LineDlgLayout->addWidget( GroupConstructors, 0, 0 );
83 /***************************************************************/
84 GroupC1 = new QGroupBox( this, "GroupC1" );
85 GroupC1->setTitle( tr( "GEOM_POINTS" ) );
86 GroupC1->setMinimumSize( QSize( 0, 0 ) );
87 GroupC1->setFrameShape( QGroupBox::Box );
88 GroupC1->setFrameShadow( QGroupBox::Sunken );
89 GroupC1->setColumnLayout(0, Qt::Vertical );
90 GroupC1->layout()->setSpacing( 0 );
91 GroupC1->layout()->setMargin( 0 );
92 GroupC1Layout = new QGridLayout( GroupC1->layout() );
93 GroupC1Layout->setAlignment( Qt::AlignTop );
94 GroupC1Layout->setSpacing( 6 );
95 GroupC1Layout->setMargin( 11 );
96 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
97 SelectButtonC1A2->setText( tr( "" ) );
98 SelectButtonC1A2->setPixmap( image1 );
99 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
100 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
101 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
102 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
103 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
104 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
105 SelectButtonC1A1->setText( tr( "" ) );
106 SelectButtonC1A1->setPixmap( image1 );
107 SelectButtonC1A1->setToggleButton( FALSE );
108 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
109 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
110 TextLabelC1A1->setText( tr( "GEOM_POINT_I" ).arg("1") );
111 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
112 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
113 TextLabelC1A1->setFrameShadow( QLabel::Plain );
114 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
115 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
116 TextLabelC1A2->setText( tr( "GEOM_POINT_I" ).arg("2") );
117 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
118 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
119 GeometryGUI_LineDlgLayout->addWidget( GroupC1, 1, 0 );
121 /***************************************************************/
122 GroupButtons = new QGroupBox( this, "GroupButtons" );
123 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
124 GroupButtons->setTitle( tr( "" ) );
125 GroupButtons->setColumnLayout(0, Qt::Vertical );
126 GroupButtons->layout()->setSpacing( 0 );
127 GroupButtons->layout()->setMargin( 0 );
128 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
129 GroupButtonsLayout->setAlignment( Qt::AlignTop );
130 GroupButtonsLayout->setSpacing( 6 );
131 GroupButtonsLayout->setMargin( 11 );
132 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
133 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
134 buttonCancel->setAutoDefault( TRUE );
135 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
136 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
137 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
138 buttonApply->setAutoDefault( TRUE );
139 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
140 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
141 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
142 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
143 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
144 buttonOk->setAutoDefault( TRUE );
145 buttonOk->setDefault( TRUE );
146 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
147 GeometryGUI_LineDlgLayout->addWidget( GroupButtons, 2, 0 );
149 Init(Sel) ; /* Initialisations */
153 //=================================================================================
154 // function : ~GeometryGUI_LineDlg()
155 // purpose : Destroys the object and frees any allocated resources
156 //=================================================================================
157 GeometryGUI_LineDlg::~GeometryGUI_LineDlg()
159 /* no need to delete child widgets, Qt does it all for us */
163 //=================================================================================
166 //=================================================================================
167 void GeometryGUI_LineDlg::Init( SALOME_Selection* Sel )
173 myConstructorId = 0 ;
174 Constructor1->setChecked( TRUE );
175 myEditCurrentArgument = LineEditC1A1 ;
177 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
178 myPoint1.SetCoord( 0.0, 0.0, 0.0 );
179 myPoint2.SetCoord( 0.0, 0.0, 0.0 );
180 myOkPoint1 = myOkPoint2 = false ;
181 mySimulationTopoDs.Nullify() ;
182 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
184 // TODO : previous selection into argument ?
186 /* Filters definition */
187 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
188 myGeom = GEOM::GEOM_Gen::_narrow(comp);
189 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
190 myEdgeFilter = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
191 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
193 /* signals and slots connections */
194 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
195 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
196 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
197 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
198 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
199 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
201 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
202 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
204 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
205 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
206 /* to close dialog if study change */
207 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
209 /* Move widget on the botton right corner of main widget */
211 myGeomGUI->DefineDlgPosition( this, x, y ) ;
213 this->show() ; /* displays Dialog */
219 //=================================================================================
220 // function : ConstructorsClicked()
221 // purpose : Radio button management
222 //=================================================================================
223 void GeometryGUI_LineDlg::ConstructorsClicked(int constructorId)
225 myGeomGUI->EraseSimulationShape() ;
227 switch (constructorId)
234 myConstructorId = constructorId ;
235 myEditCurrentArgument = LineEditC1A1 ;
236 Constructor1->setChecked( TRUE );
237 LineEditC1A1->setText(tr("")) ;
238 LineEditC1A2->setText(tr("")) ;
239 myOkPoint1 = myOkPoint2 = false ;
240 /* filter for next selections */
241 mySelection->ClearFilters() ;
242 mySelection->AddFilter( myVertexFilter );
243 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
258 //=================================================================================
259 // function : ClickOnOk()
261 //=================================================================================
262 void GeometryGUI_LineDlg::ClickOnOk()
264 this->ClickOnApply() ;
265 this->ClickOnCancel() ;
270 //=================================================================================
271 // function : ClickOnApply()
273 //=================================================================================
274 void GeometryGUI_LineDlg::ClickOnApply()
276 myGeomGUI->EraseSimulationShape() ;
277 mySimulationTopoDs.Nullify() ;
278 switch(myConstructorId)
282 if(myOkPoint1 && myOkPoint2)
283 myGeomGUI->MakeLineAndDisplay( myPoint1, myPoint2 ) ;
300 //=================================================================================
301 // function : ClickOnCancel()
303 //=================================================================================
304 void GeometryGUI_LineDlg::ClickOnCancel()
306 mySelection->ClearFilters() ;
307 myGeomGUI->EraseSimulationShape() ;
308 mySimulationTopoDs.Nullify() ;
309 disconnect( mySelection, 0, this, 0 );
310 myGeomGUI->ResetState() ;
315 //=================================================================================
316 // function : LineEditReturnPressed()
318 //=================================================================================
319 void GeometryGUI_LineDlg::LineEditReturnPressed()
321 QLineEdit* send = (QLineEdit*)sender() ;
322 if( send == LineEditC1A1 )
323 myEditCurrentArgument = LineEditC1A1 ;
324 else if ( send == LineEditC1A2 )
325 myEditCurrentArgument = LineEditC1A2 ;
329 /* User name of object input management */
330 /* If successfull the selection is changed and signal emitted... */
331 /* so SelectionIntoArgument() is automatically called. */
332 const QString objectUserName = myEditCurrentArgument->text() ;
333 QWidget* thisWidget = (QWidget*)this ;
334 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
335 myEditCurrentArgument->setText( objectUserName ) ;
341 //=================================================================================
342 // function : SelectionIntoArgument()
343 // purpose : Called when selection as changed or other case
344 //=================================================================================
345 void GeometryGUI_LineDlg::SelectionIntoArgument()
348 myGeomGUI->EraseSimulationShape() ;
349 mySimulationTopoDs.Nullify() ;
350 QString aString = ""; /* name of selection */
352 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
354 if ( myEditCurrentArgument == LineEditC1A1 ) {
355 myEditCurrentArgument->setText("") ;
358 else if ( myEditCurrentArgument == LineEditC1A2 ) {
359 myEditCurrentArgument->setText("") ;
367 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
370 /* Constructor 1 treatment */
371 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
372 myEditCurrentArgument->setText(aString) ;
375 else if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint(S, myPoint2) ) {
376 myEditCurrentArgument->setText(aString) ;
380 if( myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion() ) {
381 mySimulationTopoDs = BRepBuilderAPI_MakeEdge( myPoint1, myPoint2 ).Shape();
382 /* Try to add an arrow at simulation shape */
383 bool notNeedToTest = this->AddArrowToSimulation(mySimulationTopoDs) ;
384 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
389 //=================================================================================
390 // function : SetEditCurrentArgument()
392 //=================================================================================
393 void GeometryGUI_LineDlg::SetEditCurrentArgument()
395 QPushButton* send = (QPushButton*)sender();
396 mySelection->ClearFilters() ;
397 switch (myConstructorId)
399 case 0: /* default constructor */
401 if(send == SelectButtonC1A1) {
402 LineEditC1A1->setFocus() ;
403 myEditCurrentArgument = LineEditC1A1;
405 else if(send == SelectButtonC1A2) {
406 LineEditC1A2->setFocus() ;
407 myEditCurrentArgument = LineEditC1A2;
409 mySelection->AddFilter(myVertexFilter) ;
410 SelectionIntoArgument() ;
418 //=================================================================================
419 // function : DeactivateActiveDialog()
421 //=================================================================================
422 void GeometryGUI_LineDlg::DeactivateActiveDialog()
424 if ( GroupConstructors->isEnabled() ) {
425 GroupConstructors->setEnabled(false) ;
426 GroupC1->setEnabled(false) ;
427 GroupButtons->setEnabled(false) ;
428 disconnect( mySelection, 0, this, 0 );
429 myGeomGUI->EraseSimulationShape() ;
430 mySelection->ClearFilters() ;
436 //=================================================================================
437 // function : ActivateThisDialog()
439 //=================================================================================
440 void GeometryGUI_LineDlg::ActivateThisDialog()
442 /* Emit a signal to deactivate the active dialog */
443 myGeomGUI->EmitSignalDeactivateDialog() ;
444 GroupConstructors->setEnabled(true) ;
445 GroupC1->setEnabled(true) ;
446 GroupButtons->setEnabled(true) ;
448 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
449 if( !mySimulationTopoDs.IsNull() )
450 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
456 //=================================================================================
457 // function : enterEvent()
459 //=================================================================================
460 void GeometryGUI_LineDlg::enterEvent(QEvent* e)
462 if ( GroupConstructors->isEnabled() )
464 ActivateThisDialog() ;
468 //=================================================================================
469 // function : closeEvent()
471 //=================================================================================
472 void GeometryGUI_LineDlg::closeEvent( QCloseEvent* e )
474 this->ClickOnCancel() ; /* same than click on cancel button */
477 //=================================================================================
478 // function : AddArrowToSimulation()
479 // purpose : An arrow (cone topology) is added to 'modifiedShape'
480 // : to simulate a vector or an 'oriented line' display. The result is in 'modifiedShape'.
481 // : If an arrow can't be added returns false and 'modifiedShape' isn't modified !
482 //=================================================================================
483 bool GeometryGUI_LineDlg::AddArrowToSimulation( TopoDS_Shape& modifiedShape )
486 /* Try to add a cone simulation shape to show direction of a linear edge */
487 if( myGeomGUI->CreateArrowForLinearEdge( modifiedShape, arrow ) ) {
488 TopoDS_Compound Comp ;
490 B.MakeCompound (Comp);
491 B.Add( Comp, modifiedShape ) ;
492 B.Add( Comp, arrow ) ;
493 modifiedShape = Comp ;