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