]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_LineDlg.cxx
Salome HOME
be317e3ffda665fd9cde4b949ddbbbee64bf95d4
[modules/geom.git] / src / BasicGUI / BasicGUI_LineDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  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 // File   : BasicGUI_LineDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "BasicGUI_LineDlg.h"
27
28 #include <GeometryGUI.h>
29 #include <GEOMBase.h>
30 #include <GEOM_DlgRef.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <GEOMImpl_Types.hxx>
38
39 //=================================================================================
40 // class    : BasicGUI_LineDlg()
41 // purpose  : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 BasicGUI_LineDlg::BasicGUI_LineDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47                                     bool modal, Qt::WindowFlags fl )
48   : GEOMBase_Skeleton( theGeometryGUI, parent, "BasicGUI_LineDlg", modal, fl )
49 {
50   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52
53   setWindowTitle( tr( "GEOM_LINE_TITLE" ) );
54  
55   /***************************************************************/
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_LINE" ) );
57   mainFrame()->RadioButton1->setIcon( image0 );
58   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59   mainFrame()->RadioButton2->close();
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   GroupPoints = new DlgRef_2Sel( centralWidget() );
64
65   GroupPoints->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
66   GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
67   GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
68   GroupPoints->PushButton1->setIcon( image1 );
69   GroupPoints->PushButton2->setIcon( image1 );
70
71   GroupPoints->LineEdit1->setReadOnly( true );
72   GroupPoints->LineEdit2->setReadOnly( true );
73
74   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
75   layout->setMargin( 0 ); layout->setSpacing( 6 );
76   layout->addWidget( GroupPoints );
77
78   /***************************************************************/
79
80   setHelpFileName( "line.htm" );
81
82   Init();
83 }
84
85
86 //=================================================================================
87 // function : ~BasicGUI_LineDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BasicGUI_LineDlg::~BasicGUI_LineDlg()
91 {  
92 }
93
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void BasicGUI_LineDlg::Init()
100 {
101   /* init variables */
102   myEditCurrentArgument = GroupPoints->LineEdit1;
103
104   myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
105
106   // myGeomGUI->SetState( 0 );
107   globalSelection( GEOM_POINT );
108         
109   /* signals and slots connections */
110   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
111   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
112
113   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
114   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
115
116   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
117   connect( GroupPoints->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
118
119   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
120   connect( GroupPoints->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
121
122   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
123            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
124   
125   initName( tr( "GEOM_LINE" ) );
126 }
127
128
129 //=================================================================================
130 // function : ClickOnOk()
131 // purpose  :
132 //=================================================================================
133 void BasicGUI_LineDlg::ClickOnOk()
134 {
135   if ( ClickOnApply() )
136     ClickOnCancel();
137 }
138
139 //=================================================================================
140 // function : ClickOnApply()
141 // purpose  :
142 //=================================================================================
143 bool BasicGUI_LineDlg::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 BasicGUI_LineDlg::SelectionIntoArgument()
158 {
159   myEditCurrentArgument->setText( "" );
160
161   if ( IObjectCount() != 1 ) {
162     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )      myPoint1 = GEOM::GEOM_Object::_nil();
163     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
164     return;
165   }
166
167   // nbSel == 1 
168   Standard_Boolean aRes = Standard_False;
169   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
170   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
171     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
172     if      ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
173     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
174   }
175   
176   displayPreview();
177 }
178
179
180 //=================================================================================
181 // function : SetEditCurrentArgument()
182 // purpose  :
183 //=================================================================================
184 void BasicGUI_LineDlg::SetEditCurrentArgument()
185 {
186   QPushButton* send = (QPushButton*)sender();
187   if      ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
188   else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
189   myEditCurrentArgument->setFocus();
190   SelectionIntoArgument();
191 }
192
193
194 //=================================================================================
195 // function : LineEditReturnPressed()
196 // purpose  :
197 //=================================================================================
198 void BasicGUI_LineDlg::LineEditReturnPressed()
199 {
200   QLineEdit* send = (QLineEdit*)sender();
201   if      ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
202   else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
203   else return;
204   GEOMBase_Skeleton::LineEditReturnPressed();
205 }
206
207
208 //=================================================================================
209 // function : ActivateThisDialog()
210 // purpose  :
211 //=================================================================================
212 void BasicGUI_LineDlg::ActivateThisDialog()
213 {
214   GEOMBase_Skeleton::ActivateThisDialog();
215   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
216            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
217
218   // myGeomGUI->SetState( 0 );
219   globalSelection( GEOM_POINT );
220
221   myEditCurrentArgument = GroupPoints->LineEdit1;
222   myEditCurrentArgument->setFocus();
223
224   GroupPoints->LineEdit1->setText( "" );
225   GroupPoints->LineEdit2->setText( "" );
226   myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
227 }
228
229 //=================================================================================
230 // function : DeactivateActiveDialog()
231 // purpose  : public slot to deactivate if active
232 //=================================================================================
233 void BasicGUI_LineDlg::DeactivateActiveDialog()
234 {
235   // myGeomGUI->SetState( -1 );
236   GEOMBase_Skeleton::DeactivateActiveDialog();
237 }
238
239 //=================================================================================
240 // function : enterEvent()
241 // purpose  :
242 //=================================================================================
243 void BasicGUI_LineDlg::enterEvent( QEvent* )
244 {
245   if ( !mainFrame()->GroupConstructors->isEnabled() )
246     ActivateThisDialog();
247 }
248
249 //=================================================================================
250 // function : createOperation
251 // purpose  :
252 //=================================================================================
253 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
254 {
255   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
256 }
257
258 //=================================================================================
259 // function : isValid
260 // purpose  :
261 //=================================================================================
262 bool BasicGUI_LineDlg::isValid( QString& msg )
263 {
264   return !myPoint1->_is_nil() && !myPoint2->_is_nil();
265 }
266
267 //=================================================================================
268 // function : execute
269 // purpose  :
270 //=================================================================================
271 bool BasicGUI_LineDlg::execute( ObjectList& objects )
272 {
273   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
274   if ( !anObj->_is_nil() )
275     objects.push_back( anObj._retn() );
276   return true;
277 }
278
279 //=================================================================================
280 // function : closeEvent
281 // purpose  :
282 //=================================================================================
283 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
284 {
285   GEOMBase_Skeleton::closeEvent( e );
286 }
287