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_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 #include <QButtonGroup>
50 //=================================================================================
51 // class : RepairGUI_CloseContourDlg()
52 // purpose : Constructs a RepairGUI_CloseContourDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
59 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
61 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CLOSECONTOUR")));
62 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
68 mainFrame()->RadioButton1->setIcon(image0);
69 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
70 mainFrame()->RadioButton2->close();
71 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72 mainFrame()->RadioButton3->close();
74 GroupPoints = new DlgRef_2SelExt(centralWidget());
75 GroupPoints->GroupBox1->setTitle(tr("Contour to close"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
77 GroupPoints->PushButton1->setIcon(image1);
78 GroupPoints->LineEdit1->setReadOnly(true);
80 GroupPoints->TextLabel2->setText(tr("Contour to close"));
81 GroupPoints->PushButton2->setIcon(image1);
82 GroupPoints->LineEdit2->setReadOnly(true);
84 QRadioButton* rb1 = new QRadioButton(tr("Close by common vertex"), GroupPoints->Box);
85 QRadioButton* rb2 = new QRadioButton(tr("Close by new edge"), GroupPoints->Box);
87 myIsVertexGr = new QButtonGroup(GroupPoints->Box);
88 myIsVertexGr->addButton(rb1, 0);
89 myIsVertexGr->addButton(rb2, 1);
90 rb1->setChecked(true);
92 QVBoxLayout* l = new QVBoxLayout(GroupPoints->Box);
93 l->setMargin(0); l->setSpacing(6);
97 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
98 layout->setMargin(0); layout->setSpacing(6);
99 layout->addWidget(GroupPoints);
100 /***************************************************************/
102 setHelpFileName("close_contour_operation_page.html");
107 //=================================================================================
108 // function : ~RepairGUI_CloseContourDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
115 //=================================================================================
118 //=================================================================================
119 void RepairGUI_CloseContourDlg::Init()
122 GroupPoints->LineEdit1->clear();
123 GroupPoints->LineEdit2->clear();
124 myObject = GEOM::GEOM_Object::_nil();
125 myWiresInd = new GEOM::short_array();
126 myWiresInd->length(0);
128 // signals and slots connections
129 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 initName(tr("CLOSE_CONTOUR_NEW_OBJ_NAME"));
140 GroupPoints->PushButton1->click();
141 SelectionIntoArgument();
145 //=================================================================================
146 // function : ClickOnOk()
147 // purpose : Same than click on apply but close this dialog.
148 //=================================================================================
149 void RepairGUI_CloseContourDlg::ClickOnOk()
151 setIsApplyAndClose( true );
156 //=================================================================================
157 // function : ClickOnApply()
159 //=================================================================================
160 bool RepairGUI_CloseContourDlg::ClickOnApply()
166 // activate first line edit
167 GroupPoints->PushButton1->click();
171 //=================================================================================
172 // function : SelectionIntoArgument()
173 // purpose : Called when selection is changed or on dialog initialization or activation
174 //=================================================================================
175 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
177 myEditCurrentArgument->setText("");
178 // the second argument depends on the first one
179 GroupPoints->LineEdit2->setText("");
180 myWiresInd->length(0);
182 if (myEditCurrentArgument == GroupPoints->LineEdit1)
183 myObject = GEOM::GEOM_Object::_nil();
185 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
186 SALOME_ListIO aSelList;
187 aSelMgr->selectedObjects(aSelList);
189 if (aSelList.Extent() == 1) {
190 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
192 if (myEditCurrentArgument == GroupPoints->LineEdit1) { // face selection
193 myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
194 if ( GEOMBase::IsShape(myObject) ) {
195 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
197 if (GEOMBase::GetShape(myObject, aShape, TopAbs_WIRE))
198 GroupPoints->LineEdit2->setText(myEditCurrentArgument->text());
201 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
202 myGeomGUI->getApp()->selectionMgr()->clearSelected();
203 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
204 this, SLOT(SelectionIntoArgument()));
206 GroupPoints->PushButton2->click();
209 myObject = GEOM::GEOM_Object::_nil();
211 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
212 TColStd_IndexedMapOfInteger aMap;
213 aSelMgr->GetIndexes(anIO, aMap);
214 const int n = aMap.Extent();
215 myWiresInd->length(n);
216 for (int i = 1; i <= n; i++)
217 myWiresInd[i-1] = aMap(i);
219 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_WIRE") + tr("_S_"));
224 //=================================================================================
225 // function : SetEditCurrentArgument()
227 //=================================================================================
228 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
230 QPushButton* send = (QPushButton*)sender();
232 bool isEffective = false;
234 if (send == GroupPoints->PushButton1) {
236 myEditCurrentArgument = GroupPoints->LineEdit1;
238 GroupPoints->PushButton2->setDown(false);
239 GroupPoints->LineEdit2->setEnabled(false);
241 else if (send == GroupPoints->PushButton2 && !myObject->_is_nil()) {
243 myEditCurrentArgument = GroupPoints->LineEdit2;
245 GroupPoints->PushButton1->setDown(false);
246 GroupPoints->LineEdit1->setEnabled(false);
253 myEditCurrentArgument->setEnabled(true);
254 myEditCurrentArgument->setFocus();
255 // after setFocus(), because it will be setDown(false) when loses focus
260 //=================================================================================
261 // function : LineEditReturnPressed()
263 //=================================================================================
264 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
266 const QObject* send = sender();
267 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
268 myEditCurrentArgument = (QLineEdit*)send;
269 GEOMBase_Skeleton::LineEditReturnPressed();
273 //=================================================================================
274 // function : ActivateThisDialog()
276 //=================================================================================
277 void RepairGUI_CloseContourDlg::ActivateThisDialog()
279 GEOMBase_Skeleton::ActivateThisDialog();
280 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
281 this, SLOT( SelectionIntoArgument() ) );
283 myEditCurrentArgument = GroupPoints->LineEdit1;
284 myEditCurrentArgument->setText( "" );
285 GroupPoints->LineEdit2->setText( "" );
286 myObject = GEOM::GEOM_Object::_nil();
287 myWiresInd->length( 0 );
292 //=================================================================================
293 // function : enterEvent()
294 // purpose : Mouse enter onto the dialog to activate it
295 //=================================================================================
296 void RepairGUI_CloseContourDlg::enterEvent (QEvent*)
298 if (!mainFrame()->GroupConstructors->isEnabled())
299 ActivateThisDialog();
302 //=================================================================================
303 // function : createOperation
305 //=================================================================================
306 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
308 return getGeomEngine()->GetIHealingOperations();
311 //=================================================================================
312 // function : isValid
314 //=================================================================================
315 bool RepairGUI_CloseContourDlg::isValid (QString&)
317 TopoDS_Shape aTmpShape;
318 return !myObject->_is_nil() && (myWiresInd->length() ||
319 GEOMBase::GetShape(myObject, aTmpShape, TopAbs_WIRE));
322 //=================================================================================
323 // function : execute
325 //=================================================================================
326 bool RepairGUI_CloseContourDlg::execute (ObjectList& objects)
328 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
329 GEOM::GEOM_Object_var anObj = anOper->CloseContour(myObject, myWiresInd, getIsByVertex());
331 bool aResult = !anObj->_is_nil();
335 RepairGUI::ShowStatistics( anOper, this );
336 objects.push_back(anObj._retn());
341 //=================================================================================
342 // function : getIsByVertex
344 //=================================================================================
345 bool RepairGUI_CloseContourDlg::getIsByVertex() const
347 return myIsVertexGr->button(0)->isChecked();
350 //=================================================================================
351 // function : initSelection
353 //=================================================================================
354 void RepairGUI_CloseContourDlg::initSelection()
356 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
358 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
359 TColStd_MapOfInteger aTypes;
360 aTypes.Add(GEOM_COMPOUND);
361 aTypes.Add(GEOM_SOLID);
362 aTypes.Add(GEOM_SHELL);
363 aTypes.Add(GEOM_FACE);
364 aTypes.Add(GEOM_WIRE);
366 globalSelection(aTypes);
368 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
369 localSelection(myObject, TopAbs_EDGE);
370 localSelection(myObject, TopAbs_WIRE);
373 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
374 this, SLOT(SelectionIntoArgument()));
377 //=================================================================================
378 // function : getSourceObjects
379 // purpose : virtual method to get source objects
380 //=================================================================================
381 QList<GEOM::GeomObjPtr> RepairGUI_CloseContourDlg::getSourceObjects()
383 QList<GEOM::GeomObjPtr> res;
384 GEOM::GeomObjPtr aGeomObjPtr(myObject);