Salome HOME
228089eee0183542abef088b311583e5c9278e57
[modules/geom.git] / src / BlocksGUI / BlocksGUI_PropagateDlg.cxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : BlocksGUI_PropagateDlg.cxx
25 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
26 //
27 #include "BlocksGUI_PropagateDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32 #include <GEOMImpl_Types.hxx>
33
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 #include <TColStd_MapOfInteger.hxx>
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   : GEOMBase_Skeleton( theGeometryGUI, parent )
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   setWindowTitle( tr( "GEOM_PROPAGATE_TITLE" ) );
55
56   /***************************************************************/
57   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PROPAGATE_TITLE" ) );
58   mainFrame()->RadioButton1->setIcon( image0 );
59   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60   mainFrame()->RadioButton2->close();
61   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62   mainFrame()->RadioButton3->close();
63
64   myGrp = new DlgRef_1Sel( centralWidget() );
65   myGrp->GroupBox1->setTitle( tr( "GEOM_SELECTED_SHAPE" ) );
66   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
67   myGrp->PushButton1->setIcon( image1 );
68   myGrp->LineEdit1->setReadOnly( true );
69
70   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71   layout->setMargin( 0 ); layout->setSpacing( 6 );
72   layout->addWidget( myGrp );
73
74   /***************************************************************/
75
76   setHelpFileName( "propagate_operation_page.html" );
77
78   Init();
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 // function : Init()
91 // purpose  :
92 //=================================================================================
93 void BlocksGUI_PropagateDlg::Init()
94 {
95   /* init variables */
96
97   myObject = GEOM::GEOM_Object::_nil();
98   mainFrame()->ResultName->setText( "" );
99   mainFrame()->GroupBoxName->hide();
100
101   //myGeomGUI->SetState( 0 );
102
103   /* signals and slots connections */
104   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
105   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
106
107   connect( myGrp->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
108   connect( myGrp->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
109
110   activateSelection();
111 }
112
113
114 //=================================================================================
115 // function : ClickOnOk()
116 // purpose  : Same than click on apply but close this dialog.
117 //=================================================================================
118 void BlocksGUI_PropagateDlg::ClickOnOk()
119 {
120   setIsApplyAndClose( true );
121   if ( ClickOnApply() )
122     ClickOnCancel();
123 }
124
125 //=================================================================================
126 // function : ClickOnApply()
127 // purpose  :
128 //=================================================================================
129 bool BlocksGUI_PropagateDlg::ClickOnApply()
130 {
131   if ( !onAccept() )
132     return false;
133
134   initName();
135
136   myGrp->LineEdit1->setText( "" );
137   myObject = GEOM::GEOM_Object::_nil();
138
139   activateSelection();
140
141   return true;
142 }
143
144
145 //=================================================================================
146 // function : SelectionIntoArgument()
147 // purpose  : Called when selection
148 //=================================================================================
149 void BlocksGUI_PropagateDlg::SelectionIntoArgument()
150 {
151   myGrp->LineEdit1->setText( "" );
152   myObject = GEOM::GEOM_Object::_nil();
153
154   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
155   SALOME_ListIO aSelList;
156   aSelMgr->selectedObjects(aSelList);
157
158   if (aSelList.Extent() == 1) {
159     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
160     myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
161     if ( !CORBA::is_nil( myObject ) )
162       myGrp->LineEdit1->setText( GEOMBase::GetName( myObject ) );
163   }
164 }
165
166 //=================================================================================
167 // function : SetEditCurrentArgument()
168 // purpose  :
169 //=================================================================================
170 void BlocksGUI_PropagateDlg::SetEditCurrentArgument()
171 {
172   const QObject* send = sender();
173   if ( send == myGrp->PushButton1 )  {
174     myGrp->LineEdit1->setFocus();
175   }
176   activateSelection();
177 }
178
179
180 //=================================================================================
181 // function : LineEditReturnPressed()
182 // purpose  :
183 //=================================================================================
184 void BlocksGUI_PropagateDlg::LineEditReturnPressed()
185 {
186   const QObject* send = sender();
187   if ( send == myGrp->LineEdit1 ) {
188     GEOMBase_Skeleton::LineEditReturnPressed();
189   }
190 }
191
192
193 //=================================================================================
194 // function : ActivateThisDialog()
195 // purpose  :
196 //=================================================================================
197 void BlocksGUI_PropagateDlg::ActivateThisDialog()
198 {
199   GEOMBase_Skeleton::ActivateThisDialog();
200
201   myGrp->LineEdit1->setText( "" );
202   myObject = GEOM::GEOM_Object::_nil();
203
204   //myGeomGUI->SetState( 0 );
205   activateSelection();
206 }
207
208
209 //=================================================================================
210 // function : enterEvent()
211 // purpose  : Mouse enter onto the dialog to activate it
212 //=================================================================================
213 void BlocksGUI_PropagateDlg::enterEvent( QEvent* )
214 {
215   if ( !mainFrame()->GroupConstructors->isEnabled() )
216     ActivateThisDialog();
217 }
218
219 //=================================================================================
220 // function : createOperation
221 // purpose  :
222 //=================================================================================
223 GEOM::GEOM_IOperations_ptr BlocksGUI_PropagateDlg::createOperation()
224 {
225   return getGeomEngine()->GetIBlocksOperations();
226 }
227
228 //=================================================================================
229 // function : isValid
230 // purpose  :
231 //=================================================================================
232 bool BlocksGUI_PropagateDlg::isValid( QString& )
233 {
234   return !myObject->_is_nil() ;
235 }
236
237 //=================================================================================
238 // function : execute
239 // purpose  :
240 //=================================================================================
241 bool BlocksGUI_PropagateDlg::execute( ObjectList& objects )
242 {
243   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
244   GEOM::ListOfGO_var aList = anOper->Propagate( myObject );
245   mainFrame()->ResultName->setText( "" );
246
247   if ( !aList->length() )
248     return false;
249
250   for ( int i = 0, n = aList->length(); i < n; i++ ) {
251     objects.push_back( aList[i]._retn() );
252   }
253
254   return objects.size() > 0;
255 }
256
257 //=================================================================================
258 // function : activateSelection
259 // purpose  : Activate selection
260 //=================================================================================
261 void BlocksGUI_PropagateDlg::activateSelection()
262 {
263   TColStd_MapOfInteger aMap;
264   aMap.Add( GEOM_FACE );
265   aMap.Add( GEOM_SHELL );
266   aMap.Add( GEOM_SOLID );
267   aMap.Add( GEOM_COMPOUND );
268   globalSelection( aMap );
269   if ( myObject->_is_nil() ) {
270     SelectionIntoArgument();
271   }
272   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
273            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
274 }
275
276 //================================================================
277 // Function : getFather
278 // Purpose  : Get father object for object to be added in study
279 //            ( called with addInStudy method )
280 //================================================================
281 GEOM::GEOM_Object_ptr BlocksGUI_PropagateDlg::getFather( GEOM::GEOM_Object_ptr )
282 {
283   return myObject;
284 }
285
286 //=================================================================================
287 // function : getSourceObjects
288 // purpose  : virtual method to get source objects
289 //=================================================================================
290 QList<GEOM::GeomObjPtr> BlocksGUI_PropagateDlg::getSourceObjects()
291 {
292   QList<GEOM::GeomObjPtr> res;
293   GEOM::GeomObjPtr aGeomObjPtr(myObject);
294   res << aGeomObjPtr;
295   return res;
296 }