]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PrismDlg.cxx
Salome HOME
f2b9ea58ff2e7c910447e6882bff91dbae183d7c
[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   QAD_Application::getDesktop()->putInfo(tr(""));
150   if (mySimulationTopoDs.IsNull())
151     return;
152   myGeomBase->EraseSimulationShape();
153   mySimulationTopoDs.Nullify();
154
155   gp_Pnt P1, P2;
156
157   try {
158     gp_Vec Vec(myDx, myDy, myDz);
159     Vec.Normalize();
160     Vec *= myHeight;
161     P1.SetCoord(0.0, 0.0, 0.0);
162     P2.SetCoord(Vec.X(), Vec.Y(), Vec.Z());
163
164     if(myOkBase && myOkLine)
165       myGenerationGUI->MakePrismAndDisplay(myGeomShape, P1, P2);
166   }
167   catch(Standard_Failure) {
168     MESSAGE("Exception intercepted in GenerationGUI_PrismDlg" << endl);
169     return;
170   }
171
172   return;
173 }
174
175
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose  : Called when selection has changed
179 //=================================================================================
180 void GenerationGUI_PrismDlg::SelectionIntoArgument()
181 {
182   myGeomBase->EraseSimulationShape();
183   mySimulationTopoDs.Nullify();
184   myEditCurrentArgument->setText("");
185   QString aString = ""; /* name of selection */
186   
187   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
188   if(nbSel != 1) {
189     if(myEditCurrentArgument == GroupPoints->LineEdit1)
190       myOkBase = false;
191     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
192       myOkLine = false;
193     return;
194   }
195   
196   // nbSel == 1
197   TopoDS_Shape S; 
198   Standard_Boolean testResult;
199   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
200   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
201     return;
202   
203   gp_Pnt aPoint1, aPoint2;
204   
205   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
206     myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
207     if(!testResult)
208       return;
209     if(S.ShapeType() <= 2)
210       return;
211     myEditCurrentArgument->setText(aString);
212     myOkBase = true;
213     myBaseTopo = S;
214   }
215   else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->LinearEdgeExtremities(S, aPoint1, aPoint2)) {
216     myGeomBase->GetBipointDxDyDz(aPoint1, aPoint2, myDx, myDy, myDz);
217     myEditCurrentArgument->setText(aString);
218     myOkLine = true;
219   }
220
221   if(myOkBase && myOkLine)
222     this->MakePrismSimulationAndDisplay();
223   return; 
224 }
225
226
227 //=================================================================================
228 // function : SetEditCurrentArgument()
229 // purpose  :
230 //=================================================================================
231 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
232 {
233   QPushButton* send = (QPushButton*)sender();
234   mySelection->ClearFilters();
235
236   if(send == GroupPoints->PushButton1) {
237     GroupPoints->LineEdit1->setFocus();
238     myEditCurrentArgument = GroupPoints->LineEdit1;
239   }
240   else if(send == GroupPoints->PushButton2) {
241     GroupPoints->LineEdit2->setFocus();
242     myEditCurrentArgument = GroupPoints->LineEdit2;
243     mySelection->AddFilter(myEdgeFilter);
244   }
245   this->SelectionIntoArgument();
246
247   return;
248 }
249
250
251 //=================================================================================
252 // function : LineEditReturnPressed()
253 // purpose  :
254 //=================================================================================
255 void GenerationGUI_PrismDlg::LineEditReturnPressed()
256 {
257   QLineEdit* send = (QLineEdit*)sender();
258   if(send == GroupPoints->LineEdit1)
259     myEditCurrentArgument = GroupPoints->LineEdit1;
260   else if (send == GroupPoints->LineEdit2)
261     myEditCurrentArgument = GroupPoints->LineEdit2;
262   else
263     return;
264
265   GEOMBase_Skeleton::LineEditReturnPressed();
266   return;
267 }
268
269
270 //=================================================================================
271 // function : enterEvent()
272 // purpose  : when mouse enter onto the QWidget
273 //=================================================================================
274 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
275 {
276   if (GroupConstructors->isEnabled())
277     return;
278   this->ActivateThisDialog();
279   return;
280 }
281
282
283 //=================================================================================
284 // function : ActivateThisDialog()
285 // purpose  :
286 //=================================================================================
287 void GenerationGUI_PrismDlg::ActivateThisDialog()
288 {
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);
295   return;
296 }
297
298
299 //=================================================================================
300 // function : ValueChangedInSpinBox()
301 // purpose  :
302 //=================================================================================
303 void GenerationGUI_PrismDlg::ValueChangedInSpinBox(double newValue)
304 {
305   myHeight = newValue;
306   if(myOkBase && myOkLine)
307     this->MakePrismSimulationAndDisplay();
308   return;
309 }
310
311
312 //=================================================================================
313 // function : ReverseVector()
314 // purpose  : 'state' not used here
315 //=================================================================================
316 void GenerationGUI_PrismDlg::ReverseVector(int state)
317 {
318   myDx = -myDx;
319   myDy = -myDy;
320   myDz = -myDz;
321   if(myOkBase && myOkLine)
322     this->MakePrismSimulationAndDisplay();
323   return;
324
325
326
327 //=================================================================================
328 // function : MakePrismSimulationAndDisplay()
329 // purpose  :
330 //=================================================================================
331 void GenerationGUI_PrismDlg::MakePrismSimulationAndDisplay()
332 {
333   myGeomBase->EraseSimulationShape();
334   mySimulationTopoDs.Nullify();
335
336   try {
337     gp_Vec Vec(myDx, myDy, myDz);
338     Vec.Normalize();
339     Vec *= myHeight;
340     mySimulationTopoDs = BRepPrimAPI_MakePrism(myBaseTopo, Vec, Standard_False).Shape();
341     if(mySimulationTopoDs.IsNull())
342       return;
343     else
344       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
345   }
346   catch(Standard_Failure) {
347     MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);
348     return;
349   }
350   return;
351 }