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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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"
41 //=================================================================================
42 // class : BooleanGUI_Dialog()
43 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 BooleanGUI_Dialog::BooleanGUI_Dialog( const int theOperation, QWidget* parent, const char* name, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, modal, fl),
50 myOperation( theOperation )
53 QString aTitle, aCaption;
54 switch ( myOperation )
56 case BooleanGUI::COMMON:
57 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_COMMON")));
58 aTitle = tr("GEOM_COMMON");
59 aCaption = tr("GEOM_COMMON_TITLE");
62 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CUT")));
63 aTitle = tr("GEOM_CUT");
64 aCaption = tr("GEOM_CUT_TITLE");
66 case BooleanGUI::FUSE:
67 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_FUSE")));
68 aTitle = tr("GEOM_FUSE");
69 aCaption = tr("GEOM_FUSE_TITLE");
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");
77 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
79 setCaption( aCaption );
81 /***************************************************************/
82 GroupConstructors->setTitle( aTitle );
83 RadioButton1->setPixmap( image0 );
84 RadioButton2->close(TRUE);
85 RadioButton3->close(TRUE);
87 myGroup = new DlgRef_2Sel_QTD(this, "GroupCommon");
88 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
89 if ( myOperation != BooleanGUI::CUT )
91 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
92 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
96 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
97 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
100 myGroup->PushButton1->setPixmap(image1);
101 myGroup->PushButton2->setPixmap(image1);
102 myGroup->LineEdit1->setReadOnly( true );
103 myGroup->LineEdit2->setReadOnly( true );
105 Layout1->addWidget(myGroup, 2, 0);
106 /***************************************************************/
113 //=================================================================================
114 // function : ~BooleanGUI_Dialog()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 BooleanGUI_Dialog::~BooleanGUI_Dialog()
123 //=================================================================================
126 //=================================================================================
127 void BooleanGUI_Dialog::Init()
130 myEditCurrentArgument = myGroup->LineEdit1;
132 /* signals and slots connections */
133 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136 connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
143 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
145 initName( GroupConstructors->title() );
147 globalSelection( GEOM_ALLSHAPES );
151 //=================================================================================
152 // function : ClickOnOk()
154 //=================================================================================
155 void BooleanGUI_Dialog::ClickOnOk()
157 if ( ClickOnApply() )
162 //=================================================================================
163 // function : ClickOnApply()
165 //=================================================================================
166 bool BooleanGUI_Dialog::ClickOnApply()
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection has changed
179 //=================================================================================
180 void BooleanGUI_Dialog::SelectionIntoArgument()
182 myEditCurrentArgument->setText( "" );
184 if ( IObjectCount() != 1 )
186 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = GEOM::GEOM_Object::_nil();
187 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = GEOM::GEOM_Object::_nil();
192 Standard_Boolean aRes = Standard_False;
193 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
194 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) )
196 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
197 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = aSelectedObject;
198 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = aSelectedObject;
203 //=================================================================================
204 // function : SetEditCurrentArgument()
206 //=================================================================================
207 void BooleanGUI_Dialog::SetEditCurrentArgument()
209 QPushButton* send = (QPushButton*)sender();
211 if ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
212 else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
214 myEditCurrentArgument->setFocus();
215 SelectionIntoArgument();
220 //=================================================================================
221 // function : LineEditReturnPressed()
223 //=================================================================================
224 void BooleanGUI_Dialog::LineEditReturnPressed()
226 QLineEdit* send = (QLineEdit*)sender();
227 if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 )
229 myEditCurrentArgument = send;
230 GEOMBase_Skeleton::LineEditReturnPressed();
235 //=================================================================================
236 // function : ActivateThisDialog()
238 //=================================================================================
239 void BooleanGUI_Dialog::ActivateThisDialog()
241 GEOMBase_Skeleton::ActivateThisDialog();
242 globalSelection( GEOM_ALLSHAPES );
243 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
244 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
248 //=================================================================================
249 // function : enterEvent()
250 // purpose : when mouse enter onto the QWidget
251 //=================================================================================
252 void BooleanGUI_Dialog::enterEvent(QEvent * e)
254 if ( !GroupConstructors->isEnabled() )
255 ActivateThisDialog();
258 //=================================================================================
259 // function : createOperation
261 //=================================================================================
262 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
264 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
267 //=================================================================================
268 // function : isValid
270 //=================================================================================
271 bool BooleanGUI_Dialog::isValid( QString& msg )
273 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
276 //=================================================================================
277 // function : execute
279 //=================================================================================
280 bool BooleanGUI_Dialog::execute( ObjectList& objects )
282 GEOM::GEOM_Object_var anObj;
284 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakeBoolean( myObject1, myObject2, myOperation );
285 if ( !anObj->_is_nil() )
286 objects.push_back( anObj._retn() );