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