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