X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Entity.cxx;h=db2a8cdc4be7e353ace80a76cfcf436e59488a8a;hb=21cfaf7ae27087a9fe7f719d8a62df0a28102da9;hp=7f89f137a2047b0605481adffe4b9b3ffc28dfab;hpb=2b03abaf3d543206a0dd3eca896c05e22490c74e;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index 7f89f137..db2a8cdc 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -16,28 +16,31 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "HYDROData_Entity.h" - -#include "HYDROData_Iterator.h" -#include "HYDROData_Tool.h" - +#include +#include +#include +#include +#include #include #include #include -#include -#include #include -#include +#include #include - +#include #include #include - +#include +#include +#include #include -#include +#include #include #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects() : NCollection_Sequence() { @@ -53,9 +56,6 @@ HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const NCollection_Sequ { } - -static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000"); - IMPLEMENT_STANDARD_HANDLE(HYDROData_Entity,MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Entity,MMgt_TShared) @@ -90,7 +90,8 @@ void HYDROData_Entity::SetName(const QString& theName) TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); } -QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList anEmptyList; return anEmptyList; @@ -98,7 +99,7 @@ QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjec void HYDROData_Entity::Update() { - SetToUpdate( false ); + ClearChanged(); } void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy ) @@ -128,31 +129,61 @@ QVariant HYDROData_Entity::GetDataVariant() return QVariant(); } -void HYDROData_Entity::SetToUpdate( bool theFlag ) +void HYDROData_Entity::ClearChanged() { - if ( IsMustBeUpdated() == theFlag ) + TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 ); +} + +int HYDROData_Entity::GetGeomChangeFlag() const +{ + 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::Changed( Geometry theChangedGeometry ) +{ + 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(); + + int aBitsToChange = ( myGeom & theChangedGeometry ); + if( aBitsToChange == 0 ) + return; - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); - if ( !aDocument.IsNull() ) + 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 @@ -175,7 +206,8 @@ bool HYDROData_Entity::CanRemove() return true; } -HYDROData_Entity::HYDROData_Entity() +HYDROData_Entity::HYDROData_Entity( Geometry theGeom ) + : myGeom( theGeom ) { } @@ -569,9 +601,9 @@ QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreate QString aDocName = aDocument->GetDocPyName(); QString aName = GetObjPyName(); - aResList << QString( "%1 = %2.CreateObject( %3 );" ) + aResList << QString( "%1 = %2.CreateObject( %3 )" ) .arg( aName ).arg( aDocName ).arg( getPyTypeID() ); - aResList << QString( "%1.SetName( \"%2\" );" ) + aResList << QString( "%1.SetName( \"%2\" )" ) .arg( aName ).arg( GetName() ); aResList << QString( "" ); @@ -581,7 +613,7 @@ QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreate Standard_Integer anObjZLevel = -1; if ( GetZLevel( anObjZLevel ) ) { - aResList << QString( "%1.SetZLevel( %2 );" ) + aResList << QString( "%1.SetZLevel( %2 )" ) .arg( aName ).arg( anObjZLevel ); aResList << QString( "" ); } @@ -592,6 +624,7 @@ QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreate QString HYDROData_Entity::getPyTypeID() const { + DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind()); switch( GetKind() ) { case KIND_IMAGE: return "KIND_IMAGE"; @@ -616,32 +649,35 @@ QString HYDROData_Entity::getPyTypeID() const 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_SPLIT_GROUP: return "KIND_SPLIT_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_CHANNEL_ALTITUDE: return "KIND_CHANNEL_ALTITUDE"; case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP"; default: return "KIND_UNKNOWN"; ///! Unrecognized object } } -void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, +void HYDROData_Entity::setPythonReferenceObject( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, QStringList& theScript, const Handle(HYDROData_Entity)& theRefObject, const QString& theMethod ) const { - if ( !checkObjectPythonDefinition( theTreatedObjects, theScript, theRefObject ) ) + if ( !checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, theScript, theRefObject ) ) return; QString aRefObjName = theRefObject->GetObjPyName(); QString anObjName = GetObjPyName(); - theScript << QString( "%1.%2( %3 );" ) + theScript << QString( "%1.%2( %3 )" ) .arg( anObjName ).arg( theMethod ).arg( aRefObjName ); } -bool HYDROData_Entity::checkObjectPythonDefinition( MapOfTreatedObjects& theTreatedObjects, +bool HYDROData_Entity::checkObjectPythonDefinition( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, QStringList& theScript, const Handle(HYDROData_Entity)& theRefObject ) const { @@ -656,7 +692,7 @@ bool HYDROData_Entity::checkObjectPythonDefinition( MapOfTreatedObjects& return true; // The definition of reference object must be dumped before this - QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects ); + QStringList aRefObjDump = theRefObject->DumpToPython( thePyScriptPath, theTreatedObjects ); if ( aRefObjDump.isEmpty() ) return false; @@ -680,7 +716,7 @@ void HYDROData_Entity::setPythonObjectColor( QStringList& theScript, return; //Do not set the color for object if it like default QString anObjName = GetObjPyName(); - theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) );" ) + theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) )" ) .arg( anObjName ).arg( theMethod ) .arg( theColor.red() ).arg( theColor.green() ) .arg( theColor.blue() ).arg( theColor.alpha() ); @@ -693,7 +729,44 @@ void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreate if ( aDocument.IsNull() ) return; - theScript << QString( "%1 = %2.FindObjectByName( \"%3\" );" ).arg( GetObjPyName() ) + 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(); +} + +void HYDROData_Entity::SetDouble( int theTag, double theValue ) +{ + Handle(TDataStd_Real) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) ) + aLabel.AddAttribute( anAttr = new TDataStd_Real() ); + anAttr->Set( theValue ); +} + +double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const +{ + Handle(TDataStd_Real) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) ) + return theDefValue; + + return anAttr->Get(); +}