Salome HOME
Code refactoring
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveExtraEdgesDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  GEOM RepairGUI : GUI for Geometry component
21 //  File   : RepairGUI_RemoveExtraEdgesDlg.cxx
22 //  Author : Michael Zorin, Open CASCADE S.A.S.
23 //
24 #include "RepairGUI_RemoveExtraEdgesDlg.h"
25
26 #include <DlgRef.h>
27 #include <GeometryGUI.h>
28 #include <GEOMBase.h>
29
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34
35 #include <GEOMImpl_Types.hxx>
36
37 #include <TColStd_MapOfInteger.hxx>
38
39 //=================================================================================
40 // class    : RepairGUI_RemoveExtraEdgesDlg()
41 // purpose  : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47                                                               bool modal )
48   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
49 {
50   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
51   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REMOVE_EXTRA_EDGES" ) ) );
52   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53     
54   setWindowTitle( tr( "GEOM_REMOVE_EXTRA_EDGES_TITLE" ) );
55
56   /***************************************************************/
57   mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
58   mainFrame()->RadioButton1->setIcon( image0 );
59   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60   mainFrame()->RadioButton2->close();
61   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62   mainFrame()->RadioButton3->close();
63
64   GroupPoints = new DlgRef_1Sel1Check( centralWidget() );
65
66   GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_EXTRA_EDGES" ) );
67   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
68   GroupPoints->PushButton1->setIcon( image1 );
69   GroupPoints->LineEdit1->setReadOnly( true );
70
71   GroupPoints->CheckButton1->setText( tr( "GEOM_RMEE_UNION_FACES" ) );
72
73   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74   layout->setMargin( 0 ); layout->setSpacing( 6 );
75   layout->addWidget( GroupPoints );
76
77   /***************************************************************/
78   
79   setHelpFileName( "remove_extra_edges_operation_page.html" );
80
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~RepairGUI_RemoveExtraEdgesDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
90 {
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void RepairGUI_RemoveExtraEdgesDlg::Init()
99 {
100   /* init variables */
101   myEditCurrentArgument = GroupPoints->LineEdit1;
102   
103   myOkObject = false;
104
105   GroupPoints->CheckButton1->setChecked( false );
106
107   activateSelection();
108   
109   mainFrame()->GroupBoxPublish->show();
110
111   /* signals and slots connections */
112   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
113   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
114
115   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
116   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
117
118   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
119            this, SLOT( SelectionIntoArgument() ) );
120
121   initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
122   resize(100,100);
123   SelectionIntoArgument();
124 }
125
126
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose  : Same than click on apply but close this dialog.
130 //=================================================================================
131 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
132 {
133   if ( ClickOnApply() )
134     ClickOnCancel();
135 }
136
137 //=================================================================================
138 // function : ClickOnApply()
139 // purpose  :
140 //=================================================================================
141 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
142 {
143   if ( !onAccept() )
144     return false;
145
146   initName();
147
148   myEditCurrentArgument->setText( "" );
149   myObject = GEOM::GEOM_Object::_nil();
150   
151   myOkObject = false;
152
153   activateSelection();
154
155   return true;
156 }
157
158
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose  : Called when selection as changed or other case
162 //          : used only by SelectButtonC1A1 (LineEditC1A1)
163 //=================================================================================
164 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
165 {
166   myEditCurrentArgument->setText( "" );
167   QString aName;
168   
169   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
170   SALOME_ListIO aSelList;
171   aSelMgr->selectedObjects(aSelList);
172
173   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
174     if ( aSelList.Extent() != 1 ) {
175       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
176         myOkObject = false;
177       return;
178     }
179   }
180   
181   // nbSel == 1
182   GEOM::GEOM_Object_ptr aSelectedObject =
183     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
184
185   if ( CORBA::is_nil( aSelectedObject ) )
186     return;
187   
188   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
189     myObject = aSelectedObject;
190     myOkObject = true;
191   }
192
193   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
194 }
195
196 //=================================================================================
197 // function : SetEditCurrentArgument()
198 // purpose  :
199 //=================================================================================
200 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
201 {
202   if( sender() == GroupPoints->PushButton1 ) {
203     GroupPoints->LineEdit1->setFocus();
204     myEditCurrentArgument = GroupPoints->LineEdit1;
205   }
206   SelectionIntoArgument();
207 }
208
209
210 //=================================================================================
211 // function : LineEditReturnPressed()
212 // purpose  :
213 //=================================================================================
214 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
215 {
216   if ( sender() == GroupPoints->LineEdit1 ) {
217     myEditCurrentArgument = GroupPoints->LineEdit1;
218     GEOMBase_Skeleton::LineEditReturnPressed();
219   }
220 }
221
222
223 //=================================================================================
224 // function : ActivateThisDialog()
225 // purpose  :
226 //=================================================================================
227 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
228 {
229   GEOMBase_Skeleton::ActivateThisDialog();
230   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
231            this, SLOT( SelectionIntoArgument() ) );
232
233   activateSelection();
234 }
235
236
237 //=================================================================================
238 // function : enterEvent()
239 // purpose  : Mouse enter onto the dialog to activate it
240 //=================================================================================
241 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
242 {
243   if ( !mainFrame()->GroupConstructors->isEnabled() )
244     ActivateThisDialog();
245 }
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_SHELL );
256   aTypes.Add( GEOM_SOLID );
257   aTypes.Add( GEOM_COMPOUND );
258   globalSelection( aTypes );
259 }
260
261 //=================================================================================
262 // function : createOperation
263 // purpose  :
264 //=================================================================================
265 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
266 {
267   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
268 }
269
270 //=================================================================================
271 // function : isValid
272 // purpose  :
273 //=================================================================================
274 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
275 {
276   return myOkObject;
277 }
278
279 //=================================================================================
280 // function : execute
281 // purpose  :
282 //=================================================================================
283 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
284 {
285   GEOM::GEOM_Object_var anObj;
286
287   int nbFacesOptimum = -1; // -1 means do not union faces
288   if (GroupPoints->CheckButton1->isChecked())
289     nbFacesOptimum = 0; // 0 means union all faces, that possible
290   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
291   anObj = anOper->RemoveExtraEdges(myObject, nbFacesOptimum);
292
293   if (!anObj->_is_nil())
294     objects.push_back(anObj._retn());
295
296   return true;
297 }
298
299 //=================================================================================
300 // function : restoreSubShapes
301 // purpose  :
302 //=================================================================================
303 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
304                                                       SALOMEDS::SObject_ptr theSObject )
305 {
306   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
307     // empty list of arguments means that all arguments should be restored
308     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
309                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
310                                          /*theInheritFirstArg=*/true,
311                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
312   }
313 }