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_OrientationDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_OrientationDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
38 #include <TopoDS_Compound.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRepBuilderAPI_MakeEdge.hxx>
41 #include <BRepAdaptor_Surface.hxx>
42 #include <TopExp_Explorer.hxx>
44 #include <qbuttongroup.h>
45 #include <qcheckbox.h>
46 #include <qgroupbox.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qradiobutton.h>
54 #include <qvalidator.h>
55 #include <qwhatsthis.h>
59 //=================================================================================
60 // class : GeometryGUI_OrientationDlg()
61 // purpose : Constructs a GeometryGUI_OrientationDlg which is a child of 'parent', with the
62 // name 'name' and widget flags set to 'f'.
63 // The dialog will by default be modeless, unless you set 'modal' to
64 // TRUE to construct a modal dialog.
65 //=================================================================================
66 GeometryGUI_OrientationDlg::GeometryGUI_OrientationDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
67 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
69 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_ORIENTATION")));
70 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
72 setName( "GeometryGUI_OrientationDlg" );
74 setCaption( tr( "GEOM_ORIENTATION_TITLE" ) );
75 setSizeGripEnabled( TRUE );
76 GeometryGUI_OrientationDlgLayout = new QGridLayout( this );
77 GeometryGUI_OrientationDlgLayout->setSpacing( 6 );
78 GeometryGUI_OrientationDlgLayout->setMargin( 11 );
80 /***************************************************************/
81 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
82 GroupConstructors->setTitle( tr( "GEOM_ORIENTATION" ) );
83 GroupConstructors->setExclusive( TRUE );
84 GroupConstructors->setColumnLayout(0, Qt::Vertical );
85 GroupConstructors->layout()->setSpacing( 0 );
86 GroupConstructors->layout()->setMargin( 0 );
87 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
88 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
89 GroupConstructorsLayout->setSpacing( 6 );
90 GroupConstructorsLayout->setMargin( 11 );
91 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
92 Constructor1->setText( tr( "" ) );
93 Constructor1->setPixmap( image0 );
94 Constructor1->setChecked( TRUE );
95 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
96 Constructor1->setMinimumSize( QSize( 50, 0 ) );
97 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
98 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 GroupConstructorsLayout->addItem( spacer, 0, 1 );
100 GeometryGUI_OrientationDlgLayout->addWidget( GroupConstructors, 0, 0 );
102 /***************************************************************/
103 GroupButtons = new QGroupBox( this, "GroupButtons" );
104 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
105 GroupButtons->setTitle( tr( "" ) );
106 GroupButtons->setColumnLayout(0, Qt::Vertical );
107 GroupButtons->layout()->setSpacing( 0 );
108 GroupButtons->layout()->setMargin( 0 );
109 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
110 GroupButtonsLayout->setAlignment( Qt::AlignTop );
111 GroupButtonsLayout->setSpacing( 6 );
112 GroupButtonsLayout->setMargin( 11 );
113 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
114 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
115 buttonCancel->setAutoDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
117 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
118 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
119 buttonApply->setAutoDefault( TRUE );
120 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
121 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
122 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
123 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
124 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
125 buttonOk->setAutoDefault( TRUE );
126 buttonOk->setDefault( TRUE );
127 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
128 GeometryGUI_OrientationDlgLayout->addWidget( GroupButtons, 2, 0 );
130 /***************************************************************/
131 GroupC1 = new QGroupBox( this, "GroupC1" );
132 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
133 GroupC1->setMinimumSize( QSize( 0, 0 ) );
134 GroupC1->setFrameShape( QGroupBox::Box );
135 GroupC1->setFrameShadow( QGroupBox::Sunken );
136 GroupC1->setColumnLayout(0, Qt::Vertical );
137 GroupC1->layout()->setSpacing( 0 );
138 GroupC1->layout()->setMargin( 0 );
139 GroupC1Layout = new QGridLayout( GroupC1->layout() );
140 GroupC1Layout->setAlignment( Qt::AlignTop );
141 GroupC1Layout->setSpacing( 6 );
142 GroupC1Layout->setMargin( 11 );
143 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
144 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
146 /* Spin box construction */
147 SpinBox_C1A2 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A2" ) ;
148 GroupC1Layout->addWidget( SpinBox_C1A2, 1, 2 );
150 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
151 SelectButtonC1A1->setText( tr( "" ) );
152 SelectButtonC1A1->setPixmap( image1 );
153 SelectButtonC1A1->setToggleButton( FALSE );
154 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
155 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
156 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
157 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
158 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
159 TextLabelC1A1->setFrameShadow( QLabel::Plain );
160 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
161 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
162 TextLabelC1A2->setText( tr( "GEOM_VECTOR_LENGTH" ) );
163 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
164 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
165 CheckBoxReverse = new QCheckBox( GroupC1, "CheckBoxReverse" );
166 CheckBoxReverse->setText( tr( "GEOM_ORIENTATION_OPT" ) );
167 GroupC1Layout->addMultiCellWidget( CheckBoxReverse, 2, 2, 0, 2 );
168 GeometryGUI_OrientationDlgLayout->addWidget( GroupC1, 1, 0 );
169 /***************************************************************/
171 Init(Sel) ; /* Initialisations */
175 //=================================================================================
176 // function : ~GeometryGUI_OrientationDlg()
177 // purpose : Destroys the object and frees any allocated resources
178 //=================================================================================
179 GeometryGUI_OrientationDlg::~GeometryGUI_OrientationDlg()
181 // no need to delete child widgets, Qt does it all for us
185 //=================================================================================
188 //=================================================================================
189 void GeometryGUI_OrientationDlg::Init( SALOME_Selection* Sel )
193 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
194 step = St.toDouble() ;
196 /* min, max, step and decimals for spin boxes */
197 SpinBox_C1A2->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
198 SpinBox_C1A2->SetValue( 25.0 ) ; /* = myLength */
201 myConstructorId = 0 ;
202 Constructor1->setChecked( TRUE );
203 CheckBoxReverse->setChecked( FALSE );
204 myEditCurrentArgument = LineEditC1A1 ;
206 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
211 mySimulationTopoDs.Nullify() ;
213 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
215 // TODO : previous selection into argument ?
217 /* Filter definitions */
218 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
219 myGeom = GEOM::GEOM_Gen::_narrow(comp);
221 /* signals and slots connections */
222 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
223 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
224 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
225 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
226 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
227 connect( CheckBoxReverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseOrientation(int) ) ) ;
229 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
230 connect( SpinBox_C1A2, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
232 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
233 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
234 /* to close dialog if study change */
235 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
237 /* Move widget on the botton right corner of main widget */
239 myGeomGUI->DefineDlgPosition( this, x, y ) ;
241 this->show() ; /* displays Dialog */
247 //=================================================================================
248 // function : ConstructorsClicked()
249 // purpose : Radio button management
250 //=================================================================================
251 void GeometryGUI_OrientationDlg::ConstructorsClicked(int constructorId)
256 //=================================================================================
257 // function : ClickOnOk()
259 //=================================================================================
260 void GeometryGUI_OrientationDlg::ClickOnOk()
262 this->ClickOnApply() ;
263 this->ClickOnCancel() ;
268 //=================================================================================
269 // function : ClickOnApply()
271 //=================================================================================
272 void GeometryGUI_OrientationDlg::ClickOnApply()
274 /* Leave simulation display in this method ! */
275 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
277 switch(myConstructorId)
281 if(myOkShape && CheckBoxReverse->isChecked() && myOkLength == true ) {
282 myGeomGUI->MakeOrientationChangeAndDisplay( myGeomShape ) ;
283 CheckBoxReverse->setChecked( FALSE );
293 //=================================================================================
294 // function : ClickOnCancel()
296 //=================================================================================
297 void GeometryGUI_OrientationDlg::ClickOnCancel()
299 myGeomGUI->EraseSimulationShape() ;
300 mySimulationTopoDs.Nullify() ;
301 disconnect( mySelection, 0, this, 0 );
302 myGeomGUI->ResetState() ;
307 //=================================================================================
308 // function : LineEditReturnPressed()
310 //=================================================================================
311 void GeometryGUI_OrientationDlg::LineEditReturnPressed()
313 QLineEdit* send = (QLineEdit*)sender();
314 if( send == LineEditC1A1 )
315 myEditCurrentArgument = LineEditC1A1 ;
319 /* User name of object input management */
320 /* If successfull the selection is changed and signal emitted... */
321 /* so SelectionIntoArgument() is automatically called. */
322 const QString objectUserName = myEditCurrentArgument->text() ;
323 QWidget* thisWidget = (QWidget*)this ;
324 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
325 myEditCurrentArgument->setText( objectUserName ) ;
332 //=================================================================================
333 // function : SelectionIntoArgument()
334 // purpose : Called when selection as changed or other case
335 //=================================================================================
336 void GeometryGUI_OrientationDlg::SelectionIntoArgument()
338 myGeomGUI->EraseSimulationShape() ;
339 this->mySimulationTopoDs.Nullify() ;
341 /* Name of future selection */
342 QString aString = "";
344 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
346 if ( myEditCurrentArgument == LineEditC1A1 ) {
347 LineEditC1A1->setText("") ;
348 this->myOkShape = false ;
355 Standard_Boolean testResult ;
356 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
357 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
361 if ( myEditCurrentArgument == LineEditC1A1 ) {
362 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
365 LineEditC1A1->setText(aString) ;
370 if( myOkShape && myOkLength ) {
371 MakeOrientationSimulationAndDisplay( this->myShape, this->myLength ) ;
377 //=================================================================================
378 // function : SetEditCurrentArgument()
380 //=================================================================================
381 void GeometryGUI_OrientationDlg::SetEditCurrentArgument()
383 QPushButton* send = (QPushButton*)sender();
384 switch (myConstructorId)
386 case 0: /* default constructor */
388 if(send == SelectButtonC1A1) {
389 LineEditC1A1->setFocus() ;
390 myEditCurrentArgument = LineEditC1A1 ;
392 SelectionIntoArgument() ;
400 //=================================================================================
401 // function : ValueChangedInSpinBox()
403 //=================================================================================
404 void GeometryGUI_OrientationDlg::ValueChangedInSpinBox( double newValue )
406 myGeomGUI->EraseSimulationShape() ;
407 mySimulationTopoDs.Nullify() ;
409 QObject* send = (QObject*)sender() ;
410 if( send == SpinBox_C1A2 ) {
411 this->myLength = newValue ;
415 if ( myConstructorId == 0 && myOkShape && myOkLength == true ) {
416 MakeOrientationSimulationAndDisplay( this->myShape, this->myLength ) ;
422 //=================================================================================
423 // function : DeactivateActiveDialog()
425 //=================================================================================
426 void GeometryGUI_OrientationDlg::DeactivateActiveDialog()
428 if ( GroupConstructors->isEnabled() ) {
429 GroupConstructors->setEnabled(false) ;
430 GroupButtons->setEnabled(false) ;
431 GroupC1->setEnabled(false) ;
432 disconnect( mySelection, 0, this, 0 );
433 myGeomGUI->EraseSimulationShape() ;
439 //=================================================================================
440 // function : ActivateThisDialog()
442 //=================================================================================
443 void GeometryGUI_OrientationDlg::ActivateThisDialog()
445 /* Emit a signal to deactivate the active dialog */
446 myGeomGUI->EmitSignalDeactivateDialog() ;
447 GroupConstructors->setEnabled(true) ;
448 GroupButtons->setEnabled(true) ;
449 GroupC1->setEnabled(true) ;
451 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
452 if( !mySimulationTopoDs.IsNull() )
453 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
459 //=================================================================================
460 // function : enterEvent()
462 //=================================================================================
463 void GeometryGUI_OrientationDlg::enterEvent(QEvent* e)
465 if ( GroupConstructors->isEnabled() )
467 ActivateThisDialog() ;
473 //=================================================================================
474 // function : closeEvent()
476 //=================================================================================
477 void GeometryGUI_OrientationDlg::closeEvent( QCloseEvent* e )
479 /* same than click on cancel button */
480 this->ClickOnCancel() ;
486 //===========================================================================================
487 // function : ReverseOrientation()
489 //===========================================================================================
490 void GeometryGUI_OrientationDlg::ReverseOrientation(int state)
492 if( this->myOkShape && myOkLength == true ) {
493 MakeOrientationSimulationAndDisplay( this->myShape, this-> myLength ) ;
499 //===========================================================================================
500 // function : MakeOrientationSimulationAndDisplay()
501 // purpose : Create 'aCompound1' and 'aCompound2' each contains edges oriented
502 // : respectively FORWARD and REVERSE for all faces of 'aTopoDS'
503 // : These edges represent normal vectors on faces of 'aTopoDS'
504 // : For a unique edge an arrow is displayed to show its orientation.
505 //===========================================================================================
506 void GeometryGUI_OrientationDlg::MakeOrientationSimulationAndDisplay(const TopoDS_Shape& aTopoDS, Standard_Real length )
508 myGeomGUI->EraseSimulationShape() ;
509 mySimulationTopoDs.Nullify() ;
511 TopoDS_Compound aCompound1, aCompound2 ;
512 TopoDS_Compound NullComp ;
513 BRep_Builder aBuilder1, aBuilder2;
514 aCompound1 = aCompound2 = NullComp ;
515 aBuilder1.MakeCompound(aCompound1) ;
516 aBuilder2.MakeCompound(aCompound2) ;
518 if( aTopoDS.IsNull() )
521 /* Case of an edge */
522 if( aTopoDS.ShapeType() == TopAbs_EDGE ) {
523 /* Try to display a cone simulation shape to show direction of edge */
524 TopoDS_Shape tmpShape = aTopoDS ;
525 if( this->CheckBoxReverse->isChecked() ) {
526 if( aTopoDS.Orientation() == TopAbs_FORWARD)
527 tmpShape.Orientation(TopAbs_REVERSED) ;
529 tmpShape.Orientation(TopAbs_FORWARD) ;
531 if( myGeomGUI->CreateArrowForLinearEdge( tmpShape, mySimulationTopoDs ) ) {
532 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
540 TopExp_Explorer ex( aTopoDS, TopAbs_FACE );
544 const TopoDS_Face& F = TopoDS::Face(ex.Current());
545 /* find the center of the minmax */
546 BRepAdaptor_Surface SF(F);
547 Standard_Real u, v, x;
549 u = SF.FirstUParameter();
550 x = SF.LastUParameter();
551 if ( Precision::IsInfinite(u) ) {
552 if( Precision::IsInfinite(x) ) u = 0.0 ; else u = x ;
554 else if ( !Precision::IsInfinite(x) )
557 v = SF.FirstVParameter();
558 x = SF.LastVParameter();
559 if ( Precision::IsInfinite(v) ) {
560 if ( Precision::IsInfinite(x) ) v = 0.0 ; else v = x ;
562 else if ( !Precision::IsInfinite(x) )
565 SF.D1( u, v, P1, V1, V2 );
569 V.Multiply( length/x );
571 V.SetCoord( length/2.0, 0.0, 0.0 ) ;
572 MESSAGE ("Null normal in Orientation " << endl ) ;
576 /* test orientation of each face and displays forward (aCompound1) */
577 if( F.Orientation() == TopAbs_FORWARD )
581 BRepBuilderAPI_MakeEdge anEdge(P1, P2) ;
582 aBuilder1.Add( aCompound1, anEdge ) ;
585 /* test orientation of each face and displays forward (aCompound2) */
586 if( F.Orientation() == TopAbs_FORWARD )
590 anEdge = BRepBuilderAPI_MakeEdge(P1, P2) ;
591 aBuilder2.Add( aCompound2, anEdge ) ;
597 /* display simulation compounds */
598 if( test > 0 && this->CheckBoxReverse->isChecked() ) {
599 mySimulationTopoDs = aCompound1 ;
601 else if ( test > 0 && !CheckBoxReverse->isChecked() ) {
602 mySimulationTopoDs = aCompound2 ;
604 if(!mySimulationTopoDs.IsNull() )
605 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;