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"
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <BRepAdaptor_Curve.hxx>
45 #include <BRepPrimAPI_MakeRevol.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include "GEOMImpl_Types.hxx"
50 #include <qcheckbox.h>
52 #include "utilities.h"
54 //=================================================================================
55 // class : GenerationGUI_RevolDlg()
56 // purpose : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
62 const char* name, bool modal, WFlags fl)
63 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
64 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
66 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
67 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
69 setCaption(tr("GEOM_REVOLUTION_TITLE"));
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->close(TRUE);
75 RadioButton3->close(TRUE);
78 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
79 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
80 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
81 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
82 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
83 GroupPoints->PushButton1->setPixmap(image1);
84 GroupPoints->PushButton2->setPixmap(image1);
85 GroupPoints->LineEdit1->setReadOnly( true );
86 GroupPoints->LineEdit2->setReadOnly( true );
87 GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
88 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
90 Layout1->addWidget(GroupPoints, 2, 0);
91 /***************************************************************/
93 setHelpFileName("create_revolution_page.html");
100 //=================================================================================
101 // function : ~GenerationGUI_RevolDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
106 // no need to delete child widgets, Qt does it all for us
110 //=================================================================================
113 //=================================================================================
114 void GenerationGUI_RevolDlg::Init()
117 myEditCurrentArgument = GroupPoints->LineEdit1;
118 GroupPoints->LineEdit1->setReadOnly( true );
119 GroupPoints->LineEdit2->setReadOnly( true );
121 myOkBase = myOkAxis = false;
123 double SpecificStep = 5;
124 /* min, max, step and decimals for spin boxes & initial values */
125 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
126 GroupPoints->SpinBox_DX->SetValue(45.0);
128 /* signals and slots connections */
129 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
139 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
140 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
142 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
144 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
145 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
147 initName(tr("GEOM_REVOLUTION"));
149 globalSelection( GEOM_ALLSHAPES );
153 //=================================================================================
154 // function : ClickOnOk()
156 //=================================================================================
157 void GenerationGUI_RevolDlg::ClickOnOk()
159 if ( ClickOnApply() )
164 //=================================================================================
165 // function : ClickOnApply()
167 //=================================================================================
168 bool GenerationGUI_RevolDlg::ClickOnApply()
177 //=======================================================================
178 //function : isAcceptableBase
179 //purpose : return true if theBase can be used as algo argument
180 //=======================================================================
182 static bool isAcceptableBase(const TopoDS_Shape& theBase)
184 switch ( theBase.ShapeType() ) {
192 case TopAbs_COMPSOLID:
194 case TopAbs_COMPOUND: {
195 TopExp_Explorer exp( theBase, TopAbs_SOLID);
204 //=================================================================================
205 // function : SelectionIntoArgument()
206 // purpose : Called when selection as changed or other case
207 //=================================================================================
208 void GenerationGUI_RevolDlg::SelectionIntoArgument()
211 myEditCurrentArgument->setText("");
213 if(IObjectCount() != 1) {
214 if(myEditCurrentArgument == GroupPoints->LineEdit1)
216 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
222 Standard_Boolean testResult = Standard_False;
223 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
224 QString aName = GEOMBase::GetName( aSelectedObject );
229 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
233 if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
236 myBase = aSelectedObject;
239 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
240 if ( testResult && !aSelectedObject->_is_nil() )
244 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
246 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
247 TColStd_IndexedMapOfInteger aMap;
248 aSelMgr->GetIndexes( firstIObject(), aMap );
249 if ( aMap.Extent() == 1 )
252 int anIndex = aMap( 1 );
253 aName.append( ":edge_" + QString::number( anIndex ) );
255 //Find SubShape Object in Father
256 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
258 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
259 GEOM::GEOM_IShapesOperations_var aShapesOp =
260 getGeomEngine()->GetIShapesOperations( getStudyId() );
261 myAxis = aShapesOp->GetSubShape(aSelectedObject, anIndex);
265 myAxis = aFindedObject;
271 if (aShape.ShapeType() != TopAbs_EDGE) {
272 aSelectedObject = GEOM::GEOM_Object::_nil();
276 myAxis = aSelectedObject;
281 myEditCurrentArgument->setText( aName );
287 //=================================================================================
288 // function : SetEditCurrentArgument()
290 //=================================================================================
291 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
293 QPushButton* send = (QPushButton*)sender();
294 globalSelection( GEOM_ALLSHAPES );
296 if(send == GroupPoints->PushButton1) {
297 GroupPoints->LineEdit1->setFocus();
298 myEditCurrentArgument = GroupPoints->LineEdit1;
300 else if(send == GroupPoints->PushButton2) {
301 GroupPoints->LineEdit2->setFocus();
302 myEditCurrentArgument = GroupPoints->LineEdit2;
303 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
305 SelectionIntoArgument();
309 //=================================================================================
310 // function : LineEditReturnPressed()
312 //=================================================================================
313 void GenerationGUI_RevolDlg::LineEditReturnPressed()
315 QLineEdit* send = (QLineEdit*)sender();
316 if(send == GroupPoints->LineEdit1 ||
317 send == GroupPoints->LineEdit2)
319 myEditCurrentArgument = send;
320 GEOMBase_Skeleton::LineEditReturnPressed();
325 //=================================================================================
326 // function : ActivateThisDialog()
328 //=================================================================================
329 void GenerationGUI_RevolDlg::ActivateThisDialog()
331 GEOMBase_Skeleton::ActivateThisDialog();
332 globalSelection( GEOM_ALLSHAPES );
333 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
334 GroupPoints->LineEdit1->setFocus();
335 myEditCurrentArgument = GroupPoints->LineEdit1;
340 //=================================================================================
341 // function : enterEvent()
343 //=================================================================================
344 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
346 if ( !GroupConstructors->isEnabled() )
347 ActivateThisDialog();
351 //=================================================================================
352 // function : ValueChangedInSpinBox()
354 //=================================================================================
355 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
361 //=================================================================================
362 // function : getAngle()
364 //=================================================================================
365 double GenerationGUI_RevolDlg::getAngle() const
367 return GroupPoints->SpinBox_DX->GetValue();
370 //=================================================================================
371 // function : createOperation
373 //=================================================================================
374 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
376 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
379 //=================================================================================
380 // function : isValid
382 //=================================================================================
383 bool GenerationGUI_RevolDlg::isValid( QString& )
385 return myOkBase && myOkAxis;
388 //=================================================================================
389 // function : execute
391 //=================================================================================
392 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
394 GEOM::GEOM_Object_var anObj;
397 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
398 getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
400 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
401 getOperation() )->MakeRevolutionAxisAngle2Ways( myBase, myAxis, getAngle() * PI180 );
403 if ( !anObj->_is_nil() )
404 objects.push_back( anObj._retn() );
410 //=================================================================================
411 // function : onReverse()
413 //=================================================================================
414 void GenerationGUI_RevolDlg::onReverse()
416 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
417 GroupPoints->SpinBox_DX->SetValue( -anOldValue );
420 //=================================================================================
421 // function : onBothway()
423 //=================================================================================
424 void GenerationGUI_RevolDlg::onBothway()
426 bool anOldValue = myBothway;
427 myBothway = !anOldValue;
428 GroupPoints->CheckButton2->setEnabled(!myBothway);
432 //=================================================================================
433 // function : addSubshapeToStudy
434 // purpose : virtual method to add new SubObjects if local selection
435 //=================================================================================
436 void GenerationGUI_RevolDlg::addSubshapesToStudy()
438 QMap<QString, GEOM::GEOM_Object_var> objMap;
440 objMap[GroupPoints->LineEdit2->text()] = myAxis;
442 addSubshapesToFather( objMap );