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"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
37 #include <BRepAdaptor_Curve.hxx>
38 #include <BRepPrimAPI_MakeRevol.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <Standard_ErrorHandler.hxx>
41 #include "GEOMImpl_Types.hxx"
44 #include <qcheckbox.h>
46 #include "utilities.h"
48 //=================================================================================
49 // class : GenerationGUI_RevolDlg()
50 // purpose : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
56 const char* name, bool modal, WFlags fl)
57 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
58 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
60 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
61 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
63 setCaption(tr("GEOM_REVOLUTION_TITLE"));
65 /***************************************************************/
66 GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
67 RadioButton1->setPixmap(image0);
68 RadioButton2->close(TRUE);
69 RadioButton3->close(TRUE);
71 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
72 GroupPoints->CheckButton1->hide();
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
76 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
77 GroupPoints->PushButton1->setPixmap(image1);
78 GroupPoints->PushButton2->setPixmap(image1);
79 GroupPoints->LineEdit1->setReadOnly( true );
80 GroupPoints->LineEdit2->setReadOnly( true );
81 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
83 Layout1->addWidget(GroupPoints, 2, 0);
84 /***************************************************************/
86 setHelpFileName("revolution.htm");
93 //=================================================================================
94 // function : ~GenerationGUI_RevolDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
99 // no need to delete child widgets, Qt does it all for us
103 //=================================================================================
106 //=================================================================================
107 void GenerationGUI_RevolDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
111 GroupPoints->LineEdit1->setReadOnly( true );
112 GroupPoints->LineEdit2->setReadOnly( true );
114 myOkBase = myOkAxis = false;
116 double SpecificStep = 5;
117 /* min, max, step and decimals for spin boxes & initial values */
118 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, 3);
119 GroupPoints->SpinBox_DX->SetValue(45.0);
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(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
132 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
134 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
136 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
137 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
139 initName(tr("GEOM_REVOLUTION"));
141 globalSelection( GEOM_ALLSHAPES );
145 //=================================================================================
146 // function : ClickOnOk()
148 //=================================================================================
149 void GenerationGUI_RevolDlg::ClickOnOk()
151 if ( ClickOnApply() )
156 //=================================================================================
157 // function : ClickOnApply()
159 //=================================================================================
160 bool GenerationGUI_RevolDlg::ClickOnApply()
169 //=======================================================================
170 //function : isAcceptableBase
171 //purpose : return true if theBase can be used as algo argument
172 //=======================================================================
174 static bool isAcceptableBase(const TopoDS_Shape& theBase)
176 switch ( theBase.ShapeType() ) {
184 case TopAbs_COMPSOLID:
186 case TopAbs_COMPOUND: {
187 TopExp_Explorer exp( theBase, TopAbs_SOLID);
196 //=================================================================================
197 // function : SelectionIntoArgument()
198 // purpose : Called when selection as changed or other case
199 //=================================================================================
200 void GenerationGUI_RevolDlg::SelectionIntoArgument()
203 myEditCurrentArgument->setText("");
205 if(IObjectCount() != 1) {
206 if(myEditCurrentArgument == GroupPoints->LineEdit1)
208 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
214 Standard_Boolean testResult = Standard_False;
215 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
220 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
224 if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
227 myBase = aSelectedObject;
230 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
231 myAxis = aSelectedObject;
234 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
240 //=================================================================================
241 // function : SetEditCurrentArgument()
243 //=================================================================================
244 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
246 QPushButton* send = (QPushButton*)sender();
247 globalSelection( GEOM_ALLSHAPES );
249 if(send == GroupPoints->PushButton1) {
250 GroupPoints->LineEdit1->setFocus();
251 myEditCurrentArgument = GroupPoints->LineEdit1;
253 else if(send == GroupPoints->PushButton2) {
254 GroupPoints->LineEdit2->setFocus();
255 myEditCurrentArgument = GroupPoints->LineEdit2;
256 globalSelection( GEOM_LINE );
258 SelectionIntoArgument();
262 //=================================================================================
263 // function : LineEditReturnPressed()
265 //=================================================================================
266 void GenerationGUI_RevolDlg::LineEditReturnPressed()
268 QLineEdit* send = (QLineEdit*)sender();
269 if(send == GroupPoints->LineEdit1 ||
270 send == GroupPoints->LineEdit2)
272 myEditCurrentArgument = send;
273 GEOMBase_Skeleton::LineEditReturnPressed();
278 //=================================================================================
279 // function : ActivateThisDialog()
281 //=================================================================================
282 void GenerationGUI_RevolDlg::ActivateThisDialog()
284 GEOMBase_Skeleton::ActivateThisDialog();
285 globalSelection( GEOM_ALLSHAPES );
286 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
287 GroupPoints->LineEdit1->setFocus();
288 myEditCurrentArgument = GroupPoints->LineEdit1;
293 //=================================================================================
294 // function : enterEvent()
296 //=================================================================================
297 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
299 if ( !GroupConstructors->isEnabled() )
300 ActivateThisDialog();
304 //=================================================================================
305 // function : ValueChangedInSpinBox()
307 //=================================================================================
308 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
314 //=================================================================================
315 // function : getAngle()
317 //=================================================================================
318 double GenerationGUI_RevolDlg::getAngle() const
320 return GroupPoints->SpinBox_DX->GetValue();
323 //=================================================================================
324 // function : createOperation
326 //=================================================================================
327 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
329 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
332 //=================================================================================
333 // function : isValid
335 //=================================================================================
336 bool GenerationGUI_RevolDlg::isValid( QString& )
338 return myOkBase && myOkAxis;
341 //=================================================================================
342 // function : execute
344 //=================================================================================
345 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
347 GEOM::GEOM_Object_var anObj;
349 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
350 getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
352 if ( !anObj->_is_nil() )
353 objects.push_back( anObj._retn() );
359 //=================================================================================
360 // function : onReverse()
362 //=================================================================================
363 void GenerationGUI_RevolDlg::onReverse()
365 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
366 GroupPoints->SpinBox_DX->SetValue( -anOldValue );