1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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)
27 #include "RepairGUI_ChangeOrientationDlg.h"
30 #include "GeometryGUI.h"
32 #include "RepairGUI.h"
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
40 #include "GEOMImpl_Types.hxx"
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,
53 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
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" ) ) );
59 setWindowTitle( tr( "GEOM_CHANGE_ORIENTATION_TITLE" ) );
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();
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 );
76 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77 layout->setMargin( 0 ); layout->setSpacing( 6 );
78 layout->addWidget( GroupPoints );
80 setHelpFileName( "change_orientation_operation_page.html" );
86 //=================================================================================
87 // function : ~RepairGUI_ChangeOrientationDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 RepairGUI_ChangeOrientationDlg::~RepairGUI_ChangeOrientationDlg()
95 //=================================================================================
98 //=================================================================================
99 void RepairGUI_ChangeOrientationDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
104 GroupPoints->CheckButton1->setChecked( true );
108 /* signals and slots connections */
109 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
110 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
112 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
113 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
115 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
117 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
118 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
120 initName( tr( "CHANGE_ORIENTATION_NEW_OBJ_NAME" ) );
122 SelectionIntoArgument();
126 //=================================================================================
127 // function : ClickOnOk()
128 // purpose : Same than click on apply but close this dialog.
129 //=================================================================================
130 void RepairGUI_ChangeOrientationDlg::ClickOnOk()
132 setIsApplyAndClose( true );
133 if ( ClickOnApply() )
138 //=================================================================================
139 // function : ClickOnApply()
141 //=================================================================================
142 bool RepairGUI_ChangeOrientationDlg::ClickOnApply()
144 // if ( !onAccept() )
145 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
150 myEditCurrentArgument->setText( "" );
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void RepairGUI_ChangeOrientationDlg::SelectionIntoArgument()
162 myEditCurrentArgument->setText( "" );
165 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
166 SALOME_ListIO aSelList;
167 aSelMgr->selectedObjects(aSelList);
169 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
170 if ( aSelList.Extent() != 1 ) {
171 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
178 GEOM::GEOM_Object_ptr aSelectedObject =
179 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
181 if ( CORBA::is_nil( aSelectedObject ) )
184 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
185 myObject = aSelectedObject;
189 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
193 //=================================================================================
194 // function : SetEditCurrentArgument()
196 //=================================================================================
197 void RepairGUI_ChangeOrientationDlg::SetEditCurrentArgument()
199 QPushButton* send = (QPushButton*)sender();
201 if ( send == GroupPoints->PushButton1 ) {
202 GroupPoints->LineEdit1->setFocus();
203 myEditCurrentArgument = GroupPoints->LineEdit1;
205 SelectionIntoArgument();
209 //=================================================================================
210 // function : LineEditReturnPressed()
212 //=================================================================================
213 void RepairGUI_ChangeOrientationDlg::LineEditReturnPressed()
215 QLineEdit* send = (QLineEdit*)sender();
216 if ( send == GroupPoints->LineEdit1 ) {
217 myEditCurrentArgument = GroupPoints->LineEdit1;
218 GEOMBase_Skeleton::LineEditReturnPressed();
223 //=================================================================================
224 // function : ActivateThisDialog()
226 //=================================================================================
227 void RepairGUI_ChangeOrientationDlg::ActivateThisDialog()
229 GEOMBase_Skeleton::ActivateThisDialog();
230 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
231 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
235 //=================================================================================
236 // function : enterEvent()
237 // purpose : Mouse enter onto the dialog to activate it
238 //=================================================================================
239 void RepairGUI_ChangeOrientationDlg::enterEvent( QEvent* )
241 if ( !mainFrame()->GroupConstructors->isEnabled() )
242 ActivateThisDialog();
246 //=================================================================================
247 // function : createOperation
249 //=================================================================================
250 GEOM::GEOM_IOperations_ptr RepairGUI_ChangeOrientationDlg::createOperation()
252 return getGeomEngine()->GetIHealingOperations();
256 //=================================================================================
257 // function : isValid
259 //=================================================================================
260 bool RepairGUI_ChangeOrientationDlg::isValid( QString& )
266 //=================================================================================
267 // function : execute
269 //=================================================================================
270 bool RepairGUI_ChangeOrientationDlg::execute( ObjectList& objects )
272 bool toCreateCopy = GroupPoints->CheckButton1->isChecked();
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 );
280 anObj = anOper->ChangeOrientation( myObject );
283 if ( !anObj->_is_nil() )
286 RepairGUI::ShowStatistics( anOper, this );
287 objects.push_back( anObj._retn() );
294 //=================================================================================
295 // function : CreateCopyModeChanged()
297 //=================================================================================
298 void RepairGUI_ChangeOrientationDlg::CreateCopyModeChanged( bool isCreateCopy )
300 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
303 //=================================================================================
304 // function : getSourceObjects
305 // purpose : virtual method to get source objects
306 //=================================================================================
307 QList<GEOM::GeomObjPtr> RepairGUI_ChangeOrientationDlg::getSourceObjects()
309 QList<GEOM::GeomObjPtr> res;
310 if ( GroupPoints->CheckButton1->isChecked() ) {
311 GEOM::GeomObjPtr aGeomObjPtr(myObject);