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