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
29 #include "GenerationGUI_PrismDlg.h"
31 #include <BRepPrimAPI_MakePrism.hxx>
32 #include "QAD_Config.h"
34 #include "utilities.h"
38 //=================================================================================
39 // class : GenerationGUI_PrismDlg()
40 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
46 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PRISM")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_PRISM_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_PRISM"));
55 RadioButton1->setPixmap(image0);
56 RadioButton2->close(TRUE);
57 RadioButton3->close(TRUE);
59 GroupPoints = new DlgRef_2Sel1Spin1Check(this, "GroupPoints");
60 GroupPoints->GroupBox1->setTitle(tr("GEOM_PRISM_BSV"));
61 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
62 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
63 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
64 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE"));
65 GroupPoints->PushButton1->setPixmap(image1);
66 GroupPoints->PushButton2->setPixmap(image1);
68 Layout1->addWidget(GroupPoints, 1, 0);
69 /***************************************************************/
72 myGenerationGUI = theGenerationGUI;
77 //=================================================================================
78 // function : ~GenerationGUI_PrismDlg()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
83 /* no need to delete child widgets, Qt does it all for us */
87 //=================================================================================
90 //=================================================================================
91 void GenerationGUI_PrismDlg::Init()
94 myEditCurrentArgument = GroupPoints->LineEdit1;
97 myDx = myDy = myDz = 0.0;
98 myOkBase = myOkLine = false;
100 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
102 /* Get setting of step value from file configuration */
103 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
104 step = St.toDouble();
106 /* min, max, step and decimals for spin boxes & initial values */
107 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
108 GroupPoints->SpinBox_DX->SetValue(myHeight);
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)));
122 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseVector(int)));
124 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
126 /* displays Dialog */
134 //=================================================================================
135 // function : ClickOnOk()
137 //=================================================================================
138 void GenerationGUI_PrismDlg::ClickOnOk()
140 this->ClickOnApply();
146 //=================================================================================
147 // function : ClickOnApply()
149 //=================================================================================
150 void GenerationGUI_PrismDlg::ClickOnApply()
152 buttonApply->setFocus();
153 QAD_Application::getDesktop()->putInfo(tr(""));
154 if (mySimulationTopoDs.IsNull())
156 myGeomBase->EraseSimulationShape();
157 mySimulationTopoDs.Nullify();
162 gp_Vec Vec(myDx, myDy, myDz);
165 P1.SetCoord(0.0, 0.0, 0.0);
166 P2.SetCoord(Vec.X(), Vec.Y(), Vec.Z());
168 if(myOkBase && myOkLine)
169 myGenerationGUI->MakePrismAndDisplay(myGeomShape, P1, P2);
171 catch(Standard_Failure) {
172 MESSAGE("Exception intercepted in GenerationGUI_PrismDlg" << endl);
180 //=================================================================================
181 // function : SelectionIntoArgument()
182 // purpose : Called when selection has changed
183 //=================================================================================
184 void GenerationGUI_PrismDlg::SelectionIntoArgument()
186 myGeomBase->EraseSimulationShape();
187 mySimulationTopoDs.Nullify();
188 myEditCurrentArgument->setText("");
189 QString aString = ""; /* name of selection */
191 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
193 if(myEditCurrentArgument == GroupPoints->LineEdit1)
195 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
202 Standard_Boolean testResult;
203 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
204 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
207 gp_Pnt aPoint1, aPoint2;
209 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
210 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
213 if(S.ShapeType() <= 2)
215 myEditCurrentArgument->setText(aString);
219 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->LinearEdgeExtremities(S, aPoint1, aPoint2)) {
220 myGeomBase->GetBipointDxDyDz(aPoint1, aPoint2, myDx, myDy, myDz);
221 myEditCurrentArgument->setText(aString);
225 if(myOkBase && myOkLine)
226 this->MakePrismSimulationAndDisplay();
231 //=================================================================================
232 // function : SetEditCurrentArgument()
234 //=================================================================================
235 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
237 QPushButton* send = (QPushButton*)sender();
238 mySelection->ClearFilters();
240 if(send == GroupPoints->PushButton1) {
241 GroupPoints->LineEdit1->setFocus();
242 myEditCurrentArgument = GroupPoints->LineEdit1;
244 else if(send == GroupPoints->PushButton2) {
245 GroupPoints->LineEdit2->setFocus();
246 myEditCurrentArgument = GroupPoints->LineEdit2;
247 mySelection->AddFilter(myEdgeFilter);
249 this->SelectionIntoArgument();
255 //=================================================================================
256 // function : LineEditReturnPressed()
258 //=================================================================================
259 void GenerationGUI_PrismDlg::LineEditReturnPressed()
261 QLineEdit* send = (QLineEdit*)sender();
262 if(send == GroupPoints->LineEdit1)
263 myEditCurrentArgument = GroupPoints->LineEdit1;
264 else if (send == GroupPoints->LineEdit2)
265 myEditCurrentArgument = GroupPoints->LineEdit2;
269 GEOMBase_Skeleton::LineEditReturnPressed();
274 //=================================================================================
275 // function : enterEvent()
276 // purpose : when mouse enter onto the QWidget
277 //=================================================================================
278 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
280 if (GroupConstructors->isEnabled())
282 this->ActivateThisDialog();
287 //=================================================================================
288 // function : ActivateThisDialog()
290 //=================================================================================
291 void GenerationGUI_PrismDlg::ActivateThisDialog()
293 GEOMBase_Skeleton::ActivateThisDialog();
294 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
295 GroupPoints->LineEdit1->setFocus();
296 myEditCurrentArgument = GroupPoints->LineEdit1;
297 if(!mySimulationTopoDs.IsNull())
298 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
303 //=================================================================================
304 // function : ValueChangedInSpinBox()
306 //=================================================================================
307 void GenerationGUI_PrismDlg::ValueChangedInSpinBox(double newValue)
310 if(myOkBase && myOkLine)
311 this->MakePrismSimulationAndDisplay();
316 //=================================================================================
317 // function : ReverseVector()
318 // purpose : 'state' not used here
319 //=================================================================================
320 void GenerationGUI_PrismDlg::ReverseVector(int state)
325 if(myOkBase && myOkLine)
326 this->MakePrismSimulationAndDisplay();
331 //=================================================================================
332 // function : MakePrismSimulationAndDisplay()
334 //=================================================================================
335 void GenerationGUI_PrismDlg::MakePrismSimulationAndDisplay()
337 myGeomBase->EraseSimulationShape();
338 mySimulationTopoDs.Nullify();
341 gp_Vec Vec(myDx, myDy, myDz);
344 mySimulationTopoDs = BRepPrimAPI_MakePrism(myBaseTopo, Vec, Standard_False).Shape();
345 if(mySimulationTopoDs.IsNull())
348 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
350 catch(Standard_Failure) {
351 MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);