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 "QAD_Desktop.h"
36 //=================================================================================
37 // class : BooleanGUI_Dialog()
38 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
39 // name 'name' and widget flags set to 'f'.
40 // The dialog will by default be modeless, unless you set 'modal' to
41 // TRUE to construct a modal dialog.
42 //=================================================================================
43 BooleanGUI_Dialog::BooleanGUI_Dialog( const int theOperation, QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
44 :GEOMBase_Skeleton(parent, name, Sel, modal, fl),
45 myOperation( theOperation )
48 QString aTitle, aCaption;
49 switch ( myOperation )
51 case BooleanGUI::COMMON:
52 image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_COMMON")));
53 aTitle = tr("GEOM_COMMON");
54 aCaption = tr("GEOM_COMMON_TITLE");
57 image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CUT")));
58 aTitle = tr("GEOM_CUT");
59 aCaption = tr("GEOM_CUT_TITLE");
61 case BooleanGUI::FUSE:
62 image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FUSE")));
63 aTitle = tr("GEOM_FUSE");
64 aCaption = tr("GEOM_FUSE_TITLE");
66 case BooleanGUI::SECTION:
67 image0 = QPixmap( QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SECTION")));
68 aTitle = tr("GEOM_SECTION");
69 aCaption = tr("GEOM_SECTION_TITLE");
72 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
74 setCaption( aCaption );
76 /***************************************************************/
77 GroupConstructors->setTitle( aTitle );
78 RadioButton1->setPixmap( image0 );
79 RadioButton2->close(TRUE);
80 RadioButton3->close(TRUE);
82 myGroup = new DlgRef_2Sel_QTD(this, "GroupCommon");
83 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
84 if ( myOperation != BooleanGUI::CUT )
86 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
87 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
91 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
92 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
95 myGroup->PushButton1->setPixmap(image1);
96 myGroup->PushButton2->setPixmap(image1);
97 myGroup->LineEdit1->setReadOnly( true );
98 myGroup->LineEdit2->setReadOnly( true );
100 Layout1->addWidget(myGroup, 2, 0);
101 /***************************************************************/
108 //=================================================================================
109 // function : ~BooleanGUI_Dialog()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 BooleanGUI_Dialog::~BooleanGUI_Dialog()
118 //=================================================================================
121 //=================================================================================
122 void BooleanGUI_Dialog::Init()
125 myEditCurrentArgument = myGroup->LineEdit1;
127 /* signals and slots connections */
128 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
131 connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
139 initName( GroupConstructors->title() );
141 globalSelection( GEOM_ALLSHAPES );
145 //=================================================================================
146 // function : ClickOnOk()
148 //=================================================================================
149 void BooleanGUI_Dialog::ClickOnOk()
151 if ( ClickOnApply() )
156 //=================================================================================
157 // function : ClickOnApply()
159 //=================================================================================
160 bool BooleanGUI_Dialog::ClickOnApply()
170 //=================================================================================
171 // function : SelectionIntoArgument()
172 // purpose : Called when selection has changed
173 //=================================================================================
174 void BooleanGUI_Dialog::SelectionIntoArgument()
176 myEditCurrentArgument->setText( "" );
178 if ( mySelection->IObjectCount() != 1 )
180 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = GEOM::GEOM_Object::_nil();
181 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = GEOM::GEOM_Object::_nil();
186 Standard_Boolean aRes = Standard_False;
187 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
188 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) )
190 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
191 if ( myEditCurrentArgument == myGroup->LineEdit1 ) myObject1 = aSelectedObject;
192 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) myObject2 = aSelectedObject;
197 //=================================================================================
198 // function : SetEditCurrentArgument()
200 //=================================================================================
201 void BooleanGUI_Dialog::SetEditCurrentArgument()
203 QPushButton* send = (QPushButton*)sender();
205 if ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
206 else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
208 myEditCurrentArgument->setFocus();
209 SelectionIntoArgument();
214 //=================================================================================
215 // function : LineEditReturnPressed()
217 //=================================================================================
218 void BooleanGUI_Dialog::LineEditReturnPressed()
220 QLineEdit* send = (QLineEdit*)sender();
221 if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 )
223 myEditCurrentArgument = send;
224 GEOMBase_Skeleton::LineEditReturnPressed();
229 //=================================================================================
230 // function : ActivateThisDialog()
232 //=================================================================================
233 void BooleanGUI_Dialog::ActivateThisDialog()
235 GEOMBase_Skeleton::ActivateThisDialog();
236 globalSelection( GEOM_ALLSHAPES );
237 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241 //=================================================================================
242 // function : enterEvent()
243 // purpose : when mouse enter onto the QWidget
244 //=================================================================================
245 void BooleanGUI_Dialog::enterEvent(QEvent * e)
247 if ( !GroupConstructors->isEnabled() )
248 ActivateThisDialog();
251 //=================================================================================
252 // function : createOperation
254 //=================================================================================
255 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
257 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
260 //=================================================================================
261 // function : isValid
263 //=================================================================================
264 bool BooleanGUI_Dialog::isValid( QString& msg )
266 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
269 //=================================================================================
270 // function : execute
272 //=================================================================================
273 bool BooleanGUI_Dialog::execute( ObjectList& objects )
275 GEOM::GEOM_Object_var anObj;
277 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakeBoolean( myObject1, myObject2, myOperation );
278 if ( !anObj->_is_nil() )
279 objects.push_back( anObj._retn() );