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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : BuildGUI_WireDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BuildGUI_WireDlg.h"
30 #include "GEOMImpl_Types.hxx"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include "TColStd_MapOfInteger.hxx"
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)
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")));
53 setCaption(tr("GEOM_WIRE_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_WIRE"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->close(TRUE);
59 RadioButton3->close(TRUE);
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 );
67 Layout1->addWidget(GroupPoints, 2, 0);
68 /***************************************************************/
75 //=================================================================================
76 // function : ~BuildGUI_WireDlg()
77 // purpose : Destroys the object and frees any allocated resources
78 //=================================================================================
79 BuildGUI_WireDlg::~BuildGUI_WireDlg()
81 // no need to delete child widgets, Qt does it all for us
85 //=================================================================================
88 //=================================================================================
89 void BuildGUI_WireDlg::Init()
92 myEditCurrentArgument = GroupPoints->LineEdit1;
93 GroupPoints->LineEdit1->setReadOnly( true );
95 myOkEdgesAndWires = false;
97 TColStd_MapOfInteger aMap;
100 globalSelection( aMap );
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())) ;
109 initName(tr("GEOM_WIRE"));
113 //=================================================================================
114 // function : ClickOnOk()
116 //=================================================================================
117 void BuildGUI_WireDlg::ClickOnOk()
119 if ( ClickOnApply() )
124 //=================================================================================
125 // function : ClickOnApply()
127 //=================================================================================
128 bool BuildGUI_WireDlg::ClickOnApply()
138 //=================================================================================
139 // function : SelectionIntoArgument()
140 // purpose : Called when selection as changed or other case
141 //=================================================================================
142 void BuildGUI_WireDlg::SelectionIntoArgument()
144 myEditCurrentArgument->setText("");
145 QString aString = ""; /* name of selection */
147 myOkEdgesAndWires = false;
148 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
153 aString = tr("%1_objects").arg(nbSel);
155 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myEdgesAndWires);
156 if (!myEdgesAndWires.length())
159 myEditCurrentArgument->setText(aString);
160 myOkEdgesAndWires = true;
164 //=================================================================================
165 // function : SetEditCurrentArgument()
167 //=================================================================================
168 void BuildGUI_WireDlg::SetEditCurrentArgument()
170 QPushButton* send = (QPushButton*)sender();
171 if (send != GroupPoints->PushButton1)
174 TColStd_MapOfInteger aMap;
177 globalSelection( aMap );
178 myEditCurrentArgument = GroupPoints->LineEdit1;
180 myEditCurrentArgument->setFocus();
181 SelectionIntoArgument();
185 //=================================================================================
186 // function : ActivateThisDialog()
188 //=================================================================================
189 void BuildGUI_WireDlg::ActivateThisDialog()
191 GEOMBase_Skeleton::ActivateThisDialog();
192 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
193 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
194 TColStd_MapOfInteger aMap;
197 globalSelection( aMap );
201 //=================================================================================
202 // function : enterEvent()
204 //=================================================================================
205 void BuildGUI_WireDlg::enterEvent(QEvent* e)
207 if ( !GroupConstructors->isEnabled() )
208 ActivateThisDialog();
211 //=================================================================================
212 // function : createOperation
214 //=================================================================================
215 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
217 return getGeomEngine()->GetIShapesOperations( getStudyId() );
220 //=================================================================================
221 // function : isValid
223 //=================================================================================
224 bool BuildGUI_WireDlg::isValid( QString& )
226 return myOkEdgesAndWires;
229 //=================================================================================
230 // function : execute
232 //=================================================================================
233 bool BuildGUI_WireDlg::execute( ObjectList& objects )
235 GEOM::GEOM_Object_var anObj;
237 anObj = GEOM::GEOM_IShapesOperations::_narrow(
238 getOperation() )->MakeWire( myEdgesAndWires );
240 if ( !anObj->_is_nil() )
241 objects.push_back( anObj._retn() );