1 // Copyright (C) 2007-2008 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.
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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_SuppressFacesDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_SuppressFacesDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
39 #include <TColStd_MapOfInteger.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <GEOMImpl_Types.hxx>
44 //=================================================================================
45 // class : RepairGUI_SuppressFacesDlg()
46 // purpose : Constructs a RepairGUI_SuppressFacesDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 RepairGUI_SuppressFacesDlg::RepairGUI_SuppressFacesDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
53 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
55 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPRESS_FACE")));
56 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
58 setWindowTitle(tr("GEOM_SUPRESSFACE_TITLE"));
60 /***************************************************************/
61 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
62 mainFrame()->RadioButton1->setIcon(image0);
63 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
64 mainFrame()->RadioButton2->close();
65 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
66 mainFrame()->RadioButton3->close();
68 GroupArgs = new DlgRef_2Sel(centralWidget());
69 GroupArgs->GroupBox1->setTitle(tr("Faces to remove"));
70 GroupArgs->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
71 GroupArgs->PushButton1->setIcon(image1);
72 GroupArgs->LineEdit1->setReadOnly(true);
74 GroupArgs->TextLabel2->setText(tr("Faces to remove"));
75 GroupArgs->PushButton2->setIcon(image1);
76 GroupArgs->LineEdit2->setReadOnly(true);
78 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
79 layout->setMargin(0); layout->setSpacing(6);
80 layout->addWidget(GroupArgs);
81 /***************************************************************/
83 setHelpFileName("suppress_faces_operation_page.html");
88 //=================================================================================
89 // function : ~RepairGUI_SuppressFacesDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
96 //=================================================================================
99 //=================================================================================
100 void RepairGUI_SuppressFacesDlg::Init()
103 GroupArgs->LineEdit1->clear();
104 GroupArgs->LineEdit2->clear();
105 myObject = GEOM::GEOM_Object::_nil();
106 myFacesInd = new GEOM::short_array();
107 myFacesInd->length(0);
109 // signals and slots connections
110 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
111 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
113 connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117 connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 initName(tr("SUPRESS_FACE_NEW_OBJ_NAME"));
121 GroupArgs->PushButton1->click();
122 SelectionIntoArgument();
126 //=================================================================================
127 // function : ClickOnOk()
128 // purpose : Same than click on apply but close this dialog.
129 //=================================================================================
130 void RepairGUI_SuppressFacesDlg::ClickOnOk()
136 //=================================================================================
137 // function : ClickOnApply()
139 //=================================================================================
140 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
146 // activate first line edit
147 GroupArgs->PushButton1->click();
151 //=================================================================================
152 // function : SelectionIntoArgument()
153 // purpose : Called when selection is changed or on dialog initialization or activation
154 //=================================================================================
155 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
157 myEditCurrentArgument->setText("");
158 // the second argument depends on the first one
159 GroupArgs->LineEdit2->setText("");
160 myFacesInd->length(0);
162 if (myEditCurrentArgument == GroupArgs->LineEdit1)
163 myObject = GEOM::GEOM_Object::_nil();
165 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
166 SALOME_ListIO aSelList;
167 aSelMgr->selectedObjects(aSelList);
169 if (aSelList.Extent() == 1) {
170 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
172 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
173 Standard_Boolean aRes;
174 myObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
175 if (aRes && GEOMBase::IsShape(myObject)) {
176 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
178 if (GEOMBase::GetShape(myObject, aShape, TopAbs_FACE))
179 GroupArgs->LineEdit2->setText(myEditCurrentArgument->text());
182 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
183 myGeomGUI->getApp()->selectionMgr()->clearSelected();
184 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
185 this, SLOT(SelectionIntoArgument()));
187 GroupArgs->PushButton2->click();
190 myObject = GEOM::GEOM_Object::_nil();
192 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
193 TColStd_IndexedMapOfInteger aMap;
194 aSelMgr->GetIndexes(anIO, aMap);
195 const int n = aMap.Extent();
196 myFacesInd->length(n);
197 for (int i = 1; i <= n; i++)
198 myFacesInd[i-1] = aMap(i);
200 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_FACE") + tr("_S_"));
205 //=================================================================================
206 // function : SetEditCurrentArgument()
208 //=================================================================================
209 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
211 QPushButton* send = (QPushButton*)sender();
213 bool isEffective = false;
215 if (send == GroupArgs->PushButton1) {
217 myEditCurrentArgument = GroupArgs->LineEdit1;
219 GroupArgs->PushButton2->setDown(false);
220 GroupArgs->LineEdit2->setEnabled(false);
222 else if (send == GroupArgs->PushButton2 && !myObject->_is_nil()) {
224 myEditCurrentArgument = GroupArgs->LineEdit2;
226 GroupArgs->PushButton1->setDown(false);
227 GroupArgs->LineEdit1->setEnabled(false);
234 myEditCurrentArgument->setEnabled(true);
235 myEditCurrentArgument->setFocus();
236 // after setFocus(), because it will be setDown(false) when loses focus
241 //=================================================================================
242 // function : LineEditReturnPressed()
244 //=================================================================================
245 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
247 const QObject* send = sender();
248 if (send == GroupArgs->LineEdit1 || send == GroupArgs->LineEdit2) {
249 myEditCurrentArgument = (QLineEdit*)send;
250 GEOMBase_Skeleton::LineEditReturnPressed();
254 //=================================================================================
255 // function : ActivateThisDialog()
257 //=================================================================================
258 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
260 GEOMBase_Skeleton::ActivateThisDialog();
261 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
262 this, SLOT( SelectionIntoArgument() ) );
264 myEditCurrentArgument = GroupArgs->LineEdit1;
265 myEditCurrentArgument->setText( "" );
266 GroupArgs->LineEdit2->setText( "" );
267 myObject = GEOM::GEOM_Object::_nil();
268 myFacesInd->length( 0 );
273 //=================================================================================
274 // function : enterEvent()
275 // purpose : Mouse enter onto the dialog to activate it
276 //=================================================================================
277 void RepairGUI_SuppressFacesDlg::enterEvent (QEvent*)
279 if (!mainFrame()->GroupConstructors->isEnabled())
280 ActivateThisDialog();
283 //=================================================================================
284 // function : createOperation
286 //=================================================================================
287 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
289 return getGeomEngine()->GetIHealingOperations(getStudyId());
292 //=================================================================================
293 // function : isValid
295 //=================================================================================
296 bool RepairGUI_SuppressFacesDlg::isValid (QString&)
298 TopoDS_Shape aTmpShape;
299 return !myObject->_is_nil() && (myFacesInd->length() ||
300 GEOMBase::GetShape(myObject, aTmpShape, TopAbs_WIRE));
303 //=================================================================================
304 // function : execute
306 //=================================================================================
307 bool RepairGUI_SuppressFacesDlg::execute (ObjectList& objects)
309 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
310 GEOM::GEOM_Object_var anObj = anOper->SuppressFaces(myObject, myFacesInd);
312 bool aResult = !anObj->_is_nil();
314 objects.push_back(anObj._retn());
319 //=================================================================================
320 // function : initSelection
322 //=================================================================================
323 void RepairGUI_SuppressFacesDlg::initSelection()
325 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
327 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
328 TColStd_MapOfInteger aTypes;
329 aTypes.Add(GEOM_COMPOUND);
330 aTypes.Add(GEOM_SOLID);
331 aTypes.Add(GEOM_SHELL);
332 aTypes.Add(GEOM_FACE);
334 globalSelection(aTypes);
336 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
337 localSelection(myObject, TopAbs_FACE);
340 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
341 this, SLOT(SelectionIntoArgument()));