Salome HOME
Mantis issue 0021934: Delete the internal faces of an object
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveWebsDlg.cxx
1 // Copyright (C) 2007-2013  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 //  GEOM RepairGUI : GUI for Geometry component
20 //  File   : RepairGUI_RemoveWebsDlg.cxx
21
22 #include "RepairGUI_RemoveWebsDlg.h"
23
24 #include <DlgRef.h>
25 #include <GeometryGUI.h>
26 #include <GEOMBase.h>
27
28 #include <SalomeApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32
33 #include <GEOMImpl_Types.hxx>
34
35 #include <TColStd_MapOfInteger.hxx>
36
37 //=================================================================================
38 // class    : RepairGUI_RemoveWebsDlg()
39 // purpose  : Constructs a RepairGUI_RemoveWebsDlg which is a child of 'parent', with the
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            TRUE to construct a modal dialog.
43 //=================================================================================
44 RepairGUI_RemoveWebsDlg::RepairGUI_RemoveWebsDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
45                                                   bool modal)
46   : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
47 {
48   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
49   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_REMOVE_WEBS")));
50   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
51
52   setWindowTitle(tr("GEOM_REMOVE_WEBS_TITLE"));
53
54   /***************************************************************/
55   mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_WEBS_TITLE"));
56   mainFrame()->RadioButton1->setIcon( image0 );
57   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58   mainFrame()->RadioButton2->close();
59   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60   mainFrame()->RadioButton3->close();
61
62   GroupPoints = new DlgRef_1Sel( centralWidget() );
63
64   GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_WEBS" ) );
65   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
66   GroupPoints->PushButton1->setIcon( image1 );
67   GroupPoints->LineEdit1->setReadOnly( true );
68
69   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
70   layout->setMargin( 0 ); layout->setSpacing( 6 );
71   layout->addWidget( GroupPoints );
72
73   /***************************************************************/
74
75   setHelpFileName( "remove_webs_operation_page.html" );
76
77   Init();
78 }
79
80 //=================================================================================
81 // function : ~RepairGUI_RemoveWebsDlg()
82 // purpose  : Destroys the object and frees any allocated resources
83 //=================================================================================
84 RepairGUI_RemoveWebsDlg::~RepairGUI_RemoveWebsDlg()
85 {
86 }
87
88 //=================================================================================
89 // function : Init()
90 // purpose  :
91 //=================================================================================
92 void RepairGUI_RemoveWebsDlg::Init()
93 {
94   /* init variables */
95   myEditCurrentArgument = GroupPoints->LineEdit1;
96
97   myOkObject = false;
98
99   activateSelection();
100
101   mainFrame()->GroupBoxPublish->show();
102   //Hide preview checkbox
103   mainFrame()->CheckBoxPreview->hide();
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_WEBS_NEW_OBJ_NAME"));
116   resize(100,100);
117   SelectionIntoArgument();
118 }
119
120 //=================================================================================
121 // function : ClickOnOk()
122 // purpose  : Same than click on apply but close this dialog.
123 //=================================================================================
124 void RepairGUI_RemoveWebsDlg::ClickOnOk()
125 {
126   setIsApplyAndClose(true);
127   if (ClickOnApply())
128     ClickOnCancel();
129 }
130
131 //=================================================================================
132 // function : ClickOnApply()
133 // purpose  :
134 //=================================================================================
135 bool RepairGUI_RemoveWebsDlg::ClickOnApply()
136 {
137   if (!onAccept())
138     return false;
139
140   initName();
141
142   myEditCurrentArgument->setText("");
143   myObject = GEOM::GEOM_Object::_nil();
144
145   myOkObject = false;
146
147   activateSelection();
148
149   return true;
150 }
151
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose  : Called when selection as changed or other case
155 //          : used only by SelectButtonC1A1 (LineEditC1A1)
156 //=================================================================================
157 void RepairGUI_RemoveWebsDlg::SelectionIntoArgument()
158 {
159   myEditCurrentArgument->setText( "" );
160   QString aName;
161
162   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
163   SALOME_ListIO aSelList;
164   aSelMgr->selectedObjects(aSelList);
165
166   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
167     if (aSelList.Extent() != 1) {
168       if (myEditCurrentArgument == GroupPoints->LineEdit1)
169         myOkObject = false;
170       return;
171     }
172   }
173
174   // nbSel == 1
175   GEOM::GEOM_Object_ptr aSelectedObject =
176     GEOMBase::ConvertIOinGEOMObject(aSelList.First());
177
178   if (CORBA::is_nil(aSelectedObject))
179     return;
180
181   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
182     myObject = aSelectedObject;
183     myOkObject = true;
184   }
185
186   myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
187 }
188
189 //=================================================================================
190 // function : SetEditCurrentArgument()
191 // purpose  :
192 //=================================================================================
193 void RepairGUI_RemoveWebsDlg::SetEditCurrentArgument()
194 {
195   if (sender() == GroupPoints->PushButton1) {
196     GroupPoints->LineEdit1->setFocus();
197     myEditCurrentArgument = GroupPoints->LineEdit1;
198   }
199   SelectionIntoArgument();
200 }
201
202 //=================================================================================
203 // function : LineEditReturnPressed()
204 // purpose  :
205 //=================================================================================
206 void RepairGUI_RemoveWebsDlg::LineEditReturnPressed()
207 {
208   if (sender() == GroupPoints->LineEdit1) {
209     myEditCurrentArgument = GroupPoints->LineEdit1;
210     GEOMBase_Skeleton::LineEditReturnPressed();
211   }
212 }
213
214 //=================================================================================
215 // function : ActivateThisDialog()
216 // purpose  :
217 //=================================================================================
218 void RepairGUI_RemoveWebsDlg::ActivateThisDialog()
219 {
220   GEOMBase_Skeleton::ActivateThisDialog();
221   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
222           this, SLOT(SelectionIntoArgument()));
223
224   activateSelection();
225 }
226
227 //=================================================================================
228 // function : enterEvent()
229 // purpose  : Mouse enter onto the dialog to activate it
230 //=================================================================================
231 void RepairGUI_RemoveWebsDlg::enterEvent (QEvent* e)
232 {
233   if (!mainFrame()->GroupConstructors->isEnabled())
234     ActivateThisDialog();
235 }
236
237 //=================================================================================
238 // function : activateSelection
239 // purpose  : activate selection of solids and compounds
240 //=================================================================================
241 void RepairGUI_RemoveWebsDlg::activateSelection()
242 {
243   TColStd_MapOfInteger aTypes;
244   //aTypes.Add( GEOM_SOLID );
245   aTypes.Add( GEOM_COMPOUND );
246   globalSelection( aTypes );
247 }
248
249 //=================================================================================
250 // function : createOperation
251 // purpose  :
252 //=================================================================================
253 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveWebsDlg::createOperation()
254 {
255   return getGeomEngine()->GetIHealingOperations(getStudyId());
256 }
257
258 //=================================================================================
259 // function : isValid
260 // purpose  :
261 //=================================================================================
262 bool RepairGUI_RemoveWebsDlg::isValid (QString& msg)
263 {
264   return myOkObject;
265 }
266
267 //=================================================================================
268 // function : execute
269 // purpose  :
270 //=================================================================================
271 bool RepairGUI_RemoveWebsDlg::execute (ObjectList& objects)
272 {
273   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
274   GEOM::GEOM_Object_var anObj = anOper->RemoveInternalFaces(myObject);
275
276   if (!anObj->_is_nil())
277     objects.push_back(anObj._retn());
278
279   return true;
280 }
281
282 //=================================================================================
283 // function : restoreSubShapes
284 // purpose  :
285 //=================================================================================
286 void RepairGUI_RemoveWebsDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
287                                                 SALOMEDS::SObject_ptr theSObject)
288 {
289   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
290     // empty list of arguments means that all arguments should be restored
291     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
292                                         /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
293                                         /*theInheritFirstArg=*/true,
294                                         mainFrame()->CheckBoxAddPrefix->isChecked());
295   }
296 }