]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_WireDlg.cxx
Salome HOME
Merge from V5_1_main 10/06/2010
[modules/geom.git] / src / BuildGUI / BuildGUI_WireDlg.cxx
1 //  Copyright (C) 2007-2010  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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : BuildGUI_WireDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 //
27 #include "BuildGUI_WireDlg.h"
28
29 #include <GEOMImpl_Types.hxx>
30
31 #include <DlgRef.h>
32 #include <GeometryGUI.h>
33 #include <GEOMBase.h>
34
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39
40 #include <TColStd_MapOfInteger.hxx>
41 #include <Precision.hxx>
42
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 )
52 {
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" ) ) );
55
56   setWindowTitle( tr( "GEOM_WIRE_TITLE" ) );
57
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();
65
66   GroupArgs = new DlgRef_1Sel1Spin( centralWidget() );
67
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 );
72
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);
78
79   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
80   layout->setMargin( 0 ); layout->setSpacing( 6 );
81   layout->addWidget( GroupArgs );
82   /***************************************************************/
83
84   setHelpFileName( "create_wire_page.html" );
85
86   /* Initialisations */
87   Init();
88 }
89
90
91 //=================================================================================
92 // function : ~BuildGUI_WireDlg()
93 // purpose  : Destroys the object and frees any allocated resources
94 //=================================================================================
95 BuildGUI_WireDlg::~BuildGUI_WireDlg()
96 {
97   // no need to delete child widgets, Qt does it all for us
98 }
99
100
101 //=================================================================================
102 // function : Init()
103 // purpose  :
104 //=================================================================================
105 void BuildGUI_WireDlg::Init()
106 {
107   /* init variables */
108   myEditCurrentArgument = GroupArgs->LineEdit1;
109   GroupArgs->LineEdit1->setReadOnly( true );
110   
111   myOkEdgesAndWires = false;
112   
113   TColStd_MapOfInteger aMap;
114   aMap.Add( GEOM_WIRE );
115   aMap.Add( GEOM_EDGE );
116   globalSelection( aMap );
117
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() ) );
124   
125   initName( tr( "GEOM_WIRE" ) );
126   SelectionIntoArgument();
127 }
128
129
130 //=================================================================================
131 // function : ClickOnOk()
132 // purpose  :
133 //=================================================================================
134 void BuildGUI_WireDlg::ClickOnOk()
135 {
136   if ( ClickOnApply() )
137     ClickOnCancel();
138 }
139
140
141 //=================================================================================
142 // function : ClickOnApply()
143 // purpose  :
144 //=================================================================================
145 bool BuildGUI_WireDlg::ClickOnApply()
146 {
147   if ( !onAccept() )
148     return false;
149
150   initName();
151   return true;
152 }
153
154
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose  : Called when selection as changed or other case
158 //=================================================================================
159 void BuildGUI_WireDlg::SelectionIntoArgument()
160 {
161   myEditCurrentArgument->setText( "" );
162   QString aString = ""; /* name of selection */
163
164   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
165   SALOME_ListIO aSelList;
166   aSelMgr->selectedObjects(aSelList);
167
168   myOkEdgesAndWires = false;
169   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString);
170
171   if ( nbSel == 0 )
172     return;
173   if ( nbSel != 1 )
174     aString = tr( "%1_objects" ).arg( nbSel );
175
176   GEOMBase::ConvertListOfIOInListOfGO(aSelList,  myEdgesAndWires);
177   if ( !myEdgesAndWires.length() )
178     return;
179
180   myEditCurrentArgument->setText( aString );
181   myOkEdgesAndWires = true;
182 }
183
184
185 //=================================================================================
186 // function : SetEditCurrentArgument()
187 // purpose  :
188 //=================================================================================
189 void BuildGUI_WireDlg::SetEditCurrentArgument()
190 {
191   QPushButton* send = (QPushButton*)sender();
192   if ( send != GroupArgs->PushButton1 )
193     return;
194
195   TColStd_MapOfInteger aMap;
196   aMap.Add( GEOM_WIRE );
197   aMap.Add( GEOM_EDGE );
198   globalSelection( aMap );
199   myEditCurrentArgument = GroupArgs->LineEdit1;
200
201   myEditCurrentArgument->setFocus();
202   SelectionIntoArgument();
203 }
204
205
206 //=================================================================================
207 // function : ActivateThisDialog()
208 // purpose  :
209 //=================================================================================
210 void BuildGUI_WireDlg::ActivateThisDialog()
211 {
212   GEOMBase_Skeleton::ActivateThisDialog();
213   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
214            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
215   TColStd_MapOfInteger aMap;
216   aMap.Add( GEOM_WIRE );
217   aMap.Add( GEOM_EDGE );
218   globalSelection( aMap );
219 }
220
221
222 //=================================================================================
223 // function : enterEvent()
224 // purpose  :
225 //=================================================================================
226 void BuildGUI_WireDlg::enterEvent( QEvent* )
227 {
228   if ( !mainFrame()->GroupConstructors->isEnabled() )
229     ActivateThisDialog();
230 }
231
232 //=================================================================================
233 // function : createOperation
234 // purpose  :
235 //=================================================================================
236 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
237 {
238   return getGeomEngine()->GetIShapesOperations( getStudyId() );
239 }
240
241 //=================================================================================
242 // function : isValid
243 // purpose  :
244 //=================================================================================
245 bool BuildGUI_WireDlg::isValid (QString& msg)
246 {
247   bool ok = GroupArgs->SpinBox_DX->isValid(msg, !IsPreview());
248   return myOkEdgesAndWires && ok;
249 }
250
251 //=================================================================================
252 // function : execute
253 // purpose  :
254 //=================================================================================
255 bool BuildGUI_WireDlg::execute (ObjectList& objects)
256 {
257   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
258   GEOM::GEOM_Object_var anObj = anOper->MakeWire(myEdgesAndWires, GroupArgs->SpinBox_DX->value());
259
260   if (!anObj->_is_nil())
261     objects.push_back(anObj._retn());
262
263   return true;
264 }