1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_RemoveHolesDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "RepairGUI_RemoveHolesDlg.h"
30 #include "GeometryGUI.h"
32 #include "RepairGUI.h"
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_MessageBox.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
42 #include <TColStd_MapOfInteger.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : RepairGUI_RemoveHolesDlg()
49 // purpose : Constructs a RepairGUI_RemoveHolesDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 RepairGUI_RemoveHolesDlg::RepairGUI_RemoveHolesDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
58 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPPRESS_HOLES")));
59 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
65 mainFrame()->RadioButton1->setIcon(image0);
66 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
67 mainFrame()->RadioButton2->close();
68 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_1Sel1Check1Sel(centralWidget());
72 GroupPoints->GroupBox1->setTitle(tr("GEOM_HOLES"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
74 GroupPoints->PushButton1->setIcon(image1);
75 GroupPoints->LineEdit1->setReadOnly(true);
76 GroupPoints->CheckButton1->setText(tr("GEOM_REMOVE_ALL_HOLES"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_WIRES_TO_REMOVE"));
78 GroupPoints->PushButton2->setIcon(image1);
79 GroupPoints->LineEdit2->setReadOnly(true);
81 myFreeBoundBtn = new QPushButton(tr("GEOM_DETECT") + QString(" [%1]").arg(tr("GEOM_FREE_BOUNDARIES")),
83 QVBoxLayout* l = new QVBoxLayout(GroupPoints->Box);
84 l->setMargin(0); l->setSpacing(0);
85 l->addWidget(myFreeBoundBtn);
87 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88 layout->setMargin(0); layout->setSpacing(6);
89 layout->addWidget(GroupPoints);
90 /***************************************************************/
92 setHelpFileName("suppress_holes_operation_page.html");
97 //=================================================================================
98 // function : ~RepairGUI_RemoveHolesDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
105 //=================================================================================
108 //=================================================================================
109 void RepairGUI_RemoveHolesDlg::Init()
112 GroupPoints->LineEdit1->clear();
113 GroupPoints->LineEdit2->clear();
114 myObject = GEOM::GEOM_Object::_nil();
115 myWiresInd = new GEOM::short_array();
116 myWiresInd->length(0);
121 // signals and slots connections
122 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(GroupPoints->CheckButton1, SIGNAL(clicked()), this, SLOT(onRemoveAllClicked()));
133 connect(myFreeBoundBtn, SIGNAL(clicked()), this, SLOT(onDetect()));
135 initName(tr("REMOVE_HOLES_NEW_OBJ_NAME"));
137 GroupPoints->PushButton1->click();
138 SelectionIntoArgument();
142 //=================================================================================
143 // function : ClickOnOk()
144 // purpose : Same than click on apply but close this dialog.
145 //=================================================================================
146 void RepairGUI_RemoveHolesDlg::ClickOnOk()
148 setIsApplyAndClose( true );
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
163 // activate first line edit
164 GroupPoints->PushButton1->click();
168 //=================================================================================
169 // function : SelectionIntoArgument()
170 // purpose : Called when selection is changed or on dialog initialization or activation
171 //=================================================================================
172 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
175 myEditCurrentArgument->setText("");
176 // the second argument depends on the first one
177 GroupPoints->LineEdit2->setText("");
178 myWiresInd->length(0);
180 if (myEditCurrentArgument == GroupPoints->LineEdit1)
181 myObject = GEOM::GEOM_Object::_nil();
183 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
184 SALOME_ListIO aSelList;
185 aSelMgr->selectedObjects(aSelList);
187 if (aSelList.Extent() == 1) {
188 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
190 if (myEditCurrentArgument == GroupPoints->LineEdit1) { // face selection
191 myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
192 if ( GEOMBase::IsShape(myObject) ) {
193 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
196 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
197 myGeomGUI->getApp()->selectionMgr()->clearSelected();
198 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
199 this, SLOT(SelectionIntoArgument()));
201 if (!GroupPoints->CheckButton1->isChecked())
202 GroupPoints->PushButton2->click();
205 myObject = GEOM::GEOM_Object::_nil();
207 else if (myEditCurrentArgument == GroupPoints->LineEdit2 &&
208 !GroupPoints->CheckButton1->isChecked()) {
209 TColStd_IndexedMapOfInteger aMap;
210 aSelMgr->GetIndexes(anIO, aMap);
211 const int n = aMap.Extent();
212 myWiresInd->length(n);
213 for (int i = 1; i <= n; i++)
214 myWiresInd[i-1] = aMap(i);
216 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_WIRE") + tr("_S_"));
221 //=================================================================================
222 // function : SetEditCurrentArgument()
224 //=================================================================================
225 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
227 QPushButton* send = (QPushButton*)sender();
229 bool isEffective = false;
231 if (send == GroupPoints->PushButton1) {
233 myEditCurrentArgument = GroupPoints->LineEdit1;
235 GroupPoints->PushButton2->setDown(false);
236 GroupPoints->LineEdit2->setEnabled(false);
238 else if (send == GroupPoints->PushButton2 && !myObject->_is_nil()) {
240 myEditCurrentArgument = GroupPoints->LineEdit2;
242 GroupPoints->PushButton1->setDown(false);
243 GroupPoints->LineEdit1->setEnabled(false);
250 myEditCurrentArgument->setEnabled(true);
251 myEditCurrentArgument->setFocus();
252 // after setFocus(), because it will be setDown(false) when loses focus
257 //=================================================================================
258 // function : LineEditReturnPressed()
260 //=================================================================================
261 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
263 const QObject* send = sender();
264 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
265 myEditCurrentArgument = (QLineEdit*)send;
266 GEOMBase_Skeleton::LineEditReturnPressed();
270 //=================================================================================
271 // function : ActivateThisDialog()
273 //=================================================================================
274 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
276 GEOMBase_Skeleton::ActivateThisDialog();
277 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
278 this, SLOT( SelectionIntoArgument() ) );
280 myEditCurrentArgument = GroupPoints->LineEdit1;
281 myEditCurrentArgument->setText( "" );
282 GroupPoints->LineEdit2->setText( "" );
283 myObject = GEOM::GEOM_Object::_nil();
284 myWiresInd->length( 0 );
292 //=================================================================================
293 // function : enterEvent()
294 // purpose : Mouse enter onto the dialog to activate it
295 //=================================================================================
296 void RepairGUI_RemoveHolesDlg::enterEvent (QEvent*)
298 if (!mainFrame()->GroupConstructors->isEnabled())
299 ActivateThisDialog();
302 //=================================================================================
303 // function : createOperation
305 //=================================================================================
306 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
308 return getGeomEngine()->GetIHealingOperations();
311 //=================================================================================
312 // function : isValid
314 //=================================================================================
315 bool RepairGUI_RemoveHolesDlg::isValid (QString&)
318 return !myObject->_is_nil() && (IsPreview() || GroupPoints->CheckButton1->isChecked() || myWiresInd->length());
321 //=================================================================================
322 // function : execute
324 //=================================================================================
325 bool RepairGUI_RemoveHolesDlg::execute (ObjectList& objects)
327 bool aResult = false;
330 // called from onDetect(): detect free boundary edges,
331 // highlight them (add to objects), display message dialog
332 GEOM::ListOfGO_var aClosed, anOpen;
334 GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
336 objList[0] = myObject;
337 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
338 aResult = anOper->GetFreeBoundary(objList, aClosed, anOpen);
341 myClosed = aClosed->length();
342 myOpen = anOpen->length();
344 for (i = 0; i < myClosed; i++)
345 objects.push_back(aClosed[i]._retn());
346 for (i = 0; i < myOpen; i++)
347 objects.push_back(anOpen[i]._retn());
353 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
354 GEOM::GEOM_Object_var anObj = anOper->FillHoles(myObject, myWiresInd);
355 aResult = !anObj->_is_nil();
359 RepairGUI::ShowStatistics( anOper, this );
360 objects.push_back(anObj._retn());
367 //=================================================================================
368 // function : onRemoveAllClicked
370 //=================================================================================
371 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
373 bool b = GroupPoints->CheckButton1->isChecked();
374 GroupPoints->TextLabel2->setEnabled(!b);
375 GroupPoints->PushButton2->setEnabled(!b);
376 GroupPoints->LineEdit2->setEnabled(!b);
378 GroupPoints->LineEdit2->setText("");
379 myWiresInd->length(0);
383 //=================================================================================
384 // function : initSelection
386 //=================================================================================
387 void RepairGUI_RemoveHolesDlg::initSelection()
389 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
391 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
392 TColStd_MapOfInteger aTypes;
393 aTypes.Add(GEOM_COMPOUND);
394 aTypes.Add(GEOM_SOLID);
395 aTypes.Add(GEOM_SHELL);
396 aTypes.Add(GEOM_FACE);
398 globalSelection(aTypes);
400 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
401 localSelection(myObject, TopAbs_EDGE);
402 localSelection(myObject, TopAbs_WIRE);
405 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
406 this, SLOT(SelectionIntoArgument()));
409 //=================================================================================
410 // function : onDetect
412 //=================================================================================
413 void RepairGUI_RemoveHolesDlg::onDetect()
415 displayPreview(true, false, true, true, 3);
417 // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
420 msg = tr("GEOM_FREE_BOUNDS_MSG").arg(myClosed + myOpen).arg(myClosed).arg(myOpen);
422 msg = tr("GEOM_FREE_BOUNDS_ERROR");
423 SUIT_MessageBox::information(this, tr("GEOM_FREE_BOUNDS_TLT"), msg);
426 //=================================================================================
427 // function : getSourceObjects
428 // purpose : virtual method to get source objects
429 //=================================================================================
430 QList<GEOM::GeomObjPtr> RepairGUI_RemoveHolesDlg::getSourceObjects()
432 QList<GEOM::GeomObjPtr> res;
433 GEOM::GeomObjPtr aGeomObjPtr(myObject);