Salome HOME
NPAL18017: EDF GEOM V3.2.9rc1 : Exception raised when getShapeOn... function return...
[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 "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36
37 //Qt includes
38 #include <qcheckbox.h>
39 #include <qlabel.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, WFlags fl)
52   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 {
55   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_FACE")));
56   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_FACE_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_FACE"));
62   RadioButton1->setPixmap(image0);
63   RadioButton2->close(TRUE);
64   RadioButton3->close(TRUE);
65
66   GroupWire = new DlgRef_1Sel1Check_QTD(this, "GroupWire");
67   GroupWire->GroupBox1->setTitle(tr("GEOM_FACE_FFW"));
68   GroupWire->TextLabel1->setText(tr("GEOM_OBJECTS"));
69   GroupWire->CheckButton1->setText(tr("GEOM_FACE_OPT"));
70   GroupWire->PushButton1->setPixmap(image1);
71
72   Layout1->addWidget(GroupWire, 2, 0);
73   /***************************************************************/
74
75   setHelpFileName("face.htm");
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   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
156   
157   if(aNbSel < 1)
158     {
159       myWires.length(0);
160       return;
161     }
162   
163   GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myWires);
164   if (!myWires.length())
165     return;
166   if(aNbSel != 1)
167     aName = tr("%1_objects").arg(aNbSel);
168   
169   myEditCurrentArgument->setText( aName );
170   
171   myEditCurrentArgument->setText( aName );
172 }
173
174
175 //=================================================================================
176 // function : SetEditCurrentArgument()
177 // purpose  :
178 //=================================================================================
179 void BuildGUI_FaceDlg::SetEditCurrentArgument()
180 {
181   QPushButton* send = (QPushButton*)sender();
182   if (send != GroupWire->PushButton1)
183     return;
184   
185   TColStd_MapOfInteger aMap;
186   aMap.Add( GEOM_EDGE );
187   aMap.Add( GEOM_WIRE );
188   globalSelection( aMap );
189
190   myEditCurrentArgument = GroupWire->LineEdit1;
191
192   myEditCurrentArgument->setFocus();
193   SelectionIntoArgument();
194 }
195
196
197 //=================================================================================
198 // function : ActivateThisDialog()
199 // purpose  :
200 //=================================================================================
201 void BuildGUI_FaceDlg::ActivateThisDialog()
202 {
203   GEOMBase_Skeleton::ActivateThisDialog();
204   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
205           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
206   TColStd_MapOfInteger aMap;
207   aMap.Add( GEOM_EDGE );
208   aMap.Add( GEOM_WIRE );
209   globalSelection( aMap );
210 }
211
212
213 //=================================================================================
214 // function : enterEvent()
215 // purpose  :
216 //=================================================================================
217 void BuildGUI_FaceDlg::enterEvent(QEvent* e)
218 {
219   if ( !GroupConstructors->isEnabled() )
220     ActivateThisDialog(); 
221 }
222
223 //=================================================================================
224 // function : createOperation
225 // purpose  :
226 //=================================================================================
227 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
228 {
229   return getGeomEngine()->GetIShapesOperations( getStudyId() );
230 }
231
232 //=================================================================================
233 // function : isValid
234 // purpose  :
235 //=================================================================================
236 bool BuildGUI_FaceDlg::isValid( QString& )
237 {
238   return (myWires.length() != 0);
239 }
240
241 //=================================================================================
242 // function : execute
243 // purpose  :
244 //=================================================================================
245 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
246 {
247   GEOM::GEOM_Object_var anObj;
248
249   bool isPlanarWanted = GroupWire->CheckButton1->isChecked();
250   anObj = GEOM::GEOM_IShapesOperations::_narrow(
251     getOperation() )->MakeFaceWires( myWires, isPlanarWanted );
252
253   if ( !anObj->_is_nil() )
254     objects.push_back( anObj._retn() );
255
256   return true;
257 }
258