Salome HOME
Merge from V5_1_4_BR 07/05/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 }
127
128
129 //=================================================================================
130 // function : ClickOnOk()
131 // purpose  :
132 //=================================================================================
133 void BuildGUI_WireDlg::ClickOnOk()
134 {
135   if ( ClickOnApply() )
136     ClickOnCancel();
137 }
138
139
140 //=================================================================================
141 // function : ClickOnApply()
142 // purpose  :
143 //=================================================================================
144 bool BuildGUI_WireDlg::ClickOnApply()
145 {
146   if ( !onAccept() )
147     return false;
148
149   initName();
150   return true;
151 }
152
153
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose  : Called when selection as changed or other case
157 //=================================================================================
158 void BuildGUI_WireDlg::SelectionIntoArgument()
159 {
160   myEditCurrentArgument->setText( "" );
161   QString aString = ""; /* name of selection */
162
163   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
164   SALOME_ListIO aSelList;
165   aSelMgr->selectedObjects(aSelList);
166
167   myOkEdgesAndWires = false;
168   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString);
169
170   if ( nbSel == 0 )
171     return;
172   if ( nbSel != 1 )
173     aString = tr( "%1_objects" ).arg( nbSel );
174
175   GEOMBase::ConvertListOfIOInListOfGO(aSelList,  myEdgesAndWires);
176   if ( !myEdgesAndWires.length() )
177     return;
178
179   myEditCurrentArgument->setText( aString );
180   myOkEdgesAndWires = true;
181 }
182
183
184 //=================================================================================
185 // function : SetEditCurrentArgument()
186 // purpose  :
187 //=================================================================================
188 void BuildGUI_WireDlg::SetEditCurrentArgument()
189 {
190   QPushButton* send = (QPushButton*)sender();
191   if ( send != GroupArgs->PushButton1 )
192     return;
193
194   TColStd_MapOfInteger aMap;
195   aMap.Add( GEOM_WIRE );
196   aMap.Add( GEOM_EDGE );
197   globalSelection( aMap );
198   myEditCurrentArgument = GroupArgs->LineEdit1;
199
200   myEditCurrentArgument->setFocus();
201   SelectionIntoArgument();
202 }
203
204
205 //=================================================================================
206 // function : ActivateThisDialog()
207 // purpose  :
208 //=================================================================================
209 void BuildGUI_WireDlg::ActivateThisDialog()
210 {
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 );
218 }
219
220
221 //=================================================================================
222 // function : enterEvent()
223 // purpose  :
224 //=================================================================================
225 void BuildGUI_WireDlg::enterEvent( QEvent* )
226 {
227   if ( !mainFrame()->GroupConstructors->isEnabled() )
228     ActivateThisDialog();
229 }
230
231 //=================================================================================
232 // function : createOperation
233 // purpose  :
234 //=================================================================================
235 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
236 {
237   return getGeomEngine()->GetIShapesOperations( getStudyId() );
238 }
239
240 //=================================================================================
241 // function : isValid
242 // purpose  :
243 //=================================================================================
244 bool BuildGUI_WireDlg::isValid (QString& msg)
245 {
246   bool ok = GroupArgs->SpinBox_DX->isValid(msg, !IsPreview());
247   return myOkEdgesAndWires && ok;
248 }
249
250 //=================================================================================
251 // function : execute
252 // purpose  :
253 //=================================================================================
254 bool BuildGUI_WireDlg::execute (ObjectList& objects)
255 {
256   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
257   GEOM::GEOM_Object_var anObj = anOper->MakeWire(myEdgesAndWires, GroupArgs->SpinBox_DX->value());
258
259   if (!anObj->_is_nil())
260     objects.push_back(anObj._retn());
261
262   return true;
263 }