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