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 : BooleanGUI_Dialog.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BooleanGUI.h"
27 #include "BooleanGUI_Dialog.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 //=================================================================================
39 // class : BooleanGUI_Dialog()
40 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 BooleanGUI_Dialog::BooleanGUI_Dialog( const int theOperation, GeometryGUI* theGeometryGUI,
46 QWidget* parent, bool modal, Qt::WindowFlags fl )
47 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
48 myOperation( theOperation )
51 QString aTitle, aCaption;
52 switch ( myOperation ) {
53 case BooleanGUI::COMMON:
54 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_COMMON" ) ) );
55 aTitle = tr( "GEOM_COMMON" );
56 aCaption = tr( "GEOM_COMMON_TITLE" );
57 setHelpFileName( "common_operation_page.html" );
60 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CUT" ) ) );
61 aTitle = tr( "GEOM_CUT" );
62 aCaption = tr( "GEOM_CUT_TITLE" );
63 setHelpFileName( "cut_operation_page.html" );
65 case BooleanGUI::FUSE:
66 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FUSE" ) ) );
67 aTitle = tr( "GEOM_FUSE" );
68 aCaption = tr( "GEOM_FUSE_TITLE" );
69 setHelpFileName( "fuse_operation_page.html" );
71 case BooleanGUI::SECTION:
72 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SECTION" ) ) );
73 aTitle = tr( "GEOM_SECTION" );
74 aCaption = tr( "GEOM_SECTION_TITLE" );
75 setHelpFileName( "section_opeartion_page.html" );
78 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
80 setWindowTitle( aCaption );
82 /***************************************************************/
83 mainFrame()->GroupConstructors->setTitle( aTitle );
84 mainFrame()->RadioButton1->setIcon( image0 );
85 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
86 mainFrame()->RadioButton2->close();
87 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
88 mainFrame()->RadioButton3->close();
90 myGroup = new DlgRef_2Sel( centralWidget() );
92 myGroup->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
93 if ( myOperation != BooleanGUI::CUT ) {
94 myGroup->TextLabel1->setText( tr( "GEOM_OBJECT_I" ).arg( 1 ) );
95 myGroup->TextLabel2->setText( tr( "GEOM_OBJECT_I" ).arg( 2 ) );
98 myGroup->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
99 myGroup->TextLabel2->setText( tr( "GEOM_TOOL_OBJECT" ) );
102 myGroup->PushButton1->setIcon( image1 );
103 myGroup->PushButton2->setIcon( image1 );
104 myGroup->LineEdit1->setReadOnly( true );
105 myGroup->LineEdit2->setReadOnly( true );
107 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
108 layout->setMargin( 0 ); layout->setSpacing( 6 );
109 layout->addWidget( myGroup );
110 /***************************************************************/
117 //=================================================================================
118 // function : ~BooleanGUI_Dialog()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 BooleanGUI_Dialog::~BooleanGUI_Dialog()
126 //=================================================================================
129 //=================================================================================
130 void BooleanGUI_Dialog::Init()
132 mainFrame()->GroupBoxPublish->show();
135 myEditCurrentArgument = myGroup->LineEdit1;
137 /* signals and slots connections */
138 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
139 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
141 connect( myGroup->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
142 connect( myGroup->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
144 connect( myGroup->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
145 connect( myGroup->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
147 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
148 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
150 initName( mainFrame()->GroupConstructors->title() );
152 setTabOrder( mainFrame()->GroupConstructors, mainFrame()->GroupBoxName );
153 setTabOrder( mainFrame()->GroupBoxName, mainFrame()->GroupMedium );
154 setTabOrder( mainFrame()->GroupMedium, mainFrame()->GroupButtons );
156 mainFrame()->RadioButton1->setFocus();
158 globalSelection( GEOM_ALLSHAPES );
162 //=================================================================================
163 // function : ClickOnOk()
165 //=================================================================================
166 void BooleanGUI_Dialog::ClickOnOk()
168 if ( ClickOnApply() )
173 //=================================================================================
174 // function : ClickOnApply()
176 //=================================================================================
177 bool BooleanGUI_Dialog::ClickOnApply()
187 //=================================================================================
188 // function : SelectionIntoArgument()
189 // purpose : Called when selection has changed
190 //=================================================================================
191 void BooleanGUI_Dialog::SelectionIntoArgument()
193 myEditCurrentArgument->setText( "" );
195 if ( IObjectCount() != 1 ) {
196 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = GEOM::GEOM_Object::_nil();
197 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = GEOM::GEOM_Object::_nil();
202 Standard_Boolean aRes = Standard_False;
203 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
204 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) ) {
205 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
206 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = aSelectedObject;
207 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = aSelectedObject;
212 //=================================================================================
213 // function : SetEditCurrentArgument()
215 //=================================================================================
216 void BooleanGUI_Dialog::SetEditCurrentArgument()
218 QPushButton* send = (QPushButton*)sender();
220 if ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
221 else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
223 myEditCurrentArgument->setFocus();
224 SelectionIntoArgument();
228 //=================================================================================
229 // function : LineEditReturnPressed()
231 //=================================================================================
232 void BooleanGUI_Dialog::LineEditReturnPressed()
234 QLineEdit* send = (QLineEdit*)sender();
235 if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 ) {
236 myEditCurrentArgument = send;
237 GEOMBase_Skeleton::LineEditReturnPressed();
242 //=================================================================================
243 // function : ActivateThisDialog()
245 //=================================================================================
246 void BooleanGUI_Dialog::ActivateThisDialog()
248 GEOMBase_Skeleton::ActivateThisDialog();
249 globalSelection( GEOM_ALLSHAPES );
250 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
251 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
255 //=================================================================================
256 // function : enterEvent()
257 // purpose : when mouse enter onto the QWidget
258 //=================================================================================
259 void BooleanGUI_Dialog::enterEvent( QEvent* )
261 if ( !mainFrame()->GroupConstructors->isEnabled() )
262 ActivateThisDialog();
265 //=================================================================================
266 // function : createOperation
268 //=================================================================================
269 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
271 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
274 //=================================================================================
275 // function : isValid
277 //=================================================================================
278 bool BooleanGUI_Dialog::isValid( QString& msg )
280 Handle(SALOME_InteractiveObject) IO = firstIObject();
281 Standard_Boolean testResult;
282 GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
283 if ( !testResult || anObject->_is_nil() )
286 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
289 //=================================================================================
290 // function : execute
292 //=================================================================================
293 bool BooleanGUI_Dialog::execute( ObjectList& objects )
295 GEOM::GEOM_Object_var anObj;
297 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->
298 MakeBoolean( myObject1, myObject2, myOperation );
299 if ( !anObj->_is_nil() )
300 objects.push_back( anObj._retn() );
305 //=================================================================================
306 // function : restoreSubShapes
308 //=================================================================================
309 void BooleanGUI_Dialog::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
310 SALOMEDS::SObject_ptr theSObject )
312 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
313 // empty list of arguments means that all arguments should be restored
314 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
315 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
316 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT ); // ? false