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 // GEOM RepairGUI : GUI for Geometry component
21 // File : RepairGUI_RemoveWebsDlg.cxx
23 #include "RepairGUI_RemoveWebsDlg.h"
26 #include <GeometryGUI.h>
29 #include <SalomeApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
34 #include <GEOMImpl_Types.hxx>
36 #include <TColStd_MapOfInteger.hxx>
38 //=================================================================================
39 // class : RepairGUI_RemoveWebsDlg()
40 // purpose : Constructs a RepairGUI_RemoveWebsDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 RepairGUI_RemoveWebsDlg::RepairGUI_RemoveWebsDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
47 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
49 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
50 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_REMOVE_WEBS")));
51 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
53 setWindowTitle(tr("GEOM_REMOVE_WEBS_TITLE"));
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_WEBS_TITLE"));
57 mainFrame()->RadioButton1->setIcon( image0 );
58 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupPoints = new DlgRef_1Sel( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_WEBS" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPES" ) );
67 GroupPoints->PushButton1->setIcon( image1 );
68 GroupPoints->LineEdit1->setReadOnly( true );
70 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71 layout->setMargin( 0 ); layout->setSpacing( 6 );
72 layout->addWidget( GroupPoints );
74 /***************************************************************/
76 setHelpFileName( "remove_webs_operation_page.html" );
81 //=================================================================================
82 // function : ~RepairGUI_RemoveWebsDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 RepairGUI_RemoveWebsDlg::~RepairGUI_RemoveWebsDlg()
89 //=================================================================================
92 //=================================================================================
93 void RepairGUI_RemoveWebsDlg::Init()
96 myEditCurrentArgument = GroupPoints->LineEdit1;
102 mainFrame()->GroupBoxPublish->show();
103 //Hide preview checkbox
104 mainFrame()->CheckBoxPreview->hide();
106 /* signals and slots connections */
107 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
114 this, SLOT(SelectionIntoArgument()));
116 initName(tr("REMOVE_WEBS_NEW_OBJ_NAME"));
118 SelectionIntoArgument();
121 //=================================================================================
122 // function : ClickOnOk()
123 // purpose : Same than click on apply but close this dialog.
124 //=================================================================================
125 void RepairGUI_RemoveWebsDlg::ClickOnOk()
127 setIsApplyAndClose(true);
132 //=================================================================================
133 // function : ClickOnApply()
135 //=================================================================================
136 bool RepairGUI_RemoveWebsDlg::ClickOnApply()
143 myEditCurrentArgument->setText("");
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose : Called when selection as changed or other case
156 // : used only by SelectButtonC1A1 (LineEditC1A1)
157 //=================================================================================
158 void RepairGUI_RemoveWebsDlg::SelectionIntoArgument()
160 myEditCurrentArgument->setText( "" );
164 myObjects = getSelected( TopAbs_SHAPE, -1 );
166 if ( !myObjects.isEmpty() ) {
167 QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
169 myEditCurrentArgument->setText( aName );
173 //=================================================================================
174 // function : SetEditCurrentArgument()
176 //=================================================================================
177 void RepairGUI_RemoveWebsDlg::SetEditCurrentArgument()
179 if (sender() == GroupPoints->PushButton1) {
180 GroupPoints->LineEdit1->setFocus();
181 myEditCurrentArgument = GroupPoints->LineEdit1;
183 SelectionIntoArgument();
186 //=================================================================================
187 // function : LineEditReturnPressed()
189 //=================================================================================
190 void RepairGUI_RemoveWebsDlg::LineEditReturnPressed()
192 if (sender() == GroupPoints->LineEdit1) {
193 myEditCurrentArgument = GroupPoints->LineEdit1;
194 GEOMBase_Skeleton::LineEditReturnPressed();
198 //=================================================================================
199 // function : ActivateThisDialog()
201 //=================================================================================
202 void RepairGUI_RemoveWebsDlg::ActivateThisDialog()
204 GEOMBase_Skeleton::ActivateThisDialog();
205 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
206 this, SLOT(SelectionIntoArgument()));
211 //=================================================================================
212 // function : enterEvent()
213 // purpose : Mouse enter onto the dialog to activate it
214 //=================================================================================
215 void RepairGUI_RemoveWebsDlg::enterEvent (QEvent* e)
217 if (!mainFrame()->GroupConstructors->isEnabled())
218 ActivateThisDialog();
221 //=================================================================================
222 // function : activateSelection
223 // purpose : activate selection of solids and compounds
224 //=================================================================================
225 void RepairGUI_RemoveWebsDlg::activateSelection()
227 TColStd_MapOfInteger aTypes;
228 aTypes.Add( GEOM_SOLID );
229 aTypes.Add( GEOM_COMPOUND );
230 globalSelection( aTypes );
233 //=================================================================================
234 // function : createOperation
236 //=================================================================================
237 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveWebsDlg::createOperation()
239 return getGeomEngine()->GetIHealingOperations(getStudyId());
242 //=================================================================================
243 // function : isValid
245 //=================================================================================
246 bool RepairGUI_RemoveWebsDlg::isValid (QString& msg)
251 //=================================================================================
252 // function : execute
254 //=================================================================================
255 bool RepairGUI_RemoveWebsDlg::execute (ObjectList& objects)
257 GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
258 objList->length( myObjects.count() );
259 for ( int i = 0; i < myObjects.count(); ++i )
260 objList[i] = myObjects[i].copy();
262 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
263 GEOM::GEOM_Object_var anObj = anOper->RemoveInternalFaces(objList);
265 if (!anObj->_is_nil())
266 objects.push_back(anObj._retn());
271 //=================================================================================
272 // function : restoreSubShapes
274 //=================================================================================
275 void RepairGUI_RemoveWebsDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
276 SALOMEDS::SObject_ptr theSObject)
278 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
279 // empty list of arguments means that all arguments should be restored
280 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
281 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
282 /*theInheritFirstArg=*/true,
283 mainFrame()->CheckBoxAddPrefix->isChecked());