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