1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_SuppressFacesDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "RepairGUI_SuppressFacesDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_Study.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SALOME_ListIteratorOfListIO.hxx>
43 #include <TopExp_Explorer.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <TColStd_MapOfInteger.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <GEOMImpl_Types.hxx>
50 //=================================================================================
51 // class : RepairGUI_SuppressFacesDlg()
52 // purpose : Constructs a RepairGUI_SuppressFacesDlg 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_SuppressFacesDlg::RepairGUI_SuppressFacesDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
59 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
61 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPRESS_FACE")));
62 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_SUPRESSFACE_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
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 GroupArgs = new DlgRef_2Sel(centralWidget());
75 GroupArgs->GroupBox1->setTitle(tr("Faces to remove"));
76 GroupArgs->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
77 GroupArgs->PushButton1->setIcon(image1);
78 GroupArgs->LineEdit1->setReadOnly(true);
80 GroupArgs->TextLabel2->setText(tr("Faces to remove"));
81 GroupArgs->PushButton2->setIcon(image1);
82 GroupArgs->LineEdit2->setReadOnly(true);
84 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
85 layout->setMargin(0); layout->setSpacing(6);
86 layout->addWidget(GroupArgs);
87 /***************************************************************/
89 setHelpFileName("suppress_faces_operation_page.html");
94 //=================================================================================
95 // function : ~RepairGUI_SuppressFacesDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
102 //=================================================================================
105 //=================================================================================
106 void RepairGUI_SuppressFacesDlg::Init()
109 GroupArgs->LineEdit1->clear();
110 GroupArgs->LineEdit2->clear();
111 myObject = GEOM::GEOM_Object::_nil();
112 myFacesInd = new GEOM::short_array();
113 myFacesInd->length(0);
115 mainFrame()->GroupBoxPublish->show();
117 // signals and slots connections
118 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
121 connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122 connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 initName(tr("SUPRESS_FACE_NEW_OBJ_NAME"));
129 GroupArgs->PushButton1->click();
130 SelectionIntoArgument();
134 //=================================================================================
135 // function : ClickOnOk()
136 // purpose : Same than click on apply but close this dialog.
137 //=================================================================================
138 void RepairGUI_SuppressFacesDlg::ClickOnOk()
144 //=================================================================================
145 // function : ClickOnApply()
147 //=================================================================================
148 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
154 // activate first line edit
155 GroupArgs->PushButton1->click();
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose : Called when selection is changed or on dialog initialization or activation
162 //=================================================================================
163 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
165 myEditCurrentArgument->setText("");
166 // the second argument depends on the first one
167 GroupArgs->LineEdit2->setText("");
168 myFacesInd->length(0);
170 if (myEditCurrentArgument == GroupArgs->LineEdit1)
171 myObject = GEOM::GEOM_Object::_nil();
173 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
174 SALOME_ListIO aSelList;
175 aSelMgr->selectedObjects(aSelList);
177 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
178 if (aSelList.Extent() == 1) {
179 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
181 Standard_Boolean aRes;
182 myObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
183 if (aRes && GEOMBase::IsShape(myObject)) {
184 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
186 if (GEOMBase::GetShape(myObject, aShape, TopAbs_FACE))
187 GroupArgs->LineEdit2->setText(myEditCurrentArgument->text());
190 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
191 myGeomGUI->getApp()->selectionMgr()->clearSelected();
192 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
193 this, SLOT(SelectionIntoArgument()));
195 GroupArgs->PushButton2->click();
198 myObject = GEOM::GEOM_Object::_nil();
201 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
202 TColStd_IndexedMapOfInteger aMap;
204 if (aSelList.Extent() == 1) {
205 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
206 aSelMgr->GetIndexes(anIO, aMap);
209 if (aMap.IsEmpty() && aSelList.Extent() > 0) { // try to detect selected published sub-shape
210 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(myGeomGUI->getApp()->activeStudy());
211 if (!appStudy) return;
212 _PTR(Study) aStudy = appStudy->studyDS();
214 TopTools_IndexedMapOfShape aMainMap;
215 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myObject);
216 TopExp::MapShapes(aMainShape, aMainMap);
218 SALOME_ListIteratorOfListIO anIter (aSelList);
219 for (int i = 0; anIter.More(); anIter.Next(), i++) {
220 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
221 QString anEntry = anIO->getEntry();
223 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
224 GEOM::GEOM_Object_var aGeomObj =
225 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
227 if (GEOMBase::GetShape(aGeomObj, aShape)) {
228 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == TopAbs_FACE) {
229 TopExp_Explorer anExp (aShape, TopAbs_FACE);
230 for (; anExp.More(); anExp.Next()) {
231 TopoDS_Shape aSubShape = anExp.Current();
232 int anIndex = aMainMap.FindIndex(aSubShape);
242 const int n = aMap.Extent();
243 myFacesInd->length(n);
244 for (int i = 1; i <= n; i++)
245 myFacesInd[i-1] = aMap(i);
247 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_FACE") + tr("_S_"));
251 //=================================================================================
252 // function : SetEditCurrentArgument()
254 //=================================================================================
255 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
257 QPushButton* send = (QPushButton*)sender();
259 bool isEffective = false;
261 if (send == GroupArgs->PushButton1) {
263 myEditCurrentArgument = GroupArgs->LineEdit1;
265 GroupArgs->PushButton2->setDown(false);
266 GroupArgs->LineEdit2->setEnabled(false);
268 else if (send == GroupArgs->PushButton2 && !myObject->_is_nil()) {
270 myEditCurrentArgument = GroupArgs->LineEdit2;
272 GroupArgs->PushButton1->setDown(false);
273 GroupArgs->LineEdit1->setEnabled(false);
280 myEditCurrentArgument->setEnabled(true);
281 myEditCurrentArgument->setFocus();
282 // after setFocus(), because it will be setDown(false) when loses focus
287 //=================================================================================
288 // function : LineEditReturnPressed()
290 //=================================================================================
291 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
293 const QObject* send = sender();
294 if (send == GroupArgs->LineEdit1 || send == GroupArgs->LineEdit2) {
295 myEditCurrentArgument = (QLineEdit*)send;
296 GEOMBase_Skeleton::LineEditReturnPressed();
300 //=================================================================================
301 // function : ActivateThisDialog()
303 //=================================================================================
304 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
306 GEOMBase_Skeleton::ActivateThisDialog();
307 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
308 this, SLOT( SelectionIntoArgument() ) );
310 myEditCurrentArgument = GroupArgs->LineEdit1;
311 myEditCurrentArgument->setText( "" );
312 GroupArgs->LineEdit2->setText( "" );
313 myObject = GEOM::GEOM_Object::_nil();
314 myFacesInd->length( 0 );
319 //=================================================================================
320 // function : enterEvent()
321 // purpose : Mouse enter onto the dialog to activate it
322 //=================================================================================
323 void RepairGUI_SuppressFacesDlg::enterEvent (QEvent*)
325 if (!mainFrame()->GroupConstructors->isEnabled())
326 ActivateThisDialog();
329 //=================================================================================
330 // function : createOperation
332 //=================================================================================
333 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
335 return getGeomEngine()->GetIHealingOperations(getStudyId());
338 //=================================================================================
339 // function : isValid
341 //=================================================================================
342 bool RepairGUI_SuppressFacesDlg::isValid (QString&)
344 TopoDS_Shape aTmpShape;
345 return !myObject->_is_nil() && (myFacesInd->length() ||
346 GEOMBase::GetShape(myObject, aTmpShape, TopAbs_WIRE));
349 //=================================================================================
350 // function : execute
352 //=================================================================================
353 bool RepairGUI_SuppressFacesDlg::execute (ObjectList& objects)
355 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
356 GEOM::GEOM_Object_var anObj = anOper->SuppressFaces(myObject, myFacesInd);
358 bool aResult = !anObj->_is_nil();
360 objects.push_back(anObj._retn());
365 //=================================================================================
366 // function : initSelection
368 //=================================================================================
369 void RepairGUI_SuppressFacesDlg::initSelection()
371 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
373 if (myEditCurrentArgument == GroupArgs->LineEdit1) {
374 TColStd_MapOfInteger aTypes;
375 aTypes.Add(GEOM_COMPOUND);
376 aTypes.Add(GEOM_SOLID);
377 aTypes.Add(GEOM_SHELL);
378 aTypes.Add(GEOM_FACE);
380 globalSelection(aTypes);
382 else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
383 localSelection(myObject, TopAbs_FACE);
386 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
387 this, SLOT(SelectionIntoArgument()));
390 //=================================================================================
391 // function : restoreSubShapes
393 //=================================================================================
394 void RepairGUI_SuppressFacesDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
395 SALOMEDS::SObject_ptr theSObject)
397 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
398 // empty list of arguments means that all arguments should be restored
399 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
400 /*theFindMethod=*/GEOM::FSM_GetInPlace,
401 /*theInheritFirstArg=*/true,
402 mainFrame()->CheckBoxAddPrefix->isChecked());