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
28 #include "BasicGUI_WorkingPlaneDlg.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
37 #include <Geom_Surface.hxx>
38 #include <Geom_Plane.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Vertex.hxx>
44 #include <BRep_Tool.hxx>
48 #include <V3d_View.hxx>
50 #include "GEOMImpl_Types.hxx"
52 #include <qcheckbox.h>
57 //=================================================================================
58 // class : BasicGUI_WorkingPlaneDlg()
59 // purpose : Constructs a BasicGUI_WorkingPlaneDlg which is a child of 'parent', with the
60 // name 'name' and widget flags set to 'f'.
61 // The dialog will by default be modeless, unless you set 'modal' to
62 // TRUE to construct a modal dialog.
63 //=================================================================================
64 BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg(GeometryGUI* theGeometryGUI , QWidget* parent, const char* name, bool modal, WFlags fl)
65 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
67 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
68 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_FACE")));
69 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_VECTOR")));
70 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_ORIGIN")));
72 setCaption(tr("GEOM_WPLANE_TITLE"));
74 /***************************************************************/
75 GroupConstructors->setTitle(tr("GEOM_WPLANE"));
76 RadioButton1->setPixmap(image1);
77 RadioButton2->setPixmap(image2);
78 RadioButton3->setPixmap(image3);
80 Group1 = new DlgRef_1Sel_QTD(this, "Group1");
81 Group1->GroupBox1->setTitle(tr("GEOM_WPLANE_FACE"));
82 Group1->TextLabel1->setText(tr("GEOM_SELECTION"));
83 Group1->PushButton1->setPixmap(image0);
84 Group1->LineEdit1->setReadOnly( true );
86 Group2 = new DlgRef_2Sel_QTD(this, "Group2");
87 Group2->GroupBox1->setTitle(tr("GEOM_WPLANE_VECTOR"));
88 Group2->TextLabel1->setText(tr("GEOM_WPLANE_VX"));
89 Group2->TextLabel2->setText(tr("GEOM_WPLANE_VZ"));
90 Group2->PushButton1->setPixmap(image0);
91 Group2->PushButton2->setPixmap(image0);
92 Group2->LineEdit1->setReadOnly( true );
93 Group2->LineEdit2->setReadOnly( true );
95 Group3 = new DlgRef_3Check_QTD(this, "Group3");
96 Group3->GroupBox1->setTitle(tr("GEOM_WPLANE_ORIGIN"));
97 Group3->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
98 Group3->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
99 Group3->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
101 Layout1->addWidget(Group1, 1, 0);
102 Layout1->addWidget(Group2, 1, 0);
103 Layout1->addWidget(Group3, 1, 0);
104 /***************************************************************/
109 //=================================================================================
110 // function : ~BasicGUI_WorkingPlaneDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
117 //=================================================================================
120 //=================================================================================
121 void BasicGUI_WorkingPlaneDlg::Init()
124 myEditCurrentArgument = Group1->LineEdit1;
125 myWPlane = myGeometryGUI->GetWorkingPlane();
127 // myGeometryGUI->SetState( 0 );
129 myFace = GEOM::GEOM_Object::_nil();
130 myVectX = GEOM::GEOM_Object::_nil();
131 myVectZ = GEOM::GEOM_Object::_nil();
135 /* Filter definition */
136 globalSelection( GEOM_PLANE );
138 /* signals and slots connections */
139 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
140 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
141 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
142 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
144 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
145 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
147 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(Group3->GroupBox1, SIGNAL(clicked(int)), this, SLOT(GroupClicked(int)));
157 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
158 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
160 initName( tr( "GEOM_WPLANE" ) );
161 ConstructorsClicked(0);
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
170 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
171 // myGeometryGUI->SetState( 0 );
173 switch (constructorId)
177 globalSelection( GEOM_PLANE );
184 myEditCurrentArgument = Group1->LineEdit1;
185 Group1->LineEdit1->setText("");
186 myFace = GEOM::GEOM_Object::_nil();
188 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
189 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 globalSelection( GEOM_LINE );
201 myEditCurrentArgument = Group2->LineEdit1;
202 Group2->LineEdit1->setText("");
203 Group2->LineEdit2->setText("");
204 myVectX = GEOM::GEOM_Object::_nil();
205 myVectZ = GEOM::GEOM_Object::_nil();
207 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
208 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
218 Group3->RadioButton1->setChecked(true);
226 //=================================================================================
227 // function : GroupClicked()
228 // purpose : Radio button management
229 //=================================================================================
230 void BasicGUI_WorkingPlaneDlg::GroupClicked(int groupId)
232 aOriginType = groupId;
235 //=================================================================================
236 // function : ClickOnOk()
238 //=================================================================================
239 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
241 if ( ClickOnApply() )
245 //=================================================================================
246 // function : ClickOnApply()
248 //=================================================================================
249 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
251 buttonApply->setFocus();
252 myGeometryGUI->application()->putInfo(tr(""));
253 const int id = getConstructorId();
256 if ( !CORBA::is_nil( myFace ) ) {
257 TopoDS_Face aPlaneShape;
258 if ( GEOMBase::GetShape( myFace, aPlaneShape, TopAbs_FACE ) ) {
259 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aPlaneShape ) );
260 if ( !aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
261 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
262 gp_Pln aPln = aGPlane->Pln();
264 myWPlane = aPln.Position();
265 myGeometryGUI->SetWorkingPlane(myWPlane);
266 myGeometryGUI->ActiveWorkingPlane();
271 } else if (id == 1) {
272 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
273 showError( "Two vectors have to be selected" );
277 TopoDS_Edge aVectX, aVectZ;
278 TopoDS_Vertex V1, V2;
280 if (GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) &&
281 GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE )) {
282 TopExp::Vertices(aVectZ, V1, V2, Standard_True);
283 if (!V1.IsNull() && !V2.IsNull())
284 aVZ = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
286 showError( "Bad OZ vector" );
290 TopExp::Vertices(aVectX, V1, V2, Standard_True);
291 if (!V1.IsNull() && !V2.IsNull())
292 aVX = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
294 showError( "Bad OX vector" );
298 gp_Dir aDirZ = gp_Dir(aVZ.X(), aVZ.Y(), aVZ.Z());
299 gp_Dir aDirX = gp_Dir(aVX.X(), aVX.Y(), aVX.Z());
301 if (aDirX.IsParallel(aDirZ, Precision::Confusion())) {
302 showError( "Parallel vectors selected" );
306 myWPlane = gp_Ax3(BRep_Tool::Pnt(V1), aDirZ, aDirX);
308 myGeometryGUI->SetWorkingPlane(myWPlane);
309 myGeometryGUI->ActiveWorkingPlane();
312 } else if (id == 2) {
313 gp_Pnt P1 = gp_Pnt(0., 0., 0.);
316 if (aOriginType == 1) {
317 aDirZ = gp_Dir(0., 0., 1.);
318 aDirX = gp_Dir(1., 0., 0.);
320 else if (aOriginType == 2) {
321 aDirZ = gp_Dir(1., 0., 0.);
322 aDirX = gp_Dir(0., 1., 0.);
324 else if (aOriginType == 0) {
325 aDirZ = gp_Dir(0., 1., 0.);
326 aDirX = gp_Dir(0., 0., 1.);
329 myWPlane = gp_Ax3(P1, aDirZ, aDirX);
331 myGeometryGUI->SetWorkingPlane(myWPlane);
332 myGeometryGUI->ActiveWorkingPlane();
338 //=================================================================================
339 // function : SelectionIntoArgument()
340 // purpose : Called when selection as changed or other case
341 //=================================================================================
342 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
344 myEditCurrentArgument->setText("");
346 const int id = getConstructorId();
347 if ( IObjectCount() != 1 ) {
349 myFace = GEOM::GEOM_Object::_nil();
351 if (myEditCurrentArgument == Group2->LineEdit1)
352 myVectX = GEOM::GEOM_Object::_nil();
353 else if (myEditCurrentArgument == Group2->LineEdit2)
354 myVectZ = GEOM::GEOM_Object::_nil();
360 Standard_Boolean aRes = Standard_False;
361 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
363 if(!aRes || CORBA::is_nil( aSelectedObject ))
366 if(myEditCurrentArgument == Group1->LineEdit1)
367 myFace = aSelectedObject;
368 else if(myEditCurrentArgument == Group2->LineEdit1)
369 myVectX = aSelectedObject;
370 else if(myEditCurrentArgument == Group2->LineEdit2)
371 myVectZ = aSelectedObject;
373 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
377 //=================================================================================
378 // function : SetEditCurrentArgument()
380 //=================================================================================
381 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
383 QPushButton* send = (QPushButton*)sender();
385 if(send == Group1->PushButton1) {
386 myEditCurrentArgument = Group1->LineEdit1;
387 globalSelection( GEOM_PLANE );
389 else if(send == Group2->PushButton1) {
390 myEditCurrentArgument = Group2->LineEdit1;
391 globalSelection( GEOM_LINE );
393 else if(send == Group2->PushButton2) {
394 myEditCurrentArgument = Group2->LineEdit2;
395 globalSelection( GEOM_LINE );
398 myEditCurrentArgument->setFocus();
399 SelectionIntoArgument();
403 //=================================================================================
404 // function : LineEditReturnPressed()
406 //=================================================================================
407 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
409 QLineEdit* send = (QLineEdit*)sender();
410 if(send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2) {
411 myEditCurrentArgument = send;
412 GEOMBase_Skeleton::LineEditReturnPressed();
417 //=================================================================================
418 // function : ActivateThisDialog()
420 //=================================================================================
421 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
423 GEOMBase_Skeleton::ActivateThisDialog();
424 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
425 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
427 ConstructorsClicked( getConstructorId() );
431 //=================================================================================
432 // function : DeactivateActiveDialog()
433 // purpose : public slot to deactivate if active
434 //=================================================================================
435 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
437 // myGeometryGUI->SetState( -1 );
438 GEOMBase_Skeleton::DeactivateActiveDialog();
441 //=======================================================================
442 // function : ClickOnCancel()
444 //=======================================================================
445 void BasicGUI_WorkingPlaneDlg::ClickOnCancel()
447 GEOMBase_Skeleton::ClickOnCancel();
450 //=================================================================================
451 // function : enterEvent()
453 //=================================================================================
454 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
456 if ( !GroupConstructors->isEnabled() )
457 ActivateThisDialog();
460 //=================================================================================
461 // function : closeEvent
463 //=================================================================================
464 void BasicGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
466 // myGeometryGUI->SetState( -1 );
467 GEOMBase_Skeleton::closeEvent( e );