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