Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/geom.git] / src / BlocksGUI / BlocksGUI_PropagateDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : BlocksGUI_PropagateDlg.cxx
25 //  Author : VKN
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BlocksGUI_PropagateDlg.h"
30 #include "GEOMImpl_Types.hxx"
31
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include <TColStd_MapOfInteger.hxx>
37
38 #include <qlabel.h>
39
40 using namespace std;
41
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)
53 {
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")));
56
57   setCaption(tr("GEOM_PROPAGATE_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_PROPAGATE_TITLE"));
61   RadioButton1->setPixmap(image0);
62   RadioButton2->close(TRUE);
63   RadioButton3->close(TRUE);
64
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);
69
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);
75
76   Layout1->addWidget(aMainGrp, 1, 0);
77
78   /***************************************************************/
79
80   setHelpFileName("propagate.htm");
81
82   Init();
83 }
84
85 //=================================================================================
86 // function : ~BlocksGUI_PropagateDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
90 {
91 }
92
93 //=================================================================================
94 // function : Init()
95 // purpose  :
96 //=================================================================================
97 void BlocksGUI_PropagateDlg::Init()
98 {
99   /* init variables */
100
101   myObject = GEOM::GEOM_Object::_nil();
102   ResultName->setText( "" );
103
104   //myGeomGUI->SetState( 0 );
105
106   /* signals and slots connections */
107   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
109
110   connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111   connect(mySelName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112
113   activateSelection();
114 }
115
116
117 //=================================================================================
118 // function : ClickOnOk()
119 // purpose  : Same than click on apply but close this dialog.
120 //=================================================================================
121 void BlocksGUI_PropagateDlg::ClickOnOk()
122 {
123   if ( ClickOnApply() )
124     ClickOnCancel();
125 }
126
127 //=================================================================================
128 // function : ClickOnApply()
129 // purpose  :
130 //=================================================================================
131 bool BlocksGUI_PropagateDlg::ClickOnApply()
132 {
133   if ( !onAccept() )
134     return false;
135
136   initName();
137
138   mySelName->setText("");
139   myObject = GEOM::GEOM_Object::_nil();
140
141   activateSelection();
142
143   return true;
144 }
145
146
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose  : Called when selection
150 //=================================================================================
151 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
152 {
153   mySelName->setText("");
154   myObject = GEOM::GEOM_Object::_nil();
155
156   if ( IObjectCount() == 1 ) {
157     Handle(SALOME_InteractiveObject) anIO = firstIObject();
158     Standard_Boolean aRes;
159     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
160     if ( aRes )
161       mySelName->setText( GEOMBase::GetName( myObject ) );
162   }
163 }
164
165 //=================================================================================
166 // function : SetEditCurrentArgument()
167 // purpose  :
168 //=================================================================================
169 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
170 {
171   const QObject* send = sender();
172   if ( send == mySelBtn )  {
173     mySelName->setFocus();
174   }
175   activateSelection();
176 }
177
178
179 //=================================================================================
180 // function : LineEditReturnPressed()
181 // purpose  :
182 //=================================================================================
183 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
184 {
185   const QObject* send = sender();
186   if( send == mySelName ) {
187     GEOMBase_Skeleton::LineEditReturnPressed();
188   }
189 }
190
191
192 //=================================================================================
193 // function : ActivateThisDialog()
194 // purpose  :
195 //=================================================================================
196 void BlocksGUI_PropagateDlg::ActivateThisDialog()
197 {
198   GEOMBase_Skeleton::ActivateThisDialog();
199
200   mySelName->setText("");
201   myObject = GEOM::GEOM_Object::_nil();
202
203   //myGeomGUI->SetState( 0 );
204   activateSelection();
205 }
206
207
208 //=================================================================================
209 // function : enterEvent()
210 // purpose  : Mouse enter onto the dialog to activate it
211 //=================================================================================
212 void BlocksGUI_PropagateDlg::enterEvent(QEvent* e)
213 {
214   if ( !GroupConstructors->isEnabled() )
215     ActivateThisDialog();
216 }
217
218
219 //=================================================================================
220 // function : closeEvent()
221 // purpose  :
222 //=================================================================================
223 void BlocksGUI_PropagateDlg::closeEvent(QCloseEvent* e)
224 {
225   //myGeomGUI->SetState( -1 );
226   GEOMBase_Skeleton::closeEvent( e );
227 }
228
229 //=================================================================================
230 // function : createOperation
231 // purpose  :
232 //=================================================================================
233 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
234 {
235   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
236 }
237
238 //=================================================================================
239 // function : isValid
240 // purpose  :
241 //=================================================================================
242 bool BlocksGUI_PropagateDlg::isValid( QString& msg )
243 {
244   return !myObject->_is_nil() ;
245 }
246
247 //=================================================================================
248 // function : execute
249 // purpose  :
250 //=================================================================================
251 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
252 {
253
254   GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
255   ResultName->setText( "" );
256
257   if ( !aList->length() )
258     return false;
259
260   for ( int i = 0, n = aList->length(); i < n; i++ )
261   {
262     objects.push_back(aList[i]._retn());
263   }
264
265   return objects.size() ? true : false;
266 }
267
268 //=================================================================================
269 // function : activateSelection
270 // purpose  : Activate selection
271 //=================================================================================
272 void BlocksGUI_PropagateDlg::activateSelection()
273 {
274   TColStd_MapOfInteger aMap;
275   aMap.Add( GEOM_SOLID );
276   aMap.Add( GEOM_COMPOUND );
277   globalSelection( aMap );
278   if (myObject->_is_nil()) {
279     SelectionIntoArgument();
280   }
281   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
282           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
283 }
284
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)
291 {
292   return myObject;
293 }