X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Entity.cxx;h=f0b9e5fb034a06e9b26123375f8f69eab2fe0fc2;hb=9c947f35615e69e9e54a8c4b074dd1f2be13689c;hp=af16992f00e20e3650b3aad5bf2602def70de7b9;hpb=b8a6578b8a09ecae38f85d1cd508253c216e5963;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index af16992f..f0b9e5fb 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -1,26 +1,57 @@ - -#include "HYDROData_Entity.h" - -#include "HYDROData_Iterator.h" -#include "HYDROData_Tool.h" - +// Copyright (C) 2014-2015 EDF-R&D +// 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 +// + +#include +#include +#include +#include +#include #include #include #include +#include #include -#include -#include #include - #include #include - +#include +#include +#include #include -#include +#include #include #include -static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000"); +HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects() + : NCollection_Sequence() +{ +} + +HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& theSequence ) + : NCollection_Sequence( theSequence ) +{ +} + +HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const NCollection_Sequence& theSequence ) + : NCollection_Sequence( theSequence ) +{ +} + IMPLEMENT_STANDARD_HANDLE(HYDROData_Entity,MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Entity,MMgt_TShared) @@ -45,7 +76,10 @@ QString HYDROData_Entity::GetName() const QString HYDROData_Entity::GetObjPyName() const { - return GetName().replace(" ", "_"); + QString aName = GetName(); + aName.replace(QRegExp("[\\W]"), "_"); + + return aName; } void HYDROData_Entity::SetName(const QString& theName) @@ -59,94 +93,93 @@ QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjec return anEmptyList; } -QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const +void HYDROData_Entity::Update() { - QStringList aResList; + ClearChanged(); +} - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( aDocument.IsNull() ) - return aResList; +void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy ) +{ + //On the base level no actions are necessary +} - QString aDocName = aDocument->GetDocPyName(); - QString aName = GetObjPyName(); +bool HYDROData_Entity::IsHas2dPrs() const +{ + return false; +} - aResList << QString( "%1 = %2.CreateObject( %3 );" ) - .arg( aName ).arg( aDocName ).arg( getPyTypeID() ); - aResList << QString( "%1.SetName( \"%2\" );" ) - .arg( aName ).arg( GetName() ); - aResList << QString( "" ); +void HYDROData_Entity::Show() +{ + if ( !IsHas2dPrs() ) + return; - return aResList; + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) + return; + + aDocument->Show( this ); } -void HYDROData_Entity::Update() +QVariant HYDROData_Entity::GetDataVariant() { - SetToUpdate( false ); + return QVariant(); } -QString HYDROData_Entity::getPyTypeID() const +void HYDROData_Entity::ClearChanged() { - switch( GetKind() ) - { - case KIND_IMAGE: return "KIND_IMAGE"; - case KIND_POLYLINE: return "KIND_POLYLINE"; - case KIND_BATHYMETRY: return "KIND_BATHYMETRY"; - case KIND_ALTITUDE: return "KIND_ALTITUDE"; - case KIND_IMMERSIBLE_ZONE: return "KIND_IMMERSIBLE_ZONE"; - case KIND_RIVER: return "KIND_RIVER"; - case KIND_STREAM: return "KIND_STREAM"; - case KIND_CONFLUENCE: return "KIND_CONFLUENCE"; - case KIND_CHANNEL: return "KIND_CHANNEL"; - case KIND_OBSTACLE: return "KIND_OBSTACLE"; - case KIND_DIGUE: return "KIND_DIGUE"; - case KIND_PROFILE: return "KIND_PROFILE"; - case KIND_PROFILEUZ: return "KIND_PROFILEUZ"; - case KIND_POLYLINEXY: return "KIND_POLYLINEXY"; - case KIND_CALCULATION: return "KIND_CALCULATION"; - case KIND_ZONE: return "KIND_ZONE"; - case KIND_REGION: return "KIND_REGION"; - case KIND_VISUAL_STATE: return "KIND_VISUAL_STATE"; - case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT"; - case KIND_NATURAL_OBJECT: return "KIND_NATURAL_OBJECT"; - case KIND_DUMMY_3D: return "KIND_DUMMY_3D"; - case KIND_SHAPES_GROUP: return "KIND_SHAPES_GROUP"; - case KIND_SPLITTED_GROUP: return "KIND_SPLITTED_GROUP"; - case KIND_STREAM_ALTITUDE: return "KIND_STREAM_ALTITUDE"; - case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE"; - default: return "KIND_UNKNOWN"; ///! Unrecognized object - } + TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 ); } -QVariant HYDROData_Entity::GetDataVariant() +int HYDROData_Entity::GetGeomChangeFlag() const { - return QVariant(); + int aGeomChangeFlag = 0; + Handle(TDataStd_Integer) aGeomChangeAttr; + TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange ); + aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr ); + if ( !aGeomChangeAttr.IsNull() ) + aGeomChangeFlag = aGeomChangeAttr->Get(); + return aGeomChangeFlag; } -void HYDROData_Entity::SetToUpdate( bool theFlag ) +void HYDROData_Entity::Changed( Geometry theChangedGeometry ) { - if ( IsMustBeUpdated() == theFlag ) + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if( aDocument.IsNull() ) return; - if ( theFlag ) - { - TDataStd_UAttribute::Set( myLab, GUID_MUST_BE_UPDATED ); + int aGeomChangeFlag = 0; + Handle(TDataStd_Integer) aGeomChangeAttr; + TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange ); + aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr ); + if ( !aGeomChangeAttr.IsNull() ) + aGeomChangeFlag = aGeomChangeAttr->Get(); - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( !aDocument.IsNull() ) + int aBitsToChange = ( myGeom & theChangedGeometry ); + if( aBitsToChange == 0 ) + return; + + aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange ); + TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag ); + + HYDROData_Iterator anIter( aDocument ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Entity) anObject = anIter.Current(); + if( anObject.IsNull() ) + continue; + HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects(); + for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i ) { - // Change the states of this and all depended objects - HYDROData_Tool::SetMustBeUpdatedObjects( aDocument ); + Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i ); + if( aRefObject->Label()==myLab ) + anObject->Changed( theChangedGeometry ); } } - else - { - myLab.ForgetAttribute( GUID_MUST_BE_UPDATED ); - } } -bool HYDROData_Entity::IsMustBeUpdated() const +bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const { - return myLab.IsAttribute( GUID_MUST_BE_UPDATED ); + return ( ( GetGeomChangeFlag() & theGeom ) != 0 ); } bool HYDROData_Entity::CanBeUpdated() const @@ -169,7 +202,8 @@ bool HYDROData_Entity::CanRemove() return true; } -HYDROData_Entity::HYDROData_Entity() +HYDROData_Entity::HYDROData_Entity( Geometry theGeom ) + : myGeom( theGeom ) { } @@ -177,10 +211,37 @@ HYDROData_Entity::~HYDROData_Entity() { } -void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const +void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination, + bool isGenerateNewName ) const { + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) { + return; + } + TDF_CopyLabel aCopy(myLab, theDestination->Label()); aCopy.Perform(); + + if( isGenerateNewName ) + { + // generate a new unique name for the clone object: + // case 1: Image_1 -> Image_2 + // case 2: ImageObj -> ImageObj_1 + QString aName = theDestination->GetName(); + QString aPrefix = aName; + if( aName.contains( '_' ) ) { // case 1 + QString aSuffix = aName.section( '_', -1 ); + bool anIsInteger = false; + aSuffix.toInt( &anIsInteger ); + if( anIsInteger ) + aPrefix = aName.section( '_', 0, -2 ); + } else { // case 2 + aPrefix = aName; + } + + aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix ); + theDestination->SetName( aName ); + } } Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const @@ -206,13 +267,44 @@ HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const return HYDROData_SequenceOfObjects(); } -void HYDROData_Entity::SetLabel(TDF_Label theLabel) +Standard_Boolean HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const +{ + theLevel = -1; + + TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false ); + if ( !aLabel.IsNull() ) + { + Handle(TDataStd_Integer) anIntVal; + if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) ) + { + theLevel = anIntVal->Get(); + return Standard_True; + } + } + + return Standard_False; +} + +void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel ) +{ + TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel ); +} + +void HYDROData_Entity::RemoveZLevel() +{ + TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false ); + if ( !aLabel.IsNull() ) + aLabel.ForgetAllAttributes(); +} + +void HYDROData_Entity::SetLabel( const TDF_Label& theLabel ) { myLab = theLabel; } -void HYDROData_Entity::SaveByteArray(const int theTag, - const char* theData, const int theLen) +void HYDROData_Entity::SaveByteArray( const int theTag, + const char* theData, + const int theLen ) { TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag); // array is empty, remove the attribute @@ -494,43 +586,117 @@ QColor HYDROData_Entity::GetColor( const QColor& theDefColor, return aResColor; } +QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList; + + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) + return aResList; + + QString aDocName = aDocument->GetDocPyName(); + QString aName = GetObjPyName(); + + aResList << QString( "%1 = %2.CreateObject( %3 );" ) + .arg( aName ).arg( aDocName ).arg( getPyTypeID() ); + aResList << QString( "%1.SetName( \"%2\" );" ) + .arg( aName ).arg( GetName() ); + aResList << QString( "" ); + + if ( IsHas2dPrs() ) + { + // Dump object z-level in viewer + Standard_Integer anObjZLevel = -1; + if ( GetZLevel( anObjZLevel ) ) + { + aResList << QString( "%1.SetZLevel( %2 );" ) + .arg( aName ).arg( anObjZLevel ); + aResList << QString( "" ); + } + } + + return aResList; +} + +QString HYDROData_Entity::getPyTypeID() const +{ + switch( GetKind() ) + { + case KIND_IMAGE: return "KIND_IMAGE"; + case KIND_POLYLINE: return "KIND_POLYLINE"; + case KIND_BATHYMETRY: return "KIND_BATHYMETRY"; + case KIND_ALTITUDE: return "KIND_ALTITUDE"; + case KIND_IMMERSIBLE_ZONE: return "KIND_IMMERSIBLE_ZONE"; + case KIND_RIVER: return "KIND_RIVER"; + case KIND_STREAM: return "KIND_STREAM"; + case KIND_CONFLUENCE: return "KIND_CONFLUENCE"; + case KIND_CHANNEL: return "KIND_CHANNEL"; + case KIND_OBSTACLE: return "KIND_OBSTACLE"; + case KIND_DIGUE: return "KIND_DIGUE"; + case KIND_PROFILE: return "KIND_PROFILE"; + case KIND_PROFILEUZ: return "KIND_PROFILEUZ"; + case KIND_POLYLINEXY: return "KIND_POLYLINEXY"; + case KIND_CALCULATION: return "KIND_CALCULATION"; + case KIND_ZONE: return "KIND_ZONE"; + case KIND_REGION: return "KIND_REGION"; + case KIND_VISUAL_STATE: return "KIND_VISUAL_STATE"; + case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT"; + case KIND_NATURAL_OBJECT: return "KIND_NATURAL_OBJECT"; + case KIND_DUMMY_3D: return "KIND_DUMMY_3D"; + case KIND_SHAPES_GROUP: return "KIND_SHAPES_GROUP"; + case KIND_SPLITTED_GROUP: return "KIND_SPLITTED_GROUP"; + case KIND_STREAM_ALTITUDE: return "KIND_STREAM_ALTITUDE"; + case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE"; + case KIND_STRICKLER_TABLE: return "KIND_STRICKLER_TABLE"; + case KIND_LAND_COVER_OBSOLETE: return ""; + case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP"; + default: return "KIND_UNKNOWN"; ///! Unrecognized object + } +} + void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, QStringList& theScript, const Handle(HYDROData_Entity)& theRefObject, const QString& theMethod ) const { - if ( theRefObject.IsNull() ) + if ( !checkObjectPythonDefinition( theTreatedObjects, theScript, theRefObject ) ) return; QString aRefObjName = theRefObject->GetObjPyName(); + + QString anObjName = GetObjPyName(); + theScript << QString( "%1.%2( %3 );" ) + .arg( anObjName ).arg( theMethod ).arg( aRefObjName ); +} + +bool HYDROData_Entity::checkObjectPythonDefinition( MapOfTreatedObjects& theTreatedObjects, + QStringList& theScript, + const Handle(HYDROData_Entity)& theRefObject ) const +{ + if ( theRefObject.IsNull() ) + return false; + + QString aRefObjName = theRefObject->GetName(); if ( aRefObjName.isEmpty() ) - return; + return false; - bool anIsToSetObject = true; + if ( theTreatedObjects.contains( aRefObjName ) ) + return true; // The definition of reference object must be dumped before this - if ( !theTreatedObjects.contains( aRefObjName ) ) - { - // Write definition of reference polyline - QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects ); - if ( ( anIsToSetObject = !aRefObjDump.isEmpty() ) ) - { - QStringList aTmpList = theScript; - theScript = aRefObjDump; + QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects ); + if ( aRefObjDump.isEmpty() ) + return false; - theScript << QString( "" ); - theScript << aTmpList; + QStringList aTmpList = theScript; + theScript = aRefObjDump; - theTreatedObjects.insert( aRefObjName, theRefObject ); - } - } + theScript << QString( "" ); + theScript << aTmpList; - if ( anIsToSetObject ) - { - QString anObjName = GetObjPyName(); - theScript << QString( "%1.%2( %3 );" ) - .arg( anObjName ).arg( theMethod ).arg( aRefObjName ); - } + theTreatedObjects.insert( aRefObjName, theRefObject ); + + return true; } void HYDROData_Entity::setPythonObjectColor( QStringList& theScript, @@ -548,4 +714,32 @@ void HYDROData_Entity::setPythonObjectColor( QStringList& theScript, .arg( theColor.blue() ).arg( theColor.alpha() ); } +void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, + QStringList& theScript ) const +{ + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) + return; + + theScript << QString( "%1 = %2.FindObjectByName( \"%3\" );" ).arg( GetObjPyName() ) + .arg( aDocument->GetDocPyName() ) + .arg( GetName() ); +} + +void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape ) +{ + TNaming_Builder aBuilder( myLab.FindChild( theTag ) ); + aBuilder.Generated( theShape ); +} +TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const +{ + TDF_Label aShapeLabel = myLab.FindChild( theTag, false ); + if ( !aShapeLabel.IsNull() ) + { + Handle(TNaming_NamedShape) aNamedShape; + if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) + return aNamedShape->Get(); + } + return TopoDS_Shape(); +}