1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BlocksGUI_QuadFaceDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "BlocksGUI_QuadFaceDlg.h"
27 #include <GEOM_DlgRef.h>
28 #include <GeometryGUI.h>
30 #include <GEOMImpl_Types.hxx>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
39 //=================================================================================
40 // class : BlocksGUI_QuadFaceDlg()
41 // purpose : Constructs a BlocksGUI_QuadFaceDlg which is a child of 'parent'.
42 //=================================================================================
43 BlocksGUI_QuadFaceDlg::BlocksGUI_QuadFaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
44 : GEOMBase_Skeleton( theGeometryGUI, parent )
46 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
47 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_QUAD_FACE_4_VERT" ) ) );
48 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_QUAD_FACE_2_EDGE" ) ) );
49 QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_QUAD_FACE_4_EDGE" ) ) );
50 QPixmap imageS( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 setWindowTitle( tr( "GEOM_QUAD_FACE_TITLE" ) );
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_QUAD_FACE" ) );
57 mainFrame()->RadioButton1->setIcon( image1 );
58 mainFrame()->RadioButton2->setIcon( image2 );
59 mainFrame()->RadioButton3->setIcon( image3 );
62 myGrp1 = new QGroupBox( tr( "GEOM_ARGUMENTS" ), centralWidget() );
64 createSelWg( tr( "VERTEX_1" ), imageS, myGrp1, Vertex1 );
65 createSelWg( tr( "VERTEX_2" ), imageS, myGrp1, Vertex2 );
66 createSelWg( tr( "VERTEX_3" ), imageS, myGrp1, Vertex3 );
67 createSelWg( tr( "VERTEX_4" ), imageS, myGrp1, Vertex4 );
69 // Create second group
70 myGrp2 = new QGroupBox( tr( "GEOM_ARGUMENTS" ), centralWidget() );
72 createSelWg( tr( "EDGE_1" ), imageS, myGrp2, Edge12 );
73 createSelWg( tr( "EDGE_2" ), imageS, myGrp2, Edge22 );
76 myGrp3 = new QGroupBox( tr( "GEOM_ARGUMENTS" ), centralWidget() );
78 createSelWg( tr( "EDGE_1" ), imageS, myGrp3, Edge14 );
79 createSelWg( tr( "EDGE_2" ), imageS, myGrp3, Edge24 );
80 createSelWg( tr( "EDGE_3" ), imageS, myGrp3, Edge34 );
81 createSelWg( tr( "EDGE_4" ), imageS, myGrp3, Edge44 );
83 // Add groups to layout
84 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85 layout->setMargin( 0 ); layout->setSpacing( 6 );
86 layout->addWidget( myGrp1 );
87 layout->addWidget( myGrp2 );
88 layout->addWidget( myGrp3 );
90 /***************************************************************/
92 setHelpFileName( "newentity_blocks.htm#QuadrangleFace" );
97 //=================================================================================
98 // function : ~BlocksGUI_QuadFaceDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 BlocksGUI_QuadFaceDlg::~BlocksGUI_QuadFaceDlg()
103 // no need to delete child widgets, Qt does it all for us
106 //=================================================================================
109 //=================================================================================
110 void BlocksGUI_QuadFaceDlg::Init()
112 // signals and slots connections
113 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
114 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
116 connect( this, SIGNAL( constructorsClicked( int ) ),
117 this, SLOT( ConstructorsClicked( int ) ) );
119 QMap<int, QPushButton*>::iterator anIterBtn;
120 for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
121 connect( anIterBtn.value(), SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
123 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
124 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
126 // init controls and fields
127 initName( tr( "GEOM_QUAD_FACE" ) );
129 myConstructorId = -1;
130 ConstructorsClicked( 0 );
133 //=================================================================================
134 // function : ConstructorsClicked()
135 // purpose : Radio button management
136 //=================================================================================
137 void BlocksGUI_QuadFaceDlg::ConstructorsClicked( int constructorId )
139 if ( myConstructorId == constructorId )
142 myConstructorId = constructorId;
144 switch ( constructorId ) {
149 myEditCurrentArgument = mySelName[Vertex1];
155 myEditCurrentArgument = mySelName[Edge12];
161 myEditCurrentArgument = mySelName[Edge14];
168 QMap<int, QLineEdit*>::iterator anIterLE;
169 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
170 anIterLE.value()->setText( "" );
173 myShape1 = myShape2 = GEOM::GEOM_Object::_nil();
174 myShape3 = myShape4 = myShape1;
176 qApp->processEvents();
178 resize( minimumSize() );
183 //=================================================================================
184 // function : ClickOnOk()
186 //=================================================================================
187 void BlocksGUI_QuadFaceDlg::ClickOnOk()
189 if ( ClickOnApply() )
193 //=================================================================================
194 // function : ClickOnApply()
196 //=================================================================================
197 bool BlocksGUI_QuadFaceDlg::ClickOnApply()
206 //=================================================================================
207 // function : SelectionIntoArgument()
208 // purpose : Called when selection has changed
209 //=================================================================================
210 void BlocksGUI_QuadFaceDlg::SelectionIntoArgument()
213 myEditCurrentArgument->setText( "" );
215 // Get index of current selection focus
217 QMap<int, QLineEdit*>::iterator anIter;
218 for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter ) {
219 if ( myEditCurrentArgument == anIter.value() ) {
220 aCurrFocus = anIter.key();
225 GEOM::GEOM_Object_var anObj;
226 Standard_Boolean aResult = Standard_False;
227 if ( IObjectCount() == 1 ) {
228 anObj = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
230 if (anObj->_is_nil()) {
231 aResult = Standard_False;
234 mySelName[aCurrFocus]->setText( GEOMBase::GetName( anObj ) );
238 anObj = GEOM::GEOM_Object::_nil();
242 switch ( aCurrFocus ) {
246 myShape1 = anObj; break;
250 myShape2 = anObj; break;
253 myShape3 = anObj; break;
256 myShape4 = anObj; break;
263 //=================================================================================
264 // function : SetEditCurrentArgument()
266 //=================================================================================
267 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
269 QPushButton* aSender = (QPushButton*)sender();
271 QMap<int, QPushButton*>::iterator anIter;
272 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter ) {
273 if ( anIter.value() == aSender ) {
274 mySelName[anIter.key()]->setFocus();
275 myEditCurrentArgument = mySelName[anIter.key()];
282 //=================================================================================
283 // function : ActivateThisDialog()
285 //=================================================================================
286 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
288 GEOMBase_Skeleton::ActivateThisDialog();
289 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
290 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
296 //=================================================================================
297 // function : enterEvent()
299 //=================================================================================
300 void BlocksGUI_QuadFaceDlg::enterEvent( QEvent* )
302 if ( !mainFrame()->GroupConstructors->isEnabled() )
303 this->ActivateThisDialog();
306 //=================================================================================
307 // function : DeactivateActiveDialog()
309 //=================================================================================
310 //void BlocksGUI_QuadFaceDlg::DeactivateActiveDialog()
312 // // disconnect selection
313 // GEOMBase_Skeleton::DeactivateActiveDialog();
316 //=================================================================================
317 // function : createSelWg()
319 //=================================================================================
320 void BlocksGUI_QuadFaceDlg::createSelWg( const QString& theLbl,
325 QLabel* lab = new QLabel( theLbl, theParent );
326 mySelBtn[theId] = new QPushButton( theParent );
327 mySelBtn[theId]->setIcon( thePix );
328 mySelBtn[theId]->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
329 mySelName[theId] = new QLineEdit( theParent );
330 mySelName[theId]->setReadOnly( true );
332 if ( !theParent->layout() ) {
333 l = new QGridLayout( theParent );
334 l->setMargin( 9 ); l->setSpacing( 6 );
337 l = qobject_cast<QGridLayout*>( theParent->layout() );
339 int row = l->rowCount();
340 l->addWidget( lab, row, 0 );
341 l->addWidget( mySelBtn[theId], row, 1 );
342 l->addWidget( mySelName[theId], row, 2 );
345 //=================================================================================
346 // function : activateSelection
347 // purpose : Activate selection in accordance with myEditCurrentArgument
348 //=================================================================================
349 void BlocksGUI_QuadFaceDlg::activateSelection()
351 if ( myEditCurrentArgument == mySelName[Vertex1] ||
352 myEditCurrentArgument == mySelName[Vertex2] ||
353 myEditCurrentArgument == mySelName[Vertex3] ||
354 myEditCurrentArgument == mySelName[Vertex4] ) {
355 globalSelection( GEOM_POINT );
358 globalSelection( GEOM_EDGE );
361 SelectionIntoArgument();
364 //=================================================================================
365 // function : createOperation
367 //=================================================================================
368 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
370 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
373 //=================================================================================
374 // function : isValid
375 // purpose : Verify validity of input data
376 //=================================================================================
377 bool BlocksGUI_QuadFaceDlg::isValid( QString& )
380 switch ( getConstructorId() ) {
382 ok = ( !myShape1->_is_nil() && !myShape2->_is_nil() &&
383 !myShape3->_is_nil() && !myShape4->_is_nil() );
386 ok = ( !myShape1->_is_nil() && !myShape2->_is_nil() );
389 ok = ( !myShape1->_is_nil() && !myShape2->_is_nil() &&
390 !myShape3->_is_nil() && !myShape4->_is_nil() );
398 //=================================================================================
399 // function : execute
401 //=================================================================================
402 bool BlocksGUI_QuadFaceDlg::execute( ObjectList& objects )
406 GEOM::GEOM_Object_var anObj;
408 switch ( getConstructorId() ) {
410 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeQuad4Vertices
411 ( myShape1, myShape2, myShape3, myShape4 );
415 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeQuad2Edges
416 ( myShape1, myShape2 );
420 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeQuad
421 ( myShape1, myShape2, myShape3, myShape4 );
428 if ( !anObj->_is_nil() )
429 objects.push_back( anObj._retn() );