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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "LightApp_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,
65 const char* name, bool modal, WFlags fl)
66 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
67 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
69 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
70 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_FACE")));
71 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_VECTOR")));
72 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_ORIGIN")));
74 setCaption(tr("GEOM_WPLANE_TITLE"));
76 /***************************************************************/
77 GroupConstructors->setTitle(tr("GEOM_WPLANE"));
78 RadioButton1->setPixmap(image1);
79 RadioButton2->setPixmap(image2);
80 RadioButton3->setPixmap(image3);
82 Group1 = new DlgRef_1Sel_QTD(this, "Group1");
83 Group1->GroupBox1->setTitle(tr("GEOM_WPLANE_FACE"));
84 Group1->TextLabel1->setText(tr("GEOM_SELECTION"));
85 Group1->PushButton1->setPixmap(image0);
86 Group1->LineEdit1->setReadOnly( true );
88 Group2 = new DlgRef_2Sel_QTD(this, "Group2");
89 Group2->GroupBox1->setTitle(tr("GEOM_WPLANE_VECTOR"));
90 Group2->TextLabel1->setText(tr("GEOM_WPLANE_VX"));
91 Group2->TextLabel2->setText(tr("GEOM_WPLANE_VZ"));
92 Group2->PushButton1->setPixmap(image0);
93 Group2->PushButton2->setPixmap(image0);
94 Group2->LineEdit1->setReadOnly( true );
95 Group2->LineEdit2->setReadOnly( true );
97 Group3 = new DlgRef_3Check_QTD(this, "Group3");
98 Group3->GroupBox1->setTitle(tr("GEOM_WPLANE_ORIGIN"));
99 Group3->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
100 Group3->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
101 Group3->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
103 Layout1->addWidget(Group1, 1, 0);
104 Layout1->addWidget(Group2, 1, 0);
105 Layout1->addWidget(Group3, 1, 0);
106 /***************************************************************/
108 setHelpFileName("working_plane.htm");
113 //=================================================================================
114 // function : ~BasicGUI_WorkingPlaneDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
121 //=================================================================================
124 //=================================================================================
125 void BasicGUI_WorkingPlaneDlg::Init()
128 myEditCurrentArgument = Group1->LineEdit1;
129 myWPlane = myGeomGUI->GetWorkingPlane();
131 // myGeomGUI->SetState( 0 );
133 myFace = GEOM::GEOM_Object::_nil();
134 myVectX = GEOM::GEOM_Object::_nil();
135 myVectZ = GEOM::GEOM_Object::_nil();
139 /* Filter definition */
140 globalSelection( GEOM_PLANE );
142 /* signals and slots connections */
143 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
144 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
145 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
146 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
151 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(Group3->GroupBox1, SIGNAL(clicked(int)), this, SLOT(GroupClicked(int)));
161 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
162 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
164 initName( tr( "GEOM_WPLANE" ) );
165 ConstructorsClicked(0);
168 //=================================================================================
169 // function : ConstructorsClicked()
170 // purpose : Radio button management
171 //=================================================================================
172 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
174 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
175 // myGeomGUI->SetState( 0 );
177 switch (constructorId)
181 globalSelection( GEOM_PLANE );
188 myEditCurrentArgument = Group1->LineEdit1;
189 Group1->LineEdit1->setText("");
190 myFace = GEOM::GEOM_Object::_nil();
192 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
193 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
198 globalSelection( GEOM_LINE );
205 myEditCurrentArgument = Group2->LineEdit1;
206 Group2->LineEdit1->setText("");
207 Group2->LineEdit2->setText("");
208 myVectX = GEOM::GEOM_Object::_nil();
209 myVectZ = GEOM::GEOM_Object::_nil();
211 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
212 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
222 Group3->RadioButton1->setChecked(true);
230 //=================================================================================
231 // function : GroupClicked()
232 // purpose : Radio button management
233 //=================================================================================
234 void BasicGUI_WorkingPlaneDlg::GroupClicked(int groupId)
236 aOriginType = groupId;
239 //=================================================================================
240 // function : ClickOnOk()
242 //=================================================================================
243 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
245 if ( ClickOnApply() )
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
255 buttonApply->setFocus();
256 myGeomGUI->application()->putInfo(tr(""));
257 const int id = getConstructorId();
260 if ( !CORBA::is_nil( myFace ) ) {
261 TopoDS_Face aPlaneShape;
262 if ( GEOMBase::GetShape( myFace, aPlaneShape, TopAbs_FACE ) ) {
263 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aPlaneShape ) );
264 if ( !aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
265 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
266 gp_Pln aPln = aGPlane->Pln();
268 myWPlane = aPln.Position();
269 myGeomGUI->SetWorkingPlane(myWPlane);
270 myGeomGUI->ActiveWorkingPlane();
275 } else if (id == 1) {
276 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
277 showError( "Two vectors have to be selected" );
281 TopoDS_Edge aVectX, aVectZ;
282 TopoDS_Vertex V1, V2;
284 if (GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) &&
285 GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE )) {
286 TopExp::Vertices(aVectZ, V1, V2, Standard_True);
287 if (!V1.IsNull() && !V2.IsNull())
288 aVZ = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
290 showError( "Bad OZ vector" );
294 TopExp::Vertices(aVectX, V1, V2, Standard_True);
295 if (!V1.IsNull() && !V2.IsNull())
296 aVX = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
298 showError( "Bad OX vector" );
302 gp_Dir aDirZ = gp_Dir(aVZ.X(), aVZ.Y(), aVZ.Z());
303 gp_Dir aDirX = gp_Dir(aVX.X(), aVX.Y(), aVX.Z());
305 if (aDirX.IsParallel(aDirZ, Precision::Confusion())) {
306 showError( "Parallel vectors selected" );
310 myWPlane = gp_Ax3(BRep_Tool::Pnt(V1), aDirZ, aDirX);
312 myGeomGUI->SetWorkingPlane(myWPlane);
313 myGeomGUI->ActiveWorkingPlane();
316 } else if (id == 2) {
317 gp_Pnt P1 = gp_Pnt(0., 0., 0.);
320 if (aOriginType == 1) {
321 aDirZ = gp_Dir(0., 0., 1.);
322 aDirX = gp_Dir(1., 0., 0.);
324 else if (aOriginType == 2) {
325 aDirZ = gp_Dir(1., 0., 0.);
326 aDirX = gp_Dir(0., 1., 0.);
328 else if (aOriginType == 0) {
329 aDirZ = gp_Dir(0., 1., 0.);
330 aDirX = gp_Dir(0., 0., 1.);
333 myWPlane = gp_Ax3(P1, aDirZ, aDirX);
335 myGeomGUI->SetWorkingPlane(myWPlane);
336 myGeomGUI->ActiveWorkingPlane();
342 //=================================================================================
343 // function : SelectionIntoArgument()
344 // purpose : Called when selection as changed or other case
345 //=================================================================================
346 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
348 myEditCurrentArgument->setText("");
350 const int id = getConstructorId();
351 if ( IObjectCount() != 1 ) {
353 myFace = GEOM::GEOM_Object::_nil();
355 if (myEditCurrentArgument == Group2->LineEdit1)
356 myVectX = GEOM::GEOM_Object::_nil();
357 else if (myEditCurrentArgument == Group2->LineEdit2)
358 myVectZ = GEOM::GEOM_Object::_nil();
364 Standard_Boolean aRes = Standard_False;
365 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
367 if(!aRes || CORBA::is_nil( aSelectedObject ))
370 if(myEditCurrentArgument == Group1->LineEdit1)
371 myFace = aSelectedObject;
372 else if(myEditCurrentArgument == Group2->LineEdit1)
373 myVectX = aSelectedObject;
374 else if(myEditCurrentArgument == Group2->LineEdit2)
375 myVectZ = aSelectedObject;
377 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
381 //=================================================================================
382 // function : SetEditCurrentArgument()
384 //=================================================================================
385 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
387 QPushButton* send = (QPushButton*)sender();
389 if(send == Group1->PushButton1) {
390 myEditCurrentArgument = Group1->LineEdit1;
391 globalSelection( GEOM_PLANE );
393 else if(send == Group2->PushButton1) {
394 myEditCurrentArgument = Group2->LineEdit1;
395 globalSelection( GEOM_LINE );
397 else if(send == Group2->PushButton2) {
398 myEditCurrentArgument = Group2->LineEdit2;
399 globalSelection( GEOM_LINE );
402 myEditCurrentArgument->setFocus();
403 SelectionIntoArgument();
407 //=================================================================================
408 // function : LineEditReturnPressed()
410 //=================================================================================
411 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
413 QLineEdit* send = (QLineEdit*)sender();
414 if(send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2) {
415 myEditCurrentArgument = send;
416 GEOMBase_Skeleton::LineEditReturnPressed();
421 //=================================================================================
422 // function : ActivateThisDialog()
424 //=================================================================================
425 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
427 GEOMBase_Skeleton::ActivateThisDialog();
428 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
429 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
431 ConstructorsClicked( getConstructorId() );
435 //=================================================================================
436 // function : DeactivateActiveDialog()
437 // purpose : public slot to deactivate if active
438 //=================================================================================
439 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
441 // myGeomGUI->SetState( -1 );
442 GEOMBase_Skeleton::DeactivateActiveDialog();
445 //=======================================================================
446 // function : ClickOnCancel()
448 //=======================================================================
449 void BasicGUI_WorkingPlaneDlg::ClickOnCancel()
451 GEOMBase_Skeleton::ClickOnCancel();
454 //=================================================================================
455 // function : enterEvent()
457 //=================================================================================
458 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
460 if ( !GroupConstructors->isEnabled() )
461 ActivateThisDialog();
464 //=================================================================================
465 // function : closeEvent
467 //=================================================================================
468 void BasicGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
470 GEOMBase_Skeleton::closeEvent( e );