Salome HOME
Porting to Qt4.
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : BuildGUI_FaceDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BuildGUI_FaceDlg.h"
30 #include "GEOMImpl_Types.hxx"
31 #include "TColStd_MapOfInteger.hxx"
32
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 using namespace std;
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                                    const char* name, bool modal, Qt::WindowFlags fl)
52   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
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   GroupConstructors->setTitle(tr("GEOM_FACE"));
61   RadioButton1->setIcon(image0);
62   RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
63   RadioButton2->close();
64   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
65   RadioButton3->close();
66
67   GroupWire = new Ui::DlgRef_1Sel1Check_QTD();
68   QWidget* aGroupWireWidget = new QWidget(this);
69   GroupWire->setupUi(aGroupWireWidget);
70   aGroupWireWidget->setObjectName("GroupWire");
71
72   GroupWire->GroupBox1->setTitle(tr("GEOM_FACE_FFW"));
73   GroupWire->TextLabel1->setText(tr("GEOM_OBJECTS"));
74   GroupWire->CheckButton1->setText(tr("GEOM_FACE_OPT"));
75   GroupWire->PushButton1->setIcon(image1);
76
77   gridLayout1->addWidget(aGroupWireWidget, 2, 0);
78   /***************************************************************/
79
80   setHelpFileName("face.htm");
81
82   /* Initialisations */
83   Init();
84 }
85
86
87 //=================================================================================
88 // function : ~BuildGUI_FaceDlg()
89 // purpose  : Destroys the object and frees any allocated resources
90 //=================================================================================
91 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
92 {
93   // no need to delete child widgets, Qt does it all for us
94 }
95
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void BuildGUI_FaceDlg::Init()
102 {
103   /* init variables */
104   myEditCurrentArgument = GroupWire->LineEdit1;
105   GroupWire->LineEdit1->setReadOnly( true );
106
107   GroupWire->CheckButton1->setChecked(TRUE);
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").toStdString().c_str());
123 }
124
125
126 //=================================================================================
127 // function : ClickOnOk()
128 // purpose  :
129 //=================================================================================
130 void BuildGUI_FaceDlg::ClickOnOk()
131 {
132   if ( ClickOnApply() )
133     ClickOnCancel();
134 }
135
136
137 //=================================================================================
138 // function : ClickOnApply()
139 // purpose  :
140 //=================================================================================
141 bool BuildGUI_FaceDlg::ClickOnApply()
142 {
143   if ( !onAccept() )
144     return false;
145
146   initName();
147   return true;
148 }
149
150
151 //=================================================================================
152 // function : SelectionIntoArgument()
153 // purpose  : Called when selection as changed or other case
154 //=================================================================================
155 void BuildGUI_FaceDlg::SelectionIntoArgument()
156 {
157   myEditCurrentArgument->setText("");
158   QString aName;
159   
160   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
161   
162   if(aNbSel < 1)
163     {
164       myWires.length(0);
165       return;
166     }
167   
168   GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myWires);
169   if (!myWires.length())
170     return;
171   if(aNbSel != 1)
172     aName = tr("%1_objects").arg(aNbSel);
173   
174   myEditCurrentArgument->setText( aName );
175   
176   myEditCurrentArgument->setText( aName );
177 }
178
179
180 //=================================================================================
181 // function : SetEditCurrentArgument()
182 // purpose  :
183 //=================================================================================
184 void BuildGUI_FaceDlg::SetEditCurrentArgument()
185 {
186   QPushButton* send = (QPushButton*)sender();
187   if (send != GroupWire->PushButton1)
188     return;
189   
190   TColStd_MapOfInteger aMap;
191   aMap.Add( GEOM_EDGE );
192   aMap.Add( GEOM_WIRE );
193   globalSelection( aMap );
194
195   myEditCurrentArgument = GroupWire->LineEdit1;
196
197   myEditCurrentArgument->setFocus();
198   SelectionIntoArgument();
199 }
200
201
202 //=================================================================================
203 // function : ActivateThisDialog()
204 // purpose  :
205 //=================================================================================
206 void BuildGUI_FaceDlg::ActivateThisDialog()
207 {
208   GEOMBase_Skeleton::ActivateThisDialog();
209   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
210           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
211   TColStd_MapOfInteger aMap;
212   aMap.Add( GEOM_EDGE );
213   aMap.Add( GEOM_WIRE );
214   globalSelection( aMap );
215 }
216
217
218 //=================================================================================
219 // function : enterEvent()
220 // purpose  :
221 //=================================================================================
222 void BuildGUI_FaceDlg::enterEvent(QEvent* e)
223 {
224   if ( !GroupConstructors->isEnabled() )
225     ActivateThisDialog(); 
226 }
227
228 //=================================================================================
229 // function : createOperation
230 // purpose  :
231 //=================================================================================
232 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
233 {
234   return getGeomEngine()->GetIShapesOperations( getStudyId() );
235 }
236
237 //=================================================================================
238 // function : isValid
239 // purpose  :
240 //=================================================================================
241 bool BuildGUI_FaceDlg::isValid( QString& )
242 {
243   return (myWires.length() != 0);
244 }
245
246 //=================================================================================
247 // function : execute
248 // purpose  :
249 //=================================================================================
250 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
251 {
252   GEOM::GEOM_Object_var anObj;
253
254   bool isPlanarWanted = GroupWire->CheckButton1->isChecked();
255   anObj = GEOM::GEOM_IShapesOperations::_narrow(
256     getOperation() )->MakeFaceWires( myWires, isPlanarWanted );
257
258   if ( !anObj->_is_nil() )
259     objects.push_back( anObj._retn() );
260
261   return true;
262 }
263