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 GEOMGUI : GUI for Geometry component
23 // File : BlocksGUI_PropagateDlg.cxx
28 #include "BlocksGUI_PropagateDlg.h"
29 #include "GEOMImpl_Types.hxx"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #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 const char* name, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
51 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PROPAGATE")));
54 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_PROPAGATE_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_PROPAGATE_TITLE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
65 QGroupBox* aSelGrp = new QGroupBox(3, Qt::Horizontal, aMainGrp);
66 aSelGrp->setFrameStyle(QFrame::NoFrame);
67 aSelGrp->setInsideMargin(0);
69 new QLabel(tr("GEOM_OBJECT"), aSelGrp);
70 mySelBtn = new QPushButton(aSelGrp);
71 mySelBtn->setPixmap(image1);
72 mySelName = new QLineEdit(aSelGrp);
73 mySelName->setReadOnly(true);
75 Layout1->addWidget(aMainGrp, 1, 0);
77 /***************************************************************/
79 setHelpFileName("propagate_operation_page.html");
84 //=================================================================================
85 // function : ~BlocksGUI_PropagateDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
92 //=================================================================================
95 //=================================================================================
96 void BlocksGUI_PropagateDlg::Init()
100 myObject = GEOM::GEOM_Object::_nil();
101 ResultName->setText( "" );
103 //myGeomGUI->SetState( 0 );
105 /* signals and slots connections */
106 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
109 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110 connect(mySelName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
116 //=================================================================================
117 // function : ClickOnOk()
118 // purpose : Same than click on apply but close this dialog.
119 //=================================================================================
120 void BlocksGUI_PropagateDlg::ClickOnOk()
122 if ( ClickOnApply() )
126 //=================================================================================
127 // function : ClickOnApply()
129 //=================================================================================
130 bool BlocksGUI_PropagateDlg::ClickOnApply()
137 mySelName->setText("");
138 myObject = GEOM::GEOM_Object::_nil();
146 //=================================================================================
147 // function : SelectionIntoArgument()
148 // purpose : Called when selection
149 //=================================================================================
150 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
152 mySelName->setText("");
153 myObject = GEOM::GEOM_Object::_nil();
155 if ( IObjectCount() == 1 ) {
156 Handle(SALOME_InteractiveObject) anIO = firstIObject();
157 Standard_Boolean aRes;
158 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
160 mySelName->setText( GEOMBase::GetName( myObject ) );
164 //=================================================================================
165 // function : SetEditCurrentArgument()
167 //=================================================================================
168 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
170 const QObject* send = sender();
171 if ( send == mySelBtn ) {
172 mySelName->setFocus();
178 //=================================================================================
179 // function : LineEditReturnPressed()
181 //=================================================================================
182 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
184 const QObject* send = sender();
185 if( send == mySelName ) {
186 GEOMBase_Skeleton::LineEditReturnPressed();
191 //=================================================================================
192 // function : ActivateThisDialog()
194 //=================================================================================
195 void BlocksGUI_PropagateDlg::ActivateThisDialog()
197 GEOMBase_Skeleton::ActivateThisDialog();
199 mySelName->setText("");
200 myObject = GEOM::GEOM_Object::_nil();
202 //myGeomGUI->SetState( 0 );
207 //=================================================================================
208 // function : enterEvent()
209 // purpose : Mouse enter onto the dialog to activate it
210 //=================================================================================
211 void BlocksGUI_PropagateDlg::enterEvent(QEvent* e)
213 if ( !GroupConstructors->isEnabled() )
214 ActivateThisDialog();
218 //=================================================================================
219 // function : closeEvent()
221 //=================================================================================
222 void BlocksGUI_PropagateDlg::closeEvent(QCloseEvent* e)
224 //myGeomGUI->SetState( -1 );
225 GEOMBase_Skeleton::closeEvent( e );
228 //=================================================================================
229 // function : createOperation
231 //=================================================================================
232 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
234 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
237 //=================================================================================
238 // function : isValid
240 //=================================================================================
241 bool BlocksGUI_PropagateDlg::isValid( QString& msg )
243 return !myObject->_is_nil() ;
246 //=================================================================================
247 // function : execute
249 //=================================================================================
250 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
253 GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
254 ResultName->setText( "" );
256 if ( !aList->length() )
259 for ( int i = 0, n = aList->length(); i < n; i++ )
261 objects.push_back(aList[i]._retn());
264 return objects.size() ? true : false;
267 //=================================================================================
268 // function : activateSelection
269 // purpose : Activate selection
270 //=================================================================================
271 void BlocksGUI_PropagateDlg::activateSelection()
273 TColStd_MapOfInteger aMap;
274 aMap.Add( GEOM_SOLID );
275 aMap.Add( GEOM_COMPOUND );
276 globalSelection( aMap );
277 if (myObject->_is_nil()) {
278 SelectionIntoArgument();
280 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
281 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
284 //================================================================
285 // Function : getFather
286 // Purpose : Get father object for object to be added in study
287 // ( called with addInStudy method )
288 //================================================================
289 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather (GEOM::GEOM_Object_ptr)