1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : BuildGUI_WireDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BuildGUI_WireDlg.h"
30 #include "GEOMImpl_Types.hxx"
32 #include "GeometryGUI.h"
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Session.h"
37 #include "SalomeApp_Application.h"
38 #include "LightApp_SelectionMgr.h"
40 #include "TColStd_MapOfInteger.hxx"
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)
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")));
56 setWindowTitle(tr("GEOM_WIRE_TITLE"));
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();
66 GroupPoints = new Ui::DlgRef_1Sel_QTD();
67 QWidget* aGroupPointsWidget = new QWidget(this);
68 GroupPoints->setupUi(aGroupPointsWidget);
69 aGroupPointsWidget->setObjectName("GroupPoints");
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 );
76 gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
77 /***************************************************************/
79 setHelpFileName("wire.htm");
86 //=================================================================================
87 // function : ~BuildGUI_WireDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BuildGUI_WireDlg::~BuildGUI_WireDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void BuildGUI_WireDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 GroupPoints->LineEdit1->setReadOnly( true );
106 myOkEdgesAndWires = false;
108 TColStd_MapOfInteger aMap;
111 globalSelection( aMap );
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())) ;
120 initName(tr("GEOM_WIRE").toLatin1().constData());
124 //=================================================================================
125 // function : ClickOnOk()
127 //=================================================================================
128 void BuildGUI_WireDlg::ClickOnOk()
130 if ( ClickOnApply() )
135 //=================================================================================
136 // function : ClickOnApply()
138 //=================================================================================
139 bool BuildGUI_WireDlg::ClickOnApply()
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose : Called when selection as changed or other case
152 //=================================================================================
153 void BuildGUI_WireDlg::SelectionIntoArgument()
155 myEditCurrentArgument->setText("");
156 QString aString = ""; /* name of selection */
158 myOkEdgesAndWires = false;
159 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
164 aString = tr("%1_objects").arg(nbSel);
166 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myEdgesAndWires);
167 if (!myEdgesAndWires.length())
170 myEditCurrentArgument->setText(aString);
171 myOkEdgesAndWires = true;
175 //=================================================================================
176 // function : SetEditCurrentArgument()
178 //=================================================================================
179 void BuildGUI_WireDlg::SetEditCurrentArgument()
181 QPushButton* send = (QPushButton*)sender();
182 if (send != GroupPoints->PushButton1)
185 TColStd_MapOfInteger aMap;
188 globalSelection( aMap );
189 myEditCurrentArgument = GroupPoints->LineEdit1;
191 myEditCurrentArgument->setFocus();
192 SelectionIntoArgument();
196 //=================================================================================
197 // function : ActivateThisDialog()
199 //=================================================================================
200 void BuildGUI_WireDlg::ActivateThisDialog()
202 GEOMBase_Skeleton::ActivateThisDialog();
203 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
204 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
205 TColStd_MapOfInteger aMap;
208 globalSelection( aMap );
212 //=================================================================================
213 // function : enterEvent()
215 //=================================================================================
216 void BuildGUI_WireDlg::enterEvent(QEvent* e)
218 if ( !GroupConstructors->isEnabled() )
219 ActivateThisDialog();
222 //=================================================================================
223 // function : createOperation
225 //=================================================================================
226 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
228 return getGeomEngine()->GetIShapesOperations( getStudyId() );
231 //=================================================================================
232 // function : isValid
234 //=================================================================================
235 bool BuildGUI_WireDlg::isValid( QString& )
237 return myOkEdgesAndWires;
240 //=================================================================================
241 // function : execute
243 //=================================================================================
244 bool BuildGUI_WireDlg::execute( ObjectList& objects )
246 GEOM::GEOM_Object_var anObj;
248 anObj = GEOM::GEOM_IShapesOperations::_narrow(
249 getOperation() )->MakeWire( myEdgesAndWires );
251 if ( !anObj->_is_nil() )
252 objects.push_back( anObj._retn() );