geom/src/MeasureGUI/MeasureGUI_PointDlg.cxx

187 lines
6.1 KiB
C++
Raw Normal View History

2024-01-20 18:51:38 +05:00
// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +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
//
2012-08-09 13:58:02 +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
2014-02-18 12:44:41 +06:00
// version 2.1 of the License, or (at your option) any later version.
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +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.
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +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
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : MeasureGUI_PointDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2004-12-01 15:39:14 +05:00
//
#include "MeasureGUI_PointDlg.h"
2009-02-13 17:16:39 +05:00
#include "MeasureGUI_Widgets.h"
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <GEOMBase.h>
#include <DlgRef.h>
2009-02-13 17:16:39 +05:00
#include <GeometryGUI.h>
2009-02-13 17:16:39 +05:00
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
2004-12-01 15:39:14 +05:00
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
#include <TopExp.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <gp_Pnt.hxx>
//=================================================================================
// class : MeasureGUI_PointDlg()
// purpose : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
2009-02-13 17:16:39 +05:00
//
2004-12-01 15:39:14 +05:00
//=================================================================================
MeasureGUI_PointDlg::MeasureGUI_PointDlg( GeometryGUI* GUI, QWidget* parent )
2009-02-13 17:16:39 +05:00
: MeasureGUI_Skeleton( GUI, parent )
2004-12-01 15:39:14 +05:00
{
QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
2009-02-13 17:16:39 +05:00
"GEOM", tr( "ICON_DLG_POINT" ) ) );
QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
2009-02-13 17:16:39 +05:00
"GEOM", tr( "ICON_SELECT" ) ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "CAPTION" ) );
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setTitle( tr( "CAPTION" ) );
mainFrame()->RadioButton1->setIcon( iconPnt );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
myGrp = new MeasureGUI_1Sel3LineEdit( centralWidget() );
myGrp->TextLabel1->setText( tr( "POINT" ) );
myGrp->PushButton1->setIcon( iconSelect );
myGrp->LineEdit1->setReadOnly( true );
myGrp->TextLabel2->setText( tr( "X" ) );
myGrp->TextLabel3->setText( tr( "Y" ) );
myGrp->TextLabel4->setText( tr( "Z" ) );
myGrp->LineEdit2->setReadOnly( true );
myGrp->LineEdit3->setReadOnly( true );
myGrp->LineEdit4->setReadOnly( true );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( myGrp );
2004-12-01 15:39:14 +05:00
myHelpFileName = "point_coordinates_page.html";
Init();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : ~MeasureGUI_PointDlg()
// purpose : Destroys the object and frees any allocated resources
2009-02-13 17:16:39 +05:00
//======================myGrp->LineEdit2->setReadOnly( true );===========================================================
2004-12-01 15:39:14 +05:00
MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void MeasureGUI_PointDlg::Init()
2004-12-01 15:39:14 +05:00
{
QSize aSize( size() );
resize( (int)(aSize.width() *0.75 ), aSize.height() );
MeasureGUI_Skeleton::Init();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : activateSelection
// purpose :
//=================================================================================
void MeasureGUI_PointDlg::activateSelection()
{
localSelection( TopAbs_VERTEX );
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : SelectionIntoArgument
// purpose :
//=================================================================================
void MeasureGUI_PointDlg::SelectionIntoArgument()
{
2009-02-13 17:16:39 +05:00
try {
myObj.nullify();
2009-02-13 17:16:39 +05:00
myGrp->LineEdit1->setText( "" );
myGrp->LineEdit2->setText( "" );
myGrp->LineEdit3->setText( "" );
myGrp->LineEdit4->setText( "" );
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
if (aSelList.Extent() < 1)
return;
2004-12-01 15:39:14 +05:00
myObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
2004-12-01 15:39:14 +05:00
if ( !myObj )
2004-12-01 15:39:14 +05:00
return;
TColStd_IndexedMapOfInteger anIndexes;
2009-02-13 17:16:39 +05:00
aSelMgr->GetIndexes(aSelList.First(), anIndexes);
2004-12-01 15:39:14 +05:00
TopoDS_Shape aShape;
if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj.get(), aShape ) || aShape.IsNull() )
2004-12-01 15:39:14 +05:00
return;
TopoDS_Vertex aPoint;
QString aName = GEOMBase::GetName( myObj.get() );
2009-02-13 17:16:39 +05:00
if ( anIndexes.Extent() == 0 ) {
2004-12-01 15:39:14 +05:00
if ( aShape.ShapeType() == TopAbs_VERTEX )
aPoint = TopoDS::Vertex( aShape );
}
2009-02-13 17:16:39 +05:00
else {
2004-12-01 15:39:14 +05:00
int i = anIndexes( 1 );
TopTools_IndexedMapOfShape aShapes;
TopExp::MapShapes( aShape, aShapes );
2009-02-13 17:16:39 +05:00
2004-12-01 15:39:14 +05:00
if ( aShape != aShapes( i ) )
aName += QString( ":%1" ).arg( i );
aPoint = TopoDS::Vertex( aShapes( i ) );
}
2009-02-13 17:16:39 +05:00
if ( !aPoint.IsNull() ) {
2004-12-01 15:39:14 +05:00
gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
2009-02-13 17:16:39 +05:00
myGrp->LineEdit1->setText( aName );
2012-08-09 13:58:02 +06:00
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
myGrp->LineEdit2->setText( DlgRef::PrintDoubleValue( aPnt.X(), aPrecision ) );
myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( aPnt.Y(), aPrecision ) );
myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aPnt.Z(), aPrecision ) );
2004-12-01 15:39:14 +05:00
}
}
catch( ... )
{
myObj.nullify();
2009-02-13 17:16:39 +05:00
myGrp->LineEdit1->setText( "" );
myGrp->LineEdit2->setText( "" );
myGrp->LineEdit3->setText( "" );
myGrp->LineEdit4->setText( "" );
2004-12-01 15:39:14 +05:00
}
}