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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TransformationGUI_OffsetDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_OffsetDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
37 #include <qcheckbox.h>
39 #include "utilities.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, WFlags fl)
52 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_OFFSET")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_OFFSET_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_OFFSET"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_OFFSET"));
70 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
72 // san -- modification of an exisitng object by offset is not allowed
73 GroupPoints->CheckButton1->hide();
75 GroupPoints->PushButton1->setPixmap(image1);
77 Layout1->addWidget(GroupPoints, 2, 0);
79 /***************************************************************/
81 setHelpFileName("offset_surface.htm");
87 //=================================================================================
88 // function : ~TransformationGUI_OffsetDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
93 /* no need to delete child widgets, Qt does it all for us */
97 //=================================================================================
100 //=================================================================================
101 void TransformationGUI_OffsetDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
105 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 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
112 GroupPoints->SpinBox_DX->setPrecision(5);
113 //@ GroupPoints->SpinBox_DX->setDblPrecision(1e-05);
114 GroupPoints->SpinBox_DX->SetValue(1e-05);
116 // Activate Create a Copy mode
117 GroupPoints->CheckButton1->setChecked(true);
118 CreateCopyModeChanged(true);
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(bool)));
131 initName( tr( "GEOM_OFFSET" ) );
133 globalSelection( GEOM_ALLSHAPES );
138 //=================================================================================
139 // function : ClickOnOk()
141 //=================================================================================
142 void TransformationGUI_OffsetDlg::ClickOnOk()
144 if ( ClickOnApply() )
149 //=================================================================================
150 // function : ClickOnApply()
152 //=================================================================================
153 bool TransformationGUI_OffsetDlg::ClickOnApply()
155 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
163 //=================================================================================
164 // function : SelectionIntoArgument()
165 // purpose : Called when selection has changed
166 //=================================================================================
167 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
169 myEditCurrentArgument->setText("");
172 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
180 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
181 if (!myObjects.length())
184 myEditCurrentArgument->setText( aName );
190 //=================================================================================
191 // function : LineEditReturnPressed()
193 //=================================================================================
194 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
196 QLineEdit* send = (QLineEdit*)sender();
197 if ( send == GroupPoints->LineEdit1 )
199 myEditCurrentArgument = GroupPoints->LineEdit1;
200 GEOMBase_Skeleton::LineEditReturnPressed();
205 //=================================================================================
206 // function : SetEditCurrentArgument()
208 //=================================================================================
209 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
211 QPushButton* send = (QPushButton*)sender();
213 if(send == GroupPoints->PushButton1)
215 myEditCurrentArgument = GroupPoints->LineEdit1;
216 myEditCurrentArgument->setFocus();
217 SelectionIntoArgument();
222 //=================================================================================
223 // function : enterEvent()
224 // purpose : when mouse enter onto the QWidget
225 //=================================================================================
226 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
228 if ( !GroupConstructors->isEnabled() )
229 ActivateThisDialog();
233 //=================================================================================
234 // function : ActivateThisDialog()
236 //=================================================================================
237 void TransformationGUI_OffsetDlg::ActivateThisDialog()
239 GEOMBase_Skeleton::ActivateThisDialog();
240 connect(myGeomGUI->getApp()->selectionMgr(),
241 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
242 globalSelection( GEOM_ALLSHAPES );
243 myEditCurrentArgument = GroupPoints->LineEdit1;
244 myEditCurrentArgument->setFocus();
248 //=================================================================================
249 // function : ValueChangedInSpinBox()
251 //=================================================================================
252 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
258 //=================================================================================
259 // function : createOperation
261 //=================================================================================
262 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
264 return getGeomEngine()->GetITransformOperations( getStudyId() );
267 //=================================================================================
268 // function : isValid
270 //=================================================================================
271 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
273 return !(myObjects.length() == 0);
277 //=================================================================================
278 // function : execute
280 //=================================================================================
281 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
285 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() );
296 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() );
308 //=================================================================================
309 // function : closeEvent
311 //=================================================================================
312 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
314 // myGeomGUI->SetState( -1 );
315 GEOMBase_Skeleton::closeEvent( e );
319 //=================================================================================
320 // function : GetOffset()
322 //=================================================================================
323 double TransformationGUI_OffsetDlg::GetOffset() const
325 return GroupPoints->SpinBox_DX->GetValue();
329 //=================================================================================
330 // function : CreateCopyModeChanged()
332 //=================================================================================
333 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
335 this->GroupBoxName->setEnabled(isCreateCopy);