geom/src/RepairGUI/RepairGUI_DivideEdgeDlg.cxx

402 lines
14 KiB
C++
Raw Normal View History

2009-02-13 17:16:39 +05:00
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:39:14 +05:00
//
2009-02-13 17:16:39 +05:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// 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.
//
// 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.
//
// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-12-01 15:39:14 +05:00
//
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : RepairGUI_DivideEdgeDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2004-12-01 15:39:14 +05:00
//
#include "RepairGUI_DivideEdgeDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <QtxDoubleSpinBox.h>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_Types.hxx>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <TopAbs.hxx>
#include <Geom_Curve.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <BRep_Tool.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
2005-08-23 19:10:06 +06:00
2004-12-01 15:39:14 +05:00
//=================================================================================
// class : RepairGUI_DivideEdgeDlg()
// purpose : Constructs a RepairGUI_DivideEdgeDlg which is a child of 'parent', with the
// 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
RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
bool modal )
: GEOMBase_Skeleton( theGeometryGUI, parent, modal )
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DIVIDE_EDGE" ) ) );
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "GEOM_DIVIDE_EDGE_TITLE" ) );
2004-12-01 15:39:14 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
mainFrame()->RadioButton1->setIcon( image0 );
mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->RadioButton3->close();
GroupPoints = new DlgRef_1SelExt( centralWidget() );
GroupPoints->GroupBox1->setTitle( tr( "GEOM_ADD_POINT" ) );
GroupPoints->TextLabel1->setText( tr( "GEOM_EDGE" ) );
GroupPoints->PushButton1->setIcon( image1 );
2004-12-01 15:39:14 +05:00
GroupPoints->LineEdit1->setReadOnly( true );
2009-02-13 17:16:39 +05:00
QRadioButton* rb1 = new QRadioButton( tr( "GEOM_BY_PARAMETER" ), GroupPoints->Box );
QRadioButton* rb2 = new QRadioButton( tr( "GEOM_BY_LENGTH" ), GroupPoints->Box );
myIsParameterGr = new QButtonGroup( GroupPoints->Box );
myIsParameterGr->addButton( rb1, 0 );
myIsParameterGr->addButton( rb2, 1 );
rb1->setChecked( true );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
myValEdt = new SalomeApp_DoubleSpinBox( 0., 1., 0.1, 3, 32, GroupPoints->Box );
2004-12-01 15:39:14 +05:00
myValEdt->setValue( 0.5 );
2009-02-13 17:16:39 +05:00
QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->Box );
QGridLayout* l = new QGridLayout( GroupPoints->Box );
l->setMargin( 0 ); l->setSpacing( 6 );
l->addWidget( rb1, 0, 0, 1, 2 );
l->addWidget( rb2, 1, 0, 1, 2 );
l->addWidget( aLbl1, 2, 0 );
l->addWidget( myValEdt, 2, 1 );
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupPoints );
2004-12-01 15:39:14 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
setHelpFileName( "add_point_on_edge_operation_page.html" );
2004-12-01 15:39:14 +05:00
Init();
}
//=================================================================================
// function : ~RepairGUI_DivideEdgeDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void RepairGUI_DivideEdgeDlg::Init()
{
/* init variables */
myEditCurrentArgument = GroupPoints->LineEdit1;
myObject = GEOM::GEOM_Object::_nil();
//myGeomGUI->SetState( 0 );
2004-12-01 15:39:14 +05:00
initSelection();
/* signals and slots connections */
2009-02-13 17:16:39 +05:00
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
connect( myValEdt, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
2004-12-01 15:39:14 +05:00
initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
}
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : ValueChangedInSpinBox()
// purpose : On change value in spin box
//=================================================================================
void RepairGUI_DivideEdgeDlg::ValueChangedInSpinBox()
{
displayPreview();
}
//=================================================================================
// function : displayPreview()
// purpose : On display Preview
//=================================================================================
void RepairGUI_DivideEdgeDlg::displayPreview()
{
if ( myObject->_is_nil() )
return;
TopoDS_Shape aShape;
gp_Pnt aPnt;
if ( GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE ) ) {
if (aShape.ShapeType() == TopAbs_EDGE) {
Standard_Real aFP, aLP, aP;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
aP = aFP + (aLP - aFP) * myValEdt->value();
aPnt = aCurve->Value(aP);
BRepBuilderAPI_MakeVertex mkVertex (aPnt);
aShape = mkVertex.Shape();
// Build prs
SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
if ( aPrs != 0 && !aPrs->IsNull() )
GEOMBase_Helper::displayPreview( aPrs, false, true );
}
}
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : ClickOnOk()
// purpose : Same than click on apply but close this dialog.
//=================================================================================
void RepairGUI_DivideEdgeDlg::ClickOnOk()
{
if ( ClickOnApply() )
ClickOnCancel();
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
bool RepairGUI_DivideEdgeDlg::ClickOnApply()
{
if ( !onAccept() )
return false;
2004-12-01 15:39:14 +05:00
initName();
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText( "" );
2004-12-01 15:39:14 +05:00
myObject = GEOM::GEOM_Object::_nil();
initSelection();
return true;
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection as changed or other case
// : used only by SelectButtonC1A1 (LineEditC1A1)
//=================================================================================
void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
{
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText( "" );
2004-12-01 15:39:14 +05:00
myObject = GEOM::GEOM_Object::_nil();
2009-02-13 17:16:39 +05:00
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
if ( aSelList.Extent() == 1 ) {
Handle(SALOME_InteractiveObject) anIO = aSelList.First();
2004-12-01 15:39:14 +05:00
Standard_Boolean aRes;
2009-02-13 17:16:39 +05:00
GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
QString aName = GEOMBase::GetName( aSelectedObject );
2004-12-01 15:39:14 +05:00
TopoDS_Shape aShape;
2009-02-13 17:16:39 +05:00
if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) ) {
const int aType = aShape.ShapeType();
2009-02-13 17:16:39 +05:00
if ( aType <= TopAbs_EDGE ) {
// edge, wire, face, shell, solid, compound
GEOM::short_array anIndexes;
TColStd_IndexedMapOfInteger aMap;
2009-02-13 17:16:39 +05:00
aSelMgr->GetIndexes( anIO, aMap );
if ( aMap.Extent() == 1 ) { // local selection
int anIndex = aMap( 1 );
myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( anIndex ) );
//Find SubShape Object in Father
GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
myObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
}
else {
myObject = aFindedObject; // get Object from study
}
}
2009-02-13 17:16:39 +05:00
else if ( aType == TopAbs_EDGE ) {
// single shape selection
myObject = aSelectedObject;
myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
}
2009-02-13 17:16:39 +05:00
else {
// face, shell, solid or compound was selected, and NOT its subshape.
myObject = GEOM::GEOM_Object::_nil();
}
}
2004-12-01 15:39:14 +05:00
}
}
}
2009-02-13 17:16:39 +05:00
displayPreview();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
{
2009-02-13 17:16:39 +05:00
if ( sender() == GroupPoints->PushButton1 ) {
2004-12-01 15:39:14 +05:00
GroupPoints->LineEdit1->setFocus();
myEditCurrentArgument = GroupPoints->LineEdit1;
}
SelectionIntoArgument();
}
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
{
2009-02-13 17:16:39 +05:00
if ( sender() == GroupPoints->LineEdit1 ) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = GroupPoints->LineEdit1;
GEOMBase_Skeleton::LineEditReturnPressed();
}
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
2009-02-13 17:16:39 +05:00
connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
// myObject = GEOM::GEOM_Object::_nil();
2004-12-01 15:39:14 +05:00
//myGeomGUI->SetState( 0 );
2004-12-01 15:39:14 +05:00
initSelection();
}
//=================================================================================
// function : enterEvent()
// purpose : Mouse enter onto the dialog to activate it
//=================================================================================
2009-02-13 17:16:39 +05:00
void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
if ( !mainFrame()->GroupConstructors->isEnabled() )
2004-12-01 15:39:14 +05:00
ActivateThisDialog();
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
{
return getGeomEngine()->GetIHealingOperations( getStudyId() );
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
{
2009-02-13 17:16:39 +05:00
bool ok = myValEdt->isValid( msg, !IsPreview() );
return !myObject->_is_nil() && ok;
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
{
GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge
2009-02-13 17:16:39 +05:00
( myObject, -1, myValEdt->value(), getIsByParameter() );
bool aResult = !anObj->_is_nil();
if ( aResult )
2009-02-13 17:16:39 +05:00
{
if ( !IsPreview() )
{
QStringList aParameters;
aParameters << "";
aParameters << myValEdt->text();
aParameters << "";
anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
}
objects.push_back( anObj._retn() );
2009-02-13 17:16:39 +05:00
}
2004-12-01 15:39:14 +05:00
return aResult;
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : getIsByParameter
// purpose :
//=================================================================================
bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
{
2009-02-13 17:16:39 +05:00
return myIsParameterGr->button( 0 )->isChecked();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : initSelection
// purpose :
//=================================================================================
void RepairGUI_DivideEdgeDlg::initSelection()
{
GEOM::GEOM_Object_var aNullGeomObject;
localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects
}
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : addSubshapeToStudy
// purpose : virtual method to add new SubObjects if local selection
//=================================================================================
void RepairGUI_DivideEdgeDlg::addSubshapesToStudy()
{
QMap<QString, GEOM::GEOM_Object_var> objMap;
objMap[GroupPoints->LineEdit1->text()] = myObject;
addSubshapesToFather( objMap );
}