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 : BlocksGUI_PropagateDlg.cxx
25 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
27 #include "BlocksGUI_PropagateDlg.h"
30 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <TColStd_MapOfInteger.hxx>
41 //=================================================================================
42 // class : BlocksGUI_PropagateDlg()
43 // purpose : Constructs a BlocksGUI_PropagateDlg 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 BlocksGUI_PropagateDlg::BlocksGUI_PropagateDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
49 : GEOMBase_Skeleton( theGeometryGUI, parent )
51 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PROPAGATE" ) ) );
52 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_PROPAGATE_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PROPAGATE_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 myGrp = new DlgRef_1Sel( centralWidget() );
65 myGrp->GroupBox1->setTitle( tr( "GEOM_SELECTED_SHAPE" ) );
66 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
67 myGrp->PushButton1->setIcon( image1 );
68 myGrp->LineEdit1->setReadOnly( true );
70 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71 layout->setMargin( 0 ); layout->setSpacing( 6 );
72 layout->addWidget( myGrp );
74 /***************************************************************/
76 setHelpFileName( "propagate_operation_page.html" );
81 //=================================================================================
82 // function : ~BlocksGUI_PropagateDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
89 //=================================================================================
92 //=================================================================================
93 void BlocksGUI_PropagateDlg::Init()
97 myObject = GEOM::GEOM_Object::_nil();
98 mainFrame()->ResultName->setText( "" );
99 mainFrame()->GroupBoxName->hide();
101 //myGeomGUI->SetState( 0 );
103 /* signals and slots connections */
104 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
105 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
107 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
108 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
114 //=================================================================================
115 // function : ClickOnOk()
116 // purpose : Same than click on apply but close this dialog.
117 //=================================================================================
118 void BlocksGUI_PropagateDlg::ClickOnOk()
120 if ( ClickOnApply() )
124 //=================================================================================
125 // function : ClickOnApply()
127 //=================================================================================
128 bool BlocksGUI_PropagateDlg::ClickOnApply()
135 myGrp->LineEdit1->setText( "" );
136 myObject = GEOM::GEOM_Object::_nil();
144 //=================================================================================
145 // function : SelectionIntoArgument()
146 // purpose : Called when selection
147 //=================================================================================
148 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
150 myGrp->LineEdit1->setText( "" );
151 myObject = GEOM::GEOM_Object::_nil();
153 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
154 SALOME_ListIO aSelList;
155 aSelMgr->selectedObjects(aSelList);
157 if (aSelList.Extent() == 1) {
158 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
159 myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
160 if ( !CORBA::is_nil( myObject ) )
161 myGrp->LineEdit1->setText( GEOMBase::GetName( myObject ) );
165 //=================================================================================
166 // function : SetEditCurrentArgument()
168 //=================================================================================
169 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
171 const QObject* send = sender();
172 if ( send == myGrp->PushButton1 ) {
173 myGrp->LineEdit1->setFocus();
179 //=================================================================================
180 // function : LineEditReturnPressed()
182 //=================================================================================
183 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
185 const QObject* send = sender();
186 if ( send == myGrp->LineEdit1 ) {
187 GEOMBase_Skeleton::LineEditReturnPressed();
192 //=================================================================================
193 // function : ActivateThisDialog()
195 //=================================================================================
196 void BlocksGUI_PropagateDlg::ActivateThisDialog()
198 GEOMBase_Skeleton::ActivateThisDialog();
200 myGrp->LineEdit1->setText( "" );
201 myObject = GEOM::GEOM_Object::_nil();
203 //myGeomGUI->SetState( 0 );
208 //=================================================================================
209 // function : enterEvent()
210 // purpose : Mouse enter onto the dialog to activate it
211 //=================================================================================
212 void BlocksGUI_PropagateDlg::enterEvent( QEvent* )
214 if ( !mainFrame()->GroupConstructors->isEnabled() )
215 ActivateThisDialog();
218 //=================================================================================
219 // function : createOperation
221 //=================================================================================
222 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
224 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
227 //=================================================================================
228 // function : isValid
230 //=================================================================================
231 bool BlocksGUI_PropagateDlg::isValid( QString& )
233 return !myObject->_is_nil() ;
236 //=================================================================================
237 // function : execute
239 //=================================================================================
240 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
242 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
243 GEOM::ListOfGO_var aList = anOper->Propagate( myObject );
244 mainFrame()->ResultName->setText( "" );
246 if ( !aList->length() )
249 for ( int i = 0, n = aList->length(); i < n; i++ ) {
250 objects.push_back( aList[i]._retn() );
253 return objects.size() > 0;
256 //=================================================================================
257 // function : activateSelection
258 // purpose : Activate selection
259 //=================================================================================
260 void BlocksGUI_PropagateDlg::activateSelection()
262 TColStd_MapOfInteger aMap;
263 aMap.Add( GEOM_FACE );
264 aMap.Add( GEOM_SHELL );
265 aMap.Add( GEOM_SOLID );
266 aMap.Add( GEOM_COMPOUND );
267 globalSelection( aMap );
268 if ( myObject->_is_nil() ) {
269 SelectionIntoArgument();
271 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
272 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
275 //================================================================
276 // Function : getFather
277 // Purpose : Get father object for object to be added in study
278 // ( called with addInStudy method )
279 //================================================================
280 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather( GEOM::GEOM_Object_ptr )