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