2016-03-15 15:26:56 +03:00
|
|
|
// Copyright (C) 2015-2016 CEA/DEN, EDF R&D, OPEN CASCADE
|
2015-05-19 12:15:20 +04: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, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// 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 : GEOMGUI_TextTreeWdg.cxx
|
|
|
|
// Author : Alexander KOVALEV (akl)
|
|
|
|
|
|
|
|
#include "GEOMGUI_TextTreeWdg.h"
|
|
|
|
|
|
|
|
#include "GEOMGUI_DimensionProperty.h"
|
2016-10-19 15:55:06 +03:00
|
|
|
#include "GEOMGUI_AnnotationAttrs.h"
|
2016-10-24 16:10:23 +03:00
|
|
|
#include "GEOMGUI_AnnotationMgr.h"
|
2015-05-19 12:15:20 +04:00
|
|
|
#include "GeometryGUI.h"
|
|
|
|
#include "GeometryGUI_Operations.h"
|
|
|
|
#include <GEOM_Constants.h>
|
|
|
|
#include <GEOMUtils.hxx>
|
|
|
|
|
|
|
|
// GUI includes
|
|
|
|
#include <LightApp_Module.h>
|
|
|
|
#include <SalomeApp_Application.h>
|
|
|
|
#include <SalomeApp_Study.h>
|
|
|
|
#include <SUIT_Desktop.h>
|
|
|
|
#include <SUIT_Session.h>
|
|
|
|
#include <SUIT_ResourceMgr.h>
|
|
|
|
#include <SUIT_DataBrowser.h>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QAction>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QString>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QHash>
|
|
|
|
|
2016-10-19 15:55:06 +03:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Common style interface for managing dimension and annotation properties
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//! Access interface implementation for shape dimension attribute/property.
|
|
|
|
class DimensionsProperty : public GEOMGUI_TextTreeWdg::VisualProperty
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
DimensionsProperty( SalomeApp_Study* theStudy, const std::string& theEntry ) :
|
|
|
|
myStudy( theStudy ), myEntry( theEntry ) {
|
|
|
|
myAttr.LoadFromAttribute( theStudy, theEntry );
|
|
|
|
}
|
|
|
|
virtual int GetNumber() Standard_OVERRIDE {
|
|
|
|
return myAttr.GetNumber();
|
|
|
|
}
|
|
|
|
virtual QString GetName( const int theIndex ) Standard_OVERRIDE {
|
|
|
|
return myAttr.GetName( theIndex );
|
|
|
|
}
|
|
|
|
virtual bool GetIsVisible( const int theIndex ) Standard_OVERRIDE {
|
|
|
|
return myAttr.IsVisible( theIndex );
|
|
|
|
}
|
|
|
|
virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) Standard_OVERRIDE {
|
|
|
|
myAttr.SetVisible( theIndex, theIsVisible );
|
|
|
|
}
|
|
|
|
virtual void Save() Standard_OVERRIDE {
|
|
|
|
myAttr.SaveToAttribute( myStudy, myEntry );
|
|
|
|
}
|
|
|
|
GEOMGUI_DimensionProperty& Attr() { return myAttr; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
GEOMGUI_DimensionProperty myAttr;
|
|
|
|
SalomeApp_Study* myStudy;
|
|
|
|
std::string myEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Access interface implementation for shape annotation attribute.
|
|
|
|
class AnnotationsProperty : public GEOMGUI_TextTreeWdg::VisualProperty
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AnnotationsProperty( SalomeApp_Study* theStudy, const std::string& theEntry ) {
|
2016-10-24 16:10:23 +03:00
|
|
|
myEntry = theEntry.c_str();
|
|
|
|
myStudy = theStudy;
|
2016-10-19 15:55:06 +03:00
|
|
|
_PTR(SObject) aSObj = theStudy->studyDS()->FindObjectID( theEntry );
|
|
|
|
myAttr = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
|
|
|
|
}
|
|
|
|
virtual int GetNumber() Standard_OVERRIDE {
|
|
|
|
return !myAttr.IsNull() ? myAttr->GetNbAnnotation() : 0;
|
|
|
|
}
|
|
|
|
virtual QString GetName( const int theIndex ) Standard_OVERRIDE {
|
|
|
|
return !myAttr.IsNull() ? myAttr->GetName( theIndex ) : QString();
|
|
|
|
}
|
|
|
|
virtual bool GetIsVisible( const int theIndex ) Standard_OVERRIDE {
|
2016-10-24 16:10:23 +03:00
|
|
|
return annotationMgr()->IsDisplayed(myEntry, theIndex);
|
|
|
|
//return !myAttr.IsNull() ? myAttr->GetIsVisible( theIndex ) : false;
|
2016-10-19 15:55:06 +03:00
|
|
|
}
|
|
|
|
virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) Standard_OVERRIDE {
|
2016-10-24 16:10:23 +03:00
|
|
|
if (theIsVisible)
|
|
|
|
annotationMgr()->Display(myEntry, theIndex);
|
|
|
|
else
|
|
|
|
annotationMgr()->Erase(myEntry, theIndex);
|
|
|
|
/*if ( !myAttr.IsNull() ) {
|
2016-10-19 15:55:06 +03:00
|
|
|
myAttr->SetIsVisible( theIndex, theIsVisible );
|
2016-10-24 16:10:23 +03:00
|
|
|
}*/
|
2016-10-19 15:55:06 +03:00
|
|
|
}
|
|
|
|
virtual void Save() Standard_OVERRIDE {
|
|
|
|
/* every change is automatically saved */
|
|
|
|
}
|
|
|
|
Handle(GEOMGUI_AnnotationAttrs) Attr() { return myAttr; }
|
|
|
|
|
2016-10-24 16:10:23 +03:00
|
|
|
protected:
|
|
|
|
GEOMGUI_AnnotationMgr* annotationMgr() const
|
|
|
|
{
|
|
|
|
CAM_Application* anApp = dynamic_cast<CAM_Application*>(myStudy->application());
|
|
|
|
GeometryGUI* aModule = dynamic_cast<GeometryGUI*>(anApp->activeModule());
|
|
|
|
return aModule->GetAnnotationMgr();
|
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
|
2016-10-24 16:10:23 +03:00
|
|
|
private:
|
|
|
|
QString myEntry;
|
2016-10-19 15:55:06 +03:00
|
|
|
Handle(GEOMGUI_AnnotationAttrs) myAttr;
|
2016-10-24 16:10:23 +03:00
|
|
|
SalomeApp_Study* myStudy;
|
2016-10-19 15:55:06 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Text tree widget implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
2016-10-19 20:04:31 +03:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : Constructor
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2015-05-19 12:15:20 +04:00
|
|
|
GEOMGUI_TextTreeWdg::GEOMGUI_TextTreeWdg( SalomeApp_Application* app )
|
|
|
|
: myDisplayer(NULL)
|
|
|
|
{
|
|
|
|
myStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
|
|
|
|
myDisplayer = GEOM_Displayer( myStudy );
|
|
|
|
|
|
|
|
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
|
|
|
|
myVisibleIcon = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) );
|
|
|
|
myInvisibleIcon = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) );
|
|
|
|
|
|
|
|
setWindowTitle( tr( "TEXT_TREE_VIEW_TITLE" ) );
|
|
|
|
setObjectName( "geomTextTreeWdg" );
|
|
|
|
|
|
|
|
setRootIsDecorated( true );
|
|
|
|
setSelectionMode( QAbstractItemView::ExtendedSelection );
|
|
|
|
setAllColumnsShowFocus( true );
|
|
|
|
setUniformRowHeights( true );
|
|
|
|
|
|
|
|
QStringList columnNames;
|
|
|
|
columnNames << tr("TEXT_TREE_VIEW_NAME") << "";
|
|
|
|
QTreeWidgetItem * headerItem = new QTreeWidgetItem( columnNames );
|
|
|
|
headerItem->setIcon( 1, myVisibleIcon );
|
|
|
|
setHeaderItem ( headerItem );
|
|
|
|
header()->moveSection( 1, 0 );
|
2015-11-20 21:31:07 +03:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
2015-05-19 12:15:20 +04:00
|
|
|
header()->setResizeMode( 1, QHeaderView::ResizeToContents );
|
2015-11-20 21:31:07 +03:00
|
|
|
#else
|
|
|
|
header()->setSectionResizeMode( 1, QHeaderView::ResizeToContents );
|
|
|
|
#endif
|
2015-05-19 12:15:20 +04:00
|
|
|
QStringList rootNames;
|
|
|
|
rootNames << tr("GEOM_DIMENSIONS") << "";
|
|
|
|
myDimensionsItem = new QTreeWidgetItem( this, rootNames );
|
|
|
|
myDimensionsItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
|
|
|
|
addTopLevelItem( myDimensionsItem );
|
|
|
|
|
2016-10-06 14:33:25 +03:00
|
|
|
rootNames.clear();
|
|
|
|
rootNames << tr("GEOM_ANNOTATIONS") << "";
|
|
|
|
myAnnotationsItem = new QTreeWidgetItem( this, rootNames );
|
|
|
|
myAnnotationsItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
|
|
|
|
addTopLevelItem( myAnnotationsItem );
|
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
// get a free dockable window id
|
|
|
|
myWindowID = 11;
|
|
|
|
while( app->dockWindow( myWindowID ))
|
|
|
|
++myWindowID;
|
|
|
|
++myWindowID;
|
|
|
|
|
|
|
|
createActions();
|
|
|
|
setContextMenuPolicy( Qt::CustomContextMenu );
|
|
|
|
connect( this, SIGNAL( customContextMenuRequested(const QPoint&) ),
|
2016-10-11 17:44:18 +03:00
|
|
|
this, SLOT( showContextMenu(const QPoint&) ) );
|
2015-05-19 12:15:20 +04:00
|
|
|
|
2016-10-19 15:55:06 +03:00
|
|
|
connect( myStudy, SIGNAL( objVisibilityChanged( QString, Qtx::VisibilityState ) ),
|
2016-10-11 17:44:18 +03:00
|
|
|
this, SLOT( updateVisibilityColumn( QString, Qtx::VisibilityState ) ) );
|
2015-05-19 12:15:20 +04:00
|
|
|
connect( app->objectBrowser(), SIGNAL( updated() ), this, SLOT( updateTree() ) );
|
2016-10-19 15:55:06 +03:00
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
|
2016-10-19 20:04:31 +03:00
|
|
|
connect( aGeomGUI, SIGNAL( DimensionsUpdated( const QString& ) ),
|
|
|
|
this, SLOT( updateDimensionBranch( const QString& ) ) );
|
|
|
|
connect( aGeomGUI, SIGNAL( SignalAnnotationsUpdated( const QString& ) ),
|
|
|
|
this, SLOT( updateAnnotationBranch( const QString& ) ) );
|
2015-05-19 12:15:20 +04:00
|
|
|
connect( this, SIGNAL( itemClicked( QTreeWidgetItem*, int) ),
|
2016-10-11 17:44:18 +03:00
|
|
|
this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
|
2015-05-19 12:15:20 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-19 20:04:31 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : Destructor
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2015-05-19 12:15:20 +04:00
|
|
|
GEOMGUI_TextTreeWdg::~GEOMGUI_TextTreeWdg()
|
|
|
|
{
|
|
|
|
//std::cout<<"~GEOMGUI_TextTreeWdg"<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : createActions
|
|
|
|
// purpose : Create context popup menu actions.
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::createActions()
|
|
|
|
{
|
|
|
|
QAction* a = new QAction( tr( "MEN_DISPLAY" ), this );
|
|
|
|
a->setIcon( myVisibleIcon );
|
|
|
|
myActions.insert( GEOMOp::OpShow, a );
|
|
|
|
|
|
|
|
QAction* b = new QAction( tr( "MEN_ERASE" ), this );
|
|
|
|
b->setIcon( myInvisibleIcon );
|
|
|
|
myActions.insert( GEOMOp::OpHide, b );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : updateTree
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::updateTree()
|
|
|
|
{
|
|
|
|
myStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
|
|
|
|
_PTR(Study) aDSStudy = myStudy->studyDS();
|
|
|
|
if ( aDSStudy ) {
|
|
|
|
_PTR(SComponent) SC ( aDSStudy->FindComponent( "GEOM" ) );
|
|
|
|
if ( SC ) {
|
|
|
|
_PTR(ChildIterator) anIter ( aDSStudy->NewChildIterator( SC ) );
|
|
|
|
anIter->InitEx( true );
|
2016-10-19 15:55:06 +03:00
|
|
|
QList<QString> aDimensionObjEntries = getObjects( DimensionShape ).keys();
|
2016-10-11 17:44:18 +03:00
|
|
|
QList<QString> anAnnotationObjEntries = getObjects( AnnotationShape ).keys();
|
2015-05-19 12:15:20 +04:00
|
|
|
while( anIter->More() ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
_PTR(SObject) valSO ( anIter->Value() );
|
|
|
|
_PTR(SObject) refSO;
|
|
|
|
if ( !valSO->ReferencedObject( refSO ) ) {
|
|
|
|
// update tree of object's dimensions
|
|
|
|
QString anEntry = valSO->GetID().c_str();
|
2016-10-19 20:04:31 +03:00
|
|
|
updateBranches( anEntry );
|
2016-10-19 15:55:06 +03:00
|
|
|
aDimensionObjEntries.removeAll( anEntry );
|
2016-10-11 17:44:18 +03:00
|
|
|
anAnnotationObjEntries.removeAll( anEntry );
|
|
|
|
}
|
|
|
|
anIter->Next();
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
foreach ( QString entry, aDimensionObjEntries ) {
|
|
|
|
removeBranch( DimensionShape, entry, true );
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
foreach ( QString entry, anAnnotationObjEntries ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
removeBranch( AnnotationShape, entry, true );
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
//=================================================================================
|
2016-10-19 20:04:31 +03:00
|
|
|
// function : updateBranches
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::updateBranches( const QString& theEntry )
|
|
|
|
{
|
|
|
|
updateDimensionBranch( theEntry );
|
|
|
|
updateAnnotationBranch( theEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : updateDimensionBranch
|
2015-05-19 12:15:20 +04:00
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-19 20:04:31 +03:00
|
|
|
void GEOMGUI_TextTreeWdg::updateDimensionBranch( const QString& theEntry )
|
2016-10-11 17:44:18 +03:00
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
fillBranch( DimensionShape, theEntry );
|
2016-10-19 20:04:31 +03:00
|
|
|
}
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2016-10-19 20:04:31 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : updateAnnotationBranch
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::updateAnnotationBranch( const QString& theEntry )
|
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
fillBranch( AnnotationShape, theEntry );
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
|
|
|
|
2016-10-19 15:55:06 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : fillBranch
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QString& theEntry )
|
2015-05-19 12:15:20 +04:00
|
|
|
{
|
|
|
|
myStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
|
|
|
if ( myStudy && !theEntry.isEmpty() ) {
|
2016-10-19 15:55:06 +03:00
|
|
|
QSharedPointer<VisualProperty> aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
|
2016-10-11 17:44:18 +03:00
|
|
|
const std::string anEntry = theEntry.toStdString();
|
2016-10-19 15:55:06 +03:00
|
|
|
if ( !aProp ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
return;
|
2016-10-19 15:55:06 +03:00
|
|
|
}
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
_PTR(Study) aStudyDS = myStudy->studyDS();
|
|
|
|
if ( aStudyDS ) {
|
|
|
|
_PTR(SObject) obj( aStudyDS->FindObjectID( theEntry.toStdString() ) );
|
2016-10-19 15:55:06 +03:00
|
|
|
const QString aName = obj->GetName().c_str();
|
|
|
|
const int nbProps = aProp->GetNumber();
|
2015-05-19 12:15:20 +04:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry );
|
2015-05-19 12:15:20 +04:00
|
|
|
if ( objectItem ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
removeBranch( theBranchType, theEntry, nbProps > 0 ? false : true );
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
QStringList itemName;
|
|
|
|
if ( nbProps > 0 ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
itemName << aName << "";
|
|
|
|
if ( !objectItem ) {
|
2016-10-19 15:55:06 +03:00
|
|
|
QTreeWidgetItem* aPropRootItem = getPropertyRootItem( theBranchType );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
|
|
|
objectItem = new QTreeWidgetItem( aPropRootItem, itemName );
|
|
|
|
objectItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
|
|
|
|
objectItem->setData( 1, Qt::UserRole, theEntry );
|
|
|
|
aPropRootItem->addChild( objectItem );
|
|
|
|
getObjects( theBranchType ).insert( theEntry, objectItem );
|
|
|
|
if ( aPropRootItem->childCount() == 1 )
|
|
|
|
aPropRootItem->setExpanded( true );
|
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
for ( int anIt = 0; anIt < nbProps; ++anIt ) {
|
|
|
|
const QString aPropName = aProp->GetName( anIt );
|
|
|
|
const bool isVisible = aProp->GetIsVisible( anIt );
|
2016-10-11 17:44:18 +03:00
|
|
|
QTreeWidgetItem* anItem = new QTreeWidgetItem;
|
2016-10-19 15:55:06 +03:00
|
|
|
anItem->setText( 0, aPropName );
|
2016-10-11 17:44:18 +03:00
|
|
|
anItem->setIcon( 1, isVisible ? myVisibleIcon : myInvisibleIcon );
|
|
|
|
anItem->setData( 0, Qt::UserRole, anIt );
|
|
|
|
anItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
|
|
|
|
objectItem->addChild( anItem );
|
|
|
|
}
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : getVisualProperty
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-19 15:55:06 +03:00
|
|
|
QSharedPointer<GEOMGUI_TextTreeWdg::VisualProperty>
|
|
|
|
GEOMGUI_TextTreeWdg::getVisualProperty( const BranchType& theBranchType,
|
|
|
|
SalomeApp_Study* theStudy,
|
|
|
|
const std::string& theEntry )
|
2016-10-11 17:44:18 +03:00
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
switch ( theBranchType )
|
|
|
|
{
|
|
|
|
case DimensionShape : return QSharedPointer<VisualProperty>( new DimensionsProperty( theStudy, theEntry ) );
|
|
|
|
case AnnotationShape : return QSharedPointer<VisualProperty>( new AnnotationsProperty( theStudy, theEntry ) );
|
|
|
|
default: break;
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
return QSharedPointer<VisualProperty>();
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
//=================================================================================
|
|
|
|
// function : removeBranch
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void GEOMGUI_TextTreeWdg::removeBranch( const BranchType& theBranchType, const QString& theEntry,
|
|
|
|
bool force )
|
2015-05-19 12:15:20 +04:00
|
|
|
{
|
2016-10-11 17:44:18 +03:00
|
|
|
QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry );
|
2015-05-19 12:15:20 +04:00
|
|
|
if ( !objectItem )
|
|
|
|
return;
|
|
|
|
qDeleteAll( objectItem->takeChildren() );
|
|
|
|
if ( force ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
QTreeWidgetItem* aPropRootItem = getPropertyRootItem( theBranchType );
|
|
|
|
aPropRootItem->removeChild( objectItem );
|
|
|
|
getObjects( theBranchType ).remove( theEntry );
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : onItemClicked()
|
|
|
|
// purpose : called when tree item was clicked
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
|
|
|
|
{
|
|
|
|
if( theColumn != 1 || theItem->icon( 1 ).isNull() || theItem->isDisabled() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string anEntry = entryFromItem( theItem->parent() ).toStdString();
|
2016-10-11 17:44:18 +03:00
|
|
|
BranchType aBranchType = branchTypeFromItem( theItem );
|
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
int aDimIndex = idFromItem( theItem );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2016-10-19 15:55:06 +03:00
|
|
|
QSharedPointer<VisualProperty> aProp = getVisualProperty( aBranchType, myStudy, anEntry );
|
|
|
|
|
|
|
|
if ( aProp->GetIsVisible( aDimIndex ) ) {
|
|
|
|
aProp->SetIsVisible( aDimIndex, false );
|
2015-05-19 12:15:20 +04:00
|
|
|
theItem->setIcon( 1, myInvisibleIcon );
|
|
|
|
} else {
|
2016-10-19 15:55:06 +03:00
|
|
|
aProp->SetIsVisible( aDimIndex, true );
|
2015-05-19 12:15:20 +04:00
|
|
|
theItem->setIcon( 1, myVisibleIcon );
|
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
aProp->Save();
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
redisplay( anEntry.c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : idFromItem
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
int GEOMGUI_TextTreeWdg::idFromItem( QTreeWidgetItem* theItem )
|
|
|
|
{
|
|
|
|
if ( !theItem )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bool isIdOK = false;
|
|
|
|
const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
|
|
|
|
|
|
|
|
return isIdOK ? anId : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : entryFromItem
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
QString GEOMGUI_TextTreeWdg::entryFromItem( QTreeWidgetItem* theShapeItem )
|
|
|
|
{
|
|
|
|
if ( !theShapeItem )
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return theShapeItem->data( 1, Qt::UserRole ).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : itemFromEntry
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
QTreeWidgetItem* GEOMGUI_TextTreeWdg::itemFromEntry( const BranchType& theBranchType, QString theEntry )
|
2015-05-19 12:15:20 +04:00
|
|
|
{
|
|
|
|
if ( theEntry.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
return getObjects(theBranchType).value( theEntry, 0 );
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : updateVisibilityColumn
|
2016-10-11 17:44:18 +03:00
|
|
|
// purpose : Update visible state of icons of entry items.
|
2015-05-19 12:15:20 +04:00
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::updateVisibilityColumn( QString theEntry, Qtx::VisibilityState theState )
|
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
// dimension property branch
|
|
|
|
updateVisibilityColumn( DimensionShape, theEntry, theState );
|
|
|
|
|
|
|
|
// annotation property branch
|
2016-10-11 17:44:18 +03:00
|
|
|
updateVisibilityColumn( AnnotationShape, theEntry, theState );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : updateVisibilityColumn
|
|
|
|
// purpose : Update icons of dimension items.
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::updateVisibilityColumn( const BranchType& theBranchType, QString theEntry,
|
|
|
|
Qtx::VisibilityState theState )
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry );
|
2015-05-19 12:15:20 +04:00
|
|
|
if ( !anItem )
|
|
|
|
return;
|
|
|
|
anItem->setDisabled( theState != Qtx::ShownState );
|
|
|
|
QTreeWidgetItem* aChildItem;
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2016-10-19 15:55:06 +03:00
|
|
|
QSharedPointer<VisualProperty> aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
for ( int i=0; i < anItem->childCount(); i++ ) {
|
|
|
|
aChildItem = anItem->child( i );
|
|
|
|
if ( theState == Qtx::ShownState ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
if ( aProp->GetNumber() == 0 )
|
|
|
|
continue;
|
2016-10-19 15:55:06 +03:00
|
|
|
aChildItem->setIcon( 1, aProp->GetIsVisible( idFromItem( aChildItem ) ) ? myVisibleIcon
|
|
|
|
: myInvisibleIcon );
|
2015-05-19 12:15:20 +04:00
|
|
|
aChildItem->setDisabled( false );
|
|
|
|
} else {
|
|
|
|
aChildItem->setIcon( 1, QIcon() );
|
|
|
|
aChildItem->setDisabled( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : showContextMenu
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::showContextMenu( const QPoint& pos )
|
|
|
|
{
|
|
|
|
if ( selectedItems().isEmpty() )
|
|
|
|
return;
|
|
|
|
QMenu aMenu;
|
|
|
|
aMenu.addAction( myActions[GEOMOp::OpShow] );
|
|
|
|
aMenu.addAction( myActions[GEOMOp::OpHide] );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
if ( selectedItems().count() == 1 ) {
|
|
|
|
QTreeWidgetItem* anItem = selectedItems().first();
|
|
|
|
QString anEntry = entryFromItem( anItem->parent() );
|
|
|
|
if ( !anEntry.isEmpty() ) {
|
2016-10-11 17:44:18 +03:00
|
|
|
BranchType aBranchType = branchTypeFromItem( anItem );
|
2016-10-19 15:55:06 +03:00
|
|
|
QSharedPointer<VisualProperty>
|
|
|
|
aProp = getVisualProperty( aBranchType, myStudy, anEntry.toStdString() );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
|
|
|
if ( aProp->GetNumber() == 0 )
|
|
|
|
return;
|
2015-05-19 12:15:20 +04:00
|
|
|
aMenu.clear();
|
2016-10-19 15:55:06 +03:00
|
|
|
if ( aProp->GetIsVisible( idFromItem( anItem ) ) )
|
2016-10-11 17:44:18 +03:00
|
|
|
aMenu.addAction( myActions[GEOMOp::OpHide] );
|
2015-05-19 12:15:20 +04:00
|
|
|
else
|
2016-10-11 17:44:18 +03:00
|
|
|
aMenu.addAction( myActions[GEOMOp::OpShow] );
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
QAction* selPopupItem = aMenu.exec( viewport()->mapToGlobal(pos) );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
|
|
|
if ( selPopupItem == myActions[GEOMOp::OpShow] ||
|
|
|
|
selPopupItem == myActions[GEOMOp::OpHide] ) {
|
|
|
|
bool isVisible = selPopupItem == myActions[GEOMOp::OpShow];
|
|
|
|
foreach ( QTreeWidgetItem* anItem, selectedItems() ) {
|
|
|
|
setVisibility( anItem, isVisible );
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : setVisibility
|
2016-10-11 17:44:18 +03:00
|
|
|
// purpose : set item visible
|
2015-05-19 12:15:20 +04:00
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void GEOMGUI_TextTreeWdg::setVisibility( QTreeWidgetItem* theItem, bool theVisibility )
|
2015-05-19 12:15:20 +04:00
|
|
|
{
|
2016-10-11 17:44:18 +03:00
|
|
|
BranchType aBranchType = branchTypeFromItem( theItem );
|
|
|
|
if ( theItem == myDimensionsItem ||
|
|
|
|
theItem == myAnnotationsItem ) {
|
2016-10-19 15:55:06 +03:00
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
QTreeWidgetItem* anItem;
|
2016-10-11 17:44:18 +03:00
|
|
|
foreach ( QString entry, getObjects( aBranchType ).keys() ) {
|
|
|
|
anItem = itemFromEntry( aBranchType, entry );
|
2015-05-19 12:15:20 +04:00
|
|
|
if ( !anItem->isDisabled() )
|
2016-10-19 15:55:06 +03:00
|
|
|
setAllShapeItemsVisibility( aBranchType, entry, theVisibility );
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-10-11 17:44:18 +03:00
|
|
|
else {
|
|
|
|
if ( !theItem->isDisabled() && !theItem->parent()->isSelected() ) {
|
|
|
|
QString anEntry = entryFromItem( theItem );
|
|
|
|
if ( !anEntry.isEmpty() ) {
|
|
|
|
// it is a shape item
|
2016-10-19 15:55:06 +03:00
|
|
|
setAllShapeItemsVisibility( aBranchType, anEntry, theVisibility );
|
2016-10-11 17:44:18 +03:00
|
|
|
} else {
|
|
|
|
// it is a dimension item
|
|
|
|
anEntry = entryFromItem( theItem->parent() );
|
2016-10-19 15:55:06 +03:00
|
|
|
setShapeItemVisibility( aBranchType, anEntry, theItem, theVisibility );
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
}
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
2016-10-19 15:55:06 +03:00
|
|
|
// function : setAllShapeItemsVisibility
|
2015-05-19 12:15:20 +04:00
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-19 15:55:06 +03:00
|
|
|
void GEOMGUI_TextTreeWdg::setAllShapeItemsVisibility( const BranchType& theBranchType,
|
|
|
|
const QString& theEntry,
|
|
|
|
const bool theVisibility )
|
2015-05-19 12:15:20 +04:00
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
QSharedPointer<VisualProperty>
|
|
|
|
aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry );
|
2015-05-19 12:15:20 +04:00
|
|
|
QTreeWidgetItem* aChildItem;
|
|
|
|
for ( int i=0; i < anItem->childCount(); i++ ) {
|
|
|
|
aChildItem = anItem->child( i );
|
2016-10-19 15:55:06 +03:00
|
|
|
setShapeItemVisibility( aProp, aChildItem, theVisibility );
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
2016-10-19 15:55:06 +03:00
|
|
|
|
|
|
|
aProp->Save();
|
|
|
|
|
2015-05-19 12:15:20 +04:00
|
|
|
redisplay( theEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
2016-10-19 15:55:06 +03:00
|
|
|
// function : setShapeItemVisibility
|
2015-05-19 12:15:20 +04:00
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-19 15:55:06 +03:00
|
|
|
void GEOMGUI_TextTreeWdg::setShapeItemVisibility( const BranchType& theBranchType,
|
|
|
|
const QString& theEntry,
|
|
|
|
QTreeWidgetItem* theWidgetItem,
|
|
|
|
const bool theVisibility )
|
2015-05-19 12:15:20 +04:00
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
QSharedPointer<VisualProperty>
|
|
|
|
aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
|
2016-10-11 17:44:18 +03:00
|
|
|
|
2016-10-19 15:55:06 +03:00
|
|
|
if ( setShapeItemVisibility( aProp, theWidgetItem, theVisibility ) ) {
|
|
|
|
aProp->Save();
|
|
|
|
redisplay( theEntry );
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 12:15:20 +04:00
|
|
|
|
2016-10-19 15:55:06 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : setShapeItemVisibility
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
bool GEOMGUI_TextTreeWdg::setShapeItemVisibility( QSharedPointer<VisualProperty>& theProps,
|
|
|
|
QTreeWidgetItem* theWidgetItem,
|
|
|
|
const bool theVisibility )
|
|
|
|
{
|
|
|
|
int aDimIndex = idFromItem( theWidgetItem );
|
|
|
|
if ( theProps->GetNumber() == 0
|
|
|
|
|| theProps->GetIsVisible( aDimIndex ) == theVisibility ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
theProps->SetIsVisible( aDimIndex, theVisibility );
|
|
|
|
|
|
|
|
theWidgetItem->setIcon( 1, theVisibility ? myVisibleIcon : myInvisibleIcon );
|
|
|
|
|
|
|
|
return true;
|
2015-05-19 12:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : redisplay
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void GEOMGUI_TextTreeWdg::redisplay( QString theEntry )
|
|
|
|
{
|
|
|
|
Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( theEntry.toLatin1().constData(), "GEOM", "TEMP_IO" );
|
|
|
|
myDisplayer.Redisplay( io );
|
|
|
|
}
|
2016-10-11 17:44:18 +03:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : getPropertyRootItem
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
QTreeWidgetItem* GEOMGUI_TextTreeWdg::getPropertyRootItem( const BranchType& theBranchType )
|
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
return (theBranchType == DimensionShape) ? myDimensionsItem : myAnnotationsItem;
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : getObjects
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
QHash<QString, QTreeWidgetItem*>& GEOMGUI_TextTreeWdg::getObjects( const BranchType& theBranchType )
|
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
return (theBranchType == DimensionShape) ? myDimensionObjects : myAnnotationObjects;
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : branchTypeFromItem
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
GEOMGUI_TextTreeWdg::BranchType GEOMGUI_TextTreeWdg::branchTypeFromItem( QTreeWidgetItem* theItem )
|
|
|
|
{
|
2016-10-19 15:55:06 +03:00
|
|
|
BranchType aBranchType = DimensionShape;
|
2016-10-11 17:44:18 +03:00
|
|
|
|
|
|
|
bool aBranchTypeFound = false;
|
|
|
|
QTreeWidgetItem* anItem = theItem;
|
|
|
|
while( !aBranchTypeFound && anItem ) {
|
|
|
|
if ( anItem == myDimensionsItem ||
|
|
|
|
anItem == myAnnotationsItem) {
|
|
|
|
aBranchTypeFound = true;
|
2016-10-19 15:55:06 +03:00
|
|
|
aBranchType = (anItem == myDimensionsItem) ? DimensionShape : AnnotationShape;
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
anItem = anItem->parent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aBranchType;
|
|
|
|
}
|
|
|
|
|