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