]> SALOME platform Git repositories - modules/geom.git/blob - src/BlocksGUI/BlocksGUI_PropagateDlg.cxx
Salome HOME
*** empty log message ***
[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 // File   : BlocksGUI_PropagateDlg.cxx
23 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
24 //
25
26 #include "BlocksGUI_PropagateDlg.h"
27
28 #include <GEOM_DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31 #include <GEOMImpl_Types.hxx>
32
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37
38 #include <TColStd_MapOfInteger.hxx>
39
40 //=================================================================================
41 // class    : BlocksGUI_PropagateDlg()
42 // purpose  : Constructs a BlocksGUI_PropagateDlg  which is a child of 'parent', with the
43 //            name 'name' and widget flags set to 'f'.
44 //            The dialog will by default be modeless, unless you set 'modal' to
45 //            TRUE to construct a modal dialog.
46 //=================================================================================
47 BlocksGUI_PropagateDlg::BlocksGUI_PropagateDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
48   : GEOMBase_Skeleton( theGeometryGUI, parent )
49 {
50   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PROPAGATE" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52
53   setWindowTitle( tr( "GEOM_PROPAGATE_TITLE" ) );
54
55   /***************************************************************/
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PROPAGATE_TITLE" ) );
57   mainFrame()->RadioButton1->setIcon( image0 );
58   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59   mainFrame()->RadioButton2->close();
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   myGrp = new DlgRef_1Sel( centralWidget() );
64   myGrp->GroupBox1->setTitle( tr( "GEOM_SELECTED_SHAPE" ) );
65   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
66   myGrp->PushButton1->setIcon( image1 );
67   myGrp->LineEdit1->setReadOnly( true );
68
69   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
70   layout->setMargin( 0 ); layout->setSpacing( 6 );
71   layout->addWidget( myGrp );
72
73   /***************************************************************/
74
75   setHelpFileName( "propagate.htm" );
76
77   Init();
78 }
79
80 //=================================================================================
81 // function : ~BlocksGUI_PropagateDlg()
82 // purpose  : Destroys the object and frees any allocated resources
83 //=================================================================================
84 BlocksGUI_PropagateDlg::~BlocksGUI_PropagateDlg()
85 {
86 }
87
88 //=================================================================================
89 // function : Init()
90 // purpose  :
91 //=================================================================================
92 void BlocksGUI_PropagateDlg::Init()
93 {
94   /* init variables */
95
96   myObject = GEOM::GEOM_Object::_nil();
97   mainFrame()->ResultName->setText( "" );
98
99   //myGeomGUI->SetState( 0 );
100
101   /* signals and slots connections */
102   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
103   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
104
105   connect( myGrp->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
106   connect( myGrp->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
107
108   activateSelection();
109 }
110
111
112 //=================================================================================
113 // function : ClickOnOk()
114 // purpose  : Same than click on apply but close this dialog.
115 //=================================================================================
116 void BlocksGUI_PropagateDlg::ClickOnOk()
117 {
118   if ( ClickOnApply() )
119     ClickOnCancel();
120 }
121
122 //=================================================================================
123 // function : ClickOnApply()
124 // purpose  :
125 //=================================================================================
126 bool BlocksGUI_PropagateDlg::ClickOnApply()
127 {
128   if ( !onAccept() )
129     return false;
130
131   initName();
132
133   myGrp->LineEdit1->setText( "" );
134   myObject = GEOM::GEOM_Object::_nil();
135
136   activateSelection();
137
138   return true;
139 }
140
141
142 //=================================================================================
143 // function : SelectionIntoArgument()
144 // purpose  : Called when selection
145 //=================================================================================
146 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
147 {
148   myGrp->LineEdit1->setText( "" );
149   myObject = GEOM::GEOM_Object::_nil();
150
151   if ( IObjectCount() == 1 ) {
152     Handle(SALOME_InteractiveObject) anIO = firstIObject();
153     Standard_Boolean aRes;
154     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
155     if ( aRes )
156       myGrp->LineEdit1->setText( GEOMBase::GetName( myObject ) );
157   }
158 }
159
160 //=================================================================================
161 // function : SetEditCurrentArgument()
162 // purpose  :
163 //=================================================================================
164 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
165 {
166   const QObject* send = sender();
167   if ( send == myGrp->PushButton1 )  {
168     myGrp->LineEdit1->setFocus();
169   }
170   activateSelection();
171 }
172
173
174 //=================================================================================
175 // function : LineEditReturnPressed()
176 // purpose  :
177 //=================================================================================
178 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
179 {
180   const QObject* send = sender();
181   if ( send == myGrp->LineEdit1 ) {
182     GEOMBase_Skeleton::LineEditReturnPressed();
183   }
184 }
185
186
187 //=================================================================================
188 // function : ActivateThisDialog()
189 // purpose  :
190 //=================================================================================
191 void BlocksGUI_PropagateDlg::ActivateThisDialog()
192 {
193   GEOMBase_Skeleton::ActivateThisDialog();
194
195   myGrp->LineEdit1->setText( "" );
196   myObject = GEOM::GEOM_Object::_nil();
197
198   //myGeomGUI->SetState( 0 );
199   activateSelection();
200 }
201
202
203 //=================================================================================
204 // function : enterEvent()
205 // purpose  : Mouse enter onto the dialog to activate it
206 //=================================================================================
207 void BlocksGUI_PropagateDlg::enterEvent( QEvent* )
208 {
209   if ( !mainFrame()->GroupConstructors->isEnabled() )
210     ActivateThisDialog();
211 }
212
213
214 //=================================================================================
215 // function : closeEvent()
216 // purpose  :
217 //=================================================================================
218 void BlocksGUI_PropagateDlg::closeEvent( QCloseEvent* e )
219 {
220   //myGeomGUI->SetState( -1 );
221   GEOMBase_Skeleton::closeEvent( e );
222 }
223
224 //=================================================================================
225 // function : createOperation
226 // purpose  :
227 //=================================================================================
228 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
229 {
230   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
231 }
232
233 //=================================================================================
234 // function : isValid
235 // purpose  :
236 //=================================================================================
237 bool BlocksGUI_PropagateDlg::isValid( QString& )
238 {
239   return !myObject->_is_nil() ;
240 }
241
242 //=================================================================================
243 // function : execute
244 // purpose  :
245 //=================================================================================
246 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
247 {
248   GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
249   mainFrame()->ResultName->setText( "" );
250
251   if ( !aList->length() )
252     return false;
253
254   for ( int i = 0, n = aList->length(); i < n; i++ ) {
255     objects.push_back( aList[i]._retn() );
256   }
257
258   return objects.size() > 0;
259 }
260
261 //=================================================================================
262 // function : activateSelection
263 // purpose  : Activate selection
264 //=================================================================================
265 void BlocksGUI_PropagateDlg::activateSelection()
266 {
267   TColStd_MapOfInteger aMap;
268   aMap.Add( GEOM_SOLID );
269   aMap.Add( GEOM_COMPOUND );
270   globalSelection( aMap );
271   if ( myObject->_is_nil() ) {
272     SelectionIntoArgument();
273   }
274   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
275            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
276 }
277
278 //================================================================
279 // Function : getFather
280 // Purpose  : Get father object for object to be added in study
281 //            ( called with addInStudy method )
282 //================================================================
283 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather( GEOM::GEOM_Object_ptr )
284 {
285   return myObject;
286 }