1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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>
39 #include <SALOME_ListIO.hxx>
41 #include <TColStd_MapOfInteger.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <Precision.hxx>
46 //=================================================================================
47 // class : BuildGUI_WireDlg()
48 // purpose : Constructs a BuildGUI_WireDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 BuildGUI_WireDlg::BuildGUI_WireDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
54 : GEOMBase_Skeleton( theGeometryGUI, parent )
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_WIRE" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 setWindowTitle( tr( "GEOM_WIRE_TITLE" ) );
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WIRE" ) );
63 mainFrame()->RadioButton1->setIcon( image0 );
64 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
65 mainFrame()->RadioButton2->close();
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupType = new DlgRef_3Radio( centralWidget() );
70 GroupType->GroupBox1->setTitle( tr( "GEOM_OBJECT_TYPE" ) );
71 GroupType->RadioButton1->setText( tr( "GEOM_EDGE" ) );
72 GroupType->RadioButton2->setText( tr( "GEOM_WIRE" ) );
73 GroupType->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
74 GroupType->RadioButton3->close();
76 GroupArgs = new DlgRef_1Sel1Spin( centralWidget() );
77 GroupArgs->GroupBox1->setTitle( tr( "GEOM_WIRE_CONNECT" ) );
78 GroupArgs->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
79 GroupArgs->PushButton1->setIcon( image1 );
80 GroupArgs->LineEdit1->setReadOnly( true );
82 GroupArgs->TextLabel2->setText( tr( "GEOM_TOLERANCE" ) );
83 double SpecificStep = 0.0001;
84 double prec = Precision::Confusion();
85 initSpinBox(GroupArgs->SpinBox_DX, prec, MAX_NUMBER, SpecificStep, "len_tol_precision" );
86 GroupArgs->SpinBox_DX->setValue(prec);
88 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
89 layout->setMargin( 0 ); layout->setSpacing( 6 );
90 layout->addWidget( GroupType );
91 layout->addWidget( GroupArgs );
92 /***************************************************************/
94 setHelpFileName( "create_wire_page.html" );
101 //=================================================================================
102 // function : ~BuildGUI_WireDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 BuildGUI_WireDlg::~BuildGUI_WireDlg()
107 // no need to delete child widgets, Qt does it all for us
111 //=================================================================================
114 //=================================================================================
115 void BuildGUI_WireDlg::Init()
118 myEditCurrentArgument = GroupArgs->LineEdit1;
119 GroupArgs->LineEdit1->setReadOnly( true );
120 GroupType->RadioButton1->setChecked(true);
122 myEdgesAndWires.clear();
124 localSelection( TopAbs_EDGE );
126 /* signals and slots connections */
127 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
128 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
129 connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
130 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
131 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
133 connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
134 connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
136 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
137 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
139 initName( tr( "GEOM_WIRE" ) );
140 SelectionIntoArgument();
144 //=================================================================================
145 // function : ClickOnOk()
147 //=================================================================================
148 void BuildGUI_WireDlg::ClickOnOk()
150 setIsApplyAndClose( true );
151 if ( ClickOnApply() )
156 //=================================================================================
157 // function : ClickOnApply()
159 //=================================================================================
160 bool BuildGUI_WireDlg::ClickOnApply()
167 myEdgesAndWires.clear();
168 myEditCurrentArgument->setText( "" );
172 //=================================================================================
173 // function : TypeBittonClicked()
174 // purpose : Radio button management
175 //=================================================================================
176 void BuildGUI_WireDlg::TypeButtonClicked()
178 if ( GroupType->RadioButton1->isChecked() ) {
179 globalSelection(); // close local contexts, if any
180 localSelection( TopAbs_EDGE );
181 GroupArgs->TextLabel1->setText( tr( "GEOM_EDGE" ) );
183 else if ( GroupType->RadioButton2->isChecked() ) {
184 globalSelection(); // close local contexts, if any
185 localSelection( TopAbs_WIRE );
186 GroupArgs->TextLabel1->setText( tr( "GEOM_WIRE" ) );
188 SelectionIntoArgument();
191 //=================================================================================
192 // function : SelectionIntoArgument()
193 // purpose : Called when selection as changed or other case
194 //=================================================================================
195 void BuildGUI_WireDlg::SelectionIntoArgument()
197 myEditCurrentArgument->setText( "" );
199 QList<TopAbs_ShapeEnum> types;
200 types << TopAbs_EDGE << TopAbs_WIRE;
201 myEdgesAndWires = getSelected( types, -1 );
203 if ( !myEdgesAndWires.isEmpty() ) {
204 QString aName = myEdgesAndWires.count() > 1 ? QString( "%1_objects").arg( myEdgesAndWires.count() ) : GEOMBase::GetName( myEdgesAndWires[0].get() );
205 myEditCurrentArgument->setText( aName );
210 //=================================================================================
211 // function : SetEditCurrentArgument()
213 //=================================================================================
214 void BuildGUI_WireDlg::SetEditCurrentArgument()
216 QPushButton* send = (QPushButton*)sender();
217 if ( send != GroupArgs->PushButton1 )
221 myEditCurrentArgument = GroupArgs->LineEdit1;
223 myEditCurrentArgument->setFocus();
224 SelectionIntoArgument();
228 //=================================================================================
229 // function : ActivateThisDialog()
231 //=================================================================================
232 void BuildGUI_WireDlg::ActivateThisDialog()
234 GEOMBase_Skeleton::ActivateThisDialog();
235 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
236 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
241 //=================================================================================
242 // function : DeactivateActiveDialog()
243 // purpose : public slot to deactivate if active
244 //=================================================================================
245 void BuildGUI_WireDlg::DeactivateActiveDialog()
247 GEOMBase_Skeleton::DeactivateActiveDialog();
250 //=================================================================================
251 // function : enterEvent()
253 //=================================================================================
254 void BuildGUI_WireDlg::enterEvent( QEvent* )
256 if ( !mainFrame()->GroupConstructors->isEnabled() )
257 ActivateThisDialog();
260 //=================================================================================
261 // function : createOperation
263 //=================================================================================
264 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
266 return getGeomEngine()->GetIShapesOperations( getStudyId() );
269 //=================================================================================
270 // function : isValid
272 //=================================================================================
273 bool BuildGUI_WireDlg::isValid (QString& msg)
275 return GroupArgs->SpinBox_DX->isValid(msg, !IsPreview()) && !myEdgesAndWires.isEmpty();
278 //=================================================================================
279 // function : execute
281 //=================================================================================
282 bool BuildGUI_WireDlg::execute (ObjectList& objects)
284 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
286 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
287 objlist->length( myEdgesAndWires.count() );
288 for ( int i = 0; i < myEdgesAndWires.count(); i++ )
289 objlist[i] = myEdgesAndWires[i].copy();
291 GEOM::GEOM_Object_var anObj = anOper->MakeWire(objlist.in(), GroupArgs->SpinBox_DX->value());
293 if (!anObj->_is_nil())
294 objects.push_back(anObj._retn());
299 //=================================================================================
300 // function : addSubshapeToStudy
301 // purpose : virtual method to add new SubObjects if local selection
302 //=================================================================================
303 void BuildGUI_WireDlg::addSubshapesToStudy()
305 for ( int i = 0; i < myEdgesAndWires.count(); i++ )
306 GEOMBase::PublishSubObject( myEdgesAndWires[i].get() );
309 //=================================================================================
310 // function : getSourceObjects
311 // purpose : virtual method to get source objects
312 //=================================================================================
313 QList<GEOM::GeomObjPtr> BuildGUI_WireDlg::getSourceObjects()
315 return myEdgesAndWires;