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