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