From: Paul RASCLE Date: Fri, 1 Jul 2016 11:57:26 +0000 (+0200) Subject: debug dump Python calculation case with new region names X-Git-Tag: v1.6~95 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1c793d12fface8f13748ff87c5dd04e6b1239c0e;p=modules%2Fhydro.git debug dump Python calculation case with new region names --- diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 78c2de68..de643ebb 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -985,7 +985,7 @@ Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(H AddRegion( aNewRegion ); QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName; - aNewRegion->SetName( aRegionName ); + aNewRegion->SetName( aRegionName, true ); return aNewRegion; } @@ -1341,18 +1341,28 @@ void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList, const HYDROData_SequenceOfObjects& theRegions ) const { HYDROData_SequenceOfObjects::Iterator anIter; - anIter.Init( theRegions ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Region) aRegion = - Handle(HYDROData_Region)::DownCast( anIter.Value() ); - if ( aRegion.IsNull() ) - continue; - - theTreatedObjects.insert( aRegion->GetName(), aRegion ); - QStringList aRegDump = aRegion->DumpToPython( thePyScriptPath, theTreatedObjects ); - theResList << aRegDump; - } + anIter.Init(theRegions); + for (int ireg = 1; anIter.More(); anIter.Next(), ireg++) + { + Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value()); + if (aRegion.IsNull()) + continue; + QString defRegName = this->GetName(); + QString regSuffix = QString("_Reg_%1").arg(ireg); + defRegName += regSuffix; + theTreatedObjects.insert(aRegion->GetName(), aRegion); + QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName); + theResList << aRegDump; + } + for (anIter.Init(theRegions); anIter.More(); anIter.Next()) + { + Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value()); + if (aRegion.IsNull()) + continue; + QStringList aRegDump; + aRegion->SetNameInDumpPython(aRegDump); + theResList << aRegDump; + } } bool HYDROData_CalculationCase::GetRule( int theIndex, diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index db2a8cdc..4b8a76ed 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -85,9 +86,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, @@ -722,16 +754,36 @@ void HYDROData_Entity::setPythonObjectColor( QStringList& theScript, .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; - - theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() ) - .arg( aDocument->GetDocPyName() ) - .arg( GetName() ); + + 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; + + 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 ) diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index ab2ca47b..51186e60 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -23,9 +23,9 @@ #include #include #include +#include class QColor; -class QString; class QVariant; class QStringList; class Handle(TDataStd_ReferenceList); @@ -102,6 +102,7 @@ protected: DataTag_First = 0, ///< first tag, to reserve DataTag_ZLevel, ///< z-level of object presentation DataTag_GeomChange, + DataTag_DefaultName, ///< to keep the automatic name, useful in Python dump }; public: @@ -130,10 +131,15 @@ public: */ HYDRODATA_EXPORT virtual QString GetName() const; + /** + * Returns the default name of this object. + */ + HYDRODATA_EXPORT virtual QString GetDefaultName() const; + /** * Updates the name of this object. */ - HYDRODATA_EXPORT void SetName( const QString& theName ); + HYDRODATA_EXPORT void SetName( const QString& theName, bool isDefault = false ); /** * Returns the name of this object valid for Python script. @@ -249,14 +255,22 @@ public: HYDRODATA_EXPORT virtual void RemoveZLevel(); /** - Find the Python object in the document by the object name. - @param theTreatedObjects the map of treated objects + Add in Python script the find instruction, to retrieve the Python object in the document by the object name. @param theScript the script + @param defName the name to use, if not default name. */ - void findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, - QStringList& theScript ) const; + void findPythonReferenceObject( QStringList& theScript, + QString defName = QString()) const; /** + Add in Python script the set name instruction. + @param theScript the script + @param defName the name to use, if not default name. + */ + void SetNameInDumpPython(QStringList& theScript, + QString theName = QString()) const; + + /** * Internal method that used to store the color attribute * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) * \param theColor color to save diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 60210bbc..0a0604d8 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -389,12 +389,13 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* } QStringList HYDROData_Region::DumpToPython( const QString& thePyScriptPath, - MapOfTreatedObjects& theTreatedObjects ) const + MapOfTreatedObjects& theTreatedObjects, + QString defRegName ) const { QStringList aResList; // Find region - findPythonReferenceObject( theTreatedObjects, aResList ); + findPythonReferenceObject( aResList, defRegName ); // Add zones HYDROData_SequenceOfObjects aZones = GetZones(); @@ -407,7 +408,7 @@ QStringList HYDROData_Region::DumpToPython( const QString& thePyScriptPath } // find zone - aZone->findPythonReferenceObject( theTreatedObjects, aResList ); + aZone->findPythonReferenceObject( aResList ); theTreatedObjects.insert( aZone->GetName(), aZone ); // set zone merge type @@ -427,7 +428,7 @@ QStringList HYDROData_Region::DumpToPython( const QString& thePyScriptPath if ( aMergeType == HYDROData_Zone::Merge_Object ) { Handle(HYDROData_Entity) aMergeObject = aZone->GetMergeObject(); if ( !aMergeObject.IsNull() ) { - aMergeObject->findPythonReferenceObject( theTreatedObjects, aResList ); + aMergeObject->findPythonReferenceObject( aResList ); aResList << QString( "%1.SetMergeObject( %2 )" ).arg( aZone->GetObjPyName() ) .arg( aMergeObject->GetObjPyName() ); } diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index f92ae0e1..08af0ab6 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -60,7 +60,8 @@ public: * Dump object to Python script representation. */ HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, - MapOfTreatedObjects& theTreatedObjects ) const; + MapOfTreatedObjects& theTreatedObjects, + QString defRegName = QString()) const; /** * Returns flag indicating that object is updateble or not.