X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FRepairGUI%2FRepairGUI_DivideEdgeDlg.cxx;h=7cea1fd993597e5fb4f4f6a0d2fb9c7dc7ebae01;hb=7989a2ef27ffbfb20a244f45c8486054344da73c;hp=acd54e86dd77a68c8b1dd5c641c6bb21ad800157;hpb=d3dd282390888d7dc091ba2c2ffe7923bd7458e6;p=modules%2Fgeom.git diff --git a/src/RepairGUI/RepairGUI_DivideEdgeDlg.cxx b/src/RepairGUI/RepairGUI_DivideEdgeDlg.cxx index acd54e86d..7cea1fd99 100644 --- a/src/RepairGUI/RepairGUI_DivideEdgeDlg.cxx +++ b/src/RepairGUI/RepairGUI_DivideEdgeDlg.cxx @@ -1,43 +1,49 @@ -// GEOM GEOMGUI : GUI for Geometry component +// GEOM GEOMGUI : GUI for Geometry component // -// Copyright (C) 2003 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 -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// Copyright (C) 2003 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : RepairGUI_DivideEdgeDlg.cxx +// Author : Lucien PIGNOLONI, Open CASCADE S.A.S. // -// File : RepairGUI_DivideEdgeDlg.cxx -// Author : Lucien PIGNOLONI -// Module : GEOM -// $Header$ -using namespace std; #include "RepairGUI_DivideEdgeDlg.h" -#include "QAD_RightFrame.h" -#include "QAD_Desktop.h" -#include "OCCViewer_Viewer3d.h" -#include "SALOME_ListIteratorOfListIO.hxx" +#include +#include +#include -#include "GEOMImpl_Types.hxx" +#include +#include +#include +#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //================================================================================= // class : RepairGUI_DivideEdgeDlg() @@ -46,49 +52,60 @@ using namespace std; // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. //================================================================================= -RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl) - :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal ) + : GEOMBase_Skeleton( theGeometryGUI, parent, modal ) { - QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_DIVIDE_EDGE"))); - QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT"))); + QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DIVIDE_EDGE" ) ) ); + QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); - setCaption(tr("GEOM_DIVIDE_EDGE_TITLE")); + setWindowTitle( tr( "GEOM_DIVIDE_EDGE_TITLE" ) ); /***************************************************************/ - GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE")); - RadioButton1->setPixmap(image0); - RadioButton2->close(TRUE); - RadioButton3->close(TRUE); - - GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints"); - GroupPoints->GroupBox1->setTitle(tr("GEOM_ADD_POINT")); - GroupPoints->TextLabel1->setText(tr("GEOM_EDGE")); - GroupPoints->PushButton1->setPixmap(image1); + 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 ); GroupPoints->LineEdit1->setReadOnly( true ); - myIsParameterGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints ); - myIsParameterGr->setFrameStyle( QFrame::NoFrame ); - myIsParameterGr->setRadioButtonExclusive( true ); - myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_PARAMETER" ), myIsParameterGr ), 0 ); - myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_LENGTH" ), myIsParameterGr ), 1 ); - myIsParameterGr->find( 0 )->toggle(); + 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 ); - QGridLayout* aLay = new QGridLayout( 0, 1, 2, 0, 6, "aLay" ); - myValEdt = new QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0., 1., 0.1, 3 ); + myValEdt = new QDoubleSpinBox( GroupPoints->Box ); + initSpinBox( myValEdt, 0., 1., 0.1, 3 ); myValEdt->setValue( 0.5 ); - QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->GroupBox1 ); - aLay->addWidget( aLbl1, 0, 0 ); - aLay->addWidget( myValEdt, 0, 1 ); + 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 ); - Layout1->addWidget(GroupPoints, 2, 0); - GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsParameterGr, 1, 1, 0, 2); - GroupPoints->getGroupBoxLayout()->addLayout( aLay, 2, 0 ); /***************************************************************/ + setHelpFileName( "add_point_on_edge_operation_page.html" ); + Init(); } - //================================================================================= // function : ~RepairGUI_DivideEdgeDlg() // purpose : Destroys the object and frees any allocated resources @@ -97,7 +114,6 @@ RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg() { } - //================================================================================= // function : Init() // purpose : @@ -108,27 +124,60 @@ void RepairGUI_DivideEdgeDlg::Init() myEditCurrentArgument = GroupPoints->LineEdit1; myObject = GEOM::GEOM_Object::_nil(); - myIndex = -1; - myGeomGUI->SetState( 0 ); + //myGeomGUI->SetState( 0 ); initSelection(); /* signals and slots connections */ - connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel())); - connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog())); - connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); - connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); - connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply())); + connect( myValEdt, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), + SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) ); } +//================================================================================= +// 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 ); + } + } +} //================================================================================= // function : ClickOnOk() @@ -141,7 +190,6 @@ void RepairGUI_DivideEdgeDlg::ClickOnOk() } - //================================================================================= // function : ClickOnApply() // purpose : @@ -149,13 +197,12 @@ void RepairGUI_DivideEdgeDlg::ClickOnOk() bool RepairGUI_DivideEdgeDlg::ClickOnApply() { if ( !onAccept() ) - return false; + return false; initName(); - myEditCurrentArgument->setText(""); + myEditCurrentArgument->setText( "" ); myObject = GEOM::GEOM_Object::_nil(); - myIndex = -1; initSelection(); @@ -163,16 +210,6 @@ bool RepairGUI_DivideEdgeDlg::ClickOnApply() } -//================================================================================= -// function : ClickOnCancel() -// purpose : -//================================================================================= -void RepairGUI_DivideEdgeDlg::ClickOnCancel() -{ - GEOMBase_Skeleton::ClickOnCancel(); -} - - //================================================================================= // function : SelectionIntoArgument() // purpose : Called when selection as changed or other case @@ -180,48 +217,58 @@ void RepairGUI_DivideEdgeDlg::ClickOnCancel() //================================================================================= void RepairGUI_DivideEdgeDlg::SelectionIntoArgument() { - myEditCurrentArgument->setText(""); + myEditCurrentArgument->setText( "" ); myObject = GEOM::GEOM_Object::_nil(); - myIndex = -1; - if ( mySelection->IObjectCount() == 1 ) - { - Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject(); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if ( aSelList.Extent() == 1 ) { + Handle(SALOME_InteractiveObject) anIO = aSelList.First(); Standard_Boolean aRes; - GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes ); - if ( !CORBA::is_nil( aSelectedObj ) && aRes ) - { + GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes ); + if ( !CORBA::is_nil( aSelectedObject ) && aRes ) { + QString aName = GEOMBase::GetName( aSelectedObject ); TopoDS_Shape aShape; - if ( myGeomBase->GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) ) - { - const int aType = aShape.ShapeType(); - if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound - { - GEOM::short_array anIndexes; - if ( mySelection->HasIndex( anIO ) ) // subshape selection - { - TColStd_IndexedMapOfInteger aMap; - mySelection->GetIndex( anIO, aMap ); - myIndex = aMap( 1 ); - myObject = aSelectedObj; - myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" ); - } - else if ( aType == TopAbs_EDGE ) // single shape selection - { - myIndex = -1; - myObject = aSelectedObj; - myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) ); - } - else // face, shell, solid or compound was selected, and NOT its subshape. - { - myIndex = -1; - myObject = GEOM::GEOM_Object::_nil(); - } - } + if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) ) { + const int aType = aShape.ShapeType(); + if ( aType <= TopAbs_EDGE ) { + // edge, wire, face, shell, solid, compound + GEOM::short_array anIndexes; + + TColStd_IndexedMapOfInteger aMap; + 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 + } + } + else if ( aType == TopAbs_EDGE ) { + // single shape selection + myObject = aSelectedObject; + myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) ); + } + else { + // face, shell, solid or compound was selected, and NOT its subshape. + myObject = GEOM::GEOM_Object::_nil(); + } + } } } } + displayPreview(); } //================================================================================= @@ -230,8 +277,7 @@ void RepairGUI_DivideEdgeDlg::SelectionIntoArgument() //================================================================================= void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument() { - if( sender() == GroupPoints->PushButton1 ) - { + if ( sender() == GroupPoints->PushButton1 ) { GroupPoints->LineEdit1->setFocus(); myEditCurrentArgument = GroupPoints->LineEdit1; } @@ -245,22 +291,10 @@ void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument() //================================================================================= void RepairGUI_DivideEdgeDlg::LineEditReturnPressed() { - if( sender() == GroupPoints->LineEdit1 ) - { + if ( sender() == GroupPoints->LineEdit1 ) { myEditCurrentArgument = GroupPoints->LineEdit1; - GEOMBase_Skeleton::LineEditReturnPressed(); - } -} - - -//================================================================================= -// function : DeactivateActiveDialog() -// purpose : -//================================================================================= -void RepairGUI_DivideEdgeDlg::DeactivateActiveDialog() -{ - myGeomGUI->SetState( -1 ); - GEOMBase_Skeleton::DeactivateActiveDialog(); + GEOMBase_Skeleton::LineEditReturnPressed(); + } } @@ -271,37 +305,26 @@ void RepairGUI_DivideEdgeDlg::DeactivateActiveDialog() void RepairGUI_DivideEdgeDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), + SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - myObject = GEOM::GEOM_Object::_nil(); - myIndex = -1; +// myObject = GEOM::GEOM_Object::_nil(); - myGeomGUI->SetState( 0 ); + //myGeomGUI->SetState( 0 ); initSelection(); } - //================================================================================= // function : enterEvent() // purpose : Mouse enter onto the dialog to activate it //================================================================================= -void RepairGUI_DivideEdgeDlg::enterEvent(QEvent* e) +void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* ) { - if ( !GroupConstructors->isEnabled() ) + if ( !mainFrame()->GroupConstructors->isEnabled() ) ActivateThisDialog(); } -//================================================================================= -// function : closeEvent() -// purpose : -//================================================================================= -void RepairGUI_DivideEdgeDlg::closeEvent(QCloseEvent* e) -{ - myGeomGUI->SetState( -1 ); - GEOMBase_Skeleton::closeEvent( e ); -} - //================================================================================= // function : createOperation // purpose : @@ -315,9 +338,9 @@ GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation() // function : isValid // purpose : //================================================================================= -bool RepairGUI_DivideEdgeDlg::isValid( QString& msg ) +bool RepairGUI_DivideEdgeDlg::isValid( QString& ) { - return !myObject->_is_nil(); + return !myObject->_is_nil(); } //================================================================================= @@ -326,13 +349,13 @@ bool RepairGUI_DivideEdgeDlg::isValid( QString& msg ) //================================================================================= bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects ) { - GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge( - myObject, myIndex, myValEdt->value(), getIsByParameter() ); - bool aResult = !anObj->_is_nil(); - if ( aResult ) - objects.push_back( anObj._retn() ); + GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge + ( myObject, -1, myValEdt->value(), getIsByParameter() ); + bool aResult = !anObj->_is_nil(); + if ( aResult ) + objects.push_back( anObj._retn() ); - return aResult; + return aResult; } //================================================================================= @@ -341,7 +364,7 @@ bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects ) //================================================================================= bool RepairGUI_DivideEdgeDlg::getIsByParameter() const { - return myIsParameterGr->find( 0 )->isOn(); + return myIsParameterGr->button( 0 )->isChecked(); } //================================================================================= @@ -354,5 +377,14 @@ void RepairGUI_DivideEdgeDlg::initSelection() localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects } +//================================================================================= +// function : addSubshapeToStudy +// purpose : virtual method to add new SubObjects if local selection +//================================================================================= +void RepairGUI_DivideEdgeDlg::addSubshapesToStudy() +{ + QMap objMap; + objMap[GroupPoints->LineEdit1->text()] = myObject; - + addSubshapesToFather( objMap ); +}