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 : BasicGUI_WorkingPlaneDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_WorkingPlaneDlg.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_SelectionMgr.h"
38 #include <Geom_Surface.hxx>
39 #include <Geom_Plane.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Vertex.hxx>
45 #include <BRep_Tool.hxx>
49 #include <V3d_View.hxx>
51 #include "GEOMImpl_Types.hxx"
53 #include <qcheckbox.h>
56 //=================================================================================
57 // class : BasicGUI_WorkingPlaneDlg()
58 // purpose : Constructs a BasicGUI_WorkingPlaneDlg which is a child of 'parent', with the
59 // name 'name' and widget flags set to 'f'.
60 // The dialog will by default be modeless, unless you set 'modal' to
61 // TRUE to construct a modal dialog.
62 //=================================================================================
63 BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg(GeometryGUI* theGeometryGUI , QWidget* parent, const char* name, bool modal, WFlags fl)
64 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
66 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
67 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_FACE")));
68 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_VECTOR")));
69 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_ORIGIN")));
71 setCaption(tr("GEOM_WPLANE_TITLE"));
73 /***************************************************************/
74 GroupConstructors->setTitle(tr("GEOM_WPLANE"));
75 RadioButton1->setPixmap(image1);
76 RadioButton2->setPixmap(image2);
77 RadioButton3->setPixmap(image3);
79 Group1 = new DlgRef_1Sel_QTD(this, "Group1");
80 Group1->GroupBox1->setTitle(tr("GEOM_WPLANE_FACE"));
81 Group1->TextLabel1->setText(tr("GEOM_SELECTION"));
82 Group1->PushButton1->setPixmap(image0);
83 Group1->LineEdit1->setReadOnly( true );
85 Group2 = new DlgRef_2Sel_QTD(this, "Group2");
86 Group2->GroupBox1->setTitle(tr("GEOM_WPLANE_VECTOR"));
87 Group2->TextLabel1->setText(tr("GEOM_WPLANE_VX"));
88 Group2->TextLabel2->setText(tr("GEOM_WPLANE_VZ"));
89 Group2->PushButton1->setPixmap(image0);
90 Group2->PushButton2->setPixmap(image0);
91 Group2->LineEdit1->setReadOnly( true );
92 Group2->LineEdit2->setReadOnly( true );
94 Group3 = new DlgRef_3Check_QTD(this, "Group3");
95 Group3->GroupBox1->setTitle(tr("GEOM_WPLANE_ORIGIN"));
96 Group3->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
97 Group3->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
98 Group3->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
100 Layout1->addWidget(Group1, 1, 0);
101 Layout1->addWidget(Group2, 1, 0);
102 Layout1->addWidget(Group3, 1, 0);
103 /***************************************************************/
108 //=================================================================================
109 // function : ~BasicGUI_WorkingPlaneDlg()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
116 //=================================================================================
119 //=================================================================================
120 void BasicGUI_WorkingPlaneDlg::Init()
123 myEditCurrentArgument = Group1->LineEdit1;
124 myWPlane = myGeometryGUI->GetWorkingPlane();
126 // myGeometryGUI->SetState( 0 );
128 myFace = GEOM::GEOM_Object::_nil();
129 myVectX = GEOM::GEOM_Object::_nil();
130 myVectZ = GEOM::GEOM_Object::_nil();
134 /* Filter definition */
135 globalSelection( GEOM_PLANE );
137 /* signals and slots connections */
138 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
139 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
140 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
141 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
143 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
146 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(Group3->GroupBox1, SIGNAL(clicked(int)), this, SLOT(GroupClicked(int)));
156 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
157 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
159 initName( tr( "GEOM_WPLANE" ) );
160 ConstructorsClicked(0);
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
169 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
170 // myGeometryGUI->SetState( 0 );
172 switch (constructorId)
176 globalSelection( GEOM_PLANE );
183 myEditCurrentArgument = Group1->LineEdit1;
184 Group1->LineEdit1->setText("");
185 myFace = GEOM::GEOM_Object::_nil();
187 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
188 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
193 globalSelection( GEOM_LINE );
200 myEditCurrentArgument = Group2->LineEdit1;
201 Group2->LineEdit1->setText("");
202 Group2->LineEdit2->setText("");
203 myVectX = GEOM::GEOM_Object::_nil();
204 myVectZ = GEOM::GEOM_Object::_nil();
206 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
207 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
217 Group3->RadioButton1->setChecked(true);
225 //=================================================================================
226 // function : GroupClicked()
227 // purpose : Radio button management
228 //=================================================================================
229 void BasicGUI_WorkingPlaneDlg::GroupClicked(int groupId)
231 aOriginType = groupId;
234 //=================================================================================
235 // function : ClickOnOk()
237 //=================================================================================
238 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
240 if ( ClickOnApply() )
244 //=================================================================================
245 // function : ClickOnApply()
247 //=================================================================================
248 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
250 buttonApply->setFocus();
251 myGeometryGUI->application()->putInfo(tr(""));
252 const int id = getConstructorId();
255 if ( !CORBA::is_nil( myFace ) ) {
256 TopoDS_Face aPlaneShape;
257 if ( GEOMBase::GetShape( myFace, aPlaneShape, TopAbs_FACE ) ) {
258 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aPlaneShape ) );
259 if ( !aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
260 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
261 gp_Pln aPln = aGPlane->Pln();
263 myWPlane = aPln.Position();
264 myGeometryGUI->SetWorkingPlane(myWPlane);
265 myGeometryGUI->ActiveWorkingPlane();
270 } else if (id == 1) {
271 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
272 showError( "Two vectors have to be selected" );
276 TopoDS_Edge aVectX, aVectZ;
277 TopoDS_Vertex V1, V2;
279 if (GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) &&
280 GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE )) {
281 TopExp::Vertices(aVectZ, V1, V2, Standard_True);
282 if (!V1.IsNull() && !V2.IsNull())
283 aVZ = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
285 showError( "Bad OZ vector" );
289 TopExp::Vertices(aVectX, V1, V2, Standard_True);
290 if (!V1.IsNull() && !V2.IsNull())
291 aVX = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
293 showError( "Bad OX vector" );
297 gp_Dir aDirZ = gp_Dir(aVZ.X(), aVZ.Y(), aVZ.Z());
298 gp_Dir aDirX = gp_Dir(aVX.X(), aVX.Y(), aVX.Z());
300 if (aDirX.IsParallel(aDirZ, Precision::Confusion())) {
301 showError( "Parallel vectors selected" );
305 myWPlane = gp_Ax3(BRep_Tool::Pnt(V1), aDirZ, aDirX);
307 myGeometryGUI->SetWorkingPlane(myWPlane);
308 myGeometryGUI->ActiveWorkingPlane();
311 } else if (id == 2) {
312 gp_Pnt P1 = gp_Pnt(0., 0., 0.);
315 if (aOriginType == 1) {
316 aDirZ = gp_Dir(0., 0., 1.);
317 aDirX = gp_Dir(1., 0., 0.);
319 else if (aOriginType == 2) {
320 aDirZ = gp_Dir(1., 0., 0.);
321 aDirX = gp_Dir(0., 1., 0.);
323 else if (aOriginType == 0) {
324 aDirZ = gp_Dir(0., 1., 0.);
325 aDirX = gp_Dir(0., 0., 1.);
328 myWPlane = gp_Ax3(P1, aDirZ, aDirX);
330 myGeometryGUI->SetWorkingPlane(myWPlane);
331 myGeometryGUI->ActiveWorkingPlane();
337 //=================================================================================
338 // function : SelectionIntoArgument()
339 // purpose : Called when selection as changed or other case
340 //=================================================================================
341 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
343 myEditCurrentArgument->setText("");
345 const int id = getConstructorId();
346 if ( IObjectCount() != 1 ) {
348 myFace = GEOM::GEOM_Object::_nil();
350 if (myEditCurrentArgument == Group2->LineEdit1)
351 myVectX = GEOM::GEOM_Object::_nil();
352 else if (myEditCurrentArgument == Group2->LineEdit2)
353 myVectZ = GEOM::GEOM_Object::_nil();
359 Standard_Boolean aRes = Standard_False;
360 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
362 if(!aRes || CORBA::is_nil( aSelectedObject ))
365 if(myEditCurrentArgument == Group1->LineEdit1)
366 myFace = aSelectedObject;
367 else if(myEditCurrentArgument == Group2->LineEdit1)
368 myVectX = aSelectedObject;
369 else if(myEditCurrentArgument == Group2->LineEdit2)
370 myVectZ = aSelectedObject;
372 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
376 //=================================================================================
377 // function : SetEditCurrentArgument()
379 //=================================================================================
380 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
382 QPushButton* send = (QPushButton*)sender();
384 if(send == Group1->PushButton1) {
385 myEditCurrentArgument = Group1->LineEdit1;
386 globalSelection( GEOM_PLANE );
388 else if(send == Group2->PushButton1) {
389 myEditCurrentArgument = Group2->LineEdit1;
390 globalSelection( GEOM_LINE );
392 else if(send == Group2->PushButton2) {
393 myEditCurrentArgument = Group2->LineEdit2;
394 globalSelection( GEOM_LINE );
397 myEditCurrentArgument->setFocus();
398 SelectionIntoArgument();
402 //=================================================================================
403 // function : LineEditReturnPressed()
405 //=================================================================================
406 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
408 QLineEdit* send = (QLineEdit*)sender();
409 if(send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2) {
410 myEditCurrentArgument = send;
411 GEOMBase_Skeleton::LineEditReturnPressed();
416 //=================================================================================
417 // function : ActivateThisDialog()
419 //=================================================================================
420 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
422 GEOMBase_Skeleton::ActivateThisDialog();
423 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
424 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
426 ConstructorsClicked( getConstructorId() );
430 //=================================================================================
431 // function : DeactivateActiveDialog()
432 // purpose : public slot to deactivate if active
433 //=================================================================================
434 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
436 // myGeometryGUI->SetState( -1 );
437 GEOMBase_Skeleton::DeactivateActiveDialog();
440 //=======================================================================
441 // function : ClickOnCancel()
443 //=======================================================================
444 void BasicGUI_WorkingPlaneDlg::ClickOnCancel()
446 GEOMBase_Skeleton::ClickOnCancel();
449 //=================================================================================
450 // function : enterEvent()
452 //=================================================================================
453 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
455 if ( !GroupConstructors->isEnabled() )
456 ActivateThisDialog();
459 //=================================================================================
460 // function : closeEvent
462 //=================================================================================
463 void BasicGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
465 // myGeometryGUI->SetState( -1 );
466 GEOMBase_Skeleton::closeEvent( e );