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