1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.
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
22 // File : TransformationGUI_OffsetDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI_OffsetDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 //=================================================================================
38 // class : TransformationGUI_OffsetDlg()
39 // purpose : Constructs a TransformationGUI_OffsetDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 TransformationGUI_OffsetDlg::TransformationGUI_OffsetDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
45 bool modal, Qt::WindowFlags fl )
46 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
48 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_OFFSET" ) ) );
49 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
51 setWindowTitle( tr( "GEOM_OFFSET_TITLE" ) );
53 /***************************************************************/
54 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_OFFSET" ) );
55 mainFrame()->RadioButton1->setIcon( image0 );
56 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
57 mainFrame()->RadioButton2->close();
58 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton3->close();
61 GroupPoints = new DlgRef_1Sel1Spin1Check( centralWidget() );
62 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
63 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
64 GroupPoints->TextLabel2->setText( tr( "GEOM_OFFSET" ) );
65 GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
67 // san -- modification of an exisitng object by offset is not allowed
68 GroupPoints->CheckButton1->hide();
70 GroupPoints->PushButton1->setIcon( image1 );
72 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73 layout->setMargin( 0 ); layout->setSpacing( 6 );
74 layout->addWidget( GroupPoints );
76 /***************************************************************/
78 setHelpFileName( "offset_operation_page.html" );
84 //=================================================================================
85 // function : ~TransformationGUI_OffsetDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
90 /* no need to delete child widgets, Qt does it all for us */
94 //=================================================================================
97 //=================================================================================
98 void TransformationGUI_OffsetDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
102 GroupPoints->LineEdit1->setReadOnly( true );
104 /* Get setting of step value from file configuration */
107 /* min, max, step and decimals for spin boxes & initial values */
108 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
109 GroupPoints->SpinBox_DX->setValue( 1e-05 );
111 // Activate Create a Copy mode
112 GroupPoints->CheckButton1->setChecked( true );
113 CreateCopyModeChanged( true );
115 /* signals and slots connections */
116 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
117 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
119 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
120 connect( myGeomGUI->getApp()->selectionMgr(),
121 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
123 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
124 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
126 initName( tr( "GEOM_OFFSET" ) );
128 globalSelection( GEOM_ALLSHAPES );
132 //=================================================================================
133 // function : ClickOnOk()
135 //=================================================================================
136 void TransformationGUI_OffsetDlg::ClickOnOk()
138 if ( ClickOnApply() )
143 //=================================================================================
144 // function : ClickOnApply()
146 //=================================================================================
147 bool TransformationGUI_OffsetDlg::ClickOnApply()
149 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
157 //=================================================================================
158 // function : SelectionIntoArgument()
159 // purpose : Called when selection has changed
160 //=================================================================================
161 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
163 myEditCurrentArgument->setText( "" );
166 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
168 myObjects.length( 0 );
173 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
174 if ( !myObjects.length() )
177 myEditCurrentArgument->setText( aName );
183 //=================================================================================
184 // function : LineEditReturnPressed()
186 //=================================================================================
187 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
189 QLineEdit* send = (QLineEdit*)sender();
190 if ( send == GroupPoints->LineEdit1 ) {
191 myEditCurrentArgument = GroupPoints->LineEdit1;
192 GEOMBase_Skeleton::LineEditReturnPressed();
197 //=================================================================================
198 // function : SetEditCurrentArgument()
200 //=================================================================================
201 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
203 QPushButton* send = (QPushButton*)sender();
205 if ( send == GroupPoints->PushButton1 ) {
206 myEditCurrentArgument = GroupPoints->LineEdit1;
207 myEditCurrentArgument->setFocus();
208 SelectionIntoArgument();
213 //=================================================================================
214 // function : enterEvent()
215 // purpose : when mouse enter onto the QWidget
216 //=================================================================================
217 void TransformationGUI_OffsetDlg::enterEvent( QEvent* )
219 if ( !mainFrame()->GroupConstructors->isEnabled() )
220 ActivateThisDialog();
224 //=================================================================================
225 // function : ActivateThisDialog()
227 //=================================================================================
228 void TransformationGUI_OffsetDlg::ActivateThisDialog()
230 GEOMBase_Skeleton::ActivateThisDialog();
231 connect( myGeomGUI->getApp()->selectionMgr(),
232 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
233 globalSelection( GEOM_ALLSHAPES );
234 myEditCurrentArgument = GroupPoints->LineEdit1;
235 myEditCurrentArgument->setFocus();
239 //=================================================================================
240 // function : ValueChangedInSpinBox()
242 //=================================================================================
243 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
249 //=================================================================================
250 // function : createOperation
252 //=================================================================================
253 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
255 return getGeomEngine()->GetITransformOperations( getStudyId() );
258 //=================================================================================
259 // function : isValid
261 //=================================================================================
262 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
264 //return !(myObjects.length() == 0);
265 if ( myObjects.length() == 0 ) return false;
267 for ( int i = 0; i < myObjects.length(); i++ ) {
268 GEOM::shape_type aType = myObjects[i]->GetShapeType();
269 if ( aType != GEOM::FACE && aType != GEOM::SHELL && aType != GEOM::SOLID ) {
270 msg = tr( "ERROR_SHAPE_TYPE" );
278 //=================================================================================
279 // function : execute
281 //=================================================================================
282 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
286 GEOM::GEOM_Object_var anObj;
288 if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
289 for ( int i = 0; i < myObjects.length(); i++ ) {
291 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
292 if ( !anObj->_is_nil() )
293 objects.push_back( anObj._retn() );
297 for ( int i = 0; i < myObjects.length(); i++ ) {
298 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
299 if ( !anObj->_is_nil() )
300 objects.push_back( anObj._retn() );
309 //=================================================================================
310 // function : GetOffset()
312 //=================================================================================
313 double TransformationGUI_OffsetDlg::GetOffset() const
315 return GroupPoints->SpinBox_DX->value();
319 //=================================================================================
320 // function : CreateCopyModeChanged()
322 //=================================================================================
323 void TransformationGUI_OffsetDlg::CreateCopyModeChanged( bool isCreateCopy )
325 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );