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"
30 #include "GeometryGUI.h"
33 #include "SUIT_ResourceMgr.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "LightApp_SelectionMgr.h"
39 #include <BRep_Tool.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Vertex.hxx>
45 #include <TColStd_MapOfInteger.hxx>
50 #include "GEOMImpl_Types.hxx"
54 //=================================================================================
55 // class : BasicGUI_WorkingPlaneDlg()
56 // purpose : Constructs a BasicGUI_WorkingPlaneDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
62 const char* name, bool modal, Qt::WindowFlags fl)
63 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
65 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
66 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_FACE")));
67 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_VECTOR")));
68 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_ORIGIN")));
70 setWindowTitle(tr("GEOM_WPLANE_TITLE"));
72 /***************************************************************/
73 GroupConstructors->setTitle(tr("GEOM_WPLANE"));
74 RadioButton1->setIcon(image1);
75 RadioButton2->setIcon(image2);
76 RadioButton3->setIcon(image3);
78 Group1 = new Ui::DlgRef_1Sel_QTD();
79 QWidget* aGroup1Widget = new QWidget(this);
80 Group1->setupUi(aGroup1Widget);
81 aGroup1Widget->setObjectName("Group1");
83 Group1->GroupBox1->setTitle(tr("GEOM_WPLANE_FACE"));
84 Group1->TextLabel1->setText(tr("GEOM_SELECTION"));
85 Group1->PushButton1->setIcon(image0);
86 Group1->LineEdit1->setReadOnly( true );
88 Group2 = new Ui::DlgRef_2Sel_QTD();
89 QWidget* aGroup2Widget = new QWidget(this);
90 Group2->setupUi(aGroup2Widget);
91 aGroup2Widget->setObjectName("Group2");
93 Group2->GroupBox1->setTitle(tr("GEOM_WPLANE_VECTOR"));
94 Group2->TextLabel1->setText(tr("GEOM_WPLANE_VX"));
95 Group2->TextLabel2->setText(tr("GEOM_WPLANE_VZ"));
96 Group2->PushButton1->setIcon(image0);
97 Group2->PushButton2->setIcon(image0);
98 Group2->LineEdit1->setReadOnly( true );
99 Group2->LineEdit2->setReadOnly( true );
101 Group3 = new Ui::DlgRef_3Check_QTD();
102 QWidget* aGroup3Widget = new QWidget(this);
103 Group3->setupUi(aGroup3Widget);
104 aGroup3Widget->setObjectName("Group3");
106 Group3->GroupBox1->setTitle(tr("GEOM_WPLANE_ORIGIN"));
107 Group3->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
108 Group3->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
109 Group3->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
111 gridLayout1->addWidget(aGroup1Widget, 1, 0);
112 gridLayout1->addWidget(aGroup2Widget, 1, 0);
113 gridLayout1->addWidget(aGroup3Widget, 1, 0);
114 /***************************************************************/
115 QFrame* aReverseGroupBox = new QFrame(this);
116 aReverseGroupBox->setObjectName("aReverseGroupBox");
117 aReverseGroupBox->setContentsMargins(10, 10, 10, 10);
118 QHBoxLayout* aReverseGroupBoxLayout = new QHBoxLayout( aReverseGroupBox );
120 myReverseCB = new QCheckBox(aReverseGroupBox);
121 myReverseCB->setObjectName("myReverseCB");
122 myReverseCB->setText(tr("GEOM_REVERSE_PLANE"));
123 aReverseGroupBoxLayout->addWidget(myReverseCB);
125 gridLayout1->addWidget(aReverseGroupBox, 2, 0);
128 setHelpFileName("working_plane.htm");
133 //=================================================================================
134 // function : ~BasicGUI_WorkingPlaneDlg()
135 // purpose : Destroys the object and frees any allocated resources
136 //=================================================================================
137 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
141 //=================================================================================
144 //=================================================================================
145 void BasicGUI_WorkingPlaneDlg::Init()
148 myEditCurrentArgument = Group1->LineEdit1;
149 myWPlane = myGeomGUI->GetWorkingPlane();
151 // myGeomGUI->SetState( 0 );
153 myFace = GEOM::GEOM_Object::_nil();
154 myVectX = GEOM::GEOM_Object::_nil();
155 myVectZ = GEOM::GEOM_Object::_nil();
159 /* Filter definition */
160 globalSelection( GEOM_PLANE );
162 /* signals and slots connections */
163 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
164 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
165 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
166 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
168 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
169 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
171 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
172 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
174 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
175 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
176 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
177 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
179 connect(Group3->GroupBox1, SIGNAL(clicked(int)), this, SLOT(GroupClicked(int)));
181 connect(myReverseCB, SIGNAL(clicked()), this, SLOT(onReverse()));
183 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
184 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
186 initName( tr( "GEOM_WPLANE" ).toStdString().c_str() );
187 ConstructorsClicked(0);
190 //=================================================================================
191 // function : ConstructorsClicked()
192 // purpose : Radio button management
193 //=================================================================================
194 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
196 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
198 disconnect(aSelMgr, 0, this, 0);
200 switch (constructorId)
204 //globalSelection( GEOM_PLANE );
205 TColStd_MapOfInteger aMap;
206 aMap.Add( GEOM_PLANE );
207 aMap.Add( GEOM_MARKER );
208 globalSelection( aMap );
210 ::qobject_cast<QWidget*>( Group2->gridLayout->parent() )->hide();
211 ::qobject_cast<QWidget*>( Group3->gridLayout->parent() )->hide();
213 ::qobject_cast<QWidget*>( Group1->gridLayout->parent() )->show();
215 myEditCurrentArgument = Group1->LineEdit1;
216 Group1->LineEdit1->setText("");
217 myFace = GEOM::GEOM_Object::_nil();
219 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
224 globalSelection( GEOM_LINE );
226 ::qobject_cast<QWidget*>( Group1->gridLayout->parent() )->hide();
227 ::qobject_cast<QWidget*>( Group3->gridLayout->parent() )->hide();
229 ::qobject_cast<QWidget*>( Group2->gridLayout->parent() )->show();
231 myEditCurrentArgument = Group2->LineEdit1;
232 Group2->LineEdit1->setText("");
233 Group2->LineEdit2->setText("");
234 myVectX = GEOM::GEOM_Object::_nil();
235 myVectZ = GEOM::GEOM_Object::_nil();
237 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
242 ::qobject_cast<QWidget*>( Group1->gridLayout->parent() )->hide();
243 ::qobject_cast<QWidget*>( Group2->gridLayout->parent() )->hide();
245 ::qobject_cast<QWidget*>( Group3->gridLayout->parent() )->show();
247 Group3->RadioButton1->setChecked(true);
256 //=================================================================================
257 // function : GroupClicked()
258 // purpose : Radio button management
259 //=================================================================================
260 void BasicGUI_WorkingPlaneDlg::GroupClicked(int groupId)
262 aOriginType = groupId;
266 //=================================================================================
267 // function : ClickOnOk()
269 //=================================================================================
270 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
272 if ( ClickOnApply() )
276 //=================================================================================
277 // function : ClickOnApply()
279 //=================================================================================
280 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
282 buttonApply->setFocus();
283 myGeomGUI->application()->putInfo(tr(""));
285 if (updateWPlane(false)){
286 myGeomGUI->SetWorkingPlane(myWPlane);
287 myGeomGUI->ActiveWorkingPlane();
293 //=================================================================================
294 // function : SelectionIntoArgument()
295 // purpose : Called when selection as changed or other case
296 //=================================================================================
297 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
299 myEditCurrentArgument->setText("");
301 const int id = getConstructorId();
302 if ( IObjectCount() != 1 ) {
304 myFace = GEOM::GEOM_Object::_nil();
306 if (myEditCurrentArgument == Group2->LineEdit1)
307 myVectX = GEOM::GEOM_Object::_nil();
308 else if (myEditCurrentArgument == Group2->LineEdit2)
309 myVectZ = GEOM::GEOM_Object::_nil();
315 Standard_Boolean aRes = Standard_False;
316 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
318 if(!aRes || CORBA::is_nil( aSelectedObject ))
321 if(myEditCurrentArgument == Group1->LineEdit1)
322 myFace = aSelectedObject;
323 else if(myEditCurrentArgument == Group2->LineEdit1)
324 myVectX = aSelectedObject;
325 else if(myEditCurrentArgument == Group2->LineEdit2)
326 myVectZ = aSelectedObject;
328 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
334 //=================================================================================
335 // function : SetEditCurrentArgument()
337 //=================================================================================
338 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
340 QPushButton* send = (QPushButton*)sender();
342 if(send == Group1->PushButton1) {
343 myEditCurrentArgument = Group1->LineEdit1;
344 globalSelection( GEOM_PLANE );
346 else if(send == Group2->PushButton1) {
347 myEditCurrentArgument = Group2->LineEdit1;
348 globalSelection( GEOM_LINE );
350 else if(send == Group2->PushButton2) {
351 myEditCurrentArgument = Group2->LineEdit2;
352 globalSelection( GEOM_LINE );
355 myEditCurrentArgument->setFocus();
356 SelectionIntoArgument();
360 //=================================================================================
361 // function : LineEditReturnPressed()
363 //=================================================================================
364 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
366 QLineEdit* send = (QLineEdit*)sender();
367 if(send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2) {
368 myEditCurrentArgument = send;
369 GEOMBase_Skeleton::LineEditReturnPressed();
374 //=================================================================================
375 // function : onReverse()
377 //=================================================================================
378 void BasicGUI_WorkingPlaneDlg::onReverse()
384 //=================================================================================
385 // function : ActivateThisDialog()
387 //=================================================================================
388 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
390 GEOMBase_Skeleton::ActivateThisDialog();
391 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
392 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
394 ConstructorsClicked( getConstructorId() );
398 //=================================================================================
399 // function : DeactivateActiveDialog()
400 // purpose : public slot to deactivate if active
401 //=================================================================================
402 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
404 // myGeomGUI->SetState( -1 );
405 GEOMBase_Skeleton::DeactivateActiveDialog();
408 //=======================================================================
409 // function : ClickOnCancel()
411 //=======================================================================
412 void BasicGUI_WorkingPlaneDlg::ClickOnCancel()
414 GEOMBase_Skeleton::ClickOnCancel();
417 //=================================================================================
418 // function : enterEvent()
420 //=================================================================================
421 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
423 if ( !GroupConstructors->isEnabled() )
424 ActivateThisDialog();
427 //=================================================================================
428 // function : closeEvent
430 //=================================================================================
431 void BasicGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
433 GEOMBase_Skeleton::closeEvent( e );
437 //=================================================================================
438 // function : updateWPlane
440 //=================================================================================
441 bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview )
445 const int id = getConstructorId();
447 if (id == 0) { // by planar face selection
448 if (CORBA::is_nil(myFace)) {
450 showError( "Face has to be selected" );
454 // PAL12781: set center of WPL to face's center of mass
455 // like it is done for LCS creation
456 CORBA::Double Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz;
457 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
460 GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
461 myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId());
462 aMeasureOp->GetPosition(myFace, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
464 if (aMeasureOp->IsDone()) {
465 gp_Pnt aPnt (Ox,Oy,Oz);
466 gp_Dir aDirN (Zx,Zy,Zz);
467 gp_Dir aDirX (Xx,Xy,Xz);
468 myWPlane = gp_Ax3(aPnt, aDirN, aDirX);
471 showError( "Wrong shape selected (has to be a planar face)" );
475 } else if (id == 1) { // by two vectors (Ox & Oz)
476 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
478 showError( "Two vectors have to be selected" );
482 TopoDS_Edge aVectX, aVectZ;
483 TopoDS_Vertex VX1, VX2, VZ1, VZ2;
486 if (!GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) ||
487 !GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE )) {
489 showError( "Wrong shape selected (two vectors(edges) have to be selected)" );
493 TopExp::Vertices(aVectX, VX1, VX2, Standard_True);
494 TopExp::Vertices(aVectZ, VZ1, VZ2, Standard_True);
496 if (VX1.IsNull() || VX2.IsNull()) {
498 showError( "Bad OX vector" );
501 if (VZ1.IsNull() || VZ2.IsNull()) {
503 showError( "Bad OZ vector" );
507 aVX = gp_Vec(BRep_Tool::Pnt(VX1), BRep_Tool::Pnt(VX2));
508 aVZ = gp_Vec(BRep_Tool::Pnt(VZ1), BRep_Tool::Pnt(VZ2));
510 if (aVX.Magnitude() < Precision::Confusion()) {
512 showError( "Bad OX vector" );
515 if (aVZ.Magnitude() < Precision::Confusion()) {
517 showError( "Bad OZ vector" );
521 gp_Dir aDirX = gp_Dir(aVX.X(), aVX.Y(), aVX.Z());
522 gp_Dir aDirZ = gp_Dir(aVZ.X(), aVZ.Y(), aVZ.Z());
524 if (aDirX.IsParallel(aDirZ, Precision::Angular())) {
526 showError( "Parallel vectors selected" );
530 myWPlane = gp_Ax3(BRep_Tool::Pnt(VX1), aDirZ, aDirX);
532 } else if (id == 2) { // by selection from standard (OXY or OYZ, or OZX)
535 if (aOriginType == 1) anAx2 = gp::XOY();
536 else if (aOriginType == 2) anAx2 = gp::YOZ();
537 else if (aOriginType == 0) anAx2 = gp::ZOX();
539 myWPlane = gp_Ax3(anAx2);
545 if (myReverseCB->isChecked())
553 GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() );
554 GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(),
555 myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(),
556 myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() );
557 displayPreview(anObj);