1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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();
105 mainFrame()->CheckBoxPreview->hide();
107 /* signals and slots connections */
108 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
109 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
110 connect( GroupShapes->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
111 connect( ( (SalomeApp_Application*)(SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
112 SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
114 globalSelection( GEOM_ALLSHAPES );
116 initName( tr( "GEOM_COMPOUND" ) );
117 SelectionIntoArgument();
121 //=================================================================================
122 // function : ClickOnOk()
124 //=================================================================================
125 void BuildGUI_CompoundDlg::ClickOnOk()
127 setIsApplyAndClose( true );
128 if ( ClickOnApply() )
133 //=================================================================================
134 // function : ClickOnApply()
136 //=================================================================================
137 bool BuildGUI_CompoundDlg::ClickOnApply()
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose : Called when selection as changed or other case
150 //=================================================================================
151 void BuildGUI_CompoundDlg::SelectionIntoArgument()
153 myEditCurrentArgument->setText( "" );
155 myShapes = getSelected( TopAbs_SHAPE, -1 );
157 if ( !myShapes.isEmpty() ) {
158 QString aName = myShapes.count() > 1 ? QString( "%1_objects").arg( myShapes.count() ) : GEOMBase::GetName( myShapes[0].get() );
159 myEditCurrentArgument->setText( aName );
164 //=================================================================================
165 // function : SetEditCurrentArgument()
167 //=================================================================================
168 void BuildGUI_CompoundDlg::SetEditCurrentArgument()
170 QPushButton* send = (QPushButton*)sender();
171 if ( send != GroupShapes->PushButton1 )
174 myEditCurrentArgument = GroupShapes->LineEdit1;
176 myEditCurrentArgument->setFocus();
177 SelectionIntoArgument();
181 //=================================================================================
182 // function : ActivateThisDialog()
184 //=================================================================================
185 void BuildGUI_CompoundDlg::ActivateThisDialog()
187 GEOMBase_Skeleton::ActivateThisDialog();
188 globalSelection( GEOM_ALLSHAPES );
189 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
190 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
194 //=================================================================================
195 // function : enterEvent()
197 //=================================================================================
198 void BuildGUI_CompoundDlg::enterEvent(QEvent*)
200 if ( !mainFrame()->GroupConstructors->isEnabled() )
201 ActivateThisDialog();
204 //=================================================================================
205 // function : createOperation
207 //=================================================================================
208 GEOM::GEOM_IOperations_ptr BuildGUI_CompoundDlg::createOperation()
210 return getGeomEngine()->GetIShapesOperations();
213 //=================================================================================
214 // function : isValid
216 //=================================================================================
217 bool BuildGUI_CompoundDlg::isValid( QString& )
219 return !myShapes.isEmpty();
222 //=================================================================================
223 // function : execute
225 //=================================================================================
226 bool BuildGUI_CompoundDlg::execute( ObjectList& objects )
228 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
230 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
231 objlist->length( myShapes.count() );
232 for ( int i = 0; i < myShapes.count(); i++ )
233 objlist[i] = myShapes[i].copy();
235 GEOM::GEOM_Object_var anObj = anOper->MakeCompound( objlist );
237 if ( !anObj->_is_nil() )
238 objects.push_back( anObj._retn() );
243 //=================================================================================
244 // function : restoreSubShapes
246 //=================================================================================
247 void BuildGUI_CompoundDlg::restoreSubShapes( SALOMEDS::SObject_ptr theSObject )
249 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
250 // empty list of arguments means that all arguments should be restored
251 getGeomEngine()->RestoreSubShapesSO( theSObject, GEOM::ListOfGO(),
252 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
253 /*theInheritFirstArg=*/false,
254 mainFrame()->CheckBoxAddPrefix->isChecked() );
258 //=================================================================================
259 // function : getSourceObjects
260 // purpose : virtual method to get source objects
261 //=================================================================================
262 QList<GEOM::GeomObjPtr> BuildGUI_CompoundDlg::getSourceObjects()