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, Open CASCADE S.A.S.
26 #include "BuildGUI_WireDlg.h"
28 #include <GEOMImpl_Types.hxx>
31 #include <GeometryGUI.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <TColStd_MapOfInteger.hxx>
40 #include <Precision.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 : GEOMBase_Skeleton( theGeometryGUI, parent )
52 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_WIRE" ) ) );
53 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55 setWindowTitle( tr( "GEOM_WIRE_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WIRE" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton2->close();
62 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63 mainFrame()->RadioButton3->close();
65 GroupArgs = new DlgRef_1Sel1Spin( centralWidget() );
67 GroupArgs->GroupBox1->setTitle( tr( "GEOM_WIRE_CONNECT" ) );
68 GroupArgs->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69 GroupArgs->PushButton1->setIcon( image1 );
70 GroupArgs->LineEdit1->setReadOnly( true );
72 GroupArgs->TextLabel2->setText( tr( "GEOM_TOLERANCE" ) );
73 double SpecificStep = 0.0001;
74 double prec = Precision::Confusion();
75 initSpinBox(GroupArgs->SpinBox_DX, prec, MAX_NUMBER, SpecificStep, 9);
76 GroupArgs->SpinBox_DX->setValue(prec);
78 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79 layout->setMargin( 0 ); layout->setSpacing( 6 );
80 layout->addWidget( GroupArgs );
81 /***************************************************************/
83 setHelpFileName( "create_wire_page.html" );
90 //=================================================================================
91 // function : ~BuildGUI_WireDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 BuildGUI_WireDlg::~BuildGUI_WireDlg()
96 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void BuildGUI_WireDlg::Init()
107 myEditCurrentArgument = GroupArgs->LineEdit1;
108 GroupArgs->LineEdit1->setReadOnly( true );
110 myOkEdgesAndWires = false;
112 TColStd_MapOfInteger aMap;
113 aMap.Add( GEOM_WIRE );
114 aMap.Add( GEOM_EDGE );
115 globalSelection( aMap );
117 /* signals and slots connections */
118 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
119 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
120 connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
122 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
124 initName( tr( "GEOM_WIRE" ) );
128 //=================================================================================
129 // function : ClickOnOk()
131 //=================================================================================
132 void BuildGUI_WireDlg::ClickOnOk()
134 if ( ClickOnApply() )
139 //=================================================================================
140 // function : ClickOnApply()
142 //=================================================================================
143 bool BuildGUI_WireDlg::ClickOnApply()
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose : Called when selection as changed or other case
156 //=================================================================================
157 void BuildGUI_WireDlg::SelectionIntoArgument()
159 myEditCurrentArgument->setText( "" );
160 QString aString = ""; /* name of selection */
162 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
163 SALOME_ListIO aSelList;
164 aSelMgr->selectedObjects(aSelList);
166 myOkEdgesAndWires = false;
167 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString);
172 aString = tr( "%1_objects" ).arg( nbSel );
174 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myEdgesAndWires);
175 if ( !myEdgesAndWires.length() )
178 myEditCurrentArgument->setText( aString );
179 myOkEdgesAndWires = true;
183 //=================================================================================
184 // function : SetEditCurrentArgument()
186 //=================================================================================
187 void BuildGUI_WireDlg::SetEditCurrentArgument()
189 QPushButton* send = (QPushButton*)sender();
190 if ( send != GroupArgs->PushButton1 )
193 TColStd_MapOfInteger aMap;
194 aMap.Add( GEOM_WIRE );
195 aMap.Add( GEOM_EDGE );
196 globalSelection( aMap );
197 myEditCurrentArgument = GroupArgs->LineEdit1;
199 myEditCurrentArgument->setFocus();
200 SelectionIntoArgument();
204 //=================================================================================
205 // function : ActivateThisDialog()
207 //=================================================================================
208 void BuildGUI_WireDlg::ActivateThisDialog()
210 GEOMBase_Skeleton::ActivateThisDialog();
211 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
212 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
213 TColStd_MapOfInteger aMap;
214 aMap.Add( GEOM_WIRE );
215 aMap.Add( GEOM_EDGE );
216 globalSelection( aMap );
220 //=================================================================================
221 // function : enterEvent()
223 //=================================================================================
224 void BuildGUI_WireDlg::enterEvent( QEvent* )
226 if ( !mainFrame()->GroupConstructors->isEnabled() )
227 ActivateThisDialog();
230 //=================================================================================
231 // function : createOperation
233 //=================================================================================
234 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
236 return getGeomEngine()->GetIShapesOperations( getStudyId() );
239 //=================================================================================
240 // function : isValid
242 //=================================================================================
243 bool BuildGUI_WireDlg::isValid (QString& msg)
245 bool ok = GroupArgs->SpinBox_DX->isValid(msg, !IsPreview());
246 return myOkEdgesAndWires && ok;
249 //=================================================================================
250 // function : execute
252 //=================================================================================
253 bool BuildGUI_WireDlg::execute (ObjectList& objects)
255 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
256 GEOM::GEOM_Object_var anObj = anOper->MakeWire(myEdgesAndWires, GroupArgs->SpinBox_DX->value());
258 if (!anObj->_is_nil())
259 objects.push_back(anObj._retn());