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