X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Entity.cxx;h=62a7095e0f181f97a07fb36c24cf8628555d0ea5;hb=fce3f1240b6161d7cb837344078e5943b90eca65;hp=a02fc5da0010648d279f6c44294b6d88e6799a8a;hpb=cde2ec476486fcd7c9b7b38ce814c648d73e7fd3;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index a02fc5da..62a7095e 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -24,9 +24,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -41,25 +43,24 @@ #include "HYDRO_trace.hxx" HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects() - : NCollection_Sequence() + : NCollection_Sequence() { } HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& theSequence ) - : NCollection_Sequence( theSequence ) + : NCollection_Sequence( theSequence ) { } -HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const NCollection_Sequence& 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) // is equal function for unique object mapping -bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2) +bool IsEqual(const Handle(HYDROData_Entity)& theObj1, const Handle(HYDROData_Entity)& theObj2) { if ( !theObj1.IsNull() && !theObj2.IsNull() ) return theObj1->Label() == theObj2->Label(); @@ -84,9 +85,40 @@ QString HYDROData_Entity::GetObjPyName() const return aName; } -void HYDROData_Entity::SetName(const QString& theName) +QString HYDROData_Entity::GetDefaultName() const +{ + QString aName; + + TDF_Label aLabel = myLab.FindChild(DataTag_DefaultName, false); + if (!aLabel.IsNull()) + { + Handle(TDataStd_AsciiString) anAsciiStr; + if (aLabel.FindAttribute(TDataStd_AsciiString::GetID(), anAsciiStr)) + aName = QString(anAsciiStr->Get().ToCString()); + } + else + aName = GetName(); + + return aName; + +} + +void HYDROData_Entity::SetName(const QString& theName, bool isDefault) { TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); + 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 )) + { + TCollection_AsciiString aName = theName.toStdString().c_str(); + theDefaultName = TDataStd_AsciiString::Set(myLab.FindChild( DataTag_DefaultName), aName ); + } + } } QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath, @@ -270,7 +302,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; @@ -281,11 +313,11 @@ 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 ) @@ -302,7 +334,7 @@ void HYDROData_Entity::RemoveZLevel() void HYDROData_Entity::SetLabel( const TDF_Label& theLabel ) { - myLab = theLabel; + myLab = theLabel; } void HYDROData_Entity::SaveByteArray( const int theTag, @@ -320,15 +352,19 @@ void HYDROData_Entity::SaveByteArray( const int theTag, if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) { aData = TDataStd_ByteArray::Set(aLab, 1, theLen); } + 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]); } } @@ -350,7 +386,7 @@ int HYDROData_Entity::NbReferenceObjects( const int theTag ) const return aRefs.IsNull() ? 0 : aRefs->Extent(); } -bool HYDROData_Entity::HasReference( const Handle_HYDROData_Entity& theObj, +bool HYDROData_Entity::HasReference( const Handle(HYDROData_Entity)& theObj, const int theTag ) const { if ( theObj.IsNull() ) @@ -371,7 +407,7 @@ bool HYDROData_Entity::HasReference( const Handle_HYDROData_Entity& theObj, return false; } -void HYDROData_Entity::AddReferenceObject( const Handle_HYDROData_Entity& theObj, +void HYDROData_Entity::AddReferenceObject( const Handle(HYDROData_Entity)& theObj, const int theTag ) { if ( theObj.IsNull() ) @@ -381,7 +417,7 @@ void HYDROData_Entity::AddReferenceObject( const Handle_HYDROData_Entity& theObj aRefs->Append( theObj->Label() ); } -void HYDROData_Entity::SetReferenceObject( const Handle_HYDROData_Entity& theObj, +void HYDROData_Entity::SetReferenceObject( const Handle(HYDROData_Entity)& theObj, const int theTag, const int theIndex ) { @@ -415,7 +451,7 @@ void HYDROData_Entity::SetReferenceObject( const Handle_HYDROData_Entity& theObj } } -void HYDROData_Entity::InsertReferenceObject( const Handle_HYDROData_Entity& theObj, +void HYDROData_Entity::InsertReferenceObject( const Handle(HYDROData_Entity)& theObj, const int theTag, const int theBeforeIndex ) { @@ -457,6 +493,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 ); @@ -546,12 +583,12 @@ 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 ); - return aRefs; } @@ -600,9 +637,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( "" ); @@ -612,7 +649,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( "" ); } @@ -623,7 +660,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"; @@ -671,7 +708,7 @@ void HYDROData_Entity::setPythonReferenceObject( const QString& QString aRefObjName = theRefObject->GetObjPyName(); QString anObjName = GetObjPyName(); - theScript << QString( "%1.%2( %3 );" ) + theScript << QString( "%1.%2( %3 )" ) .arg( anObjName ).arg( theMethod ).arg( aRefObjName ); } @@ -715,22 +752,42 @@ 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() ); } -void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, - QStringList& theScript ) const +void HYDROData_Entity::findPythonReferenceObject( QStringList& theScript, + QString defName) const +{ + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) + return; + + if (defName.isEmpty()) + theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() ) + .arg( aDocument->GetDocPyName() ) + .arg( GetDefaultName() ); + else + theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() ) + .arg( aDocument->GetDocPyName() ) + .arg( defName ); +} + +void HYDROData_Entity::SetNameInDumpPython(QStringList& theScript, + QString theName) 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() ); + + if (theName.isEmpty()) + theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() ) + .arg( GetName() ); + else + theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() ) + .arg( theName ); } void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape ) @@ -750,3 +807,49 @@ TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const } 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(); +} + +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 ) ) + aLabel.AddAttribute( anAttr = new TDataStd_Integer() ); + 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; +} +