1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TransformationGUI_MirrorDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_MirrorDlg.h"
31 #include <BRepBuilderAPI_Transform.hxx>
32 #include <Geom_Plane.hxx>
33 #include <BRep_Tool.hxx>
35 #include "utilities.h"
39 //=================================================================================
40 // class : TransformationGUI_MirrorDlg()
41 // purpose : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
47 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
52 setCaption(tr("GEOM_MIRROR_TITLE"));
54 /***************************************************************/
55 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
56 RadioButton1->setPixmap(image0);
57 RadioButton2->close(TRUE);
58 RadioButton3->close(TRUE);
60 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
61 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
62 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
63 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
64 GroupPoints->PushButton1->setPixmap(image1);
65 GroupPoints->PushButton2->setPixmap(image1);
67 Layout1->addWidget(GroupPoints, 1, 0);
68 /***************************************************************/
71 myTransformationGUI = theTransformationGUI;
76 //=================================================================================
77 // function : ~TransformationGUI_MirrorDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
82 /* no need to delete child widgets, Qt does it all for us */
86 //=================================================================================
89 //=================================================================================
90 void TransformationGUI_MirrorDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
95 myOkShape1 = myOkShape2 = false;
97 /* Vertices Filter for all arguments */
98 myFaceFilter = new GEOM_FaceFilter(StdSelect_Plane, myGeom);
100 /* signals and slots connections */
101 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
102 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
104 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
105 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
107 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
108 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
112 /* displays Dialog */
120 //=================================================================================
121 // function : ClickOnOk()
123 //=================================================================================
124 void TransformationGUI_MirrorDlg::ClickOnOk()
126 this->ClickOnApply();
131 //=================================================================================
132 // function : ClickOnApply()
134 //=================================================================================
135 void TransformationGUI_MirrorDlg::ClickOnApply()
137 buttonApply->setFocus();
138 QAD_Application::getDesktop()->putInfo(tr(""));
139 if (mySimulationTopoDs.IsNull())
141 myGeomBase->EraseSimulationShape();
142 mySimulationTopoDs.Nullify();
144 if(myOkShape1 && myOkShape2)
145 myTransformationGUI->MakeMirrorAndDisplay(myGeomShape1, myGeomShape2);
150 //=================================================================================
151 // function : SelectionIntoArgument()
152 // purpose : Called when selection has changed
153 //=================================================================================
154 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
156 myGeomBase->EraseSimulationShape();
157 mySimulationTopoDs.Nullify();
158 myEditCurrentArgument->setText("");
159 QString aString = ""; /* name of selection */
161 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
163 if(myEditCurrentArgument == GroupPoints->LineEdit1)
165 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
172 Standard_Boolean testResult;
173 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
174 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
177 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
178 myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
182 myEditCurrentArgument->setText(aString);
185 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
186 myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
190 myEditCurrentArgument->setText(aString);
194 if(myOkShape1 && myOkShape2)
195 MakeMirrorSimulationAndDisplay();
200 //=================================================================================
201 // function : SetEditCurrentArgument()
203 //=================================================================================
204 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
206 QPushButton* send = (QPushButton*)sender();
207 mySelection->ClearFilters();
209 if(send == GroupPoints->PushButton1) {
210 GroupPoints->LineEdit1->setFocus();
211 myEditCurrentArgument = GroupPoints->LineEdit1;
213 else if(send == GroupPoints->PushButton2) {
214 GroupPoints->LineEdit2->setFocus();
215 myEditCurrentArgument = GroupPoints->LineEdit2;
216 mySelection->AddFilter(myFaceFilter);
218 this->SelectionIntoArgument();
224 //=================================================================================
225 // function : LineEditReturnPressed()
227 //=================================================================================
228 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
230 QLineEdit* send = (QLineEdit*)sender();
231 if(send == GroupPoints->LineEdit1)
232 myEditCurrentArgument = GroupPoints->LineEdit1;
233 else if(send == GroupPoints->LineEdit2)
234 myEditCurrentArgument = GroupPoints->LineEdit2;
238 GEOMBase_Skeleton::LineEditReturnPressed();
243 //=================================================================================
244 // function : enterEvent()
245 // purpose : when mouse enter onto the QWidget
246 //=================================================================================
247 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
249 if(GroupConstructors->isEnabled())
251 this->ActivateThisDialog();
256 //=================================================================================
257 // function : ActivateThisDialog()
259 //=================================================================================
260 void TransformationGUI_MirrorDlg::ActivateThisDialog()
262 GEOMBase_Skeleton::ActivateThisDialog();
263 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
264 GroupPoints->LineEdit1->setFocus();
265 myEditCurrentArgument = GroupPoints->LineEdit1;
266 if(!mySimulationTopoDs.IsNull())
267 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
272 //=================================================================================
273 // function : MakeMirrorSimulationAndDisplay()
274 // purpose : S1 is a shape and S2 a mirror.
275 //=================================================================================
276 void TransformationGUI_MirrorDlg::MakeMirrorSimulationAndDisplay()
278 myGeomBase->EraseSimulationShape();
279 mySimulationTopoDs.Nullify();
282 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(myShape2));
283 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
284 const gp_Ax3 pos = myPlane->Position();
285 const gp_Pnt loc = pos.Location(); /* location of the plane */
286 const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
288 /* plane used for mirroring */
289 gp_Ax2 pln(loc, dir);
290 gp_Trsf theTransformation;
291 theTransformation.SetMirror(pln);
292 BRepBuilderAPI_Transform myBRepTransformation(myShape1, theTransformation, Standard_False);
294 this->mySimulationTopoDs = myBRepTransformation.Shape();
295 if(mySimulationTopoDs.IsNull())
298 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
300 catch(Standard_Failure) {
301 MESSAGE("Exception catched in MakeMirrorSimulationAndDisplay");