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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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(GeometryGUI* theGeometryGUI, QWidget* parent,
50 const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
52 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PROPAGATE")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_PROPAGATE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_PROPAGATE_TITLE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
65 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
66 QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, aMainGrp);
67 aSelGrp->setFrameStyle(QFrame::NoFrame);
68 aSelGrp->setInsideMargin(0);
70 new QLabel(tr("GEOM_OBJECT"), aSelGrp);
71 mySelBtn = new QPushButton(aSelGrp);
72 mySelBtn->setPixmap(image1);
73 mySelName = new QLineEdit(aSelGrp);
74 mySelName->setReadOnly(true);
76 Layout1->addWidget(aMainGrp, 1, 0);
78 /***************************************************************/
80 setHelpFileName("propagate.htm");
85 //=================================================================================
86 // function : ~BlocksGUI_PropagateDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
93 //=================================================================================
96 //=================================================================================
97 void BlocksGUI_PropagateDlg::Init()
101 myObject = GEOM::GEOM_Object::_nil();
102 ResultName->setText( "" );
104 //myGeomGUI->SetState( 0 );
106 /* signals and slots connections */
107 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(mySelName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117 //=================================================================================
118 // function : ClickOnOk()
119 // purpose : Same than click on apply but close this dialog.
120 //=================================================================================
121 void BlocksGUI_PropagateDlg::ClickOnOk()
123 if ( ClickOnApply() )
127 //=================================================================================
128 // function : ClickOnApply()
130 //=================================================================================
131 bool BlocksGUI_PropagateDlg::ClickOnApply()
138 mySelName->setText("");
139 myObject = GEOM::GEOM_Object::_nil();
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose : Called when selection
150 //=================================================================================
151 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
153 mySelName->setText("");
154 myObject = GEOM::GEOM_Object::_nil();
156 if ( IObjectCount() == 1 ) {
157 Handle(SALOME_InteractiveObject) anIO = firstIObject();
158 Standard_Boolean aRes;
159 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
161 mySelName->setText( GEOMBase::GetName( myObject ) );
165 //=================================================================================
166 // function : SetEditCurrentArgument()
168 //=================================================================================
169 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
171 const QObject* send = sender();
172 if ( send == mySelBtn ) {
173 mySelName->setFocus();
179 //=================================================================================
180 // function : LineEditReturnPressed()
182 //=================================================================================
183 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
185 const QObject* send = sender();
186 if( send == mySelName ) {
187 GEOMBase_Skeleton::LineEditReturnPressed();
192 //=================================================================================
193 // function : ActivateThisDialog()
195 //=================================================================================
196 void BlocksGUI_PropagateDlg::ActivateThisDialog()
198 GEOMBase_Skeleton::ActivateThisDialog();
200 mySelName->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* e)
214 if ( !GroupConstructors->isEnabled() )
215 ActivateThisDialog();
219 //=================================================================================
220 // function : closeEvent()
222 //=================================================================================
223 void BlocksGUI_PropagateDlg::closeEvent(QCloseEvent* e)
225 //myGeomGUI->SetState( -1 );
226 GEOMBase_Skeleton::closeEvent( e );
229 //=================================================================================
230 // function : createOperation
232 //=================================================================================
233 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
235 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
238 //=================================================================================
239 // function : isValid
241 //=================================================================================
242 bool BlocksGUI_PropagateDlg::isValid( QString& msg )
244 return !myObject->_is_nil() ;
247 //=================================================================================
248 // function : execute
250 //=================================================================================
251 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
254 GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
255 ResultName->setText( "" );
257 if ( !aList->length() )
260 for ( int i = 0, n = aList->length(); i < n; i++ )
262 objects.push_back(aList[i]._retn());
265 return objects.size() ? true : false;
268 //=================================================================================
269 // function : activateSelection
270 // purpose : Activate selection
271 //=================================================================================
272 void BlocksGUI_PropagateDlg::activateSelection()
274 TColStd_MapOfInteger aMap;
275 aMap.Add( GEOM_SOLID );
276 aMap.Add( GEOM_COMPOUND );
277 globalSelection( aMap );
278 if (myObject->_is_nil()) {
279 SelectionIntoArgument();
281 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
282 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
285 //================================================================
286 // Function : getFather
287 // Purpose : Get father object for object to be added in study
288 // ( called with addInStudy method )
289 //================================================================
290 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather (GEOM::GEOM_Object_ptr)