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