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_PrismDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GenerationGUI_PrismDlg.h"
32 #include <BRepPrimAPI_MakePrism.hxx>
33 #include "QAD_Config.h"
35 //=================================================================================
36 // class : GenerationGUI_PrismDlg()
37 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
43 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PRISM")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48 setCaption(tr("GEOM_PRISM_TITLE"));
50 /***************************************************************/
51 GroupConstructors->setTitle(tr("GEOM_PRISM"));
52 RadioButton1->setPixmap(image0);
53 RadioButton2->close(TRUE);
54 RadioButton3->close(TRUE);
56 GroupPoints = new DlgRef_2Sel1Spin1Check(this, "GroupPoints");
57 GroupPoints->GroupBox1->setTitle(tr("GEOM_PRISM_BSV"));
58 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
59 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
60 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
61 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE"));
62 GroupPoints->PushButton1->setPixmap(image1);
63 GroupPoints->PushButton2->setPixmap(image1);
65 Layout1->addWidget(GroupPoints, 1, 0);
66 /***************************************************************/
69 myGenerationGUI = theGenerationGUI;
74 //=================================================================================
75 // function : ~GenerationGUI_PrismDlg()
76 // purpose : Destroys the object and frees any allocated resources
77 //=================================================================================
78 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
80 /* no need to delete child widgets, Qt does it all for us */
84 //=================================================================================
87 //=================================================================================
88 void GenerationGUI_PrismDlg::Init()
91 myEditCurrentArgument = GroupPoints->LineEdit1;
94 myDx = myDy = myDz = 0.0;
95 myOkBase = myOkLine = false;
97 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
99 /* Get setting of step value from file configuration */
100 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
101 step = St.toDouble();
103 /* min, max, step and decimals for spin boxes & initial values */
104 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
105 GroupPoints->SpinBox_DX->SetValue(myHeight);
107 /* signals and slots connections */
108 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
111 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
118 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
119 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseVector(int)));
121 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
123 /* displays Dialog */
131 //=================================================================================
132 // function : ClickOnOk()
134 //=================================================================================
135 void GenerationGUI_PrismDlg::ClickOnOk()
137 this->ClickOnApply();
143 //=================================================================================
144 // function : ClickOnApply()
146 //=================================================================================
147 void GenerationGUI_PrismDlg::ClickOnApply()
149 QAD_Application::getDesktop()->putInfo(tr(""));
150 if (mySimulationTopoDs.IsNull())
152 myGeomBase->EraseSimulationShape();
153 mySimulationTopoDs.Nullify();
158 gp_Vec Vec(myDx, myDy, myDz);
161 P1.SetCoord(0.0, 0.0, 0.0);
162 P2.SetCoord(Vec.X(), Vec.Y(), Vec.Z());
164 if(myOkBase && myOkLine)
165 myGenerationGUI->MakePrismAndDisplay(myGeomShape, P1, P2);
167 catch(Standard_Failure) {
168 MESSAGE("Exception intercepted in GenerationGUI_PrismDlg" << endl);
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection has changed
179 //=================================================================================
180 void GenerationGUI_PrismDlg::SelectionIntoArgument()
182 myGeomBase->EraseSimulationShape();
183 mySimulationTopoDs.Nullify();
184 myEditCurrentArgument->setText("");
185 QString aString = ""; /* name of selection */
187 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
189 if(myEditCurrentArgument == GroupPoints->LineEdit1)
191 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
198 Standard_Boolean testResult;
199 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
200 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
203 gp_Pnt aPoint1, aPoint2;
205 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
206 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
209 if(S.ShapeType() <= 2)
211 myEditCurrentArgument->setText(aString);
215 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->LinearEdgeExtremities(S, aPoint1, aPoint2)) {
216 myGeomBase->GetBipointDxDyDz(aPoint1, aPoint2, myDx, myDy, myDz);
217 myEditCurrentArgument->setText(aString);
221 if(myOkBase && myOkLine)
222 this->MakePrismSimulationAndDisplay();
227 //=================================================================================
228 // function : SetEditCurrentArgument()
230 //=================================================================================
231 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
233 QPushButton* send = (QPushButton*)sender();
234 mySelection->ClearFilters();
236 if(send == GroupPoints->PushButton1) {
237 GroupPoints->LineEdit1->setFocus();
238 myEditCurrentArgument = GroupPoints->LineEdit1;
240 else if(send == GroupPoints->PushButton2) {
241 GroupPoints->LineEdit2->setFocus();
242 myEditCurrentArgument = GroupPoints->LineEdit2;
243 mySelection->AddFilter(myEdgeFilter);
245 this->SelectionIntoArgument();
251 //=================================================================================
252 // function : LineEditReturnPressed()
254 //=================================================================================
255 void GenerationGUI_PrismDlg::LineEditReturnPressed()
257 QLineEdit* send = (QLineEdit*)sender();
258 if(send == GroupPoints->LineEdit1)
259 myEditCurrentArgument = GroupPoints->LineEdit1;
260 else if (send == GroupPoints->LineEdit2)
261 myEditCurrentArgument = GroupPoints->LineEdit2;
265 GEOMBase_Skeleton::LineEditReturnPressed();
270 //=================================================================================
271 // function : enterEvent()
272 // purpose : when mouse enter onto the QWidget
273 //=================================================================================
274 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
276 if (GroupConstructors->isEnabled())
278 this->ActivateThisDialog();
283 //=================================================================================
284 // function : ActivateThisDialog()
286 //=================================================================================
287 void GenerationGUI_PrismDlg::ActivateThisDialog()
289 GEOMBase_Skeleton::ActivateThisDialog();
290 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
291 GroupPoints->LineEdit1->setFocus();
292 myEditCurrentArgument = GroupPoints->LineEdit1;
293 if(!mySimulationTopoDs.IsNull())
294 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
299 //=================================================================================
300 // function : ValueChangedInSpinBox()
302 //=================================================================================
303 void GenerationGUI_PrismDlg::ValueChangedInSpinBox(double newValue)
306 if(myOkBase && myOkLine)
307 this->MakePrismSimulationAndDisplay();
312 //=================================================================================
313 // function : ReverseVector()
314 // purpose : 'state' not used here
315 //=================================================================================
316 void GenerationGUI_PrismDlg::ReverseVector(int state)
321 if(myOkBase && myOkLine)
322 this->MakePrismSimulationAndDisplay();
327 //=================================================================================
328 // function : MakePrismSimulationAndDisplay()
330 //=================================================================================
331 void GenerationGUI_PrismDlg::MakePrismSimulationAndDisplay()
333 myGeomBase->EraseSimulationShape();
334 mySimulationTopoDs.Nullify();
337 gp_Vec Vec(myDx, myDy, myDz);
340 mySimulationTopoDs = BRepPrimAPI_MakePrism(myBaseTopo, Vec, Standard_False).Shape();
341 if(mySimulationTopoDs.IsNull())
344 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
346 catch(Standard_Failure) {
347 MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);