Update of text tree widget integration to new class

of shape annotation attributes
This commit is contained in:
apl 2016-10-19 15:55:06 +03:00
parent 96407303b7
commit c11f35e20d
8 changed files with 672 additions and 680 deletions

View File

@ -75,7 +75,6 @@ SET(GEOMGUI_HEADERS
GEOM_GEOMGUI.hxx GEOM_GEOMGUI.hxx
GEOMGUI_CreationInfoWdg.h GEOMGUI_CreationInfoWdg.h
GEOMGUI_TextTreeWdg.h GEOMGUI_TextTreeWdg.h
GEOMGUI_VisualProperties.h
GEOMGUI_DimensionProperty.h GEOMGUI_DimensionProperty.h
GEOMGUI_AnnotationAttrs.h GEOMGUI_AnnotationAttrs.h
) )

View File

@ -147,12 +147,12 @@ void GEOMGUI_AnnotationAttrs::Remove( const _PTR(SObject)& theObject )
} }
//================================================================================= //=================================================================================
// function : SetCount // function : SetNbAnnotation
// purpose : // purpose :
//================================================================================= //=================================================================================
void GEOMGUI_AnnotationAttrs::SetCount( const int theCount ) const void GEOMGUI_AnnotationAttrs::SetNbAnnotation( const int theCount ) const
{ {
const int aCount = this->GetCount(); const int aCount = this->GetNbAnnotation();
if ( aCount < theCount ) if ( aCount < theCount )
{ {
@ -187,10 +187,10 @@ void GEOMGUI_AnnotationAttrs::SetCount( const int theCount ) const
} }
//================================================================================= //=================================================================================
// function : GetCount // function : GetNbAnnotation
// purpose : // purpose :
//================================================================================= //=================================================================================
int GEOMGUI_AnnotationAttrs::GetCount() const int GEOMGUI_AnnotationAttrs::GetNbAnnotation() const
{ {
return myParameterMap->GetInt( PARAMETER_COUNT ); return myParameterMap->GetInt( PARAMETER_COUNT );
} }
@ -354,8 +354,8 @@ void GEOMGUI_AnnotationAttrs::GetShapeSel( const int theIndex, int& theShapeType
//================================================================================= //=================================================================================
void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps ) void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps )
{ {
const int aCount = this->GetCount(); const int aCount = this->GetNbAnnotation();
this->SetCount( aCount + 1 ); this->SetNbAnnotation( aCount + 1 );
this->SetProperties( aCount, theProps ); this->SetProperties( aCount, theProps );
} }

View File

@ -28,6 +28,7 @@
#define GEOMGUI_ANNOTATIONATTRS_H #define GEOMGUI_ANNOTATIONATTRS_H
// SALOME GUI includes // SALOME GUI includes
#include <GEOMGUI.h>
#include <SalomeApp_Study.h> #include <SalomeApp_Study.h>
// OCCT includes // OCCT includes
@ -50,14 +51,14 @@ public:
DEFINE_STANDARD_RTTIEXT( GEOMGUI_AnnotationAttrs, Standard_Transient ) DEFINE_STANDARD_RTTIEXT( GEOMGUI_AnnotationAttrs, Standard_Transient )
//! Find annotation data defined for an object. //! Find annotation data defined for an object.
Standard_EXPORT static Handle(GEOMGUI_AnnotationAttrs) FindAttributes( const _PTR(SObject)& theObject ); GEOMGUI_EXPORT static Handle(GEOMGUI_AnnotationAttrs) FindAttributes( const _PTR(SObject)& theObject );
//! Find or create annotation data fields for an object. //! Find or create annotation data fields for an object.
Standard_EXPORT static Handle(GEOMGUI_AnnotationAttrs) FindOrCreateAttributes( const _PTR(SObject)& theObject, GEOMGUI_EXPORT static Handle(GEOMGUI_AnnotationAttrs) FindOrCreateAttributes( const _PTR(SObject)& theObject,
SalomeApp_Study* theStudy ); SalomeApp_Study* theStudy );
//! Remove annotation data fields for an object. //! Remove annotation data fields for an object.
Standard_EXPORT static void Remove( const _PTR(SObject)& theObject ); GEOMGUI_EXPORT static void Remove( const _PTR(SObject)& theObject );
public: public:
@ -80,7 +81,7 @@ public:
//! @param thePresentation [in] the presentation to setup. //! @param thePresentation [in] the presentation to setup.
//! @param theProps [in] the set of properties. //! @param theProps [in] the set of properties.
//! @param theLCS [in] the local coordinate system of the shape. //! @param theLCS [in] the local coordinate system of the shape.
Standard_EXPORT static void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, GEOMGUI_EXPORT static void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation,
const Properties& theProps, const Properties& theProps,
const gp_Ax3& theLCS ); const gp_Ax3& theLCS );
@ -88,7 +89,7 @@ public:
//! @param thePresentation [in] the presentation to setup. //! @param thePresentation [in] the presentation to setup.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theLCS [in] the local coordinate system of the shape. //! @param theLCS [in] the local coordinate system of the shape.
Standard_EXPORT void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, GEOMGUI_EXPORT void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation,
const int theIndex, const int theIndex,
const gp_Ax3& theLCS ); const gp_Ax3& theLCS );
@ -98,84 +99,84 @@ public:
//! If the count is decreased the extra annotation definitions are //! If the count is decreased the extra annotation definitions are
//! cleared out from the attribute. //! cleared out from the attribute.
//! @param theNumber [in] the new number of annotation definitions. //! @param theNumber [in] the new number of annotation definitions.
Standard_EXPORT void SetCount( const int theCount ) const; GEOMGUI_EXPORT void SetNbAnnotation( const int theCount ) const;
//! Returns number of annotation definitions stored on the object. //! Returns number of annotation definitions stored on the object.
Standard_EXPORT int GetCount() const; GEOMGUI_EXPORT int GetNbAnnotation() const;
//! Sets application name property of an annotation definition. //! Sets application name property of an annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theName [in] the new application name. //! @param theName [in] the new application name.
Standard_EXPORT void SetName( const int theIndex, const QString& theName ); GEOMGUI_EXPORT void SetName( const int theIndex, const QString& theName );
//! Returns application name of an annotation definition. //! Returns application name of an annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
Standard_EXPORT QString GetName( const int theIndex ) const; GEOMGUI_EXPORT QString GetName( const int theIndex ) const;
//! Sets application visibility state of an annotation definition. //! Sets application visibility state of an annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theIsVisible [in] the visibility state. //! @param theIsVisible [in] the visibility state.
Standard_EXPORT void SetIsVisible( const int theIndex, const bool theIsVisible ); GEOMGUI_EXPORT void SetIsVisible( const int theIndex, const bool theIsVisible );
//! Returns applicationb visibility state of an annotaion definition. //! Returns applicationb visibility state of an annotaion definition.
Standard_EXPORT bool GetIsVisible( const int theIndex ) const; GEOMGUI_EXPORT bool GetIsVisible( const int theIndex ) const;
//! Sets annotation label's text. //! Sets annotation label's text.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theText [in] the text string. //! @param theText [in] the text string.
Standard_EXPORT void SetText( const int theIndex, const QString& theText ); GEOMGUI_EXPORT void SetText( const int theIndex, const QString& theText );
//! Returns annotation label's text. //! Returns annotation label's text.
Standard_EXPORT QString GetText( const int theIndex ) const; GEOMGUI_EXPORT QString GetText( const int theIndex ) const;
//! Sets screen fixed flag of the annotation definition. //! Sets screen fixed flag of the annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theIsScreenFixed [in] the presentation flag. //! @param theIsScreenFixed [in] the presentation flag.
Standard_EXPORT void SetIsScreenFixed( const int theIndex, const bool theIsScreenFixed ); GEOMGUI_EXPORT void SetIsScreenFixed( const int theIndex, const bool theIsScreenFixed );
//! Returns screen fixed flag of the annotation definition. //! Returns screen fixed flag of the annotation definition.
Standard_EXPORT bool GetIsScreenFixed( const int theIndex ) const; GEOMGUI_EXPORT bool GetIsScreenFixed( const int theIndex ) const;
//! Sets position of the annotation definition. //! Sets position of the annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param thePosition [in] the position of the annotation label. //! @param thePosition [in] the position of the annotation label.
Standard_EXPORT void SetPosition( const int theIndex, const gp_Pnt& thePosition ); GEOMGUI_EXPORT void SetPosition( const int theIndex, const gp_Pnt& thePosition );
//! Returns position of the annotation definition. //! Returns position of the annotation definition.
Standard_EXPORT gp_Pnt GetPosition( const int theIndex ) const; GEOMGUI_EXPORT gp_Pnt GetPosition( const int theIndex ) const;
//! Sets attach point of the annotation definition. //! Sets attach point of the annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theAttach [in] the attach point of the annotation. //! @param theAttach [in] the attach point of the annotation.
Standard_EXPORT void SetAttach( const int theIndex, const gp_Pnt& theAttach ); GEOMGUI_EXPORT void SetAttach( const int theIndex, const gp_Pnt& theAttach );
//! Returns attach point of the annotation definition. //! Returns attach point of the annotation definition.
Standard_EXPORT gp_Pnt GetAttach( const int theIndex ) const; GEOMGUI_EXPORT gp_Pnt GetAttach( const int theIndex ) const;
//! Sets shape selection arguments. //! Sets shape selection arguments.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theShapeType, theSubIdx [in] the type of the selected shape and the sub-shape index. //! @param theShapeType, theSubIdx [in] the type of the selected shape and the sub-shape index.
Standard_EXPORT void SetShapeSel( const int theIndex, const int theShapeType, const int theSubIdx ); GEOMGUI_EXPORT void SetShapeSel( const int theIndex, const int theShapeType, const int theSubIdx );
//! Returns shape selection arguments. //! Returns shape selection arguments.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theShapeType, theSubIdx [out] the type of the selected shape and the sub-shape index. //! @param theShapeType, theSubIdx [out] the type of the selected shape and the sub-shape index.
Standard_EXPORT void GetShapeSel( const int theIndex, int& theShapeType, int& theSubIdx ) const; GEOMGUI_EXPORT void GetShapeSel( const int theIndex, int& theShapeType, int& theSubIdx ) const;
public: public:
//! Appends new annotation definition with the given properties. //! Appends new annotation definition with the given properties.
Standard_EXPORT void Append( const Properties& theProps ); GEOMGUI_EXPORT void Append( const Properties& theProps );
//! Sets complete properties of an annotation definition. //! Sets complete properties of an annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theProps [in] the structure containing the properties. //! @param theProps [in] the structure containing the properties.
Standard_EXPORT void SetProperties( const int theIndex, const Properties& theProps ); GEOMGUI_EXPORT void SetProperties( const int theIndex, const Properties& theProps );
//! Returns complete properties of an annotation definition. //! Returns complete properties of an annotation definition.
//! @param theIndex [in] the index of the annotation definition. //! @param theIndex [in] the index of the annotation definition.
//! @param theProps [out] the structure containing the properties. //! @param theProps [out] the structure containing the properties.
Standard_EXPORT void GetProperties( const int theIndex, Properties& theProps ) const; GEOMGUI_EXPORT void GetProperties( const int theIndex, Properties& theProps ) const;
private: private:

View File

@ -28,8 +28,6 @@
#define GEOMGUI_DIMENSIONPROPERTY_H #define GEOMGUI_DIMENSIONPROPERTY_H
// OCCT includes // OCCT includes
#include <GEOMGUI_VisualProperties.h>
#include <AIS_DiameterDimension.hxx> #include <AIS_DiameterDimension.hxx>
#include <AIS_LengthDimension.hxx> #include <AIS_LengthDimension.hxx>
#include <AIS_AngleDimension.hxx> #include <AIS_AngleDimension.hxx>
@ -62,7 +60,7 @@ typedef QSharedPointer<GEOMGUI_DimensionProperty> DimensionPropertyPtr;
* Diam: (plane)[0-3] (flyout)[4] (text flags)[5-6] (arrow flag)[7] (circle loc, xdir, ydir, rad)[8-17] * Diam: (plane)[0-3] (flyout)[4] (text flags)[5-6] (arrow flag)[7] (circle loc, xdir, ydir, rad)[8-17]
* Angle: (flyout)[0] (text flags)[1-2] (arrow flag)[3] (p1)[4-6] (p2)[7-9] (center)[10-12] * Angle: (flyout)[0] (text flags)[1-2] (arrow flag)[3] (p1)[4-6] (p2)[7-9] (center)[10-12]
*/ */
class Standard_EXPORT GEOMGUI_DimensionProperty : public GEOMGUI_VisualProperties class Standard_EXPORT GEOMGUI_DimensionProperty
{ {
public: public:

View File

@ -22,7 +22,7 @@
#include "GEOMGUI_TextTreeWdg.h" #include "GEOMGUI_TextTreeWdg.h"
#include "GEOMGUI_DimensionProperty.h" #include "GEOMGUI_DimensionProperty.h"
//#include "GEOMGUI_ShapeAnnotations.h" #include "GEOMGUI_AnnotationAttrs.h"
#include "GeometryGUI.h" #include "GeometryGUI.h"
#include "GeometryGUI_Operations.h" #include "GeometryGUI_Operations.h"
#include <GEOM_Constants.h> #include <GEOM_Constants.h>
@ -50,6 +50,80 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QHash> #include <QHash>
// ----------------------------------------------------------------------------
// 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 ) {
_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 {
return !myAttr.IsNull() ? myAttr->GetIsVisible( theIndex ) : false;
}
virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) Standard_OVERRIDE {
if ( !myAttr.IsNull() ) {
myAttr->SetIsVisible( theIndex, theIsVisible );
}
}
virtual void Save() Standard_OVERRIDE {
/* every change is automatically saved */
}
Handle(GEOMGUI_AnnotationAttrs) Attr() { return myAttr; }
private:
Handle(GEOMGUI_AnnotationAttrs) myAttr;
};
}
// ----------------------------------------------------------------------------
// Text tree widget implementation
// ----------------------------------------------------------------------------
GEOMGUI_TextTreeWdg::GEOMGUI_TextTreeWdg( SalomeApp_Application* app ) GEOMGUI_TextTreeWdg::GEOMGUI_TextTreeWdg( SalomeApp_Application* app )
: myDisplayer(NULL) : myDisplayer(NULL)
{ {
@ -105,6 +179,7 @@ GEOMGUI_TextTreeWdg::GEOMGUI_TextTreeWdg( SalomeApp_Application* app )
connect( myStudy, SIGNAL( objVisibilityChanged( QString, Qtx::VisibilityState ) ), connect( myStudy, SIGNAL( objVisibilityChanged( QString, Qtx::VisibilityState ) ),
this, SLOT( updateVisibilityColumn( QString, Qtx::VisibilityState ) ) ); this, SLOT( updateVisibilityColumn( QString, Qtx::VisibilityState ) ) );
connect( app->objectBrowser(), SIGNAL( updated() ), this, SLOT( updateTree() ) ); connect( app->objectBrowser(), SIGNAL( updated() ), this, SLOT( updateTree() ) );
GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) ); GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
connect( aGeomGUI, SIGNAL( DimensionsUpdated( const QString& ) ), this, SLOT( updateBranch( const QString& ) ) ); connect( aGeomGUI, SIGNAL( DimensionsUpdated( const QString& ) ), this, SLOT( updateBranch( const QString& ) ) );
connect( this, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), connect( this, SIGNAL( itemClicked( QTreeWidgetItem*, int) ),
@ -145,7 +220,7 @@ void GEOMGUI_TextTreeWdg::updateTree()
if ( SC ) { if ( SC ) {
_PTR(ChildIterator) anIter ( aDSStudy->NewChildIterator( SC ) ); _PTR(ChildIterator) anIter ( aDSStudy->NewChildIterator( SC ) );
anIter->InitEx( true ); anIter->InitEx( true );
QList<QString> aGeomObjEntries = getObjects( Geometry ).keys(); QList<QString> aDimensionObjEntries = getObjects( DimensionShape ).keys();
QList<QString> anAnnotationObjEntries = getObjects( AnnotationShape ).keys(); QList<QString> anAnnotationObjEntries = getObjects( AnnotationShape ).keys();
while( anIter->More() ) { while( anIter->More() ) {
_PTR(SObject) valSO ( anIter->Value() ); _PTR(SObject) valSO ( anIter->Value() );
@ -154,15 +229,15 @@ void GEOMGUI_TextTreeWdg::updateTree()
// update tree of object's dimensions // update tree of object's dimensions
QString anEntry = valSO->GetID().c_str(); QString anEntry = valSO->GetID().c_str();
updateBranch( anEntry ); updateBranch( anEntry );
aGeomObjEntries.removeAll( anEntry ); aDimensionObjEntries.removeAll( anEntry );
anAnnotationObjEntries.removeAll( anEntry ); anAnnotationObjEntries.removeAll( anEntry );
} }
anIter->Next(); anIter->Next();
} }
foreach (QString entry, aGeomObjEntries) { foreach ( QString entry, aDimensionObjEntries ) {
removeBranch( Geometry, entry, true ); removeBranch( DimensionShape, entry, true );
} }
foreach (QString entry, anAnnotationObjEntries) { foreach ( QString entry, anAnnotationObjEntries ) {
removeBranch( AnnotationShape, entry, true ); removeBranch( AnnotationShape, entry, true );
} }
} }
@ -175,33 +250,33 @@ void GEOMGUI_TextTreeWdg::updateTree()
//================================================================================= //=================================================================================
void GEOMGUI_TextTreeWdg::updateBranch( const QString& theEntry ) void GEOMGUI_TextTreeWdg::updateBranch( const QString& theEntry )
{ {
/// dimension property branch // dimension property branch
fillBranch( Geometry, theEntry ); fillBranch( DimensionShape, theEntry );
// annotation property branch // annotation property branch
// fillBranch(AnnotationShape, theEntry); fillBranch( AnnotationShape, theEntry );
} }
//=================================================================================
// function : fillBranch
// purpose :
//=================================================================================
void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QString& theEntry ) void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QString& theEntry )
{ {
myStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() ); myStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
if ( myStudy && !theEntry.isEmpty() ) { if ( myStudy && !theEntry.isEmpty() ) {
VisualPropertiesPtr aProp = getVisualProperty( theBranchType ); QSharedPointer<VisualProperty> aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
int aNumber = aProp->GetNumber();
const std::string anEntry = theEntry.toStdString(); const std::string anEntry = theEntry.toStdString();
if ( !aProp ) {
aProp->LoadFromAttribute( myStudy, theEntry.toStdString() );
if (!aProp)
return; return;
}
_PTR(Study) aStudyDS = myStudy->studyDS(); _PTR(Study) aStudyDS = myStudy->studyDS();
if ( aStudyDS ) { if ( aStudyDS ) {
_PTR(SObject) obj( aStudyDS->FindObjectID( theEntry.toStdString() ) ); _PTR(SObject) obj( aStudyDS->FindObjectID( theEntry.toStdString() ) );
QString aName = obj->GetName().c_str(); const QString aName = obj->GetName().c_str();
const int nbProps = aProp->GetNumber();
int nbProps = aProp->GetNumber();
QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry ); QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry );
if ( objectItem ) { if ( objectItem ) {
@ -211,7 +286,7 @@ void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QSt
if ( nbProps > 0 ) { if ( nbProps > 0 ) {
itemName << aName << ""; itemName << aName << "";
if ( !objectItem ) { if ( !objectItem ) {
QTreeWidgetItem* aPropRootItem = getPropertyRootItem(theBranchType); QTreeWidgetItem* aPropRootItem = getPropertyRootItem( theBranchType );
objectItem = new QTreeWidgetItem( aPropRootItem, itemName ); objectItem = new QTreeWidgetItem( aPropRootItem, itemName );
objectItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); objectItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
@ -221,15 +296,11 @@ void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QSt
if ( aPropRootItem->childCount() == 1 ) if ( aPropRootItem->childCount() == 1 )
aPropRootItem->setExpanded( true ); aPropRootItem->setExpanded( true );
} }
bool isDisplayed = myDisplayer.IsDisplayed( theEntry ); for ( int anIt = 0; anIt < nbProps; ++anIt ) {
// read dimension records from property const QString aPropName = aProp->GetName( anIt );
for ( int anIt = 0; anIt < aProp->GetNumber(); ++anIt ) { const bool isVisible = aProp->GetIsVisible( anIt );
QString aName = aProp->GetName( anIt );
bool isVisible = aProp->IsVisible( anIt );
QTreeWidgetItem* anItem = new QTreeWidgetItem; QTreeWidgetItem* anItem = new QTreeWidgetItem;
anItem->setText( 0, aName ); anItem->setText( 0, aPropName );
// if ( isDisplayed )
anItem->setIcon( 1, isVisible ? myVisibleIcon : myInvisibleIcon ); anItem->setIcon( 1, isVisible ? myVisibleIcon : myInvisibleIcon );
anItem->setData( 0, Qt::UserRole, anIt ); anItem->setData( 0, Qt::UserRole, anIt );
anItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); anItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
@ -244,18 +315,18 @@ void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QSt
// function : getVisualProperty // function : getVisualProperty
// purpose : // purpose :
//================================================================================= //=================================================================================
VisualPropertiesPtr GEOMGUI_TextTreeWdg::getVisualProperty( const BranchType& theBranchType ) QSharedPointer<GEOMGUI_TextTreeWdg::VisualProperty>
GEOMGUI_TextTreeWdg::getVisualProperty( const BranchType& theBranchType,
SalomeApp_Study* theStudy,
const std::string& theEntry )
{ {
VisualPropertiesPtr aProp; switch ( theBranchType )
{
if ( theBranchType == Geometry ) { case DimensionShape : return QSharedPointer<VisualProperty>( new DimensionsProperty( theStudy, theEntry ) );
aProp = QSharedPointer<GEOMGUI_DimensionProperty>( new GEOMGUI_DimensionProperty() ); case AnnotationShape : return QSharedPointer<VisualProperty>( new AnnotationsProperty( theStudy, theEntry ) );
default: break;
} }
else { return QSharedPointer<VisualProperty>();
//aProp = QSharedPointer<GEOMGUI_ShapeAnnotations>( new GEOMGUI_ShapeAnnotations() );
}
return aProp;
} }
//================================================================================= //=================================================================================
@ -290,16 +361,16 @@ void GEOMGUI_TextTreeWdg::onItemClicked( QTreeWidgetItem* theItem, int theColumn
int aDimIndex = idFromItem( theItem ); int aDimIndex = idFromItem( theItem );
VisualPropertiesPtr aProp = getVisualProperty( aBranchType ); QSharedPointer<VisualProperty> aProp = getVisualProperty( aBranchType, myStudy, anEntry );
aProp->LoadFromAttribute( myStudy, anEntry );
if ( aProp->IsVisible( aDimIndex ) ) { if ( aProp->GetIsVisible( aDimIndex ) ) {
aProp->SetVisible( aDimIndex, false ); aProp->SetIsVisible( aDimIndex, false );
theItem->setIcon( 1, myInvisibleIcon ); theItem->setIcon( 1, myInvisibleIcon );
} else { } else {
aProp->SetVisible( aDimIndex, true ); aProp->SetIsVisible( aDimIndex, true );
theItem->setIcon( 1, myVisibleIcon ); theItem->setIcon( 1, myVisibleIcon );
} }
aProp->SaveToAttribute( myStudy, anEntry ); aProp->Save();
redisplay( anEntry.c_str() ); redisplay( anEntry.c_str() );
} }
@ -349,8 +420,10 @@ QTreeWidgetItem* GEOMGUI_TextTreeWdg::itemFromEntry( const BranchType& theBranch
//================================================================================= //=================================================================================
void GEOMGUI_TextTreeWdg::updateVisibilityColumn( QString theEntry, Qtx::VisibilityState theState ) void GEOMGUI_TextTreeWdg::updateVisibilityColumn( QString theEntry, Qtx::VisibilityState theState )
{ {
//BranchType theBranchType, // dimension property branch
updateVisibilityColumn( Geometry, theEntry, theState ); updateVisibilityColumn( DimensionShape, theEntry, theState );
// annotation property branch
updateVisibilityColumn( AnnotationShape, theEntry, theState ); updateVisibilityColumn( AnnotationShape, theEntry, theState );
} }
@ -367,15 +440,14 @@ void GEOMGUI_TextTreeWdg::updateVisibilityColumn( const BranchType& theBranchTyp
anItem->setDisabled( theState != Qtx::ShownState ); anItem->setDisabled( theState != Qtx::ShownState );
QTreeWidgetItem* aChildItem; QTreeWidgetItem* aChildItem;
VisualPropertiesPtr aProp = getVisualProperty( theBranchType ); QSharedPointer<VisualProperty> aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
for ( int i=0; i < anItem->childCount(); i++ ) { for ( int i=0; i < anItem->childCount(); i++ ) {
aChildItem = anItem->child( i ); aChildItem = anItem->child( i );
if ( theState == Qtx::ShownState ) { if ( theState == Qtx::ShownState ) {
aProp->LoadFromAttribute( myStudy, theEntry.toStdString() );
if ( aProp->GetNumber() == 0 ) if ( aProp->GetNumber() == 0 )
continue; continue;
aChildItem->setIcon( 1, aProp->IsVisible( idFromItem( aChildItem ) ) ? myVisibleIcon aChildItem->setIcon( 1, aProp->GetIsVisible( idFromItem( aChildItem ) ) ? myVisibleIcon
: myInvisibleIcon ); : myInvisibleIcon );
aChildItem->setDisabled( false ); aChildItem->setDisabled( false );
} else { } else {
@ -402,13 +474,13 @@ void GEOMGUI_TextTreeWdg::showContextMenu( const QPoint& pos )
QString anEntry = entryFromItem( anItem->parent() ); QString anEntry = entryFromItem( anItem->parent() );
if ( !anEntry.isEmpty() ) { if ( !anEntry.isEmpty() ) {
BranchType aBranchType = branchTypeFromItem( anItem ); BranchType aBranchType = branchTypeFromItem( anItem );
VisualPropertiesPtr aProp = getVisualProperty( aBranchType ); QSharedPointer<VisualProperty>
aProp = getVisualProperty( aBranchType, myStudy, anEntry.toStdString() );
aProp->LoadFromAttribute( myStudy, anEntry.toStdString() );
if ( aProp->GetNumber() == 0 ) if ( aProp->GetNumber() == 0 )
return; return;
aMenu.clear(); aMenu.clear();
if ( aProp->IsVisible( idFromItem( anItem ) ) ) if ( aProp->GetIsVisible( idFromItem( anItem ) ) )
aMenu.addAction( myActions[GEOMOp::OpHide] ); aMenu.addAction( myActions[GEOMOp::OpHide] );
else else
aMenu.addAction( myActions[GEOMOp::OpShow] ); aMenu.addAction( myActions[GEOMOp::OpShow] );
@ -434,12 +506,12 @@ void GEOMGUI_TextTreeWdg::setVisibility( QTreeWidgetItem* theItem, bool theVisib
BranchType aBranchType = branchTypeFromItem( theItem ); BranchType aBranchType = branchTypeFromItem( theItem );
if ( theItem == myDimensionsItem || if ( theItem == myDimensionsItem ||
theItem == myAnnotationsItem ) { theItem == myAnnotationsItem ) {
// set visibility for all dimensions
QTreeWidgetItem* anItem; QTreeWidgetItem* anItem;
foreach ( QString entry, getObjects( aBranchType ).keys() ) { foreach ( QString entry, getObjects( aBranchType ).keys() ) {
anItem = itemFromEntry( aBranchType, entry ); anItem = itemFromEntry( aBranchType, entry );
if ( !anItem->isDisabled() ) if ( !anItem->isDisabled() )
setShapeDimensionsVisibility( aBranchType, entry, theVisibility ); setAllShapeItemsVisibility( aBranchType, entry, theVisibility );
} }
return; return;
} }
@ -448,50 +520,75 @@ void GEOMGUI_TextTreeWdg::setVisibility( QTreeWidgetItem* theItem, bool theVisib
QString anEntry = entryFromItem( theItem ); QString anEntry = entryFromItem( theItem );
if ( !anEntry.isEmpty() ) { if ( !anEntry.isEmpty() ) {
// it is a shape item // it is a shape item
setShapeDimensionsVisibility( aBranchType, anEntry, theVisibility ); setAllShapeItemsVisibility( aBranchType, anEntry, theVisibility );
} else { } else {
// it is a dimension item // it is a dimension item
anEntry = entryFromItem( theItem->parent() ); anEntry = entryFromItem( theItem->parent() );
setDimensionVisibility( aBranchType, anEntry, theItem, theVisibility ); setShapeItemVisibility( aBranchType, anEntry, theItem, theVisibility );
} }
} }
} }
} }
//================================================================================= //=================================================================================
// function : setShapeDimensionsVisibility // function : setAllShapeItemsVisibility
// purpose : // purpose :
//================================================================================= //=================================================================================
void GEOMGUI_TextTreeWdg::setShapeDimensionsVisibility( const BranchType& theBranchType, void GEOMGUI_TextTreeWdg::setAllShapeItemsVisibility( const BranchType& theBranchType,
QString theEntry, bool theVisibility ) const QString& theEntry,
const bool theVisibility )
{ {
QSharedPointer<VisualProperty>
aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry ); QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry );
QTreeWidgetItem* aChildItem; QTreeWidgetItem* aChildItem;
for ( int i=0; i < anItem->childCount(); i++ ) { for ( int i=0; i < anItem->childCount(); i++ ) {
aChildItem = anItem->child( i ); aChildItem = anItem->child( i );
setDimensionVisibility( theBranchType, theEntry, aChildItem, theVisibility ); setShapeItemVisibility( aProp, aChildItem, theVisibility );
} }
aProp->Save();
redisplay( theEntry ); redisplay( theEntry );
} }
//================================================================================= //=================================================================================
// function : setDimensionVisibility // function : setShapeItemVisibility
// purpose : // purpose :
//================================================================================= //=================================================================================
void GEOMGUI_TextTreeWdg::setDimensionVisibility( const BranchType& theBranchType, QString theEntry, void GEOMGUI_TextTreeWdg::setShapeItemVisibility( const BranchType& theBranchType,
QTreeWidgetItem* theDimItem, bool theVisibility ) const QString& theEntry,
QTreeWidgetItem* theWidgetItem,
const bool theVisibility )
{ {
VisualPropertiesPtr aProp = getVisualProperty( theBranchType ); QSharedPointer<VisualProperty>
aProp = getVisualProperty( theBranchType, myStudy, theEntry.toStdString() );
aProp->LoadFromAttribute( myStudy, theEntry.toStdString() ); if ( setShapeItemVisibility( aProp, theWidgetItem, theVisibility ) ) {
int aDimIndex = idFromItem( theDimItem ); aProp->Save();
if ( aProp->GetNumber() == 0 || aProp->IsVisible( aDimIndex ) == theVisibility )
return;;
aProp->SetVisible( aDimIndex, theVisibility );
aProp->SaveToAttribute( myStudy, theEntry.toStdString() );
theDimItem->setIcon( 1, theVisibility ? myVisibleIcon : myInvisibleIcon );
redisplay( theEntry ); redisplay( theEntry );
}
}
//=================================================================================
// 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;
} }
//================================================================================= //=================================================================================
@ -510,7 +607,7 @@ void GEOMGUI_TextTreeWdg::redisplay( QString theEntry )
//================================================================================= //=================================================================================
QTreeWidgetItem* GEOMGUI_TextTreeWdg::getPropertyRootItem( const BranchType& theBranchType ) QTreeWidgetItem* GEOMGUI_TextTreeWdg::getPropertyRootItem( const BranchType& theBranchType )
{ {
return theBranchType == Geometry ? myDimensionsItem : myAnnotationsItem; return (theBranchType == DimensionShape) ? myDimensionsItem : myAnnotationsItem;
} }
//================================================================================= //=================================================================================
@ -519,7 +616,7 @@ QTreeWidgetItem* GEOMGUI_TextTreeWdg::getPropertyRootItem( const BranchType& the
//================================================================================= //=================================================================================
QHash<QString, QTreeWidgetItem*>& GEOMGUI_TextTreeWdg::getObjects( const BranchType& theBranchType ) QHash<QString, QTreeWidgetItem*>& GEOMGUI_TextTreeWdg::getObjects( const BranchType& theBranchType )
{ {
return theBranchType == Geometry ? myObjects : myAnnotationObjects; return (theBranchType == DimensionShape) ? myDimensionObjects : myAnnotationObjects;
} }
//================================================================================= //=================================================================================
@ -528,7 +625,7 @@ QHash<QString, QTreeWidgetItem*>& GEOMGUI_TextTreeWdg::getObjects( const BranchT
//================================================================================= //=================================================================================
GEOMGUI_TextTreeWdg::BranchType GEOMGUI_TextTreeWdg::branchTypeFromItem( QTreeWidgetItem* theItem ) GEOMGUI_TextTreeWdg::BranchType GEOMGUI_TextTreeWdg::branchTypeFromItem( QTreeWidgetItem* theItem )
{ {
BranchType aBranchType = Geometry; BranchType aBranchType = DimensionShape;
bool aBranchTypeFound = false; bool aBranchTypeFound = false;
QTreeWidgetItem* anItem = theItem; QTreeWidgetItem* anItem = theItem;
@ -536,7 +633,7 @@ GEOMGUI_TextTreeWdg::BranchType GEOMGUI_TextTreeWdg::branchTypeFromItem( QTreeWi
if ( anItem == myDimensionsItem || if ( anItem == myDimensionsItem ||
anItem == myAnnotationsItem) { anItem == myAnnotationsItem) {
aBranchTypeFound = true; aBranchTypeFound = true;
aBranchType = anItem == myDimensionsItem ? Geometry : AnnotationShape; aBranchType = (anItem == myDimensionsItem) ? DimensionShape : AnnotationShape;
} }
else { else {
anItem = anItem->parent(); anItem = anItem->parent();

51
src/GEOMGUI/GEOMGUI_TextTreeWdg.h Normal file → Executable file
View File

@ -22,10 +22,10 @@
#include "GEOM_GEOMGUI.hxx" #include "GEOM_GEOMGUI.hxx"
#include "GEOM_Displayer.h" #include "GEOM_Displayer.h"
#include "GEOMGUI_VisualProperties.h"
#include <QTreeWidget>
#include <QHash> #include <QHash>
#include <QSharedPointer>
#include <QTreeWidget>
#include <SALOMEDSClient.hxx> #include <SALOMEDSClient.hxx>
@ -36,7 +36,6 @@ class QTreeWidgetItem;
class SalomeApp_Application; class SalomeApp_Application;
class SalomeApp_Study; class SalomeApp_Study;
/*! /*!
* \brief Tree view contains Dimension and Annotation text items: * \brief Tree view contains Dimension and Annotation text items:
* - text visibility in OCC viewer * - text visibility in OCC viewer
@ -47,8 +46,7 @@ class GEOMGUI_EXPORT GEOMGUI_TextTreeWdg : public QTreeWidget
Q_OBJECT Q_OBJECT
public: public:
enum BranchType { Geometry, AnnotationShape }; enum BranchType { DimensionShape, AnnotationShape };
public: public:
GEOMGUI_TextTreeWdg( SalomeApp_Application* app ); GEOMGUI_TextTreeWdg( SalomeApp_Application* app );
@ -61,11 +59,13 @@ public:
int idFromItem( QTreeWidgetItem* theItem ); int idFromItem( QTreeWidgetItem* theItem );
QString entryFromItem( QTreeWidgetItem* theShapeItem ); QString entryFromItem( QTreeWidgetItem* theShapeItem );
QTreeWidgetItem* itemFromEntry( const BranchType& theBranchType, QString theEntry ); QTreeWidgetItem* itemFromEntry( const BranchType& theBranchType, QString theEntry );
void setShapeDimensionsVisibility( const BranchType& theBranchType, void setAllShapeItemsVisibility( const BranchType& theBranchType,
QString theEntry, bool theVisibility ); const QString& theEntry,
void setDimensionVisibility( const BranchType& theBranchType, const bool theVisibility );
QString theEntry, QTreeWidgetItem* theDimItem, void setShapeItemVisibility( const BranchType& theBranchType,
bool theVisibility ); const QString& theEntry,
QTreeWidgetItem* theWidgetItem,
const bool theVisibility );
protected: protected:
void createActions(); void createActions();
void redisplay( QString theEntry ); void redisplay( QString theEntry );
@ -80,9 +80,29 @@ private slots:
void setVisibility( QTreeWidgetItem* theItem, bool visibility ); void setVisibility( QTreeWidgetItem* theItem, bool visibility );
void showContextMenu( const QPoint& pos ); void showContextMenu( const QPoint& pos );
private: public:
VisualPropertiesPtr getVisualProperty( const BranchType& theBranchType );
/*!
* \brief Common interface for working with shape dimension and annotation properties
* of object in a unified way irrespectively of the implementation.
*/
class VisualProperty
{
public:
virtual int GetNumber() = 0;
virtual QString GetName( const int theIndex ) = 0;
virtual bool GetIsVisible( const int theIndex ) = 0;
virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) = 0;
virtual void Save() = 0;
};
private:
bool setShapeItemVisibility( QSharedPointer<VisualProperty>& theProps,
QTreeWidgetItem* theWidgetItem,
const bool theVisibility );
QSharedPointer<VisualProperty> getVisualProperty( const BranchType& theBranchType,
SalomeApp_Study* theStudy,
const std::string& theEntry );
void fillBranch( const BranchType& theBranchType, void fillBranch( const BranchType& theBranchType,
const QString& theEntry ); const QString& theEntry );
void updateVisibilityColumn( const BranchType& theBranchType, void updateVisibilityColumn( const BranchType& theBranchType,
@ -93,18 +113,17 @@ private:
BranchType branchTypeFromItem( QTreeWidgetItem* theItem ); BranchType branchTypeFromItem( QTreeWidgetItem* theItem );
private: private:
int myWindowID;
int myWindowID;
QIcon myVisibleIcon; QIcon myVisibleIcon;
QIcon myInvisibleIcon; QIcon myInvisibleIcon;
QHash<QString, QTreeWidgetItem*> myObjects; QHash<QString, QTreeWidgetItem*> myDimensionObjects;
QHash<QString, QTreeWidgetItem*> myAnnotationObjects; QHash<QString, QTreeWidgetItem*> myAnnotationObjects;
SalomeApp_Study* myStudy; SalomeApp_Study* myStudy;
QTreeWidgetItem* myDimensionsItem; QTreeWidgetItem* myDimensionsItem;
QTreeWidgetItem* myAnnotationsItem; QTreeWidgetItem* myAnnotationsItem;
GEOM_Displayer myDisplayer; GEOM_Displayer myDisplayer;
QMap<int, QAction*> myActions; //!< menu actions list QMap<int, QAction*> myActions; //!< menu actions list
}; };
#endif #endif

View File

@ -1,122 +0,0 @@
// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// 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, 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_VisualProperties.h
// Author : Anton POLETAEV, Open CASCADE S.A.S.
//
#ifndef GEOMGUI_VisualProperties_H
#define GEOMGUI_VisualProperties_H
// OCCT includes
#include <Standard_Macro.hxx>
#include <QSharedPointer>
class GEOMGUI_VisualProperties;
typedef QSharedPointer<GEOMGUI_VisualProperties> VisualPropertiesPtr;
class SalomeApp_Study;
/*!
* \brief Utility class to presentations as object property of study.
*
* This is an abstract class with interface to manipulate with a property object
* Methods should be implemented in inherited classes.
*/
class Standard_EXPORT GEOMGUI_VisualProperties
{
public:
/*!
* \brief Constructor. Inits empty property.
*/
GEOMGUI_VisualProperties() {}
/*!
* \brief Destructor.
*/
~GEOMGUI_VisualProperties() {}
/*!
* \brief Returns number of dimension records.
*/
virtual int GetNumber() const = 0;
/*!
* \brief Removes record by its index.
* \param theIndex [in] the index of dimension record.
*/
//virtual void RemoveRecord( const int theIndex ) = 0;
/*!
* \brief Clears property data.
*/
//virtual void Clear() = 0;
public:
/*!
* \brief Returns visibility state of dimension record by its index.
*
* \param theIndex [in] the index of the dimension record.
*/
virtual bool IsVisible( const int theIndex ) const = 0;
/*!
* \brief Changes visibility state of the dimension record.
*
* \param theIndex [in] the index of the dimension record.
* \param theIsVisible [in] the new visibility state.
*/
virtual void SetVisible( const int theIndex, const bool theIsVisible ) = 0;
/*!
* \brief Returns name of dimension record by its index.
*
* \param theIndex [in] the index of the dimension record.
*/
virtual QString GetName( const int theIndex ) const = 0;
/*!
* \brief Changes name of dimension record.
*
* \param theIndex [in] the index of the dimension record.
* \param theName [in] the new name.
*/
virtual void SetName( const int theIndex, const QString& theName ) = 0;
public:
/*!
* \brief Loads properties data from attribute "AttributeTableOfReal".
* \param theStudy [in] the study.
* \param theEntry [in] the entry of GEOM object to operate with.
*/
virtual void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ) = 0;
/*!
* \brief Saves properties data to attribute "AttributeTableOfReal".
* \param theStudy [in] the study.
* \param theEntry [in] the entry of GEOM object to operate with.
*/
virtual void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ) = 0;
};
#endif

View File

@ -1420,7 +1420,7 @@ void GEOM_Displayer::updateShapeAnnotations( const Handle(SALOME_InteractiveObje
gp_Trsf aToLCS; gp_Trsf aToLCS;
aToLCS.SetTransformation( theShapeLCS, gp_Ax3() ); aToLCS.SetTransformation( theShapeLCS, gp_Ax3() );
for ( int anI = 0; anI < aShapeAnnotations->GetCount(); ++anI ) for ( int anI = 0; anI < aShapeAnnotations->GetNbAnnotation(); ++anI )
{ {
if ( !aShapeAnnotations->GetIsVisible( anI ) ) if ( !aShapeAnnotations->GetIsVisible( anI ) )
{ {