1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BasicGUI_WorkingPlaneDlg.cxx
24 // Author : Lucien PIGNOLONI
27 #include "BasicGUI_WorkingPlaneDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
37 #include <BRep_Tool.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
44 #include <TColStd_MapOfInteger.hxx>
45 #include <TopoDS_Shape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <qcheckbox.h>
53 #include "GEOMImpl_Types.hxx"
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 /***************************************************************/
107 QGroupBox* aReverseGroupBox = new QGroupBox(this, "aReverseGroupBox");
108 aReverseGroupBox->setTitle(tr(""));
109 aReverseGroupBox->setColumnLayout(1, Qt::Horizontal);
110 aReverseGroupBox->setInsideMargin(10);
112 myReverseCB = new QCheckBox(aReverseGroupBox, "myReverseCB");
113 myReverseCB->setText(tr("GEOM_REVERSE_PLANE"));
115 Layout1->addWidget(aReverseGroupBox, 2, 0);
118 setHelpFileName("create_wplane_page.html");
123 //=================================================================================
124 // function : ~BasicGUI_WorkingPlaneDlg()
125 // purpose : Destroys the object and frees any allocated resources
126 //=================================================================================
127 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
131 //=================================================================================
134 //=================================================================================
135 void BasicGUI_WorkingPlaneDlg::Init()
138 myEditCurrentArgument = Group1->LineEdit1;
139 myWPlane = myGeomGUI->GetWorkingPlane();
141 // myGeomGUI->SetState( 0 );
143 myFace = GEOM::GEOM_Object::_nil();
144 myVectX = GEOM::GEOM_Object::_nil();
145 myVectZ = GEOM::GEOM_Object::_nil();
149 /* Filter definition */
150 globalSelection( GEOM_PLANE );
152 /* signals and slots connections */
153 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
154 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
155 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
156 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
158 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
159 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
161 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
167 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
169 connect(Group3->GroupBox1, SIGNAL(clicked(int)), this, SLOT(GroupClicked(int)));
171 connect(myReverseCB, SIGNAL(clicked()), this, SLOT(onReverse()));
173 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
174 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
176 initName( tr( "GEOM_WPLANE" ) );
177 ConstructorsClicked(0);
180 //=================================================================================
181 // function : ConstructorsClicked()
182 // purpose : Radio button management
183 //=================================================================================
184 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
186 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
188 disconnect(aSelMgr, 0, this, 0);
190 switch (constructorId)
194 //globalSelection( GEOM_PLANE );
195 TColStd_MapOfInteger aMap;
196 aMap.Add( GEOM_PLANE );
197 aMap.Add( GEOM_MARKER );
198 globalSelection( aMap );
205 myEditCurrentArgument = Group1->LineEdit1;
206 Group1->LineEdit1->setText("");
207 myFace = GEOM::GEOM_Object::_nil();
209 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
214 //globalSelection( GEOM_LINE );
215 GEOM::GEOM_Object_var anObj;
216 localSelection( anObj, TopAbs_EDGE );
223 myEditCurrentArgument = Group2->LineEdit1;
224 Group2->LineEdit1->setText("");
225 Group2->LineEdit2->setText("");
226 myVectX = GEOM::GEOM_Object::_nil();
227 myVectZ = GEOM::GEOM_Object::_nil();
229 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
239 Group3->RadioButton1->setChecked(true);
248 //=================================================================================
249 // function : GroupClicked()
250 // purpose : Radio button management
251 //=================================================================================
252 void BasicGUI_WorkingPlaneDlg::GroupClicked(int groupId)
254 aOriginType = groupId;
258 //=================================================================================
259 // function : ClickOnOk()
261 //=================================================================================
262 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
264 if ( ClickOnApply() )
268 //=================================================================================
269 // function : ClickOnApply()
271 //=================================================================================
272 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
274 buttonApply->setFocus();
275 myGeomGUI->application()->putInfo(tr(""));
277 if (updateWPlane(false)){
278 myGeomGUI->SetWorkingPlane(myWPlane);
279 myGeomGUI->ActiveWorkingPlane();
285 //=================================================================================
286 // function : SelectionIntoArgument()
287 // purpose : Called when selection as changed or other case
288 //=================================================================================
289 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
291 myEditCurrentArgument->setText("");
294 const int id = getConstructorId();
295 if (IObjectCount() != 1) {
297 myFace = GEOM::GEOM_Object::_nil();
299 if (myEditCurrentArgument == Group2->LineEdit1)
300 myVectX = GEOM::GEOM_Object::_nil();
301 else if (myEditCurrentArgument == Group2->LineEdit2)
302 myVectZ = GEOM::GEOM_Object::_nil();
308 Standard_Boolean aRes = Standard_False;
309 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
311 if (!aRes || CORBA::is_nil(aSelectedObject))
314 aName = GEOMBase::GetName(aSelectedObject);
316 if (myEditCurrentArgument == Group1->LineEdit1)
317 myFace = aSelectedObject;
318 else if (myEditCurrentArgument == Group2->LineEdit1 || myEditCurrentArgument == Group2->LineEdit2)
320 if ( aRes && !aSelectedObject->_is_nil() )
323 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
325 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
326 TColStd_IndexedMapOfInteger aMap;
327 aSelMgr->GetIndexes( firstIObject(), aMap );
328 if ( aMap.Extent() == 1 )
330 int anIndex = aMap( 1 );
331 aName = aName + ":edge_" + QString::number( anIndex );
333 GEOM::GEOM_IShapesOperations_var aShapesOp =
334 getGeomEngine()->GetIShapesOperations( getStudyId() );
335 if(myEditCurrentArgument == Group2->LineEdit1)
336 myVectX = aShapesOp->GetSubShape(aSelectedObject, anIndex);
338 myVectZ = aShapesOp->GetSubShape(aSelectedObject, anIndex);
341 if (myEditCurrentArgument == Group2->LineEdit1)
342 myVectX = aSelectedObject;
344 myVectZ = aSelectedObject;
346 aSelMgr->clearSelected();
351 myEditCurrentArgument->setText( aName );
356 //=================================================================================
357 // function : SetEditCurrentArgument()
359 //=================================================================================
360 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
362 QPushButton* send = (QPushButton*)sender();
364 if (send == Group1->PushButton1) {
365 myEditCurrentArgument = Group1->LineEdit1;
366 globalSelection( GEOM_PLANE );
368 else if (send == Group2->PushButton1) {
369 myEditCurrentArgument = Group2->LineEdit1;
370 GEOM::GEOM_Object_var anObj;
371 localSelection( anObj, TopAbs_EDGE );
373 else if (send == Group2->PushButton2) {
374 myEditCurrentArgument = Group2->LineEdit2;
375 GEOM::GEOM_Object_var anObj;
376 localSelection( anObj, TopAbs_EDGE );
379 myEditCurrentArgument->setFocus();
380 SelectionIntoArgument();
383 //=================================================================================
384 // function : LineEditReturnPressed()
386 //=================================================================================
387 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
389 QLineEdit* send = (QLineEdit*)sender();
390 if(send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2) {
391 myEditCurrentArgument = send;
392 GEOMBase_Skeleton::LineEditReturnPressed();
396 //=================================================================================
397 // function : onReverse()
399 //=================================================================================
400 void BasicGUI_WorkingPlaneDlg::onReverse()
405 //=================================================================================
406 // function : ActivateThisDialog()
408 //=================================================================================
409 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
411 GEOMBase_Skeleton::ActivateThisDialog();
412 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
413 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
415 ConstructorsClicked( getConstructorId() );
418 //=================================================================================
419 // function : DeactivateActiveDialog()
420 // purpose : public slot to deactivate if active
421 //=================================================================================
422 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
424 GEOMBase_Skeleton::DeactivateActiveDialog();
427 //=================================================================================
428 // function : ClickOnCancel()
430 //=================================================================================
431 void BasicGUI_WorkingPlaneDlg::ClickOnCancel()
433 GEOMBase_Skeleton::ClickOnCancel();
436 //=================================================================================
437 // function : enterEvent()
439 //=================================================================================
440 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
442 if ( !GroupConstructors->isEnabled() )
443 ActivateThisDialog();
446 //=================================================================================
447 // function : closeEvent
449 //=================================================================================
450 void BasicGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
452 GEOMBase_Skeleton::closeEvent( e );
455 //=================================================================================
456 // function : updateWPlane
458 //=================================================================================
459 bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview )
463 const int id = getConstructorId();
465 if (id == 0) { // by planar face selection
466 if (CORBA::is_nil(myFace)) {
468 showError( "Face has to be selected" );
472 // PAL12781: set center of WPL to face's center of mass
473 // like it is done for LCS creation
474 CORBA::Double Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz;
475 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
478 GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
479 myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId());
480 aMeasureOp->GetPosition(myFace, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
482 if (aMeasureOp->IsDone()) {
483 gp_Pnt aPnt (Ox,Oy,Oz);
484 gp_Dir aDirN (Zx,Zy,Zz);
485 gp_Dir aDirX (Xx,Xy,Xz);
486 myWPlane = gp_Ax3(aPnt, aDirN, aDirX);
489 showError( "Wrong shape selected (has to be a planar face)" );
493 else if (id == 1) { // by two vectors (Ox & Oz)
494 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
496 showError( "Two vectors have to be selected" );
500 TopoDS_Edge aVectX, aVectZ;
501 TopoDS_Vertex VX1, VX2, VZ1, VZ2;
504 if (!GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) ||
505 !GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE )) {
507 showError( "Wrong shape selected (two vectors(edges) have to be selected)" );
511 TopExp::Vertices(aVectX, VX1, VX2, Standard_True);
512 TopExp::Vertices(aVectZ, VZ1, VZ2, Standard_True);
514 if (VX1.IsNull() || VX2.IsNull()) {
516 showError( "Bad OX vector" );
519 if (VZ1.IsNull() || VZ2.IsNull()) {
521 showError( "Bad OZ vector" );
525 aVX = gp_Vec(BRep_Tool::Pnt(VX1), BRep_Tool::Pnt(VX2));
526 aVZ = gp_Vec(BRep_Tool::Pnt(VZ1), BRep_Tool::Pnt(VZ2));
528 if (aVX.Magnitude() < Precision::Confusion()) {
530 showError( "Bad OX vector" );
533 if (aVZ.Magnitude() < Precision::Confusion()) {
535 showError( "Bad OZ vector" );
539 gp_Dir aDirX = gp_Dir(aVX.X(), aVX.Y(), aVX.Z());
540 gp_Dir aDirZ = gp_Dir(aVZ.X(), aVZ.Y(), aVZ.Z());
542 if (aDirX.IsParallel(aDirZ, Precision::Angular())) {
544 showError( "Parallel vectors selected" );
548 myWPlane = gp_Ax3(BRep_Tool::Pnt(VX1), aDirZ, aDirX);
550 else if (id == 2) { // by selection from standard (OXY or OYZ, or OZX)
553 if (aOriginType == 1) anAx2 = gp::XOY();
554 else if (aOriginType == 2) anAx2 = gp::YOZ();
555 else if (aOriginType == 0) anAx2 = gp::ZOX();
557 myWPlane = gp_Ax3(anAx2);
563 if (myReverseCB->isChecked())
571 GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations(getStudyId());
572 GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker
573 (myWPlane.Location().X() , myWPlane.Location().Y() , myWPlane.Location().Z(),
574 myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(),
575 myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z());
576 displayPreview(anObj);