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() ) );
160 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
162 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( onBothway() ) );
163 connect( GroupPoints->CheckButton2, SIGNAL( toggled( bool ) ), this, SLOT( onReverse() ) );
165 connect( GroupPoints2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
166 connect( GroupPoints2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
167 connect( GroupPoints2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
168 connect( GroupPoints2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( onBothway2() ) );
170 connect( GroupPoints2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
171 connect( GroupPoints2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
172 connect( GroupPoints2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
175 connect( myGeomGUI->getApp()->selectionMgr(),
176 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
178 initName( tr( "GEOM_EXTRUSION" ) );
180 ConstructorsClicked( 0 );
183 //=================================================================================
184 // function : SetDoubleSpinBoxStep()
185 // purpose : Double spin box management
186 //=================================================================================
187 void GenerationGUI_PrismDlg::SetDoubleSpinBoxStep( double step )
189 GroupPoints->SpinBox_DX->setSingleStep(step);
193 //=================================================================================
194 // function : ConstructorsClicked()
195 // purpose : Radio button management
196 //=================================================================================
197 void GenerationGUI_PrismDlg::ConstructorsClicked( int constructorId )
200 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
202 switch ( constructorId ) {
205 globalSelection( GEOM_ALLSHAPES );
207 GroupPoints2->hide();
210 myEditCurrentArgument = GroupPoints->LineEdit1;
211 GroupPoints->LineEdit1->setText( GroupPoints2->LineEdit1->text() ); // keep base
212 GroupPoints->LineEdit2->setText( "" );
213 myVec = GEOM::GEOM_Object::_nil();
220 globalSelection( GEOM_ALLSHAPES );
223 GroupPoints2->show();
225 myEditCurrentArgument = GroupPoints2->LineEdit1;
226 GroupPoints2->LineEdit1->setText( GroupPoints->LineEdit1->text() ); // keep base
227 GroupPoints2->LineEdit2->setText( "" );
228 GroupPoints2->LineEdit3->setText( "" );
229 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
230 myOkPnt1 = myOkPnt2 = false;
236 qApp->processEvents();
238 resize( minimumSize() );
240 myEditCurrentArgument->setFocus();
241 connect( myGeomGUI->getApp()->selectionMgr(),
242 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
245 SelectionIntoArgument();
249 //=================================================================================
250 // function : ClickOnOk()
252 //=================================================================================
253 void GenerationGUI_PrismDlg::ClickOnOk()
255 if ( ClickOnApply() )
260 //=================================================================================
261 // function : ClickOnApply()
263 //=================================================================================
264 bool GenerationGUI_PrismDlg::ClickOnApply()
274 //=================================================================================
275 // function : SelectionIntoArgument()
276 // purpose : Called when selection has changed
277 //=================================================================================
278 void GenerationGUI_PrismDlg::SelectionIntoArgument()
281 myEditCurrentArgument->setText( "" );
283 if ( getConstructorId() == 0 ) {
285 if ( IObjectCount() != 1 ) {
286 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
288 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
294 Standard_Boolean testResult = Standard_False;
295 GEOM::GEOM_Object_var aSelectedObject =
296 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
303 QString aName = GEOMBase::GetName( aSelectedObject );
304 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
305 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
306 TColStd_IndexedMapOfInteger aMap;
307 aSelMgr->GetIndexes( firstIObject(), aMap );
308 if ( aMap.Extent() == 1 ) {
309 int anIndex = aMap( 1 );
310 aName.append( ":edge_" + QString::number( anIndex ) );
312 //Find SubShape Object in Father
313 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
315 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
316 GEOM::GEOM_IShapesOperations_var aShapesOp =
317 getGeomEngine()->GetIShapesOperations( getStudyId() );
318 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
321 aSelectedObject = aFindedObject; // get Object from study
325 if ( aShape.ShapeType() != TopAbs_EDGE && myEditCurrentArgument == GroupPoints->LineEdit2 ) {
326 aSelectedObject = GEOM::GEOM_Object::_nil();
333 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
334 myBase = aSelectedObject;
337 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && myOk ) {
339 myVec = aSelectedObject;
341 myEditCurrentArgument->setText( aName );
343 else { // getConstructorId()==1 - extrusion using 2 points
344 if ( IObjectCount() != 1 ) {
345 if ( myEditCurrentArgument == GroupPoints2->LineEdit1 )
347 else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 ) {
348 myPoint1 = GEOM::GEOM_Object::_nil();
351 else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 ) {
352 myPoint2 = GEOM::GEOM_Object::_nil();
359 Standard_Boolean testResult = Standard_False;
360 GEOM::GEOM_Object_var aSelectedObject =
361 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
363 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
366 QString aName = GEOMBase::GetName( aSelectedObject );
369 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
370 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
371 TColStd_IndexedMapOfInteger aMap;
372 aSelMgr->GetIndexes( firstIObject(), aMap );
373 if (aMap.Extent() == 1) {
374 int anIndex = aMap(1);
375 aName.append( ":vertex_" + QString::number( anIndex ) );
377 //Find SubShape Object in Father
378 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
380 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
381 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
382 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
385 aSelectedObject = aFindedObject;
389 if ( ( aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit2 ) ||
390 ( aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit3 ) ) {
391 aSelectedObject = GEOM::GEOM_Object::_nil();
398 myEditCurrentArgument->setText( aName );
400 if ( myEditCurrentArgument == GroupPoints2->LineEdit1 ) {
402 myBase = aSelectedObject;
404 else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 && myOk ) {
406 myPoint1 = aSelectedObject;
408 else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 && myOk ) {
410 myPoint2 = aSelectedObject;
418 //=================================================================================
419 // function : SetEditCurrentArgument()
421 //=================================================================================
422 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
424 QPushButton* send = (QPushButton*)sender();
425 globalSelection( GEOM_ALLSHAPES );
427 if ( send == GroupPoints->PushButton1 ) {
428 GroupPoints->LineEdit1->setFocus();
429 myEditCurrentArgument = GroupPoints->LineEdit1;
431 else if ( send == GroupPoints->PushButton2 ) {
432 GroupPoints->LineEdit2->setFocus();
433 myEditCurrentArgument = GroupPoints->LineEdit2;
434 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
436 else if ( send == GroupPoints2->PushButton1 ) {
437 GroupPoints2->LineEdit1->setFocus();
438 myEditCurrentArgument = GroupPoints2->LineEdit1;
440 else if ( send == GroupPoints2->PushButton2 ) {
441 GroupPoints2->LineEdit2->setFocus();
442 myEditCurrentArgument = GroupPoints2->LineEdit2;
443 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
445 else if ( send == GroupPoints2->PushButton3 ) {
446 GroupPoints2->LineEdit3->setFocus();
447 myEditCurrentArgument = GroupPoints2->LineEdit3;
448 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
451 myEditCurrentArgument->setFocus();
452 SelectionIntoArgument();
456 //=================================================================================
457 // function : LineEditReturnPressed()
459 //=================================================================================
460 void GenerationGUI_PrismDlg::LineEditReturnPressed()
462 QLineEdit* send = (QLineEdit*)sender();
463 if ( send == GroupPoints->LineEdit1 ||
464 send == GroupPoints->LineEdit2 ||
465 send == GroupPoints2->LineEdit1 ||
466 send == GroupPoints2->LineEdit2 ||
467 send == GroupPoints2->LineEdit3 ) {
468 myEditCurrentArgument = send;
469 GEOMBase_Skeleton::LineEditReturnPressed();
473 //=================================================================================
474 // function : enterEvent()
475 // purpose : when mouse enter onto the QWidget
476 //=================================================================================
477 void GenerationGUI_PrismDlg::enterEvent( QEvent* )
479 if ( !mainFrame()->GroupConstructors->isEnabled() )
480 ActivateThisDialog();
484 //=================================================================================
485 // function : ActivateThisDialog()
487 //=================================================================================
488 void GenerationGUI_PrismDlg::ActivateThisDialog()
490 GEOMBase_Skeleton::ActivateThisDialog();
492 connect( myGeomGUI->getApp()->selectionMgr(),
493 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
495 ConstructorsClicked( getConstructorId() );
499 //=================================================================================
500 // function : ValueChangedInSpinBox()
502 //=================================================================================
503 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
509 //=================================================================================
510 // function : getHeight()
512 //=================================================================================
513 double GenerationGUI_PrismDlg::getHeight() const
515 return GroupPoints->SpinBox_DX->value();
518 //=================================================================================
519 // function : createOperation
521 //=================================================================================
522 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
524 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
527 //=================================================================================
528 // function : isValid
530 //=================================================================================
531 bool GenerationGUI_PrismDlg::isValid( QString& )
533 if ( getConstructorId() == 0 )
534 return ( myOkBase && myOkVec ); // by vector and height
536 return ( myOkBase && myOkPnt1 && myOkPnt2 ); // by two points
539 //=================================================================================
540 // function : execute
542 //=================================================================================
543 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
545 GEOM::GEOM_Object_var anObj;
547 switch ( getConstructorId() ) {
550 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
551 MakePrismVecH( myBase, myVec, getHeight() );
554 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
555 MakePrismVecH2Ways( myBase, myVec, getHeight() );
560 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
561 MakePrismTwoPnt( myBase, myPoint1, myPoint2 );
564 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
565 MakePrismTwoPnt2Ways( myBase, myPoint1, myPoint2 );
569 if ( !anObj->_is_nil() )
570 objects.push_back( anObj._retn() );
576 //=================================================================================
577 // function : onReverse()
579 //=================================================================================
580 void GenerationGUI_PrismDlg::onReverse()
582 double anOldValue = GroupPoints->SpinBox_DX->value();
583 GroupPoints->SpinBox_DX->setValue( -anOldValue );
586 //=================================================================================
587 // function : onBothway()
589 //=================================================================================
590 void GenerationGUI_PrismDlg::onBothway()
592 bool anOldValue = myBothway;
593 myBothway = !anOldValue;
594 GroupPoints->CheckButton2->setEnabled( !myBothway );
598 void GenerationGUI_PrismDlg::onBothway2()
600 bool anOldValue = myBothway2;
601 myBothway2 = !anOldValue;
605 //=================================================================================
606 // function : addSubshapeToStudy
607 // purpose : virtual method to add new SubObjects if local selection
608 //=================================================================================
609 void GenerationGUI_PrismDlg::addSubshapesToStudy()
611 QMap<QString, GEOM::GEOM_Object_var> objMap;
613 switch ( getConstructorId() ) {
615 objMap[GroupPoints->LineEdit2->text()] = myVec;
618 objMap[GroupPoints2->LineEdit2->text()] = myPoint1;
619 objMap[GroupPoints2->LineEdit3->text()] = myPoint2;
622 addSubshapesToFather( objMap );