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_BlockDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "BlocksGUI_BlockDlg.h"
28 #include <GeometryGUI.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
36 #include <GEOMImpl_Types.hxx>
38 //=================================================================================
39 // class : BlocksGUI_BlockDlg()
40 // purpose : Constructs a BlocksGUI_BlockDlg which is a child of 'parent'.
41 //=================================================================================
42 BlocksGUI_BlockDlg::BlocksGUI_BlockDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
43 : GEOMBase_Skeleton( theGeometryGUI, parent )
45 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BLOCK_2F" ) ) );
46 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BLOCK_6F" ) ) );
47 QPixmap imageS( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
49 setWindowTitle( tr( "GEOM_BLOCK_TITLE" ) );
51 /***************************************************************/
52 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BLOCK" ) );
54 mainFrame()->RadioButton1->setIcon( image0 );
55 mainFrame()->RadioButton2->setIcon( image1 );
56 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
57 mainFrame()->RadioButton3->close();
60 Group2F = new DlgRef_2Sel( centralWidget() );
61 Group2F->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
62 Group2F->TextLabel1->setText( tr( "FACE_1" ) );
63 Group2F->TextLabel2->setText( tr( "FACE_2" ) );
64 Group2F->PushButton1->setIcon( imageS );
65 Group2F->PushButton2->setIcon( imageS );
67 // Create second group
68 Group6F = new DlgRef_6Sel( centralWidget() );
69 Group6F->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
70 Group6F->TextLabel1->setText( tr( "FACE_1" ) );
71 Group6F->TextLabel2->setText( tr( "FACE_2" ) );
72 Group6F->TextLabel3->setText( tr( "FACE_3" ) );
73 Group6F->TextLabel4->setText( tr( "FACE_4" ) );
74 Group6F->TextLabel5->setText( tr( "FACE_5" ) );
75 Group6F->TextLabel6->setText( tr( "FACE_6" ) );
76 Group6F->PushButton1->setIcon( imageS );
77 Group6F->PushButton2->setIcon( imageS );
78 Group6F->PushButton3->setIcon( imageS );
79 Group6F->PushButton4->setIcon( imageS );
80 Group6F->PushButton5->setIcon( imageS );
81 Group6F->PushButton6->setIcon( imageS );
83 // Add groups to layout
84 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85 layout->setMargin( 0 ); layout->setSpacing( 6 );
86 layout->addWidget( Group2F );
87 layout->addWidget( Group6F );
88 /***************************************************************/
90 setHelpFileName( "build_by_blocks_page.html#hexa_solid_anchor" );
95 //=================================================================================
96 // function : ~BlocksGUI_BlockDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 BlocksGUI_BlockDlg::~BlocksGUI_BlockDlg()
101 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void BlocksGUI_BlockDlg::Init()
111 Group2F->LineEdit1->setReadOnly( true );
112 Group2F->LineEdit2->setReadOnly( true );
114 Group6F->LineEdit1->setReadOnly( true );
115 Group6F->LineEdit2->setReadOnly( true );
116 Group6F->LineEdit3->setReadOnly( true );
117 Group6F->LineEdit4->setReadOnly( true );
118 Group6F->LineEdit5->setReadOnly( true );
119 Group6F->LineEdit6->setReadOnly( true );
121 // signals and slots connections
122 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
123 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
125 connect( this, SIGNAL( constructorsClicked( int ) ),
126 this, SLOT( ConstructorsClicked( int ) ) );
128 connect( Group2F->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
129 connect( Group2F->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
131 connect( Group6F->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
132 connect( Group6F->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
133 connect( Group6F->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
134 connect( Group6F->PushButton4, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
135 connect( Group6F->PushButton5, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
136 connect( Group6F->PushButton6, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
138 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
139 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
141 // init controls and fields
142 initName( tr( "GEOM_BLOCK" ) );
144 myConstructorId = -1;
145 ConstructorsClicked( 0 );
148 //=================================================================================
149 // function : ConstructorsClicked()
150 // purpose : Radio button management
151 //=================================================================================
152 void BlocksGUI_BlockDlg::ConstructorsClicked( int constructorId )
154 if ( myConstructorId == constructorId )
157 myConstructorId = constructorId;
159 switch ( constructorId ) {
164 myEditCurrentArgument = Group2F->LineEdit1;
165 Group2F->LineEdit1->setText( tr( "" ) );
166 Group2F->LineEdit2->setText( tr( "" ) );
172 myEditCurrentArgument = Group6F->LineEdit1;
173 Group6F->LineEdit1->setText( tr( "" ) );
174 Group6F->LineEdit2->setText( tr( "" ) );
175 Group6F->LineEdit3->setText( tr( "" ) );
176 Group6F->LineEdit4->setText( tr( "" ) );
177 Group6F->LineEdit5->setText( tr( "" ) );
178 Group6F->LineEdit6->setText( tr( "" ) );
185 myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
186 myFace3 = myFace4 = myFace5 = myFace6 = myFace1;
188 qApp->processEvents();
190 resize( minimumSize() );
192 globalSelection( GEOM_FACE );
193 SelectionIntoArgument();
194 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
195 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
198 //=================================================================================
199 // function : ClickOnOk()
201 //=================================================================================
202 void BlocksGUI_BlockDlg::ClickOnOk()
204 if ( ClickOnApply() )
208 //=================================================================================
209 // function : ClickOnApply()
211 //=================================================================================
212 bool BlocksGUI_BlockDlg::ClickOnApply()
221 //=================================================================================
222 // function : SelectionIntoArgument()
223 // purpose : Called when selection as changed or other case
224 //=================================================================================
225 void BlocksGUI_BlockDlg::SelectionIntoArgument()
228 myEditCurrentArgument->setText( "" );
230 if ( IObjectCount() != 1 ) {
231 if ( myEditCurrentArgument == Group2F->LineEdit1 ||
232 myEditCurrentArgument == Group6F->LineEdit1 )
233 myFace1 = GEOM::GEOM_Object::_nil();
234 else if ( myEditCurrentArgument == Group2F->LineEdit2 ||
235 myEditCurrentArgument == Group6F->LineEdit2 )
236 myFace2 = GEOM::GEOM_Object::_nil();
237 else if ( myEditCurrentArgument == Group6F->LineEdit3 )
238 myFace3 = GEOM::GEOM_Object::_nil();
239 else if ( myEditCurrentArgument == Group6F->LineEdit4 )
240 myFace4 = GEOM::GEOM_Object::_nil();
241 else if ( myEditCurrentArgument == Group6F->LineEdit5 )
242 myFace5 = GEOM::GEOM_Object::_nil();
243 else if ( myEditCurrentArgument == Group6F->LineEdit6 )
244 myFace6 = GEOM::GEOM_Object::_nil();
249 Standard_Boolean testResult = Standard_False;
250 GEOM::GEOM_Object_var aSelectedObject =
251 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
253 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
256 if ( myEditCurrentArgument == Group2F->LineEdit1 ||
257 myEditCurrentArgument == Group6F->LineEdit1 )
258 myFace1 = aSelectedObject;
259 else if ( myEditCurrentArgument == Group2F->LineEdit2 ||
260 myEditCurrentArgument == Group6F->LineEdit2 )
261 myFace2 = aSelectedObject;
262 else if ( myEditCurrentArgument == Group6F->LineEdit3 )
263 myFace3 = aSelectedObject;
264 else if ( myEditCurrentArgument == Group6F->LineEdit4 )
265 myFace4 = aSelectedObject;
266 else if ( myEditCurrentArgument == Group6F->LineEdit5 )
267 myFace5 = aSelectedObject;
268 else if ( myEditCurrentArgument == Group6F->LineEdit6 )
269 myFace6 = aSelectedObject;
271 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
276 //=================================================================================
277 // function : SetEditCurrentArgument()
279 //=================================================================================
280 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
282 QPushButton* aSender = (QPushButton*)sender();
284 if ( aSender == Group2F->PushButton1 ) {
285 myEditCurrentArgument = Group2F->LineEdit1;
287 else if ( aSender == Group2F->PushButton2 ) {
288 myEditCurrentArgument = Group2F->LineEdit2;
290 else if ( aSender == Group6F->PushButton1 ) {
291 myEditCurrentArgument = Group6F->LineEdit1;
293 else if ( aSender == Group6F->PushButton2 ) {
294 myEditCurrentArgument = Group6F->LineEdit2;
296 else if ( aSender == Group6F->PushButton3 ) {
297 myEditCurrentArgument = Group6F->LineEdit3;
299 else if ( aSender == Group6F->PushButton4 ) {
300 myEditCurrentArgument = Group6F->LineEdit4;
302 else if ( aSender == Group6F->PushButton5 ) {
303 myEditCurrentArgument = Group6F->LineEdit5;
305 else if ( aSender == Group6F->PushButton6 ) {
306 myEditCurrentArgument = Group6F->LineEdit6;
309 globalSelection( GEOM_FACE );
311 myEditCurrentArgument->setFocus();
312 SelectionIntoArgument();
315 //=================================================================================
316 // function : ActivateThisDialog()
318 //=================================================================================
319 void BlocksGUI_BlockDlg::ActivateThisDialog()
321 GEOMBase_Skeleton::ActivateThisDialog();
322 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
323 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
325 globalSelection( GEOM_FACE );
327 SelectionIntoArgument();
330 //=================================================================================
331 // function : enterEvent()
333 //=================================================================================
334 void BlocksGUI_BlockDlg::enterEvent( QEvent* )
336 if ( !mainFrame()->GroupConstructors->isEnabled() )
337 ActivateThisDialog();
340 //=================================================================================
341 // function : createOperation
343 //=================================================================================
344 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
346 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
349 //=================================================================================
350 // function : isValid
352 //=================================================================================
353 bool BlocksGUI_BlockDlg::isValid (QString&)
356 switch ( getConstructorId() ) {
358 ok = !( myFace1->_is_nil() || myFace2->_is_nil() );
361 ok = !( myFace1->_is_nil() || myFace2->_is_nil() ||
362 myFace3->_is_nil() || myFace4->_is_nil() ||
363 myFace5->_is_nil() || myFace6->_is_nil() );
371 //=================================================================================
372 // function : execute
374 //=================================================================================
375 bool BlocksGUI_BlockDlg::execute( ObjectList& objects )
379 GEOM::GEOM_Object_var anObj;
381 switch ( getConstructorId() ) {
383 if ( !CORBA::is_nil( myFace1 ) && !CORBA::is_nil( myFace2 ) ) {
384 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->
385 MakeHexa2Faces( myFace1, myFace2 );
390 if ( !CORBA::is_nil( myFace1 ) && !CORBA::is_nil( myFace2 ) &&
391 !CORBA::is_nil(myFace3 ) && !CORBA::is_nil( myFace4 ) &&
392 !CORBA::is_nil( myFace5 ) && !CORBA::is_nil( myFace6 ) ) {
393 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->
394 MakeHexa( myFace1, myFace2, myFace3, myFace4, myFace5, myFace6 );
400 if ( !anObj->_is_nil() )
401 objects.push_back( anObj._retn() );