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