1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "RepairGUI_FuseEdgesDlg.h"
23 #include <GeometryGUI.h>
26 #include <SUIT_Desktop.h>
27 #include <SUIT_Session.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_ViewWindow.h>
30 #include <SUIT_ViewManager.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <OCCViewer_ViewModel.h>
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <GEOMImpl_Types.hxx>
41 //=================================================================================
42 // class : RepairGUI_FuseEdgesDlg()
43 // purpose : Constructs a RepairGUI_FuseEdgesDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 RepairGUI_FuseEdgesDlg::RepairGUI_FuseEdgesDlg (GeometryGUI* theGeometryGUI,
50 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
52 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
53 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FUSE_EDGES")));
54 QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
56 setWindowTitle(tr("GEOM_FUSE_EDGES_TITLE"));
58 mainFrame()->GroupConstructors->setTitle(tr("GEOM_FUSE_EDGES"));
59 mainFrame()->RadioButton1->setIcon(image0);
60 mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->close();
63 GroupVertexes = new DlgRef_2Sel1Spin (centralWidget());
64 GroupVertexes->GroupBox1->setTitle(tr("GEOM_FUSE_EDGES"));
65 GroupVertexes->TextLabel1->setText(tr("GEOM_WIRE"));
66 GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
67 GroupVertexes->PushButton1->setIcon(iconSelect);
68 GroupVertexes->PushButton2->setIcon(iconSelect);
69 GroupVertexes->LineEdit1->setReadOnly(true);
70 GroupVertexes->LineEdit2->setReadOnly(true);
72 GroupVertexes->TextLabel3->setVisible(false);
73 GroupVertexes->SpinBox_DX->setVisible(false);
75 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
77 layout->setSpacing(6);
78 layout->addWidget(GroupVertexes);
80 setHelpFileName("fuse_edges_operation_page.html");
87 //=================================================================================
88 // function : ~RepairGUI_FuseEdgesDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 RepairGUI_FuseEdgesDlg::~RepairGUI_FuseEdgesDlg()
95 //=================================================================================
98 //=================================================================================
99 void RepairGUI_FuseEdgesDlg::Init()
102 GroupVertexes->LineEdit1->setText("");
103 GroupVertexes->LineEdit2->setText("");
105 myShape = GEOM::GEOM_Object::_nil();
109 // signals and slots connections
110 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
111 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
113 connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117 connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 initName(tr("FUSE_EDGES_NEW_OBJ_NAME"));
120 GroupVertexes->PushButton1->click();
122 SelectionIntoArgument();
125 //=================================================================================
126 // function : ClickOnOk()
128 //=================================================================================
129 void RepairGUI_FuseEdgesDlg::ClickOnOk()
131 setIsApplyAndClose(true);
136 //=================================================================================
137 // function : ClickOnApply()
139 //=================================================================================
140 bool RepairGUI_FuseEdgesDlg::ClickOnApply()
146 // Reset dialog state
147 GroupVertexes->LineEdit1->setText("");
148 GroupVertexes->LineEdit2->setText("");
149 myShape = GEOM::GEOM_Object::_nil();
151 GroupVertexes->PushButton1->click();
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection is changed or on dialog initialization or activation
159 //=================================================================================
160 void RepairGUI_FuseEdgesDlg::SelectionIntoArgument()
162 myEditCurrentArgument->setText("");
164 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
165 SALOME_ListIO aSelList;
166 aSelMgr->selectedObjects(aSelList);
168 // If selection of main object is activated
169 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
170 myShape = GEOM::GEOM_Object::_nil();
171 if (aSelList.Extent() == 1) {
172 GEOM::GEOM_Object_var anObj =
173 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
175 if (!anObj->_is_nil()) {
176 QString aName = GEOMBase::GetName(anObj);
178 if (GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
179 TColStd_IndexedMapOfInteger aMap;
180 aSelMgr->GetIndexes(aSelList.First(), aMap);
181 if (aMap.Extent() == 1) { // Local Selection
182 int anIndex = aMap(1);
183 aName += QString(":wire_%1").arg(anIndex);
185 //Find SubShape Object in Father
186 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(anObj, aName);
188 if (aFindedObject->_is_nil()) { // Object not found in study
189 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
190 anObj = aShapesOp->GetSubShape(anObj, anIndex);
193 anObj = aFindedObject; // get Object from study
195 else { // Global Selection
196 if (aShape.ShapeType() != TopAbs_WIRE) {
197 anObj = GEOM::GEOM_Object::_nil();
203 myEditCurrentArgument->setText(aName);
207 if (!myShape->_is_nil() && myPoints.isEmpty())
208 GroupVertexes->PushButton2->click();
210 else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
211 myPoints = getSelected(TopAbs_VERTEX, -1);
212 if (!myPoints.isEmpty())
213 myEditCurrentArgument->setText(QString::number(myPoints.count()) + "_" + tr("GEOM_POINT") + tr("_S_"));
215 myEditCurrentArgument->setText("");
219 //=================================================================================
220 // function : SetEditCurrentArgument()
222 //=================================================================================
223 void RepairGUI_FuseEdgesDlg::SetEditCurrentArgument()
225 QPushButton* send = (QPushButton*)sender();
227 if (send == GroupVertexes->PushButton1) {
228 myEditCurrentArgument = GroupVertexes->LineEdit1;
229 GroupVertexes->PushButton2->setDown(false);
230 GroupVertexes->LineEdit2->setEnabled(false);
232 else if (send == GroupVertexes->PushButton2) {
233 myEditCurrentArgument = GroupVertexes->LineEdit2;
234 GroupVertexes->PushButton1->setDown(false);
235 GroupVertexes->LineEdit1->setEnabled(false);
239 myEditCurrentArgument->setEnabled(true);
240 myEditCurrentArgument->setFocus();
241 // after setFocus(), because it will be setDown(false) when loses focus
247 //=================================================================================
248 // function : LineEditReturnPressed()
250 //=================================================================================
251 void RepairGUI_FuseEdgesDlg::LineEditReturnPressed()
253 QLineEdit* send = (QLineEdit*)sender();
255 if (send == GroupVertexes->LineEdit1)
256 myEditCurrentArgument = GroupVertexes->LineEdit1;
257 else if (send == GroupVertexes->LineEdit2)
258 myEditCurrentArgument = GroupVertexes->LineEdit2;
262 GEOMBase_Skeleton::LineEditReturnPressed();
265 //=================================================================================
266 // function : ActivateThisDialog()
268 //=================================================================================
269 void RepairGUI_FuseEdgesDlg::ActivateThisDialog()
271 GEOMBase_Skeleton::ActivateThisDialog();
274 //=================================================================================
275 // function : enterEvent()
277 //=================================================================================
278 void RepairGUI_FuseEdgesDlg::enterEvent (QEvent*)
280 if (!mainFrame()->GroupConstructors->isEnabled())
281 this->ActivateThisDialog();
284 //=================================================================================
285 // function : activateSelection
286 // purpose : Activate selection in accordance with myEditCurrentArgument
287 //=================================================================================
288 void RepairGUI_FuseEdgesDlg::activateSelection()
290 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
292 if (myEditCurrentArgument == GroupVertexes->LineEdit1)
293 globalSelection(GEOM_WIRE);
294 else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
295 localSelection(myShape, TopAbs_VERTEX);
297 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
298 this, SLOT(SelectionIntoArgument()));
301 //=================================================================================
302 // function : createOperation
304 //=================================================================================
305 GEOM::GEOM_IOperations_ptr RepairGUI_FuseEdgesDlg::createOperation()
307 return getGeomEngine()->GetIHealingOperations(getStudyId());
310 //=================================================================================
311 // function : isValid()
312 // purpose : Verify validity of input data
313 //=================================================================================
314 bool RepairGUI_FuseEdgesDlg::isValid (QString& msg)
316 return (!myShape->_is_nil());
319 //=================================================================================
320 // function : execute
322 //=================================================================================
323 bool RepairGUI_FuseEdgesDlg::execute (ObjectList& objects)
325 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
327 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
328 points->length(myPoints.count());
329 for (int i = 0; i < myPoints.count(); i++)
330 points[i] = myPoints[i].copy();
332 GEOM::GEOM_Object_var anObj = anOper->FuseCollinearEdgesWithinWire(myShape, points.in());
334 if (!anObj->_is_nil())
335 objects.push_back(anObj._retn());
340 //=================================================================================
341 // function : addSubshapeToStudy
342 // purpose : virtual method to add new SubObjects if local selection
343 //=================================================================================
344 void RepairGUI_FuseEdgesDlg::addSubshapesToStudy()
346 for (int i = 0; i < myPoints.count(); i++)
347 GEOMBase::PublishSubObject(myPoints[i].get());
350 //=================================================================================
351 // function : getSourceObjects
352 // purpose : virtual method to get source objects
353 //=================================================================================
354 QList<GEOM::GeomObjPtr> RepairGUI_FuseEdgesDlg::getSourceObjects()
356 QList<GEOM::GeomObjPtr> res(myPoints);
357 GEOM::GeomObjPtr aGeomObjPtr(myShape);