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
24 // File : BooleanGUI_Dialog.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BooleanGUI_Dialog.h"
30 #include "BooleanGUI.h"
31 #include "DlgRef_2Sel_QTD.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
38 #include <qcheckbox.h>
42 //=================================================================================
43 // class : BooleanGUI_Dialog()
44 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 BooleanGUI_Dialog::BooleanGUI_Dialog( const int theOperation, GeometryGUI* theGeometryGUI,
50 QWidget* parent, const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl),
52 myOperation( theOperation )
55 QString aTitle, aCaption;
56 switch ( myOperation )
58 case BooleanGUI::COMMON:
59 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_COMMON")));
60 aTitle = tr("GEOM_COMMON");
61 aCaption = tr("GEOM_COMMON_TITLE");
62 setHelpFileName("common_operation_page.html");
65 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CUT")));
66 aTitle = tr("GEOM_CUT");
67 aCaption = tr("GEOM_CUT_TITLE");
68 setHelpFileName("cut_operation_page.html");
70 case BooleanGUI::FUSE:
71 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_FUSE")));
72 aTitle = tr("GEOM_FUSE");
73 aCaption = tr("GEOM_FUSE_TITLE");
74 setHelpFileName("fuse_operation_page.html");
76 case BooleanGUI::SECTION:
77 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SECTION")));
78 aTitle = tr("GEOM_SECTION");
79 aCaption = tr("GEOM_SECTION_TITLE");
80 setHelpFileName("section_opeartion_page.html");
83 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
85 setCaption( aCaption );
87 /***************************************************************/
88 GroupConstructors->setTitle( aTitle );
89 RadioButton1->setPixmap( image0 );
90 RadioButton2->close(TRUE);
91 RadioButton3->close(TRUE);
93 myGroup = new DlgRef_2Sel_QTD(this, "GroupCommon");
94 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
95 if ( myOperation != BooleanGUI::CUT )
97 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
98 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
102 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
103 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
106 myGroup->PushButton1->setPixmap(image1);
107 myGroup->PushButton2->setPixmap(image1);
108 myGroup->LineEdit1->setReadOnly( true );
109 myGroup->LineEdit2->setReadOnly( true );
111 Layout1->addWidget(myGroup, 2, 0);
112 /***************************************************************/
119 //=================================================================================
120 // function : ~BooleanGUI_Dialog()
121 // purpose : Destroys the object and frees any allocated resources
122 //=================================================================================
123 BooleanGUI_Dialog::~BooleanGUI_Dialog()
128 //=================================================================================
131 //=================================================================================
132 void BooleanGUI_Dialog::Init()
134 GroupBoxPublish->show();
137 myEditCurrentArgument = myGroup->LineEdit1;
139 /* signals and slots connections */
140 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
150 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
152 initName( GroupConstructors->title() );
154 setTabOrder (RadioButton1, ResultName );
155 setTabOrder (ResultName, myGroup->PushButton1);
156 setTabOrder (myGroup->PushButton1, myGroup->PushButton2);
157 setTabOrder (myGroup->PushButton2, buttonOk);
158 setTabOrder (buttonOk, buttonApply);
159 setTabOrder (buttonApply, buttonCancel);
160 setTabOrder (buttonCancel, buttonHelp);
162 RadioButton1->setFocus();
164 globalSelection( GEOM_ALLSHAPES );
168 //=================================================================================
169 // function : ClickOnOk()
171 //=================================================================================
172 void BooleanGUI_Dialog::ClickOnOk()
174 if ( ClickOnApply() )
179 //=================================================================================
180 // function : ClickOnApply()
182 //=================================================================================
183 bool BooleanGUI_Dialog::ClickOnApply()
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose : Called when selection has changed
196 //=================================================================================
197 void BooleanGUI_Dialog::SelectionIntoArgument()
199 myEditCurrentArgument->setText( "" );
201 if ( IObjectCount() != 1 )
203 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = GEOM::GEOM_Object::_nil();
204 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = GEOM::GEOM_Object::_nil();
209 Standard_Boolean aRes = Standard_False;
210 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
211 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) )
213 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
214 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = aSelectedObject;
215 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = aSelectedObject;
220 //=================================================================================
221 // function : SetEditCurrentArgument()
223 //=================================================================================
224 void BooleanGUI_Dialog::SetEditCurrentArgument()
226 QPushButton* send = (QPushButton*)sender();
228 if ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
229 else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
231 myEditCurrentArgument->setFocus();
232 SelectionIntoArgument();
236 //=================================================================================
237 // function : LineEditReturnPressed()
239 //=================================================================================
240 void BooleanGUI_Dialog::LineEditReturnPressed()
242 QLineEdit* send = (QLineEdit*)sender();
243 if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 )
245 myEditCurrentArgument = send;
246 GEOMBase_Skeleton::LineEditReturnPressed();
251 //=================================================================================
252 // function : ActivateThisDialog()
254 //=================================================================================
255 void BooleanGUI_Dialog::ActivateThisDialog()
257 GEOMBase_Skeleton::ActivateThisDialog();
258 globalSelection( GEOM_ALLSHAPES );
259 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
260 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
264 //=================================================================================
265 // function : enterEvent()
266 // purpose : when mouse enter onto the QWidget
267 //=================================================================================
268 void BooleanGUI_Dialog::enterEvent(QEvent * e)
270 if ( !GroupConstructors->isEnabled() )
271 ActivateThisDialog();
274 //=================================================================================
275 // function : createOperation
277 //=================================================================================
278 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
280 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
283 //=================================================================================
284 // function : isValid
286 //=================================================================================
287 bool BooleanGUI_Dialog::isValid( QString& msg )
289 Handle(SALOME_InteractiveObject) IO = firstIObject();
290 Standard_Boolean testResult;
291 GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
292 if ( !testResult || anObject->_is_nil() )
295 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
298 //=================================================================================
299 // function : execute
301 //=================================================================================
302 bool BooleanGUI_Dialog::execute( ObjectList& objects )
304 GEOM::GEOM_Object_var anObj;
306 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakeBoolean( myObject1, myObject2, myOperation );
307 if ( !anObj->_is_nil() )
308 objects.push_back( anObj._retn() );
313 //=================================================================================
314 // function : restoreSubShapes
316 //=================================================================================
317 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
318 SALOMEDS::SObject_ptr theSObject)
320 if (CheckBoxRestoreSS->isChecked()) {
321 // empty list of arguments means that all arguments should be restored
322 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(), /*isTrsf=*/false);