Salome HOME
0021355: [CEA] Problem of partition
[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
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 <SUIT_ResourceMgr.h>
37 #include <SUIT_Session.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40
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 )
50 {
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" ) ) );
53
54   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
55
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();
63
64   GroupWire = new DlgRef_1Sel1Check( centralWidget() );
65
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 );
70
71   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72   layout->setMargin( 0 ); layout->setSpacing( 6 );
73   layout->addWidget( GroupWire );
74   /***************************************************************/
75
76   setHelpFileName("create_face_page.html");
77
78   /* Initialisations */
79   Init();
80 }
81
82
83 //=================================================================================
84 // function : ~BuildGUI_FaceDlg()
85 // purpose  : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
88 {
89   // no need to delete child widgets, Qt does it all for us
90 }
91
92
93 //=================================================================================
94 // function : Init()
95 // purpose  :
96 //=================================================================================
97 void BuildGUI_FaceDlg::Init()
98 {
99   /* init variables */
100   myEditCurrentArgument = GroupWire->LineEdit1;
101   GroupWire->LineEdit1->setReadOnly( true );
102
103   GroupWire->CheckButton1->setChecked( true );
104   myWires.clear();
105
106   TColStd_MapOfInteger aMap;
107   aMap.Add( GEOM_EDGE );
108   aMap.Add( GEOM_WIRE );
109   globalSelection( aMap );
110
111   /* signals and slots connections */
112   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
113   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
114   connect( GroupWire->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
115   connect( GroupWire->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
116   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
117            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
118
119   initName( tr( "GEOM_FACE" ) );
120   SelectionIntoArgument();
121 }
122
123
124 //=================================================================================
125 // function : ClickOnOk()
126 // purpose  :
127 //=================================================================================
128 void BuildGUI_FaceDlg::ClickOnOk()
129 {
130   setIsApplyAndClose( true );
131   if ( ClickOnApply() )
132     ClickOnCancel();
133 }
134
135
136 //=================================================================================
137 // function : ClickOnApply()
138 // purpose  :
139 //=================================================================================
140 bool BuildGUI_FaceDlg::ClickOnApply()
141 {
142   if ( !onAccept() )
143     return false;
144
145   initName();
146   return true;
147 }
148
149
150 //=================================================================================
151 // function : SelectionIntoArgument()
152 // purpose  : Called when selection as changed or other case
153 //=================================================================================
154 void BuildGUI_FaceDlg::SelectionIntoArgument()
155 {
156   myEditCurrentArgument->setText( "" );
157
158   QList<TopAbs_ShapeEnum> types;
159   types << TopAbs_EDGE << TopAbs_WIRE;
160   myWires = getSelected( types, -1 );
161
162   if ( !myWires.isEmpty() ) {
163     QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
164     myEditCurrentArgument->setText( aName );
165   }
166 }
167
168
169 //=================================================================================
170 // function : SetEditCurrentArgument()
171 // purpose  :
172 //=================================================================================
173 void BuildGUI_FaceDlg::SetEditCurrentArgument()
174 {
175   QPushButton* send = (QPushButton*)sender();
176   if ( send != GroupWire->PushButton1 )
177     return;
178   
179   TColStd_MapOfInteger aMap;
180   aMap.Add( GEOM_EDGE );
181   aMap.Add( GEOM_WIRE );
182   globalSelection( aMap );
183
184   myEditCurrentArgument = GroupWire->LineEdit1;
185
186   myEditCurrentArgument->setFocus();
187   SelectionIntoArgument();
188 }
189
190
191 //=================================================================================
192 // function : ActivateThisDialog()
193 // purpose  :
194 //=================================================================================
195 void BuildGUI_FaceDlg::ActivateThisDialog()
196 {
197   GEOMBase_Skeleton::ActivateThisDialog();
198   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
199            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
200   TColStd_MapOfInteger aMap;
201   aMap.Add( GEOM_EDGE );
202   aMap.Add( GEOM_WIRE );
203   globalSelection( aMap );
204 }
205
206
207 //=================================================================================
208 // function : enterEvent()
209 // purpose  :
210 //=================================================================================
211 void BuildGUI_FaceDlg::enterEvent( QEvent* )
212 {
213   if ( !mainFrame()->GroupConstructors->isEnabled() )
214     ActivateThisDialog(); 
215 }
216
217 //=================================================================================
218 // function : createOperation
219 // purpose  :
220 //=================================================================================
221 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
222 {
223   return getGeomEngine()->GetIShapesOperations( getStudyId() );
224 }
225
226 //=================================================================================
227 // function : isValid
228 // purpose  :
229 //=================================================================================
230 bool BuildGUI_FaceDlg::isValid( QString& )
231 {
232   return !myWires.isEmpty();
233 }
234
235 //=================================================================================
236 // function : execute
237 // purpose  :
238 //=================================================================================
239 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
240 {
241   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
242
243   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
244   objlist->length( myWires.count() );
245   for ( int i = 0; i < myWires.count(); i++ )
246     objlist[i] = myWires[i].copy();
247
248   GEOM::GEOM_Object_var anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() );
249
250   if ( !anObj->_is_nil() )
251     objects.push_back( anObj._retn() );
252
253   return true;
254 }
255