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"
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( "build_by_blocks_page.html#quad_face_anchor" );
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 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
226 SALOME_ListIO aSelList;
227 aSelMgr->selectedObjects(aSelList);
229 GEOM::GEOM_Object_var anObj;
230 if (aSelList.Extent() == 1) {
231 Standard_Boolean aResult = Standard_False;
232 anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
234 if (anObj->_is_nil()) {
235 aResult = Standard_False;
238 mySelName[aCurrFocus]->setText( GEOMBase::GetName( anObj ) );
242 anObj = GEOM::GEOM_Object::_nil();
246 switch ( aCurrFocus ) {
250 myShape1 = anObj; break;
254 myShape2 = anObj; break;
257 myShape3 = anObj; break;
260 myShape4 = anObj; break;
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
273 QPushButton* aSender = (QPushButton*)sender();
275 QMap<int, QPushButton*>::iterator anIter;
276 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter ) {
277 if ( anIter.value() == aSender ) {
278 mySelName[anIter.key()]->setFocus();
279 myEditCurrentArgument = mySelName[anIter.key()];
286 //=================================================================================
287 // function : ActivateThisDialog()
289 //=================================================================================
290 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
292 GEOMBase_Skeleton::ActivateThisDialog();
293 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
294 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
300 //=================================================================================
301 // function : enterEvent()
303 //=================================================================================
304 void BlocksGUI_QuadFaceDlg::enterEvent( QEvent* )
306 if ( !mainFrame()->GroupConstructors->isEnabled() )
307 this->ActivateThisDialog();
310 //=================================================================================
311 // function : DeactivateActiveDialog()
313 //=================================================================================
314 //void BlocksGUI_QuadFaceDlg::DeactivateActiveDialog()
316 // // disconnect selection
317 // GEOMBase_Skeleton::DeactivateActiveDialog();
320 //=================================================================================
321 // function : createSelWg()
323 //=================================================================================
324 void BlocksGUI_QuadFaceDlg::createSelWg( const QString& theLbl,
329 QLabel* lab = new QLabel( theLbl, theParent );
330 mySelBtn[theId] = new QPushButton( theParent );
331 mySelBtn[theId]->setIcon( thePix );
332 mySelBtn[theId]->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
333 mySelName[theId] = new QLineEdit( theParent );
334 mySelName[theId]->setReadOnly( true );
336 if ( !theParent->layout() ) {
337 l = new QGridLayout( theParent );
338 l->setMargin( 9 ); l->setSpacing( 6 );
341 l = qobject_cast<QGridLayout*>( theParent->layout() );
343 int row = l->rowCount();
344 l->addWidget( lab, row, 0 );
345 l->addWidget( mySelBtn[theId], row, 1 );
346 l->addWidget( mySelName[theId], row, 2 );
349 //=================================================================================
350 // function : activateSelection
351 // purpose : Activate selection in accordance with myEditCurrentArgument
352 //=================================================================================
353 void BlocksGUI_QuadFaceDlg::activateSelection()
355 if ( myEditCurrentArgument == mySelName[Vertex1] ||
356 myEditCurrentArgument == mySelName[Vertex2] ||
357 myEditCurrentArgument == mySelName[Vertex3] ||
358 myEditCurrentArgument == mySelName[Vertex4] ) {
359 globalSelection( GEOM_POINT );
362 globalSelection( GEOM_EDGE );
365 SelectionIntoArgument();
368 //=================================================================================
369 // function : createOperation
371 //=================================================================================
372 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
374 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
377 //=================================================================================
378 // function : isValid
379 // purpose : Verify validity of input data
380 //=================================================================================
381 bool BlocksGUI_QuadFaceDlg::isValid( QString& )
384 switch ( getConstructorId() ) {
386 ok = ( !myShape1->_is_nil() && !myShape2->_is_nil() &&
387 !myShape3->_is_nil() && !myShape4->_is_nil() );
390 ok = ( !myShape1->_is_nil() && !myShape2->_is_nil() );
393 ok = ( !myShape1->_is_nil() && !myShape2->_is_nil() &&
394 !myShape3->_is_nil() && !myShape4->_is_nil() );
402 //=================================================================================
403 // function : execute
405 //=================================================================================
406 bool BlocksGUI_QuadFaceDlg::execute( ObjectList& objects )
410 GEOM::GEOM_Object_var anObj;
412 switch ( getConstructorId() ) {
414 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeQuad4Vertices
415 ( myShape1, myShape2, myShape3, myShape4 );
419 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeQuad2Edges
420 ( myShape1, myShape2 );
424 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeQuad
425 ( myShape1, myShape2, myShape3, myShape4 );
432 if ( !anObj->_is_nil() )
433 objects.push_back( anObj._retn() );