geom/src/RepairGUI/RepairGUI_FreeFacesDlg.cxx

375 lines
12 KiB
C++
Raw Normal View History

2014-02-18 12:44:41 +06:00
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
2005-01-20 11:24:17 +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
2005-01-20 11:24:17 +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.
2005-01-20 11:24:17 +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.
2005-01-20 11:24:17 +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
2005-01-20 11:24:17 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2005-01-20 11:24:17 +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 : RepairGUI_FreeFacesDlg.cxx
// Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
2005-01-20 11:24:17 +05:00
//
#include "RepairGUI_FreeFacesDlg.h"
#include <GEOMBase.h>
#include <GeometryGUI.h>
#include <GEOMImpl_Types.hxx>
#include <GEOM_Constants.h>
2009-02-13 17:16:39 +05:00
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Tools.h>
2009-02-13 17:16:39 +05:00
#include <SUIT_Desktop.h>
#include <SUIT_OverrideCursor.h>
2009-02-13 17:16:39 +05:00
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SUIT_ViewManager.h>
#include <SUIT_ViewWindow.h>
2005-01-20 11:24:17 +05:00
#include <TColStd_MapOfInteger.hxx>
2005-01-20 11:24:17 +05:00
#include <TopExp.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
2005-01-20 11:24:17 +05:00
2009-02-13 17:16:39 +05:00
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
2009-02-13 17:16:39 +05:00
#include <QVBoxLayout>
2009-02-13 17:16:39 +05:00
#define SPACING 6
#define MARGIN 9
#define MIN_WIDTH 200
2005-01-20 11:24:17 +05:00
//=================================================================================
// class : RepairGUI_FreeFacesDlg()
// purpose : Constructs a RepairGUI_FreeFacesDlg 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_FreeFacesDlg::RepairGUI_FreeFacesDlg( GeometryGUI* GUI, QWidget* parent,
bool modal)
: GEOMBase_Skeleton(GUI, parent, modal),
myDisplayer (0),
myEdit (0)
2005-01-20 11:24:17 +05:00
{
QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FREE_FACES")));
2009-02-13 17:16:39 +05:00
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
2005-01-20 11:24:17 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "GEOM_FREE_FACES_TITLE" ) );
2005-01-20 11:24:17 +05:00
/***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_FREE_FACES"));
mainFrame()->RadioButton1->setIcon(image0);
mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton3->close();
mainFrame()->GroupBoxName->hide();
2009-02-13 17:16:39 +05:00
QGroupBox* aMainGrp = new QGroupBox( tr( "GEOM_SELECTED_SHAPE" ), this );
2005-01-20 11:24:17 +05:00
2009-02-13 17:16:39 +05:00
QLabel* lab = new QLabel( tr( "GEOM_OBJECT" ), aMainGrp );
QPushButton *aSelBtn = new QPushButton( aMainGrp );
aSelBtn->setIcon( image1 );
2009-02-13 17:16:39 +05:00
myEdit = new QLineEdit( aMainGrp );
2005-01-20 11:24:17 +05:00
myEdit->setReadOnly( true );
myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
myEdit->setMinimumWidth( MIN_WIDTH );
2009-02-13 17:16:39 +05:00
QHBoxLayout* aMainLay = new QHBoxLayout( aMainGrp );
aMainLay->setSpacing( SPACING );
aMainLay->setMargin( MARGIN );
aMainLay->addWidget( lab );
aMainLay->addWidget( aSelBtn );
2009-02-13 17:16:39 +05:00
aMainLay->addWidget( myEdit );
QVBoxLayout* aLay = new QVBoxLayout (centralWidget());
aLay->setSpacing(SPACING);
aLay->setMargin(MARGIN);
aLay->addWidget(aMainGrp);
resize(minimumSizeHint());
2005-01-20 11:24:17 +05:00
/***************************************************************/
myHelpFileName = "free_faces_page.html";
Init();
2005-01-20 11:24:17 +05:00
}
//=================================================================================
// function : ~RepairGUI_FreeFacesDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
2005-01-20 11:24:17 +05:00
//=================================================================================
void RepairGUI_FreeFacesDlg::Init()
2005-01-20 11:24:17 +05:00
{
myObj = GEOM::GEOM_Object::_nil();
myEditCurrentArgument = myEdit;
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
initName(tr("GEOM_FREE_FACES_NAME"));
buttonOk()->setEnabled(false);
buttonApply()->setEnabled(false);
activateSelection();
SelectionIntoArgument();
2005-01-20 11:24:17 +05:00
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void RepairGUI_FreeFacesDlg::ClickOnOk()
{
if (ClickOnApply())
ClickOnCancel();
}
2005-01-20 11:24:17 +05:00
//=================================================================================
// function : ClickOnApply()
// purpose :
2005-01-20 11:24:17 +05:00
//=================================================================================
bool RepairGUI_FreeFacesDlg::ClickOnApply()
2005-01-20 11:24:17 +05:00
{
if (!onAccept())
return false;
initName();
return true;
2005-01-20 11:24:17 +05:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
2005-01-20 11:24:17 +05:00
//=================================================================================
void RepairGUI_FreeFacesDlg::ActivateThisDialog()
2005-01-20 11:24:17 +05:00
{
GEOMBase_Skeleton::ActivateThisDialog();
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
2005-01-20 11:24:17 +05:00
activateSelection();
displayPreview(true);
2005-01-20 11:24:17 +05:00
}
//=================================================================================
// function : enterEvent()
2005-01-20 11:24:17 +05:00
// purpose :
//=================================================================================
void RepairGUI_FreeFacesDlg::enterEvent(QEvent*)
2005-01-20 11:24:17 +05:00
{
if (!mainFrame()->GroupConstructors->isEnabled())
ActivateThisDialog();
2005-01-20 11:24:17 +05:00
}
//=================================================================================
// function : SelectionIntoArgument
2005-01-20 11:24:17 +05:00
// purpose : SLOT. Called when selection changed.
//=================================================================================
void RepairGUI_FreeFacesDlg::SelectionIntoArgument()
2005-01-20 11:24:17 +05:00
{
myEditCurrentArgument->setText("");
myObj = GEOM::GEOM_Object::_nil();
2005-01-20 11:24:17 +05:00
erasePreview();
2009-02-13 17:16:39 +05:00
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
if ( aSelList.Extent() != 1 ) {
buttonOk()->setEnabled(false);
buttonApply()->setEnabled(false);
2005-01-20 11:24:17 +05:00
return;
}
GEOM::GEOM_Object_var anObj =
2012-08-09 13:58:02 +06:00
GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
2005-01-20 11:24:17 +05:00
2012-08-09 13:58:02 +06:00
if ( !GEOMBase::IsShape( anObj ) ) {
buttonOk()->setEnabled(false);
buttonApply()->setEnabled(false);
2005-01-20 11:24:17 +05:00
return;
} else {
2005-01-20 11:24:17 +05:00
myObj = anObj;
myEditCurrentArgument->setText(GEOMBase::GetName(myObj));
2012-08-09 13:58:02 +06:00
displayPreview( true, false, true, true, 3 );
2005-01-20 11:24:17 +05:00
}
}
//=================================================================================
// function : activateSelection
// purpose : activate selection of solids
2005-01-20 11:24:17 +05:00
//=================================================================================
void RepairGUI_FreeFacesDlg::activateSelection()
{
TColStd_MapOfInteger aMap;
aMap.Add( GEOM_SOLID );
aMap.Add( GEOM_COMPOUND );
globalSelection( aMap );
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
{
return getGeomEngine()->GetIShapesOperations( getStudyId() );
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
bool RepairGUI_FreeFacesDlg::isValid( QString& )
2005-01-20 11:24:17 +05:00
{
return !myObj->_is_nil() ;
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
{
bool aResult = false;
2012-08-09 13:58:02 +06:00
GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
GEOM::ListOfLong_var aFaceLst = anOper->GetFreeFacesIDs( myObj );
2005-01-20 11:24:17 +05:00
TopoDS_Shape aSelShape;
TopoDS_Shape aFace;
TopTools_IndexedMapOfShape anIndices;
int aNbObj = 0;
2009-02-13 17:16:39 +05:00
if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
2005-01-20 11:24:17 +05:00
myEdit->setText( GEOMBase::GetName( myObj ) );
QString aMess;
2009-02-13 17:16:39 +05:00
if ( !isValid( aMess ) ) {
2005-01-20 11:24:17 +05:00
erasePreview( true );
buttonOk()->setEnabled(false);
buttonApply()->setEnabled(false);
2005-01-20 11:24:17 +05:00
return false;
}
2005-06-10 18:43:15 +06:00
SUIT_OverrideCursor();
2005-01-20 11:24:17 +05:00
TopExp::MapShapes( aSelShape, anIndices);
SALOME_Prs* aPrs = 0;
2005-06-10 18:43:15 +06:00
//Get object trancparency and set it to preview
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
double transparency = 1.0;
if( app ) {
SUIT_ViewWindow* window = app->desktop( )->activeWindow( );
if( window && window->getViewManager() ) {
if ( app ) {
SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
if( aStudy ) {
int aMgrId = window->getViewManager()->getGlobalId();
CORBA::String_var aMainEntry = myObj->GetStudyEntry();
QString anEntry = aMainEntry.in();
QVariant v = aStudy->getObjectProperty( aMgrId , anEntry , GEOM::propertyName( GEOM::Transparency ) , transparency );
if( v.canConvert( QVariant::Double ) ) {
transparency = v.toDouble();
}
}
}
}
}
int i;
int n = aFaceLst->length();
for (i = 0; i < n; i++ ) {
2005-01-20 11:24:17 +05:00
aFace = anIndices.FindKey( aFaceLst[i] );
2009-02-13 17:16:39 +05:00
try {
2005-01-20 11:24:17 +05:00
getDisplayer()->SetColor( Quantity_NOC_RED );
getDisplayer()->SetToActivate( false );
getDisplayer()->SetTransparency( transparency );
2012-08-09 13:58:02 +06:00
aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
2005-01-20 11:24:17 +05:00
if ( aPrs )
2012-08-09 13:58:02 +06:00
displayPreview( aPrs, true );
2005-01-20 11:24:17 +05:00
}
catch( const SALOME::SALOME_Exception& e )
{
SalomeApp_Tools::QtCatchCorbaException( e );
buttonOk()->setEnabled(false);
buttonApply()->setEnabled(false);
return false;
2005-01-20 11:24:17 +05:00
}
}
// Create sub-objects
GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObj, aFaceLst);
aNbObj = aList->length();
for (i = 0; i < aNbObj; i++) {
objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
}
aResult = true;
2005-01-20 11:24:17 +05:00
}
buttonOk()->setEnabled(aNbObj > 0);
buttonApply()->setEnabled(aNbObj > 0);
2005-01-20 11:24:17 +05:00
return aResult;
}
//================================================================
// Function : getDisplayer
// Purpose :
//================================================================
GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
{
if ( !myDisplayer )
myDisplayer = new GEOM_Displayer( getStudy() );
2005-01-20 11:24:17 +05:00
return myDisplayer;
}
//================================================================
// Function : getFather
// Purpose : Get father object for object to be added in study
// (called with addInStudy method)
//================================================================
GEOM::GEOM_Object_ptr RepairGUI_FreeFacesDlg::getFather (GEOM::GEOM_Object_ptr)
{
return myObj;
}