-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE\r
-//\r
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS\r
-//\r
-// This library is free software; you can redistribute it and/or\r
-// modify it under the terms of the GNU Lesser General Public\r
-// License as published by the Free Software Foundation; either\r
-// version 2.1 of the License, or (at your option) any later version.\r
-//\r
-// This library is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
-// Lesser General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU Lesser General Public\r
-// License along with this library; if not, write to the Free Software\r
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-//\r
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com\r
-//\r
-\r
-// File : GEOMGUI_AnnotationAttr.cxx\r
-// Author : Anton POLETAEV, Open CASCADE S.A.S.\r
-//\r
-\r
-// SALOME includes\r
-#include <GEOMGUI_AnnotationAttrs.h>\r
-#include <GEOM_Annotation.hxx>\r
-#include <SALOMEDSImpl_AttributeParameter.hxx>\r
-\r
-// STL includes\r
-#include <string>\r
-#include <vector>\r
-\r
-IMPLEMENT_STANDARD_RTTIEXT( GEOMGUI_AnnotationAttrs, Standard_Transient )\r
-\r
-namespace\r
-{\r
- static const std::string PARAMETER_COUNT = "GEOMGUI_AnnotationAttrs_Count";\r
-\r
- std::string PARAMETER_I( const std::string& s, const int i ) {\r
- return std::string( s ) + std::to_string( i );\r
- }\r
- std::string PARAMETER_IS_VISIBLE( const int i ) {\r
- return PARAMETER_I( "GEOMGUI_AnnotationAttrs_IsVisible", i );\r
- }\r
- std::string PARAMETER_IS_2D( const int i ) {\r
- return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Is2D", i );\r
- }\r
- std::string PARAMETER_TEXT( const int i ) {\r
- return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Text", i );\r
- }\r
- std::string PARAMETER_POSITION( const int i ) {\r
- return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Position", i );\r
- }\r
- std::string PARAMETER_ATTACH( const int i ) {\r
- return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Attach", i );\r
- }\r
- std::string PARAMETER_SHAPE( const int i ) {\r
- return PARAMETER_I( "GEOMGUI_AnnotationAttrs_Shape", i );\r
- }\r
-\r
- // REGEXP pattern for converting array of entries into plain text string.\r
- // The pattern has the following structure:\r
- // ENTRY: { text[string] : visibility[bool] : screen fixed[bool] : position[xyz] : attach[xyz] }\r
- static const QString PATTERN_ITEM_GROUP = "\\{ (Text=(?::{2,}|.)*:(?!:)Screen=.*:Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=.*:ShapeType=.*) \\}";\r
- static const QString PATTERN_ITEM = "Text=((?::{2,}|.)*):(?!:)Screen=(\\d{1}):Position=\\{(.*):(.*):(.*)\\}:Attach=\\{(.*):(.*):(.*)\\}:ShapeIdx=(\\-?\\d{1,}):ShapeType=(\\d{1})";\r
- static QString toPattern (const QString& theText,\r
- const bool theIsFixed,\r
- const gp_Pnt& thePosition,\r
- const gp_Pnt& theAttach,\r
- const int theShapeIndex,\r
- const int theShapeType)\r
- {\r
- return QString( "{ Text=" ) + theText +\r
- QString( ":" ) + QString( "Screen=" ) + QString::number( theIsFixed ? 1 : 0 ) +\r
- QString( ":" ) + QString( "Position={" ) +\r
- QString::number( thePosition.X() ) + QString( ":" ) + \r
- QString::number( thePosition.Y() ) + QString( ":" ) + \r
- QString::number( thePosition.Z() ) + QString( "}" ) + \r
- QString( ":" ) + QString( "Attach={" ) +\r
- QString::number( theAttach.X() ) + QString( ":" ) + \r
- QString::number( theAttach.Y() ) + QString( ":" ) + \r
- QString::number( theAttach.Z() ) + QString( "}" ) +\r
- QString( ":" ) + QString( "ShapeIdx=" ) + QString::number( theShapeIndex ) +\r
- QString( ":" ) + QString( "ShapeType=" ) + QString::number( theShapeType ) +\r
- QString( " }" );\r
- }\r
-};\r
-\r
-//=================================================================================\r
-// function : FindAttributes\r
-// purpose : \r
-//=================================================================================\r
-Handle(GEOMGUI_AnnotationAttrs) GEOMGUI_AnnotationAttrs::FindAttributes( const _PTR(SObject)& theObject )\r
-{\r
- _PTR(GenericAttribute) aGenericAttr;\r
- _PTR(AttributeParameter) aParameterMap;\r
-\r
- if ( !theObject->FindAttribute( aGenericAttr, "AttributeParameter" ) )\r
- {\r
- return Handle(GEOMGUI_AnnotationAttrs)();\r
- }\r
-\r
- aParameterMap = aGenericAttr;\r
-\r
- if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) )\r
- {\r
- return Handle(GEOMGUI_AnnotationAttrs)();\r
- }\r
-\r
- return new GEOMGUI_AnnotationAttrs( theObject, aParameterMap );\r
-}\r
-\r
-//=================================================================================\r
-// function : FindOrCreateAttributes\r
-// purpose : \r
-//=================================================================================\r
-Handle(GEOMGUI_AnnotationAttrs) GEOMGUI_AnnotationAttrs::FindOrCreateAttributes(\r
- const _PTR(SObject)& theObject, SalomeApp_Study* theStudy )\r
-{\r
- _PTR(StudyBuilder) aBuilder = theStudy->studyDS()->NewBuilder();\r
- _PTR(AttributeParameter) aParameterMap = aBuilder->FindOrCreateAttribute( theObject, "AttributeParameter" );\r
- if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) )\r
- {\r
- aParameterMap->SetInt( PARAMETER_COUNT, 0 );\r
- }\r
-\r
- return new GEOMGUI_AnnotationAttrs( theObject, aParameterMap );\r
-}\r
-\r
-//=================================================================================\r
-// function : Remove\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::Remove( const _PTR(SObject)& theObject )\r
-{\r
- _PTR(GenericAttribute) aGenericAttr;\r
- _PTR(AttributeParameter) aParameterMap;\r
-\r
- if ( !theObject->FindAttribute( aGenericAttr, "AttributeParameter" ) )\r
- {\r
- return;\r
- }\r
-\r
- aParameterMap = aGenericAttr;\r
-\r
- if ( !aParameterMap->IsSet( PARAMETER_COUNT, PT_INTEGER ) )\r
- {\r
- return;\r
- }\r
-\r
- const int aParamCount = aParameterMap->GetInt( PARAMETER_COUNT );\r
-\r
- for ( int anI = 0; anI < aParamCount; ++anI )\r
- {\r
- aParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN );\r
- aParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN );\r
- aParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING );\r
- aParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY );\r
- aParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY );\r
- aParameterMap->RemoveID( PARAMETER_SHAPE( anI ), PT_INTARRAY );\r
- }\r
-\r
- aParameterMap->RemoveID( PARAMETER_COUNT, PT_INTEGER );\r
-}\r
-\r
-//=================================================================================\r
-// function : ExportAsPropertyString\r
-// purpose : \r
-//=================================================================================\r
-QString GEOMGUI_AnnotationAttrs::ExportAsPropertyString() const\r
-{\r
- QStringList anItems;\r
-\r
- for ( int anI = 0; anI < GetNbAnnotation(); ++anI )\r
- {\r
- Properties aEntry;\r
-\r
- GetProperties( anI, aEntry );\r
-\r
- anItems.append( toPattern( aEntry.Text,\r
- aEntry.IsScreenFixed,\r
- aEntry.Position,\r
- aEntry.Attach,\r
- aEntry.ShapeIndex,\r
- aEntry.ShapeType ) );\r
- }\r
-\r
- return anItems.join( ":" );\r
-}\r
-\r
-//=================================================================================\r
-// function : ImportFromPropertyString\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::ImportFromPropertyString( const QString& theString )\r
-{\r
- SetNbAnnotation( 0 );\r
-\r
- QRegExp aRegExpItemGroups( PATTERN_ITEM_GROUP );\r
- QRegExp aRegExpItem( "^" + PATTERN_ITEM + "$" );\r
- aRegExpItemGroups.setMinimal( true );\r
- aRegExpItem.setMinimal( true );\r
-\r
- int aPos = 0;\r
- while ( ( aPos = aRegExpItemGroups.indexIn( theString, aPos ) ) != -1 )\r
- {\r
- aPos += aRegExpItemGroups.matchedLength();\r
-\r
- QString aStrItem = aRegExpItemGroups.cap(1);\r
-\r
- if ( aRegExpItem.indexIn( aStrItem ) < 0 )\r
- {\r
- continue;\r
- }\r
-\r
- QString aStrText = aRegExpItem.cap( 1 );\r
- QString aStrFixed = aRegExpItem.cap( 2 );\r
- QString aStrPosX = aRegExpItem.cap( 3 );\r
- QString aStrPosY = aRegExpItem.cap( 4 );\r
- QString aStrPosZ = aRegExpItem.cap( 5 );\r
- QString aStrAttX = aRegExpItem.cap( 6 );\r
- QString aStrAttY = aRegExpItem.cap( 7 );\r
- QString aStrAttZ = aRegExpItem.cap( 8 );\r
- QString aStrShapeIdx = aRegExpItem.cap( 9 );\r
- QString aStrShapeType = aRegExpItem.cap( 10 );\r
- aStrText.replace( "::", ":" );\r
-\r
- Properties aEntry;\r
- aEntry.Text = aStrText;\r
- aEntry.IsVisible = false;\r
- aEntry.IsScreenFixed = aStrFixed.toInt() != 0;\r
- aEntry.Position.SetX( aStrPosX.toDouble() );\r
- aEntry.Position.SetY( aStrPosY.toDouble() );\r
- aEntry.Position.SetZ( aStrPosZ.toDouble() );\r
- aEntry.Attach.SetX( aStrAttX.toDouble() );\r
- aEntry.Attach.SetY( aStrAttY.toDouble() );\r
- aEntry.Attach.SetZ( aStrAttZ.toDouble() );\r
- aEntry.ShapeIndex = aStrShapeIdx.toInt();\r
- aEntry.ShapeType = aStrShapeType.toInt();\r
-\r
- Append( aEntry );\r
- }\r
-}\r
-\r
-//=================================================================================\r
-// function : SetNbAnnotation\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetNbAnnotation( const int theCount ) const\r
-{\r
- const int aCount = this->GetNbAnnotation();\r
-\r
- if ( aCount < theCount )\r
- {\r
- // set default values\r
- for ( int anI = aCount; anI < theCount; ++anI )\r
- {\r
- myParameterMap->SetBool( PARAMETER_IS_VISIBLE( anI ), true );\r
- myParameterMap->SetBool( PARAMETER_IS_2D( anI ), false );\r
- myParameterMap->SetString( PARAMETER_TEXT( anI ), std::string() );\r
- myParameterMap->SetRealArray( PARAMETER_POSITION( anI ), std::vector<double>(3, 0.0) );\r
- myParameterMap->SetRealArray( PARAMETER_ATTACH( anI ), std::vector<double>(3, 0.0) );\r
- myParameterMap->SetIntArray( PARAMETER_SHAPE( anI ), std::vector<int>(2, 0) );\r
- }\r
- }\r
- else\r
- {\r
- // remove exceeding values\r
- for ( int anI = theCount; anI < aCount; ++anI )\r
- {\r
- myParameterMap->RemoveID( PARAMETER_IS_VISIBLE( anI ), PT_BOOLEAN );\r
- myParameterMap->RemoveID( PARAMETER_IS_2D( anI ), PT_BOOLEAN );\r
- myParameterMap->RemoveID( PARAMETER_TEXT( anI ), PT_STRING );\r
- myParameterMap->RemoveID( PARAMETER_POSITION( anI ), PT_REALARRAY );\r
- myParameterMap->RemoveID( PARAMETER_ATTACH( anI ), PT_REALARRAY );\r
- myParameterMap->RemoveID( PARAMETER_SHAPE( anI ), PT_INTARRAY );\r
- }\r
- }\r
-\r
- myParameterMap->SetInt( PARAMETER_COUNT, theCount );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetNbAnnotation\r
-// purpose : \r
-//=================================================================================\r
-int GEOMGUI_AnnotationAttrs::GetNbAnnotation() const\r
-{\r
- return myParameterMap->GetInt( PARAMETER_COUNT );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetVisible\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetIsVisible( const int theIndex, const bool theIsVisible )\r
-{\r
- myParameterMap->SetBool( PARAMETER_IS_VISIBLE( theIndex ), theIsVisible );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetIsVisible\r
-// purpose : \r
-//=================================================================================\r
-bool GEOMGUI_AnnotationAttrs::GetIsVisible( const int theIndex ) const\r
-{\r
- return myParameterMap->GetBool( PARAMETER_IS_VISIBLE( theIndex ) );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetText\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetText( const int theIndex, const QString& theText )\r
-{\r
- myParameterMap->SetString( PARAMETER_TEXT( theIndex ), theText.toStdString() );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetText\r
-// purpose : \r
-//=================================================================================\r
-QString GEOMGUI_AnnotationAttrs::GetText( const int theIndex ) const\r
-{\r
- return QString::fromStdString( myParameterMap->GetString( PARAMETER_TEXT( theIndex ) ) );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetIsScreenFixed\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetIsScreenFixed( const int theIndex, const bool theIsScreenFixed )\r
-{\r
- myParameterMap->SetBool( PARAMETER_IS_2D( theIndex ), theIsScreenFixed );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetIsScreenFixed\r
-// purpose : \r
-//=================================================================================\r
-bool GEOMGUI_AnnotationAttrs::GetIsScreenFixed( const int theIndex ) const\r
-{\r
- return myParameterMap->GetBool( PARAMETER_IS_2D( theIndex ) );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetPosition\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetPosition( const int theIndex, const gp_Pnt& thePosition )\r
-{\r
- std::vector<double> aCoords( 3 );\r
-\r
- aCoords[0] = thePosition.X();\r
- aCoords[1] = thePosition.Y();\r
- aCoords[2] = thePosition.Z();\r
-\r
- myParameterMap->SetRealArray( PARAMETER_POSITION( theIndex ), aCoords );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetPosition\r
-// purpose : \r
-//=================================================================================\r
-gp_Pnt GEOMGUI_AnnotationAttrs::GetPosition( const int theIndex ) const\r
-{\r
- std::vector<double> aCoords =\r
- myParameterMap->GetRealArray( PARAMETER_POSITION( theIndex ) );\r
-\r
- return gp_Pnt( aCoords[0], aCoords[1], aCoords[2] );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetAttach\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetAttach( const int theIndex, const gp_Pnt& theAttach )\r
-{\r
- std::vector<double> aCoords( 3 );\r
-\r
- aCoords[0] = theAttach.X();\r
- aCoords[1] = theAttach.Y();\r
- aCoords[2] = theAttach.Z();\r
-\r
- myParameterMap->SetRealArray( PARAMETER_ATTACH( theIndex ), aCoords );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetAttach\r
-// purpose : \r
-//=================================================================================\r
-gp_Pnt GEOMGUI_AnnotationAttrs::GetAttach( const int theIndex ) const\r
-{\r
- std::vector<double> aCoords =\r
- myParameterMap->GetRealArray( PARAMETER_ATTACH( theIndex ) );\r
-\r
- return gp_Pnt( aCoords[0], aCoords[1], aCoords[2] );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetShapeSel\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetShapeSel( const int theIndex, const int theShapeType, const int theSubIdx )\r
-{\r
- std::vector<int> aSelection( 2 );\r
-\r
- aSelection[0] = theShapeType;\r
- aSelection[1] = theSubIdx;\r
-\r
- myParameterMap->SetIntArray( PARAMETER_SHAPE( theIndex ), aSelection );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetShapeSel\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::GetShapeSel( const int theIndex, int& theShapeType, int& theSubIdx ) const\r
-{\r
- std::vector<int> aSelection =\r
- myParameterMap->GetIntArray( PARAMETER_SHAPE( theIndex ) );\r
-\r
- theShapeType = aSelection[0];\r
- theSubIdx = aSelection[1];\r
-}\r
-\r
-//=================================================================================\r
-// function : Append\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps )\r
-{\r
- this->Append( theProps, gp_Ax3() );\r
-}\r
-\r
-//=================================================================================\r
-// function : Append\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps, const gp_Ax3& theShapeLCS )\r
-{\r
- const int aCount = this->GetNbAnnotation();\r
- this->SetNbAnnotation( aCount + 1 );\r
- this->SetProperties( aCount, theProps, theShapeLCS );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetProperties\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps )\r
-{\r
- this->SetProperties( theIndex, theProps, gp_Ax3() );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetProperties\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps,\r
- const gp_Ax3& theShapeLCS )\r
-{\r
- gp_Trsf aToShapeLCS;\r
- aToShapeLCS.SetTransformation( gp_Ax3(), theShapeLCS );\r
-\r
- this->SetText( theIndex, theProps.Text );\r
- this->SetIsVisible( theIndex, theProps.IsVisible );\r
- this->SetIsScreenFixed( theIndex, theProps.IsScreenFixed );\r
- this->SetShapeSel( theIndex, theProps.ShapeType, theProps.ShapeIndex );\r
- this->SetAttach( theIndex, theProps.Attach.Transformed( aToShapeLCS ) );\r
- this->SetPosition( theIndex, (theProps.IsScreenFixed) ? \r
- theProps.Position : theProps.Position.Transformed( aToShapeLCS ) );\r
-}\r
-\r
-//=================================================================================\r
-// function : GetProperties\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::GetProperties( const int theIndex, Properties& theProps ) const\r
-{\r
- theProps.Text = this->GetText( theIndex );\r
- theProps.IsVisible = this->GetIsVisible( theIndex );\r
- theProps.IsScreenFixed = this->GetIsScreenFixed( theIndex );\r
- theProps.Position = this->GetPosition( theIndex );\r
- theProps.Attach = this->GetAttach( theIndex );\r
-\r
- this->GetShapeSel( theIndex, theProps.ShapeType, theProps.ShapeIndex );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetupPresentation\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation,\r
- const Properties& theProps,\r
- const gp_Ax3& theShapeLCS )\r
-{\r
- gp_Trsf aFromShapeLCS;\r
- aFromShapeLCS.SetTransformation( theShapeLCS, gp_Ax3() );\r
-\r
- TCollection_ExtendedString aText;\r
- for (int i = 0; i < (int)theProps.Text.length(); i++ )\r
- aText.Insert( i + 1, theProps.Text[ i ].unicode() );\r
-\r
- thePresentation->SetText( aText );\r
- thePresentation->SetIsScreenFixed( theProps.IsScreenFixed );\r
- thePresentation->SetAttachPoint( theProps.Attach.Transformed( aFromShapeLCS ) );\r
- thePresentation->SetPosition( (theProps.IsScreenFixed) ? \r
- theProps.Position : theProps.Position.Transformed( aFromShapeLCS ) );\r
-}\r
-\r
-//=================================================================================\r
-// function : SetupPresentation\r
-// purpose : \r
-//=================================================================================\r
-void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation,\r
- const int theIndex,\r
- const gp_Ax3& theShapeLCS )\r
-{\r
- Properties aProps;\r
- this->GetProperties( theIndex, aProps );\r
- this->SetupPresentation( thePresentation, aProps, theShapeLCS );\r
-}\r
+// 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 <GEOMGUI_AnnotationAttrs.h>
+#include <GEOM_Annotation.hxx>
+#include <SALOMEDSImpl_AttributeParameter.hxx>
+
+// STL includes
+#include <string>
+#include <vector>
+
+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<double>(3, 0.0) );
+ myParameterMap->SetRealArray( PARAMETER_ATTACH( anI ), std::vector<double>(3, 0.0) );
+ myParameterMap->SetIntArray( PARAMETER_SHAPE( anI ), std::vector<int>(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<double> 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<double> 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<double> 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<double> 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<int> 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<int> 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<Properties> 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<int>( 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 );
+}
#include <SOCC_Prs.h>
#include <SOCC_ViewModel.h>
+#include <SOCC_ViewWindow.h>
#include <Quantity_Color.hxx>
#include <TCollection_AsciiString.hxx>
QString GEOMGUI_AnnotationMgr::GetEntrySeparator()
{
- return "_annotation:";
+ return "_annotation:";
}
//================================================================
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<Aspect_TypeOfLine>( 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<SalomeApp_Study*>( 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 =
//=======================================================================
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 );
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<SOCC_Prs*> (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
SALOME_View* GEOMGUI_AnnotationMgr::viewOrActiveView(SALOME_View* theView) const
{
- SALOME_View* aView = theView;
- if ( !aView ) {
+ if ( theView ) {
+ return dynamic_cast<SOCC_Viewer*>( theView );
+ }
+ else {
SalomeApp_Application* anApp = getApplication();
SUIT_ViewWindow* anActiveWindow = anApp->desktop()->activeWindow();
- if (anActiveWindow)
- aView = dynamic_cast<SALOME_View*>(anActiveWindow->getViewManager()->getViewModel());
+ if ( anActiveWindow ) {
+ return dynamic_cast<SOCC_Viewer*>( anActiveWindow->getViewManager()->getViewModel() );
+ }
}
- return aView;
+ return NULL;
}
void GEOMGUI_AnnotationMgr::getObject( const QString& theEntry, const int theIndex,
}
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<Aspect_TypeOfLine>( aLineStyle ) );
+ thePrs->SetAutoHide( isAutoHide ? Standard_True : Standard_False );
+
+ SALOME_View* aView = viewOrActiveView( theView );
+ if ( aView && !theEntry.isEmpty() ) {
+
+ SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( 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();
+ }
+}