]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_WireDlg.cxx
Salome HOME
Porting to Qt4.
[modules/geom.git] / src / BuildGUI / BuildGUI_WireDlg.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_WireDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BuildGUI_WireDlg.h"
30 #include "GEOMImpl_Types.hxx"
31
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 #include "TColStd_MapOfInteger.hxx"
41
42 //=================================================================================
43 // class    : BuildGUI_WireDlg()
44 // purpose  : Constructs a BuildGUI_WireDlg 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_WireDlg::BuildGUI_WireDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
50                                    const char* name, bool modal, Qt::WindowFlags fl)
51   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
52 {
53   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_WIRE")));
54   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
55
56   setWindowTitle(tr("GEOM_WIRE_TITLE"));
57
58   /***************************************************************/
59   GroupConstructors->setTitle(tr("GEOM_WIRE"));
60   RadioButton1->setIcon(image0);
61   RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62   RadioButton2->close();
63   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64   RadioButton3->close();
65
66   GroupPoints = new Ui::DlgRef_1Sel_QTD();
67   QWidget* aGroupPointsWidget = new QWidget(this);
68   GroupPoints->setupUi(aGroupPointsWidget);
69   aGroupPointsWidget->setObjectName("GroupPoints");
70
71   GroupPoints->GroupBox1->setTitle(tr("GEOM_WIRE_CONNECT"));
72   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73   GroupPoints->PushButton1->setIcon(image1);
74   GroupPoints->LineEdit1->setReadOnly( true );
75
76   gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
77   /***************************************************************/
78
79   setHelpFileName("wire.htm");
80
81   /* Initialisations */
82   Init();
83 }
84
85
86 //=================================================================================
87 // function : ~BuildGUI_WireDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BuildGUI_WireDlg::~BuildGUI_WireDlg()
91 {
92   // no need to delete child widgets, Qt does it all for us
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void BuildGUI_WireDlg::Init()
101 {
102   /* init variables */
103   myEditCurrentArgument = GroupPoints->LineEdit1;
104   GroupPoints->LineEdit1->setReadOnly( true );
105   
106   myOkEdgesAndWires = false;
107   
108   TColStd_MapOfInteger aMap;
109   aMap.Add(GEOM_WIRE);
110   aMap.Add(GEOM_EDGE);
111   globalSelection( aMap );
112
113   /* signals and slots connections */
114   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
118           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
119   
120   initName(tr("GEOM_WIRE").toStdString().c_str());
121 }
122
123
124 //=================================================================================
125 // function : ClickOnOk()
126 // purpose  :
127 //=================================================================================
128 void BuildGUI_WireDlg::ClickOnOk()
129 {
130   if ( ClickOnApply() )
131     ClickOnCancel();
132 }
133
134
135 //=================================================================================
136 // function : ClickOnApply()
137 // purpose  :
138 //=================================================================================
139 bool BuildGUI_WireDlg::ClickOnApply()
140 {
141   if ( !onAccept() )
142     return false;
143
144   initName();
145   return true;
146 }
147
148
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose  : Called when selection as changed or other case
152 //=================================================================================
153 void BuildGUI_WireDlg::SelectionIntoArgument()
154 {
155   myEditCurrentArgument->setText("");
156   QString aString = ""; /* name of selection */
157
158   myOkEdgesAndWires = false;
159   int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
160
161   if(nbSel == 0)
162     return;
163   if(nbSel != 1)
164     aString = tr("%1_objects").arg(nbSel);
165
166   GEOMBase::ConvertListOfIOInListOfGO(selectedIO(),  myEdgesAndWires);
167   if (!myEdgesAndWires.length())
168     return;
169
170   myEditCurrentArgument->setText(aString);
171   myOkEdgesAndWires = true;
172 }
173
174
175 //=================================================================================
176 // function : SetEditCurrentArgument()
177 // purpose  :
178 //=================================================================================
179 void BuildGUI_WireDlg::SetEditCurrentArgument()
180 {
181   QPushButton* send = (QPushButton*)sender();
182   if (send != GroupPoints->PushButton1)
183     return;
184
185   TColStd_MapOfInteger aMap;
186   aMap.Add(GEOM_WIRE);
187   aMap.Add(GEOM_EDGE);
188   globalSelection( aMap );
189   myEditCurrentArgument = GroupPoints->LineEdit1;
190
191   myEditCurrentArgument->setFocus();
192   SelectionIntoArgument();
193 }
194
195
196 //=================================================================================
197 // function : ActivateThisDialog()
198 // purpose  :
199 //=================================================================================
200 void BuildGUI_WireDlg::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_WIRE);
207   aMap.Add(GEOM_EDGE);
208   globalSelection( aMap );
209 }
210
211
212 //=================================================================================
213 // function : enterEvent()
214 // purpose  :
215 //=================================================================================
216 void BuildGUI_WireDlg::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_WireDlg::createOperation()
227 {
228   return getGeomEngine()->GetIShapesOperations( getStudyId() );
229 }
230
231 //=================================================================================
232 // function : isValid
233 // purpose  :
234 //=================================================================================
235 bool BuildGUI_WireDlg::isValid( QString& )
236 {
237   return myOkEdgesAndWires;
238 }
239
240 //=================================================================================
241 // function : execute
242 // purpose  :
243 //=================================================================================
244 bool BuildGUI_WireDlg::execute( ObjectList& objects )
245 {
246   GEOM::GEOM_Object_var anObj;
247
248   anObj = GEOM::GEOM_IShapesOperations::_narrow(
249     getOperation() )->MakeWire( myEdgesAndWires );
250
251   if ( !anObj->_is_nil() )
252     objects.push_back( anObj._retn() );
253
254   return true;
255 }
256