1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BuildGUI_CompoundDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BuildGUI_CompoundDlg.h"
30 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
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 )
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" ) ) );
53 setWindowTitle( tr( "GEOM_COMPOUND_TITLE" ) );
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();
63 GroupShapes = new DlgRef_1Sel( centralWidget() );
65 GroupShapes->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 GroupShapes->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
67 GroupShapes->PushButton1->setIcon( image1 );
68 GroupShapes->LineEdit1->setReadOnly( true );
70 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71 layout->setMargin( 0 ); layout->setSpacing( 6 );
72 layout->addWidget( GroupShapes );
73 /***************************************************************/
75 setHelpFileName("create_compound_page.html");
82 //=================================================================================
83 // function : ~BuildGUI_CompoundDlg()
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BuildGUI_CompoundDlg::~BuildGUI_CompoundDlg()
88 // no need to delete child widgets, Qt does it all for us
92 //=================================================================================
95 //=================================================================================
96 void BuildGUI_CompoundDlg::Init()
99 myEditCurrentArgument = GroupShapes->LineEdit1;
100 GroupShapes->LineEdit1->setReadOnly( true );
104 mainFrame()->GroupBoxPublish->show();
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() ) );
113 globalSelection( GEOM_ALLSHAPES );
115 initName( tr( "GEOM_COMPOUND" ) );
119 //=================================================================================
120 // function : ClickOnOk()
122 //=================================================================================
123 void BuildGUI_CompoundDlg::ClickOnOk()
125 if ( ClickOnApply() )
130 //=================================================================================
131 // function : ClickOnApply()
133 //=================================================================================
134 bool BuildGUI_CompoundDlg::ClickOnApply()
144 //=================================================================================
145 // function : SelectionIntoArgument()
146 // purpose : Called when selection as changed or other case
147 //=================================================================================
148 void BuildGUI_CompoundDlg::SelectionIntoArgument()
150 myEditCurrentArgument->setText( "" );
151 QString aString = ""; /* name of selection */
153 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
154 SALOME_ListIO aSelList;
155 aSelMgr->selectedObjects(aSelList);
158 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
162 aString = QString( "%1_objects").arg( nbSel );
164 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myShapes, true);
165 myEditCurrentArgument->setText( aString );
170 //=================================================================================
171 // function : SetEditCurrentArgument()
173 //=================================================================================
174 void BuildGUI_CompoundDlg::SetEditCurrentArgument()
176 QPushButton* send = (QPushButton*)sender();
177 if ( send != GroupShapes->PushButton1 )
180 myEditCurrentArgument = GroupShapes->LineEdit1;
182 myEditCurrentArgument->setFocus();
183 SelectionIntoArgument();
187 //=================================================================================
188 // function : ActivateThisDialog()
190 //=================================================================================
191 void BuildGUI_CompoundDlg::ActivateThisDialog()
193 GEOMBase_Skeleton::ActivateThisDialog();
194 globalSelection( GEOM_ALLSHAPES );
195 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
196 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
200 //=================================================================================
201 // function : enterEvent()
203 //=================================================================================
204 void BuildGUI_CompoundDlg::enterEvent(QEvent* e)
206 if ( !mainFrame()->GroupConstructors->isEnabled() )
207 ActivateThisDialog();
210 //=================================================================================
211 // function : createOperation
213 //=================================================================================
214 GEOM::GEOM_IOperations_ptr BuildGUI_CompoundDlg::createOperation()
216 return getGeomEngine()->GetIShapesOperations( getStudyId() );
219 //=================================================================================
220 // function : isValid
222 //=================================================================================
223 bool BuildGUI_CompoundDlg::isValid( QString& )
228 //=================================================================================
229 // function : execute
231 //=================================================================================
232 bool BuildGUI_CompoundDlg::execute( ObjectList& objects )
234 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
235 GEOM::GEOM_Object_var anObj = anOper->MakeCompound( myShapes );
237 if ( !anObj->_is_nil() )
238 objects.push_back( anObj._retn() );
243 //=================================================================================
244 // function : restoreSubShapes
246 //=================================================================================
247 void BuildGUI_CompoundDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
248 SALOMEDS::SObject_ptr theSObject )
250 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
251 // empty list of arguments means that all arguments should be restored
252 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
253 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
254 /*theInheritFirstArg=*/false,
255 mainFrame()->CheckBoxAddPrefix->isChecked() );