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 <SalomeApp_Study.h>
36 #include <LightApp_SelectionMgr.h>
41 #include <TopExp_Explorer.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TColStd_MapOfInteger.hxx>
44 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : RepairGUI_SuppressFacesDlg()
50 // purpose : Constructs a RepairGUI_SuppressFacesDlg 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_SuppressFacesDlg::RepairGUI_SuppressFacesDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
59 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPRESS_FACE")));
60 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
62 setWindowTitle(tr("GEOM_SUPRESSFACE_TITLE"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
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 GroupArgs = new DlgRef_2Sel(centralWidget());
73 GroupArgs->GroupBox1->setTitle(tr("Faces to remove"));
74 GroupArgs->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
75 GroupArgs->PushButton1->setIcon(image1);
76 GroupArgs->LineEdit1->setReadOnly(true);
78 GroupArgs->TextLabel2->setText(tr("Faces to remove"));
79 GroupArgs->PushButton2->setIcon(image1);
80 GroupArgs->LineEdit2->setReadOnly(true);
82 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
83 layout->setMargin(0); layout->setSpacing(6);
84 layout->addWidget(GroupArgs);
85 /***************************************************************/
87 setHelpFileName("suppress_faces_operation_page.html");
92 //=================================================================================
93 // function : ~RepairGUI_SuppressFacesDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
100 //=================================================================================
103 //=================================================================================
104 void RepairGUI_SuppressFacesDlg::Init()
107 GroupArgs->LineEdit1->clear();
108 GroupArgs->LineEdit2->clear();
109 myObject = GEOM::GEOM_Object::_nil();
110 myFacesInd = new GEOM::short_array();
111 myFacesInd->length(0);
113 // signals and slots connections
114 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
117 connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120 connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123 initName(tr("SUPRESS_FACE_NEW_OBJ_NAME"));
125 GroupArgs->PushButton1->click();
126 SelectionIntoArgument();
130 //=================================================================================
131 // function : ClickOnOk()
132 // purpose : Same than click on apply but close this dialog.
133 //=================================================================================
134 void RepairGUI_SuppressFacesDlg::ClickOnOk()
140 //=================================================================================
141 // function : ClickOnApply()
143 //=================================================================================
144 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
150 // activate first line edit
151 GroupArgs->PushButton1->click();
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose : Called when selection is changed or on dialog initialization or activation
158 //=================================================================================
159 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
161 myEditCurrentArgument->setText("");
162 // the second argument depends on the first one
163 GroupArgs->LineEdit2->setText("");
164 myFacesInd->length(0);
166 if (myEditCurrentArgument == GroupArgs->LineEdit1)
167 myObject = GEOM::GEOM_Object::_nil();
169 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
170 SALOME_ListIO aSelList;
171 aSelMgr->selectedObjects(aSelList);
173 if (aSelList.Extent() == 1) {
174 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
176 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
177 Standard_Boolean aRes;
178 myObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
179 if (aRes && GEOMBase::IsShape(myObject)) {
180 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
182 if (GEOMBase::GetShape(myObject, aShape, TopAbs_FACE))
183 GroupArgs->LineEdit2->setText(myEditCurrentArgument->text());
186 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
187 myGeomGUI->getApp()->selectionMgr()->clearSelected();
188 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
189 this, SLOT(SelectionIntoArgument()));
191 GroupArgs->PushButton2->click();
194 myObject = GEOM::GEOM_Object::_nil();
196 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
197 TColStd_IndexedMapOfInteger aMap;
198 aSelMgr->GetIndexes(anIO, aMap);
200 if (aMap.IsEmpty()) { // try to detect selected published sub-shape
201 QString anEntry = anIO->getEntry();
203 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(myGeomGUI->getApp()->activeStudy());
204 if (!appStudy) return;
205 _PTR(Study) aStudy = appStudy->studyDS();
206 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
207 GEOM::GEOM_Object_var aGeomObj =
208 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
210 if (GEOMBase::GetShape(aGeomObj, aShape)) {
211 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == TopAbs_FACE) {
212 TopTools_IndexedMapOfShape aMainMap;
213 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myObject);
214 TopExp::MapShapes(aMainShape, aMainMap);
216 TopExp_Explorer anExp (aShape, TopAbs_FACE);
217 for (; anExp.More(); anExp.Next()) {
218 TopoDS_Shape aSubShape = anExp.Current();
219 int anIndex = aMainMap.FindIndex(aSubShape);
228 const int n = aMap.Extent();
229 myFacesInd->length(n);
230 for (int i = 1; i <= n; i++)
231 myFacesInd[i-1] = aMap(i);
233 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_FACE") + tr("_S_"));
238 //=================================================================================
239 // function : SetEditCurrentArgument()
241 //=================================================================================
242 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
244 QPushButton* send = (QPushButton*)sender();
246 bool isEffective = false;
248 if (send == GroupArgs->PushButton1) {
250 myEditCurrentArgument = GroupArgs->LineEdit1;
252 GroupArgs->PushButton2->setDown(false);
253 GroupArgs->LineEdit2->setEnabled(false);
255 else if (send == GroupArgs->PushButton2 && !myObject->_is_nil()) {
257 myEditCurrentArgument = GroupArgs->LineEdit2;
259 GroupArgs->PushButton1->setDown(false);
260 GroupArgs->LineEdit1->setEnabled(false);
267 myEditCurrentArgument->setEnabled(true);
268 myEditCurrentArgument->setFocus();
269 // after setFocus(), because it will be setDown(false) when loses focus
274 //=================================================================================
275 // function : LineEditReturnPressed()
277 //=================================================================================
278 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
280 const QObject* send = sender();
281 if (send == GroupArgs->LineEdit1 || send == GroupArgs->LineEdit2) {
282 myEditCurrentArgument = (QLineEdit*)send;
283 GEOMBase_Skeleton::LineEditReturnPressed();
287 //=================================================================================
288 // function : ActivateThisDialog()
290 //=================================================================================
291 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
293 GEOMBase_Skeleton::ActivateThisDialog();
294 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
295 this, SLOT( SelectionIntoArgument() ) );
297 myEditCurrentArgument = GroupArgs->LineEdit1;
298 myEditCurrentArgument->setText( "" );
299 GroupArgs->LineEdit2->setText( "" );
300 myObject = GEOM::GEOM_Object::_nil();
301 myFacesInd->length( 0 );
306 //=================================================================================
307 // function : enterEvent()
308 // purpose : Mouse enter onto the dialog to activate it
309 //=================================================================================
310 void RepairGUI_SuppressFacesDlg::enterEvent (QEvent*)
312 if (!mainFrame()->GroupConstructors->isEnabled())
313 ActivateThisDialog();
316 //=================================================================================
317 // function : createOperation
319 //=================================================================================
320 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
322 return getGeomEngine()->GetIHealingOperations(getStudyId());
325 //=================================================================================
326 // function : isValid
328 //=================================================================================
329 bool RepairGUI_SuppressFacesDlg::isValid (QString&)
331 TopoDS_Shape aTmpShape;
332 return !myObject->_is_nil() && (myFacesInd->length() ||
333 GEOMBase::GetShape(myObject, aTmpShape, TopAbs_WIRE));
336 //=================================================================================
337 // function : execute
339 //=================================================================================
340 bool RepairGUI_SuppressFacesDlg::execute (ObjectList& objects)
342 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
343 GEOM::GEOM_Object_var anObj = anOper->SuppressFaces(myObject, myFacesInd);
345 bool aResult = !anObj->_is_nil();
347 objects.push_back(anObj._retn());
352 //=================================================================================
353 // function : initSelection
355 //=================================================================================
356 void RepairGUI_SuppressFacesDlg::initSelection()
358 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
360 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
361 TColStd_MapOfInteger aTypes;
362 aTypes.Add(GEOM_COMPOUND);
363 aTypes.Add(GEOM_SOLID);
364 aTypes.Add(GEOM_SHELL);
365 aTypes.Add(GEOM_FACE);
367 globalSelection(aTypes);
369 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
370 localSelection(myObject, TopAbs_FACE);
373 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
374 this, SLOT(SelectionIntoArgument()));