Salome HOME
Merge from V6_main 01/04/2013
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : BuildGUI_FaceDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26
27 #include "BuildGUI_FaceDlg.h"
28
29 #include <GEOMImpl_Types.hxx>
30 #include <TColStd_MapOfInteger.hxx>
31
32 #include <DlgRef.h>
33 #include <GeometryGUI.h>
34 #include <GEOMBase.h>
35
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
43
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 )
53 {
54   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
55   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56
57   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
58
59   /***************************************************************/
60   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
61   mainFrame()->RadioButton1->setIcon( image0 );
62   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
63   mainFrame()->RadioButton2->close();
64   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
65   mainFrame()->RadioButton3->close();
66
67   GroupWire = new DlgRef_1Sel1Check( centralWidget() );
68
69   GroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
70   GroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
71   GroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
72   GroupWire->PushButton1->setIcon( image1 );
73
74   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
75   layout->setMargin( 0 ); layout->setSpacing( 6 );
76   layout->addWidget( GroupWire );
77   /***************************************************************/
78
79   setHelpFileName("create_face_page.html");
80
81   /* Initialisations */
82   Init();
83 }
84
85
86 //=================================================================================
87 // function : ~BuildGUI_FaceDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
91 {
92   // no need to delete child widgets, Qt does it all for us
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void BuildGUI_FaceDlg::Init()
101 {
102   /* init variables */
103   myEditCurrentArgument = GroupWire->LineEdit1;
104   GroupWire->LineEdit1->setReadOnly( true );
105
106   GroupWire->CheckButton1->setChecked( true );
107   myWires.clear();
108
109   TColStd_MapOfInteger aMap;
110   aMap.Add( GEOM_EDGE );
111   aMap.Add( GEOM_WIRE );
112   globalSelection( aMap );
113
114   /* signals and slots connections */
115   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
116   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
117   connect( GroupWire->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
118   connect( GroupWire->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
119   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
120            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
121
122   initName( tr( "GEOM_FACE" ) );
123   SelectionIntoArgument();
124 }
125
126
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose  :
130 //=================================================================================
131 void BuildGUI_FaceDlg::ClickOnOk()
132 {
133   setIsApplyAndClose( true );
134   if ( ClickOnApply() )
135     ClickOnCancel();
136 }
137
138
139 //=================================================================================
140 // function : ClickOnApply()
141 // purpose  :
142 //=================================================================================
143 bool BuildGUI_FaceDlg::ClickOnApply()
144 {
145   if ( !onAccept() )
146     return false;
147
148   initName();
149   return true;
150 }
151
152
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose  : Called when selection as changed or other case
156 //=================================================================================
157 void BuildGUI_FaceDlg::SelectionIntoArgument()
158 {
159   myEditCurrentArgument->setText( "" );
160
161   QList<TopAbs_ShapeEnum> types;
162   types << TopAbs_EDGE << TopAbs_WIRE;
163   myWires = getSelected( types, -1 );
164
165   if ( !myWires.isEmpty() ) {
166     QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
167     myEditCurrentArgument->setText( aName );
168   }
169 }
170
171
172 //=================================================================================
173 // function : SetEditCurrentArgument()
174 // purpose  :
175 //=================================================================================
176 void BuildGUI_FaceDlg::SetEditCurrentArgument()
177 {
178   QPushButton* send = (QPushButton*)sender();
179   if ( send != GroupWire->PushButton1 )
180     return;
181   
182   TColStd_MapOfInteger aMap;
183   aMap.Add( GEOM_EDGE );
184   aMap.Add( GEOM_WIRE );
185   globalSelection( aMap );
186
187   myEditCurrentArgument = GroupWire->LineEdit1;
188
189   myEditCurrentArgument->setFocus();
190   SelectionIntoArgument();
191 }
192
193
194 //=================================================================================
195 // function : ActivateThisDialog()
196 // purpose  :
197 //=================================================================================
198 void BuildGUI_FaceDlg::ActivateThisDialog()
199 {
200   GEOMBase_Skeleton::ActivateThisDialog();
201   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
202            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
203   TColStd_MapOfInteger aMap;
204   aMap.Add( GEOM_EDGE );
205   aMap.Add( GEOM_WIRE );
206   globalSelection( aMap );
207 }
208
209
210 //=================================================================================
211 // function : enterEvent()
212 // purpose  :
213 //=================================================================================
214 void BuildGUI_FaceDlg::enterEvent( QEvent* )
215 {
216   if ( !mainFrame()->GroupConstructors->isEnabled() )
217     ActivateThisDialog(); 
218 }
219
220 //=================================================================================
221 // function : createOperation
222 // purpose  :
223 //=================================================================================
224 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
225 {
226   return getGeomEngine()->GetIShapesOperations( getStudyId() );
227 }
228
229 //=================================================================================
230 // function : isValid
231 // purpose  :
232 //=================================================================================
233 bool BuildGUI_FaceDlg::isValid( QString& )
234 {
235   return !myWires.isEmpty();
236 }
237
238 //=================================================================================
239 // function : execute
240 // purpose  :
241 //=================================================================================
242 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
243 {
244   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
245
246   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
247   objlist->length( myWires.count() );
248   for ( int i = 0; i < myWires.count(); i++ )
249     objlist[i] = myWires[i].copy();
250
251   GEOM::GEOM_Object_var anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() );
252
253   if (!anObj->_is_nil()) {
254     objects.push_back(anObj._retn());
255
256     if (!anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
257       SUIT_OverrideCursor wc;
258       wc.suspend();
259       QString msgw = QObject::tr(anOper->GetErrorCode());
260       SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
261       anOper->SetErrorCode("PAL_NO_ERROR");
262     }
263   }
264
265   return true;
266 }