]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MirrorDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[modules/geom.git] / src / TransformationGUI / TransformationGUI_MirrorDlg.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   : TransformationGUI_MirrorDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "TransformationGUI_MirrorDlg.h"
31
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include <Geom_Plane.hxx>
34 #include <BRep_Tool.hxx>
35
36 //=================================================================================
37 // class    : TransformationGUI_MirrorDlg()
38 // purpose  : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the 
39 //            name 'name' and widget flags set to 'f'.
40 //            The dialog will by default be modeless, unless you set 'modal' to
41 //            TRUE to construct a modal dialog.
42 //=================================================================================
43 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg(QWidget* parent,  const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
44     :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 {
46   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR")));
47   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48
49   setCaption(tr("GEOM_MIRROR_TITLE"));
50
51   /***************************************************************/
52   GroupConstructors->setTitle(tr("GEOM_MIRROR"));
53   RadioButton1->setPixmap(image0);
54   RadioButton2->close(TRUE);
55   RadioButton3->close(TRUE);
56
57   GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
58   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
59   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
60   GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
61   GroupPoints->PushButton1->setPixmap(image1);
62   GroupPoints->PushButton2->setPixmap(image1);
63
64   Layout1->addWidget(GroupPoints, 1, 0);
65   /***************************************************************/
66
67   /* Initialisations */
68   myTransformationGUI = theTransformationGUI;
69   Init();
70 }
71
72
73 //=================================================================================
74 // function : ~TransformationGUI_MirrorDlg()
75 // purpose  : Destroys the object and frees any allocated resources
76 //=================================================================================
77 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
78 {  
79   /* no need to delete child widgets, Qt does it all for us */
80 }
81
82
83 //=================================================================================
84 // function : Init()
85 // purpose  :
86 //=================================================================================
87 void TransformationGUI_MirrorDlg::Init()
88 {  
89   /* init variables */
90   myEditCurrentArgument = GroupPoints->LineEdit1;
91
92   myOkShape1 = myOkShape2 = false;
93
94   /*  Vertices Filter for all arguments */
95   myFaceFilter = new GEOM_FaceFilter(StdSelect_Plane, myGeom);
96
97   /* signals and slots connections */
98   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
99   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
100
101   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
102   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
103
104   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
105   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
106
107   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
108
109   /* displays Dialog */
110   GroupPoints->show();
111   this->show();
112
113   return;
114 }
115
116
117 //=================================================================================
118 // function : ClickOnOk()
119 // purpose  :
120 //=================================================================================
121 void TransformationGUI_MirrorDlg::ClickOnOk()
122 {
123   this->ClickOnApply();
124   ClickOnCancel();
125   return;
126 }
127
128 //=================================================================================
129 // function : ClickOnApply()
130 // purpose  :
131 //=================================================================================
132 void TransformationGUI_MirrorDlg::ClickOnApply()
133 {
134   buttonApply->setFocus();
135   QAD_Application::getDesktop()->putInfo(tr(""));
136   if (mySimulationTopoDs.IsNull())
137     return;
138   myGeomBase->EraseSimulationShape();
139   mySimulationTopoDs.Nullify();
140
141   if(myOkShape1 && myOkShape2)
142     myTransformationGUI->MakeMirrorAndDisplay(myGeomShape1, myGeomShape2);
143   return;
144 }
145
146
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose  : Called when selection has changed
150 //=================================================================================
151 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
152 {
153   myGeomBase->EraseSimulationShape();
154   mySimulationTopoDs.Nullify();
155   myEditCurrentArgument->setText("");
156   QString aString = ""; /* name of selection */
157
158   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
159   if(nbSel != 1) {
160     if(myEditCurrentArgument == GroupPoints->LineEdit1)
161       myOkShape1 = false;
162     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
163       myOkShape2 = false;
164     return;
165   }
166
167   // nbSel == 1
168   TopoDS_Shape S;
169   Standard_Boolean testResult;
170   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
171   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
172     return;
173   
174   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
175     myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
176     if(!testResult)
177       return;
178     myShape1 = S;
179     myEditCurrentArgument->setText(aString);
180     myOkShape1 = true;
181   }
182   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
183     myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
184     if(!testResult)
185       return ;
186     myShape2 = S;
187     myEditCurrentArgument->setText(aString);
188     myOkShape2 = true;
189   }
190
191   if(myOkShape1 && myOkShape2)
192     MakeMirrorSimulationAndDisplay();
193   return; 
194 }
195
196
197 //=================================================================================
198 // function : SetEditCurrentArgument()
199 // purpose  :
200 //=================================================================================
201 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
202 {
203   QPushButton* send = (QPushButton*)sender();
204   mySelection->ClearFilters();
205
206   if(send == GroupPoints->PushButton1) {
207     GroupPoints->LineEdit1->setFocus();
208     myEditCurrentArgument = GroupPoints->LineEdit1;
209   }
210   else if(send == GroupPoints->PushButton2) {
211     GroupPoints->LineEdit2->setFocus();
212     myEditCurrentArgument = GroupPoints->LineEdit2;
213     mySelection->AddFilter(myFaceFilter);
214   }
215   this->SelectionIntoArgument();
216
217   return;
218 }
219
220
221 //=================================================================================
222 // function : LineEditReturnPressed()
223 // purpose  :
224 //=================================================================================
225 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
226 {
227   QLineEdit* send = (QLineEdit*)sender();
228   if(send == GroupPoints->LineEdit1)
229     myEditCurrentArgument = GroupPoints->LineEdit1;
230   else if(send == GroupPoints->LineEdit2)
231     myEditCurrentArgument = GroupPoints->LineEdit2;
232   else
233     return;
234
235   GEOMBase_Skeleton::LineEditReturnPressed();
236   return;
237 }
238
239
240 //=================================================================================
241 // function : enterEvent()
242 // purpose  : when mouse enter onto the QWidget
243 //=================================================================================
244 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
245 {
246   if(GroupConstructors->isEnabled())
247     return;
248   this->ActivateThisDialog();
249   return;
250 }
251
252
253 //=================================================================================
254 // function : ActivateThisDialog()
255 // purpose  :
256 //=================================================================================
257 void TransformationGUI_MirrorDlg::ActivateThisDialog()
258 {
259   GEOMBase_Skeleton::ActivateThisDialog();
260   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261   GroupPoints->LineEdit1->setFocus();
262   myEditCurrentArgument = GroupPoints->LineEdit1;
263   if(!mySimulationTopoDs.IsNull())
264     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
265   return;
266 }
267
268
269 //=================================================================================
270 // function : MakeMirrorSimulationAndDisplay()
271 // purpose  : S1 is a shape and S2 a mirror.
272 //=================================================================================
273 void TransformationGUI_MirrorDlg::MakeMirrorSimulationAndDisplay()
274 {
275   myGeomBase->EraseSimulationShape();
276   mySimulationTopoDs.Nullify();
277   
278   try {
279     Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(myShape2));
280     Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
281     const gp_Ax3 pos = myPlane->Position();
282     const gp_Pnt loc = pos.Location();  /* location of the plane */
283     const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
284     
285     /* plane used for mirroring */
286     gp_Ax2 pln(loc, dir);
287     gp_Trsf theTransformation;
288     theTransformation.SetMirror(pln);
289     BRepBuilderAPI_Transform myBRepTransformation(myShape1, theTransformation, Standard_False);
290     
291     this->mySimulationTopoDs = myBRepTransformation.Shape();
292     if(mySimulationTopoDs.IsNull())
293       return;
294     else
295       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
296   }
297   catch(Standard_Failure) {
298     MESSAGE("Exception catched in MakeMirrorSimulationAndDisplay");
299     return;
300   }
301   return;
302 }