1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GenerationGUI_RevolDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "GenerationGUI_RevolDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <TopExp_Explorer.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : GenerationGUI_RevolDlg()
50 // purpose : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
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 setWindowTitle(tr("GEOM_REVOLUTION_TITLE"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
66 mainFrame()->RadioButton1->setIcon(image0);
67 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
70 mainFrame()->RadioButton3->close();
72 GroupPoints = new DlgRef_2Sel1Spin2Check(centralWidget());
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
76 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
77 GroupPoints->PushButton1->setIcon(image1);
78 GroupPoints->PushButton2->setIcon(image1);
79 GroupPoints->LineEdit1->setReadOnly(true);
80 GroupPoints->LineEdit2->setReadOnly(true);
81 GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
82 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
84 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
85 layout->setMargin(0); layout->setSpacing(6);
86 layout->addWidget(GroupPoints);
87 /***************************************************************/
89 setHelpFileName("create_revolution_page.html");
95 //=================================================================================
96 // function : ~GenerationGUI_RevolDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
101 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void GenerationGUI_RevolDlg::Init()
110 // min, max, step and decimals for spin boxes & initial values
111 double SpecificStep = 5;
112 initSpinBox(GroupPoints->SpinBox_DX, -360.0, 360.0, SpecificStep, "angle_precision" );
113 GroupPoints->SpinBox_DX->setValue(45.0);
116 GroupPoints->LineEdit1->setReadOnly(true);
117 GroupPoints->LineEdit2->setReadOnly(true);
119 GroupPoints->LineEdit1->setText("");
120 GroupPoints->LineEdit2->setText("");
122 myBaseObjects.clear();
125 // signals and slots connections
126 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
133 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
134 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
136 // san: We don't need this, as the default step value is not used in this dialog box
137 //connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
139 initName(tr("GEOM_REVOLUTION"));
142 GroupPoints->PushButton1->click();
143 SelectionIntoArgument();
146 //=================================================================================
147 // function : SetDoubleSpinBoxStep()
148 // purpose : Double spin box management
149 //=================================================================================
150 void GenerationGUI_RevolDlg::SetDoubleSpinBoxStep (double step)
152 GroupPoints->SpinBox_DX->setSingleStep(step);
155 //=================================================================================
156 // function : ClickOnOk()
158 //=================================================================================
159 void GenerationGUI_RevolDlg::ClickOnOk()
165 //=================================================================================
166 // function : ClickOnApply()
168 //=================================================================================
169 bool GenerationGUI_RevolDlg::ClickOnApply()
175 // activate selection and connect selection manager
176 GroupPoints->PushButton1->click();
180 //=================================================================================
181 // function : SelectionIntoArgument()
182 // purpose : Called when selection is changed or on dialog initialization or activation
183 //=================================================================================
184 void GenerationGUI_RevolDlg::SelectionIntoArgument()
187 myEditCurrentArgument->setText("");
189 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
190 myBaseObjects.clear();
191 QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
192 for ( int i = 0; i < objects.count(); i++ ) {
193 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
194 if ( stype < GEOM::SHELL || stype > GEOM::VERTEX )
196 myBaseObjects << objects[i];
198 if ( !myBaseObjects.isEmpty() ) {
199 QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
200 myEditCurrentArgument->setText( aName );
203 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
204 myAxis = getSelected( TopAbs_EDGE );
206 QString aName = GEOMBase::GetName( myAxis.get() );
207 myEditCurrentArgument->setText( aName );
208 if ( myBaseObjects.isEmpty() )
209 GroupPoints->PushButton1->click();
215 //=================================================================================
216 // function : SetEditCurrentArgument()
218 //=================================================================================
219 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
221 QPushButton* send = (QPushButton*)sender();
223 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
224 globalSelection(GEOM_ALLSHAPES);
225 if (send == GroupPoints->PushButton1) {
226 myEditCurrentArgument = GroupPoints->LineEdit1;
227 GroupPoints->PushButton2->setDown(false);
228 GroupPoints->LineEdit2->setEnabled(false);
230 else if (send == GroupPoints->PushButton2) {
231 myEditCurrentArgument = GroupPoints->LineEdit2;
232 GroupPoints->PushButton1->setDown(false);
233 GroupPoints->LineEdit1->setEnabled(false);
234 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
236 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
237 this, SLOT(SelectionIntoArgument()));
240 myEditCurrentArgument->setEnabled(true);
241 myEditCurrentArgument->setFocus();
242 // after setFocus(), because it will be setDown(false) when loses focus
245 // seems we need it only to avoid preview disappearing, caused by selection mode change
249 //=================================================================================
250 // function : ActivateThisDialog()
252 //=================================================================================
253 void GenerationGUI_RevolDlg::ActivateThisDialog()
255 GEOMBase_Skeleton::ActivateThisDialog();
256 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
257 this, SLOT( SelectionIntoArgument() ) );
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void GenerationGUI_RevolDlg::enterEvent (QEvent*)
268 if (!mainFrame()->GroupConstructors->isEnabled())
269 ActivateThisDialog();
272 //=================================================================================
273 // function : ValueChangedInSpinBox()
275 //=================================================================================
276 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
281 //=================================================================================
282 // function : getAngle()
284 //=================================================================================
285 double GenerationGUI_RevolDlg::getAngle() const
287 return GroupPoints->SpinBox_DX->value();
290 //=================================================================================
291 // function : createOperation
293 //=================================================================================
294 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
296 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
299 //=================================================================================
300 // function : isValid
302 //=================================================================================
303 bool GenerationGUI_RevolDlg::isValid (QString& msg)
305 return GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myBaseObjects.isEmpty() && myAxis;
308 //=================================================================================
309 // function : execute
311 //=================================================================================
312 bool GenerationGUI_RevolDlg::execute (ObjectList& objects)
314 GEOM::GEOM_Object_var anObj;
315 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
317 for (int i = 0; i < myBaseObjects.count(); i++) {
318 if (!GroupPoints->CheckButton1->isChecked())
319 anObj = anOper->MakeRevolutionAxisAngle(myBaseObjects[i].get(), myAxis.get(), getAngle() * PI180);
321 anObj = anOper->MakeRevolutionAxisAngle2Ways(myBaseObjects[i].get(), myAxis.get(), getAngle() * PI180);
323 if (!anObj->_is_nil()) {
325 QStringList aParameters;
326 aParameters << GroupPoints->SpinBox_DX->text();
327 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
329 objects.push_back(anObj._retn());
336 //=================================================================================
337 // function : onReverse()
339 //=================================================================================
340 void GenerationGUI_RevolDlg::onReverse()
342 double anOldValue = GroupPoints->SpinBox_DX->value();
343 GroupPoints->SpinBox_DX->setValue(-anOldValue);
346 //=================================================================================
347 // function : onBothway()
349 //=================================================================================
350 void GenerationGUI_RevolDlg::onBothway()
352 GroupPoints->CheckButton2->setEnabled(!GroupPoints->CheckButton1->isChecked());
356 //=================================================================================
357 // function : addSubshapeToStudy
358 // purpose : virtual method to add new SubObjects if local selection
359 //=================================================================================
360 void GenerationGUI_RevolDlg::addSubshapesToStudy()
362 GEOMBase::PublishSubObject( myAxis.get() );
365 //=================================================================================
366 // function : extractPrefix
367 // purpose : redefined from GEOMBase_Helper class
368 //=================================================================================
369 bool GenerationGUI_RevolDlg::extractPrefix() const
371 return myBaseObjects.count() > 1;