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 "GEOMImpl_Types.hxx"
43 #include <qcheckbox.h>
45 #include "utilities.h"
47 //=================================================================================
48 // class : GenerationGUI_RevolDlg()
49 // purpose : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
55 const char* name, bool modal, WFlags fl)
56 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
57 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
59 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
60 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
62 setCaption(tr("GEOM_REVOLUTION_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->close(TRUE);
68 RadioButton3->close(TRUE);
70 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
71 GroupPoints->CheckButton1->hide();
72 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
76 GroupPoints->PushButton1->setPixmap(image1);
77 GroupPoints->PushButton2->setPixmap(image1);
78 GroupPoints->LineEdit1->setReadOnly( true );
79 GroupPoints->LineEdit2->setReadOnly( true );
80 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
82 Layout1->addWidget(GroupPoints, 2, 0);
83 /***************************************************************/
85 setHelpFileName("revolution.htm");
92 //=================================================================================
93 // function : ~GenerationGUI_RevolDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
98 // no need to delete child widgets, Qt does it all for us
102 //=================================================================================
105 //=================================================================================
106 void GenerationGUI_RevolDlg::Init()
109 myEditCurrentArgument = GroupPoints->LineEdit1;
110 GroupPoints->LineEdit1->setReadOnly( true );
111 GroupPoints->LineEdit2->setReadOnly( true );
113 myOkBase = myOkAxis = false;
115 double SpecificStep = 5;
116 /* min, max, step and decimals for spin boxes & initial values */
117 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
118 GroupPoints->SpinBox_DX->SetValue(45.0);
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(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
131 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
133 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
135 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
136 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
138 initName(tr("GEOM_REVOLUTION"));
140 globalSelection( GEOM_ALLSHAPES );
144 //=================================================================================
145 // function : ClickOnOk()
147 //=================================================================================
148 void GenerationGUI_RevolDlg::ClickOnOk()
150 if ( ClickOnApply() )
155 //=================================================================================
156 // function : ClickOnApply()
158 //=================================================================================
159 bool GenerationGUI_RevolDlg::ClickOnApply()
168 //=======================================================================
169 //function : isAcceptableBase
170 //purpose : return true if theBase can be used as algo argument
171 //=======================================================================
173 static bool isAcceptableBase(const TopoDS_Shape& theBase)
175 switch ( theBase.ShapeType() ) {
183 case TopAbs_COMPSOLID:
185 case TopAbs_COMPOUND: {
186 TopExp_Explorer exp( theBase, TopAbs_SOLID);
195 //=================================================================================
196 // function : SelectionIntoArgument()
197 // purpose : Called when selection as changed or other case
198 //=================================================================================
199 void GenerationGUI_RevolDlg::SelectionIntoArgument()
202 myEditCurrentArgument->setText("");
204 if(IObjectCount() != 1) {
205 if(myEditCurrentArgument == GroupPoints->LineEdit1)
207 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
213 Standard_Boolean testResult = Standard_False;
214 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
219 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
223 if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
226 myBase = aSelectedObject;
229 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
230 myAxis = aSelectedObject;
233 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
239 //=================================================================================
240 // function : SetEditCurrentArgument()
242 //=================================================================================
243 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
245 QPushButton* send = (QPushButton*)sender();
246 globalSelection( GEOM_ALLSHAPES );
248 if(send == GroupPoints->PushButton1) {
249 GroupPoints->LineEdit1->setFocus();
250 myEditCurrentArgument = GroupPoints->LineEdit1;
252 else if(send == GroupPoints->PushButton2) {
253 GroupPoints->LineEdit2->setFocus();
254 myEditCurrentArgument = GroupPoints->LineEdit2;
255 globalSelection( GEOM_LINE );
257 SelectionIntoArgument();
261 //=================================================================================
262 // function : LineEditReturnPressed()
264 //=================================================================================
265 void GenerationGUI_RevolDlg::LineEditReturnPressed()
267 QLineEdit* send = (QLineEdit*)sender();
268 if(send == GroupPoints->LineEdit1 ||
269 send == GroupPoints->LineEdit2)
271 myEditCurrentArgument = send;
272 GEOMBase_Skeleton::LineEditReturnPressed();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void GenerationGUI_RevolDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
284 globalSelection( GEOM_ALLSHAPES );
285 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
286 GroupPoints->LineEdit1->setFocus();
287 myEditCurrentArgument = GroupPoints->LineEdit1;
292 //=================================================================================
293 // function : enterEvent()
295 //=================================================================================
296 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
298 if ( !GroupConstructors->isEnabled() )
299 ActivateThisDialog();
303 //=================================================================================
304 // function : ValueChangedInSpinBox()
306 //=================================================================================
307 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
313 //=================================================================================
314 // function : getAngle()
316 //=================================================================================
317 double GenerationGUI_RevolDlg::getAngle() const
319 return GroupPoints->SpinBox_DX->GetValue();
322 //=================================================================================
323 // function : createOperation
325 //=================================================================================
326 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
328 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
331 //=================================================================================
332 // function : isValid
334 //=================================================================================
335 bool GenerationGUI_RevolDlg::isValid( QString& )
337 return myOkBase && myOkAxis;
340 //=================================================================================
341 // function : execute
343 //=================================================================================
344 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
346 GEOM::GEOM_Object_var anObj;
348 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
349 getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
351 if ( !anObj->_is_nil() )
352 objects.push_back( anObj._retn() );
358 //=================================================================================
359 // function : onReverse()
361 //=================================================================================
362 void GenerationGUI_RevolDlg::onReverse()
364 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
365 GroupPoints->SpinBox_DX->SetValue( -anOldValue );