Salome HOME
9b62e1fd60a9ad91e27ea4f98b64720c9ae5cbb7
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveWebsDlg.cxx
1 // Copyright (C) 2007-2023  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_SHAPES" ) );
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   myObjects.clear();
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   myObjects.clear();
162   myOkObject = false;
163
164   myObjects = getSelected( TopAbs_SHAPE, -1 );
165
166   if ( !myObjects.isEmpty() ) {
167     QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
168     myOkObject = true;
169     myEditCurrentArgument->setText( aName );
170   }
171 }
172
173 //=================================================================================
174 // function : SetEditCurrentArgument()
175 // purpose  :
176 //=================================================================================
177 void RepairGUI_RemoveWebsDlg::SetEditCurrentArgument()
178 {
179   if (sender() == GroupPoints->PushButton1) {
180     GroupPoints->LineEdit1->setFocus();
181     myEditCurrentArgument = GroupPoints->LineEdit1;
182   }
183   SelectionIntoArgument();
184 }
185
186 //=================================================================================
187 // function : LineEditReturnPressed()
188 // purpose  :
189 //=================================================================================
190 void RepairGUI_RemoveWebsDlg::LineEditReturnPressed()
191 {
192   if (sender() == GroupPoints->LineEdit1) {
193     myEditCurrentArgument = GroupPoints->LineEdit1;
194     GEOMBase_Skeleton::LineEditReturnPressed();
195   }
196 }
197
198 //=================================================================================
199 // function : ActivateThisDialog()
200 // purpose  :
201 //=================================================================================
202 void RepairGUI_RemoveWebsDlg::ActivateThisDialog()
203 {
204   GEOMBase_Skeleton::ActivateThisDialog();
205   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
206           this, SLOT(SelectionIntoArgument()));
207
208   activateSelection();
209 }
210
211 //=================================================================================
212 // function : enterEvent()
213 // purpose  : Mouse enter onto the dialog to activate it
214 //=================================================================================
215 void RepairGUI_RemoveWebsDlg::enterEvent (QEvent*)
216 {
217   if (!mainFrame()->GroupConstructors->isEnabled())
218     ActivateThisDialog();
219 }
220
221 //=================================================================================
222 // function : activateSelection
223 // purpose  : activate selection of solids and compounds
224 //=================================================================================
225 void RepairGUI_RemoveWebsDlg::activateSelection()
226 {
227   TColStd_MapOfInteger aTypes;
228   aTypes.Add( GEOM_SOLID );
229   aTypes.Add( GEOM_COMPOUND );
230   globalSelection( aTypes );
231 }
232
233 //=================================================================================
234 // function : createOperation
235 // purpose  :
236 //=================================================================================
237 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveWebsDlg::createOperation()
238 {
239   return getGeomEngine()->GetIHealingOperations();
240 }
241
242 //=================================================================================
243 // function : isValid
244 // purpose  :
245 //=================================================================================
246 bool RepairGUI_RemoveWebsDlg::isValid (QString& /*msg*/)
247 {
248   return myOkObject;
249 }
250
251 //=================================================================================
252 // function : execute
253 // purpose  :
254 //=================================================================================
255 bool RepairGUI_RemoveWebsDlg::execute (ObjectList& objects)
256 {
257   GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
258   objList->length( myObjects.count() );
259   for ( int i = 0; i < myObjects.count(); ++i )
260     objList[i] = myObjects[i].copy();
261
262   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
263   GEOM::GEOM_Object_var anObj = anOper->RemoveInternalFaces(objList);
264
265   if (!anObj->_is_nil())
266     objects.push_back(anObj._retn());
267
268   return true;
269 }
270
271 //=================================================================================
272 // function : restoreSubShapes
273 // purpose  :
274 //=================================================================================
275 void RepairGUI_RemoveWebsDlg::restoreSubShapes (SALOMEDS::SObject_ptr theSObject)
276 {
277   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
278     // empty list of arguments means that all arguments should be restored
279     getGeomEngine()->RestoreSubShapesSO(theSObject, GEOM::ListOfGO(),
280                                         /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
281                                         /*theInheritFirstArg=*/true,
282                                         mainFrame()->CheckBoxAddPrefix->isChecked());
283   }
284 }
285
286 //=================================================================================
287 // function : getSourceObjects
288 // purpose  : virtual method to get source objects
289 //=================================================================================
290 QList<GEOM::GeomObjPtr> RepairGUI_RemoveWebsDlg::getSourceObjects()
291 {
292   return myObjects;
293 }