Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / src / RepairGUI / RepairGUI_ChangeOrientationDlg.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 //
23 //
24 //  File   : RepairGUI_ChangeOrientationDlg.cxx
25 //  Author : Sergey KUUL
26 //  Module : GEOM
27
28 #include "RepairGUI_ChangeOrientationDlg.h"
29
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_Session.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
34
35 #include "GEOMImpl_Types.hxx"
36
37 #include <TopAbs.hxx>
38
39 #include <qlabel.h>
40
41 using namespace std;
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, const char* name,
52                                                                bool modal, WFlags fl)
53   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 {
56   //QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
57   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHANGE_ORIENTATION")));
58   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59     
60   setCaption(tr("GEOM_CHANGE_ORIENTATION_TITLE"));
61
62   /***************************************************************/
63   GroupConstructors->setTitle(tr("GEOM_CHANGE_ORIENTATION_TITLE"));
64   RadioButton1->setPixmap(image0);
65   RadioButton2->close(TRUE);
66   RadioButton3->close(TRUE);
67
68   GroupPoints = new DlgRef_1Sel1Check_QTD(this, "GroupPoints");
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->setPixmap(image1);
73 //  GroupPoints->LineEdit1->setReadOnly( true );
74
75   Layout1->addWidget(GroupPoints, 2, 0);
76
77   setHelpFileName("change_orientation_operation_page.html");
78
79   Init();
80 }
81
82
83 //=================================================================================
84 // function : ~RepairGUI_ChangeOrientationDlg()
85 // purpose  : Destroys the object and frees any allocated resources
86 //=================================================================================
87 RepairGUI_ChangeOrientationDlg::~RepairGUI_ChangeOrientationDlg()
88 {
89 }
90
91
92 //=================================================================================
93 // function : Init()
94 // purpose  :
95 //=================================================================================
96 void RepairGUI_ChangeOrientationDlg::Init()
97 {
98   /* init variables */
99   myEditCurrentArgument = GroupPoints->LineEdit1;
100
101   GroupPoints->CheckButton1->setChecked(true);
102
103   myOkObject = false;
104
105   /* signals and slots connections */
106   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108
109   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111
112   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
113
114   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
115           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
116
117   initName( tr( "CHANGE_ORIENTATION_NEW_OBJ_NAME" ) );
118 }
119
120
121 //=================================================================================
122 // function : ClickOnOk()
123 // purpose  : Same than click on apply but close this dialog.
124 //=================================================================================
125 void RepairGUI_ChangeOrientationDlg::ClickOnOk()
126 {
127   if ( ClickOnApply() )
128     ClickOnCancel();
129 }
130
131
132 //=================================================================================
133 // function : ClickOnApply()
134 // purpose  :
135 //=================================================================================
136 bool RepairGUI_ChangeOrientationDlg::ClickOnApply()
137 {
138 //  if ( !onAccept() )
139   if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
140     return false;
141
142   initName();
143
144   myEditCurrentArgument->setText("");
145   
146   return true;
147 }
148
149
150 //=================================================================================
151 // function : SelectionIntoArgument()
152 // purpose  : Called when selection as changed or other case
153 //=================================================================================
154 void RepairGUI_ChangeOrientationDlg::SelectionIntoArgument()
155 {
156   myEditCurrentArgument->setText("");
157   QString aName;
158   
159   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
160     if (IObjectCount() != 1) {
161       if (myEditCurrentArgument == GroupPoints->LineEdit1)
162         myOkObject = false;
163       return;
164     }
165   }
166
167   // nbSel == 1
168   Standard_Boolean testResult = Standard_False;
169   GEOM::GEOM_Object_ptr aSelectedObject =
170     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
171
172   if (!testResult)
173     return;
174
175   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
176     myObject = aSelectedObject;
177     myOkObject = true;
178   }
179
180   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
181
182 }
183
184
185 //=================================================================================
186 // function : SetEditCurrentArgument()
187 // purpose  :
188 //=================================================================================
189 void RepairGUI_ChangeOrientationDlg::SetEditCurrentArgument()
190 {
191   QPushButton* send = (QPushButton*)sender();
192
193   if( send == GroupPoints->PushButton1 )
194   {
195     GroupPoints->LineEdit1->setFocus();
196     myEditCurrentArgument = GroupPoints->LineEdit1;
197   }
198   SelectionIntoArgument();
199 }
200
201
202 //=================================================================================
203 // function : LineEditReturnPressed()
204 // purpose  :
205 //=================================================================================
206 void RepairGUI_ChangeOrientationDlg::LineEditReturnPressed()
207 {
208   QLineEdit* send = (QLineEdit*)sender();
209   if( send == GroupPoints->LineEdit1 ) {
210     myEditCurrentArgument = GroupPoints->LineEdit1;
211     GEOMBase_Skeleton::LineEditReturnPressed();
212   }
213 }
214
215
216 //=================================================================================
217 // function : ActivateThisDialog()
218 // purpose  :
219 //=================================================================================
220 void RepairGUI_ChangeOrientationDlg::ActivateThisDialog()
221 {
222   GEOMBase_Skeleton::ActivateThisDialog();
223   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
224           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
225
226 }
227
228
229 //=================================================================================
230 // function : enterEvent()
231 // purpose  : Mouse enter onto the dialog to activate it
232 //=================================================================================
233 void RepairGUI_ChangeOrientationDlg::enterEvent(QEvent* e)
234 {
235   if ( !GroupConstructors->isEnabled() )
236     ActivateThisDialog();
237 }
238
239
240 //=================================================================================
241 // function : closeEvent()
242 // purpose  :
243 //=================================================================================
244 void RepairGUI_ChangeOrientationDlg::closeEvent(QCloseEvent* e)
245 {
246   //myGeomGUI->SetState( -1 );
247   GEOMBase_Skeleton::closeEvent( e );
248 }
249
250
251 //=================================================================================
252 // function : createOperation
253 // purpose  :
254 //=================================================================================
255 GEOM::GEOM_IOperations_ptr RepairGUI_ChangeOrientationDlg::createOperation()
256 {
257   return getGeomEngine()->GetIHealingOperations( getStudyId() );
258 }
259
260
261 //=================================================================================
262 // function : isValid
263 // purpose  :
264 //=================================================================================
265 bool RepairGUI_ChangeOrientationDlg::isValid( QString& msg )
266 {
267   return myOkObject;
268 }
269
270
271 //=================================================================================
272 // function : execute
273 // purpose  :
274 //=================================================================================
275 bool RepairGUI_ChangeOrientationDlg::execute( ObjectList& objects )
276 {
277   bool toCreateCopy = GroupPoints->CheckButton1->isChecked();
278
279   GEOM::GEOM_Object_var anObj;
280   if(toCreateCopy) {
281     anObj = GEOM::GEOM_IHealingOperations::_narrow(getOperation())->ChangeOrientationCopy(myObject);
282   }
283   else {
284     anObj = GEOM::GEOM_IHealingOperations::_narrow(getOperation())->ChangeOrientation(myObject);
285   }
286
287   if ( !anObj->_is_nil() )
288     objects.push_back( anObj._retn() );
289
290   return true;
291 }
292
293
294 //=================================================================================
295 // function :  CreateCopyModeChanged()
296 // purpose  :
297 //=================================================================================
298 void RepairGUI_ChangeOrientationDlg::CreateCopyModeChanged(bool isCreateCopy)
299 {
300   GroupBoxName->setEnabled(isCreateCopy);
301 }