From: apl Date: Tue, 8 Nov 2016 16:29:55 +0000 (+0300) Subject: Several bug fixes X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d61dfb05a3031cb617fea6b063c6c4c88aaffe0c;p=modules%2Fgeom.git Several bug fixes --- diff --git a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx index c4cab5c2f..5ed3c497a 100755 --- a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx +++ b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx @@ -1,526 +1,549 @@ -// 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_AnnotationAttr.cxx -// Author : Anton POLETAEV, Open CASCADE S.A.S. -// - -// SALOME includes -#include -#include -#include - -// STL includes -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT( GEOMGUI_AnnotationAttrs, Standard_Transient ) - -namespace -{ - static const std::string PARAMETER_COUNT = "GEOMGUI_AnnotationAttrs_Count"; - - std::string PARAMETER_I( const std::string& s, const int i ) { - return std::string( s ) + std::to_string( i ); - } - std::string PARAMETER_IS_VISIBLE( const int i ) { - return PARAMETER_I( "GEOMGUI_AnnotationAttrs_IsVisible", i ); - } - std::string PARAMETER_IS_2D( const int i ) { - return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Is2D", i ); - } - std::string PARAMETER_TEXT( const int i ) { - return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Text", i ); - } - std::string PARAMETER_POSITION( const int i ) { - return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Position", i ); - } - std::string PARAMETER_ATTACH( const int i ) { - return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Attach", i ); - } - std::string PARAMETER_SHAPE( const int i ) { - return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Shape", i ); - } - - // REGEXP pattern for converting array of entries into plain text string. - // The pattern has the following structure: - // ENTRY: { text[string] : visibility[bool] : screen fixed[bool] : position[xyz] : attach[xyz] } - static const QString PATTERN_ITEM_GROUP = "\\{ (Text=(?::{2,}|.)*:(?!:)Screen=.*:Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=.*:ShapeType=.*) \\}"; - static const QString PATTERN_ITEM = "Text=((?::{2,}|.)*):(?!:)Screen=(\\d{1}):Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=(\\-?\\d{1,}):ShapeType=(\\d{1})"; - static QString toPattern (const QString& theText, - const bool theIsFixed, - const gp_Pnt& thePosition, - const gp_Pnt& theAttach, - const int theShapeIndex, - const int theShapeType) - { - return QString( "{ Text=" ) + theText + - QString( ":" ) + QString( "Screen=" ) + QString::number( theIsFixed ? 1 : 0 ) + - QString( ":" ) + QString( "Position={" ) + - QString::number( thePosition.X() ) + QString( ":" ) + - QString::number( thePosition.Y() ) + QString( ":" ) + - QString::number( thePosition.Z() ) + QString( "}" ) + - QString( ":" ) + QString( "Attach={" ) + - QString::number( theAttach.X() ) + QString( ":" ) + - QString::number( theAttach.Y() ) + QString( ":" ) + - QString::number( theAttach.Z() ) + QString( "}" ) + - QString( ":" ) + QString( "ShapeIdx=" ) + QString::number( theShapeIndex ) + - QString( ":" ) + QString( "ShapeType=" ) + QString::number( theShapeType ) + - QString( " }" ); - } -}; - -//================================================================================= -// function : FindAttributes -// purpose : -//================================================================================= -Handle(GEOMGUI_AnnotationAttrs) GEOMGUI_AnnotationAttrs::FindAttributes( const _PTR(SObject)& theObject ) -{ - _PTR(GenericAttribute) aGenericAttr; - _PTR(AttributeParameter) aParameterMap; - - if ( !theObject->FindAttribute( aGenericAttr, "AttributeParameter" ) ) - { - return Handle(GEOMGUI_AnnotationAttrs)(); - } - - aParameterMap = aGenericAttr; - - if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) ) - { - return Handle(GEOMGUI_AnnotationAttrs)(); - } - - return new GEOMGUI_AnnotationAttrs( theObject, aParameterMap ); -} - -//================================================================================= -// function : FindOrCreateAttributes -// purpose : -//================================================================================= -Handle(GEOMGUI_AnnotationAttrs) GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( - const _PTR(SObject)& theObject, SalomeApp_Study* theStudy ) -{ - _PTR(StudyBuilder) aBuilder = theStudy->studyDS()->NewBuilder(); - _PTR(AttributeParameter) aParameterMap = aBuilder->FindOrCreateAttribute( theObject, "AttributeParameter" ); - if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) ) - { - aParameterMap->SetInt( PARAMETER_COUNT, 0 ); - } - - return new GEOMGUI_AnnotationAttrs( theObject, aParameterMap ); -} - -//================================================================================= -// function : Remove -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::Remove( const _PTR(SObject)& theObject ) -{ - _PTR(GenericAttribute) aGenericAttr; - _PTR(AttributeParameter) aParameterMap; - - if ( !theObject->FindAttribute( aGenericAttr, "AttributeParameter" ) ) - { - return; - } - - aParameterMap = aGenericAttr; - - if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) ) - { - return; - } - - const int aParamCount = aParameterMap->GetInt( PARAMETER_COUNT ); - - for ( int anI = 0; anI < aParamCount; ++anI ) - { - aParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN ); - aParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN ); - aParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING ); - aParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY ); - aParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY ); - aParameterMap->RemoveID( PARAMETER_SHAPE( anI ), PT_INTARRAY ); - } - - aParameterMap->RemoveID( PARAMETER_COUNT, PT_INTEGER ); -} - -//================================================================================= -// function : ExportAsPropertyString -// purpose : -//================================================================================= -QString GEOMGUI_AnnotationAttrs::ExportAsPropertyString() const -{ - QStringList anItems; - - for ( int anI = 0; anI < GetNbAnnotation(); ++anI ) - { - Properties aEntry; - - GetProperties( anI, aEntry ); - - anItems.append( toPattern( aEntry.Text, - aEntry.IsScreenFixed, - aEntry.Position, - aEntry.Attach, - aEntry.ShapeIndex, - aEntry.ShapeType ) ); - } - - return anItems.join( ":" ); -} - -//================================================================================= -// function : ImportFromPropertyString -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::ImportFromPropertyString( const QString& theString ) -{ - SetNbAnnotation( 0 ); - - QRegExp aRegExpItemGroups( PATTERN_ITEM_GROUP ); - QRegExp aRegExpItem( "^" + PATTERN_ITEM + "$" ); - aRegExpItemGroups.setMinimal( true ); - aRegExpItem.setMinimal( true ); - - int aPos = 0; - while ( ( aPos = aRegExpItemGroups.indexIn( theString, aPos ) ) != -1 ) - { - aPos += aRegExpItemGroups.matchedLength(); - - QString aStrItem = aRegExpItemGroups.cap(1); - - if ( aRegExpItem.indexIn( aStrItem ) < 0 ) - { - continue; - } - - QString aStrText = aRegExpItem.cap( 1 ); - QString aStrFixed = aRegExpItem.cap( 2 ); - QString aStrPosX = aRegExpItem.cap( 3 ); - QString aStrPosY = aRegExpItem.cap( 4 ); - QString aStrPosZ = aRegExpItem.cap( 5 ); - QString aStrAttX = aRegExpItem.cap( 6 ); - QString aStrAttY = aRegExpItem.cap( 7 ); - QString aStrAttZ = aRegExpItem.cap( 8 ); - QString aStrShapeIdx = aRegExpItem.cap( 9 ); - QString aStrShapeType = aRegExpItem.cap( 10 ); - aStrText.replace( "::", ":" ); - - Properties aEntry; - aEntry.Text = aStrText; - aEntry.IsVisible = false; - aEntry.IsScreenFixed = aStrFixed.toInt() != 0; - aEntry.Position.SetX( aStrPosX.toDouble() ); - aEntry.Position.SetY( aStrPosY.toDouble() ); - aEntry.Position.SetZ( aStrPosZ.toDouble() ); - aEntry.Attach.SetX( aStrAttX.toDouble() ); - aEntry.Attach.SetY( aStrAttY.toDouble() ); - aEntry.Attach.SetZ( aStrAttZ.toDouble() ); - aEntry.ShapeIndex = aStrShapeIdx.toInt(); - aEntry.ShapeType = aStrShapeType.toInt(); - - Append( aEntry ); - } -} - -//================================================================================= -// function : SetNbAnnotation -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetNbAnnotation( const int theCount ) const -{ - const int aCount = this->GetNbAnnotation(); - - if ( aCount < theCount ) - { - // set default values - for ( int anI = aCount; anI < theCount; ++anI ) - { - myParameterMap->SetBool( PARAMETER_IS_VISIBLE( anI ), true ); - myParameterMap->SetBool( PARAMETER_IS_2D( anI ), false ); - myParameterMap->SetString( PARAMETER_TEXT( anI ), std::string() ); - myParameterMap->SetRealArray( PARAMETER_POSITION( anI ), std::vector(3, 0.0) ); - myParameterMap->SetRealArray( PARAMETER_ATTACH( anI ), std::vector(3, 0.0) ); - myParameterMap->SetIntArray( PARAMETER_SHAPE( anI ), std::vector(2, 0) ); - } - } - else - { - // remove exceeding values - for ( int anI = theCount; anI < aCount; ++anI ) - { - myParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN ); - myParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN ); - myParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING ); - myParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY ); - myParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY ); - myParameterMap->RemoveID( PARAMETER_SHAPE( anI ), PT_INTARRAY ); - } - } - - myParameterMap->SetInt( PARAMETER_COUNT, theCount ); -} - -//================================================================================= -// function : GetNbAnnotation -// purpose : -//================================================================================= -int GEOMGUI_AnnotationAttrs::GetNbAnnotation() const -{ - return myParameterMap->GetInt( PARAMETER_COUNT ); -} - -//================================================================================= -// function : SetVisible -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetIsVisible( const int theIndex, const bool theIsVisible ) -{ - myParameterMap->SetBool( PARAMETER_IS_VISIBLE( theIndex ), theIsVisible ); -} - -//================================================================================= -// function : GetIsVisible -// purpose : -//================================================================================= -bool GEOMGUI_AnnotationAttrs::GetIsVisible( const int theIndex ) const -{ - return myParameterMap->GetBool( PARAMETER_IS_VISIBLE( theIndex ) ); -} - -//================================================================================= -// function : SetText -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetText( const int theIndex, const QString& theText ) -{ - myParameterMap->SetString( PARAMETER_TEXT( theIndex ), theText.toStdString() ); -} - -//================================================================================= -// function : GetText -// purpose : -//================================================================================= -QString GEOMGUI_AnnotationAttrs::GetText( const int theIndex ) const -{ - return QString::fromStdString( myParameterMap->GetString( PARAMETER_TEXT( theIndex ) ) ); -} - -//================================================================================= -// function : SetIsScreenFixed -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetIsScreenFixed( const int theIndex, const bool theIsScreenFixed ) -{ - myParameterMap->SetBool( PARAMETER_IS_2D( theIndex ), theIsScreenFixed ); -} - -//================================================================================= -// function : GetIsScreenFixed -// purpose : -//================================================================================= -bool GEOMGUI_AnnotationAttrs::GetIsScreenFixed( const int theIndex ) const -{ - return myParameterMap->GetBool( PARAMETER_IS_2D( theIndex ) ); -} - -//================================================================================= -// function : SetPosition -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetPosition( const int theIndex, const gp_Pnt& thePosition ) -{ - std::vector aCoords( 3 ); - - aCoords[0] = thePosition.X(); - aCoords[1] = thePosition.Y(); - aCoords[2] = thePosition.Z(); - - myParameterMap->SetRealArray( PARAMETER_POSITION( theIndex ), aCoords ); -} - -//================================================================================= -// function : GetPosition -// purpose : -//================================================================================= -gp_Pnt GEOMGUI_AnnotationAttrs::GetPosition( const int theIndex ) const -{ - std::vector aCoords = - myParameterMap->GetRealArray( PARAMETER_POSITION( theIndex ) ); - - return gp_Pnt( aCoords[0], aCoords[1], aCoords[2] ); -} - -//================================================================================= -// function : SetAttach -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetAttach( const int theIndex, const gp_Pnt& theAttach ) -{ - std::vector aCoords( 3 ); - - aCoords[0] = theAttach.X(); - aCoords[1] = theAttach.Y(); - aCoords[2] = theAttach.Z(); - - myParameterMap->SetRealArray( PARAMETER_ATTACH( theIndex ), aCoords ); -} - -//================================================================================= -// function : GetAttach -// purpose : -//================================================================================= -gp_Pnt GEOMGUI_AnnotationAttrs::GetAttach( const int theIndex ) const -{ - std::vector aCoords = - myParameterMap->GetRealArray( PARAMETER_ATTACH( theIndex ) ); - - return gp_Pnt( aCoords[0], aCoords[1], aCoords[2] ); -} - -//================================================================================= -// function : SetShapeSel -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetShapeSel( const int theIndex, const int theShapeType, const int theSubIdx ) -{ - std::vector aSelection( 2 ); - - aSelection[0] = theShapeType; - aSelection[1] = theSubIdx; - - myParameterMap->SetIntArray( PARAMETER_SHAPE( theIndex ), aSelection ); -} - -//================================================================================= -// function : GetShapeSel -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::GetShapeSel( const int theIndex, int& theShapeType, int& theSubIdx ) const -{ - std::vector aSelection = - myParameterMap->GetIntArray( PARAMETER_SHAPE( theIndex ) ); - - theShapeType = aSelection[0]; - theSubIdx = aSelection[1]; -} - -//================================================================================= -// function : Append -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps ) -{ - this->Append( theProps, gp_Ax3() ); -} - -//================================================================================= -// function : Append -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps, const gp_Ax3& theShapeLCS ) -{ - const int aCount = this->GetNbAnnotation(); - this->SetNbAnnotation( aCount + 1 ); - this->SetProperties( aCount, theProps, theShapeLCS ); -} - -//================================================================================= -// function : SetProperties -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps ) -{ - this->SetProperties( theIndex, theProps, gp_Ax3() ); -} - -//================================================================================= -// function : SetProperties -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps, - const gp_Ax3& theShapeLCS ) -{ - gp_Trsf aToShapeLCS; - aToShapeLCS.SetTransformation( gp_Ax3(), theShapeLCS ); - - this->SetText( theIndex, theProps.Text ); - this->SetIsVisible( theIndex, theProps.IsVisible ); - this->SetIsScreenFixed( theIndex, theProps.IsScreenFixed ); - this->SetShapeSel( theIndex, theProps.ShapeType, theProps.ShapeIndex ); - this->SetAttach( theIndex, theProps.Attach.Transformed( aToShapeLCS ) ); - this->SetPosition( theIndex, (theProps.IsScreenFixed) ? - theProps.Position : theProps.Position.Transformed( aToShapeLCS ) ); -} - -//================================================================================= -// function : GetProperties -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::GetProperties( const int theIndex, Properties& theProps ) const -{ - theProps.Text = this->GetText( theIndex ); - theProps.IsVisible = this->GetIsVisible( theIndex ); - theProps.IsScreenFixed = this->GetIsScreenFixed( theIndex ); - theProps.Position = this->GetPosition( theIndex ); - theProps.Attach = this->GetAttach( theIndex ); - - this->GetShapeSel( theIndex, theProps.ShapeType, theProps.ShapeIndex ); -} - -//================================================================================= -// function : SetupPresentation -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, - const Properties& theProps, - const gp_Ax3& theShapeLCS ) -{ - gp_Trsf aFromShapeLCS; - aFromShapeLCS.SetTransformation( theShapeLCS, gp_Ax3() ); - - TCollection_ExtendedString aText; - for (int i = 0; i < (int)theProps.Text.length(); i++ ) - aText.Insert( i + 1, theProps.Text[ i ].unicode() ); - - thePresentation->SetText( aText ); - thePresentation->SetIsScreenFixed( theProps.IsScreenFixed ); - thePresentation->SetAttachPoint( theProps.Attach.Transformed( aFromShapeLCS ) ); - thePresentation->SetPosition( (theProps.IsScreenFixed) ? - theProps.Position : theProps.Position.Transformed( aFromShapeLCS ) ); -} - -//================================================================================= -// function : SetupPresentation -// purpose : -//================================================================================= -void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, - const int theIndex, - const gp_Ax3& theShapeLCS ) -{ - Properties aProps; - this->GetProperties( theIndex, aProps ); - this->SetupPresentation( thePresentation, aProps, theShapeLCS ); -} +// 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_AnnotationAttr.cxx +// Author : Anton POLETAEV, Open CASCADE S.A.S. +// + +// SALOME includes +#include +#include +#include + +// STL includes +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT( GEOMGUI_AnnotationAttrs, Standard_Transient ) + +namespace +{ + static const std::string PARAMETER_COUNT = "GEOMGUI_AnnotationAttrs_Count"; + + std::string PARAMETER_I( const std::string& s, const int i ) { + return std::string( s ) + std::to_string( i ); + } + std::string PARAMETER_IS_VISIBLE( const int i ) { + return PARAMETER_I( "GEOMGUI_AnnotationAttrs_IsVisible", i ); + } + std::string PARAMETER_IS_2D( const int i ) { + return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Is2D", i ); + } + std::string PARAMETER_TEXT( const int i ) { + return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Text", i ); + } + std::string PARAMETER_POSITION( const int i ) { + return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Position", i ); + } + std::string PARAMETER_ATTACH( const int i ) { + return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Attach", i ); + } + std::string PARAMETER_SHAPE( const int i ) { + return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Shape", i ); + } + + // REGEXP pattern for converting array of entries into plain text string. + // The pattern has the following structure: + // ENTRY: { text[string] : visibility[bool] : screen fixed[bool] : position[xyz] : attach[xyz] } + static const QString PATTERN_ITEM_GROUP = "\\{ (Text=(?::{2,}|.)*:(?!:)Screen=.*:Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=.*:ShapeType=.*) \\}"; + static const QString PATTERN_ITEM = "Text=((?::{2,}|.)*):(?!:)Screen=(\\d{1}):Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=(\\-?\\d{1,}):ShapeType=(\\d{1})"; + static QString toPattern (const QString& theText, + const bool theIsFixed, + const gp_Pnt& thePosition, + const gp_Pnt& theAttach, + const int theShapeIndex, + const int theShapeType) + { + return QString( "{ Text=" ) + theText + + QString( ":" ) + QString( "Screen=" ) + QString::number( theIsFixed ? 1 : 0 ) + + QString( ":" ) + QString( "Position={" ) + + QString::number( thePosition.X() ) + QString( ":" ) + + QString::number( thePosition.Y() ) + QString( ":" ) + + QString::number( thePosition.Z() ) + QString( "}" ) + + QString( ":" ) + QString( "Attach={" ) + + QString::number( theAttach.X() ) + QString( ":" ) + + QString::number( theAttach.Y() ) + QString( ":" ) + + QString::number( theAttach.Z() ) + QString( "}" ) + + QString( ":" ) + QString( "ShapeIdx=" ) + QString::number( theShapeIndex ) + + QString( ":" ) + QString( "ShapeType=" ) + QString::number( theShapeType ) + + QString( " }" ); + } +}; + +//================================================================================= +// function : FindAttributes +// purpose : +//================================================================================= +Handle(GEOMGUI_AnnotationAttrs) GEOMGUI_AnnotationAttrs::FindAttributes( const _PTR(SObject)& theObject ) +{ + _PTR(GenericAttribute) aGenericAttr; + _PTR(AttributeParameter) aParameterMap; + + if ( !theObject->FindAttribute( aGenericAttr, "AttributeParameter" ) ) + { + return Handle(GEOMGUI_AnnotationAttrs)(); + } + + aParameterMap = aGenericAttr; + + if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) ) + { + return Handle(GEOMGUI_AnnotationAttrs)(); + } + + return new GEOMGUI_AnnotationAttrs( theObject, aParameterMap ); +} + +//================================================================================= +// function : FindOrCreateAttributes +// purpose : +//================================================================================= +Handle(GEOMGUI_AnnotationAttrs) GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( + const _PTR(SObject)& theObject, SalomeApp_Study* theStudy ) +{ + _PTR(StudyBuilder) aBuilder = theStudy->studyDS()->NewBuilder(); + _PTR(AttributeParameter) aParameterMap = aBuilder->FindOrCreateAttribute( theObject, "AttributeParameter" ); + if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) ) + { + aParameterMap->SetInt( PARAMETER_COUNT, 0 ); + } + + return new GEOMGUI_AnnotationAttrs( theObject, aParameterMap ); +} + +//================================================================================= +// function : Remove +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::Remove( const _PTR(SObject)& theObject ) +{ + _PTR(GenericAttribute) aGenericAttr; + _PTR(AttributeParameter) aParameterMap; + + if ( !theObject->FindAttribute( aGenericAttr, "AttributeParameter" ) ) + { + return; + } + + aParameterMap = aGenericAttr; + + if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) ) + { + return; + } + + const int aParamCount = aParameterMap->GetInt( PARAMETER_COUNT ); + + for ( int anI = 0; anI < aParamCount; ++anI ) + { + aParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN ); + aParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN ); + aParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING ); + aParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY ); + aParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY ); + aParameterMap->RemoveID( PARAMETER_SHAPE( anI ), PT_INTARRAY ); + } + + aParameterMap->RemoveID( PARAMETER_COUNT, PT_INTEGER ); +} + +//================================================================================= +// function : ExportAsPropertyString +// purpose : +//================================================================================= +QString GEOMGUI_AnnotationAttrs::ExportAsPropertyString() const +{ + QStringList anItems; + + for ( int anI = 0; anI < GetNbAnnotation(); ++anI ) + { + Properties aEntry; + + GetProperties( anI, aEntry ); + + anItems.append( toPattern( aEntry.Text, + aEntry.IsScreenFixed, + aEntry.Position, + aEntry.Attach, + aEntry.ShapeIndex, + aEntry.ShapeType ) ); + } + + return anItems.join( ":" ); +} + +//================================================================================= +// function : ImportFromPropertyString +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::ImportFromPropertyString( const QString& theString ) +{ + SetNbAnnotation( 0 ); + + QRegExp aRegExpItemGroups( PATTERN_ITEM_GROUP ); + QRegExp aRegExpItem( "^" + PATTERN_ITEM + "$" ); + aRegExpItemGroups.setMinimal( true ); + aRegExpItem.setMinimal( true ); + + int aPos = 0; + while ( ( aPos = aRegExpItemGroups.indexIn( theString, aPos ) ) != -1 ) + { + aPos += aRegExpItemGroups.matchedLength(); + + QString aStrItem = aRegExpItemGroups.cap(1); + + if ( aRegExpItem.indexIn( aStrItem ) < 0 ) + { + continue; + } + + QString aStrText = aRegExpItem.cap( 1 ); + QString aStrFixed = aRegExpItem.cap( 2 ); + QString aStrPosX = aRegExpItem.cap( 3 ); + QString aStrPosY = aRegExpItem.cap( 4 ); + QString aStrPosZ = aRegExpItem.cap( 5 ); + QString aStrAttX = aRegExpItem.cap( 6 ); + QString aStrAttY = aRegExpItem.cap( 7 ); + QString aStrAttZ = aRegExpItem.cap( 8 ); + QString aStrShapeIdx = aRegExpItem.cap( 9 ); + QString aStrShapeType = aRegExpItem.cap( 10 ); + aStrText.replace( "::", ":" ); + + Properties aEntry; + aEntry.Text = aStrText; + aEntry.IsVisible = false; + aEntry.IsScreenFixed = aStrFixed.toInt() != 0; + aEntry.Position.SetX( aStrPosX.toDouble() ); + aEntry.Position.SetY( aStrPosY.toDouble() ); + aEntry.Position.SetZ( aStrPosZ.toDouble() ); + aEntry.Attach.SetX( aStrAttX.toDouble() ); + aEntry.Attach.SetY( aStrAttY.toDouble() ); + aEntry.Attach.SetZ( aStrAttZ.toDouble() ); + aEntry.ShapeIndex = aStrShapeIdx.toInt(); + aEntry.ShapeType = aStrShapeType.toInt(); + + Append( aEntry ); + } +} + +//================================================================================= +// function : SetNbAnnotation +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetNbAnnotation( const int theCount ) const +{ + const int aCount = this->GetNbAnnotation(); + + if ( aCount < theCount ) + { + // set default values + for ( int anI = aCount; anI < theCount; ++anI ) + { + myParameterMap->SetBool( PARAMETER_IS_VISIBLE( anI ), true ); + myParameterMap->SetBool( PARAMETER_IS_2D( anI ), false ); + myParameterMap->SetString( PARAMETER_TEXT( anI ), std::string() ); + myParameterMap->SetRealArray( PARAMETER_POSITION( anI ), std::vector(3, 0.0) ); + myParameterMap->SetRealArray( PARAMETER_ATTACH( anI ), std::vector(3, 0.0) ); + myParameterMap->SetIntArray( PARAMETER_SHAPE( anI ), std::vector(2, 0) ); + } + } + else + { + // remove exceeding values + for ( int anI = theCount; anI < aCount; ++anI ) + { + myParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN ); + myParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN ); + myParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING ); + myParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY ); + myParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY ); + myParameterMap->RemoveID( PARAMETER_SHAPE( anI ), PT_INTARRAY ); + } + } + + myParameterMap->SetInt( PARAMETER_COUNT, theCount ); +} + +//================================================================================= +// function : GetNbAnnotation +// purpose : +//================================================================================= +int GEOMGUI_AnnotationAttrs::GetNbAnnotation() const +{ + return myParameterMap->GetInt( PARAMETER_COUNT ); +} + +//================================================================================= +// function : SetVisible +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetIsVisible( const int theIndex, const bool theIsVisible ) +{ + myParameterMap->SetBool( PARAMETER_IS_VISIBLE( theIndex ), theIsVisible ); +} + +//================================================================================= +// function : GetIsVisible +// purpose : +//================================================================================= +bool GEOMGUI_AnnotationAttrs::GetIsVisible( const int theIndex ) const +{ + return myParameterMap->GetBool( PARAMETER_IS_VISIBLE( theIndex ) ); +} + +//================================================================================= +// function : SetText +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetText( const int theIndex, const QString& theText ) +{ + myParameterMap->SetString( PARAMETER_TEXT( theIndex ), theText.toStdString() ); +} + +//================================================================================= +// function : GetText +// purpose : +//================================================================================= +QString GEOMGUI_AnnotationAttrs::GetText( const int theIndex ) const +{ + return QString::fromStdString( myParameterMap->GetString( PARAMETER_TEXT( theIndex ) ) ); +} + +//================================================================================= +// function : SetIsScreenFixed +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetIsScreenFixed( const int theIndex, const bool theIsScreenFixed ) +{ + myParameterMap->SetBool( PARAMETER_IS_2D( theIndex ), theIsScreenFixed ); +} + +//================================================================================= +// function : GetIsScreenFixed +// purpose : +//================================================================================= +bool GEOMGUI_AnnotationAttrs::GetIsScreenFixed( const int theIndex ) const +{ + return myParameterMap->GetBool( PARAMETER_IS_2D( theIndex ) ); +} + +//================================================================================= +// function : SetPosition +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetPosition( const int theIndex, const gp_Pnt& thePosition ) +{ + std::vector aCoords( 3 ); + + aCoords[0] = thePosition.X(); + aCoords[1] = thePosition.Y(); + aCoords[2] = thePosition.Z(); + + myParameterMap->SetRealArray( PARAMETER_POSITION( theIndex ), aCoords ); +} + +//================================================================================= +// function : GetPosition +// purpose : +//================================================================================= +gp_Pnt GEOMGUI_AnnotationAttrs::GetPosition( const int theIndex ) const +{ + std::vector aCoords = + myParameterMap->GetRealArray( PARAMETER_POSITION( theIndex ) ); + + return gp_Pnt( aCoords[0], aCoords[1], aCoords[2] ); +} + +//================================================================================= +// function : SetAttach +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetAttach( const int theIndex, const gp_Pnt& theAttach ) +{ + std::vector aCoords( 3 ); + + aCoords[0] = theAttach.X(); + aCoords[1] = theAttach.Y(); + aCoords[2] = theAttach.Z(); + + myParameterMap->SetRealArray( PARAMETER_ATTACH( theIndex ), aCoords ); +} + +//================================================================================= +// function : GetAttach +// purpose : +//================================================================================= +gp_Pnt GEOMGUI_AnnotationAttrs::GetAttach( const int theIndex ) const +{ + std::vector aCoords = + myParameterMap->GetRealArray( PARAMETER_ATTACH( theIndex ) ); + + return gp_Pnt( aCoords[0], aCoords[1], aCoords[2] ); +} + +//================================================================================= +// function : SetShapeSel +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetShapeSel( const int theIndex, const int theShapeType, const int theSubIdx ) +{ + std::vector aSelection( 2 ); + + aSelection[0] = theShapeType; + aSelection[1] = theSubIdx; + + myParameterMap->SetIntArray( PARAMETER_SHAPE( theIndex ), aSelection ); +} + +//================================================================================= +// function : GetShapeSel +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::GetShapeSel( const int theIndex, int& theShapeType, int& theSubIdx ) const +{ + std::vector aSelection = + myParameterMap->GetIntArray( PARAMETER_SHAPE( theIndex ) ); + + theShapeType = aSelection[0]; + theSubIdx = aSelection[1]; +} + +//================================================================================= +// function : Append +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps ) +{ + this->Append( theProps, gp_Ax3() ); +} + +//================================================================================= +// function : Append +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps, const gp_Ax3& theShapeLCS ) +{ + const int aCount = this->GetNbAnnotation(); + this->SetNbAnnotation( aCount + 1 ); + this->SetProperties( aCount, theProps, theShapeLCS ); +} + +//================================================================================= +// function : Remove +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::Remove( const Standard_Integer theIndex ) +{ + const int aCount = this->GetNbAnnotation(); + if ( theIndex < 0 || theIndex >= aCount ) { + return; + } + + std::vector aEntries( (aCount - 1) - theIndex ); + for ( int anI = theIndex + 1; anI < aCount; ++anI ) { + GetProperties( anI, aEntries[ anI - (theIndex + 1) ] ); + } + + SetNbAnnotation( theIndex ); + + for ( int anI = 0; anI < static_cast( aEntries.size() ); ++anI ) { + Append( aEntries[anI] ); + } +} + +//================================================================================= +// function : SetProperties +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps ) +{ + this->SetProperties( theIndex, theProps, gp_Ax3() ); +} + +//================================================================================= +// function : SetProperties +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps, + const gp_Ax3& theShapeLCS ) +{ + gp_Trsf aToShapeLCS; + aToShapeLCS.SetTransformation( gp_Ax3(), theShapeLCS ); + + this->SetText( theIndex, theProps.Text ); + this->SetIsVisible( theIndex, theProps.IsVisible ); + this->SetIsScreenFixed( theIndex, theProps.IsScreenFixed ); + this->SetShapeSel( theIndex, theProps.ShapeType, theProps.ShapeIndex ); + this->SetAttach( theIndex, theProps.Attach.Transformed( aToShapeLCS ) ); + this->SetPosition( theIndex, (theProps.IsScreenFixed) ? + theProps.Position : theProps.Position.Transformed( aToShapeLCS ) ); +} + +//================================================================================= +// function : GetProperties +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::GetProperties( const int theIndex, Properties& theProps ) const +{ + theProps.Text = this->GetText( theIndex ); + theProps.IsVisible = this->GetIsVisible( theIndex ); + theProps.IsScreenFixed = this->GetIsScreenFixed( theIndex ); + theProps.Position = this->GetPosition( theIndex ); + theProps.Attach = this->GetAttach( theIndex ); + + this->GetShapeSel( theIndex, theProps.ShapeType, theProps.ShapeIndex ); +} + +//================================================================================= +// function : SetupPresentation +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, + const Properties& theProps, + const gp_Ax3& theShapeLCS ) +{ + gp_Trsf aFromShapeLCS; + aFromShapeLCS.SetTransformation( theShapeLCS, gp_Ax3() ); + + TCollection_ExtendedString aText; + for (int i = 0; i < (int)theProps.Text.length(); i++ ) + aText.Insert( i + 1, theProps.Text[ i ].unicode() ); + + thePresentation->SetText( aText ); + thePresentation->SetIsScreenFixed( theProps.IsScreenFixed ); + thePresentation->SetAttachPoint( theProps.Attach.Transformed( aFromShapeLCS ) ); + thePresentation->SetPosition( (theProps.IsScreenFixed) ? + theProps.Position : theProps.Position.Transformed( aFromShapeLCS ) ); +} + +//================================================================================= +// function : SetupPresentation +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, + const int theIndex, + const gp_Ax3& theShapeLCS ) +{ + Properties aProps; + this->GetProperties( theIndex, aProps ); + this->SetupPresentation( thePresentation, aProps, theShapeLCS ); +} diff --git a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h index f8876c73e..9d93347aa 100755 --- a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h +++ b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h @@ -174,6 +174,12 @@ public: //! to the world frame of reference. GEOMGUI_EXPORT void Append( const Properties& theProps, const gp_Ax3& theShapeLCS ); + //! Removes annotation definition by the given index. + //! This methods performs iterative reindexing of elements starting + //! from the given index, so sequential removal should be performed + //! from the last element, or avoided at all. + GEOMGUI_EXPORT void Remove( const Standard_Integer theIndex ); + //! Sets complete properties of an annotation definition. //! @param theIndex [in] the index of the annotation definition. //! @param theProps [in] the structure containing the properties. diff --git a/src/GEOMGUI/GEOMGUI_AnnotationMgr.cxx b/src/GEOMGUI/GEOMGUI_AnnotationMgr.cxx index 4fe3f9843..6ed2039cf 100755 --- a/src/GEOMGUI/GEOMGUI_AnnotationMgr.cxx +++ b/src/GEOMGUI/GEOMGUI_AnnotationMgr.cxx @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -58,7 +59,7 @@ GEOMGUI_AnnotationMgr::GEOMGUI_AnnotationMgr( SalomeApp_Application* theApplicat QString GEOMGUI_AnnotationMgr::GetEntrySeparator() { - return "_annotation:"; + return "_annotation:"; } //================================================================ @@ -78,48 +79,14 @@ SALOME_Prs* GEOMGUI_AnnotationMgr::CreatePresentation( const GEOMGUI_AnnotationA aPresentation->SetOwner( anIO ); } - //aPresentation->SetOwner( new SALOME_InteractiveObject( getEntry( theObject ).c_str(), "GEOM", getName( theObject ).c_str() ) ); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) ); - const QColor aFontColor = aResMgr->colorValue( "Geometry", "shape_annotation_font_color", QColor( 255, 255, 255 ) ); - const QColor aLineColor = aResMgr->colorValue( "Geometry", "shape_annotation_line_color", QColor( 255, 255, 255 ) ); - const double aLineWidth = aResMgr->doubleValue( "Geometry", "shape_annotation_line_width", 1.0 ); - const int aLineStyle = aResMgr->integerValue( "Geometry", "shape_annotation_line_style", 0 ); - const bool isAutoHide = aResMgr->booleanValue( "Geometry", "shape_annotation_autohide", false ); - - const Quantity_Color aOcctFontColor( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ); - const Quantity_Color aOcctLineColor( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ); - const Standard_Real aFontHeight = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize(); - - aPresentation->SetFont( TCollection_AsciiString( aFont.family().toLatin1().data() ) ); - aPresentation->SetTextHeight( aFontHeight ); - aPresentation->SetTextColor( Quantity_Color( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ) ); - aPresentation->SetLineColor( Quantity_Color( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ) ); - aPresentation->SetLineWidth( aLineWidth ); - aPresentation->SetLineStyle( static_cast( aLineStyle ) ); - aPresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False ); aPresentation->SetIsScreenFixed( theProperty.IsScreenFixed ); + setDisplayProperties( aPresentation, theView, getEntry( theObject ).c_str() ); + TopoDS_Shape aShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObject ); - //TopoDS_Shape aShape; - //GEOMBase::GetShape( theObject.get(), aShape ); gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() ); GEOMGUI_AnnotationAttrs::SetupPresentation( aPresentation, theProperty, aShapeLCS ); - SALOME_View* aView = viewOrActiveView( theView ); - if ( aView ) { - - // set top-level flag correspondingly - SalomeApp_Study* aStudy = dynamic_cast( getApplication()->activeStudy() ); - int aMgrId = dynamic_cast< SUIT_ViewModel* >( aView )->getViewManager()->getGlobalId(); - QVariant aVal = aStudy->getObjectProperty( aMgrId, QString( getEntry( theObject ).c_str() ), GEOM::propertyName( GEOM::TopLevel ), QVariant() ); - bool isBringToFront = aVal.isValid() ? aVal.toBool() : false; - if( isBringToFront ) { - aPresentation->SetZLayer( Graphic3d_ZLayerId_Topmost ); - } - } - // add Prs to preview SUIT_ViewWindow* vw = getApplication()->desktop()->activeWindow(); SOCC_Prs* aPrs = @@ -156,13 +123,13 @@ bool GEOMGUI_AnnotationMgr::IsDisplayed( const QString& theEntry, const int theI //======================================================================= void GEOMGUI_AnnotationMgr::Display( const QString& theEntry, const int theIndex, SALOME_View* theView ) { - if ( IsDisplayed( theEntry, theIndex ) ) - return; - SALOME_View* aView = viewOrActiveView( theView ); if ( !aView ) return; + if ( IsDisplayed( theEntry, theIndex, aView ) ) + return; + GEOMGUI_AnnotationAttrs::Properties aProperty; GEOM::GEOM_Object_ptr anObject; getObject( theEntry, theIndex, anObject, aProperty ); @@ -276,6 +243,43 @@ void GEOMGUI_AnnotationMgr::EraseVisibleAnnotations( const QString& theEntry, SA myVisualized[aView] = anEntryToAnnotation; } +//======================================================================= +// function : GEOMGUI_AnnotationMgr::UpdateVisibleAnnotations +// purpose : +//======================================================================= +void GEOMGUI_AnnotationMgr::UpdateVisibleAnnotations( const QString& theEntry, SALOME_View* theView ) +{ + SALOME_View* aView = viewOrActiveView( theView ); + if ( !myVisualized.contains( aView ) ) + return; + + EntryToAnnotations& anEntryToAnnotation = myVisualized[aView]; + if ( !anEntryToAnnotation.contains( theEntry ) ) + return; + + AnnotationToPrs& anAnnotationToPrs = anEntryToAnnotation[theEntry]; + AnnotationToPrs::iterator anIt = anAnnotationToPrs.begin(); + for (; anIt != anAnnotationToPrs.end(); ++anIt ) { + SOCC_Prs* aPrs = + dynamic_cast (anIt.value()); + + AIS_ListOfInteractive aIObjects; + aPrs->GetObjects( aIObjects ); + AIS_ListOfInteractive::Iterator aIOIt( aIObjects ); + for ( ; aIOIt.More(); aIOIt.Next() ) { + + Handle(GEOM_Annotation) aPresentation = + Handle(GEOM_Annotation)::DownCast( aIOIt.Value() ); + + if ( aPresentation.IsNull() ) + continue; + + setDisplayProperties( aPresentation, aView, theEntry ); + } + } + getDisplayer()->UpdateViewer(); +} + Handle(SALOME_InteractiveObject) GEOMGUI_AnnotationMgr::FindInteractiveObject( const QString& theEntry, const int theIndex, SALOME_View* theView ) const @@ -406,14 +410,17 @@ GEOM_Displayer* GEOMGUI_AnnotationMgr::getDisplayer() const SALOME_View* GEOMGUI_AnnotationMgr::viewOrActiveView(SALOME_View* theView) const { - SALOME_View* aView = theView; - if ( !aView ) { + if ( theView ) { + return dynamic_cast( theView ); + } + else { SalomeApp_Application* anApp = getApplication(); SUIT_ViewWindow* anActiveWindow = anApp->desktop()->activeWindow(); - if (anActiveWindow) - aView = dynamic_cast(anActiveWindow->getViewManager()->getViewModel()); + if ( anActiveWindow ) { + return dynamic_cast( anActiveWindow->getViewManager()->getViewModel() ); + } } - return aView; + return NULL; } void GEOMGUI_AnnotationMgr::getObject( const QString& theEntry, const int theIndex, @@ -503,3 +510,50 @@ std::string GEOMGUI_AnnotationMgr::getName( const GEOM::GEOM_Object_ptr theObjec } return std::string(); } + +//======================================================================= +// function : GEOMGUI_AnnotationMgr::setDisplayProperties +// purpose : +//======================================================================= +void GEOMGUI_AnnotationMgr::setDisplayProperties( const Handle(GEOM_Annotation)& thePrs, + SALOME_View* theView, + const QString& theEntry ) +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) ); + const QColor aFontColor = aResMgr->colorValue( "Geometry", "shape_annotation_font_color", QColor( 255, 255, 255 ) ); + const QColor aLineColor = aResMgr->colorValue( "Geometry", "shape_annotation_line_color", QColor( 255, 255, 255 ) ); + const double aLineWidth = aResMgr->doubleValue( "Geometry", "shape_annotation_line_width", 1.0 ); + const int aLineStyle = aResMgr->integerValue( "Geometry", "shape_annotation_line_style", 0 ); + const bool isAutoHide = aResMgr->booleanValue( "Geometry", "shape_annotation_autohide", false ); + + const Quantity_Color aOcctFontColor( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ); + const Quantity_Color aOcctLineColor( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ); + const Standard_Real aFontHeight = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize(); + + thePrs->SetFont( TCollection_AsciiString( aFont.family().toLatin1().data() ) ); + thePrs->SetTextHeight( aFontHeight ); + thePrs->SetTextColor( Quantity_Color( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ) ); + thePrs->SetLineColor( Quantity_Color( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ) ); + thePrs->SetLineWidth( aLineWidth ); + thePrs->SetLineStyle( static_cast( aLineStyle ) ); + thePrs->SetAutoHide( isAutoHide ? Standard_True : Standard_False ); + + SALOME_View* aView = viewOrActiveView( theView ); + if ( aView && !theEntry.isEmpty() ) { + + SalomeApp_Study* aStudy = dynamic_cast( getApplication()->activeStudy() ); + int aMgrId = dynamic_cast< SUIT_ViewModel* >( aView )->getViewManager()->getGlobalId(); + QVariant aVal = aStudy->getObjectProperty( aMgrId, theEntry, GEOM::propertyName( GEOM::TopLevel ), QVariant() ); + bool isBringToFront = aVal.isValid() ? aVal.toBool() : false; + if( isBringToFront ) { + thePrs->SetZLayer( Graphic3d_ZLayerId_Topmost ); + } + else { + thePrs->SetDefaultZLayer(); + } + } + else { + thePrs->SetDefaultZLayer(); + } +} diff --git a/src/GEOMGUI/GEOMGUI_AnnotationMgr.h b/src/GEOMGUI/GEOMGUI_AnnotationMgr.h index 8b3445903..de7cfcc67 100755 --- a/src/GEOMGUI/GEOMGUI_AnnotationMgr.h +++ b/src/GEOMGUI/GEOMGUI_AnnotationMgr.h @@ -32,6 +32,7 @@ #include class SalomeApp_Application; +class GEOM_Annotation; class GEOM_Displayer; /*! @@ -61,6 +62,7 @@ public: void DisplayVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 ); void EraseVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 ); + void UpdateVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 ); void RemoveView( SALOME_View* theView); @@ -92,6 +94,10 @@ protected: std::string getName( const GEOM::GEOM_Object_ptr theObject ); + void setDisplayProperties( const Handle(GEOM_Annotation)& thePrs, + SALOME_View* theView = 0, + const QString& theEntry = QString() ); + private: SalomeApp_Application* myApplication; diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 2371bf229..15058b029 100755 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -702,10 +702,12 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, SalomeApp_Application* anApp = dynamic_cast( session->activeApplication() ); GeometryGUI* aModule = dynamic_cast( anApp->activeModule() ); if ( aModule ) { - if ( !theViewFrame->isVisible( theIO ) ) + if ( !theViewFrame->isVisible( theIO ) ) { aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), theViewFrame); - else + } + else { aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), theViewFrame); + } } } @@ -2073,13 +2075,17 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* ) void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p ) { UpdateColorScale(false,false); - if ( !myIsRedisplayed ) { - // visualize annotations for displayed presentation - SUIT_Session* session = SUIT_Session::session(); - SalomeApp_Application* anApp = dynamic_cast( session->activeApplication() ); - GeometryGUI* aModule = dynamic_cast( anApp->activeModule() ); - if ( aModule ) + + // visualize annotations for displayed presentation + SUIT_Session* session = SUIT_Session::session(); + SalomeApp_Application* anApp = dynamic_cast( session->activeApplication() ); + GeometryGUI* aModule = dynamic_cast( anApp->activeModule() ); + if ( aModule ) { + if ( !myIsRedisplayed ) { aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), v); + } else { + aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), v); + } } } diff --git a/src/MeasureGUI/MeasureGUI.cxx b/src/MeasureGUI/MeasureGUI.cxx index d8ea3d555..d9ad2c7f0 100755 --- a/src/MeasureGUI/MeasureGUI.cxx +++ b/src/MeasureGUI/MeasureGUI.cxx @@ -249,7 +249,7 @@ void MeasureGUI::ChangeAnnotationsVisibility( const bool theIsVisible ) SUIT_OverrideCursor wc; - for ( int anI = 0; anI <= aCount; ++anI ) { + for ( int anI = 0; anI < aCount; ++anI ) { if ( !theIsVisible ) { getGeometryGUI()->GetAnnotationMgr()->Erase( aEntry, anI ); diff --git a/src/OBJECT/GEOM_Annotation.cxx b/src/OBJECT/GEOM_Annotation.cxx index f95f26ed6..0bdadf3c7 100755 --- a/src/OBJECT/GEOM_Annotation.cxx +++ b/src/OBJECT/GEOM_Annotation.cxx @@ -63,7 +63,7 @@ GEOM_Annotation::GEOM_Annotation() : AIS_InteractiveObject() SetIsScreenFixed( Standard_False ); SetAttachPoint( gp_Pnt( 0.0, 0.0, 0.0 ) ); SetDisplayMode( 0 ); - SetZLayer( Graphic3d_ZLayerId_Top ); + SetZLayer( Graphic3d_ZLayerId_Default ); SetAutoHide( Standard_True ); SetHilightMode( HighlightAll ); SetMutable( Standard_True ); @@ -149,7 +149,7 @@ void GEOM_Annotation::SetIsScreenFixed( const Standard_Boolean theIsFixed ) AIS_InteractiveObject::SetTransformPersistence( Graphic3d_TMF_2d ); } - SetZLayer( myIsScreenFixed ? Graphic3d_ZLayerId_Topmost : Graphic3d_ZLayerId_Top ); + SetZLayer( myIsScreenFixed ? Graphic3d_ZLayerId_Topmost : Graphic3d_ZLayerId_Default ); SetToUpdate(); @@ -334,6 +334,17 @@ void GEOM_Annotation::SetDepthCulling( const Standard_Boolean theToEnable ) } } +// ======================================================================= +// function : SetDefaultZLayer +// purpose : +// ======================================================================= +void GEOM_Annotation::SetDefaultZLayer() +{ + SetZLayer( myIsScreenFixed ? Graphic3d_ZLayerId_Topmost : Graphic3d_ZLayerId_Default ); + + SetToUpdate(); +} + // ======================================================================= // function : GetDefaultPosition // purpose : diff --git a/src/OBJECT/GEOM_Annotation.hxx b/src/OBJECT/GEOM_Annotation.hxx index 0fe6b11f5..9cc553f5b 100755 --- a/src/OBJECT/GEOM_Annotation.hxx +++ b/src/OBJECT/GEOM_Annotation.hxx @@ -203,6 +203,9 @@ public: // Helper tools: public: + //! Restores default z-layer for this presentation. + Standard_EXPORT void SetDefaultZLayer(); + //! Returns default position for placing annotation when its attachment point //! has been determined. //! @param theIsScreenFixed [in] the state of annotation's "2D screen fixed" mode.