]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_RemoveExtraEdgesDlg.cxx
Salome HOME
NPAL14167: Parameter isTrsf replaced by two: theFindMethod and theInheritFirstArg.
[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   activateSelection();
144
145   return true;
146 }
147
148
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose  : Called when selection as changed or other case
152 //          : used only by SelectButtonC1A1 (LineEditC1A1)
153 //=================================================================================
154 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
155 {
156   myEditCurrentArgument->setText("");
157   QString aName;
158
159   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
160     if (IObjectCount() != 1) {
161       if (myEditCurrentArgument == GroupPoints->LineEdit1)
162         myOkObject = false;
163       return;
164     }
165   }
166
167   // nbSel == 1
168   Standard_Boolean testResult = Standard_False;
169   GEOM::GEOM_Object_ptr aSelectedObject =
170     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
171
172   if (!testResult)
173     return;
174
175   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
176     myObject = aSelectedObject;
177     myOkObject = true;
178   }
179
180   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
181 }
182
183 //=================================================================================
184 // function : SetEditCurrentArgument()
185 // purpose  :
186 //=================================================================================
187 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
188 {
189   if( sender() == GroupPoints->PushButton1 )
190   {
191     GroupPoints->LineEdit1->setFocus();
192     myEditCurrentArgument = GroupPoints->LineEdit1;
193   }
194   SelectionIntoArgument();
195 }
196
197
198 //=================================================================================
199 // function : LineEditReturnPressed()
200 // purpose  :
201 //=================================================================================
202 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
203 {
204   if( sender() == GroupPoints->LineEdit1 )
205   {
206     myEditCurrentArgument = GroupPoints->LineEdit1;
207     GEOMBase_Skeleton::LineEditReturnPressed();
208   }
209 }
210
211
212 //=================================================================================
213 // function : ActivateThisDialog()
214 // purpose  :
215 //=================================================================================
216 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
217 {
218   GEOMBase_Skeleton::ActivateThisDialog();
219   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
220           this, SLOT(SelectionIntoArgument()));
221
222   activateSelection();
223 }
224
225
226 //=================================================================================
227 // function : enterEvent()
228 // purpose  : Mouse enter onto the dialog to activate it
229 //=================================================================================
230 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
231 {
232   if ( !GroupConstructors->isEnabled() )
233     ActivateThisDialog();
234 }
235
236
237 //=================================================================================
238 // function : closeEvent()
239 // purpose  :
240 //=================================================================================
241 void RepairGUI_RemoveExtraEdgesDlg::closeEvent(QCloseEvent* e)
242 {
243   GEOMBase_Skeleton::closeEvent( e );
244 }
245
246 //=================================================================================
247 // function : activateSelection
248 // purpose  : activate selection of solids and compounds
249 //=================================================================================
250 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
251 {
252   TColStd_MapOfInteger aTypes;
253   aTypes.Add( GEOM_SOLID );
254   aTypes.Add( GEOM_COMPOUND );
255   globalSelection( aTypes );
256 }
257
258 //=================================================================================
259 // function : createOperation
260 // purpose  :
261 //=================================================================================
262 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
263 {
264   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
265 }
266
267 //=================================================================================
268 // function : isValid
269 // purpose  :
270 //=================================================================================
271 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
272 {
273   return myOkObject;
274 }
275
276 //=================================================================================
277 // function : execute
278 // purpose  :
279 //=================================================================================
280 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
281 {
282   GEOM::GEOM_Object_var anObj;
283
284   anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->RemoveExtraEdges(myObject);
285
286   if ( !anObj->_is_nil() )
287     objects.push_back( anObj._retn() );
288
289   return true;
290 }
291
292 //=================================================================================
293 // function : restoreSubShapes
294 // purpose  :
295 //=================================================================================
296 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
297                                                       SALOMEDS::SObject_ptr theSObject)
298 {
299   if (CheckBoxRestoreSS->isChecked()) {
300     // empty list of arguments means that all arguments should be restored
301     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
302                                         /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
303                                         /*theInheritFirstArg=*/true);
304   }
305 }