1 // Copyright (C) 2007-2012 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.
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
19 #include "RepairGUI_FuseEdgesDlg.h"
22 #include <GeometryGUI.h>
25 #include <SUIT_Desktop.h>
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_ViewWindow.h>
29 #include <SUIT_ViewManager.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <OCCViewer_ViewModel.h>
35 #include <TColStd_MapOfInteger.hxx>
36 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <GEOMImpl_Types.hxx>
40 //=================================================================================
41 // class : RepairGUI_FuseEdgesDlg()
42 // purpose : Constructs a RepairGUI_FuseEdgesDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 RepairGUI_FuseEdgesDlg::RepairGUI_FuseEdgesDlg (GeometryGUI* theGeometryGUI,
49 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
51 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
52 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FUSE_EDGES")));
53 QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
55 setWindowTitle(tr("GEOM_FUSE_EDGES_TITLE"));
57 mainFrame()->GroupConstructors->setTitle(tr("GEOM_FUSE_EDGES"));
58 mainFrame()->RadioButton1->setIcon(image0);
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->close();
62 GroupVertexes = new DlgRef_2Sel1Spin (centralWidget());
63 GroupVertexes->GroupBox1->setTitle(tr("GEOM_FUSE_EDGES"));
64 GroupVertexes->TextLabel1->setText(tr("GEOM_WIRE"));
65 GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
66 GroupVertexes->PushButton1->setIcon(iconSelect);
67 GroupVertexes->PushButton2->setIcon(iconSelect);
68 GroupVertexes->LineEdit1->setReadOnly(true);
69 GroupVertexes->LineEdit2->setReadOnly(true);
71 GroupVertexes->TextLabel3->setShown(false);
72 GroupVertexes->SpinBox_DX->setShown(false);
74 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
76 layout->setSpacing(6);
77 layout->addWidget(GroupVertexes);
79 setHelpFileName("fuse_edges_operation_page.html");
86 //=================================================================================
87 // function : ~RepairGUI_FuseEdgesDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 RepairGUI_FuseEdgesDlg::~RepairGUI_FuseEdgesDlg()
94 //=================================================================================
97 //=================================================================================
98 void RepairGUI_FuseEdgesDlg::Init()
101 GroupVertexes->LineEdit1->setText("");
102 GroupVertexes->LineEdit2->setText("");
104 myShape = GEOM::GEOM_Object::_nil();
108 // signals and slots connections
109 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
110 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
112 connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113 connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
116 connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118 initName(tr("FUSE_EDGES_NEW_OBJ_NAME"));
119 GroupVertexes->PushButton1->click();
121 SelectionIntoArgument();
124 //=================================================================================
125 // function : ClickOnOk()
127 //=================================================================================
128 void RepairGUI_FuseEdgesDlg::ClickOnOk()
130 setIsApplyAndClose(true);
135 //=================================================================================
136 // function : ClickOnApply()
138 //=================================================================================
139 bool RepairGUI_FuseEdgesDlg::ClickOnApply()
145 // Reset dialog state
146 GroupVertexes->LineEdit1->setText("");
147 GroupVertexes->LineEdit2->setText("");
148 myShape = GEOM::GEOM_Object::_nil();
150 GroupVertexes->PushButton1->click();
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose : Called when selection is changed or on dialog initialization or activation
158 //=================================================================================
159 void RepairGUI_FuseEdgesDlg::SelectionIntoArgument()
161 myEditCurrentArgument->setText("");
163 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
164 SALOME_ListIO aSelList;
165 aSelMgr->selectedObjects(aSelList);
167 // If selection of main object is activated
168 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
169 myShape = GEOM::GEOM_Object::_nil();
170 if (aSelList.Extent() == 1) {
171 GEOM::GEOM_Object_var anObj =
172 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
174 if (!anObj->_is_nil()) {
175 QString aName = GEOMBase::GetName(anObj);
177 if (GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
178 TColStd_IndexedMapOfInteger aMap;
179 aSelMgr->GetIndexes(aSelList.First(), aMap);
180 if (aMap.Extent() == 1) { // Local Selection
181 int anIndex = aMap(1);
182 aName += QString(":wire_%1").arg(anIndex);
184 //Find SubShape Object in Father
185 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(anObj, aName);
187 if (aFindedObject->_is_nil()) { // Object not found in study
188 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
189 anObj = aShapesOp->GetSubShape(anObj, anIndex);
192 anObj = aFindedObject; // get Object from study
194 else { // Global Selection
195 if (aShape.ShapeType() != TopAbs_WIRE) {
196 anObj = GEOM::GEOM_Object::_nil();
202 myEditCurrentArgument->setText(aName);
206 if (!myShape->_is_nil() && myPoints.isEmpty())
207 GroupVertexes->PushButton2->click();
209 else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
210 myPoints = getSelected(TopAbs_VERTEX, -1);
211 if (!myPoints.isEmpty())
212 myEditCurrentArgument->setText(QString::number(myPoints.count()) + "_" + tr("GEOM_POINT") + tr("_S_"));
214 myEditCurrentArgument->setText("");
218 //=================================================================================
219 // function : SetEditCurrentArgument()
221 //=================================================================================
222 void RepairGUI_FuseEdgesDlg::SetEditCurrentArgument()
224 QPushButton* send = (QPushButton*)sender();
226 if (send == GroupVertexes->PushButton1) {
227 myEditCurrentArgument = GroupVertexes->LineEdit1;
228 GroupVertexes->PushButton2->setDown(false);
229 GroupVertexes->LineEdit2->setEnabled(false);
231 else if (send == GroupVertexes->PushButton2) {
232 myEditCurrentArgument = GroupVertexes->LineEdit2;
233 GroupVertexes->PushButton1->setDown(false);
234 GroupVertexes->LineEdit1->setEnabled(false);
238 myEditCurrentArgument->setEnabled(true);
239 myEditCurrentArgument->setFocus();
240 // after setFocus(), because it will be setDown(false) when loses focus
246 //=================================================================================
247 // function : LineEditReturnPressed()
249 //=================================================================================
250 void RepairGUI_FuseEdgesDlg::LineEditReturnPressed()
252 QLineEdit* send = (QLineEdit*)sender();
254 if (send == GroupVertexes->LineEdit1)
255 myEditCurrentArgument = GroupVertexes->LineEdit1;
256 else if (send == GroupVertexes->LineEdit2)
257 myEditCurrentArgument = GroupVertexes->LineEdit2;
261 GEOMBase_Skeleton::LineEditReturnPressed();
264 //=================================================================================
265 // function : ActivateThisDialog()
267 //=================================================================================
268 void RepairGUI_FuseEdgesDlg::ActivateThisDialog()
270 GEOMBase_Skeleton::ActivateThisDialog();
273 //=================================================================================
274 // function : enterEvent()
276 //=================================================================================
277 void RepairGUI_FuseEdgesDlg::enterEvent (QEvent*)
279 if (!mainFrame()->GroupConstructors->isEnabled())
280 this->ActivateThisDialog();
283 //=================================================================================
284 // function : activateSelection
285 // purpose : Activate selection in accordance with myEditCurrentArgument
286 //=================================================================================
287 void RepairGUI_FuseEdgesDlg::activateSelection()
289 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
291 if (myEditCurrentArgument == GroupVertexes->LineEdit1)
292 globalSelection(GEOM_WIRE);
293 else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
294 localSelection(myShape, TopAbs_VERTEX);
296 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
297 this, SLOT(SelectionIntoArgument()));
300 //=================================================================================
301 // function : createOperation
303 //=================================================================================
304 GEOM::GEOM_IOperations_ptr RepairGUI_FuseEdgesDlg::createOperation()
306 return getGeomEngine()->GetIHealingOperations(getStudyId());
309 //=================================================================================
310 // function : isValid()
311 // purpose : Verify validity of input data
312 //=================================================================================
313 bool RepairGUI_FuseEdgesDlg::isValid (QString& msg)
315 return (!myShape->_is_nil());
318 //=================================================================================
319 // function : execute
321 //=================================================================================
322 bool RepairGUI_FuseEdgesDlg::execute (ObjectList& objects)
324 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
326 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
327 points->length(myPoints.count());
328 for (int i = 0; i < myPoints.count(); i++)
329 points[i] = myPoints[i].copy();
331 GEOM::GEOM_Object_var anObj = anOper->FuseCollinearEdgesWithinWire(myShape, points.in());
333 if (!anObj->_is_nil())
334 objects.push_back(anObj._retn());
339 //=================================================================================
340 // function : addSubshapeToStudy
341 // purpose : virtual method to add new SubObjects if local selection
342 //=================================================================================
343 void RepairGUI_FuseEdgesDlg::addSubshapesToStudy()
345 for (int i = 0; i < myPoints.count(); i++)
346 GEOMBase::PublishSubObject(myPoints[i].get());