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_FaceDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BuildGUI_FaceDlg.h"
29 #include <GEOMImpl_Types.hxx>
30 #include <TColStd_MapOfInteger.hxx>
33 #include <GeometryGUI.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_Session.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 //=================================================================================
42 // class : BuildGUI_FaceDlg()
43 // purpose : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 BuildGUI_FaceDlg::BuildGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
49 : GEOMBase_Skeleton( theGeometryGUI, parent )
51 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
52 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupWire = new DlgRef_1Sel1Check( centralWidget() );
66 GroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
67 GroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
68 GroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
69 GroupWire->PushButton1->setIcon( image1 );
71 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72 layout->setMargin( 0 ); layout->setSpacing( 6 );
73 layout->addWidget( GroupWire );
74 /***************************************************************/
76 setHelpFileName("create_face_page.html");
83 //=================================================================================
84 // function : ~BuildGUI_FaceDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
89 // no need to delete child widgets, Qt does it all for us
93 //=================================================================================
96 //=================================================================================
97 void BuildGUI_FaceDlg::Init()
100 myEditCurrentArgument = GroupWire->LineEdit1;
101 GroupWire->LineEdit1->setReadOnly( true );
103 GroupWire->CheckButton1->setChecked( true );
105 TColStd_MapOfInteger aMap;
106 aMap.Add( GEOM_EDGE );
107 aMap.Add( GEOM_WIRE );
108 globalSelection( aMap );
110 /* signals and slots connections */
111 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
112 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
113 connect( GroupWire->LineEdit1, SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
114 connect( GroupWire->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
115 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
116 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
118 initName( tr( "GEOM_FACE" ) );
122 //=================================================================================
123 // function : ClickOnOk()
125 //=================================================================================
126 void BuildGUI_FaceDlg::ClickOnOk()
128 if ( ClickOnApply() )
133 //=================================================================================
134 // function : ClickOnApply()
136 //=================================================================================
137 bool BuildGUI_FaceDlg::ClickOnApply()
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose : Called when selection as changed or other case
150 //=================================================================================
151 void BuildGUI_FaceDlg::SelectionIntoArgument()
153 myEditCurrentArgument->setText( "" );
156 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
157 SALOME_ListIO aSelList;
158 aSelMgr->selectedObjects(aSelList);
160 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
167 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myWires);
168 if ( !myWires.length() )
171 aName = tr( "%1_objects" ).arg( aNbSel );
173 myEditCurrentArgument->setText( aName );
177 //=================================================================================
178 // function : SetEditCurrentArgument()
180 //=================================================================================
181 void BuildGUI_FaceDlg::SetEditCurrentArgument()
183 QPushButton* send = (QPushButton*)sender();
184 if ( send != GroupWire->PushButton1 )
187 TColStd_MapOfInteger aMap;
188 aMap.Add( GEOM_EDGE );
189 aMap.Add( GEOM_WIRE );
190 globalSelection( aMap );
192 myEditCurrentArgument = GroupWire->LineEdit1;
194 myEditCurrentArgument->setFocus();
195 SelectionIntoArgument();
199 //=================================================================================
200 // function : ActivateThisDialog()
202 //=================================================================================
203 void BuildGUI_FaceDlg::ActivateThisDialog()
205 GEOMBase_Skeleton::ActivateThisDialog();
206 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
207 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
208 TColStd_MapOfInteger aMap;
209 aMap.Add( GEOM_EDGE );
210 aMap.Add( GEOM_WIRE );
211 globalSelection( aMap );
215 //=================================================================================
216 // function : enterEvent()
218 //=================================================================================
219 void BuildGUI_FaceDlg::enterEvent( QEvent* )
221 if ( !mainFrame()->GroupConstructors->isEnabled() )
222 ActivateThisDialog();
225 //=================================================================================
226 // function : createOperation
228 //=================================================================================
229 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
231 return getGeomEngine()->GetIShapesOperations( getStudyId() );
234 //=================================================================================
235 // function : isValid
237 //=================================================================================
238 bool BuildGUI_FaceDlg::isValid( QString& )
240 return ( myWires.length() != 0 );
243 //=================================================================================
244 // function : execute
246 //=================================================================================
247 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
249 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
250 GEOM::GEOM_Object_var anObj = anOper->MakeFaceWires( myWires, GroupWire->CheckButton1->isChecked() );
252 if ( !anObj->_is_nil() )
253 objects.push_back( anObj._retn() );