Salome HOME
Portability windows
[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 : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
25 //
26 #include "BlocksGUI_PropagateDlg.h"
27
28 #include <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_operation_page.html" );
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   mainFrame()->GroupBoxName->hide();
99
100   //myGeomGUI->SetState( 0 );
101
102   /* signals and slots connections */
103   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
104   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
105
106   connect( myGrp->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
107   connect( myGrp->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
108
109   activateSelection();
110 }
111
112
113 //=================================================================================
114 // function : ClickOnOk()
115 // purpose  : Same than click on apply but close this dialog.
116 //=================================================================================
117 void BlocksGUI_PropagateDlg::ClickOnOk()
118 {
119   if ( ClickOnApply() )
120     ClickOnCancel();
121 }
122
123 //=================================================================================
124 // function : ClickOnApply()
125 // purpose  :
126 //=================================================================================
127 bool BlocksGUI_PropagateDlg::ClickOnApply()
128 {
129   if ( !onAccept() )
130     return false;
131
132   initName();
133
134   myGrp->LineEdit1->setText( "" );
135   myObject = GEOM::GEOM_Object::_nil();
136
137   activateSelection();
138
139   return true;
140 }
141
142
143 //=================================================================================
144 // function : SelectionIntoArgument()
145 // purpose  : Called when selection
146 //=================================================================================
147 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
148 {
149   myGrp->LineEdit1->setText( "" );
150   myObject = GEOM::GEOM_Object::_nil();
151
152   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
153   SALOME_ListIO aSelList;
154   aSelMgr->selectedObjects(aSelList);
155
156   if (aSelList.Extent() == 1) {
157     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
158     Standard_Boolean aRes;
159     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
160     if ( aRes )
161       myGrp->LineEdit1->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 == myGrp->PushButton1 )  {
173     myGrp->LineEdit1->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 == myGrp->LineEdit1 ) {
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   myGrp->LineEdit1->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* )
213 {
214   if ( !mainFrame()->GroupConstructors->isEnabled() )
215     ActivateThisDialog();
216 }
217
218 //=================================================================================
219 // function : createOperation
220 // purpose  :
221 //=================================================================================
222 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
223 {
224   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
225 }
226
227 //=================================================================================
228 // function : isValid
229 // purpose  :
230 //=================================================================================
231 bool BlocksGUI_PropagateDlg::isValid( QString& )
232 {
233   return !myObject->_is_nil() ;
234 }
235
236 //=================================================================================
237 // function : execute
238 // purpose  :
239 //=================================================================================
240 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
241 {
242   GEOM::ListOfGO_var aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->Propagate( myObject );
243   mainFrame()->ResultName->setText( "" );
244
245   if ( !aList->length() )
246     return false;
247
248   for ( int i = 0, n = aList->length(); i < n; i++ ) {
249     objects.push_back( aList[i]._retn() );
250   }
251
252   return objects.size() > 0;
253 }
254
255 //=================================================================================
256 // function : activateSelection
257 // purpose  : Activate selection
258 //=================================================================================
259 void BlocksGUI_PropagateDlg::activateSelection()
260 {
261   TColStd_MapOfInteger aMap;
262   aMap.Add( GEOM_SOLID );
263   aMap.Add( GEOM_COMPOUND );
264   globalSelection( aMap );
265   if ( myObject->_is_nil() ) {
266     SelectionIntoArgument();
267   }
268   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
269            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
270 }
271
272 //================================================================
273 // Function : getFather
274 // Purpose  : Get father object for object to be added in study
275 //            ( called with addInStudy method )
276 //================================================================
277 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather( GEOM::GEOM_Object_ptr )
278 {
279   return myObject;
280 }