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"
38 #include <BRep_Tool.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Vertex.hxx>
45 #include <TColStd_MapOfInteger.hxx>
48 #include <qcheckbox.h>
51 #include "GEOMImpl_Types.hxx"
55 //=================================================================================
56 // class : BasicGUI_WorkingPlaneDlg()
57 // purpose : Constructs a BasicGUI_WorkingPlaneDlg which is a child of 'parent', with the
58 // name 'name' and widget flags set to 'f'.
59 // The dialog will by default be modeless, unless you set 'modal' to
60 // TRUE to construct a modal dialog.
61 //=================================================================================
62 BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
63 const char* name, bool modal, WFlags fl)
64 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
65 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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 /***************************************************************/
105 QGroupBox* aReverseGroupBox = new QGroupBox(this, "aReverseGroupBox");
106 aReverseGroupBox->setTitle(tr(""));
107 aReverseGroupBox->setColumnLayout(1, Qt::Horizontal);
108 aReverseGroupBox->setInsideMargin(10);
110 myReverseCB = new QCheckBox(aReverseGroupBox, "myReverseCB");
111 myReverseCB->setText(tr("GEOM_REVERSE_PLANE"));
113 Layout1->addWidget(aReverseGroupBox, 2, 0);
116 setHelpFileName("working_plane.htm");
121 //=================================================================================
122 // function : ~BasicGUI_WorkingPlaneDlg()
123 // purpose : Destroys the object and frees any allocated resources
124 //=================================================================================
125 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
129 //=================================================================================
132 //=================================================================================
133 void BasicGUI_WorkingPlaneDlg::Init()
136 myEditCurrentArgument = Group1->LineEdit1;
137 myWPlane = myGeomGUI->GetWorkingPlane();
139 // myGeomGUI->SetState( 0 );
141 myFace = GEOM::GEOM_Object::_nil();
142 myVectX = GEOM::GEOM_Object::_nil();
143 myVectZ = GEOM::GEOM_Object::_nil();
147 /* Filter definition */
148 globalSelection( GEOM_PLANE );
150 /* signals and slots connections */
151 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
152 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
153 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
154 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
156 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
157 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
159 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167 connect(Group3->GroupBox1, SIGNAL(clicked(int)), this, SLOT(GroupClicked(int)));
169 connect(myReverseCB, SIGNAL(clicked()), this, SLOT(onReverse()));
171 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
172 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
174 initName( tr( "GEOM_WPLANE" ) );
175 ConstructorsClicked(0);
178 //=================================================================================
179 // function : ConstructorsClicked()
180 // purpose : Radio button management
181 //=================================================================================
182 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
184 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
186 disconnect(aSelMgr, 0, this, 0);
188 switch (constructorId)
192 //globalSelection( GEOM_PLANE );
193 TColStd_MapOfInteger aMap;
194 aMap.Add( GEOM_PLANE );
195 aMap.Add( GEOM_MARKER );
196 globalSelection( aMap );
203 myEditCurrentArgument = Group1->LineEdit1;
204 Group1->LineEdit1->setText("");
205 myFace = GEOM::GEOM_Object::_nil();
207 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
212 globalSelection( GEOM_LINE );
219 myEditCurrentArgument = Group2->LineEdit1;
220 Group2->LineEdit1->setText("");
221 Group2->LineEdit2->setText("");
222 myVectX = GEOM::GEOM_Object::_nil();
223 myVectZ = GEOM::GEOM_Object::_nil();
225 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
235 Group3->RadioButton1->setChecked(true);
244 //=================================================================================
245 // function : GroupClicked()
246 // purpose : Radio button management
247 //=================================================================================
248 void BasicGUI_WorkingPlaneDlg::GroupClicked(int groupId)
250 aOriginType = groupId;
254 //=================================================================================
255 // function : ClickOnOk()
257 //=================================================================================
258 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
260 if ( ClickOnApply() )
264 //=================================================================================
265 // function : ClickOnApply()
267 //=================================================================================
268 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
270 buttonApply->setFocus();
271 myGeomGUI->application()->putInfo(tr(""));
273 if (updateWPlane(false)){
274 myGeomGUI->SetWorkingPlane(myWPlane);
275 myGeomGUI->ActiveWorkingPlane();
281 //=================================================================================
282 // function : SelectionIntoArgument()
283 // purpose : Called when selection as changed or other case
284 //=================================================================================
285 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
287 myEditCurrentArgument->setText("");
289 const int id = getConstructorId();
290 if ( IObjectCount() != 1 ) {
292 myFace = GEOM::GEOM_Object::_nil();
294 if (myEditCurrentArgument == Group2->LineEdit1)
295 myVectX = GEOM::GEOM_Object::_nil();
296 else if (myEditCurrentArgument == Group2->LineEdit2)
297 myVectZ = GEOM::GEOM_Object::_nil();
303 Standard_Boolean aRes = Standard_False;
304 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
306 if(!aRes || CORBA::is_nil( aSelectedObject ))
309 if(myEditCurrentArgument == Group1->LineEdit1)
310 myFace = aSelectedObject;
311 else if(myEditCurrentArgument == Group2->LineEdit1)
312 myVectX = aSelectedObject;
313 else if(myEditCurrentArgument == Group2->LineEdit2)
314 myVectZ = aSelectedObject;
316 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
322 //=================================================================================
323 // function : SetEditCurrentArgument()
325 //=================================================================================
326 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
328 QPushButton* send = (QPushButton*)sender();
330 if(send == Group1->PushButton1) {
331 myEditCurrentArgument = Group1->LineEdit1;
332 globalSelection( GEOM_PLANE );
334 else if(send == Group2->PushButton1) {
335 myEditCurrentArgument = Group2->LineEdit1;
336 globalSelection( GEOM_LINE );
338 else if(send == Group2->PushButton2) {
339 myEditCurrentArgument = Group2->LineEdit2;
340 globalSelection( GEOM_LINE );
343 myEditCurrentArgument->setFocus();
344 SelectionIntoArgument();
348 //=================================================================================
349 // function : LineEditReturnPressed()
351 //=================================================================================
352 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
354 QLineEdit* send = (QLineEdit*)sender();
355 if(send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2) {
356 myEditCurrentArgument = send;
357 GEOMBase_Skeleton::LineEditReturnPressed();
362 //=================================================================================
363 // function : onReverse()
365 //=================================================================================
366 void BasicGUI_WorkingPlaneDlg::onReverse()
372 //=================================================================================
373 // function : ActivateThisDialog()
375 //=================================================================================
376 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
378 GEOMBase_Skeleton::ActivateThisDialog();
379 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
380 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
382 ConstructorsClicked( getConstructorId() );
386 //=================================================================================
387 // function : DeactivateActiveDialog()
388 // purpose : public slot to deactivate if active
389 //=================================================================================
390 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
392 // myGeomGUI->SetState( -1 );
393 GEOMBase_Skeleton::DeactivateActiveDialog();
396 //=======================================================================
397 // function : ClickOnCancel()
399 //=======================================================================
400 void BasicGUI_WorkingPlaneDlg::ClickOnCancel()
402 GEOMBase_Skeleton::ClickOnCancel();
405 //=================================================================================
406 // function : enterEvent()
408 //=================================================================================
409 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
411 if ( !GroupConstructors->isEnabled() )
412 ActivateThisDialog();
415 //=================================================================================
416 // function : closeEvent
418 //=================================================================================
419 void BasicGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
421 GEOMBase_Skeleton::closeEvent( e );
425 //=================================================================================
426 // function : updateWPlane
428 //=================================================================================
429 bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview )
433 const int id = getConstructorId();
435 if (id == 0) { // by planar face selection
436 if (CORBA::is_nil(myFace)) {
438 showError( "Face has to be selected" );
442 // PAL12781: set center of WPL to face's center of mass
443 // like it is done for LCS creation
444 CORBA::Double Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz;
445 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
448 GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
449 myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId());
450 aMeasureOp->GetPosition(myFace, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
452 if (aMeasureOp->IsDone()) {
453 gp_Pnt aPnt (Ox,Oy,Oz);
454 gp_Dir aDirN (Zx,Zy,Zz);
455 gp_Dir aDirX (Xx,Xy,Xz);
456 myWPlane = gp_Ax3(aPnt, aDirN, aDirX);
459 showError( "Wrong shape selected (has to be a planar face)" );
463 } else if (id == 1) { // by two vectors (Ox & Oz)
464 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
466 showError( "Two vectors have to be selected" );
470 TopoDS_Edge aVectX, aVectZ;
471 TopoDS_Vertex VX1, VX2, VZ1, VZ2;
474 if (!GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) ||
475 !GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE )) {
477 showError( "Wrong shape selected (two vectors(edges) have to be selected)" );
481 TopExp::Vertices(aVectX, VX1, VX2, Standard_True);
482 TopExp::Vertices(aVectZ, VZ1, VZ2, Standard_True);
484 if (VX1.IsNull() || VX2.IsNull()) {
486 showError( "Bad OX vector" );
489 if (VZ1.IsNull() || VZ2.IsNull()) {
491 showError( "Bad OZ vector" );
495 aVX = gp_Vec(BRep_Tool::Pnt(VX1), BRep_Tool::Pnt(VX2));
496 aVZ = gp_Vec(BRep_Tool::Pnt(VZ1), BRep_Tool::Pnt(VZ2));
498 if (aVX.Magnitude() < Precision::Confusion()) {
500 showError( "Bad OX vector" );
503 if (aVZ.Magnitude() < Precision::Confusion()) {
505 showError( "Bad OZ vector" );
509 gp_Dir aDirX = gp_Dir(aVX.X(), aVX.Y(), aVX.Z());
510 gp_Dir aDirZ = gp_Dir(aVZ.X(), aVZ.Y(), aVZ.Z());
512 if (aDirX.IsParallel(aDirZ, Precision::Angular())) {
514 showError( "Parallel vectors selected" );
518 myWPlane = gp_Ax3(BRep_Tool::Pnt(VX1), aDirZ, aDirX);
520 } else if (id == 2) { // by selection from standard (OXY or OYZ, or OZX)
523 if (aOriginType == 1) anAx2 = gp::XOY();
524 else if (aOriginType == 2) anAx2 = gp::YOZ();
525 else if (aOriginType == 0) anAx2 = gp::ZOX();
527 myWPlane = gp_Ax3(anAx2);
533 if (myReverseCB->isChecked())
541 GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() );
542 GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(),
543 myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(),
544 myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() );
545 displayPreview(anObj);