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 RepairGUI : GUI for Geometry component
23 // File : RepairGUI_RemoveExtraEdgesDlg.cxx
24 // Author : Michael Zorin, Open CASCADE S.A.S.
26 #include "RepairGUI_RemoveExtraEdgesDlg.h"
29 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <GEOMImpl_Types.hxx>
39 #include <TColStd_MapOfInteger.hxx>
41 //=================================================================================
42 // class : RepairGUI_RemoveExtraEdgesDlg()
43 // purpose : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
50 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
52 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
53 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REMOVE_EXTRA_EDGES" ) ) );
54 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56 setWindowTitle( tr( "GEOM_REMOVE_EXTRA_EDGES_TITLE" ) );
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton2->close();
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 GroupPoints = new DlgRef_1Sel( centralWidget() );
67 GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_EXTRA_EDGES" ) );
68 GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
69 GroupPoints->PushButton1->setIcon( image1 );
70 GroupPoints->LineEdit1->setReadOnly( true );
72 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73 layout->setMargin( 0 ); layout->setSpacing( 6 );
74 layout->addWidget( GroupPoints );
76 /***************************************************************/
78 setHelpFileName( "remove_extra_edges_operation_page.html" );
84 //=================================================================================
85 // function : ~RepairGUI_RemoveExtraEdgesDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
93 //=================================================================================
96 //=================================================================================
97 void RepairGUI_RemoveExtraEdgesDlg::Init()
100 myEditCurrentArgument = GroupPoints->LineEdit1;
106 mainFrame()->GroupBoxPublish->show();
108 /* signals and slots connections */
109 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
110 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
112 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
113 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
115 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
116 this, SLOT( SelectionIntoArgument() ) );
118 initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
122 //=================================================================================
123 // function : ClickOnOk()
124 // purpose : Same than click on apply but close this dialog.
125 //=================================================================================
126 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
128 if ( ClickOnApply() )
132 //=================================================================================
133 // function : ClickOnApply()
135 //=================================================================================
136 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
143 myEditCurrentArgument->setText( "" );
144 myObject = GEOM::GEOM_Object::_nil();
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose : Called when selection as changed or other case
157 // : used only by SelectButtonC1A1 (LineEditC1A1)
158 //=================================================================================
159 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
161 myEditCurrentArgument->setText( "" );
164 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
165 SALOME_ListIO aSelList;
166 aSelMgr->selectedObjects(aSelList);
168 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
169 if ( aSelList.Extent() != 1 ) {
170 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
177 Standard_Boolean testResult = Standard_False;
178 GEOM::GEOM_Object_ptr aSelectedObject =
179 GEOMBase::ConvertIOinGEOMObject( aSelList.First(), testResult );
184 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
185 myObject = aSelectedObject;
189 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
192 //=================================================================================
193 // function : SetEditCurrentArgument()
195 //=================================================================================
196 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
198 if( sender() == GroupPoints->PushButton1 ) {
199 GroupPoints->LineEdit1->setFocus();
200 myEditCurrentArgument = GroupPoints->LineEdit1;
202 SelectionIntoArgument();
206 //=================================================================================
207 // function : LineEditReturnPressed()
209 //=================================================================================
210 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
212 if ( sender() == GroupPoints->LineEdit1 ) {
213 myEditCurrentArgument = GroupPoints->LineEdit1;
214 GEOMBase_Skeleton::LineEditReturnPressed();
219 //=================================================================================
220 // function : ActivateThisDialog()
222 //=================================================================================
223 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
225 GEOMBase_Skeleton::ActivateThisDialog();
226 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
227 this, SLOT( SelectionIntoArgument() ) );
233 //=================================================================================
234 // function : enterEvent()
235 // purpose : Mouse enter onto the dialog to activate it
236 //=================================================================================
237 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
239 if ( !mainFrame()->GroupConstructors->isEnabled() )
240 ActivateThisDialog();
244 //=================================================================================
245 // function : activateSelection
246 // purpose : activate selection of solids and compounds
247 //=================================================================================
248 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
250 TColStd_MapOfInteger aTypes;
251 aTypes.Add( GEOM_SOLID );
252 aTypes.Add( GEOM_COMPOUND );
253 globalSelection( aTypes );
256 //=================================================================================
257 // function : createOperation
259 //=================================================================================
260 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
262 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
265 //=================================================================================
266 // function : isValid
268 //=================================================================================
269 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
274 //=================================================================================
275 // function : execute
277 //=================================================================================
278 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
280 GEOM::GEOM_Object_var anObj;
282 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->RemoveExtraEdges( myObject );
284 if ( !anObj->_is_nil() )
285 objects.push_back( anObj._retn() );
290 //=================================================================================
291 // function : restoreSubShapes
293 //=================================================================================
294 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
295 SALOMEDS::SObject_ptr theSObject )
297 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
298 // empty list of arguments means that all arguments should be restored
299 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
300 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
301 /*theInheritFirstArg=*/true );