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"));
134 //=================================================================================
135 // function : ClickOnOk()
137 //=================================================================================
138 void GenerationGUI_RevolDlg::ClickOnOk()
140 if ( ClickOnApply() )
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool GenerationGUI_RevolDlg::ClickOnApply()
158 //=======================================================================
159 //function : isAcceptableBase
160 //purpose : return true if theBase can be used as algo argument
161 //=======================================================================
163 static bool isAcceptableBase(const TopoDS_Shape& theBase)
165 switch ( theBase.ShapeType() ) {
173 case TopAbs_COMPSOLID:
175 case TopAbs_COMPOUND: {
176 TopExp_Explorer exp( theBase, TopAbs_SOLID);
185 //=================================================================================
186 // function : SelectionIntoArgument()
187 // purpose : Called when selection as changed or other case
188 //=================================================================================
189 void GenerationGUI_RevolDlg::SelectionIntoArgument()
192 myEditCurrentArgument->setText("");
194 if(mySelection->IObjectCount() != 1) {
195 if(myEditCurrentArgument == GroupPoints->LineEdit1)
197 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
203 Standard_Boolean testResult = Standard_False;
204 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
209 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
213 if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
216 myBase = aSelectedObject;
219 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
220 myAxis = aSelectedObject;
223 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
229 //=================================================================================
230 // function : SetEditCurrentArgument()
232 //=================================================================================
233 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
235 QPushButton* send = (QPushButton*)sender();
238 if(send == GroupPoints->PushButton1) {
239 GroupPoints->LineEdit1->setFocus();
240 myEditCurrentArgument = GroupPoints->LineEdit1;
242 else if(send == GroupPoints->PushButton2) {
243 GroupPoints->LineEdit2->setFocus();
244 myEditCurrentArgument = GroupPoints->LineEdit2;
245 globalSelection( GEOM_LINE );
247 SelectionIntoArgument();
251 //=================================================================================
252 // function : LineEditReturnPressed()
254 //=================================================================================
255 void GenerationGUI_RevolDlg::LineEditReturnPressed()
257 QLineEdit* send = (QLineEdit*)sender();
258 if(send == GroupPoints->LineEdit1 ||
259 send == GroupPoints->LineEdit2)
261 myEditCurrentArgument = send;
262 GEOMBase_Skeleton::LineEditReturnPressed();
267 //=================================================================================
268 // function : ActivateThisDialog()
270 //=================================================================================
271 void GenerationGUI_RevolDlg::ActivateThisDialog()
273 GEOMBase_Skeleton::ActivateThisDialog();
274 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
275 GroupPoints->LineEdit1->setFocus();
276 myEditCurrentArgument = GroupPoints->LineEdit1;
281 //=================================================================================
282 // function : enterEvent()
284 //=================================================================================
285 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
287 if ( !GroupConstructors->isEnabled() )
288 ActivateThisDialog();
292 //=================================================================================
293 // function : ValueChangedInSpinBox()
295 //=================================================================================
296 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
302 //=================================================================================
303 // function : getAngle()
305 //=================================================================================
306 double GenerationGUI_RevolDlg::getAngle() const
308 return GroupPoints->SpinBox_DX->GetValue();
311 //=================================================================================
312 // function : createOperation
314 //=================================================================================
315 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
317 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
320 //=================================================================================
321 // function : isValid
323 //=================================================================================
324 bool GenerationGUI_RevolDlg::isValid( QString& )
326 return myOkBase && myOkAxis;
329 //=================================================================================
330 // function : execute
332 //=================================================================================
333 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
335 GEOM::GEOM_Object_var anObj;
337 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
338 getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
340 if ( !anObj->_is_nil() )
341 objects.push_back( anObj._retn() );
347 //=================================================================================
348 // function : onReverse()
350 //=================================================================================
351 void GenerationGUI_RevolDlg::onReverse()
353 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
354 GroupPoints->SpinBox_DX->SetValue( -anOldValue );