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