]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_WireDlg.cxx
Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / BuildGUI / BuildGUI_WireDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BuildGUI_WireDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 //
26 #include "BuildGUI_WireDlg.h"
27
28 #include <GEOMImpl_Types.hxx>
29
30 #include <DlgRef.h>
31 #include <GeometryGUI.h>
32 #include <GEOMBase.h>
33
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 #include <TColStd_MapOfInteger.hxx>
40
41 //=================================================================================
42 // class    : BuildGUI_WireDlg()
43 // purpose  : Constructs a BuildGUI_WireDlg which is a child of 'parent', with the 
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 BuildGUI_WireDlg::BuildGUI_WireDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
49   : GEOMBase_Skeleton( theGeometryGUI, parent )
50 {
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" ) ) );
53
54   setWindowTitle( tr( "GEOM_WIRE_TITLE" ) );
55
56   /***************************************************************/
57   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WIRE" ) );
58   mainFrame()->RadioButton1->setIcon( image0 );
59   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60   mainFrame()->RadioButton2->close();
61   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62   mainFrame()->RadioButton3->close();
63
64   GroupPoints = new DlgRef_1Sel( centralWidget() );
65
66   GroupPoints->GroupBox1->setTitle( tr( "GEOM_WIRE_CONNECT" ) );
67   GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
68   GroupPoints->PushButton1->setIcon( image1 );
69   GroupPoints->LineEdit1->setReadOnly( true );
70
71   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72   layout->setMargin( 0 ); layout->setSpacing( 6 );
73   layout->addWidget( GroupPoints );
74   /***************************************************************/
75
76   setHelpFileName( "create_wire_page.html" );
77
78   /* Initialisations */
79   Init();
80 }
81
82
83 //=================================================================================
84 // function : ~BuildGUI_WireDlg()
85 // purpose  : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BuildGUI_WireDlg::~BuildGUI_WireDlg()
88 {
89   // no need to delete child widgets, Qt does it all for us
90 }
91
92
93 //=================================================================================
94 // function : Init()
95 // purpose  :
96 //=================================================================================
97 void BuildGUI_WireDlg::Init()
98 {
99   /* init variables */
100   myEditCurrentArgument = GroupPoints->LineEdit1;
101   GroupPoints->LineEdit1->setReadOnly( true );
102   
103   myOkEdgesAndWires = false;
104   
105   TColStd_MapOfInteger aMap;
106   aMap.Add( GEOM_WIRE );
107   aMap.Add( GEOM_EDGE );
108   globalSelection( aMap );
109
110   /* signals and slots connections */
111   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
112   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
113   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
114   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
115            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
116   
117   initName( tr( "GEOM_WIRE" ) );
118 }
119
120
121 //=================================================================================
122 // function : ClickOnOk()
123 // purpose  :
124 //=================================================================================
125 void BuildGUI_WireDlg::ClickOnOk()
126 {
127   if ( ClickOnApply() )
128     ClickOnCancel();
129 }
130
131
132 //=================================================================================
133 // function : ClickOnApply()
134 // purpose  :
135 //=================================================================================
136 bool BuildGUI_WireDlg::ClickOnApply()
137 {
138   if ( !onAccept() )
139     return false;
140
141   initName();
142   return true;
143 }
144
145
146 //=================================================================================
147 // function : SelectionIntoArgument()
148 // purpose  : Called when selection as changed or other case
149 //=================================================================================
150 void BuildGUI_WireDlg::SelectionIntoArgument()
151 {
152   myEditCurrentArgument->setText( "" );
153   QString aString = ""; /* name of selection */
154
155   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
156   SALOME_ListIO aSelList;
157   aSelMgr->selectedObjects(aSelList);
158
159   myOkEdgesAndWires = false;
160   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString);
161
162   if ( nbSel == 0 )
163     return;
164   if ( nbSel != 1 )
165     aString = tr( "%1_objects" ).arg( nbSel );
166
167   GEOMBase::ConvertListOfIOInListOfGO(aSelList,  myEdgesAndWires);
168   if ( !myEdgesAndWires.length() )
169     return;
170
171   myEditCurrentArgument->setText( aString );
172   myOkEdgesAndWires = true;
173 }
174
175
176 //=================================================================================
177 // function : SetEditCurrentArgument()
178 // purpose  :
179 //=================================================================================
180 void BuildGUI_WireDlg::SetEditCurrentArgument()
181 {
182   QPushButton* send = (QPushButton*)sender();
183   if ( send != GroupPoints->PushButton1 )
184     return;
185
186   TColStd_MapOfInteger aMap;
187   aMap.Add( GEOM_WIRE );
188   aMap.Add( GEOM_EDGE );
189   globalSelection( aMap );
190   myEditCurrentArgument = GroupPoints->LineEdit1;
191
192   myEditCurrentArgument->setFocus();
193   SelectionIntoArgument();
194 }
195
196
197 //=================================================================================
198 // function : ActivateThisDialog()
199 // purpose  :
200 //=================================================================================
201 void BuildGUI_WireDlg::ActivateThisDialog()
202 {
203   GEOMBase_Skeleton::ActivateThisDialog();
204   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
205            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
206   TColStd_MapOfInteger aMap;
207   aMap.Add( GEOM_WIRE );
208   aMap.Add( GEOM_EDGE );
209   globalSelection( aMap );
210 }
211
212
213 //=================================================================================
214 // function : enterEvent()
215 // purpose  :
216 //=================================================================================
217 void BuildGUI_WireDlg::enterEvent( QEvent* )
218 {
219   if ( !mainFrame()->GroupConstructors->isEnabled() )
220     ActivateThisDialog();
221 }
222
223 //=================================================================================
224 // function : createOperation
225 // purpose  :
226 //=================================================================================
227 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
228 {
229   return getGeomEngine()->GetIShapesOperations( getStudyId() );
230 }
231
232 //=================================================================================
233 // function : isValid
234 // purpose  :
235 //=================================================================================
236 bool BuildGUI_WireDlg::isValid( QString& )
237 {
238   return myOkEdgesAndWires;
239 }
240
241 //=================================================================================
242 // function : execute
243 // purpose  :
244 //=================================================================================
245 bool BuildGUI_WireDlg::execute( ObjectList& objects )
246 {
247   GEOM::GEOM_Object_var anObj;
248
249   anObj = GEOM::GEOM_IShapesOperations::_narrow(
250     getOperation() )->MakeWire( myEdgesAndWires );
251
252   if ( !anObj->_is_nil() )
253     objects.push_back( anObj._retn() );
254
255   return true;
256 }
257