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