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 : GenerationGUI_RevolDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GenerationGUI_RevolDlg.h"
32 #include <BRepAdaptor_Curve.hxx>
33 #include <BRepPrimAPI_MakeRevol.hxx>
34 #include "QAD_Config.h"
35 #include "QAD_Desktop.h"
36 #include <TopExp_Explorer.hxx>
37 #include <Standard_ErrorHandler.hxx>
38 #include "GEOMImpl_Types.hxx"
40 #include <qcheckbox.h>
42 #include "utilities.h"
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(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
55 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_REVOLUTION_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
65 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
66 GroupPoints->CheckButton1->hide();
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
71 GroupPoints->PushButton1->setPixmap(image1);
72 GroupPoints->PushButton2->setPixmap(image1);
73 GroupPoints->LineEdit1->setReadOnly( true );
74 GroupPoints->LineEdit2->setReadOnly( true );
75 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
77 Layout1->addWidget(GroupPoints, 2, 0);
78 /***************************************************************/
85 //=================================================================================
86 // function : ~GenerationGUI_RevolDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
91 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void GenerationGUI_RevolDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 GroupPoints->LineEdit1->setReadOnly( true );
104 GroupPoints->LineEdit2->setReadOnly( true );
106 myOkBase = myOkAxis = false;
108 double SpecificStep = 5;
109 /* min, max, step and decimals for spin boxes & initial values */
110 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
111 GroupPoints->SpinBox_DX->SetValue(45.0);
113 /* signals and slots connections */
114 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
117 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
124 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
126 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
128 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
130 initName(tr("GEOM_REVOLUTION"));
132 globalSelection( GEOM_ALLSHAPES );
136 //=================================================================================
137 // function : ClickOnOk()
139 //=================================================================================
140 void GenerationGUI_RevolDlg::ClickOnOk()
142 if ( ClickOnApply() )
147 //=================================================================================
148 // function : ClickOnApply()
150 //=================================================================================
151 bool GenerationGUI_RevolDlg::ClickOnApply()
160 //=======================================================================
161 //function : isAcceptableBase
162 //purpose : return true if theBase can be used as algo argument
163 //=======================================================================
165 static bool isAcceptableBase(const TopoDS_Shape& theBase)
167 switch ( theBase.ShapeType() ) {
175 case TopAbs_COMPSOLID:
177 case TopAbs_COMPOUND: {
178 TopExp_Explorer exp( theBase, TopAbs_SOLID);
187 //=================================================================================
188 // function : SelectionIntoArgument()
189 // purpose : Called when selection as changed or other case
190 //=================================================================================
191 void GenerationGUI_RevolDlg::SelectionIntoArgument()
194 myEditCurrentArgument->setText("");
196 if(mySelection->IObjectCount() != 1) {
197 if(myEditCurrentArgument == GroupPoints->LineEdit1)
199 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
205 Standard_Boolean testResult = Standard_False;
206 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
211 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
215 if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
218 myBase = aSelectedObject;
221 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
222 myAxis = aSelectedObject;
225 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
231 //=================================================================================
232 // function : SetEditCurrentArgument()
234 //=================================================================================
235 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
237 QPushButton* send = (QPushButton*)sender();
238 globalSelection( GEOM_ALLSHAPES );
240 if(send == GroupPoints->PushButton1) {
241 GroupPoints->LineEdit1->setFocus();
242 myEditCurrentArgument = GroupPoints->LineEdit1;
244 else if(send == GroupPoints->PushButton2) {
245 GroupPoints->LineEdit2->setFocus();
246 myEditCurrentArgument = GroupPoints->LineEdit2;
247 globalSelection( GEOM_LINE );
249 SelectionIntoArgument();
253 //=================================================================================
254 // function : LineEditReturnPressed()
256 //=================================================================================
257 void GenerationGUI_RevolDlg::LineEditReturnPressed()
259 QLineEdit* send = (QLineEdit*)sender();
260 if(send == GroupPoints->LineEdit1 ||
261 send == GroupPoints->LineEdit2)
263 myEditCurrentArgument = send;
264 GEOMBase_Skeleton::LineEditReturnPressed();
269 //=================================================================================
270 // function : ActivateThisDialog()
272 //=================================================================================
273 void GenerationGUI_RevolDlg::ActivateThisDialog()
275 GEOMBase_Skeleton::ActivateThisDialog();
276 globalSelection( GEOM_ALLSHAPES );
277 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
278 GroupPoints->LineEdit1->setFocus();
279 myEditCurrentArgument = GroupPoints->LineEdit1;
284 //=================================================================================
285 // function : enterEvent()
287 //=================================================================================
288 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
290 if ( !GroupConstructors->isEnabled() )
291 ActivateThisDialog();
295 //=================================================================================
296 // function : ValueChangedInSpinBox()
298 //=================================================================================
299 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
305 //=================================================================================
306 // function : getAngle()
308 //=================================================================================
309 double GenerationGUI_RevolDlg::getAngle() const
311 return GroupPoints->SpinBox_DX->GetValue();
314 //=================================================================================
315 // function : createOperation
317 //=================================================================================
318 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
320 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
323 //=================================================================================
324 // function : isValid
326 //=================================================================================
327 bool GenerationGUI_RevolDlg::isValid( QString& )
329 return myOkBase && myOkAxis;
332 //=================================================================================
333 // function : execute
335 //=================================================================================
336 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
338 GEOM::GEOM_Object_var anObj;
340 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
341 getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
343 if ( !anObj->_is_nil() )
344 objects.push_back( anObj._retn() );
350 //=================================================================================
351 // function : onReverse()
353 //=================================================================================
354 void GenerationGUI_RevolDlg::onReverse()
356 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
357 GroupPoints->SpinBox_DX->SetValue( -anOldValue );