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 : GenerationGUI_PrismDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "GenerationGUI_PrismDlg.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 <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : GenerationGUI_PrismDlg()
48 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PRISM" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PRISM_2P" ) ) );
62 setWindowTitle( tr( "GEOM_EXTRUSION_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_EXTRUSION" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image2 );
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 mainFrame()->RadioButton1->setChecked( true );
72 myBothway = myBothway2 = false;
74 GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
75 GroupPoints->GroupBox1->setTitle( tr( "GEOM_EXTRUSION_BSV" ) );
76 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE" ) );
77 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
78 GroupPoints->TextLabel3->setText( tr( "GEOM_HEIGHT" ) );
79 GroupPoints->PushButton1->setIcon( image1 );
80 GroupPoints->PushButton2->setIcon( image1 );
81 GroupPoints->LineEdit1->setReadOnly( true );
82 GroupPoints->LineEdit2->setReadOnly( true );
83 GroupPoints->CheckButton1->setText( tr( "GEOM_BOTHWAY" ) );
84 GroupPoints->CheckButton1->setChecked( myBothway );
85 GroupPoints->CheckButton2->setText( tr( "GEOM_REVERSE" ) );
87 GroupPoints2 = new DlgRef_3Sel1Check( centralWidget() );
89 GroupPoints2->GroupBox1->setTitle( tr( "GEOM_EXTRUSION_BSV_2P" ) );
90 GroupPoints2->TextLabel1->setText( tr( "GEOM_BASE" ) );
91 GroupPoints2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
92 GroupPoints2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
93 GroupPoints2->PushButton1->setIcon( image1 );
94 GroupPoints2->PushButton2->setIcon( image1 );
95 GroupPoints2->PushButton3->setIcon( image1 );
96 GroupPoints2->CheckButton1->setText( tr( "GEOM_BOTHWAY" ) );
97 GroupPoints2->CheckButton1->setChecked( myBothway2 );
99 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
100 layout->setMargin( 0 ); layout->setSpacing( 6 );
101 layout->addWidget( GroupPoints );
102 layout->addWidget( GroupPoints2 );
103 /***************************************************************/
105 setHelpFileName( "create_extrusion_page.html" );
111 //=================================================================================
112 // function : ~GenerationGUI_PrismDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
117 // no need to delete child widgets, Qt does it all for us
121 //=================================================================================
124 //=================================================================================
125 void GenerationGUI_PrismDlg::Init()
128 myEditCurrentArgument = GroupPoints->LineEdit1;
129 GroupPoints->LineEdit1->setReadOnly( true );
130 GroupPoints->LineEdit2->setReadOnly( true );
132 GroupPoints2->LineEdit1->setReadOnly( true );
133 GroupPoints2->LineEdit2->setReadOnly( true );
134 GroupPoints2->LineEdit3->setReadOnly( true );
136 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
137 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
139 /* Get setting of step value from file configuration */
140 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
141 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
143 /* min, max, step and decimals for spin boxes & initial values */
144 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
145 GroupPoints->SpinBox_DX->setValue( 100.0 );
147 /* signals and slots connections */
148 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
149 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
151 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
153 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
156 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
157 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
159 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
161 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
164 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( onBothway() ) );
165 connect( GroupPoints->CheckButton2, SIGNAL( toggled( bool ) ), this, SLOT( onReverse() ) );
167 connect( GroupPoints2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
168 connect( GroupPoints2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
169 connect( GroupPoints2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
170 connect( GroupPoints2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( onBothway2() ) );
172 connect( GroupPoints2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
173 connect( GroupPoints2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
174 connect( GroupPoints2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
177 connect( myGeomGUI->getApp()->selectionMgr(),
178 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
180 initName( tr( "GEOM_EXTRUSION" ) );
182 ConstructorsClicked( 0 );
186 //=================================================================================
187 // function : ConstructorsClicked()
188 // purpose : Radio button management
189 //=================================================================================
190 void GenerationGUI_PrismDlg::ConstructorsClicked( int constructorId )
193 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
195 switch ( constructorId ) {
198 globalSelection( GEOM_ALLSHAPES );
200 GroupPoints2->hide();
203 myEditCurrentArgument = GroupPoints->LineEdit1;
204 GroupPoints->LineEdit1->setText( GroupPoints2->LineEdit1->text() ); // keep base
205 GroupPoints->LineEdit2->setText( "" );
206 myVec = GEOM::GEOM_Object::_nil();
213 globalSelection( GEOM_ALLSHAPES );
216 GroupPoints2->show();
218 myEditCurrentArgument = GroupPoints2->LineEdit1;
219 GroupPoints2->LineEdit1->setText( GroupPoints->LineEdit1->text() ); // keep base
220 GroupPoints2->LineEdit2->setText( "" );
221 GroupPoints2->LineEdit3->setText( "" );
222 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
223 myOkPnt1 = myOkPnt2 = false;
229 qApp->processEvents();
231 resize( minimumSize() );
233 myEditCurrentArgument->setFocus();
234 connect( myGeomGUI->getApp()->selectionMgr(),
235 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
238 SelectionIntoArgument();
242 //=================================================================================
243 // function : ClickOnOk()
245 //=================================================================================
246 void GenerationGUI_PrismDlg::ClickOnOk()
248 if ( ClickOnApply() )
253 //=================================================================================
254 // function : ClickOnApply()
256 //=================================================================================
257 bool GenerationGUI_PrismDlg::ClickOnApply()
267 //=================================================================================
268 // function : SelectionIntoArgument()
269 // purpose : Called when selection has changed
270 //=================================================================================
271 void GenerationGUI_PrismDlg::SelectionIntoArgument()
274 myEditCurrentArgument->setText( "" );
276 if ( getConstructorId() == 0 ) {
278 if ( IObjectCount() != 1 ) {
279 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
281 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
287 Standard_Boolean testResult = Standard_False;
288 GEOM::GEOM_Object_var aSelectedObject =
289 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
296 QString aName = GEOMBase::GetName( aSelectedObject );
297 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
298 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
299 TColStd_IndexedMapOfInteger aMap;
300 aSelMgr->GetIndexes( firstIObject(), aMap );
301 if ( aMap.Extent() == 1 ) {
302 int anIndex = aMap( 1 );
303 aName.append( ":edge_" + QString::number( anIndex ) );
305 //Find SubShape Object in Father
306 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
308 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
309 GEOM::GEOM_IShapesOperations_var aShapesOp =
310 getGeomEngine()->GetIShapesOperations( getStudyId() );
311 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
314 aSelectedObject = aFindedObject; // get Object from study
318 if ( aShape.ShapeType() != TopAbs_EDGE && myEditCurrentArgument == GroupPoints->LineEdit2 ) {
319 aSelectedObject = GEOM::GEOM_Object::_nil();
326 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
327 myBase = aSelectedObject;
330 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && myOk ) {
332 myVec = aSelectedObject;
334 myEditCurrentArgument->setText( aName );
336 else { // getConstructorId()==1 - extrusion using 2 points
337 if ( IObjectCount() != 1 ) {
338 if ( myEditCurrentArgument == GroupPoints2->LineEdit1 )
340 else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 ) {
341 myPoint1 = GEOM::GEOM_Object::_nil();
344 else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 ) {
345 myPoint2 = GEOM::GEOM_Object::_nil();
352 Standard_Boolean testResult = Standard_False;
353 GEOM::GEOM_Object_var aSelectedObject =
354 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
356 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
359 QString aName = GEOMBase::GetName( aSelectedObject );
362 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
363 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
364 TColStd_IndexedMapOfInteger aMap;
365 aSelMgr->GetIndexes( firstIObject(), aMap );
366 if (aMap.Extent() == 1) {
367 int anIndex = aMap(1);
368 aName.append( ":vertex_" + QString::number( anIndex ) );
370 //Find SubShape Object in Father
371 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
373 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
374 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
375 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
378 aSelectedObject = aFindedObject;
382 if ( ( aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit2 ) ||
383 ( aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit3 ) ) {
384 aSelectedObject = GEOM::GEOM_Object::_nil();
391 myEditCurrentArgument->setText( aName );
393 if ( myEditCurrentArgument == GroupPoints2->LineEdit1 ) {
395 myBase = aSelectedObject;
397 else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 && myOk ) {
399 myPoint1 = aSelectedObject;
401 else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 && myOk ) {
403 myPoint2 = aSelectedObject;
411 //=================================================================================
412 // function : SetEditCurrentArgument()
414 //=================================================================================
415 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
417 QPushButton* send = (QPushButton*)sender();
418 globalSelection( GEOM_ALLSHAPES );
420 if ( send == GroupPoints->PushButton1 ) {
421 GroupPoints->LineEdit1->setFocus();
422 myEditCurrentArgument = GroupPoints->LineEdit1;
424 else if ( send == GroupPoints->PushButton2 ) {
425 GroupPoints->LineEdit2->setFocus();
426 myEditCurrentArgument = GroupPoints->LineEdit2;
427 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
429 else if ( send == GroupPoints2->PushButton1 ) {
430 GroupPoints2->LineEdit1->setFocus();
431 myEditCurrentArgument = GroupPoints2->LineEdit1;
433 else if ( send == GroupPoints2->PushButton2 ) {
434 GroupPoints2->LineEdit2->setFocus();
435 myEditCurrentArgument = GroupPoints2->LineEdit2;
436 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
438 else if ( send == GroupPoints2->PushButton3 ) {
439 GroupPoints2->LineEdit3->setFocus();
440 myEditCurrentArgument = GroupPoints2->LineEdit3;
441 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
444 myEditCurrentArgument->setFocus();
445 SelectionIntoArgument();
449 //=================================================================================
450 // function : LineEditReturnPressed()
452 //=================================================================================
453 void GenerationGUI_PrismDlg::LineEditReturnPressed()
455 QLineEdit* send = (QLineEdit*)sender();
456 if ( send == GroupPoints->LineEdit1 ||
457 send == GroupPoints->LineEdit2 ||
458 send == GroupPoints2->LineEdit1 ||
459 send == GroupPoints2->LineEdit2 ||
460 send == GroupPoints2->LineEdit3 ) {
461 myEditCurrentArgument = send;
462 GEOMBase_Skeleton::LineEditReturnPressed();
466 //=================================================================================
467 // function : enterEvent()
468 // purpose : when mouse enter onto the QWidget
469 //=================================================================================
470 void GenerationGUI_PrismDlg::enterEvent( QEvent* )
472 if ( !mainFrame()->GroupConstructors->isEnabled() )
473 ActivateThisDialog();
477 //=================================================================================
478 // function : ActivateThisDialog()
480 //=================================================================================
481 void GenerationGUI_PrismDlg::ActivateThisDialog()
483 GEOMBase_Skeleton::ActivateThisDialog();
485 connect( myGeomGUI->getApp()->selectionMgr(),
486 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
488 ConstructorsClicked( getConstructorId() );
492 //=================================================================================
493 // function : ValueChangedInSpinBox()
495 //=================================================================================
496 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
502 //=================================================================================
503 // function : getHeight()
505 //=================================================================================
506 double GenerationGUI_PrismDlg::getHeight() const
508 return GroupPoints->SpinBox_DX->value();
511 //=================================================================================
512 // function : createOperation
514 //=================================================================================
515 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
517 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
520 //=================================================================================
521 // function : isValid
523 //=================================================================================
524 bool GenerationGUI_PrismDlg::isValid( QString& )
526 if ( getConstructorId() == 0 )
527 return ( myOkBase && myOkVec ); // by vector and height
529 return ( myOkBase && myOkPnt1 && myOkPnt2 ); // by two points
532 //=================================================================================
533 // function : execute
535 //=================================================================================
536 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
538 GEOM::GEOM_Object_var anObj;
540 switch ( getConstructorId() ) {
543 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
544 MakePrismVecH( myBase, myVec, getHeight() );
547 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
548 MakePrismVecH2Ways( myBase, myVec, getHeight() );
553 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
554 MakePrismTwoPnt( myBase, myPoint1, myPoint2 );
557 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
558 MakePrismTwoPnt2Ways( myBase, myPoint1, myPoint2 );
562 if ( !anObj->_is_nil() )
563 objects.push_back( anObj._retn() );
569 //=================================================================================
570 // function : onReverse()
572 //=================================================================================
573 void GenerationGUI_PrismDlg::onReverse()
575 double anOldValue = GroupPoints->SpinBox_DX->value();
576 GroupPoints->SpinBox_DX->setValue( -anOldValue );
579 //=================================================================================
580 // function : onBothway()
582 //=================================================================================
583 void GenerationGUI_PrismDlg::onBothway()
585 bool anOldValue = myBothway;
586 myBothway = !anOldValue;
587 GroupPoints->CheckButton2->setEnabled( !myBothway );
591 void GenerationGUI_PrismDlg::onBothway2()
593 bool anOldValue = myBothway2;
594 myBothway2 = !anOldValue;
598 //=================================================================================
599 // function : addSubshapeToStudy
600 // purpose : virtual method to add new SubObjects if local selection
601 //=================================================================================
602 void GenerationGUI_PrismDlg::addSubshapesToStudy()
604 QMap<QString, GEOM::GEOM_Object_var> objMap;
606 switch ( getConstructorId() ) {
608 objMap[GroupPoints->LineEdit2->text()] = myVec;
611 objMap[GroupPoints2->LineEdit2->text()] = myPoint1;
612 objMap[GroupPoints2->LineEdit3->text()] = myPoint2;
615 addSubshapesToFather( objMap );