]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MirrorDlg.cxx
Salome HOME
6a968659cb170893f1a5b78c73a5ee44136b38f3
[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   QAD_Application::getDesktop()->putInfo(tr(""));
135   if (mySimulationTopoDs.IsNull())
136     return;
137   myGeomBase->EraseSimulationShape();
138   mySimulationTopoDs.Nullify();
139
140   if(myOkShape1 && myOkShape2)
141     myTransformationGUI->MakeMirrorAndDisplay(myGeomShape1, myGeomShape2);
142   return;
143 }
144
145
146 //=================================================================================
147 // function : SelectionIntoArgument()
148 // purpose  : Called when selection has changed
149 //=================================================================================
150 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
151 {
152   myGeomBase->EraseSimulationShape();
153   mySimulationTopoDs.Nullify();
154   myEditCurrentArgument->setText("");
155   QString aString = ""; /* name of selection */
156
157   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
158   if(nbSel != 1) {
159     if(myEditCurrentArgument == GroupPoints->LineEdit1)
160       myOkShape1 = false;
161     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
162       myOkShape2 = false;
163     return;
164   }
165
166   // nbSel == 1
167   TopoDS_Shape S;
168   Standard_Boolean testResult;
169   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
170   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
171     return;
172   
173   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
174     myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
175     if(!testResult)
176       return;
177     myShape1 = S;
178     myEditCurrentArgument->setText(aString);
179     myOkShape1 = true;
180   }
181   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
182     myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
183     if(!testResult)
184       return ;
185     myShape2 = S;
186     myEditCurrentArgument->setText(aString);
187     myOkShape2 = true;
188   }
189
190   if(myOkShape1 && myOkShape2)
191     MakeMirrorSimulationAndDisplay();
192   return; 
193 }
194
195
196 //=================================================================================
197 // function : SetEditCurrentArgument()
198 // purpose  :
199 //=================================================================================
200 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
201 {
202   QPushButton* send = (QPushButton*)sender();
203   mySelection->ClearFilters();
204
205   if(send == GroupPoints->PushButton1) {
206     GroupPoints->LineEdit1->setFocus();
207     myEditCurrentArgument = GroupPoints->LineEdit1;
208   }
209   else if(send == GroupPoints->PushButton2) {
210     GroupPoints->LineEdit2->setFocus();
211     myEditCurrentArgument = GroupPoints->LineEdit2;
212     mySelection->AddFilter(myFaceFilter);
213   }
214   this->SelectionIntoArgument();
215
216   return;
217 }
218
219
220 //=================================================================================
221 // function : LineEditReturnPressed()
222 // purpose  :
223 //=================================================================================
224 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
225 {
226   QLineEdit* send = (QLineEdit*)sender();
227   if(send == GroupPoints->LineEdit1)
228     myEditCurrentArgument = GroupPoints->LineEdit1;
229   else if(send == GroupPoints->LineEdit2)
230     myEditCurrentArgument = GroupPoints->LineEdit2;
231   else
232     return;
233
234   GEOMBase_Skeleton::LineEditReturnPressed();
235   return;
236 }
237
238
239 //=================================================================================
240 // function : enterEvent()
241 // purpose  : when mouse enter onto the QWidget
242 //=================================================================================
243 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
244 {
245   if(GroupConstructors->isEnabled())
246     return;
247   this->ActivateThisDialog();
248   return;
249 }
250
251
252 //=================================================================================
253 // function : ActivateThisDialog()
254 // purpose  :
255 //=================================================================================
256 void TransformationGUI_MirrorDlg::ActivateThisDialog()
257 {
258   GEOMBase_Skeleton::ActivateThisDialog();
259   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260   GroupPoints->LineEdit1->setFocus();
261   myEditCurrentArgument = GroupPoints->LineEdit1;
262   if(!mySimulationTopoDs.IsNull())
263     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
264   return;
265 }
266
267
268 //=================================================================================
269 // function : MakeMirrorSimulationAndDisplay()
270 // purpose  : S1 is a shape and S2 a mirror.
271 //=================================================================================
272 void TransformationGUI_MirrorDlg::MakeMirrorSimulationAndDisplay()
273 {
274   myGeomBase->EraseSimulationShape();
275   mySimulationTopoDs.Nullify();
276   
277   try {
278     Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(myShape2));
279     Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
280     const gp_Ax3 pos = myPlane->Position();
281     const gp_Pnt loc = pos.Location();  /* location of the plane */
282     const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
283     
284     /* plane used for mirroring */
285     gp_Ax2 pln(loc, dir);
286     gp_Trsf theTransformation;
287     theTransformation.SetMirror(pln);
288     BRepBuilderAPI_Transform myBRepTransformation(myShape1, theTransformation, Standard_False);
289     
290     this->mySimulationTopoDs = myBRepTransformation.Shape();
291     if(mySimulationTopoDs.IsNull())
292       return;
293     else
294       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
295   }
296   catch(Standard_Failure) {
297     MESSAGE("Exception catched in MakeMirrorSimulationAndDisplay");
298     return;
299   }
300   return;
301 }