]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PrismDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PrismDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GenerationGUI_PrismDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GenerationGUI_PrismDlg.h"
31
32 #include <BRepPrimAPI_MakePrism.hxx>
33 #include "QAD_Config.h"
34
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)
44 {
45   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PRISM")));
46   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
47
48   setCaption(tr("GEOM_PRISM_TITLE"));
49
50   /***************************************************************/
51   GroupConstructors->setTitle(tr("GEOM_PRISM"));
52   RadioButton1->setPixmap(image0);
53   RadioButton2->close(TRUE);
54   RadioButton3->close(TRUE);
55
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);
64
65   Layout1->addWidget(GroupPoints, 1, 0);
66   /***************************************************************/
67
68   /* Initialisations */
69   myGenerationGUI = theGenerationGUI;
70   Init();
71 }
72
73
74 //=================================================================================
75 // function : ~GenerationGUI_PrismDlg()
76 // purpose  : Destroys the object and frees any allocated resources
77 //=================================================================================
78 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
79 {  
80   /* no need to delete child widgets, Qt does it all for us */
81 }
82
83
84 //=================================================================================
85 // function : Init()
86 // purpose  :
87 //=================================================================================
88 void GenerationGUI_PrismDlg::Init()
89 {
90   /* init variables */
91   myEditCurrentArgument = GroupPoints->LineEdit1;
92
93   myHeight = 100.000;
94   myDx = myDy = myDz = 0.0;
95   myOkBase = myOkLine = false;
96
97   myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
98
99   /* Get setting of step value from file configuration */
100   QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
101   step = St.toDouble();
102
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);
106
107   /* signals and slots connections */
108   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110
111   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113
114   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
116
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)));
120   
121   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
122
123   /* displays Dialog */
124   GroupPoints->show();
125   this->show();
126
127   return;
128 }
129
130
131 //=================================================================================
132 // function : ClickOnOk()
133 // purpose  :
134 //=================================================================================
135 void GenerationGUI_PrismDlg::ClickOnOk()
136 {
137   this->ClickOnApply();
138   ClickOnCancel();
139   return;
140 }
141
142
143 //=================================================================================
144 // function : ClickOnApply()
145 // purpose  :
146 //=================================================================================
147 void GenerationGUI_PrismDlg::ClickOnApply()
148 {
149   buttonApply->setFocus();
150   QAD_Application::getDesktop()->putInfo(tr(""));
151   if (mySimulationTopoDs.IsNull())
152     return;
153   myGeomBase->EraseSimulationShape();
154   mySimulationTopoDs.Nullify();
155
156   gp_Pnt P1, P2;
157
158   try {
159     gp_Vec Vec(myDx, myDy, myDz);
160     Vec.Normalize();
161     Vec *= myHeight;
162     P1.SetCoord(0.0, 0.0, 0.0);
163     P2.SetCoord(Vec.X(), Vec.Y(), Vec.Z());
164
165     if(myOkBase && myOkLine)
166       myGenerationGUI->MakePrismAndDisplay(myGeomShape, P1, P2);
167   }
168   catch(Standard_Failure) {
169     MESSAGE("Exception intercepted in GenerationGUI_PrismDlg" << endl);
170     return;
171   }
172
173   return;
174 }
175
176
177 //=================================================================================
178 // function : SelectionIntoArgument()
179 // purpose  : Called when selection has changed
180 //=================================================================================
181 void GenerationGUI_PrismDlg::SelectionIntoArgument()
182 {
183   myGeomBase->EraseSimulationShape();
184   mySimulationTopoDs.Nullify();
185   myEditCurrentArgument->setText("");
186   QString aString = ""; /* name of selection */
187   
188   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
189   if(nbSel != 1) {
190     if(myEditCurrentArgument == GroupPoints->LineEdit1)
191       myOkBase = false;
192     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
193       myOkLine = false;
194     return;
195   }
196   
197   // nbSel == 1
198   TopoDS_Shape S; 
199   Standard_Boolean testResult;
200   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
201   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
202     return;
203   
204   gp_Pnt aPoint1, aPoint2;
205   
206   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
207     myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
208     if(!testResult)
209       return;
210     if(S.ShapeType() <= 2)
211       return;
212     myEditCurrentArgument->setText(aString);
213     myOkBase = true;
214     myBaseTopo = S;
215   }
216   else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->LinearEdgeExtremities(S, aPoint1, aPoint2)) {
217     myGeomBase->GetBipointDxDyDz(aPoint1, aPoint2, myDx, myDy, myDz);
218     myEditCurrentArgument->setText(aString);
219     myOkLine = true;
220   }
221
222   if(myOkBase && myOkLine)
223     this->MakePrismSimulationAndDisplay();
224   return; 
225 }
226
227
228 //=================================================================================
229 // function : SetEditCurrentArgument()
230 // purpose  :
231 //=================================================================================
232 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
233 {
234   QPushButton* send = (QPushButton*)sender();
235   mySelection->ClearFilters();
236
237   if(send == GroupPoints->PushButton1) {
238     GroupPoints->LineEdit1->setFocus();
239     myEditCurrentArgument = GroupPoints->LineEdit1;
240   }
241   else if(send == GroupPoints->PushButton2) {
242     GroupPoints->LineEdit2->setFocus();
243     myEditCurrentArgument = GroupPoints->LineEdit2;
244     mySelection->AddFilter(myEdgeFilter);
245   }
246   this->SelectionIntoArgument();
247
248   return;
249 }
250
251
252 //=================================================================================
253 // function : LineEditReturnPressed()
254 // purpose  :
255 //=================================================================================
256 void GenerationGUI_PrismDlg::LineEditReturnPressed()
257 {
258   QLineEdit* send = (QLineEdit*)sender();
259   if(send == GroupPoints->LineEdit1)
260     myEditCurrentArgument = GroupPoints->LineEdit1;
261   else if (send == GroupPoints->LineEdit2)
262     myEditCurrentArgument = GroupPoints->LineEdit2;
263   else
264     return;
265
266   GEOMBase_Skeleton::LineEditReturnPressed();
267   return;
268 }
269
270
271 //=================================================================================
272 // function : enterEvent()
273 // purpose  : when mouse enter onto the QWidget
274 //=================================================================================
275 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
276 {
277   if (GroupConstructors->isEnabled())
278     return;
279   this->ActivateThisDialog();
280   return;
281 }
282
283
284 //=================================================================================
285 // function : ActivateThisDialog()
286 // purpose  :
287 //=================================================================================
288 void GenerationGUI_PrismDlg::ActivateThisDialog()
289 {
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);
296   return;
297 }
298
299
300 //=================================================================================
301 // function : ValueChangedInSpinBox()
302 // purpose  :
303 //=================================================================================
304 void GenerationGUI_PrismDlg::ValueChangedInSpinBox(double newValue)
305 {
306   myHeight = newValue;
307   if(myOkBase && myOkLine)
308     this->MakePrismSimulationAndDisplay();
309   return;
310 }
311
312
313 //=================================================================================
314 // function : ReverseVector()
315 // purpose  : 'state' not used here
316 //=================================================================================
317 void GenerationGUI_PrismDlg::ReverseVector(int state)
318 {
319   myDx = -myDx;
320   myDy = -myDy;
321   myDz = -myDz;
322   if(myOkBase && myOkLine)
323     this->MakePrismSimulationAndDisplay();
324   return;
325
326
327
328 //=================================================================================
329 // function : MakePrismSimulationAndDisplay()
330 // purpose  :
331 //=================================================================================
332 void GenerationGUI_PrismDlg::MakePrismSimulationAndDisplay()
333 {
334   myGeomBase->EraseSimulationShape();
335   mySimulationTopoDs.Nullify();
336
337   try {
338     gp_Vec Vec(myDx, myDy, myDz);
339     Vec.Normalize();
340     Vec *= myHeight;
341     mySimulationTopoDs = BRepPrimAPI_MakePrism(myBaseTopo, Vec, Standard_False).Shape();
342     if(mySimulationTopoDs.IsNull())
343       return;
344     else
345       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
346   }
347   catch(Standard_Failure) {
348     MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);
349     return;
350   }
351   return;
352 }