Salome HOME
29f54f67138b360f67ad4b936cc27ec782d4d700
[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 #include <Precision.hxx>
41
42 //=================================================================================
43 // class    : BuildGUI_WireDlg()
44 // purpose  : Constructs a BuildGUI_WireDlg which is a child of 'parent', with the 
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 BuildGUI_WireDlg::BuildGUI_WireDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
50   : GEOMBase_Skeleton( theGeometryGUI, parent )
51 {
52   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_WIRE" ) ) );
53   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54
55   setWindowTitle( tr( "GEOM_WIRE_TITLE" ) );
56
57   /***************************************************************/
58   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WIRE" ) );
59   mainFrame()->RadioButton1->setIcon( image0 );
60   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton2->close();
62   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63   mainFrame()->RadioButton3->close();
64
65   GroupArgs = new DlgRef_1Sel1Spin( centralWidget() );
66
67   GroupArgs->GroupBox1->setTitle( tr( "GEOM_WIRE_CONNECT" ) );
68   GroupArgs->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69   GroupArgs->PushButton1->setIcon( image1 );
70   GroupArgs->LineEdit1->setReadOnly( true );
71
72   GroupArgs->TextLabel2->setText( tr( "GEOM_TOLERANCE" ) );
73   double SpecificStep = 0.0001;
74   double prec = Precision::Confusion();
75   initSpinBox(GroupArgs->SpinBox_DX, prec, MAX_NUMBER, SpecificStep, 9);
76   GroupArgs->SpinBox_DX->setValue(prec);
77
78   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79   layout->setMargin( 0 ); layout->setSpacing( 6 );
80   layout->addWidget( GroupArgs );
81   /***************************************************************/
82
83   setHelpFileName( "create_wire_page.html" );
84
85   /* Initialisations */
86   Init();
87 }
88
89
90 //=================================================================================
91 // function : ~BuildGUI_WireDlg()
92 // purpose  : Destroys the object and frees any allocated resources
93 //=================================================================================
94 BuildGUI_WireDlg::~BuildGUI_WireDlg()
95 {
96   // no need to delete child widgets, Qt does it all for us
97 }
98
99
100 //=================================================================================
101 // function : Init()
102 // purpose  :
103 //=================================================================================
104 void BuildGUI_WireDlg::Init()
105 {
106   /* init variables */
107   myEditCurrentArgument = GroupArgs->LineEdit1;
108   GroupArgs->LineEdit1->setReadOnly( true );
109   
110   myOkEdgesAndWires = false;
111   
112   TColStd_MapOfInteger aMap;
113   aMap.Add( GEOM_WIRE );
114   aMap.Add( GEOM_EDGE );
115   globalSelection( aMap );
116
117   /* signals and slots connections */
118   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
119   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
120   connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
122            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
123   
124   initName( tr( "GEOM_WIRE" ) );
125 }
126
127
128 //=================================================================================
129 // function : ClickOnOk()
130 // purpose  :
131 //=================================================================================
132 void BuildGUI_WireDlg::ClickOnOk()
133 {
134   if ( ClickOnApply() )
135     ClickOnCancel();
136 }
137
138
139 //=================================================================================
140 // function : ClickOnApply()
141 // purpose  :
142 //=================================================================================
143 bool BuildGUI_WireDlg::ClickOnApply()
144 {
145   if ( !onAccept() )
146     return false;
147
148   initName();
149   return true;
150 }
151
152
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose  : Called when selection as changed or other case
156 //=================================================================================
157 void BuildGUI_WireDlg::SelectionIntoArgument()
158 {
159   myEditCurrentArgument->setText( "" );
160   QString aString = ""; /* name of selection */
161
162   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
163   SALOME_ListIO aSelList;
164   aSelMgr->selectedObjects(aSelList);
165
166   myOkEdgesAndWires = false;
167   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString);
168
169   if ( nbSel == 0 )
170     return;
171   if ( nbSel != 1 )
172     aString = tr( "%1_objects" ).arg( nbSel );
173
174   GEOMBase::ConvertListOfIOInListOfGO(aSelList,  myEdgesAndWires);
175   if ( !myEdgesAndWires.length() )
176     return;
177
178   myEditCurrentArgument->setText( aString );
179   myOkEdgesAndWires = true;
180 }
181
182
183 //=================================================================================
184 // function : SetEditCurrentArgument()
185 // purpose  :
186 //=================================================================================
187 void BuildGUI_WireDlg::SetEditCurrentArgument()
188 {
189   QPushButton* send = (QPushButton*)sender();
190   if ( send != GroupArgs->PushButton1 )
191     return;
192
193   TColStd_MapOfInteger aMap;
194   aMap.Add( GEOM_WIRE );
195   aMap.Add( GEOM_EDGE );
196   globalSelection( aMap );
197   myEditCurrentArgument = GroupArgs->LineEdit1;
198
199   myEditCurrentArgument->setFocus();
200   SelectionIntoArgument();
201 }
202
203
204 //=================================================================================
205 // function : ActivateThisDialog()
206 // purpose  :
207 //=================================================================================
208 void BuildGUI_WireDlg::ActivateThisDialog()
209 {
210   GEOMBase_Skeleton::ActivateThisDialog();
211   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
212            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
213   TColStd_MapOfInteger aMap;
214   aMap.Add( GEOM_WIRE );
215   aMap.Add( GEOM_EDGE );
216   globalSelection( aMap );
217 }
218
219
220 //=================================================================================
221 // function : enterEvent()
222 // purpose  :
223 //=================================================================================
224 void BuildGUI_WireDlg::enterEvent( QEvent* )
225 {
226   if ( !mainFrame()->GroupConstructors->isEnabled() )
227     ActivateThisDialog();
228 }
229
230 //=================================================================================
231 // function : createOperation
232 // purpose  :
233 //=================================================================================
234 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
235 {
236   return getGeomEngine()->GetIShapesOperations( getStudyId() );
237 }
238
239 //=================================================================================
240 // function : isValid
241 // purpose  :
242 //=================================================================================
243 bool BuildGUI_WireDlg::isValid (QString& msg)
244 {
245   bool ok = GroupArgs->SpinBox_DX->isValid(msg, !IsPreview());
246   return myOkEdgesAndWires && ok;
247 }
248
249 //=================================================================================
250 // function : execute
251 // purpose  :
252 //=================================================================================
253 bool BuildGUI_WireDlg::execute (ObjectList& objects)
254 {
255   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
256   GEOM::GEOM_Object_var anObj = anOper->MakeWire(myEdgesAndWires, GroupArgs->SpinBox_DX->value());
257
258   if (!anObj->_is_nil())
259     objects.push_back(anObj._retn());
260
261   return true;
262 }