Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / RepairGUI / RepairGUI_GlueDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : RepairGUI_GlueDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "RepairGUI_GlueDlg.h"
31
32 #include "QAD_Desktop.h"
33 #include "QAD_SpinBoxDbl.h"
34
35 #include "OCCViewer_Viewer3d.h"
36 #include "DlgRef_1Sel_Ext.h"
37 #include "SALOME_ListIteratorOfListIO.hxx"
38
39 #include "GEOMImpl_Types.hxx"
40
41 #define DEFAULT_TOLERANCE_VALUE 1e-07
42
43
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)
53 {
54   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_GLUE_FACES")));
55   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
56
57   setCaption(tr("GEOM_GLUE_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_GLUE_TITLE"));
61   RadioButton1->setPixmap(image0);
62   RadioButton2->close(TRUE);
63   RadioButton3->close(TRUE);
64
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 );
70
71   Layout1->addWidget(GroupPoints, 2, 0);
72
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 );
77
78   aLay->addWidget( aLbl1, 0, 0 );
79   aLay->addWidget( myTolEdt, 0, 1 );
80
81   GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
82   /***************************************************************/
83
84   Init();
85 }
86
87
88 //=================================================================================
89 // function : ~RepairGUI_GlueDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //=================================================================================
92 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
93 {
94 }
95
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void RepairGUI_GlueDlg::Init()
102 {
103   /* init variables */
104   myEditCurrentArgument = GroupPoints->LineEdit1;
105
106   myObject = GEOM::GEOM_Object::_nil();
107
108   myGeomGUI->SetState( 0 );
109   globalSelection( GEOM_COMPOUND );
110
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()));
115
116   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
117   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118
119   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121
122   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
123
124   initName( tr( "GLUE_NEW_OBJ_NAME" ) );
125 }
126
127
128 //=================================================================================
129 // function : ClickOnOk()
130 // purpose  : Same than click on apply but close this dialog.
131 //=================================================================================
132 void RepairGUI_GlueDlg::ClickOnOk()
133 {
134   if ( ClickOnApply() )
135     ClickOnCancel();
136 }
137
138
139
140 //=================================================================================
141 // function : ClickOnApply()
142 // purpose  :
143 //=================================================================================
144 bool RepairGUI_GlueDlg::ClickOnApply()
145 {
146   if ( !onAccept() )
147     return false;
148
149   initName();
150
151   GroupPoints->LineEdit1->setText("");
152   myObject = GEOM::GEOM_Object::_nil();
153
154   globalSelection( GEOM_COMPOUND );
155
156   return true;
157 }
158
159
160 //=================================================================================
161 // function : ClickOnCancel()
162 // purpose  :
163 //=================================================================================
164 void RepairGUI_GlueDlg::ClickOnCancel()
165 {
166   GEOMBase_Skeleton::ClickOnCancel();
167 }
168
169
170 //=================================================================================
171 // function : SelectionIntoArgument()
172 // purpose  : Called when selection
173 //=================================================================================
174 void RepairGUI_GlueDlg::SelectionIntoArgument()
175 {
176   erasePreview();
177   myEditCurrentArgument->setText("");
178   myObject = GEOM::GEOM_Object::_nil();
179
180   if ( mySelection->IObjectCount() == 1 ) {
181     Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
182     Standard_Boolean aRes;
183     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
184     if ( aRes )
185       myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
186   }
187 }
188
189 //=================================================================================
190 // function : SetEditCurrentArgument()
191 // purpose  :
192 //=================================================================================
193 void RepairGUI_GlueDlg::SetEditCurrentArgument()
194 {
195   const QObject* send = sender();
196   if ( send == GroupPoints->PushButton1 )  {
197     myEditCurrentArgument->setFocus();
198     SelectionIntoArgument();
199   }
200 }
201
202
203 //=================================================================================
204 // function : LineEditReturnPressed()
205 // purpose  :
206 //=================================================================================
207 void RepairGUI_GlueDlg::LineEditReturnPressed()
208 {
209   const QObject* send = sender();
210   if( send == GroupPoints->LineEdit1 ) {
211     myEditCurrentArgument = GroupPoints->LineEdit1;
212     GEOMBase_Skeleton::LineEditReturnPressed();
213   }
214 }
215
216
217 //=================================================================================
218 // function : DeactivateActiveDialog()
219 // purpose  :
220 //=================================================================================
221 void RepairGUI_GlueDlg::DeactivateActiveDialog()
222 {
223   myGeomGUI->SetState( -1 );
224   GEOMBase_Skeleton::DeactivateActiveDialog();
225 }
226
227
228 //=================================================================================
229 // function : ActivateThisDialog()
230 // purpose  :
231 //=================================================================================
232 void RepairGUI_GlueDlg::ActivateThisDialog()
233 {
234   GEOMBase_Skeleton::ActivateThisDialog();
235   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
236
237   GroupPoints->LineEdit1->setText("");
238   myObject = GEOM::GEOM_Object::_nil();
239
240   myGeomGUI->SetState( 0 );
241   globalSelection( GEOM_COMPOUND );
242 }
243
244
245 //=================================================================================
246 // function : enterEvent()
247 // purpose  : Mouse enter onto the dialog to activate it
248 //=================================================================================
249 void RepairGUI_GlueDlg::enterEvent(QEvent* e)
250 {
251   if ( !GroupConstructors->isEnabled() )
252     ActivateThisDialog();
253 }
254
255
256 //=================================================================================
257 // function : closeEvent()
258 // purpose  :
259 //=================================================================================
260 void RepairGUI_GlueDlg::closeEvent(QCloseEvent* e)
261 {
262   myGeomGUI->SetState( -1 );
263   GEOMBase_Skeleton::closeEvent( e );
264 }
265
266 //=================================================================================
267 // function : createOperation
268 // purpose  :
269 //=================================================================================
270 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
271 {
272   return getGeomEngine()->GetIShapesOperations( getStudyId() );
273 }
274
275 //=================================================================================
276 // function : isValid
277 // purpose  :
278 //=================================================================================
279 bool RepairGUI_GlueDlg::isValid( QString& msg )
280 {
281   return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
282 }
283
284 //=================================================================================
285 // function : execute
286 // purpose  :
287 //=================================================================================
288 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
289 {
290   bool aResult = false;
291   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeGlueFaces( myObject, myTolEdt->value() );
292   aResult = !anObj->_is_nil();
293   if ( aResult )
294     objects.push_back( anObj._retn() );
295
296   return aResult;
297 }