1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GenerationGUI_RevolDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "GenerationGUI_RevolDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <BRepPrimAPI_MakeRevol.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include "GEOMImpl_Types.hxx"
49 #include <qcheckbox.h>
51 #include "utilities.h"
53 //=================================================================================
54 // class : GenerationGUI_RevolDlg()
55 // purpose : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
61 const char* name, bool modal, WFlags fl)
62 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
63 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
65 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
66 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
68 setCaption(tr("GEOM_REVOLUTION_TITLE"));
70 /***************************************************************/
71 GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
72 RadioButton1->setPixmap(image0);
73 RadioButton2->close(TRUE);
74 RadioButton3->close(TRUE);
77 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
80 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
81 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
82 GroupPoints->PushButton1->setPixmap(image1);
83 GroupPoints->PushButton2->setPixmap(image1);
84 GroupPoints->LineEdit1->setReadOnly( true );
85 GroupPoints->LineEdit2->setReadOnly( true );
86 GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
87 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
89 Layout1->addWidget(GroupPoints, 2, 0);
90 /***************************************************************/
92 setHelpFileName("create_revolution_page.html");
99 //=================================================================================
100 // function : ~GenerationGUI_RevolDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
105 // no need to delete child widgets, Qt does it all for us
109 //=================================================================================
112 //=================================================================================
113 void GenerationGUI_RevolDlg::Init()
116 myEditCurrentArgument = GroupPoints->LineEdit1;
117 GroupPoints->LineEdit1->setReadOnly( true );
118 GroupPoints->LineEdit2->setReadOnly( true );
120 myOkBase = myOkAxis = false;
122 double SpecificStep = 5;
123 /* min, max, step and decimals for spin boxes & initial values */
124 //GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX,
125 // SpecificStep, DBL_DIGITS_DISPLAY);
126 // 05.06.2008 skl for IPAL12958
127 GroupPoints->SpinBox_DX->RangeStepAndValidator(-360.0, 360.0, SpecificStep, DBL_DIGITS_DISPLAY);
128 GroupPoints->SpinBox_DX->SetValue(45.0);
130 /* signals and slots connections */
131 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
141 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
142 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
144 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
146 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
147 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
149 initName(tr("GEOM_REVOLUTION"));
151 globalSelection( GEOM_ALLSHAPES );
155 //=================================================================================
156 // function : ClickOnOk()
158 //=================================================================================
159 void GenerationGUI_RevolDlg::ClickOnOk()
161 if ( ClickOnApply() )
166 //=================================================================================
167 // function : ClickOnApply()
169 //=================================================================================
170 bool GenerationGUI_RevolDlg::ClickOnApply()
179 //=======================================================================
180 //function : isAcceptableBase
181 //purpose : return true if theBase can be used as algo argument
182 //=======================================================================
184 static bool isAcceptableBase(const TopoDS_Shape& theBase)
186 switch ( theBase.ShapeType() ) {
194 case TopAbs_COMPSOLID:
196 case TopAbs_COMPOUND: {
197 TopExp_Explorer exp( theBase, TopAbs_SOLID);
206 //=================================================================================
207 // function : SelectionIntoArgument()
208 // purpose : Called when selection as changed or other case
209 //=================================================================================
210 void GenerationGUI_RevolDlg::SelectionIntoArgument()
213 myEditCurrentArgument->setText("");
215 if(IObjectCount() != 1) {
216 if(myEditCurrentArgument == GroupPoints->LineEdit1)
218 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
224 Standard_Boolean testResult = Standard_False;
225 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
226 QString aName = GEOMBase::GetName( aSelectedObject );
231 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
235 if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
238 myBase = aSelectedObject;
241 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
242 if ( testResult && !aSelectedObject->_is_nil() )
246 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
248 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
249 TColStd_IndexedMapOfInteger aMap;
250 aSelMgr->GetIndexes( firstIObject(), aMap );
251 if ( aMap.Extent() == 1 )
254 int anIndex = aMap( 1 );
255 aName.append( ":edge_" + QString::number( anIndex ) );
257 //Find SubShape Object in Father
258 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
260 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
261 GEOM::GEOM_IShapesOperations_var aShapesOp =
262 getGeomEngine()->GetIShapesOperations( getStudyId() );
263 myAxis = aShapesOp->GetSubShape(aSelectedObject, anIndex);
267 myAxis = aFindedObject;
273 if (aShape.ShapeType() != TopAbs_EDGE) {
274 aSelectedObject = GEOM::GEOM_Object::_nil();
278 myAxis = aSelectedObject;
283 myEditCurrentArgument->setText( aName );
289 //=================================================================================
290 // function : SetEditCurrentArgument()
292 //=================================================================================
293 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
295 QPushButton* send = (QPushButton*)sender();
296 globalSelection( GEOM_ALLSHAPES );
298 if(send == GroupPoints->PushButton1) {
299 GroupPoints->LineEdit1->setFocus();
300 myEditCurrentArgument = GroupPoints->LineEdit1;
302 else if(send == GroupPoints->PushButton2) {
303 GroupPoints->LineEdit2->setFocus();
304 myEditCurrentArgument = GroupPoints->LineEdit2;
305 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
307 SelectionIntoArgument();
311 //=================================================================================
312 // function : LineEditReturnPressed()
314 //=================================================================================
315 void GenerationGUI_RevolDlg::LineEditReturnPressed()
317 QLineEdit* send = (QLineEdit*)sender();
318 if(send == GroupPoints->LineEdit1 ||
319 send == GroupPoints->LineEdit2)
321 myEditCurrentArgument = send;
322 GEOMBase_Skeleton::LineEditReturnPressed();
327 //=================================================================================
328 // function : ActivateThisDialog()
330 //=================================================================================
331 void GenerationGUI_RevolDlg::ActivateThisDialog()
333 GEOMBase_Skeleton::ActivateThisDialog();
334 globalSelection( GEOM_ALLSHAPES );
335 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
336 GroupPoints->LineEdit1->setFocus();
337 myEditCurrentArgument = GroupPoints->LineEdit1;
342 //=================================================================================
343 // function : enterEvent()
345 //=================================================================================
346 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
348 if ( !GroupConstructors->isEnabled() )
349 ActivateThisDialog();
353 //=================================================================================
354 // function : ValueChangedInSpinBox()
356 //=================================================================================
357 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
363 //=================================================================================
364 // function : getAngle()
366 //=================================================================================
367 double GenerationGUI_RevolDlg::getAngle() const
369 return GroupPoints->SpinBox_DX->GetValue();
372 //=================================================================================
373 // function : createOperation
375 //=================================================================================
376 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
378 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
381 //=================================================================================
382 // function : isValid
384 //=================================================================================
385 bool GenerationGUI_RevolDlg::isValid( QString& )
387 return myOkBase && myOkAxis;
390 //=================================================================================
391 // function : execute
393 //=================================================================================
394 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
396 GEOM::GEOM_Object_var anObj;
399 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
400 getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
402 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
403 getOperation() )->MakeRevolutionAxisAngle2Ways( myBase, myAxis, getAngle() * PI180 );
405 if ( !anObj->_is_nil() )
406 objects.push_back( anObj._retn() );
412 //=================================================================================
413 // function : onReverse()
415 //=================================================================================
416 void GenerationGUI_RevolDlg::onReverse()
418 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
419 GroupPoints->SpinBox_DX->SetValue( -anOldValue );
422 //=================================================================================
423 // function : onBothway()
425 //=================================================================================
426 void GenerationGUI_RevolDlg::onBothway()
428 bool anOldValue = myBothway;
429 myBothway = !anOldValue;
430 GroupPoints->CheckButton2->setEnabled(!myBothway);
434 //=================================================================================
435 // function : addSubshapeToStudy
436 // purpose : virtual method to add new SubObjects if local selection
437 //=================================================================================
438 void GenerationGUI_RevolDlg::addSubshapesToStudy()
440 QMap<QString, GEOM::GEOM_Object_var> objMap;
442 objMap[GroupPoints->LineEdit2->text()] = myAxis;
444 addSubshapesToFather( objMap );