Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / BasicGUI / BasicGUI_WorkingPlaneDlg.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   : BasicGUI_WorkingPlaneDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27
28 using namespace std;
29 #include "BasicGUI_WorkingPlaneDlg.h"
30
31 #include <BRepAdaptor_Surface.hxx>
32 #include <gp_Pln.hxx>
33 #include <gp_Dir.hxx>
34 #include <gp_Ax1.hxx>
35
36 //=================================================================================
37 // class    : BasicGUI_WorkingPlaneDlg()
38 // purpose  : Constructs a BasicGUI_WorkingPlaneDlg 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 BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, 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_WPLANE_FACE")));
47   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48
49   setCaption(tr("GEOM_WPLANE_TITLE"));
50     
51   /***************************************************************/
52   GroupConstructors->setTitle(tr("GEOM_WPLANE"));
53   RadioButton1->setPixmap(image0);
54   RadioButton2->close(TRUE);
55   RadioButton3->close(TRUE);
56
57   GroupWPlane = new DlgRef_1Sel_QTD(this, "GroupWPlane");
58   GroupWPlane->GroupBox1->setTitle(tr("GEOM_WPLANE_FACE"));
59   GroupWPlane->TextLabel1->setText(tr("GEOM_SELECTION"));
60   GroupWPlane->PushButton1->setPixmap(image1);
61
62   Layout1->addWidget(GroupWPlane, 1, 0);
63   /***************************************************************/
64
65   /* Initialisation */
66   myBasicGUI = theBasicGUI;
67   Init();
68 }
69
70
71 //=================================================================================
72 // function : ~BasicGUI_WorkingPlaneDlg()
73 // purpose  : Destroys the object and frees any allocated resources
74 //=================================================================================
75 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
76 {
77     // no need to delete child widgets, Qt does it all for us
78 }
79
80
81 //=================================================================================
82 // function : Init()
83 // purpose  :
84 //=================================================================================
85 void BasicGUI_WorkingPlaneDlg::Init()
86 {
87   /* init variables */
88   myEditCurrentArgument = GroupWPlane->LineEdit1;
89
90   myOkPlane = false;
91
92   /* Filter definition */
93   myFaceFilter = new GEOM_FaceFilter(StdSelect_Plane, myGeom);
94   mySelection->AddFilter(myFaceFilter); /* filter for next selection */
95
96    /* signals and slots connections */
97   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
98   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
99
100   connect(GroupWPlane->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
101   connect(GroupWPlane->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
102
103   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
104
105   /* displays Dialog */
106   GroupWPlane->show();
107   this->show();
108
109   return;
110 }
111
112
113 //=================================================================================
114 // function : ClickOnOk()
115 // purpose  :
116 //=================================================================================
117 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
118 {
119   this->ClickOnApply();
120   ClickOnCancel();
121   return;
122 }
123
124 //=================================================================================
125 // function : ClickOnApply()
126 // purpose  :
127 //=================================================================================
128 void BasicGUI_WorkingPlaneDlg::ClickOnApply()
129 {
130   buttonApply->setFocus();
131   QAD_Application::getDesktop()->putInfo(tr(""));
132   if(myOkPlane)
133     myBasicGUI->MakeWorkingPlane(myLoc, myDir);
134
135   return;
136 }
137
138
139 //=================================================================================
140 // function : SelectionIntoArgument()
141 // purpose  : Called when selection as changed or other case
142 //=================================================================================
143 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
144 {
145   myEditCurrentArgument->setText("");
146   QString aString = "";
147
148   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
149   if(nbSel != 1) {
150     myOkPlane = false;
151     return;
152   }
153   
154   /*  nbSel == 1  */ 
155   TopoDS_Shape S;
156   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
157     return;
158    
159   BRepAdaptor_Surface surf(TopoDS::Face(S));
160   gp_Pln Plane = surf.Plane();
161   myLoc = Plane.Location();
162   myDir = Plane.Axis().Direction();
163
164   GroupWPlane->LineEdit1->setText(aString);
165   myOkPlane = true;
166
167   /* no simulation */
168   return;
169 }
170
171
172 //=================================================================================
173 // function : SetEditCurrentArgument()
174 // purpose  :
175 //=================================================================================
176 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
177 {
178   GroupWPlane->LineEdit1->setFocus();
179   this->SelectionIntoArgument();
180   return;
181 }
182
183
184 //=================================================================================
185 // function : LineEditReturnPressed()
186 // purpose  :
187 //=================================================================================
188 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
189 {
190   GEOMBase_Skeleton::LineEditReturnPressed();
191   return;
192 }
193
194
195 //=================================================================================
196 // function : ActivateThisDialog()
197 // purpose  :
198 //=================================================================================
199 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog()
200 {
201   GEOMBase_Skeleton::ActivateThisDialog();
202   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
203   mySelection->AddFilter(myFaceFilter);
204   return;
205 }
206
207
208 //=================================================================================
209 // function : enterEvent()
210 // purpose  :
211 //=================================================================================
212 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
213 {
214   if(GroupConstructors->isEnabled())
215     return;
216   this->ActivateThisDialog();
217   return;
218 }