Salome HOME
This commit was generated by cvs2git to create tag 'V4_1_0rc1'.
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveExtraEdgesDlg.cxx
1 //  GEOM RepairGUI : 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : RepairGUI_RemoveExtraEdgesDlg.cxx
25 //  Author : Michael Zorin
26 //  Module : GEOM
27 //  $Header$
28
29 #include "RepairGUI_RemoveExtraEdgesDlg.h"
30
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33 #include "SUIT_Session.h"
34
35 #include "GEOMImpl_Types.hxx"
36
37 #include <TColStd_MapOfInteger.hxx>
38
39 #include <qlabel.h>
40 #include <qcheckbox.h>
41
42 //=================================================================================
43 // class    : RepairGUI_RemoveExtraEdgesDlg()
44 // purpose  : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
50                                                              const char* name, bool modal, WFlags fl)
51   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
52                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 {
54   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
55   QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_REMOVE_EXTRA_EDGES")));
56   QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
62   RadioButton1->setPixmap(image0);
63   RadioButton2->close(TRUE);
64   RadioButton3->close(TRUE);
65
66   GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
67   GroupPoints->GroupBox1->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES"));
68   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
69   GroupPoints->PushButton1->setPixmap(image1);
70   GroupPoints->LineEdit1->setReadOnly( true );
71
72   Layout1->addWidget(GroupPoints, 2, 0);
73   /***************************************************************/
74
75   setHelpFileName("remove_extra_edges_operation_page.html");
76
77   Init();
78 }
79
80
81 //=================================================================================
82 // function : ~RepairGUI_RemoveExtraEdgesDlg()
83 // purpose  : Destroys the object and frees any allocated resources
84 //=================================================================================
85 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
86 {
87 }
88
89
90 //=================================================================================
91 // function : Init()
92 // purpose  :
93 //=================================================================================
94 void RepairGUI_RemoveExtraEdgesDlg::Init()
95 {
96   /* init variables */
97   myEditCurrentArgument = GroupPoints->LineEdit1;
98
99   myOkObject = false;
100
101   activateSelection();
102
103   GroupBoxPublish->show();
104
105   /* signals and slots connections */
106   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108
109   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111
112   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
113           this, SLOT(SelectionIntoArgument()));
114
115   initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
116 }
117
118
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose  : Same than click on apply but close this dialog.
122 //=================================================================================
123 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
124 {
125   if ( ClickOnApply() )
126     ClickOnCancel();
127 }
128
129 //=================================================================================
130 // function : ClickOnApply()
131 // purpose  :
132 //=================================================================================
133 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
134 {
135   if ( !onAccept() )
136     return false;
137
138   initName();
139
140   myEditCurrentArgument->setText("");
141   myObject = GEOM::GEOM_Object::_nil();
142
143   myOkObject = false;
144
145   activateSelection();
146
147   return true;
148 }
149
150
151 //=================================================================================
152 // function : SelectionIntoArgument()
153 // purpose  : Called when selection as changed or other case
154 //          : used only by SelectButtonC1A1 (LineEditC1A1)
155 //=================================================================================
156 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
157 {
158   myEditCurrentArgument->setText("");
159   QString aName;
160
161   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
162     if (IObjectCount() != 1) {
163       if (myEditCurrentArgument == GroupPoints->LineEdit1)
164         myOkObject = false;
165       return;
166     }
167   }
168
169   // nbSel == 1
170   Standard_Boolean testResult = Standard_False;
171   GEOM::GEOM_Object_ptr aSelectedObject =
172     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
173
174   if (!testResult)
175     return;
176
177   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
178     myObject = aSelectedObject;
179     myOkObject = true;
180   }
181
182   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
183 }
184
185 //=================================================================================
186 // function : SetEditCurrentArgument()
187 // purpose  :
188 //=================================================================================
189 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
190 {
191   if( sender() == GroupPoints->PushButton1 )
192   {
193     GroupPoints->LineEdit1->setFocus();
194     myEditCurrentArgument = GroupPoints->LineEdit1;
195   }
196   SelectionIntoArgument();
197 }
198
199
200 //=================================================================================
201 // function : LineEditReturnPressed()
202 // purpose  :
203 //=================================================================================
204 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
205 {
206   if( sender() == GroupPoints->LineEdit1 )
207   {
208     myEditCurrentArgument = GroupPoints->LineEdit1;
209     GEOMBase_Skeleton::LineEditReturnPressed();
210   }
211 }
212
213
214 //=================================================================================
215 // function : ActivateThisDialog()
216 // purpose  :
217 //=================================================================================
218 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
219 {
220   GEOMBase_Skeleton::ActivateThisDialog();
221   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
222           this, SLOT(SelectionIntoArgument()));
223
224   activateSelection();
225 }
226
227
228 //=================================================================================
229 // function : enterEvent()
230 // purpose  : Mouse enter onto the dialog to activate it
231 //=================================================================================
232 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
233 {
234   if ( !GroupConstructors->isEnabled() )
235     ActivateThisDialog();
236 }
237
238
239 //=================================================================================
240 // function : closeEvent()
241 // purpose  :
242 //=================================================================================
243 void RepairGUI_RemoveExtraEdgesDlg::closeEvent(QCloseEvent* e)
244 {
245   GEOMBase_Skeleton::closeEvent( e );
246 }
247
248 //=================================================================================
249 // function : activateSelection
250 // purpose  : activate selection of solids and compounds
251 //=================================================================================
252 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
253 {
254   TColStd_MapOfInteger aTypes;
255   aTypes.Add( GEOM_SOLID );
256   aTypes.Add( GEOM_COMPOUND );
257   globalSelection( aTypes );
258 }
259
260 //=================================================================================
261 // function : createOperation
262 // purpose  :
263 //=================================================================================
264 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
265 {
266   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
267 }
268
269 //=================================================================================
270 // function : isValid
271 // purpose  :
272 //=================================================================================
273 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
274 {
275   return myOkObject;
276 }
277
278 //=================================================================================
279 // function : execute
280 // purpose  :
281 //=================================================================================
282 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
283 {
284   GEOM::GEOM_Object_var anObj;
285
286   anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->RemoveExtraEdges(myObject);
287
288   if ( !anObj->_is_nil() )
289     objects.push_back( anObj._retn() );
290
291   return true;
292 }
293
294 //=================================================================================
295 // function : restoreSubShapes
296 // purpose  :
297 //=================================================================================
298 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
299                                                       SALOMEDS::SObject_ptr theSObject)
300 {
301   if (CheckBoxRestoreSS->isChecked()) {
302     // empty list of arguments means that all arguments should be restored
303     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
304                                         /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
305                                         /*theInheritFirstArg=*/true);
306   }
307 }