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