1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BuildGUI_WireDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "BuildGUI_WireDlg.h"
29 #include "GEOMImpl_Types.hxx"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include "TColStd_MapOfInteger.hxx"
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)
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")));
54 setCaption(tr("GEOM_WIRE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_WIRE"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->close(TRUE);
60 RadioButton3->close(TRUE);
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 );
68 Layout1->addWidget(GroupPoints, 2, 0);
69 /***************************************************************/
71 setHelpFileName("create_wire_page.html");
78 //=================================================================================
79 // function : ~BuildGUI_WireDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 BuildGUI_WireDlg::~BuildGUI_WireDlg()
84 // no need to delete child widgets, Qt does it all for us
88 //=================================================================================
91 //=================================================================================
92 void BuildGUI_WireDlg::Init()
95 myEditCurrentArgument = GroupPoints->LineEdit1;
96 GroupPoints->LineEdit1->setReadOnly( true );
98 myOkEdgesAndWires = false;
100 TColStd_MapOfInteger aMap;
103 globalSelection( aMap );
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())) ;
112 initName(tr("GEOM_WIRE"));
116 //=================================================================================
117 // function : ClickOnOk()
119 //=================================================================================
120 void BuildGUI_WireDlg::ClickOnOk()
122 if ( ClickOnApply() )
127 //=================================================================================
128 // function : ClickOnApply()
130 //=================================================================================
131 bool BuildGUI_WireDlg::ClickOnApply()
141 //=================================================================================
142 // function : SelectionIntoArgument()
143 // purpose : Called when selection as changed or other case
144 //=================================================================================
145 void BuildGUI_WireDlg::SelectionIntoArgument()
147 myEditCurrentArgument->setText("");
148 QString aString = ""; /* name of selection */
150 myOkEdgesAndWires = false;
151 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
156 aString = tr("%1_objects").arg(nbSel);
158 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myEdgesAndWires);
159 if (!myEdgesAndWires.length())
162 myEditCurrentArgument->setText(aString);
163 myOkEdgesAndWires = true;
167 //=================================================================================
168 // function : SetEditCurrentArgument()
170 //=================================================================================
171 void BuildGUI_WireDlg::SetEditCurrentArgument()
173 QPushButton* send = (QPushButton*)sender();
174 if (send != GroupPoints->PushButton1)
177 TColStd_MapOfInteger aMap;
180 globalSelection( aMap );
181 myEditCurrentArgument = GroupPoints->LineEdit1;
183 myEditCurrentArgument->setFocus();
184 SelectionIntoArgument();
188 //=================================================================================
189 // function : ActivateThisDialog()
191 //=================================================================================
192 void BuildGUI_WireDlg::ActivateThisDialog()
194 GEOMBase_Skeleton::ActivateThisDialog();
195 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
196 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
197 TColStd_MapOfInteger aMap;
200 globalSelection( aMap );
204 //=================================================================================
205 // function : enterEvent()
207 //=================================================================================
208 void BuildGUI_WireDlg::enterEvent(QEvent* e)
210 if ( !GroupConstructors->isEnabled() )
211 ActivateThisDialog();
214 //=================================================================================
215 // function : createOperation
217 //=================================================================================
218 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
220 return getGeomEngine()->GetIShapesOperations( getStudyId() );
223 //=================================================================================
224 // function : isValid
226 //=================================================================================
227 bool BuildGUI_WireDlg::isValid( QString& )
229 return myOkEdgesAndWires;
232 //=================================================================================
233 // function : execute
235 //=================================================================================
236 bool BuildGUI_WireDlg::execute( ObjectList& objects )
238 GEOM::GEOM_Object_var anObj;
240 anObj = GEOM::GEOM_IShapesOperations::_narrow(
241 getOperation() )->MakeWire( myEdgesAndWires );
243 if ( !anObj->_is_nil() )
244 objects.push_back( anObj._retn() );