Salome HOME
e1adb30c60e155ada891e93b7b09a65c77973890
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.cxx
1 //  Copyright (C) 2007-2008  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 <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39
40 //=================================================================================
41 // class    : BuildGUI_FaceDlg()
42 // purpose  : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the 
43 //            name 'name' and widget flags set to 'f'.
44 //            The dialog will by default be modeless, unless you set 'modal' to
45 //            TRUE to construct a modal dialog.
46 //=================================================================================
47 BuildGUI_FaceDlg::BuildGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
48   : GEOMBase_Skeleton( theGeometryGUI, parent )
49 {
50   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52
53   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
54
55   /***************************************************************/
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
57   mainFrame()->RadioButton1->setIcon( image0 );
58   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59   mainFrame()->RadioButton2->close();
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   GroupWire = new DlgRef_1Sel1Check( centralWidget() );
64
65   GroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
66   GroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
67   GroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
68   GroupWire->PushButton1->setIcon( image1 );
69
70   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71   layout->setMargin( 0 ); layout->setSpacing( 6 );
72   layout->addWidget( GroupWire );
73   /***************************************************************/
74
75   setHelpFileName("create_face_page.html");
76
77   /* Initialisations */
78   Init();
79 }
80
81
82 //=================================================================================
83 // function : ~BuildGUI_FaceDlg()
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
87 {
88   // no need to delete child widgets, Qt does it all for us
89 }
90
91
92 //=================================================================================
93 // function : Init()
94 // purpose  :
95 //=================================================================================
96 void BuildGUI_FaceDlg::Init()
97 {
98   /* init variables */
99   myEditCurrentArgument = GroupWire->LineEdit1;
100   GroupWire->LineEdit1->setReadOnly( true );
101
102   GroupWire->CheckButton1->setChecked( true );
103
104   TColStd_MapOfInteger aMap;
105   aMap.Add( GEOM_EDGE );
106   aMap.Add( GEOM_WIRE );
107   globalSelection( aMap );
108
109   /* signals and slots connections */
110   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
111   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
112   connect( GroupWire->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
113   connect( GroupWire->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
114   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
115            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
116
117   initName( tr( "GEOM_FACE" ) );
118 }
119
120
121 //=================================================================================
122 // function : ClickOnOk()
123 // purpose  :
124 //=================================================================================
125 void BuildGUI_FaceDlg::ClickOnOk()
126 {
127   if ( ClickOnApply() )
128     ClickOnCancel();
129 }
130
131
132 //=================================================================================
133 // function : ClickOnApply()
134 // purpose  :
135 //=================================================================================
136 bool BuildGUI_FaceDlg::ClickOnApply()
137 {
138   if ( !onAccept() )
139     return false;
140
141   initName();
142   return true;
143 }
144
145
146 //=================================================================================
147 // function : SelectionIntoArgument()
148 // purpose  : Called when selection as changed or other case
149 //=================================================================================
150 void BuildGUI_FaceDlg::SelectionIntoArgument()
151 {
152   myEditCurrentArgument->setText( "" );
153   QString aName;
154   
155   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
156   SALOME_ListIO aSelList;
157   aSelMgr->selectedObjects(aSelList);
158
159   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
160   
161   if ( aNbSel < 1) {
162     myWires.length(0);
163     return;
164   }
165   
166   GEOMBase::ConvertListOfIOInListOfGO(aSelList, myWires);
167   if ( !myWires.length() )
168     return;
169   if ( aNbSel != 1 )
170     aName = tr( "%1_objects" ).arg( aNbSel );
171   
172   myEditCurrentArgument->setText( aName );
173 }
174
175
176 //=================================================================================
177 // function : SetEditCurrentArgument()
178 // purpose  :
179 //=================================================================================
180 void BuildGUI_FaceDlg::SetEditCurrentArgument()
181 {
182   QPushButton* send = (QPushButton*)sender();
183   if ( send != GroupWire->PushButton1 )
184     return;
185   
186   TColStd_MapOfInteger aMap;
187   aMap.Add( GEOM_EDGE );
188   aMap.Add( GEOM_WIRE );
189   globalSelection( aMap );
190
191   myEditCurrentArgument = GroupWire->LineEdit1;
192
193   myEditCurrentArgument->setFocus();
194   SelectionIntoArgument();
195 }
196
197
198 //=================================================================================
199 // function : ActivateThisDialog()
200 // purpose  :
201 //=================================================================================
202 void BuildGUI_FaceDlg::ActivateThisDialog()
203 {
204   GEOMBase_Skeleton::ActivateThisDialog();
205   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
206            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
207   TColStd_MapOfInteger aMap;
208   aMap.Add( GEOM_EDGE );
209   aMap.Add( GEOM_WIRE );
210   globalSelection( aMap );
211 }
212
213
214 //=================================================================================
215 // function : enterEvent()
216 // purpose  :
217 //=================================================================================
218 void BuildGUI_FaceDlg::enterEvent( QEvent* )
219 {
220   if ( !mainFrame()->GroupConstructors->isEnabled() )
221     ActivateThisDialog(); 
222 }
223
224 //=================================================================================
225 // function : createOperation
226 // purpose  :
227 //=================================================================================
228 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
229 {
230   return getGeomEngine()->GetIShapesOperations( getStudyId() );
231 }
232
233 //=================================================================================
234 // function : isValid
235 // purpose  :
236 //=================================================================================
237 bool BuildGUI_FaceDlg::isValid( QString& )
238 {
239   return ( myWires.length() != 0 );
240 }
241
242 //=================================================================================
243 // function : execute
244 // purpose  :
245 //=================================================================================
246 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
247 {
248   GEOM::GEOM_Object_var anObj;
249
250   bool isPlanarWanted = GroupWire->CheckButton1->isChecked();
251   anObj = GEOM::GEOM_IShapesOperations::_narrow(
252     getOperation() )->MakeFaceWires( myWires, isPlanarWanted );
253
254   if ( !anObj->_is_nil() )
255     objects.push_back( anObj._retn() );
256
257   return true;
258 }
259