geom/src/BasicGUI/BasicGUI_WorkingPlaneDlg.cxx

595 lines
20 KiB
C++
Raw Normal View History

2011-06-06 13:23:11 +06:00
// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
2004-01-07 20:46:21 +05:00
//
2011-06-06 13:23:11 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2004-12-01 15:39:14 +05:00
//
2011-06-06 13:23:11 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
2004-12-01 15:39:14 +05:00
//
2011-06-06 13:23:11 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2004-12-01 15:39:14 +05:00
//
2011-06-06 13:23:11 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2004-12-01 15:39:14 +05:00
//
2011-06-06 13:23:11 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-01-07 20:46:21 +05:00
//
2010-05-14 21:15:28 +06:00
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : BasicGUI_WorkingPlaneDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2004-01-07 20:46:21 +05:00
//
#include "BasicGUI_WorkingPlaneDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
2004-12-01 15:39:14 +05:00
// OCCT Includes
#include <BRep_Tool.hxx>
2004-12-01 15:39:14 +05:00
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp.hxx>
#include <gp_Pnt.hxx>
2004-01-07 20:46:21 +05:00
#include <gp_Dir.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TopoDS_Shape.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
2004-12-01 15:39:14 +05:00
// QT Includes
2009-02-13 17:16:39 +05:00
#include <QCheckBox>
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_Types.hxx>
2005-08-19 17:51:38 +06:00
2004-01-07 20:46:21 +05:00
//=================================================================================
// class : BasicGUI_WorkingPlaneDlg()
2004-12-01 15:39:14 +05:00
// purpose : Constructs a BasicGUI_WorkingPlaneDlg which is a child of 'parent', with the
2004-01-07 20:46:21 +05:00
// name 'name' and widget flags set to 'f'.
// The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog.
//=================================================================================
2009-02-13 17:16:39 +05:00
BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
2009-12-25 16:28:58 +05:00
bool modal, Qt::WindowFlags fl )
2009-02-13 17:16:39 +05:00
: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_WPLANE_FACE" ) ) );
QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_WPLANE_VECTOR" ) ) );
QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_WPLANE_ORIGIN" ) ) );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "GEOM_WPLANE_TITLE" ) );
2004-12-01 15:39:14 +05:00
2004-01-07 20:46:21 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WPLANE" ) );
mainFrame()->RadioButton1->setIcon( image1 );
mainFrame()->RadioButton2->setIcon( image2 );
mainFrame()->RadioButton3->setIcon( image3 );
Group1 = new DlgRef_1Sel( centralWidget() );
Group1->GroupBox1->setTitle( tr( "GEOM_WPLANE_FACE" ) );
Group1->TextLabel1->setText( tr( "GEOM_SELECTION" ) );
Group1->PushButton1->setIcon( image0 );
2004-12-01 15:39:14 +05:00
Group1->LineEdit1->setReadOnly( true );
2009-02-13 17:16:39 +05:00
Group2 = new DlgRef_2Sel( centralWidget() );
Group2->GroupBox1->setTitle( tr( "GEOM_WPLANE_VECTOR" ) );
Group2->TextLabel1->setText( tr( "GEOM_WPLANE_VX" ) );
Group2->TextLabel2->setText( tr( "GEOM_WPLANE_VZ" ) );
Group2->PushButton1->setIcon( image0 );
Group2->PushButton2->setIcon( image0 );
2004-12-01 15:39:14 +05:00
Group2->LineEdit1->setReadOnly( true );
Group2->LineEdit2->setReadOnly( true );
2009-02-13 17:16:39 +05:00
Group2->PushButton1->setDown( true );
Group2->LineEdit1->setEnabled( true );
Group2->LineEdit2->setEnabled( false );
Group3 = new DlgRef_3Check( centralWidget() );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
Group3->GroupBox1->setTitle( tr( "GEOM_WPLANE_ORIGIN" ) );
Group3->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
Group3->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
Group3->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
2004-12-01 15:39:14 +05:00
2004-01-07 20:46:21 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
QGroupBox* aReverseGroupBox = new QGroupBox( centralWidget() );
QHBoxLayout* aReverseGroupBoxLayout = new QHBoxLayout( aReverseGroupBox );
aReverseGroupBoxLayout->setMargin( 9 );
aReverseGroupBoxLayout->setSpacing( 6 );
myReverseCB = new QCheckBox( aReverseGroupBox );
myReverseCB->setText( tr( "GEOM_REVERSE_PLANE" ) );
aReverseGroupBoxLayout->addWidget( myReverseCB );
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( Group1 );
layout->addWidget( Group2 );
layout->addWidget( Group3 );
layout->addWidget( aReverseGroupBox );
setHelpFileName( "create_wplane_page.html" );
2004-01-07 20:46:21 +05:00
Init();
}
//=================================================================================
// function : ~BasicGUI_WorkingPlaneDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void BasicGUI_WorkingPlaneDlg::Init()
{
/* init variables */
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = Group1->LineEdit1;
myWPlane = myGeomGUI->GetWorkingPlane();
2004-12-01 15:39:14 +05:00
// myGeomGUI->SetState( 0 );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
myFace = GEOM::GEOM_Object::_nil();
2004-12-01 15:39:14 +05:00
myVectX = GEOM::GEOM_Object::_nil();
myVectZ = GEOM::GEOM_Object::_nil();
aOriginType = 1;
2004-01-07 20:46:21 +05:00
/* Filter definition */
2004-12-01 15:39:14 +05:00
globalSelection( GEOM_PLANE );
2004-01-07 20:46:21 +05:00
/* signals and slots connections */
2009-02-13 17:16:39 +05:00
connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( Group1->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
connect( Group1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( Group2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
connect( Group2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( Group2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
connect( Group2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( Group3->GroupBox1, SIGNAL( clicked( int ) ), this, SLOT( GroupClicked( int ) ) );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
connect( myReverseCB, SIGNAL( clicked() ), this, SLOT( onReverse() ) );
2009-02-13 17:16:39 +05:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
2009-12-25 16:28:58 +05:00
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
initName( tr( "GEOM_WPLANE" ) );
2009-02-13 17:16:39 +05:00
setConstructorId( 2 ); // simplest constructor
ConstructorsClicked( 2 );
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : ConstructorsClicked()
// purpose : Radio button management
//=================================================================================
2009-02-13 17:16:39 +05:00
void BasicGUI_WorkingPlaneDlg::ConstructorsClicked( int constructorId )
2004-12-01 15:39:14 +05:00
{
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
2009-02-13 17:16:39 +05:00
disconnect( aSelMgr, 0, this, 0 );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
switch ( constructorId ) {
case 0:
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
TColStd_MapOfInteger aMap;
aMap.Add( GEOM_PLANE );
aMap.Add( GEOM_MARKER );
globalSelection( aMap );
Group2->hide();
Group3->hide();
Group1->show();
Group1->PushButton1->setDown(true);
myEditCurrentArgument = Group1->LineEdit1;
Group1->LineEdit1->setText( "" );
myFace = GEOM::GEOM_Object::_nil();
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
break;
}
case 1:
{
globalSelection( GEOM_LINE );
Group1->hide();
Group3->hide();
Group2->show();
myEditCurrentArgument = Group2->LineEdit1;
Group2->LineEdit1->setText( "" );
Group2->LineEdit2->setText( "" );
Group2->PushButton1->setDown( true );
Group2->PushButton2->setDown( false );
Group2->LineEdit1->setEnabled( true );
Group2->LineEdit2->setEnabled( false );
myVectX = GEOM::GEOM_Object::_nil();
myVectZ = GEOM::GEOM_Object::_nil();
connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
break;
}
case 2:
{
Group1->hide();
Group2->hide();
Group3->show();
Group3->RadioButton1->setChecked( true );
aOriginType = 1;
break;
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
}
qApp->processEvents();
updateGeometry();
resize( minimumSizeHint() );
updateWPlane();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : GroupClicked()
// purpose : Radio button management
//=================================================================================
2009-02-13 17:16:39 +05:00
void BasicGUI_WorkingPlaneDlg::GroupClicked( int groupId )
2004-12-01 15:39:14 +05:00
{
aOriginType = groupId;
updateWPlane();
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void BasicGUI_WorkingPlaneDlg::ClickOnOk()
{
setIsApplyAndClose( true );
2004-12-01 15:39:14 +05:00
if ( ClickOnApply() )
ClickOnCancel();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
buttonApply()->setFocus();
myGeomGUI->application()->putInfo( "" );
if ( updateWPlane( false ) ) {
myGeomGUI->SetWorkingPlane( myWPlane );
myGeomGUI->ActiveWorkingPlane();
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
return true;
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection as changed or other case
//=================================================================================
void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
{
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText( "" );
QString aName;
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
2004-12-01 15:39:14 +05:00
const int id = getConstructorId();
2009-02-13 17:16:39 +05:00
if (aSelList.Extent() != 1) {
if ( id == 0 )
2004-12-01 15:39:14 +05:00
myFace = GEOM::GEOM_Object::_nil();
2009-02-13 17:16:39 +05:00
else if ( id == 1 ) {
if ( myEditCurrentArgument == Group2->LineEdit1 )
2004-12-01 15:39:14 +05:00
myVectX = GEOM::GEOM_Object::_nil();
2009-02-13 17:16:39 +05:00
else if ( myEditCurrentArgument == Group2->LineEdit2 )
2004-12-01 15:39:14 +05:00
myVectZ = GEOM::GEOM_Object::_nil();
}
2004-01-07 20:46:21 +05:00
return;
}
2004-12-01 15:39:14 +05:00
// nbSel == 1
Standard_Boolean aRes = Standard_False;
2009-02-13 17:16:39 +05:00
GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
if ( !aRes || CORBA::is_nil( aSelectedObject ) )
2004-01-07 20:46:21 +05:00
return;
aName = GEOMBase::GetName(aSelectedObject);
2009-02-13 17:16:39 +05:00
if ( myEditCurrentArgument == Group1->LineEdit1 )
2004-12-01 15:39:14 +05:00
myFace = aSelectedObject;
2009-02-13 17:16:39 +05:00
else if ( myEditCurrentArgument == Group2->LineEdit1 ||
2009-12-25 16:28:58 +05:00
myEditCurrentArgument == Group2->LineEdit2 ) {
2009-02-13 17:16:39 +05:00
if ( aRes && !aSelectedObject->_is_nil() ) {
TopoDS_Shape aShape;
2009-02-13 17:16:39 +05:00
if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
TColStd_IndexedMapOfInteger aMap;
2009-02-13 17:16:39 +05:00
aSelMgr->GetIndexes(aSelList.First(), aMap);
if ( aMap.Extent() == 1 ) {
int anIndex = aMap( 1 );
aName = aName + ":edge_" + QString::number( anIndex );
2009-12-25 16:28:58 +05:00
GEOM::GEOM_IShapesOperations_var aShapesOp =
getGeomEngine()->GetIShapesOperations( getStudyId() );
if ( myEditCurrentArgument == Group2->LineEdit1 )
myVectX = aShapesOp->GetSubShape( aSelectedObject, anIndex );
else
myVectZ = aShapesOp->GetSubShape( aSelectedObject, anIndex );
}
else {
2009-12-25 16:28:58 +05:00
if ( aShape.ShapeType() != TopAbs_EDGE ) {
aSelectedObject = GEOM::GEOM_Object::_nil();
aName = "";
}
}
aSelMgr->clearSelected();
}
}
}
2004-01-07 20:46:21 +05:00
myEditCurrentArgument->setText( aName );
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
if ( myEditCurrentArgument == Group2->LineEdit1 ) {
myVectX = aSelectedObject;
if ( !myVectX->_is_nil() && myVectZ->_is_nil() )
Group2->PushButton2->click();
}
else {
myVectZ = aSelectedObject;
if ( !myVectZ->_is_nil() && myVectX->_is_nil() )
Group2->PushButton1->click();
}
updateWPlane();
}
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
{
2004-12-01 15:39:14 +05:00
QPushButton* send = (QPushButton*)sender();
2009-02-13 17:16:39 +05:00
if ( send == Group1->PushButton1 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = Group1->LineEdit1;
globalSelection( GEOM_PLANE );
}
2009-02-13 17:16:39 +05:00
else if ( send == Group2->PushButton1 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = Group2->LineEdit1;
GEOM::GEOM_Object_var anObj;
2009-02-13 17:16:39 +05:00
// localSelection( anObj, TopAbs_EDGE );
globalSelection( GEOM_LINE );
Group2->PushButton2->setDown( false );
Group2->LineEdit1->setEnabled( true );
Group2->LineEdit2->setEnabled( false );
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
else if ( send == Group2->PushButton2 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = Group2->LineEdit2;
GEOM::GEOM_Object_var anObj;
2009-02-13 17:16:39 +05:00
// localSelection( anObj, TopAbs_EDGE );
globalSelection( GEOM_LINE );
Group2->PushButton1->setDown( false );
Group2->LineEdit1->setEnabled( false );
Group2->LineEdit2->setEnabled( true );
2004-12-01 15:39:14 +05:00
}
myEditCurrentArgument->setFocus();
2009-02-13 17:16:39 +05:00
// SelectionIntoArgument();
send->setDown(true);
displayPreview(true);
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
{
2004-12-01 15:39:14 +05:00
QLineEdit* send = (QLineEdit*)sender();
2009-02-13 17:16:39 +05:00
if ( send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = send;
GEOMBase_Skeleton::LineEditReturnPressed();
}
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : onReverse()
// purpose :
//=================================================================================
void BasicGUI_WorkingPlaneDlg::onReverse()
{
updateWPlane();
}
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
2004-01-07 20:46:21 +05:00
{
GEOMBase_Skeleton::ActivateThisDialog();
2009-02-13 17:16:39 +05:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ) )->selectionMgr(),
2009-12-25 16:28:58 +05:00
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
2004-12-01 15:39:14 +05:00
ConstructorsClicked( getConstructorId() );
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : DeactivateActiveDialog()
// purpose : public slot to deactivate if active
//=================================================================================
void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
{
2009-02-13 17:16:39 +05:00
// myGeomGUI->SetState( -1 );
2004-12-01 15:39:14 +05:00
GEOMBase_Skeleton::DeactivateActiveDialog();
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
void BasicGUI_WorkingPlaneDlg::enterEvent( QEvent* )
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
if ( !mainFrame()->GroupConstructors->isEnabled() )
2004-12-01 15:39:14 +05:00
ActivateThisDialog();
}
//=================================================================================
// function : updateWPlane
// purpose :
//=================================================================================
bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview )
{
erasePreview();
2009-02-13 17:16:39 +05:00
const int id = getConstructorId();
2009-02-13 17:16:39 +05:00
if ( id == 0 ) { // by planar face selection
if ( CORBA::is_nil( myFace ) ) {
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Face has to be selected" );
return false;
}
// PAL12781: set center of WPL to face's center of mass
// like it is done for LCS creation
2009-02-13 17:16:39 +05:00
CORBA::Double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
Zz = Xx = 1.;
GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
2009-02-13 17:16:39 +05:00
myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
aMeasureOp->GetPosition( myFace, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
if ( aMeasureOp->IsDone() ) {
gp_Pnt aPnt ( Ox, Oy, Oz );
gp_Dir aDirN ( Zx, Zy, Zz );
gp_Dir aDirX ( Xx, Xy, Xz );
myWPlane = gp_Ax3( aPnt, aDirN, aDirX );
}
else {
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Wrong shape selected (has to be a planar face)" );
return false;
}
}
2009-02-13 17:16:39 +05:00
else if ( id == 1 ) { // by two vectors (Ox & Oz)
if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
2009-02-13 17:16:39 +05:00
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Two vectors have to be selected" );
return false;
}
TopoDS_Edge aVectX, aVectZ;
TopoDS_Vertex VX1, VX2, VZ1, VZ2;
gp_Vec aVX, aVZ;
2009-02-13 17:16:39 +05:00
if ( !GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) ||
2009-12-25 16:28:58 +05:00
!GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE ) ) {
2009-02-13 17:16:39 +05:00
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Wrong shape selected (two vectors(edges) have to be selected)" );
return false;
}
2009-02-13 17:16:39 +05:00
TopExp::Vertices( aVectX, VX1, VX2, Standard_True );
TopExp::Vertices( aVectZ, VZ1, VZ2, Standard_True );
2009-02-13 17:16:39 +05:00
if ( VX1.IsNull() || VX2.IsNull() ) {
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Bad OX vector" );
return false;
}
2009-02-13 17:16:39 +05:00
if ( VZ1.IsNull() || VZ2.IsNull() ) {
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Bad OZ vector" );
return false;
}
2009-02-13 17:16:39 +05:00
aVX = gp_Vec( BRep_Tool::Pnt( VX1 ), BRep_Tool::Pnt( VX2 ) );
aVZ = gp_Vec( BRep_Tool::Pnt( VZ1 ), BRep_Tool::Pnt( VZ2 ) );
2009-02-13 17:16:39 +05:00
if ( aVX.Magnitude() < Precision::Confusion() ) {
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Bad OX vector" );
return false;
}
2009-02-13 17:16:39 +05:00
if ( aVZ.Magnitude() < Precision::Confusion() ) {
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Bad OZ vector" );
return false;
}
2009-02-13 17:16:39 +05:00
gp_Dir aDirX = gp_Dir( aVX.X(), aVX.Y(), aVX.Z() );
gp_Dir aDirZ = gp_Dir( aVZ.X(), aVZ.Y(), aVZ.Z() );
2009-02-13 17:16:39 +05:00
if ( aDirX.IsParallel( aDirZ, Precision::Angular() ) ) {
if ( !showPreview )
2009-12-25 16:28:58 +05:00
showError( "Parallel vectors selected" );
return false;
}
2009-02-13 17:16:39 +05:00
myWPlane = gp_Ax3( BRep_Tool::Pnt( VX1 ), aDirZ, aDirX );
}
2009-02-13 17:16:39 +05:00
else if ( id == 2 ) { // by selection from standard (OXY or OYZ, or OZX)
gp_Ax2 anAx2;
2009-02-13 17:16:39 +05:00
if ( aOriginType == 1 ) anAx2 = gp::XOY();
else if ( aOriginType == 2 ) anAx2 = gp::YOZ();
else if ( aOriginType == 0 ) anAx2 = gp::ZOX();
myWPlane = gp_Ax3( anAx2 );
}
else {
return false;
}
2009-02-13 17:16:39 +05:00
if ( myReverseCB->isChecked() ) {
myWPlane.YReverse();
myWPlane.ZReverse();
}
2009-02-13 17:16:39 +05:00
if ( showPreview ) {
GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() );
GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker
2009-02-13 17:16:39 +05:00
( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(),
myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(),
myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() );
displayPreview( anObj );
}
return true;
}