X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Entity.cxx;h=94c4921a78dc8e04e42db0b1440bd7abba083a6e;hb=c16caee6b6e61dffbc739dce6639215b24a459d3;hp=ce65478918e3ed68de4909d4cd9d2aa74ee3842c;hpb=05d82ada59110252be57aaa774095a18ebdca455;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index ce654789..94c4921a 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -77,11 +77,91 @@ QString HYDROData_Entity::GetName() const return QString(); } +QString HYDROData_Entity::GetType() const +{ + return Type( GetKind() ); +} + +QString HYDROData_Entity::Type( ObjectKind theKind ) +{ + switch( theKind ) + { + case KIND_UNKNOWN: + return "Unknown"; + case KIND_IMAGE: + return "Image"; + case KIND_POLYLINE: + return "Polyline"; + case KIND_BATHYMETRY: + return "Bathymetry"; + case KIND_ALTITUDE: + return "Altitude"; + case KIND_IMMERSIBLE_ZONE: + return "Immersible_zone"; + case KIND_RIVER: + return "River"; + case KIND_STREAM: + return "Stream"; + case KIND_CONFLUENCE: + return "Confluence"; + case KIND_CHANNEL: + return "Channel"; + case KIND_OBSTACLE: + return "Obstacle"; + case KIND_DIGUE: + return "Digue"; + case KIND_PROFILE: + return "Profile"; + case KIND_PROFILEUZ: + return "Profile_UZ"; + case KIND_POLYLINEXY: + return "Polyline_XY"; + case KIND_CALCULATION: + return "Calculation_case"; + case KIND_ZONE: + return "Zone"; + case KIND_REGION: + return "Region"; + case KIND_VISUAL_STATE: + return "Visual_state"; + case KIND_ARTIFICIAL_OBJECT: + return "Artificial_object"; + case KIND_NATURAL_OBJECT: + return "Natural_object"; + case KIND_DUMMY_3D: + return "Dummy_3d"; + case KIND_SHAPES_GROUP: + return "Shapes_group"; + case KIND_SPLIT_GROUP: + return "Split_group"; + case KIND_STREAM_ALTITUDE: + return "Stream_altitude"; + case KIND_OBSTACLE_ALTITUDE: + return "Obstacle_altitude"; + case KIND_STRICKLER_TABLE: + return "Strickler_table"; + case KIND_LAND_COVER_OBSOLETE: + return "Land_cover"; + case KIND_CHANNEL_ALTITUDE: + return "Channel_altitude"; + case KIND_LAND_COVER_MAP: + return "Land_cover_map"; + case KIND_DTM: + return "DTM"; + case KIND_BC_POLYGON: + return "Boundary Polygon"; + } + return ""; +} + QString HYDROData_Entity::GetObjPyName() const { QString aName = GetName(); aName.replace(QRegExp("[\\W]"), "_"); + if( aName[0].isDigit() ) + aName = GetType() + "_" + aName; + return aName; } @@ -105,20 +185,22 @@ QString HYDROData_Entity::GetDefaultName() const void HYDROData_Entity::SetName(const QString& theName, bool isDefault) { - TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); + Handle(TDataStd_Name) A = TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); + A->SetID(TDataStd_Name::GetID()); if (isDefault) + { + TDF_Label aDefaultNameLabel = myLab.FindChild( DataTag_DefaultName, true ); + if ( aDefaultNameLabel.IsNull() ) + return; + Handle(TDataStd_AsciiString) theDefaultName; + + if ( !aDefaultNameLabel.FindAttribute( TDataStd_AsciiString::GetID(), theDefaultName )) { - TDF_Label aDefaultNameLabel = myLab.FindChild( DataTag_DefaultName, true ); - if ( aDefaultNameLabel.IsNull() ) - return; - Handle(TDataStd_AsciiString) theDefaultName; - - if ( !aDefaultNameLabel.FindAttribute( TDataStd_AsciiString::GetID(), theDefaultName )) - { - TCollection_AsciiString aName = theName.toStdString().c_str(); - theDefaultName = TDataStd_AsciiString::Set(myLab.FindChild( DataTag_DefaultName), aName ); - } + TCollection_AsciiString aName = theName.toStdString().c_str(); + theDefaultName = TDataStd_AsciiString::Set(myLab.FindChild( DataTag_DefaultName), aName ); + theDefaultName->SetID( TDataStd_AsciiString::GetID() ); } + } } QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath, @@ -162,7 +244,8 @@ QVariant HYDROData_Entity::GetDataVariant() void HYDROData_Entity::ClearChanged() { - TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 ); + Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 ); + A->SetID(TDataStd_Integer::GetID()); } int HYDROData_Entity::GetGeomChangeFlag() const @@ -194,7 +277,8 @@ void HYDROData_Entity::Changed( Geometry theChangedGeometry ) return; aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange ); - TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag ); + Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag ); + anAttr->SetID( TDataStd_Integer::GetID() ); HYDROData_Iterator anIter( aDocument ); for ( ; anIter.More(); anIter.Next() ) @@ -302,7 +386,7 @@ HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const return HYDROData_SequenceOfObjects(); } -Standard_Boolean HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const +bool HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const { theLevel = -1; @@ -313,16 +397,17 @@ Standard_Boolean HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) ) { theLevel = anIntVal->Get(); - return Standard_True; + return true; } } - return Standard_False; + return false; } void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel ) { - TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel ); + Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel ); + A->SetID(TDataStd_Integer::GetID()); } void HYDROData_Entity::RemoveZLevel() @@ -334,7 +419,7 @@ void HYDROData_Entity::RemoveZLevel() void HYDROData_Entity::SetLabel( const TDF_Label& theLabel ) { - myLab = theLabel; + myLab = theLabel; } void HYDROData_Entity::SaveByteArray( const int theTag, @@ -351,16 +436,21 @@ void HYDROData_Entity::SaveByteArray( const int theTag, Handle(TDataStd_ByteArray) aData; if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) { aData = TDataStd_ByteArray::Set(aLab, 1, theLen); + aData->SetID( TDataStd_ByteArray::GetID() ); } + Standard_Byte* Byte0 = &(aData->InternalArray()->ChangeArray1().ChangeFirst()); + memcpy(Byte0, theData, theLen * sizeof (char)); // copy bytes one by one if (aData->Length() != theLen) { Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen); for(int a = 0; a < theLen; a++) aNewData->SetValue(a + 1, theData[a]); aData->ChangeArray(aNewData); - } else { - for(int a = 0; a < theLen; a++) - aData->SetValue(a + 1, theData[a]); + } + else + { + // for(int a = 0; a < theLen; a++) + // aData->SetValue(a + 1, theData[a]); } } @@ -411,6 +501,7 @@ void HYDROData_Entity::AddReferenceObject( const Handle(HYDROData_Entity)& theOb Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true ); aRefs->Append( theObj->Label() ); + aRefs->SetID(TDataStd_ReferenceList::GetID()); } void HYDROData_Entity::SetReferenceObject( const Handle(HYDROData_Entity)& theObj, @@ -489,6 +580,7 @@ void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& t Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag, const int theIndex ) const { + //DEBTRACE("GetReferenceObject " << theTag << " " << theIndex); Handle(HYDROData_Entity) aRes; Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); @@ -578,12 +670,15 @@ void HYDROData_Entity::ClearReferenceObjects( const int theTag ) Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag, const bool theIsCreate ) const { + //DEBTRACE("getReferenceList " << theTag << " " << theIsCreate); TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); Handle(TDataStd_ReferenceList) aRefs; if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate ) + { aRefs = TDataStd_ReferenceList::Set( aLabel ); - + aRefs->SetID(TDataStd_ReferenceList::GetID()); + } return aRefs; } @@ -594,7 +689,10 @@ void HYDROData_Entity::SetColor( const QColor& theColor, Handle(TDataStd_IntegerArray) aColorArray; if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) + { aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 ); + aColorArray->SetID(TDataStd_IntegerArray::GetID()); + } aColorArray->SetValue( 1, theColor.red() ); aColorArray->SetValue( 2, theColor.green() ); @@ -655,7 +753,7 @@ QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreate QString HYDROData_Entity::getPyTypeID() const { - DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind()); + //DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind()); switch( GetKind() ) { case KIND_IMAGE: return "KIND_IMAGE"; @@ -687,6 +785,7 @@ QString HYDROData_Entity::getPyTypeID() const case KIND_LAND_COVER_OBSOLETE: return ""; case KIND_CHANNEL_ALTITUDE: return "KIND_CHANNEL_ALTITUDE"; case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP"; + case KIND_BC_POLYGON: return "KIND_BC_POLYGON"; default: return "KIND_UNKNOWN"; ///! Unrecognized object } } @@ -789,6 +888,7 @@ void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape ) { TNaming_Builder aBuilder( myLab.FindChild( theTag ) ); aBuilder.Generated( theShape ); + aBuilder.NamedShape()->SetID(TNaming_NamedShape::GetID()); } TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const @@ -808,7 +908,11 @@ 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 = new TDataStd_Real(); + anAttr->SetID(TDataStd_Real::GetID()); + aLabel.AddAttribute( anAttr ); + } anAttr->Set( theValue ); } @@ -821,3 +925,34 @@ double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const return anAttr->Get(); } + +void HYDROData_Entity::SetInteger( int theTag, int theValue ) +{ + Handle(TDataStd_Integer) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) ) + { + anAttr = new TDataStd_Integer(); + anAttr->SetID(TDataStd_Integer::GetID()); + aLabel.AddAttribute(anAttr); + } + anAttr->Set( theValue ); +} + +int HYDROData_Entity::GetInteger( int theTag, int theDefValue ) const +{ + Handle(TDataStd_Integer) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) ) + return 0; + + return anAttr->Get(); +} + +bool HYDROData_Entity::CompareLabels(const Handle(HYDROData_Entity)& theOtherObj) +{ + if ( !theOtherObj.IsNull() ) + return this->Label() == theOtherObj->Label(); + return false; +} +