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 QAD_Application::getDesktop()->putInfo(tr(""));
135 if (mySimulationTopoDs.IsNull())
137 myGeomBase->EraseSimulationShape();
138 mySimulationTopoDs.Nullify();
140 if(myOkShape1 && myOkShape2)
141 myTransformationGUI->MakeMirrorAndDisplay(myGeomShape1, myGeomShape2);
146 //=================================================================================
147 // function : SelectionIntoArgument()
148 // purpose : Called when selection has changed
149 //=================================================================================
150 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
152 myGeomBase->EraseSimulationShape();
153 mySimulationTopoDs.Nullify();
154 myEditCurrentArgument->setText("");
155 QString aString = ""; /* name of selection */
157 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
159 if(myEditCurrentArgument == GroupPoints->LineEdit1)
161 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
168 Standard_Boolean testResult;
169 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
170 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
173 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
174 myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
178 myEditCurrentArgument->setText(aString);
181 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
182 myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
186 myEditCurrentArgument->setText(aString);
190 if(myOkShape1 && myOkShape2)
191 MakeMirrorSimulationAndDisplay();
196 //=================================================================================
197 // function : SetEditCurrentArgument()
199 //=================================================================================
200 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
202 QPushButton* send = (QPushButton*)sender();
203 mySelection->ClearFilters();
205 if(send == GroupPoints->PushButton1) {
206 GroupPoints->LineEdit1->setFocus();
207 myEditCurrentArgument = GroupPoints->LineEdit1;
209 else if(send == GroupPoints->PushButton2) {
210 GroupPoints->LineEdit2->setFocus();
211 myEditCurrentArgument = GroupPoints->LineEdit2;
212 mySelection->AddFilter(myFaceFilter);
214 this->SelectionIntoArgument();
220 //=================================================================================
221 // function : LineEditReturnPressed()
223 //=================================================================================
224 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
226 QLineEdit* send = (QLineEdit*)sender();
227 if(send == GroupPoints->LineEdit1)
228 myEditCurrentArgument = GroupPoints->LineEdit1;
229 else if(send == GroupPoints->LineEdit2)
230 myEditCurrentArgument = GroupPoints->LineEdit2;
234 GEOMBase_Skeleton::LineEditReturnPressed();
239 //=================================================================================
240 // function : enterEvent()
241 // purpose : when mouse enter onto the QWidget
242 //=================================================================================
243 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
245 if(GroupConstructors->isEnabled())
247 this->ActivateThisDialog();
252 //=================================================================================
253 // function : ActivateThisDialog()
255 //=================================================================================
256 void TransformationGUI_MirrorDlg::ActivateThisDialog()
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);
268 //=================================================================================
269 // function : MakeMirrorSimulationAndDisplay()
270 // purpose : S1 is a shape and S2 a mirror.
271 //=================================================================================
272 void TransformationGUI_MirrorDlg::MakeMirrorSimulationAndDisplay()
274 myGeomBase->EraseSimulationShape();
275 mySimulationTopoDs.Nullify();
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) */
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);
290 this->mySimulationTopoDs = myBRepTransformation.Shape();
291 if(mySimulationTopoDs.IsNull())
294 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
296 catch(Standard_Failure) {
297 MESSAGE("Exception catched in MakeMirrorSimulationAndDisplay");