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 : RepairGUI_GlueDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "RepairGUI_GlueDlg.h"
32 #include "QAD_Desktop.h"
33 #include "QAD_SpinBoxDbl.h"
35 #include "OCCViewer_Viewer3d.h"
36 #include "DlgRef_1Sel_Ext.h"
37 #include "SALOME_ListIteratorOfListIO.hxx"
39 #include "GEOMImpl_Types.hxx"
41 #define DEFAULT_TOLERANCE_VALUE 1e-07
44 //=================================================================================
45 // class : RepairGUI_GlueDlg()
46 // purpose : Constructs a RepairGUI_GlueDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 RepairGUI_GlueDlg::RepairGUI_GlueDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_GLUE_FACES")));
55 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_GLUE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_GLUE_TITLE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
65 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
66 GroupPoints->GroupBox1->setTitle(tr("GEOM_GLUE"));
67 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
68 GroupPoints->PushButton1->setPixmap(image1);
69 GroupPoints->LineEdit1->setReadOnly( true );
71 Layout1->addWidget(GroupPoints, 2, 0);
73 QGridLayout* aLay = new QGridLayout( 0, 2, 2, 0, 6, "aLay" );
74 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->GroupBox1 );
75 myTolEdt = new QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0, 100, 1e-7, 10, 1e-10 );
76 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
78 aLay->addWidget( aLbl1, 0, 0 );
79 aLay->addWidget( myTolEdt, 0, 1 );
81 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
82 /***************************************************************/
88 //=================================================================================
89 // function : ~RepairGUI_GlueDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
97 //=================================================================================
100 //=================================================================================
101 void RepairGUI_GlueDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
106 myObject = GEOM::GEOM_Object::_nil();
108 myGeomGUI->SetState( 0 );
109 globalSelection( GEOM_COMPOUND );
111 /* signals and slots connections */
112 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
113 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
114 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
116 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
117 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
119 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
124 initName( tr( "GLUE_NEW_OBJ_NAME" ) );
128 //=================================================================================
129 // function : ClickOnOk()
130 // purpose : Same than click on apply but close this dialog.
131 //=================================================================================
132 void RepairGUI_GlueDlg::ClickOnOk()
134 if ( ClickOnApply() )
140 //=================================================================================
141 // function : ClickOnApply()
143 //=================================================================================
144 bool RepairGUI_GlueDlg::ClickOnApply()
151 GroupPoints->LineEdit1->setText("");
152 myObject = GEOM::GEOM_Object::_nil();
154 globalSelection( GEOM_COMPOUND );
160 //=================================================================================
161 // function : ClickOnCancel()
163 //=================================================================================
164 void RepairGUI_GlueDlg::ClickOnCancel()
166 GEOMBase_Skeleton::ClickOnCancel();
170 //=================================================================================
171 // function : SelectionIntoArgument()
172 // purpose : Called when selection
173 //=================================================================================
174 void RepairGUI_GlueDlg::SelectionIntoArgument()
177 myEditCurrentArgument->setText("");
178 myObject = GEOM::GEOM_Object::_nil();
180 if ( mySelection->IObjectCount() == 1 ) {
181 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
182 Standard_Boolean aRes;
183 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
185 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
189 //=================================================================================
190 // function : SetEditCurrentArgument()
192 //=================================================================================
193 void RepairGUI_GlueDlg::SetEditCurrentArgument()
195 const QObject* send = sender();
196 if ( send == GroupPoints->PushButton1 ) {
197 myEditCurrentArgument->setFocus();
198 SelectionIntoArgument();
203 //=================================================================================
204 // function : LineEditReturnPressed()
206 //=================================================================================
207 void RepairGUI_GlueDlg::LineEditReturnPressed()
209 const QObject* send = sender();
210 if( send == GroupPoints->LineEdit1 ) {
211 myEditCurrentArgument = GroupPoints->LineEdit1;
212 GEOMBase_Skeleton::LineEditReturnPressed();
217 //=================================================================================
218 // function : DeactivateActiveDialog()
220 //=================================================================================
221 void RepairGUI_GlueDlg::DeactivateActiveDialog()
223 myGeomGUI->SetState( -1 );
224 GEOMBase_Skeleton::DeactivateActiveDialog();
228 //=================================================================================
229 // function : ActivateThisDialog()
231 //=================================================================================
232 void RepairGUI_GlueDlg::ActivateThisDialog()
234 GEOMBase_Skeleton::ActivateThisDialog();
235 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
237 GroupPoints->LineEdit1->setText("");
238 myObject = GEOM::GEOM_Object::_nil();
240 myGeomGUI->SetState( 0 );
241 globalSelection( GEOM_COMPOUND );
245 //=================================================================================
246 // function : enterEvent()
247 // purpose : Mouse enter onto the dialog to activate it
248 //=================================================================================
249 void RepairGUI_GlueDlg::enterEvent(QEvent* e)
251 if ( !GroupConstructors->isEnabled() )
252 ActivateThisDialog();
256 //=================================================================================
257 // function : closeEvent()
259 //=================================================================================
260 void RepairGUI_GlueDlg::closeEvent(QCloseEvent* e)
262 myGeomGUI->SetState( -1 );
263 GEOMBase_Skeleton::closeEvent( e );
266 //=================================================================================
267 // function : createOperation
269 //=================================================================================
270 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
272 return getGeomEngine()->GetIShapesOperations( getStudyId() );
275 //=================================================================================
276 // function : isValid
278 //=================================================================================
279 bool RepairGUI_GlueDlg::isValid( QString& msg )
281 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
284 //=================================================================================
285 // function : execute
287 //=================================================================================
288 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
290 bool aResult = false;
291 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeGlueFaces( myObject, myTolEdt->value() );
292 aResult = !anObj->_is_nil();
294 objects.push_back( anObj._retn() );