Salome HOME
Porting to Qt4.
[modules/geom.git] / src / BuildGUI / BuildGUI_CompoundDlg.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 //
23 //
24 //  File   : BuildGUI_CompoundDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BuildGUI_CompoundDlg.h"
30 #include "GEOMImpl_Types.hxx"
31
32 #include "GeometryGUI.h"
33 #include "GEOMBase.h"
34
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Session.h"
37 #include "SalomeApp_Application.h"
38 #include "LightApp_SelectionMgr.h"
39
40 //=================================================================================
41 // class    : BuildGUI_CompoundDlg()
42 // purpose  : Constructs a BuildGUI_CompoundDlg 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 BuildGUI_CompoundDlg::BuildGUI_CompoundDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
48                                            const char* name, bool modal, Qt::WindowFlags fl)
49   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
50 {
51   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_COMPOUND")));
52   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
53
54   setWindowTitle(tr("GEOM_COMPOUND_TITLE"));
55
56   /***************************************************************/
57   GroupConstructors->setTitle(tr("GEOM_COMPOUND"));
58   RadioButton1->setIcon(image0);
59   RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60   RadioButton2->close();
61   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62   RadioButton3->close();
63
64   GroupShapes = new Ui::DlgRef_1Sel_QTD();
65   QWidget* aGroupShapesWidget = new QWidget(this);
66   GroupShapes->setupUi(aGroupShapesWidget);
67   aGroupShapesWidget->setObjectName("GroupShapes");
68
69   GroupShapes->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70   GroupShapes->TextLabel1->setText(tr("GEOM_OBJECTS"));
71   GroupShapes->PushButton1->setIcon(image1);
72   GroupShapes->LineEdit1->setReadOnly( true );
73
74   gridLayout1->addWidget(aGroupShapesWidget, 2, 0);
75   /***************************************************************/
76
77   setHelpFileName("compound.htm");
78
79   /* Initialisations */
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~BuildGUI_CompoundDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BuildGUI_CompoundDlg::~BuildGUI_CompoundDlg()
89 {
90   // no need to delete child widgets, Qt does it all for us
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void BuildGUI_CompoundDlg::Init()
99 {
100   /* init variables */
101   myEditCurrentArgument = GroupShapes->LineEdit1;
102   GroupShapes->LineEdit1->setReadOnly( true );
103   
104   myOkShapes = false;
105
106   /* signals and slots connections */
107   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
109   connect(GroupShapes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));  
110   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
111           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
112
113   globalSelection( GEOM_ALLSHAPES );
114
115   initName( tr( "GEOM_COMPOUND" ).toLatin1().constData() );
116 }
117
118
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose  :
122 //=================================================================================
123 void BuildGUI_CompoundDlg::ClickOnOk()
124 {
125   if ( ClickOnApply() )
126     ClickOnCancel();
127 }
128
129
130 //=================================================================================
131 // function : ClickOnApply()
132 // purpose  :
133 //=================================================================================
134 bool BuildGUI_CompoundDlg::ClickOnApply()
135 {
136   if ( !onAccept() )
137     return false;
138
139   initName();
140   return true;
141 }
142
143
144 //=================================================================================
145 // function : SelectionIntoArgument()
146 // purpose  : Called when selection as changed or other case
147 //=================================================================================
148 void BuildGUI_CompoundDlg::SelectionIntoArgument()
149 {
150   myEditCurrentArgument->setText( "" );
151   QString aString = ""; /* name of selection */
152
153   myOkShapes = false;
154   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
155   if ( nbSel == 0 ) 
156     return;
157   if ( nbSel != 1 )
158     aString = QString( "%1_objects").arg( nbSel );
159   
160   GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myShapes, true );
161   myEditCurrentArgument->setText( aString );
162   myOkShapes = true;
163 }
164
165
166 //=================================================================================
167 // function : SetEditCurrentArgument()
168 // purpose  :
169 //=================================================================================
170 void BuildGUI_CompoundDlg::SetEditCurrentArgument()
171 {
172   QPushButton* send = (QPushButton*)sender();
173   if (send != GroupShapes->PushButton1)
174     return;
175   
176   myEditCurrentArgument = GroupShapes->LineEdit1;
177   
178   myEditCurrentArgument->setFocus();
179   SelectionIntoArgument();
180 }
181
182
183 //=================================================================================
184 // function : ActivateThisDialog()
185 // purpose  :
186 //=================================================================================
187 void BuildGUI_CompoundDlg::ActivateThisDialog()
188 {
189   GEOMBase_Skeleton::ActivateThisDialog();
190   globalSelection( GEOM_ALLSHAPES );
191   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
192           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
193 }
194
195
196 //=================================================================================
197 // function : enterEvent()
198 // purpose  :
199 //=================================================================================
200 void BuildGUI_CompoundDlg::enterEvent(QEvent* e)
201 {
202   if ( !GroupConstructors->isEnabled() )
203     ActivateThisDialog(); 
204 }
205
206 //=================================================================================
207 // function : createOperation
208 // purpose  :
209 //=================================================================================
210 GEOM::GEOM_IOperations_ptr BuildGUI_CompoundDlg::createOperation()
211 {
212   return getGeomEngine()->GetIShapesOperations( getStudyId() );
213 }
214
215 //=================================================================================
216 // function : isValid
217 // purpose  :
218 //=================================================================================
219 bool BuildGUI_CompoundDlg::isValid( QString& )
220 {
221   return myOkShapes;
222 }
223
224 //=================================================================================
225 // function : execute
226 // purpose  :
227 //=================================================================================
228 bool BuildGUI_CompoundDlg::execute( ObjectList& objects )
229 {
230   GEOM::GEOM_Object_var anObj;
231
232   anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeCompound( myShapes );
233
234   if ( !anObj->_is_nil() )
235     objects.push_back( anObj._retn() );
236
237   return true;
238 }