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
30 #include "BooleanGUI_Dialog.h"
31 #include "BooleanGUI.h"
32 #include "DlgRef_2Sel_QTD.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_SelectionMgr.h"
40 //=================================================================================
41 // class : BooleanGUI_Dialog()
42 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 BooleanGUI_Dialog::BooleanGUI_Dialog( const int theOperation, QWidget* parent, const char* name, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, modal, fl),
49 myOperation( theOperation )
52 QString aTitle, aCaption;
53 switch ( myOperation )
55 case BooleanGUI::COMMON:
56 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_COMMON")));
57 aTitle = tr("GEOM_COMMON");
58 aCaption = tr("GEOM_COMMON_TITLE");
61 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CUT")));
62 aTitle = tr("GEOM_CUT");
63 aCaption = tr("GEOM_CUT_TITLE");
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");
70 case BooleanGUI::SECTION:
71 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SECTION")));
72 aTitle = tr("GEOM_SECTION");
73 aCaption = tr("GEOM_SECTION_TITLE");
76 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
78 setCaption( aCaption );
80 /***************************************************************/
81 GroupConstructors->setTitle( aTitle );
82 RadioButton1->setPixmap( image0 );
83 RadioButton2->close(TRUE);
84 RadioButton3->close(TRUE);
86 myGroup = new DlgRef_2Sel_QTD(this, "GroupCommon");
87 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
88 if ( myOperation != BooleanGUI::CUT )
90 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
91 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
95 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
96 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
99 myGroup->PushButton1->setPixmap(image1);
100 myGroup->PushButton2->setPixmap(image1);
101 myGroup->LineEdit1->setReadOnly( true );
102 myGroup->LineEdit2->setReadOnly( true );
104 Layout1->addWidget(myGroup, 2, 0);
105 /***************************************************************/
112 //=================================================================================
113 // function : ~BooleanGUI_Dialog()
114 // purpose : Destroys the object and frees any allocated resources
115 //=================================================================================
116 BooleanGUI_Dialog::~BooleanGUI_Dialog()
122 //=================================================================================
125 //=================================================================================
126 void BooleanGUI_Dialog::Init()
129 myEditCurrentArgument = myGroup->LineEdit1;
131 /* signals and slots connections */
132 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
135 connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
142 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
144 initName( GroupConstructors->title() );
146 globalSelection( GEOM_ALLSHAPES );
150 //=================================================================================
151 // function : ClickOnOk()
153 //=================================================================================
154 void BooleanGUI_Dialog::ClickOnOk()
156 if ( ClickOnApply() )
161 //=================================================================================
162 // function : ClickOnApply()
164 //=================================================================================
165 bool BooleanGUI_Dialog::ClickOnApply()
175 //=================================================================================
176 // function : SelectionIntoArgument()
177 // purpose : Called when selection has changed
178 //=================================================================================
179 void BooleanGUI_Dialog::SelectionIntoArgument()
181 myEditCurrentArgument->setText( "" );
183 if ( IObjectCount() != 1 )
185 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = GEOM::GEOM_Object::_nil();
186 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = GEOM::GEOM_Object::_nil();
191 Standard_Boolean aRes = Standard_False;
192 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
193 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) )
195 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
196 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = aSelectedObject;
197 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = aSelectedObject;
202 //=================================================================================
203 // function : SetEditCurrentArgument()
205 //=================================================================================
206 void BooleanGUI_Dialog::SetEditCurrentArgument()
208 QPushButton* send = (QPushButton*)sender();
210 if ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
211 else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
213 myEditCurrentArgument->setFocus();
214 SelectionIntoArgument();
219 //=================================================================================
220 // function : LineEditReturnPressed()
222 //=================================================================================
223 void BooleanGUI_Dialog::LineEditReturnPressed()
225 QLineEdit* send = (QLineEdit*)sender();
226 if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 )
228 myEditCurrentArgument = send;
229 GEOMBase_Skeleton::LineEditReturnPressed();
234 //=================================================================================
235 // function : ActivateThisDialog()
237 //=================================================================================
238 void BooleanGUI_Dialog::ActivateThisDialog()
240 GEOMBase_Skeleton::ActivateThisDialog();
241 globalSelection( GEOM_ALLSHAPES );
242 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
243 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
247 //=================================================================================
248 // function : enterEvent()
249 // purpose : when mouse enter onto the QWidget
250 //=================================================================================
251 void BooleanGUI_Dialog::enterEvent(QEvent * e)
253 if ( !GroupConstructors->isEnabled() )
254 ActivateThisDialog();
257 //=================================================================================
258 // function : createOperation
260 //=================================================================================
261 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
263 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
266 //=================================================================================
267 // function : isValid
269 //=================================================================================
270 bool BooleanGUI_Dialog::isValid( QString& msg )
272 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
275 //=================================================================================
276 // function : execute
278 //=================================================================================
279 bool BooleanGUI_Dialog::execute( ObjectList& objects )
281 GEOM::GEOM_Object_var anObj;
283 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakeBoolean( myObject1, myObject2, myOperation );
284 if ( !anObj->_is_nil() )
285 objects.push_back( anObj._retn() );