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
24 // File : TransformationGUI_OffsetDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_OffsetDlg.h"
30 #include "DlgRef_1Sel1Spin1Check.h"
31 #include "DlgRef_SpinBox.h"
33 #include "GeometryGUI.h"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
43 //=================================================================================
44 // class : TransformationGUI_OffsetDlg()
45 // purpose : Constructs a TransformationGUI_OffsetDlg which is a child of 'parent', with the
46 // 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 TransformationGUI_OffsetDlg::TransformationGUI_OffsetDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, Qt::WindowFlags fl)
52 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
54 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_OFFSET")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setWindowTitle(tr("GEOM_OFFSET_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_OFFSET"));
61 RadioButton1->setIcon(image0);
62 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
63 RadioButton2->close();
64 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
65 RadioButton3->close();
67 GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_OFFSET"));
71 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
73 // san -- modification of an exisitng object by offset is not allowed
74 GroupPoints->CheckButton1->hide();
76 GroupPoints->PushButton1->setIcon(image1);
78 gridLayout1->addWidget(GroupPoints, 2, 0);
80 /***************************************************************/
82 setHelpFileName("offset_surface.htm");
88 //=================================================================================
89 // function : ~TransformationGUI_OffsetDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
94 /* no need to delete child widgets, Qt does it all for us */
98 //=================================================================================
101 //=================================================================================
102 void TransformationGUI_OffsetDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
108 /* Get setting of step value from file configuration */
111 /* min, max, step and decimals for spin boxes & initial values */
112 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
113 GroupPoints->SpinBox_DX->setDecimals(5);
114 //@ GroupPoints->SpinBox_DX->setDblPrecision(1e-05);
115 GroupPoints->SpinBox_DX->SetValue(1e-05);
117 // Activate Create a Copy mode
118 GroupPoints->CheckButton1->setChecked(true);
119 CreateCopyModeChanged(true);
121 /* signals and slots connections */
122 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(myGeomGUI->getApp()->selectionMgr(),
127 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
129 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
130 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
132 initName( tr( "GEOM_OFFSET" ).toLatin1().constData() );
134 globalSelection( GEOM_ALLSHAPES );
139 //=================================================================================
140 // function : ClickOnOk()
142 //=================================================================================
143 void TransformationGUI_OffsetDlg::ClickOnOk()
145 if ( ClickOnApply() )
150 //=================================================================================
151 // function : ClickOnApply()
153 //=================================================================================
154 bool TransformationGUI_OffsetDlg::ClickOnApply()
156 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
164 //=================================================================================
165 // function : SelectionIntoArgument()
166 // purpose : Called when selection has changed
167 //=================================================================================
168 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
170 myEditCurrentArgument->setText("");
173 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
181 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
182 if (!myObjects.length())
185 myEditCurrentArgument->setText( aName );
191 //=================================================================================
192 // function : LineEditReturnPressed()
194 //=================================================================================
195 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
197 QLineEdit* send = (QLineEdit*)sender();
198 if ( send == GroupPoints->LineEdit1 )
200 myEditCurrentArgument = GroupPoints->LineEdit1;
201 GEOMBase_Skeleton::LineEditReturnPressed();
206 //=================================================================================
207 // function : SetEditCurrentArgument()
209 //=================================================================================
210 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
212 QPushButton* send = (QPushButton*)sender();
214 if(send == GroupPoints->PushButton1)
216 myEditCurrentArgument = GroupPoints->LineEdit1;
217 myEditCurrentArgument->setFocus();
218 SelectionIntoArgument();
223 //=================================================================================
224 // function : enterEvent()
225 // purpose : when mouse enter onto the QWidget
226 //=================================================================================
227 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
229 if ( !GroupConstructors->isEnabled() )
230 ActivateThisDialog();
234 //=================================================================================
235 // function : ActivateThisDialog()
237 //=================================================================================
238 void TransformationGUI_OffsetDlg::ActivateThisDialog()
240 GEOMBase_Skeleton::ActivateThisDialog();
241 connect(myGeomGUI->getApp()->selectionMgr(),
242 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243 globalSelection( GEOM_ALLSHAPES );
244 myEditCurrentArgument = GroupPoints->LineEdit1;
245 myEditCurrentArgument->setFocus();
249 //=================================================================================
250 // function : ValueChangedInSpinBox()
252 //=================================================================================
253 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
259 //=================================================================================
260 // function : createOperation
262 //=================================================================================
263 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
265 return getGeomEngine()->GetITransformOperations( getStudyId() );
268 //=================================================================================
269 // function : isValid
271 //=================================================================================
272 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
274 //return !(myObjects.length() == 0);
275 if (myObjects.length() == 0) return false;
277 for (int i = 0; i < myObjects.length(); i++)
279 GEOM::shape_type aType = myObjects[i]->GetShapeType();
280 if( aType != GEOM::FACE && aType != GEOM::SHELL && aType != GEOM::SOLID ){
281 msg = tr("ERROR_SHAPE_TYPE");
289 //=================================================================================
290 // function : execute
292 //=================================================================================
293 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
297 GEOM::GEOM_Object_var anObj;
300 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
301 for (int i = 0; i < myObjects.length(); i++)
304 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
305 if ( !anObj->_is_nil() )
306 objects.push_back( anObj._retn() );
309 for (int i = 0; i < myObjects.length(); i++)
311 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
312 if ( !anObj->_is_nil() )
313 objects.push_back( anObj._retn() );
321 //=================================================================================
322 // function : closeEvent
324 //=================================================================================
325 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
327 // myGeomGUI->SetState( -1 );
328 GEOMBase_Skeleton::closeEvent( e );
332 //=================================================================================
333 // function : GetOffset()
335 //=================================================================================
336 double TransformationGUI_OffsetDlg::GetOffset() const
338 return GroupPoints->SpinBox_DX->GetValue();
342 //=================================================================================
343 // function : CreateCopyModeChanged()
345 //=================================================================================
346 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
348 this->GroupBoxName->setEnabled(isCreateCopy);