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
29 #include "BlocksGUI_PropagateDlg.h"
30 #include "GEOMImpl_Types.hxx"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TColStd_MapOfInteger.hxx>
42 //=================================================================================
43 // class : BlocksGUI_PropagateDlg()
44 // purpose : Constructs a BlocksGUI_PropagateDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 BlocksGUI_PropagateDlg::BlocksGUI_PropagateDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PROPAGATE")));
53 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_PROPAGATE_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_PROPAGATE_TITLE"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
64 QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, aMainGrp);
65 aSelGrp->setFrameStyle(QFrame::NoFrame);
66 aSelGrp->setInsideMargin(0);
68 new QLabel(tr("GEOM_OBJECT"), aSelGrp);
69 mySelBtn = new QPushButton(aSelGrp);
70 mySelBtn->setPixmap(image1);
71 mySelName = new QLineEdit(aSelGrp);
72 mySelName->setReadOnly(true);
74 Layout1->addWidget(aMainGrp, 1, 0);
76 /***************************************************************/
82 //=================================================================================
83 // function : ~BlocksGUI_PropagateDlg()
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
91 //=================================================================================
94 //=================================================================================
95 void BlocksGUI_PropagateDlg::Init()
99 myObject = GEOM::GEOM_Object::_nil();
100 ResultName->setText( "" );
102 //myGeomGUI->SetState( 0 );
104 /* signals and slots connections */
105 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
106 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
107 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
109 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
110 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
112 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113 connect(mySelName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose : Same than click on apply but close this dialog.
122 //=================================================================================
123 void BlocksGUI_PropagateDlg::ClickOnOk()
125 if ( ClickOnApply() )
131 //=================================================================================
132 // function : ClickOnApply()
134 //=================================================================================
135 bool BlocksGUI_PropagateDlg::ClickOnApply()
142 mySelName->setText("");
143 myObject = GEOM::GEOM_Object::_nil();
151 //=================================================================================
152 // function : ClickOnCancel()
154 //=================================================================================
155 void BlocksGUI_PropagateDlg::ClickOnCancel()
157 GEOMBase_Skeleton::ClickOnCancel();
161 //=================================================================================
162 // function : SelectionIntoArgument()
163 // purpose : Called when selection
164 //=================================================================================
165 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
167 mySelName->setText("");
168 myObject = GEOM::GEOM_Object::_nil();
170 if ( IObjectCount() == 1 ) {
171 Handle(SALOME_InteractiveObject) anIO = firstIObject();
172 Standard_Boolean aRes;
173 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
175 mySelName->setText( GEOMBase::GetName( myObject ) );
179 //=================================================================================
180 // function : SetEditCurrentArgument()
182 //=================================================================================
183 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
185 const QObject* send = sender();
186 if ( send == mySelBtn ) {
187 mySelName->setFocus();
193 //=================================================================================
194 // function : LineEditReturnPressed()
196 //=================================================================================
197 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
199 const QObject* send = sender();
200 if( send == mySelName ) {
201 GEOMBase_Skeleton::LineEditReturnPressed();
206 //=================================================================================
207 // function : DeactivateActiveDialog()
209 //=================================================================================
210 void BlocksGUI_PropagateDlg::DeactivateActiveDialog()
212 //myGeomGUI->SetState( -1 );
213 GEOMBase_Skeleton::DeactivateActiveDialog();
217 //=================================================================================
218 // function : ActivateThisDialog()
220 //=================================================================================
221 void BlocksGUI_PropagateDlg::ActivateThisDialog()
223 GEOMBase_Skeleton::ActivateThisDialog();
225 mySelName->setText("");
226 myObject = GEOM::GEOM_Object::_nil();
228 //myGeomGUI->SetState( 0 );
233 //=================================================================================
234 // function : enterEvent()
235 // purpose : Mouse enter onto the dialog to activate it
236 //=================================================================================
237 void BlocksGUI_PropagateDlg::enterEvent(QEvent* e)
239 if ( !GroupConstructors->isEnabled() )
240 ActivateThisDialog();
244 //=================================================================================
245 // function : closeEvent()
247 //=================================================================================
248 void BlocksGUI_PropagateDlg::closeEvent(QCloseEvent* e)
250 //myGeomGUI->SetState( -1 );
251 GEOMBase_Skeleton::closeEvent( e );
254 //=================================================================================
255 // function : createOperation
257 //=================================================================================
258 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
260 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
263 //=================================================================================
264 // function : isValid
266 //=================================================================================
267 bool BlocksGUI_PropagateDlg::isValid( QString& msg )
269 return !myObject->_is_nil() ;
272 //=================================================================================
273 // function : execute
275 //=================================================================================
276 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
279 GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
280 ResultName->setText( "" );
282 if ( !aList->length() )
285 for ( int i = 0, n = aList->length(); i < n; i++ )
287 objects.push_back(aList[i]._retn());
290 return objects.size() ? true : false;
293 //=================================================================================
294 // function : activateSelection
295 // purpose : Activate selection
296 //=================================================================================
297 void BlocksGUI_PropagateDlg::activateSelection()
299 TColStd_MapOfInteger aMap;
300 aMap.Add( GEOM_SOLID );
301 aMap.Add( GEOM_COMPOUND );
302 globalSelection( aMap );
303 if (myObject->_is_nil()) {
304 SelectionIntoArgument();
306 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
307 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
310 //================================================================
311 // Function : getFather
312 // Purpose : Get father object for object to be added in study
313 // ( called with addInStudy method )
314 //================================================================
315 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather (GEOM::GEOM_Object_ptr)