Salome HOME
Synchronize adm files
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveExtraEdgesDlg.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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   //Hide preview checkbox
111   mainFrame()->CheckBoxPreview->hide();
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   SelectionIntoArgument();
126 }
127
128
129 //=================================================================================
130 // function : ClickOnOk()
131 // purpose  : Same than click on apply but close this dialog.
132 //=================================================================================
133 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
134 {
135   setIsApplyAndClose( true );
136   if ( ClickOnApply() )
137     ClickOnCancel();
138 }
139
140 //=================================================================================
141 // function : ClickOnApply()
142 // purpose  :
143 //=================================================================================
144 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
145 {
146   if ( !onAccept() )
147     return false;
148
149   initName();
150
151   myEditCurrentArgument->setText( "" );
152   myObject = GEOM::GEOM_Object::_nil();
153   
154   myOkObject = false;
155
156   activateSelection();
157
158   return true;
159 }
160
161
162 //=================================================================================
163 // function : SelectionIntoArgument()
164 // purpose  : Called when selection as changed or other case
165 //          : used only by SelectButtonC1A1 (LineEditC1A1)
166 //=================================================================================
167 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
168 {
169   myEditCurrentArgument->setText( "" );
170   QString aName;
171   
172   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
173   SALOME_ListIO aSelList;
174   aSelMgr->selectedObjects(aSelList);
175
176   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
177     if ( aSelList.Extent() != 1 ) {
178       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
179         myOkObject = false;
180       return;
181     }
182   }
183   
184   // nbSel == 1
185   GEOM::GEOM_Object_ptr aSelectedObject =
186     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
187
188   if ( CORBA::is_nil( aSelectedObject ) )
189     return;
190   
191   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
192     myObject = aSelectedObject;
193     myOkObject = true;
194   }
195
196   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
197 }
198
199 //=================================================================================
200 // function : SetEditCurrentArgument()
201 // purpose  :
202 //=================================================================================
203 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
204 {
205   if( sender() == GroupPoints->PushButton1 ) {
206     GroupPoints->LineEdit1->setFocus();
207     myEditCurrentArgument = GroupPoints->LineEdit1;
208   }
209   SelectionIntoArgument();
210 }
211
212
213 //=================================================================================
214 // function : LineEditReturnPressed()
215 // purpose  :
216 //=================================================================================
217 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
218 {
219   if ( sender() == GroupPoints->LineEdit1 ) {
220     myEditCurrentArgument = GroupPoints->LineEdit1;
221     GEOMBase_Skeleton::LineEditReturnPressed();
222   }
223 }
224
225
226 //=================================================================================
227 // function : ActivateThisDialog()
228 // purpose  :
229 //=================================================================================
230 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
231 {
232   GEOMBase_Skeleton::ActivateThisDialog();
233   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
234            this, SLOT( SelectionIntoArgument() ) );
235
236   activateSelection();
237 }
238
239
240 //=================================================================================
241 // function : enterEvent()
242 // purpose  : Mouse enter onto the dialog to activate it
243 //=================================================================================
244 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
245 {
246   if ( !mainFrame()->GroupConstructors->isEnabled() )
247     ActivateThisDialog();
248 }
249
250
251 //=================================================================================
252 // function : activateSelection
253 // purpose  : activate selection of solids and compounds
254 //=================================================================================
255 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
256 {
257   TColStd_MapOfInteger aTypes;
258   aTypes.Add( GEOM_SHELL );
259   aTypes.Add( GEOM_SOLID );
260   aTypes.Add( GEOM_COMPOUND );
261   globalSelection( aTypes );
262 }
263
264 //=================================================================================
265 // function : createOperation
266 // purpose  :
267 //=================================================================================
268 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
269 {
270   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
271 }
272
273 //=================================================================================
274 // function : isValid
275 // purpose  :
276 //=================================================================================
277 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
278 {
279   return myOkObject;
280 }
281
282 //=================================================================================
283 // function : execute
284 // purpose  :
285 //=================================================================================
286 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
287 {
288   GEOM::GEOM_Object_var anObj;
289
290   int nbFacesOptimum = -1; // -1 means do not union faces
291   if (GroupPoints->CheckButton1->isChecked())
292     nbFacesOptimum = 0; // 0 means union all faces, that possible
293   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
294   anObj = anOper->RemoveExtraEdges(myObject, nbFacesOptimum);
295
296   if (!anObj->_is_nil())
297     objects.push_back(anObj._retn());
298
299   return true;
300 }
301
302 //=================================================================================
303 // function : restoreSubShapes
304 // purpose  :
305 //=================================================================================
306 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
307                                                       SALOMEDS::SObject_ptr theSObject )
308 {
309   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
310     // empty list of arguments means that all arguments should be restored
311     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
312                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
313                                          /*theInheritFirstArg=*/true,
314                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
315   }
316 }