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