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 buttonApply->setFocus();
150 QAD_Application::getDesktop()->putInfo(tr(""));
151 if (mySimulationTopoDs.IsNull())
153 myGeomBase->EraseSimulationShape();
154 mySimulationTopoDs.Nullify();
159 gp_Vec Vec(myDx, myDy, myDz);
162 P1.SetCoord(0.0, 0.0, 0.0);
163 P2.SetCoord(Vec.X(), Vec.Y(), Vec.Z());
165 if(myOkBase && myOkLine)
166 myGenerationGUI->MakePrismAndDisplay(myGeomShape, P1, P2);
168 catch(Standard_Failure) {
169 MESSAGE("Exception intercepted in GenerationGUI_PrismDlg" << endl);
177 //=================================================================================
178 // function : SelectionIntoArgument()
179 // purpose : Called when selection has changed
180 //=================================================================================
181 void GenerationGUI_PrismDlg::SelectionIntoArgument()
183 myGeomBase->EraseSimulationShape();
184 mySimulationTopoDs.Nullify();
185 myEditCurrentArgument->setText("");
186 QString aString = ""; /* name of selection */
188 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
190 if(myEditCurrentArgument == GroupPoints->LineEdit1)
192 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
199 Standard_Boolean testResult;
200 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
201 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
204 gp_Pnt aPoint1, aPoint2;
206 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
207 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
210 if(S.ShapeType() <= 2)
212 myEditCurrentArgument->setText(aString);
216 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->LinearEdgeExtremities(S, aPoint1, aPoint2)) {
217 myGeomBase->GetBipointDxDyDz(aPoint1, aPoint2, myDx, myDy, myDz);
218 myEditCurrentArgument->setText(aString);
222 if(myOkBase && myOkLine)
223 this->MakePrismSimulationAndDisplay();
228 //=================================================================================
229 // function : SetEditCurrentArgument()
231 //=================================================================================
232 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
234 QPushButton* send = (QPushButton*)sender();
235 mySelection->ClearFilters();
237 if(send == GroupPoints->PushButton1) {
238 GroupPoints->LineEdit1->setFocus();
239 myEditCurrentArgument = GroupPoints->LineEdit1;
241 else if(send == GroupPoints->PushButton2) {
242 GroupPoints->LineEdit2->setFocus();
243 myEditCurrentArgument = GroupPoints->LineEdit2;
244 mySelection->AddFilter(myEdgeFilter);
246 this->SelectionIntoArgument();
252 //=================================================================================
253 // function : LineEditReturnPressed()
255 //=================================================================================
256 void GenerationGUI_PrismDlg::LineEditReturnPressed()
258 QLineEdit* send = (QLineEdit*)sender();
259 if(send == GroupPoints->LineEdit1)
260 myEditCurrentArgument = GroupPoints->LineEdit1;
261 else if (send == GroupPoints->LineEdit2)
262 myEditCurrentArgument = GroupPoints->LineEdit2;
266 GEOMBase_Skeleton::LineEditReturnPressed();
271 //=================================================================================
272 // function : enterEvent()
273 // purpose : when mouse enter onto the QWidget
274 //=================================================================================
275 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
277 if (GroupConstructors->isEnabled())
279 this->ActivateThisDialog();
284 //=================================================================================
285 // function : ActivateThisDialog()
287 //=================================================================================
288 void GenerationGUI_PrismDlg::ActivateThisDialog()
290 GEOMBase_Skeleton::ActivateThisDialog();
291 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
292 GroupPoints->LineEdit1->setFocus();
293 myEditCurrentArgument = GroupPoints->LineEdit1;
294 if(!mySimulationTopoDs.IsNull())
295 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
300 //=================================================================================
301 // function : ValueChangedInSpinBox()
303 //=================================================================================
304 void GenerationGUI_PrismDlg::ValueChangedInSpinBox(double newValue)
307 if(myOkBase && myOkLine)
308 this->MakePrismSimulationAndDisplay();
313 //=================================================================================
314 // function : ReverseVector()
315 // purpose : 'state' not used here
316 //=================================================================================
317 void GenerationGUI_PrismDlg::ReverseVector(int state)
322 if(myOkBase && myOkLine)
323 this->MakePrismSimulationAndDisplay();
328 //=================================================================================
329 // function : MakePrismSimulationAndDisplay()
331 //=================================================================================
332 void GenerationGUI_PrismDlg::MakePrismSimulationAndDisplay()
334 myGeomBase->EraseSimulationShape();
335 mySimulationTopoDs.Nullify();
338 gp_Vec Vec(myDx, myDy, myDz);
341 mySimulationTopoDs = BRepPrimAPI_MakePrism(myBaseTopo, Vec, Standard_False).Shape();
342 if(mySimulationTopoDs.IsNull())
345 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
347 catch(Standard_Failure) {
348 MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);