1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : BlocksGUI_PropagateDlg.cxx
30 #include "BlocksGUI_PropagateDlg.h"
31 #include "GEOMImpl_Types.hxx"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
37 #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(QWidget* parent, const char* name, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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 setCaption(tr("GEOM_PROPAGATE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_PROPAGATE_TITLE"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->close(TRUE);
60 RadioButton3->close(TRUE);
62 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
63 QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, aMainGrp);
64 aSelGrp->setFrameStyle(QFrame::NoFrame);
65 aSelGrp->setInsideMargin(0);
67 new QLabel(tr("GEOM_OBJECT"), aSelGrp);
68 mySelBtn = new QPushButton(aSelGrp);
69 mySelBtn->setPixmap(image1);
70 mySelName = new QLineEdit(aSelGrp);
71 mySelName->setReadOnly(true);
73 Layout1->addWidget(aMainGrp, 1, 0);
75 /***************************************************************/
81 //=================================================================================
82 // function : ~BlocksGUI_PropagateDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
90 //=================================================================================
93 //=================================================================================
94 void BlocksGUI_PropagateDlg::Init()
98 myObject = GEOM::GEOM_Object::_nil();
99 ResultName->setText( "" );
101 //myGeomGUI->SetState( 0 );
103 /* signals and slots connections */
104 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
105 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
106 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
108 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
111 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112 connect(mySelName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118 //=================================================================================
119 // function : ClickOnOk()
120 // purpose : Same than click on apply but close this dialog.
121 //=================================================================================
122 void BlocksGUI_PropagateDlg::ClickOnOk()
124 if ( ClickOnApply() )
130 //=================================================================================
131 // function : ClickOnApply()
133 //=================================================================================
134 bool BlocksGUI_PropagateDlg::ClickOnApply()
141 mySelName->setText("");
142 myObject = GEOM::GEOM_Object::_nil();
150 //=================================================================================
151 // function : ClickOnCancel()
153 //=================================================================================
154 void BlocksGUI_PropagateDlg::ClickOnCancel()
156 GEOMBase_Skeleton::ClickOnCancel();
160 //=================================================================================
161 // function : SelectionIntoArgument()
162 // purpose : Called when selection
163 //=================================================================================
164 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
166 mySelName->setText("");
167 myObject = GEOM::GEOM_Object::_nil();
169 if ( IObjectCount() == 1 ) {
170 Handle(SALOME_InteractiveObject) anIO = firstIObject();
171 Standard_Boolean aRes;
172 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
174 mySelName->setText( GEOMBase::GetName( myObject ) );
178 //=================================================================================
179 // function : SetEditCurrentArgument()
181 //=================================================================================
182 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
184 const QObject* send = sender();
185 if ( send == mySelBtn ) {
186 mySelName->setFocus();
192 //=================================================================================
193 // function : LineEditReturnPressed()
195 //=================================================================================
196 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
198 const QObject* send = sender();
199 if( send == mySelName ) {
200 GEOMBase_Skeleton::LineEditReturnPressed();
205 //=================================================================================
206 // function : DeactivateActiveDialog()
208 //=================================================================================
209 void BlocksGUI_PropagateDlg::DeactivateActiveDialog()
211 //myGeomGUI->SetState( -1 );
212 GEOMBase_Skeleton::DeactivateActiveDialog();
216 //=================================================================================
217 // function : ActivateThisDialog()
219 //=================================================================================
220 void BlocksGUI_PropagateDlg::ActivateThisDialog()
222 GEOMBase_Skeleton::ActivateThisDialog();
224 mySelName->setText("");
225 myObject = GEOM::GEOM_Object::_nil();
227 //myGeomGUI->SetState( 0 );
232 //=================================================================================
233 // function : enterEvent()
234 // purpose : Mouse enter onto the dialog to activate it
235 //=================================================================================
236 void BlocksGUI_PropagateDlg::enterEvent(QEvent* e)
238 if ( !GroupConstructors->isEnabled() )
239 ActivateThisDialog();
243 //=================================================================================
244 // function : closeEvent()
246 //=================================================================================
247 void BlocksGUI_PropagateDlg::closeEvent(QCloseEvent* e)
249 //myGeomGUI->SetState( -1 );
250 GEOMBase_Skeleton::closeEvent( e );
253 //=================================================================================
254 // function : createOperation
256 //=================================================================================
257 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
259 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
262 //=================================================================================
263 // function : isValid
265 //=================================================================================
266 bool BlocksGUI_PropagateDlg::isValid( QString& msg )
268 return !myObject->_is_nil() ;
271 //=================================================================================
272 // function : execute
274 //=================================================================================
275 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
278 GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
279 ResultName->setText( "" );
281 if ( !aList->length() )
284 for ( int i = 0, n = aList->length(); i < n; i++ )
286 objects.push_back(aList[i]._retn());
289 return objects.size() ? true : false;
292 //=================================================================================
293 // function : activateSelection
294 // purpose : Activate selection
295 //=================================================================================
296 void BlocksGUI_PropagateDlg::activateSelection()
298 TColStd_MapOfInteger aMap;
299 aMap.Add( GEOM_SOLID );
300 aMap.Add( GEOM_COMPOUND );
301 globalSelection( aMap );
302 if (myObject->_is_nil()) {
303 SelectionIntoArgument();
305 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
306 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
309 //================================================================
310 // Function : getFather
311 // Purpose : Get father object for object to be added in study
312 // ( called with addInStudy method )
313 //================================================================
314 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather (GEOM::GEOM_Object_ptr)