1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, 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.
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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_FreeBoundDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
26 #include "RepairGUI_FreeBoundDlg.h"
31 #include <GeometryGUI.h>
32 #include <GEOM_Displayer.h>
33 #include <GEOMImpl_Types.hxx>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_ResourceMgr.h>
43 #include <TColStd_MapOfInteger.hxx>
47 #include <QHBoxLayout>
48 #include <QVBoxLayout>
49 #include <QGridLayout>
51 #include <QPushButton>
58 Class : RepairGUI_FreeBoundDlg
59 Description : Dialog for displaying free boundaries of selected face, shell or solid
62 //=================================================================================
63 // function : RepairGUI_FreeBoundDlg
64 // purpose : Constructor
65 //=================================================================================
66 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg (GeometryGUI* theGUI, QWidget* theParent)
67 : GEOMBase_Skeleton(theGUI, theParent)
69 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FREE_BOUNDS")));
70 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
72 setWindowTitle(tr("CAPTION"));
74 /***************************************************************/
76 mainFrame()->GroupConstructors->setTitle(tr("FREE_BOUND"));
77 mainFrame()->RadioButton1->setIcon(image0);
78 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
79 mainFrame()->RadioButton2->close();
80 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
81 mainFrame()->RadioButton3->close();
83 mainFrame()->GroupBoxName->hide();
85 QGroupBox* aMainGrp = new QGroupBox (tr("FREE_BOUND"), this);
87 QLabel* lab = new QLabel (tr("GEOM_OBJECT"), aMainGrp);
88 QPushButton* btn = new QPushButton (aMainGrp);
90 myEdit = new QLineEdit (aMainGrp);
91 myEdit->setReadOnly(true);
92 myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
94 myClosedLbl = new QLabel (tr("NUMBER_CLOSED"), aMainGrp);
95 myOpenLbl = new QLabel (tr("NUMBER_OPEN"), aMainGrp);
96 myClosedLbl->setMinimumWidth(150);
97 myOpenLbl->setMinimumWidth(150);
99 QGridLayout* aMainGrpLayout = new QGridLayout (aMainGrp);
100 aMainGrpLayout->addWidget(lab, 0, 0);
101 aMainGrpLayout->addWidget(btn, 0, 1);
102 aMainGrpLayout->addWidget(myEdit, 0, 2);
103 aMainGrpLayout->addWidget(myClosedLbl, 1, 0, 1, 3);
104 aMainGrpLayout->addWidget(myOpenLbl, 2, 0, 1, 3);
106 QVBoxLayout* aLay = new QVBoxLayout (centralWidget());
107 aLay->setSpacing(SPACING);
108 aLay->setMargin(MARGIN);
109 aLay->addWidget(aMainGrp);
111 resize(minimumSizeHint());
112 /***************************************************************/
114 myHelpFileName = "boundaries_page.html";
119 //=================================================================================
120 // function : ~RepairGUI_FreeBoundDlg
121 // purpose : Destructor
122 //=================================================================================
123 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
127 //=================================================================================
129 // purpose : Initialize dialog fields
130 //=================================================================================
131 void RepairGUI_FreeBoundDlg::Init()
133 myNbClosed = myNbOpen = 0;
134 myObj = GEOM::GEOM_Object::_nil();
136 myEditCurrentArgument = myEdit;
138 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
142 this, SLOT(SelectionIntoArgument()));
145 SelectionIntoArgument();
148 //=================================================================================
149 // function : ClickOnOk()
151 //=================================================================================
152 void RepairGUI_FreeBoundDlg::ClickOnOk()
158 //=================================================================================
159 // function : ClickOnApply()
161 //=================================================================================
162 bool RepairGUI_FreeBoundDlg::ClickOnApply()
169 //=================================================================================
170 // function : ActivateThisDialog()
172 //=================================================================================
173 void RepairGUI_FreeBoundDlg::ActivateThisDialog()
175 GEOMBase_Skeleton::ActivateThisDialog();
177 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
178 this, SLOT(SelectionIntoArgument()));
181 displayPreview(true);
184 //=================================================================================
185 // function : enterEvent()
187 //=================================================================================
188 void RepairGUI_FreeBoundDlg::enterEvent(QEvent*)
190 if (!mainFrame()->GroupConstructors->isEnabled())
191 ActivateThisDialog();
194 //=================================================================================
195 // function : SelectionIntoArgument
196 // purpose : SLOT. Called when selection changed.
197 //=================================================================================
198 void RepairGUI_FreeBoundDlg::SelectionIntoArgument()
200 myEditCurrentArgument->setText("");
201 myClosedLbl->setText(tr("NUMBER_CLOSED"));
202 myOpenLbl->setText(tr("NUMBER_OPEN"));
203 myObj = GEOM::GEOM_Object::_nil();
206 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
207 SALOME_ListIO aSelList;
208 aSelMgr->selectedObjects(aSelList);
210 if (aSelList.Extent() != 1)
213 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
215 if (!GEOMBase::IsShape(anObj))
219 myEditCurrentArgument->setText(GEOMBase::GetName(myObj));
220 displayPreview(true, false, true, true, 3);
223 //=================================================================================
224 // function : activateSelection
225 // purpose : activate selection of faces, shells, and solids
226 //=================================================================================
227 void RepairGUI_FreeBoundDlg::activateSelection()
229 TColStd_MapOfInteger aMap;
231 aMap.Add(GEOM_SHELL);
232 aMap.Add(GEOM_SOLID);
233 aMap.Add(GEOM_COMPOUND);
234 globalSelection(aMap);
237 //=================================================================================
238 // function : createOperation
239 // purpose : Create operation
240 //=================================================================================
241 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
243 return getGeomEngine()->GetIHealingOperations(getStudyId());
246 //=================================================================================
247 // function : isValid
249 //=================================================================================
250 bool RepairGUI_FreeBoundDlg::isValid (QString&)
252 return !myObj->_is_nil();
255 //=================================================================================
256 // function : execute
257 // purpose : Get free boundaries
258 //=================================================================================
259 bool RepairGUI_FreeBoundDlg::execute (ObjectList& objects)
261 GEOM::ListOfGO_var aClosed, anOpen;
263 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
264 bool result = anOper->GetFreeBoundary(myObj, aClosed, anOpen);
267 myNbClosed = aClosed->length();
268 myNbOpen = anOpen->length();
270 for (i = 0; i < myNbClosed; i++)
271 objects.push_back(aClosed[i]._retn());
272 for (i = 0; i < myNbOpen; i++)
273 objects.push_back(anOpen[i]._retn());
275 QString aLabelText = tr("NUMBER_CLOSED") + QString("%1").arg(myNbClosed);
276 myClosedLbl->setText(aLabelText);
277 aLabelText = tr("NUMBER_OPEN") + QString("%1").arg(myNbOpen);
278 myOpenLbl->setText(aLabelText);
285 //================================================================
286 // Function : getNewObjectName
287 // Purpose : Redefine this method to return proper name for a new object
288 //================================================================
289 QString RepairGUI_FreeBoundDlg::getNewObjectName (int currObj) const
291 QString aName = tr("NAME_CLOSED").arg(currObj);
292 if (currObj > myNbClosed)
293 aName = tr("NAME_OPEN").arg(currObj);
297 //================================================================
298 // Function : getFather
299 // Purpose : Get father object for object to be added in study
300 // (called with addInStudy method)
301 //================================================================
302 GEOM::GEOM_Object_ptr RepairGUI_FreeBoundDlg::getFather (GEOM::GEOM_Object_ptr)