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