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
30 #include "TransformationGUI_MirrorDlg.h"
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include <Geom_Plane.hxx>
34 #include <BRep_Tool.hxx>
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)
46 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49 setCaption(tr("GEOM_MIRROR_TITLE"));
51 /***************************************************************/
52 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
53 RadioButton1->setPixmap(image0);
54 RadioButton2->close(TRUE);
55 RadioButton3->close(TRUE);
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);
64 Layout1->addWidget(GroupPoints, 1, 0);
65 /***************************************************************/
68 myTransformationGUI = theTransformationGUI;
73 //=================================================================================
74 // function : ~TransformationGUI_MirrorDlg()
75 // purpose : Destroys the object and frees any allocated resources
76 //=================================================================================
77 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
79 /* no need to delete child widgets, Qt does it all for us */
83 //=================================================================================
86 //=================================================================================
87 void TransformationGUI_MirrorDlg::Init()
90 myEditCurrentArgument = GroupPoints->LineEdit1;
92 myOkShape1 = myOkShape2 = false;
94 /* Vertices Filter for all arguments */
95 myFaceFilter = new GEOM_FaceFilter(StdSelect_Plane, myGeom);
97 /* signals and slots connections */
98 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
99 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
101 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
102 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
104 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
105 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
107 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
109 /* displays Dialog */
117 //=================================================================================
118 // function : ClickOnOk()
120 //=================================================================================
121 void TransformationGUI_MirrorDlg::ClickOnOk()
123 this->ClickOnApply();
128 //=================================================================================
129 // function : ClickOnApply()
131 //=================================================================================
132 void TransformationGUI_MirrorDlg::ClickOnApply()
134 buttonApply->setFocus();
135 QAD_Application::getDesktop()->putInfo(tr(""));
136 if (mySimulationTopoDs.IsNull())
138 myGeomBase->EraseSimulationShape();
139 mySimulationTopoDs.Nullify();
141 if(myOkShape1 && myOkShape2)
142 myTransformationGUI->MakeMirrorAndDisplay(myGeomShape1, myGeomShape2);
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose : Called when selection has changed
150 //=================================================================================
151 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
153 myGeomBase->EraseSimulationShape();
154 mySimulationTopoDs.Nullify();
155 myEditCurrentArgument->setText("");
156 QString aString = ""; /* name of selection */
158 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
160 if(myEditCurrentArgument == GroupPoints->LineEdit1)
162 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
169 Standard_Boolean testResult;
170 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
171 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
174 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
175 myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
179 myEditCurrentArgument->setText(aString);
182 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
183 myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
187 myEditCurrentArgument->setText(aString);
191 if(myOkShape1 && myOkShape2)
192 MakeMirrorSimulationAndDisplay();
197 //=================================================================================
198 // function : SetEditCurrentArgument()
200 //=================================================================================
201 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
203 QPushButton* send = (QPushButton*)sender();
204 mySelection->ClearFilters();
206 if(send == GroupPoints->PushButton1) {
207 GroupPoints->LineEdit1->setFocus();
208 myEditCurrentArgument = GroupPoints->LineEdit1;
210 else if(send == GroupPoints->PushButton2) {
211 GroupPoints->LineEdit2->setFocus();
212 myEditCurrentArgument = GroupPoints->LineEdit2;
213 mySelection->AddFilter(myFaceFilter);
215 this->SelectionIntoArgument();
221 //=================================================================================
222 // function : LineEditReturnPressed()
224 //=================================================================================
225 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
227 QLineEdit* send = (QLineEdit*)sender();
228 if(send == GroupPoints->LineEdit1)
229 myEditCurrentArgument = GroupPoints->LineEdit1;
230 else if(send == GroupPoints->LineEdit2)
231 myEditCurrentArgument = GroupPoints->LineEdit2;
235 GEOMBase_Skeleton::LineEditReturnPressed();
240 //=================================================================================
241 // function : enterEvent()
242 // purpose : when mouse enter onto the QWidget
243 //=================================================================================
244 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
246 if(GroupConstructors->isEnabled())
248 this->ActivateThisDialog();
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void TransformationGUI_MirrorDlg::ActivateThisDialog()
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);
269 //=================================================================================
270 // function : MakeMirrorSimulationAndDisplay()
271 // purpose : S1 is a shape and S2 a mirror.
272 //=================================================================================
273 void TransformationGUI_MirrorDlg::MakeMirrorSimulationAndDisplay()
275 myGeomBase->EraseSimulationShape();
276 mySimulationTopoDs.Nullify();
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) */
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);
291 this->mySimulationTopoDs = myBRepTransformation.Shape();
292 if(mySimulationTopoDs.IsNull())
295 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
297 catch(Standard_Failure) {
298 MESSAGE("Exception catched in MakeMirrorSimulationAndDisplay");