1 // Copyright (C) 2007-2016 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, 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_CloseContourDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "RepairGUI_CloseContourDlg.h"
30 #include "GeometryGUI.h"
32 #include "RepairGUI.h"
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
41 #include <TColStd_MapOfInteger.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : RepairGUI_CloseContourDlg()
48 // purpose : Constructs a RepairGUI_CloseContourDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
55 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
57 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CLOSECONTOUR")));
58 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
60 setWindowTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
64 mainFrame()->RadioButton1->setIcon(image0);
65 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
66 mainFrame()->RadioButton2->close();
67 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
68 mainFrame()->RadioButton3->close();
70 GroupPoints = new DlgRef_2SelExt(centralWidget());
71 GroupPoints->GroupBox1->setTitle(tr("Contour to close"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
73 GroupPoints->PushButton1->setIcon(image1);
74 GroupPoints->LineEdit1->setReadOnly(true);
76 GroupPoints->TextLabel2->setText(tr("Contour to close"));
77 GroupPoints->PushButton2->setIcon(image1);
78 GroupPoints->LineEdit2->setReadOnly(true);
80 QRadioButton* rb1 = new QRadioButton(tr("Close by common vertex"), GroupPoints->Box);
81 QRadioButton* rb2 = new QRadioButton(tr("Close by new edge"), GroupPoints->Box);
83 myIsVertexGr = new QButtonGroup(GroupPoints->Box);
84 myIsVertexGr->addButton(rb1, 0);
85 myIsVertexGr->addButton(rb2, 1);
86 rb1->setChecked(true);
88 QVBoxLayout* l = new QVBoxLayout(GroupPoints->Box);
89 l->setMargin(0); l->setSpacing(6);
93 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
94 layout->setMargin(0); layout->setSpacing(6);
95 layout->addWidget(GroupPoints);
96 /***************************************************************/
98 setHelpFileName("close_contour_operation_page.html");
103 //=================================================================================
104 // function : ~RepairGUI_CloseContourDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
111 //=================================================================================
114 //=================================================================================
115 void RepairGUI_CloseContourDlg::Init()
118 GroupPoints->LineEdit1->clear();
119 GroupPoints->LineEdit2->clear();
120 myObject = GEOM::GEOM_Object::_nil();
121 myWiresInd = new GEOM::short_array();
122 myWiresInd->length(0);
124 // signals and slots connections
125 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 initName(tr("CLOSE_CONTOUR_NEW_OBJ_NAME"));
136 GroupPoints->PushButton1->click();
137 SelectionIntoArgument();
141 //=================================================================================
142 // function : ClickOnOk()
143 // purpose : Same than click on apply but close this dialog.
144 //=================================================================================
145 void RepairGUI_CloseContourDlg::ClickOnOk()
147 setIsApplyAndClose( true );
152 //=================================================================================
153 // function : ClickOnApply()
155 //=================================================================================
156 bool RepairGUI_CloseContourDlg::ClickOnApply()
162 // activate first line edit
163 GroupPoints->PushButton1->click();
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose : Called when selection is changed or on dialog initialization or activation
170 //=================================================================================
171 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
173 myEditCurrentArgument->setText("");
174 // the second argument depends on the first one
175 GroupPoints->LineEdit2->setText("");
176 myWiresInd->length(0);
178 if (myEditCurrentArgument == GroupPoints->LineEdit1)
179 myObject = GEOM::GEOM_Object::_nil();
181 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
182 SALOME_ListIO aSelList;
183 aSelMgr->selectedObjects(aSelList);
185 if (aSelList.Extent() == 1) {
186 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
188 if (myEditCurrentArgument == GroupPoints->LineEdit1) { // face selection
189 myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
190 if ( GEOMBase::IsShape(myObject) ) {
191 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
193 if (GEOMBase::GetShape(myObject, aShape, TopAbs_WIRE))
194 GroupPoints->LineEdit2->setText(myEditCurrentArgument->text());
197 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
198 myGeomGUI->getApp()->selectionMgr()->clearSelected();
199 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
200 this, SLOT(SelectionIntoArgument()));
202 GroupPoints->PushButton2->click();
205 myObject = GEOM::GEOM_Object::_nil();
207 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
208 TColStd_IndexedMapOfInteger aMap;
209 aSelMgr->GetIndexes(anIO, aMap);
210 const int n = aMap.Extent();
211 myWiresInd->length(n);
212 for (int i = 1; i <= n; i++)
213 myWiresInd[i-1] = aMap(i);
215 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_WIRE") + tr("_S_"));
220 //=================================================================================
221 // function : SetEditCurrentArgument()
223 //=================================================================================
224 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
226 QPushButton* send = (QPushButton*)sender();
228 bool isEffective = false;
230 if (send == GroupPoints->PushButton1) {
232 myEditCurrentArgument = GroupPoints->LineEdit1;
234 GroupPoints->PushButton2->setDown(false);
235 GroupPoints->LineEdit2->setEnabled(false);
237 else if (send == GroupPoints->PushButton2 && !myObject->_is_nil()) {
239 myEditCurrentArgument = GroupPoints->LineEdit2;
241 GroupPoints->PushButton1->setDown(false);
242 GroupPoints->LineEdit1->setEnabled(false);
249 myEditCurrentArgument->setEnabled(true);
250 myEditCurrentArgument->setFocus();
251 // after setFocus(), because it will be setDown(false) when loses focus
256 //=================================================================================
257 // function : LineEditReturnPressed()
259 //=================================================================================
260 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
262 const QObject* send = sender();
263 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
264 myEditCurrentArgument = (QLineEdit*)send;
265 GEOMBase_Skeleton::LineEditReturnPressed();
269 //=================================================================================
270 // function : ActivateThisDialog()
272 //=================================================================================
273 void RepairGUI_CloseContourDlg::ActivateThisDialog()
275 GEOMBase_Skeleton::ActivateThisDialog();
276 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
277 this, SLOT( SelectionIntoArgument() ) );
279 myEditCurrentArgument = GroupPoints->LineEdit1;
280 myEditCurrentArgument->setText( "" );
281 GroupPoints->LineEdit2->setText( "" );
282 myObject = GEOM::GEOM_Object::_nil();
283 myWiresInd->length( 0 );
288 //=================================================================================
289 // function : enterEvent()
290 // purpose : Mouse enter onto the dialog to activate it
291 //=================================================================================
292 void RepairGUI_CloseContourDlg::enterEvent (QEvent*)
294 if (!mainFrame()->GroupConstructors->isEnabled())
295 ActivateThisDialog();
298 //=================================================================================
299 // function : createOperation
301 //=================================================================================
302 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
304 return getGeomEngine()->GetIHealingOperations(getStudyId());
307 //=================================================================================
308 // function : isValid
310 //=================================================================================
311 bool RepairGUI_CloseContourDlg::isValid (QString&)
313 TopoDS_Shape aTmpShape;
314 return !myObject->_is_nil() && (myWiresInd->length() ||
315 GEOMBase::GetShape(myObject, aTmpShape, TopAbs_WIRE));
318 //=================================================================================
319 // function : execute
321 //=================================================================================
322 bool RepairGUI_CloseContourDlg::execute (ObjectList& objects)
324 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
325 GEOM::GEOM_Object_var anObj = anOper->CloseContour(myObject, myWiresInd, getIsByVertex());
327 bool aResult = !anObj->_is_nil();
331 RepairGUI::ShowStatistics( anOper, this );
332 objects.push_back(anObj._retn());
337 //=================================================================================
338 // function : getIsByVertex
340 //=================================================================================
341 bool RepairGUI_CloseContourDlg::getIsByVertex() const
343 return myIsVertexGr->button(0)->isChecked();
346 //=================================================================================
347 // function : initSelection
349 //=================================================================================
350 void RepairGUI_CloseContourDlg::initSelection()
352 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
354 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
355 TColStd_MapOfInteger aTypes;
356 aTypes.Add(GEOM_COMPOUND);
357 aTypes.Add(GEOM_SOLID);
358 aTypes.Add(GEOM_SHELL);
359 aTypes.Add(GEOM_FACE);
360 aTypes.Add(GEOM_WIRE);
362 globalSelection(aTypes);
364 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
365 localSelection(myObject, TopAbs_EDGE);
366 localSelection(myObject, TopAbs_WIRE);
369 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
370 this, SLOT(SelectionIntoArgument()));
373 //=================================================================================
374 // function : getSourceObjects
375 // purpose : virtual method to get source objects
376 //=================================================================================
377 QList<GEOM::GeomObjPtr> RepairGUI_CloseContourDlg::getSourceObjects()
379 QList<GEOM::GeomObjPtr> res;
380 GEOM::GeomObjPtr aGeomObjPtr(myObject);