1 // Copyright (C) 2007-2011 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BuildGUI_FaceDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BuildGUI_FaceDlg.h"
28 #include <GEOMImpl_Types.hxx>
29 #include <TColStd_MapOfInteger.hxx>
32 #include <GeometryGUI.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_OverrideCursor.h>
43 //=================================================================================
44 // class : BuildGUI_FaceDlg()
45 // purpose : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 BuildGUI_FaceDlg::BuildGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
51 : GEOMBase_Skeleton( theGeometryGUI, parent )
53 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
54 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56 setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton2->close();
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 GroupWire = new DlgRef_1Sel1Check( centralWidget() );
68 GroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
69 GroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
70 GroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
71 GroupWire->PushButton1->setIcon( image1 );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupWire );
76 /***************************************************************/
78 setHelpFileName("create_face_page.html");
85 //=================================================================================
86 // function : ~BuildGUI_FaceDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
91 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void BuildGUI_FaceDlg::Init()
102 myEditCurrentArgument = GroupWire->LineEdit1;
103 GroupWire->LineEdit1->setReadOnly( true );
105 GroupWire->CheckButton1->setChecked( true );
108 TColStd_MapOfInteger aMap;
109 aMap.Add( GEOM_EDGE );
110 aMap.Add( GEOM_WIRE );
111 globalSelection( aMap );
113 /* signals and slots connections */
114 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
115 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
116 connect( GroupWire->LineEdit1, SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
117 connect( GroupWire->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
118 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
119 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
121 initName( tr( "GEOM_FACE" ) );
122 SelectionIntoArgument();
126 //=================================================================================
127 // function : ClickOnOk()
129 //=================================================================================
130 void BuildGUI_FaceDlg::ClickOnOk()
132 setIsApplyAndClose( true );
133 if ( ClickOnApply() )
138 //=================================================================================
139 // function : ClickOnApply()
141 //=================================================================================
142 bool BuildGUI_FaceDlg::ClickOnApply()
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection as changed or other case
155 //=================================================================================
156 void BuildGUI_FaceDlg::SelectionIntoArgument()
158 myEditCurrentArgument->setText( "" );
160 QList<TopAbs_ShapeEnum> types;
161 types << TopAbs_EDGE << TopAbs_WIRE;
162 myWires = getSelected( types, -1 );
164 if ( !myWires.isEmpty() ) {
165 QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
166 myEditCurrentArgument->setText( aName );
171 //=================================================================================
172 // function : SetEditCurrentArgument()
174 //=================================================================================
175 void BuildGUI_FaceDlg::SetEditCurrentArgument()
177 QPushButton* send = (QPushButton*)sender();
178 if ( send != GroupWire->PushButton1 )
181 TColStd_MapOfInteger aMap;
182 aMap.Add( GEOM_EDGE );
183 aMap.Add( GEOM_WIRE );
184 globalSelection( aMap );
186 myEditCurrentArgument = GroupWire->LineEdit1;
188 myEditCurrentArgument->setFocus();
189 SelectionIntoArgument();
193 //=================================================================================
194 // function : ActivateThisDialog()
196 //=================================================================================
197 void BuildGUI_FaceDlg::ActivateThisDialog()
199 GEOMBase_Skeleton::ActivateThisDialog();
200 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
201 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
202 TColStd_MapOfInteger aMap;
203 aMap.Add( GEOM_EDGE );
204 aMap.Add( GEOM_WIRE );
205 globalSelection( aMap );
209 //=================================================================================
210 // function : enterEvent()
212 //=================================================================================
213 void BuildGUI_FaceDlg::enterEvent( QEvent* )
215 if ( !mainFrame()->GroupConstructors->isEnabled() )
216 ActivateThisDialog();
219 //=================================================================================
220 // function : createOperation
222 //=================================================================================
223 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
225 return getGeomEngine()->GetIShapesOperations( getStudyId() );
228 //=================================================================================
229 // function : isValid
231 //=================================================================================
232 bool BuildGUI_FaceDlg::isValid( QString& )
234 return !myWires.isEmpty();
237 //=================================================================================
238 // function : execute
240 //=================================================================================
241 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
243 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
245 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
246 objlist->length( myWires.count() );
247 for ( int i = 0; i < myWires.count(); i++ )
248 objlist[i] = myWires[i].copy();
250 GEOM::GEOM_Object_var anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() );
252 if (!anObj->_is_nil()) {
253 objects.push_back(anObj._retn());
255 if (!anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
256 SUIT_OverrideCursor wc;
258 QString msgw = QObject::tr(anOper->GetErrorCode());
259 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
260 anOper->SetErrorCode("PAL_NO_ERROR");