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"
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, GeometryGUI* theGeometryGUI,
49 QWidget* parent, const char* name, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl),
51 myOperation( theOperation )
54 QString aTitle, aCaption;
55 switch ( myOperation )
57 case BooleanGUI::COMMON:
58 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_COMMON")));
59 aTitle = tr("GEOM_COMMON");
60 aCaption = tr("GEOM_COMMON_TITLE");
61 setHelpFileName("common.htm");
64 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CUT")));
65 aTitle = tr("GEOM_CUT");
66 aCaption = tr("GEOM_CUT_TITLE");
67 setHelpFileName("cut.htm");
69 case BooleanGUI::FUSE:
70 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_FUSE")));
71 aTitle = tr("GEOM_FUSE");
72 aCaption = tr("GEOM_FUSE_TITLE");
73 setHelpFileName("fuse.htm");
75 case BooleanGUI::SECTION:
76 image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SECTION")));
77 aTitle = tr("GEOM_SECTION");
78 aCaption = tr("GEOM_SECTION_TITLE");
79 setHelpFileName("section.htm");
82 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
84 setCaption( aCaption );
86 /***************************************************************/
87 GroupConstructors->setTitle( aTitle );
88 RadioButton1->setPixmap( image0 );
89 RadioButton2->close(TRUE);
90 RadioButton3->close(TRUE);
92 myGroup = new DlgRef_2Sel_QTD(this, "GroupCommon");
93 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
94 if ( myOperation != BooleanGUI::CUT )
96 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
97 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
101 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
102 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
105 myGroup->PushButton1->setPixmap(image1);
106 myGroup->PushButton2->setPixmap(image1);
107 myGroup->LineEdit1->setReadOnly( true );
108 myGroup->LineEdit2->setReadOnly( true );
110 Layout1->addWidget(myGroup, 2, 0);
111 /***************************************************************/
118 //=================================================================================
119 // function : ~BooleanGUI_Dialog()
120 // purpose : Destroys the object and frees any allocated resources
121 //=================================================================================
122 BooleanGUI_Dialog::~BooleanGUI_Dialog()
127 //=================================================================================
130 //=================================================================================
131 void BooleanGUI_Dialog::Init()
134 myEditCurrentArgument = myGroup->LineEdit1;
136 /* signals and slots connections */
137 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
138 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
147 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
149 initName( GroupConstructors->title() );
151 globalSelection( GEOM_ALLSHAPES );
155 //=================================================================================
156 // function : ClickOnOk()
158 //=================================================================================
159 void BooleanGUI_Dialog::ClickOnOk()
161 if ( ClickOnApply() )
166 //=================================================================================
167 // function : ClickOnApply()
169 //=================================================================================
170 bool BooleanGUI_Dialog::ClickOnApply()
180 //=================================================================================
181 // function : SelectionIntoArgument()
182 // purpose : Called when selection has changed
183 //=================================================================================
184 void BooleanGUI_Dialog::SelectionIntoArgument()
186 myEditCurrentArgument->setText( "" );
188 if ( IObjectCount() != 1 )
190 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = GEOM::GEOM_Object::_nil();
191 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = GEOM::GEOM_Object::_nil();
196 Standard_Boolean aRes = Standard_False;
197 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
198 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) )
200 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
201 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = aSelectedObject;
202 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = aSelectedObject;
207 //=================================================================================
208 // function : SetEditCurrentArgument()
210 //=================================================================================
211 void BooleanGUI_Dialog::SetEditCurrentArgument()
213 QPushButton* send = (QPushButton*)sender();
215 if ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
216 else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
218 myEditCurrentArgument->setFocus();
219 SelectionIntoArgument();
223 //=================================================================================
224 // function : LineEditReturnPressed()
226 //=================================================================================
227 void BooleanGUI_Dialog::LineEditReturnPressed()
229 QLineEdit* send = (QLineEdit*)sender();
230 if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 )
232 myEditCurrentArgument = send;
233 GEOMBase_Skeleton::LineEditReturnPressed();
238 //=================================================================================
239 // function : ActivateThisDialog()
241 //=================================================================================
242 void BooleanGUI_Dialog::ActivateThisDialog()
244 GEOMBase_Skeleton::ActivateThisDialog();
245 globalSelection( GEOM_ALLSHAPES );
246 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
247 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
251 //=================================================================================
252 // function : enterEvent()
253 // purpose : when mouse enter onto the QWidget
254 //=================================================================================
255 void BooleanGUI_Dialog::enterEvent(QEvent * e)
257 if ( !GroupConstructors->isEnabled() )
258 ActivateThisDialog();
261 //=================================================================================
262 // function : createOperation
264 //=================================================================================
265 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
267 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
270 //=================================================================================
271 // function : isValid
273 //=================================================================================
274 bool BooleanGUI_Dialog::isValid( QString& msg )
276 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
279 //=================================================================================
280 // function : execute
282 //=================================================================================
283 bool BooleanGUI_Dialog::execute( ObjectList& objects )
285 GEOM::GEOM_Object_var anObj;
287 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakeBoolean( myObject1, myObject2, myOperation );
288 if ( !anObj->_is_nil() )
289 objects.push_back( anObj._retn() );