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 : GenerationGUI_RevolDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GenerationGUI_RevolDlg.h"
30 #include "DlgRef_2Sel1Spin2Check.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"
41 #include <TopExp_Explorer.hxx>
42 #include "GEOMImpl_Types.hxx"
44 //=================================================================================
45 // class : GenerationGUI_RevolDlg()
46 // purpose : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52 const char* name, bool modal, Qt::WindowFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setWindowTitle(tr("GEOM_REVOLUTION_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
62 RadioButton1->setIcon(image0);
63 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64 RadioButton2->close();
65 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66 RadioButton3->close();
68 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
69 GroupPoints->CheckButton1->hide();
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
72 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
73 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
74 GroupPoints->PushButton1->setIcon(image1);
75 GroupPoints->PushButton2->setIcon(image1);
76 GroupPoints->LineEdit1->setReadOnly( true );
77 GroupPoints->LineEdit2->setReadOnly( true );
78 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
80 gridLayout1->addWidget(GroupPoints, 2, 0);
81 /***************************************************************/
83 setHelpFileName("revolution.htm");
90 //=================================================================================
91 // function : ~GenerationGUI_RevolDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
96 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void GenerationGUI_RevolDlg::Init()
107 myEditCurrentArgument = GroupPoints->LineEdit1;
108 GroupPoints->LineEdit1->setReadOnly( true );
109 GroupPoints->LineEdit2->setReadOnly( true );
111 myOkBase = myOkAxis = false;
113 double SpecificStep = 5;
114 /* min, max, step and decimals for spin boxes & initial values */
115 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, 3);
116 GroupPoints->SpinBox_DX->SetValue(45.0);
118 /* signals and slots connections */
119 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
120 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
129 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
131 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
133 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
134 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
136 initName(tr("GEOM_REVOLUTION").toStdString().c_str());
138 globalSelection( GEOM_ALLSHAPES );
142 //=================================================================================
143 // function : ClickOnOk()
145 //=================================================================================
146 void GenerationGUI_RevolDlg::ClickOnOk()
148 if ( ClickOnApply() )
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 bool GenerationGUI_RevolDlg::ClickOnApply()
166 //=======================================================================
167 //function : isAcceptableBase
168 //purpose : return true if theBase can be used as algo argument
169 //=======================================================================
171 static bool isAcceptableBase(const TopoDS_Shape& theBase)
173 switch ( theBase.ShapeType() ) {
181 case TopAbs_COMPSOLID:
183 case TopAbs_COMPOUND: {
184 TopExp_Explorer exp( theBase, TopAbs_SOLID);
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose : Called when selection as changed or other case
196 //=================================================================================
197 void GenerationGUI_RevolDlg::SelectionIntoArgument()
200 myEditCurrentArgument->setText("");
202 if(IObjectCount() != 1) {
203 if(myEditCurrentArgument == GroupPoints->LineEdit1)
205 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
211 Standard_Boolean testResult = Standard_False;
212 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
217 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
221 if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
224 myBase = aSelectedObject;
227 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
228 myAxis = aSelectedObject;
231 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
237 //=================================================================================
238 // function : SetEditCurrentArgument()
240 //=================================================================================
241 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
243 QPushButton* send = (QPushButton*)sender();
244 globalSelection( GEOM_ALLSHAPES );
246 if(send == GroupPoints->PushButton1) {
247 GroupPoints->LineEdit1->setFocus();
248 myEditCurrentArgument = GroupPoints->LineEdit1;
250 else if(send == GroupPoints->PushButton2) {
251 GroupPoints->LineEdit2->setFocus();
252 myEditCurrentArgument = GroupPoints->LineEdit2;
253 globalSelection( GEOM_LINE );
255 SelectionIntoArgument();
259 //=================================================================================
260 // function : LineEditReturnPressed()
262 //=================================================================================
263 void GenerationGUI_RevolDlg::LineEditReturnPressed()
265 QLineEdit* send = (QLineEdit*)sender();
266 if(send == GroupPoints->LineEdit1 ||
267 send == GroupPoints->LineEdit2)
269 myEditCurrentArgument = send;
270 GEOMBase_Skeleton::LineEditReturnPressed();
275 //=================================================================================
276 // function : ActivateThisDialog()
278 //=================================================================================
279 void GenerationGUI_RevolDlg::ActivateThisDialog()
281 GEOMBase_Skeleton::ActivateThisDialog();
282 globalSelection( GEOM_ALLSHAPES );
283 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
284 GroupPoints->LineEdit1->setFocus();
285 myEditCurrentArgument = GroupPoints->LineEdit1;
290 //=================================================================================
291 // function : enterEvent()
293 //=================================================================================
294 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
296 if ( !GroupConstructors->isEnabled() )
297 ActivateThisDialog();
301 //=================================================================================
302 // function : ValueChangedInSpinBox()
304 //=================================================================================
305 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
311 //=================================================================================
312 // function : getAngle()
314 //=================================================================================
315 double GenerationGUI_RevolDlg::getAngle() const
317 return GroupPoints->SpinBox_DX->GetValue();
320 //=================================================================================
321 // function : createOperation
323 //=================================================================================
324 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
326 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
329 //=================================================================================
330 // function : isValid
332 //=================================================================================
333 bool GenerationGUI_RevolDlg::isValid( QString& )
335 return myOkBase && myOkAxis;
338 //=================================================================================
339 // function : execute
341 //=================================================================================
342 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
344 GEOM::GEOM_Object_var anObj;
346 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
347 getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
349 if ( !anObj->_is_nil() )
350 objects.push_back( anObj._retn() );
356 //=================================================================================
357 // function : onReverse()
359 //=================================================================================
360 void GenerationGUI_RevolDlg::onReverse()
362 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
363 GroupPoints->SpinBox_DX->SetValue( -anOldValue );