Salome HOME
3b7a2c08a19ca852eec5d27c00cb3632bff895e5
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_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(QWidget* parent, const char* name, bool modal, WFlags fl)
50   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 {
52   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_FACE")));
53   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
54
55   setCaption(tr("GEOM_FACE_TITLE"));
56
57   /***************************************************************/
58   GroupConstructors->setTitle(tr("GEOM_FACE"));
59   RadioButton1->setPixmap(image0);
60   RadioButton2->close(TRUE);
61   RadioButton3->close(TRUE);
62
63   GroupWire = new DlgRef_1Sel1Check_QTD(this, "GroupWire");
64   GroupWire->GroupBox1->setTitle(tr("GEOM_FACE_FFW"));
65   GroupWire->TextLabel1->setText(tr("GEOM_WIRES"));
66   GroupWire->CheckButton1->setText(tr("GEOM_FACE_OPT"));
67   GroupWire->PushButton1->setPixmap(image1);
68
69   Layout1->addWidget(GroupWire, 2, 0);
70   /***************************************************************/
71
72   /* Initialisations */
73   Init();
74 }
75
76
77 //=================================================================================
78 // function : ~BuildGUI_FaceDlg()
79 // purpose  : Destroys the object and frees any allocated resources
80 //=================================================================================
81 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
82 {
83   // no need to delete child widgets, Qt does it all for us
84 }
85
86
87 //=================================================================================
88 // function : Init()
89 // purpose  :
90 //=================================================================================
91 void BuildGUI_FaceDlg::Init()
92 {
93   /* init variables */
94   myEditCurrentArgument = GroupWire->LineEdit1;
95   GroupWire->LineEdit1->setReadOnly( true );
96
97   GroupWire->CheckButton1->setChecked(TRUE);
98
99   globalSelection( GEOM_WIRE );
100
101   /* signals and slots connections */
102   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
103   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
104   connect(GroupWire->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
105   connect(GroupWire->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));  
106   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
107           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
108
109   initName(tr("GEOM_FACE"));
110 }
111
112
113 //=================================================================================
114 // function : ClickOnOk()
115 // purpose  :
116 //=================================================================================
117 void BuildGUI_FaceDlg::ClickOnOk()
118 {
119   if ( ClickOnApply() )
120     ClickOnCancel();
121 }
122
123
124 //=================================================================================
125 // function : ClickOnApply()
126 // purpose  :
127 //=================================================================================
128 bool BuildGUI_FaceDlg::ClickOnApply()
129 {
130   if ( !onAccept() )
131     return false;
132
133   initName();
134   return true;
135 }
136
137
138 //=================================================================================
139 // function : SelectionIntoArgument()
140 // purpose  : Called when selection as changed or other case
141 //=================================================================================
142 void BuildGUI_FaceDlg::SelectionIntoArgument()
143 {
144   myEditCurrentArgument->setText("");
145   QString aName;
146   
147   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
148   
149   if(aNbSel < 1)
150     {
151       myWires.length(0);
152       return;
153     }
154   
155   GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myWires);
156   if (!myWires.length())
157     return;
158   if(aNbSel != 1)
159     aName = tr("%1_wires").arg(aNbSel);
160   
161   myEditCurrentArgument->setText( aName );
162   
163   myEditCurrentArgument->setText( aName );
164 }
165
166
167 //=================================================================================
168 // function : SetEditCurrentArgument()
169 // purpose  :
170 //=================================================================================
171 void BuildGUI_FaceDlg::SetEditCurrentArgument()
172 {
173   QPushButton* send = (QPushButton*)sender();
174   if (send != GroupWire->PushButton1)
175     return;
176   
177   globalSelection( GEOM_WIRE );
178   myEditCurrentArgument = GroupWire->LineEdit1;
179
180   myEditCurrentArgument->setFocus();
181   SelectionIntoArgument();
182 }
183
184
185 //=================================================================================
186 // function : ActivateThisDialog()
187 // purpose  :
188 //=================================================================================
189 void BuildGUI_FaceDlg::ActivateThisDialog()
190 {
191   GEOMBase_Skeleton::ActivateThisDialog();
192   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
193           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
194   globalSelection( GEOM_WIRE );
195 }
196
197
198 //=================================================================================
199 // function : enterEvent()
200 // purpose  :
201 //=================================================================================
202 void BuildGUI_FaceDlg::enterEvent(QEvent* e)
203 {
204   if ( !GroupConstructors->isEnabled() )
205     ActivateThisDialog(); 
206 }
207
208 //=================================================================================
209 // function : createOperation
210 // purpose  :
211 //=================================================================================
212 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
213 {
214   return getGeomEngine()->GetIShapesOperations( getStudyId() );
215 }
216
217 //=================================================================================
218 // function : isValid
219 // purpose  :
220 //=================================================================================
221 bool BuildGUI_FaceDlg::isValid( QString& )
222 {
223   return (myWires.length() != 0);
224 }
225
226 //=================================================================================
227 // function : execute
228 // purpose  :
229 //=================================================================================
230 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
231 {
232   GEOM::GEOM_Object_var anObj;
233
234   bool isPlanarWanted = GroupWire->CheckButton1->isChecked();
235   anObj = GEOM::GEOM_IShapesOperations::_narrow(
236     getOperation() )->MakeFaceWires( myWires, isPlanarWanted );
237
238   if ( !anObj->_is_nil() )
239     objects.push_back( anObj._retn() );
240
241   return true;
242 }
243