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 <TopExp_Explorer.hxx>
36 #include <Standard_ErrorHandler.hxx>
38 #include "utilities.h"
42 //=================================================================================
43 // class : GenerationGUI_RevolDlg()
44 // purpose : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_REVOLUTION_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_2Sel1Spin1Check(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
66 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
67 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
68 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->PushButton2->setPixmap(image1);
72 Layout1->addWidget(GroupPoints, 1, 0);
73 /***************************************************************/
76 myGenerationGUI = theGenerationGUI;
81 //=================================================================================
82 // function : ~GenerationGUI_RevolDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
87 // no need to delete child widgets, Qt does it all for us
91 //=================================================================================
94 //=================================================================================
95 void GenerationGUI_RevolDlg::Init()
98 myEditCurrentArgument = GroupPoints->LineEdit1;
101 myOkBase = myOkAxis = false;
103 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
105 double SpecificStep = 5;
106 /* min, max, step and decimals for spin boxes & initial values */
107 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
108 GroupPoints->SpinBox_DX->SetValue(myAngle);
110 /* signals and slots connections */
111 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
121 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
123 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
125 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
127 /* displays Dialog */
135 //=================================================================================
136 // function : ClickOnOk()
138 //=================================================================================
139 void GenerationGUI_RevolDlg::ClickOnOk()
141 this->ClickOnApply();
147 //=================================================================================
148 // function : ClickOnApply()
150 //=================================================================================
151 void GenerationGUI_RevolDlg::ClickOnApply()
153 buttonApply->setFocus();
154 QAD_Application::getDesktop()->putInfo(tr(""));
155 if (mySimulationTopoDs.IsNull())
157 myGeomBase->EraseSimulationShape();
158 mySimulationTopoDs.Nullify();
160 if(myOkBase && myOkAxis)
161 myGenerationGUI->MakeRevolutionAndDisplay(myGeomShape, myLoc, myDir, myAngle*PI180);
165 //=======================================================================
166 //function : isAcceptableBase
167 //purpose : return true if theBase can be used as algo argument
168 //=======================================================================
170 static bool isAcceptableBase(const TopoDS_Shape& theBase)
172 switch ( theBase.ShapeType() ) {
180 case TopAbs_COMPSOLID:
182 case TopAbs_COMPOUND: {
183 TopExp_Explorer exp( theBase, TopAbs_SOLID);
192 //=================================================================================
193 // function : SelectionIntoArgument()
194 // purpose : Called when selection as changed or other case
195 //=================================================================================
196 void GenerationGUI_RevolDlg::SelectionIntoArgument()
198 myGeomBase->EraseSimulationShape();
199 mySimulationTopoDs.Nullify();
200 myEditCurrentArgument->setText("");
201 QString aString = ""; /* name of selection */
203 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
205 if(myEditCurrentArgument == GroupPoints->LineEdit1)
207 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
214 Standard_Boolean testResult;
215 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
216 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
219 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
220 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
223 if( !isAcceptableBase( S ))
225 myEditCurrentArgument->setText(aString);
229 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
230 BRepAdaptor_Curve curv(TopoDS::Edge(S));
231 myDir = curv.Line().Direction();
232 myLoc = curv.Line().Location();
233 myEditCurrentArgument->setText(aString);
237 if(myOkBase && myOkAxis)
238 this->MakeRevolutionSimulationAndDisplay();
243 //=================================================================================
244 // function : SetEditCurrentArgument()
246 //=================================================================================
247 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
249 QPushButton* send = (QPushButton*)sender();
250 mySelection->ClearFilters();
252 if(send == GroupPoints->PushButton1) {
253 GroupPoints->LineEdit1->setFocus();
254 myEditCurrentArgument = GroupPoints->LineEdit1;
256 else if(send == GroupPoints->PushButton2) {
257 GroupPoints->LineEdit2->setFocus();
258 myEditCurrentArgument = GroupPoints->LineEdit2;
259 mySelection->AddFilter(myEdgeFilter);
261 this->SelectionIntoArgument();
267 //=================================================================================
268 // function : LineEditReturnPressed()
270 //=================================================================================
271 void GenerationGUI_RevolDlg::LineEditReturnPressed()
273 QLineEdit* send = (QLineEdit*)sender();
274 if(send == GroupPoints->LineEdit1)
275 myEditCurrentArgument = GroupPoints->LineEdit1;
276 else if (send == GroupPoints->LineEdit2)
277 myEditCurrentArgument = GroupPoints->LineEdit2;
281 GEOMBase_Skeleton::LineEditReturnPressed();
286 //=================================================================================
287 // function : ActivateThisDialog()
289 //=================================================================================
290 void GenerationGUI_RevolDlg::ActivateThisDialog()
292 GEOMBase_Skeleton::ActivateThisDialog();
293 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
294 GroupPoints->LineEdit1->setFocus();
295 myEditCurrentArgument = GroupPoints->LineEdit1;
296 if(!mySimulationTopoDs.IsNull())
297 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
302 //=================================================================================
303 // function : enterEvent()
305 //=================================================================================
306 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
308 if (GroupConstructors->isEnabled())
310 this->ActivateThisDialog();
315 //=================================================================================
316 // function : ValueChangedInSpinBox()
318 //=================================================================================
319 void GenerationGUI_RevolDlg::ValueChangedInSpinBox(double newValue)
322 if(myOkBase && myOkAxis)
323 this->MakeRevolutionSimulationAndDisplay();
328 //=================================================================================
329 // function : ReverseAngle()
330 // purpose : 'state' not used here
331 //=================================================================================
332 void GenerationGUI_RevolDlg::ReverseAngle(int state)
335 GroupPoints->SpinBox_DX->SetValue(myAngle);
336 if(myOkBase && myOkAxis)
337 this->MakeRevolutionSimulationAndDisplay();
342 //=================================================================================
343 // function : MakeRevolutionSimulationAndDisplay()
345 //=================================================================================
346 void GenerationGUI_RevolDlg::MakeRevolutionSimulationAndDisplay()
348 myGeomBase->EraseSimulationShape();
349 mySimulationTopoDs.Nullify();
351 if (!isAcceptableBase( myBase ))
355 gp_Ax1 AX(myLoc, myDir);
356 mySimulationTopoDs = BRepPrimAPI_MakeRevol(myBase, AX, myAngle*PI180);
357 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
359 catch(Standard_Failure) {
360 MESSAGE("Exception catched in MakeRevolutionSimulationAndDisplay");