]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_ChangeOrientationDlg.cxx
Salome HOME
Code refactoring
[modules/geom.git] / src / RepairGUI / RepairGUI_ChangeOrientationDlg.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   : RepairGUI_ChangeOrientationDlg.cxx
25 // Author : Sergey KUUL, Open CASCADE S.A.S. (sergey.kuul@opencascade.com)
26 //
27 #include "RepairGUI_ChangeOrientationDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37
38 #include <GEOMImpl_Types.hxx>
39
40 #include <TopAbs.hxx>
41
42 //=================================================================================
43 // class    : RepairGUI_ChangeOrientationDlg()
44 // purpose  : Constructs a RepairGUI_ChangeOrientationDlg  which is a child of 'parent',
45 //            with the 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 RepairGUI_ChangeOrientationDlg::RepairGUI_ChangeOrientationDlg( GeometryGUI* theGeometryGUI,
50                                                                 QWidget* parent,
51                                                                 bool modal )
52   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
53 {
54   //QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
55   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CHANGE_ORIENTATION" ) ));
56   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
57     
58   setWindowTitle( tr( "GEOM_CHANGE_ORIENTATION_TITLE" ) );
59
60   /***************************************************************/
61   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHANGE_ORIENTATION_TITLE" ) );
62   mainFrame()->RadioButton1->setIcon( image0 );
63   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64   mainFrame()->RadioButton2->close();
65   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66   mainFrame()->RadioButton3->close();
67
68   GroupPoints = new DlgRef_1Sel1Check( centralWidget() );
69   GroupPoints->GroupBox1->setTitle( tr( "GEOM_CHANGE_ORIENTATION" ) );
70   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
71   GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
72   GroupPoints->PushButton1->setIcon( image1 );
73 //  GroupPoints->LineEdit1->setReadOnly( true );
74   
75   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76   layout->setMargin( 0 ); layout->setSpacing( 6 );
77   layout->addWidget( GroupPoints );
78
79   setHelpFileName( "change_orientation_operation_page.html" );
80
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~RepairGUI_ChangeOrientationDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 RepairGUI_ChangeOrientationDlg::~RepairGUI_ChangeOrientationDlg()
90 {
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void RepairGUI_ChangeOrientationDlg::Init()
99 {
100   /* init variables */
101   myEditCurrentArgument = GroupPoints->LineEdit1;
102
103   GroupPoints->CheckButton1->setChecked( true );
104
105   myOkObject = false;
106
107   /* signals and slots connections */
108   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
109   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
110
111   connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
112   connect( GroupPoints->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
113
114   connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
115
116   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
117            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
118
119   initName( tr( "CHANGE_ORIENTATION_NEW_OBJ_NAME" ) );
120   resize(100,100);
121   SelectionIntoArgument();
122 }
123
124
125 //=================================================================================
126 // function : ClickOnOk()
127 // purpose  : Same than click on apply but close this dialog.
128 //=================================================================================
129 void RepairGUI_ChangeOrientationDlg::ClickOnOk()
130 {
131   if ( ClickOnApply() )
132     ClickOnCancel();
133 }
134
135
136 //=================================================================================
137 // function : ClickOnApply()
138 // purpose  :
139 //=================================================================================
140 bool RepairGUI_ChangeOrientationDlg::ClickOnApply()
141 {
142 //  if ( !onAccept() )
143   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
144     return false;
145
146   initName();
147
148   myEditCurrentArgument->setText( "" );
149   
150   return true;
151 }
152
153
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose  : Called when selection as changed or other case
157 //=================================================================================
158 void RepairGUI_ChangeOrientationDlg::SelectionIntoArgument()
159 {
160   myEditCurrentArgument->setText( "" );
161   QString aName;
162   
163   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
164   SALOME_ListIO aSelList;
165   aSelMgr->selectedObjects(aSelList);
166
167   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
168     if ( aSelList.Extent() != 1 ) {
169       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
170         myOkObject = false;
171       return;
172     }
173   }
174
175   // nbSel == 1
176   GEOM::GEOM_Object_ptr aSelectedObject =
177     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
178   
179   if ( CORBA::is_nil( aSelectedObject ) )
180     return;
181
182   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
183     myObject = aSelectedObject;
184     myOkObject = true;
185   }
186
187   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
188 }
189
190
191 //=================================================================================
192 // function : SetEditCurrentArgument()
193 // purpose  :
194 //=================================================================================
195 void RepairGUI_ChangeOrientationDlg::SetEditCurrentArgument()
196 {
197   QPushButton* send = (QPushButton*)sender();
198
199   if ( send == GroupPoints->PushButton1 ) {
200     GroupPoints->LineEdit1->setFocus();
201     myEditCurrentArgument = GroupPoints->LineEdit1;
202   }
203   SelectionIntoArgument();
204 }
205
206
207 //=================================================================================
208 // function : LineEditReturnPressed()
209 // purpose  :
210 //=================================================================================
211 void RepairGUI_ChangeOrientationDlg::LineEditReturnPressed()
212 {
213   QLineEdit* send = (QLineEdit*)sender();
214   if ( send == GroupPoints->LineEdit1 ) {
215     myEditCurrentArgument = GroupPoints->LineEdit1;
216     GEOMBase_Skeleton::LineEditReturnPressed();
217   }
218 }
219
220
221 //=================================================================================
222 // function : ActivateThisDialog()
223 // purpose  :
224 //=================================================================================
225 void RepairGUI_ChangeOrientationDlg::ActivateThisDialog()
226 {
227   GEOMBase_Skeleton::ActivateThisDialog();
228   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
229            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
230 }
231
232
233 //=================================================================================
234 // function : enterEvent()
235 // purpose  : Mouse enter onto the dialog to activate it
236 //=================================================================================
237 void RepairGUI_ChangeOrientationDlg::enterEvent( QEvent* )
238 {
239   if ( !mainFrame()->GroupConstructors->isEnabled() )
240     ActivateThisDialog();
241 }
242
243
244 //=================================================================================
245 // function : createOperation
246 // purpose  :
247 //=================================================================================
248 GEOM::GEOM_IOperations_ptr RepairGUI_ChangeOrientationDlg::createOperation()
249 {
250   return getGeomEngine()->GetIHealingOperations( getStudyId() );
251 }
252
253
254 //=================================================================================
255 // function : isValid
256 // purpose  :
257 //=================================================================================
258 bool RepairGUI_ChangeOrientationDlg::isValid( QString& )
259 {
260   return myOkObject;
261 }
262
263
264 //=================================================================================
265 // function : execute
266 // purpose  :
267 //=================================================================================
268 bool RepairGUI_ChangeOrientationDlg::execute( ObjectList& objects )
269 {
270   bool toCreateCopy = GroupPoints->CheckButton1->isChecked();
271
272   GEOM::GEOM_Object_var anObj;
273   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
274   if ( toCreateCopy ) {
275     anObj = anOper->ChangeOrientationCopy( myObject );
276   }
277   else {
278     anObj = anOper->ChangeOrientation( myObject );
279   }
280
281   if ( !anObj->_is_nil() )
282     objects.push_back( anObj._retn() );
283
284   return true;
285 }
286
287
288 //=================================================================================
289 // function :  CreateCopyModeChanged()
290 // purpose  :
291 //=================================================================================
292 void RepairGUI_ChangeOrientationDlg::CreateCopyModeChanged( bool isCreateCopy )
293 {
294   mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
295 }