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