1 // Copyright (C) 2007-2010 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
20 // GEOM RepairGUI : GUI for Geometry component
21 // File : RepairGUI_RemoveExtraEdgesDlg.cxx
22 // Author : Michael Zorin, Open CASCADE S.A.S.
24 #include "RepairGUI_RemoveExtraEdgesDlg.h"
27 #include <GeometryGUI.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
35 #include <GEOMImpl_Types.hxx>
37 #include <TColStd_MapOfInteger.hxx>
39 //=================================================================================
40 // class : RepairGUI_RemoveExtraEdgesDlg()
41 // purpose : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
50 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
51 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REMOVE_EXTRA_EDGES" ) ) );
52 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_REMOVE_EXTRA_EDGES_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_1Sel1Check( centralWidget() );
66 GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_EXTRA_EDGES" ) );
67 GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
68 GroupPoints->PushButton1->setIcon( image1 );
69 GroupPoints->LineEdit1->setReadOnly( true );
71 GroupPoints->CheckButton1->setText( tr( "GEOM_RMEE_UNION_FACES" ) );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupPoints );
77 /***************************************************************/
79 setHelpFileName( "remove_extra_edges_operation_page.html" );
85 //=================================================================================
86 // function : ~RepairGUI_RemoveExtraEdgesDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
94 //=================================================================================
97 //=================================================================================
98 void RepairGUI_RemoveExtraEdgesDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
105 GroupPoints->CheckButton1->setChecked( false );
109 mainFrame()->GroupBoxPublish->show();
111 /* signals and slots connections */
112 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
113 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
115 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
116 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
118 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
119 this, SLOT( SelectionIntoArgument() ) );
121 initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
123 SelectionIntoArgument();
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose : Same than click on apply but close this dialog.
130 //=================================================================================
131 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
133 if ( ClickOnApply() )
137 //=================================================================================
138 // function : ClickOnApply()
140 //=================================================================================
141 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
148 myEditCurrentArgument->setText( "" );
149 myObject = GEOM::GEOM_Object::_nil();
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose : Called when selection as changed or other case
162 // : used only by SelectButtonC1A1 (LineEditC1A1)
163 //=================================================================================
164 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
166 myEditCurrentArgument->setText( "" );
169 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
170 SALOME_ListIO aSelList;
171 aSelMgr->selectedObjects(aSelList);
173 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
174 if ( aSelList.Extent() != 1 ) {
175 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
182 Standard_Boolean testResult = Standard_False;
183 GEOM::GEOM_Object_ptr aSelectedObject =
184 GEOMBase::ConvertIOinGEOMObject( aSelList.First(), testResult );
189 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
190 myObject = aSelectedObject;
194 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
197 //=================================================================================
198 // function : SetEditCurrentArgument()
200 //=================================================================================
201 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
203 if( sender() == GroupPoints->PushButton1 ) {
204 GroupPoints->LineEdit1->setFocus();
205 myEditCurrentArgument = GroupPoints->LineEdit1;
207 SelectionIntoArgument();
211 //=================================================================================
212 // function : LineEditReturnPressed()
214 //=================================================================================
215 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
217 if ( sender() == GroupPoints->LineEdit1 ) {
218 myEditCurrentArgument = GroupPoints->LineEdit1;
219 GEOMBase_Skeleton::LineEditReturnPressed();
224 //=================================================================================
225 // function : ActivateThisDialog()
227 //=================================================================================
228 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
230 GEOMBase_Skeleton::ActivateThisDialog();
231 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
232 this, SLOT( SelectionIntoArgument() ) );
238 //=================================================================================
239 // function : enterEvent()
240 // purpose : Mouse enter onto the dialog to activate it
241 //=================================================================================
242 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
244 if ( !mainFrame()->GroupConstructors->isEnabled() )
245 ActivateThisDialog();
249 //=================================================================================
250 // function : activateSelection
251 // purpose : activate selection of solids and compounds
252 //=================================================================================
253 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
255 TColStd_MapOfInteger aTypes;
256 aTypes.Add( GEOM_SHELL );
257 aTypes.Add( GEOM_SOLID );
258 aTypes.Add( GEOM_COMPOUND );
259 globalSelection( aTypes );
262 //=================================================================================
263 // function : createOperation
265 //=================================================================================
266 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
268 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
271 //=================================================================================
272 // function : isValid
274 //=================================================================================
275 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
280 //=================================================================================
281 // function : execute
283 //=================================================================================
284 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
286 GEOM::GEOM_Object_var anObj;
288 int nbFacesOptimum = -1; // -1 means do not union faces
289 if (GroupPoints->CheckButton1->isChecked())
290 nbFacesOptimum = 0; // 0 means union all faces, that possible
291 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
292 anObj = anOper->RemoveExtraEdges(myObject, nbFacesOptimum);
294 if (!anObj->_is_nil())
295 objects.push_back(anObj._retn());
300 //=================================================================================
301 // function : restoreSubShapes
303 //=================================================================================
304 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
305 SALOMEDS::SObject_ptr theSObject )
307 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
308 // empty list of arguments means that all arguments should be restored
309 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
310 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
311 /*theInheritFirstArg=*/true,
312 mainFrame()->CheckBoxAddPrefix->isChecked() );