Salome HOME
Merge from V6_4_BR 05/12/2011
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.cxx
1 // Copyright (C) 2007-2011  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BuildGUI_FaceDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25
26 #include "BuildGUI_FaceDlg.h"
27
28 #include <GEOMImpl_Types.hxx>
29 #include <TColStd_MapOfInteger.hxx>
30
31 #include <DlgRef.h>
32 #include <GeometryGUI.h>
33 #include <GEOMBase.h>
34
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_OverrideCursor.h>
42
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 )
52 {
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" ) ) );
55
56   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
57
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();
65
66   GroupWire = new DlgRef_1Sel1Check( centralWidget() );
67
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 );
72
73   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74   layout->setMargin( 0 ); layout->setSpacing( 6 );
75   layout->addWidget( GroupWire );
76   /***************************************************************/
77
78   setHelpFileName("create_face_page.html");
79
80   /* Initialisations */
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~BuildGUI_FaceDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
90 {
91   // no need to delete child widgets, Qt does it all for us
92 }
93
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void BuildGUI_FaceDlg::Init()
100 {
101   /* init variables */
102   myEditCurrentArgument = GroupWire->LineEdit1;
103   GroupWire->LineEdit1->setReadOnly( true );
104
105   GroupWire->CheckButton1->setChecked( true );
106   myWires.clear();
107
108   TColStd_MapOfInteger aMap;
109   aMap.Add( GEOM_EDGE );
110   aMap.Add( GEOM_WIRE );
111   globalSelection( aMap );
112
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() ) );
120
121   initName( tr( "GEOM_FACE" ) );
122   SelectionIntoArgument();
123 }
124
125
126 //=================================================================================
127 // function : ClickOnOk()
128 // purpose  :
129 //=================================================================================
130 void BuildGUI_FaceDlg::ClickOnOk()
131 {
132   setIsApplyAndClose( true );
133   if ( ClickOnApply() )
134     ClickOnCancel();
135 }
136
137
138 //=================================================================================
139 // function : ClickOnApply()
140 // purpose  :
141 //=================================================================================
142 bool BuildGUI_FaceDlg::ClickOnApply()
143 {
144   if ( !onAccept() )
145     return false;
146
147   initName();
148   return true;
149 }
150
151
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose  : Called when selection as changed or other case
155 //=================================================================================
156 void BuildGUI_FaceDlg::SelectionIntoArgument()
157 {
158   myEditCurrentArgument->setText( "" );
159
160   QList<TopAbs_ShapeEnum> types;
161   types << TopAbs_EDGE << TopAbs_WIRE;
162   myWires = getSelected( types, -1 );
163
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 );
167   }
168 }
169
170
171 //=================================================================================
172 // function : SetEditCurrentArgument()
173 // purpose  :
174 //=================================================================================
175 void BuildGUI_FaceDlg::SetEditCurrentArgument()
176 {
177   QPushButton* send = (QPushButton*)sender();
178   if ( send != GroupWire->PushButton1 )
179     return;
180   
181   TColStd_MapOfInteger aMap;
182   aMap.Add( GEOM_EDGE );
183   aMap.Add( GEOM_WIRE );
184   globalSelection( aMap );
185
186   myEditCurrentArgument = GroupWire->LineEdit1;
187
188   myEditCurrentArgument->setFocus();
189   SelectionIntoArgument();
190 }
191
192
193 //=================================================================================
194 // function : ActivateThisDialog()
195 // purpose  :
196 //=================================================================================
197 void BuildGUI_FaceDlg::ActivateThisDialog()
198 {
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 );
206 }
207
208
209 //=================================================================================
210 // function : enterEvent()
211 // purpose  :
212 //=================================================================================
213 void BuildGUI_FaceDlg::enterEvent( QEvent* )
214 {
215   if ( !mainFrame()->GroupConstructors->isEnabled() )
216     ActivateThisDialog(); 
217 }
218
219 //=================================================================================
220 // function : createOperation
221 // purpose  :
222 //=================================================================================
223 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
224 {
225   return getGeomEngine()->GetIShapesOperations( getStudyId() );
226 }
227
228 //=================================================================================
229 // function : isValid
230 // purpose  :
231 //=================================================================================
232 bool BuildGUI_FaceDlg::isValid( QString& )
233 {
234   return !myWires.isEmpty();
235 }
236
237 //=================================================================================
238 // function : execute
239 // purpose  :
240 //=================================================================================
241 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
242 {
243   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
244
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();
249
250   GEOM::GEOM_Object_var anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() );
251
252   if (!anObj->_is_nil()) {
253     objects.push_back(anObj._retn());
254
255     if (!anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
256       SUIT_OverrideCursor wc;
257       wc.suspend();
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");
261     }
262   }
263
264   return true;
265 }