1 // Copyright (C) 2007-2014 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_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 <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
44 //=================================================================================
45 // class : BuildGUI_FaceDlg()
46 // purpose : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 BuildGUI_FaceDlg::BuildGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
52 : GEOMBase_Skeleton( theGeometryGUI, parent ),
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE_SURFACE" ) ) );
60 setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
64 mainFrame()->RadioButton1->setIcon( image1 );
65 mainFrame()->RadioButton2->setIcon( image2 );
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupWire = new DlgRef_1Sel1Check( centralWidget() );
71 GroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
72 GroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
73 GroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
74 GroupWire->PushButton1->setIcon( image0 );
76 myGroupSurf = new DlgRef_2Sel(centralWidget());
78 myGroupSurf->GroupBox1->setTitle(tr("GEOM_FACE_FROM_SURFACE" ) );
79 myGroupSurf->TextLabel1->setText(tr("GEOM_FACE"));
80 myGroupSurf->TextLabel2->setText(tr("GEOM_WIRE"));
81 myGroupSurf->PushButton1->setIcon(image0);
82 myGroupSurf->PushButton2->setIcon(image0);
84 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85 layout->setMargin( 0 ); layout->setSpacing( 6 );
86 layout->addWidget( GroupWire );
87 layout->addWidget(myGroupSurf);
88 /***************************************************************/
90 setHelpFileName("create_face_page.html");
97 //=================================================================================
98 // function : ~BuildGUI_FaceDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
103 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void BuildGUI_FaceDlg::Init()
114 myEditCurrentArgument = GroupWire->LineEdit1;
115 GroupWire->LineEdit1->setReadOnly( true );
116 myGroupSurf->LineEdit1->setReadOnly( true );
117 myGroupSurf->LineEdit2->setReadOnly( true );
119 GroupWire->CheckButton1->setChecked( true );
124 /* signals and slots connections */
125 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
126 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
128 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
130 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
131 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
132 connect( GroupWire->LineEdit1, SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
133 connect( GroupWire->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
134 connect( myGroupSurf->LineEdit1, SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
135 connect( myGroupSurf->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
136 connect( myGroupSurf->LineEdit2, SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
137 connect( myGroupSurf->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
138 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
139 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
141 initName( tr( "GEOM_FACE" ) );
143 ConstructorsClicked(0);
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose : Radio button management
149 //=================================================================================
150 void BuildGUI_FaceDlg::ConstructorsClicked(int constructorId)
152 switch (constructorId) {
155 TColStd_MapOfInteger aMap;
160 aMap.Add(GEOM_SHELL);
161 aMap.Add(GEOM_SOLID);
162 aMap.Add(GEOM_COMPOUND);
163 globalSelection(aMap);
165 myEditCurrentArgument = GroupWire->LineEdit1;
166 GroupWire->LineEdit1->setText("");
173 globalSelection(GEOM_FACE); // For the first element.
175 myEditCurrentArgument = myGroupSurf->LineEdit1;
176 myGroupSurf->LineEdit1->setText("");
177 myGroupSurf->PushButton1->setDown(true);
178 myGroupSurf->PushButton2->setDown(false);
188 qApp->processEvents();
190 resize(minimumSizeHint());
191 SelectionIntoArgument();
194 //=================================================================================
195 // function : ClickOnOk()
197 //=================================================================================
198 void BuildGUI_FaceDlg::ClickOnOk()
200 setIsApplyAndClose( true );
201 if ( ClickOnApply() )
206 //=================================================================================
207 // function : ClickOnApply()
209 //=================================================================================
210 bool BuildGUI_FaceDlg::ClickOnApply()
220 //=================================================================================
221 // function : SelectionIntoArgument()
222 // purpose : Called when selection as changed or other case
223 //=================================================================================
224 void BuildGUI_FaceDlg::SelectionIntoArgument()
226 if (myEditCurrentArgument == GroupWire->LineEdit1) {
227 myEditCurrentArgument->setText( "" );
229 QList<TopAbs_ShapeEnum> types;
230 types << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE
231 << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPOUND;
232 myWires = getSelected( types, -1 );
234 if ( !myWires.isEmpty() ) {
235 QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
236 myEditCurrentArgument->setText( aName );
238 } else if (myEditCurrentArgument == myGroupSurf->LineEdit1 ||
239 myEditCurrentArgument == myGroupSurf->LineEdit2) {
240 const bool isEditFace = myEditCurrentArgument == myGroupSurf->LineEdit1;
241 const TopAbs_ShapeEnum aType = isEditFace ? TopAbs_FACE : TopAbs_WIRE;
242 GEOM::GeomObjPtr aSelectedObject = getSelected(aType);
243 GEOM::GeomObjPtr &anObj = isEditFace ? myFace : myWire;
245 if (aSelectedObject) {
246 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
247 anObj = aSelectedObject;
249 myEditCurrentArgument->setText("");
254 if (myFace && !myWire) {
255 myGroupSurf->PushButton2->click();
258 if (!myFace && myWire) {
259 myGroupSurf->PushButton1->click();
264 displayPreview(true);
268 //=================================================================================
269 // function : SetEditCurrentArgument()
271 //=================================================================================
272 void BuildGUI_FaceDlg::SetEditCurrentArgument()
274 QPushButton* send = (QPushButton*)sender();
275 if (send == GroupWire->PushButton1) {
276 TColStd_MapOfInteger aMap;
281 aMap.Add(GEOM_SHELL);
282 aMap.Add(GEOM_SOLID);
283 aMap.Add(GEOM_COMPOUND);
284 globalSelection(aMap);
285 myEditCurrentArgument = GroupWire->LineEdit1;
287 else if (send == myGroupSurf->PushButton1) {
288 globalSelection(GEOM_FACE);
289 myEditCurrentArgument = myGroupSurf->LineEdit1;
290 myGroupSurf->PushButton2->setDown(false);
291 myGroupSurf->LineEdit2->setEnabled(false);
293 else if (send == myGroupSurf->PushButton2) {
294 globalSelection(GEOM_WIRE);
295 myEditCurrentArgument = myGroupSurf->LineEdit2;
296 myGroupSurf->PushButton1->setDown(false);
297 myGroupSurf->LineEdit1->setEnabled(false);
301 myEditCurrentArgument->setEnabled(true);
302 myEditCurrentArgument->setFocus();
304 displayPreview(true);
308 //=================================================================================
309 // function : ActivateThisDialog()
311 //=================================================================================
312 void BuildGUI_FaceDlg::ActivateThisDialog()
314 GEOMBase_Skeleton::ActivateThisDialog();
315 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
316 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
317 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
318 this, SLOT(SelectionIntoArgument()));
320 ConstructorsClicked(getConstructorId());
324 //=================================================================================
325 // function : enterEvent()
327 //=================================================================================
328 void BuildGUI_FaceDlg::enterEvent( QEvent* )
330 if ( !mainFrame()->GroupConstructors->isEnabled() )
331 ActivateThisDialog();
334 //=================================================================================
335 // function : createOperation
337 //=================================================================================
338 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
340 return getGeomEngine()->GetIShapesOperations( getStudyId() );
343 //=================================================================================
344 // function : isValid
346 //=================================================================================
347 bool BuildGUI_FaceDlg::isValid( QString& )
351 switch (getConstructorId()) {
353 ok = !myWires.isEmpty();
356 ok = myFace && myWire;
365 //=================================================================================
366 // function : execute
368 //=================================================================================
369 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
372 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
373 GEOM::GEOM_Object_var anObj;
375 switch (getConstructorId()) {
378 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
380 objlist->length( myWires.count() );
382 for ( int i = 0; i < myWires.count(); i++ ) {
383 objlist[i] = myWires[i].copy();
386 anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() );
391 anObj = anOper->MakeFaceFromSurface(myFace.get(), myWire.get());
398 if (!anObj->_is_nil()) {
399 objects.push_back(anObj._retn());
401 if (!anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
402 SUIT_OverrideCursor wc;
404 QString msgw = QObject::tr(anOper->GetErrorCode());
405 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
406 anOper->SetErrorCode("PAL_NO_ERROR");