Salome HOME
df8814144f69bb308f922d74374e33227528b4a3
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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 "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
35
36 #include <qlabel.h>
37
38 //=================================================================================
39 // class    : BuildGUI_CompoundDlg()
40 // purpose  : Constructs a BuildGUI_CompoundDlg which is a child of 'parent', with the 
41 //            name 'name' and widget flags set to 'f'.
42 //            The dialog will by default be modeless, unless you set 'modal' to
43 //            TRUE to construct a modal dialog.
44 //=================================================================================
45 BuildGUI_CompoundDlg::BuildGUI_CompoundDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
46   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 {
48   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_COMPOUND")));
49   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
50
51   setCaption(tr("GEOM_COMPOUND_TITLE"));
52
53   /***************************************************************/
54   GroupConstructors->setTitle(tr("GEOM_COMPOUND"));
55   RadioButton1->setPixmap(image0);
56   RadioButton2->close(TRUE);
57   RadioButton3->close(TRUE);
58
59   GroupShapes = new DlgRef_1Sel_QTD(this, "GroupShapes");
60   GroupShapes->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
61   GroupShapes->TextLabel1->setText(tr("GEOM_OBJECTS"));
62   GroupShapes->PushButton1->setPixmap(image1);
63   GroupShapes->LineEdit1->setReadOnly( true );
64
65   Layout1->addWidget(GroupShapes, 2, 0);
66   /***************************************************************/
67
68   /* Initialisations */
69   Init();
70 }
71
72
73 //=================================================================================
74 // function : ~BuildGUI_CompoundDlg()
75 // purpose  : Destroys the object and frees any allocated resources
76 //=================================================================================
77 BuildGUI_CompoundDlg::~BuildGUI_CompoundDlg()
78 {
79   // no need to delete child widgets, Qt does it all for us
80 }
81
82
83 //=================================================================================
84 // function : Init()
85 // purpose  :
86 //=================================================================================
87 void BuildGUI_CompoundDlg::Init()
88 {
89   /* init variables */
90   myEditCurrentArgument = GroupShapes->LineEdit1;
91   GroupShapes->LineEdit1->setReadOnly( true );
92   
93   myOkShapes = false;
94
95   /* signals and slots connections */
96   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
97   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
98   connect(GroupShapes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));  
99   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
100           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
101
102   globalSelection( GEOM_ALLSHAPES );
103
104   initName( tr( "GEOM_COMPOUND" ) );
105 }
106
107
108 //=================================================================================
109 // function : ClickOnOk()
110 // purpose  :
111 //=================================================================================
112 void BuildGUI_CompoundDlg::ClickOnOk()
113 {
114   if ( ClickOnApply() )
115     ClickOnCancel();
116 }
117
118
119 //=================================================================================
120 // function : ClickOnApply()
121 // purpose  :
122 //=================================================================================
123 bool BuildGUI_CompoundDlg::ClickOnApply()
124 {
125   if ( !onAccept() )
126     return false;
127
128   initName();
129   return true;
130 }
131
132
133 //=================================================================================
134 // function : SelectionIntoArgument()
135 // purpose  : Called when selection as changed or other case
136 //=================================================================================
137 void BuildGUI_CompoundDlg::SelectionIntoArgument()
138 {
139   myEditCurrentArgument->setText( "" );
140   QString aString = ""; /* name of selection */
141
142   myOkShapes = false;
143   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
144   if ( nbSel == 0 ) 
145     return;
146   if ( nbSel != 1 )
147     aString = QString( "%1_objects").arg( nbSel );
148   
149   GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myShapes, true );
150   myEditCurrentArgument->setText( aString );
151   myOkShapes = true;
152 }
153
154
155 //=================================================================================
156 // function : SetEditCurrentArgument()
157 // purpose  :
158 //=================================================================================
159 void BuildGUI_CompoundDlg::SetEditCurrentArgument()
160 {
161   QPushButton* send = (QPushButton*)sender();
162   if (send != GroupShapes->PushButton1)
163     return;
164   
165   myEditCurrentArgument = GroupShapes->LineEdit1;
166   
167   myEditCurrentArgument->setFocus();
168   SelectionIntoArgument();
169 }
170
171
172 //=================================================================================
173 // function : ActivateThisDialog()
174 // purpose  :
175 //=================================================================================
176 void BuildGUI_CompoundDlg::ActivateThisDialog()
177 {
178   GEOMBase_Skeleton::ActivateThisDialog();
179   globalSelection( GEOM_ALLSHAPES );
180   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
181           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
182 }
183
184
185 //=================================================================================
186 // function : enterEvent()
187 // purpose  :
188 //=================================================================================
189 void BuildGUI_CompoundDlg::enterEvent(QEvent* e)
190 {
191   if ( !GroupConstructors->isEnabled() )
192     ActivateThisDialog(); 
193 }
194
195 //=================================================================================
196 // function : createOperation
197 // purpose  :
198 //=================================================================================
199 GEOM::GEOM_IOperations_ptr BuildGUI_CompoundDlg::createOperation()
200 {
201   return getGeomEngine()->GetIShapesOperations( getStudyId() );
202 }
203
204 //=================================================================================
205 // function : isValid
206 // purpose  :
207 //=================================================================================
208 bool BuildGUI_CompoundDlg::isValid( QString& )
209 {
210   return myOkShapes;
211 }
212
213 //=================================================================================
214 // function : execute
215 // purpose  :
216 //=================================================================================
217 bool BuildGUI_CompoundDlg::execute( ObjectList& objects )
218 {
219   GEOM::GEOM_Object_var anObj;
220
221   anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeCompound( myShapes );
222
223   if ( !anObj->_is_nil() )
224     objects.push_back( anObj._retn() );
225
226   return true;
227 }