1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, 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.
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 : TransformationGUI_OffsetDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "TransformationGUI_OffsetDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 //=================================================================================
39 // class : TransformationGUI_OffsetDlg()
40 // purpose : Constructs a TransformationGUI_OffsetDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 TransformationGUI_OffsetDlg::TransformationGUI_OffsetDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
46 bool modal, Qt::WindowFlags fl )
47 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
49 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_OFFSET" ) ) );
50 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 setWindowTitle( tr( "GEOM_OFFSET_TITLE" ) );
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_OFFSET" ) );
56 mainFrame()->RadioButton1->setIcon( image0 );
57 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58 mainFrame()->RadioButton2->close();
59 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton3->close();
62 GroupPoints = new DlgRef_1Sel1Spin1Check( centralWidget() );
63 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
64 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
65 GroupPoints->TextLabel2->setText( tr( "GEOM_OFFSET" ) );
66 GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
68 // san -- modification of an exisitng object by offset is not allowed
69 GroupPoints->CheckButton1->hide();
71 GroupPoints->PushButton1->setIcon( image1 );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupPoints );
77 /***************************************************************/
79 setHelpFileName( "offset_operation_page.html" );
85 //=================================================================================
86 // function : ~TransformationGUI_OffsetDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
91 /* no need to delete child widgets, Qt does it all for us */
95 //=================================================================================
98 //=================================================================================
99 void TransformationGUI_OffsetDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 GroupPoints->LineEdit1->setReadOnly( true );
107 /* Get setting of step value from file configuration */
110 /* min, max, step and decimals for spin boxes & initial values */
111 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
112 GroupPoints->SpinBox_DX->setValue( 1e-05 );
114 // Activate Create a Copy mode
115 GroupPoints->CheckButton1->setChecked( true );
116 CreateCopyModeChanged();
118 mainFrame()->GroupBoxPublish->show();
120 /* signals and slots connections */
121 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
122 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
124 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
125 connect( myGeomGUI->getApp()->selectionMgr(),
126 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
128 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
129 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged() ) );
131 initName( tr( "GEOM_OFFSET" ) );
133 globalSelection( GEOM_ALLSHAPES );
135 SelectionIntoArgument();
139 //=================================================================================
140 // function : ClickOnOk()
142 //=================================================================================
143 void TransformationGUI_OffsetDlg::ClickOnOk()
145 setIsApplyAndClose( true );
146 if ( ClickOnApply() )
151 //=================================================================================
152 // function : ClickOnApply()
154 //=================================================================================
155 bool TransformationGUI_OffsetDlg::ClickOnApply()
157 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
165 //=================================================================================
166 // function : SelectionIntoArgument()
167 // purpose : Called when selection has changed
168 //=================================================================================
169 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
171 myObjects = getSelected( TopAbs_SHAPE, -1 );
172 if ( !myObjects.isEmpty() ) {
173 QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
174 myEditCurrentArgument->setText( aName );
177 myEditCurrentArgument->setText("");
184 //=================================================================================
185 // function : SetEditCurrentArgument()
187 //=================================================================================
188 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
190 QPushButton* send = (QPushButton*)sender();
192 if ( send == GroupPoints->PushButton1 ) {
193 GroupPoints->PushButton1->setDown(true);
194 myEditCurrentArgument = GroupPoints->LineEdit1;
195 myEditCurrentArgument->setFocus();
196 SelectionIntoArgument();
201 //=================================================================================
202 // function : enterEvent()
203 // purpose : when mouse enter onto the QWidget
204 //=================================================================================
205 void TransformationGUI_OffsetDlg::enterEvent( QEvent* )
207 if ( !mainFrame()->GroupConstructors->isEnabled() )
208 ActivateThisDialog();
212 //=================================================================================
213 // function : ActivateThisDialog()
215 //=================================================================================
216 void TransformationGUI_OffsetDlg::ActivateThisDialog()
218 GEOMBase_Skeleton::ActivateThisDialog();
219 connect( myGeomGUI->getApp()->selectionMgr(),
220 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
221 globalSelection( GEOM_ALLSHAPES );
222 myEditCurrentArgument = GroupPoints->LineEdit1;
223 myEditCurrentArgument->setFocus();
227 //=================================================================================
228 // function : ValueChangedInSpinBox()
230 //=================================================================================
231 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
237 //=================================================================================
238 // function : createOperation
240 //=================================================================================
241 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
243 return getGeomEngine()->GetITransformOperations( getStudyId() );
246 //=================================================================================
247 // function : isValid
249 //=================================================================================
250 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
252 bool ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myObjects.isEmpty();
253 for ( int i = 0; i < myObjects.count() && ok; i++ ) {
254 GEOM::shape_type aType = myObjects[i]->GetShapeType();
255 ok = aType == GEOM::FACE || aType == GEOM::SHELL || aType == GEOM::SOLID;
257 msg = tr( "ERROR_SHAPE_TYPE" );
262 //=================================================================================
263 // function : execute
265 //=================================================================================
266 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
270 GEOM::GEOM_Object_var anObj;
272 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
274 if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
275 for ( int i = 0; i < myObjects.count(); i++ ) {
277 anObj = anOper->OffsetShapeCopy( myObjects[i].get(), GetOffset() );
278 if ( !anObj->_is_nil() ) {
280 anObj->SetParameters(GroupPoints->SpinBox_DX->text().toLatin1().constData());
282 objects.push_back( anObj._retn() );
287 for ( int i = 0; i < myObjects.count(); i++ ) {
288 anObj = anOper->OffsetShape( myObjects[i].get(), GetOffset() );
289 if ( !anObj->_is_nil() )
290 objects.push_back( anObj._retn() );
298 //=================================================================================
299 // function : restoreSubShapes
301 //=================================================================================
302 void TransformationGUI_OffsetDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
303 SALOMEDS::SObject_ptr theSObject )
305 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
306 // empty list of arguments means that all arguments should be restored
307 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
308 /*theFindMethod=*/GEOM::FSM_Transformed,
309 /*theInheritFirstArg=*/true,
310 mainFrame()->CheckBoxAddPrefix->isChecked() );
314 //=================================================================================
315 // function : GetOffset()
317 //=================================================================================
318 double TransformationGUI_OffsetDlg::GetOffset() const
320 return GroupPoints->SpinBox_DX->value();
323 //=================================================================================
324 // function : CreateCopyModeChanged()
326 //=================================================================================
327 void TransformationGUI_OffsetDlg::CreateCopyModeChanged()
329 mainFrame()->GroupBoxName->setEnabled( GroupPoints->CheckButton1->isChecked() );