1 // Copyright (C) 2007-2020 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 <QButtonGroup>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : RepairGUI_CloseContourDlg()
50 // purpose : Constructs a RepairGUI_CloseContourDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
59 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CLOSECONTOUR")));
60 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
62 setWindowTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
66 mainFrame()->RadioButton1->setIcon(image0);
67 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
70 mainFrame()->RadioButton3->close();
72 GroupPoints = new DlgRef_2SelExt(centralWidget());
73 GroupPoints->GroupBox1->setTitle(tr("Contour to close"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
75 GroupPoints->PushButton1->setIcon(image1);
76 GroupPoints->LineEdit1->setReadOnly(true);
78 GroupPoints->TextLabel2->setText(tr("Contour to close"));
79 GroupPoints->PushButton2->setIcon(image1);
80 GroupPoints->LineEdit2->setReadOnly(true);
82 QRadioButton* rb1 = new QRadioButton(tr("Close by common vertex"), GroupPoints->Box);
83 QRadioButton* rb2 = new QRadioButton(tr("Close by new edge"), GroupPoints->Box);
85 myIsVertexGr = new QButtonGroup(GroupPoints->Box);
86 myIsVertexGr->addButton(rb1, 0);
87 myIsVertexGr->addButton(rb2, 1);
88 rb1->setChecked(true);
90 QVBoxLayout* l = new QVBoxLayout(GroupPoints->Box);
91 l->setMargin(0); l->setSpacing(6);
95 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
96 layout->setMargin(0); layout->setSpacing(6);
97 layout->addWidget(GroupPoints);
98 /***************************************************************/
100 setHelpFileName("close_contour_operation_page.html");
105 //=================================================================================
106 // function : ~RepairGUI_CloseContourDlg()
107 // purpose : Destroys the object and frees any allocated resources
108 //=================================================================================
109 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
113 //=================================================================================
116 //=================================================================================
117 void RepairGUI_CloseContourDlg::Init()
120 GroupPoints->LineEdit1->clear();
121 GroupPoints->LineEdit2->clear();
122 myObject = GEOM::GEOM_Object::_nil();
123 myWiresInd = new GEOM::short_array();
124 myWiresInd->length(0);
126 // signals and slots connections
127 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 initName(tr("CLOSE_CONTOUR_NEW_OBJ_NAME"));
138 GroupPoints->PushButton1->click();
139 SelectionIntoArgument();
143 //=================================================================================
144 // function : ClickOnOk()
145 // purpose : Same than click on apply but close this dialog.
146 //=================================================================================
147 void RepairGUI_CloseContourDlg::ClickOnOk()
149 setIsApplyAndClose( true );
154 //=================================================================================
155 // function : ClickOnApply()
157 //=================================================================================
158 bool RepairGUI_CloseContourDlg::ClickOnApply()
164 // activate first line edit
165 GroupPoints->PushButton1->click();
169 //=================================================================================
170 // function : SelectionIntoArgument()
171 // purpose : Called when selection is changed or on dialog initialization or activation
172 //=================================================================================
173 void RepairGUI_CloseContourDlg::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));
195 if (GEOMBase::GetShape(myObject, aShape, TopAbs_WIRE))
196 GroupPoints->LineEdit2->setText(myEditCurrentArgument->text());
199 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
200 myGeomGUI->getApp()->selectionMgr()->clearSelected();
201 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
202 this, SLOT(SelectionIntoArgument()));
204 GroupPoints->PushButton2->click();
207 myObject = GEOM::GEOM_Object::_nil();
209 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
210 TColStd_IndexedMapOfInteger aMap;
211 aSelMgr->GetIndexes(anIO, aMap);
212 const int n = aMap.Extent();
213 myWiresInd->length(n);
214 for (int i = 1; i <= n; i++)
215 myWiresInd[i-1] = aMap(i);
217 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_WIRE") + tr("_S_"));
222 //=================================================================================
223 // function : SetEditCurrentArgument()
225 //=================================================================================
226 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
228 QPushButton* send = (QPushButton*)sender();
230 bool isEffective = false;
232 if (send == GroupPoints->PushButton1) {
234 myEditCurrentArgument = GroupPoints->LineEdit1;
236 GroupPoints->PushButton2->setDown(false);
237 GroupPoints->LineEdit2->setEnabled(false);
239 else if (send == GroupPoints->PushButton2 && !myObject->_is_nil()) {
241 myEditCurrentArgument = GroupPoints->LineEdit2;
243 GroupPoints->PushButton1->setDown(false);
244 GroupPoints->LineEdit1->setEnabled(false);
251 myEditCurrentArgument->setEnabled(true);
252 myEditCurrentArgument->setFocus();
253 // after setFocus(), because it will be setDown(false) when loses focus
258 //=================================================================================
259 // function : LineEditReturnPressed()
261 //=================================================================================
262 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
264 const QObject* send = sender();
265 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
266 myEditCurrentArgument = (QLineEdit*)send;
267 GEOMBase_Skeleton::LineEditReturnPressed();
271 //=================================================================================
272 // function : ActivateThisDialog()
274 //=================================================================================
275 void RepairGUI_CloseContourDlg::ActivateThisDialog()
277 GEOMBase_Skeleton::ActivateThisDialog();
278 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
279 this, SLOT( SelectionIntoArgument() ) );
281 myEditCurrentArgument = GroupPoints->LineEdit1;
282 myEditCurrentArgument->setText( "" );
283 GroupPoints->LineEdit2->setText( "" );
284 myObject = GEOM::GEOM_Object::_nil();
285 myWiresInd->length( 0 );
290 //=================================================================================
291 // function : enterEvent()
292 // purpose : Mouse enter onto the dialog to activate it
293 //=================================================================================
294 void RepairGUI_CloseContourDlg::enterEvent (QEvent*)
296 if (!mainFrame()->GroupConstructors->isEnabled())
297 ActivateThisDialog();
300 //=================================================================================
301 // function : createOperation
303 //=================================================================================
304 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
306 return getGeomEngine()->GetIHealingOperations();
309 //=================================================================================
310 // function : isValid
312 //=================================================================================
313 bool RepairGUI_CloseContourDlg::isValid (QString&)
315 TopoDS_Shape aTmpShape;
316 return !myObject->_is_nil() && (myWiresInd->length() ||
317 GEOMBase::GetShape(myObject, aTmpShape, TopAbs_WIRE));
320 //=================================================================================
321 // function : execute
323 //=================================================================================
324 bool RepairGUI_CloseContourDlg::execute (ObjectList& objects)
326 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
327 GEOM::GEOM_Object_var anObj = anOper->CloseContour(myObject, myWiresInd, getIsByVertex());
329 bool aResult = !anObj->_is_nil();
333 RepairGUI::ShowStatistics( anOper, this );
334 objects.push_back(anObj._retn());
339 //=================================================================================
340 // function : getIsByVertex
342 //=================================================================================
343 bool RepairGUI_CloseContourDlg::getIsByVertex() const
345 return myIsVertexGr->button(0)->isChecked();
348 //=================================================================================
349 // function : initSelection
351 //=================================================================================
352 void RepairGUI_CloseContourDlg::initSelection()
354 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
356 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
357 TColStd_MapOfInteger aTypes;
358 aTypes.Add(GEOM_COMPOUND);
359 aTypes.Add(GEOM_SOLID);
360 aTypes.Add(GEOM_SHELL);
361 aTypes.Add(GEOM_FACE);
362 aTypes.Add(GEOM_WIRE);
364 globalSelection(aTypes);
366 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
367 localSelection(myObject, TopAbs_EDGE);
368 localSelection(myObject, TopAbs_WIRE);
371 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
372 this, SLOT(SelectionIntoArgument()));
375 //=================================================================================
376 // function : getSourceObjects
377 // purpose : virtual method to get source objects
378 //=================================================================================
379 QList<GEOM::GeomObjPtr> RepairGUI_CloseContourDlg::getSourceObjects()
381 QList<GEOM::GeomObjPtr> res;
382 GEOM::GeomObjPtr aGeomObjPtr(myObject);