1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BuildGUI_WireDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BuildGUI_WireDlg.h"
29 #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>
41 #include <Precision.hxx>
43 //=================================================================================
44 // class : BuildGUI_WireDlg()
45 // purpose : Constructs a BuildGUI_WireDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 BuildGUI_WireDlg::BuildGUI_WireDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
51 : GEOMBase_Skeleton( theGeometryGUI, parent )
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 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WIRE" ) );
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton2->close();
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 GroupArgs = new DlgRef_1Sel1Spin( centralWidget() );
68 GroupArgs->GroupBox1->setTitle( tr( "GEOM_WIRE_CONNECT" ) );
69 GroupArgs->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
70 GroupArgs->PushButton1->setIcon( image1 );
71 GroupArgs->LineEdit1->setReadOnly( true );
73 GroupArgs->TextLabel2->setText( tr( "GEOM_TOLERANCE" ) );
74 double SpecificStep = 0.0001;
75 double prec = Precision::Confusion();
76 initSpinBox(GroupArgs->SpinBox_DX, prec, MAX_NUMBER, SpecificStep, "len_tol_precision" );
77 GroupArgs->SpinBox_DX->setValue(prec);
79 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
80 layout->setMargin( 0 ); layout->setSpacing( 6 );
81 layout->addWidget( GroupArgs );
82 /***************************************************************/
84 setHelpFileName( "create_wire_page.html" );
91 //=================================================================================
92 // function : ~BuildGUI_WireDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 BuildGUI_WireDlg::~BuildGUI_WireDlg()
97 // no need to delete child widgets, Qt does it all for us
101 //=================================================================================
104 //=================================================================================
105 void BuildGUI_WireDlg::Init()
108 myEditCurrentArgument = GroupArgs->LineEdit1;
109 GroupArgs->LineEdit1->setReadOnly( true );
111 myOkEdgesAndWires = false;
113 TColStd_MapOfInteger aMap;
114 aMap.Add( GEOM_WIRE );
115 aMap.Add( GEOM_EDGE );
116 globalSelection( aMap );
118 /* signals and slots connections */
119 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
120 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
121 connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
122 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
123 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
125 initName( tr( "GEOM_WIRE" ) );
129 //=================================================================================
130 // function : ClickOnOk()
132 //=================================================================================
133 void BuildGUI_WireDlg::ClickOnOk()
135 if ( ClickOnApply() )
140 //=================================================================================
141 // function : ClickOnApply()
143 //=================================================================================
144 bool BuildGUI_WireDlg::ClickOnApply()
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose : Called when selection as changed or other case
157 //=================================================================================
158 void BuildGUI_WireDlg::SelectionIntoArgument()
160 myEditCurrentArgument->setText( "" );
161 QString aString = ""; /* name of selection */
163 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
164 SALOME_ListIO aSelList;
165 aSelMgr->selectedObjects(aSelList);
167 myOkEdgesAndWires = false;
168 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString);
173 aString = tr( "%1_objects" ).arg( nbSel );
175 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myEdgesAndWires);
176 if ( !myEdgesAndWires.length() )
179 myEditCurrentArgument->setText( aString );
180 myOkEdgesAndWires = true;
184 //=================================================================================
185 // function : SetEditCurrentArgument()
187 //=================================================================================
188 void BuildGUI_WireDlg::SetEditCurrentArgument()
190 QPushButton* send = (QPushButton*)sender();
191 if ( send != GroupArgs->PushButton1 )
194 TColStd_MapOfInteger aMap;
195 aMap.Add( GEOM_WIRE );
196 aMap.Add( GEOM_EDGE );
197 globalSelection( aMap );
198 myEditCurrentArgument = GroupArgs->LineEdit1;
200 myEditCurrentArgument->setFocus();
201 SelectionIntoArgument();
205 //=================================================================================
206 // function : ActivateThisDialog()
208 //=================================================================================
209 void BuildGUI_WireDlg::ActivateThisDialog()
211 GEOMBase_Skeleton::ActivateThisDialog();
212 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
213 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
214 TColStd_MapOfInteger aMap;
215 aMap.Add( GEOM_WIRE );
216 aMap.Add( GEOM_EDGE );
217 globalSelection( aMap );
221 //=================================================================================
222 // function : enterEvent()
224 //=================================================================================
225 void BuildGUI_WireDlg::enterEvent( QEvent* )
227 if ( !mainFrame()->GroupConstructors->isEnabled() )
228 ActivateThisDialog();
231 //=================================================================================
232 // function : createOperation
234 //=================================================================================
235 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
237 return getGeomEngine()->GetIShapesOperations( getStudyId() );
240 //=================================================================================
241 // function : isValid
243 //=================================================================================
244 bool BuildGUI_WireDlg::isValid (QString& msg)
246 bool ok = GroupArgs->SpinBox_DX->isValid(msg, !IsPreview());
247 return myOkEdgesAndWires && ok;
250 //=================================================================================
251 // function : execute
253 //=================================================================================
254 bool BuildGUI_WireDlg::execute (ObjectList& objects)
256 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
257 GEOM::GEOM_Object_var anObj = anOper->MakeWire(myEdgesAndWires, GroupArgs->SpinBox_DX->value());
259 if (!anObj->_is_nil())
260 objects.push_back(anObj._retn());