AddRegion( aNewRegion );
QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
- aNewRegion->SetName( aRegionName );
+ aNewRegion->SetName( aRegionName, true );
return aNewRegion;
}
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,
#include <TDataStd_Name.hxx>
#include <TDataStd_ByteArray.hxx>
#include <TDataStd_UAttribute.hxx>
+#include <TDataStd_AsciiString.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_IntegerArray.hxx>
#include <TDataStd_ReferenceList.hxx>
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,
.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 )
#include <NCollection_Sequence.hxx>
#include <TDF_Label.hxx>
#include <QMap>
+#include <QString>
class QColor;
-class QString;
class QVariant;
class QStringList;
class Handle(TDataStd_ReferenceList);
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:
*/
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.
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
}
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();
}
// find zone
- aZone->findPythonReferenceObject( theTreatedObjects, aResList );
+ aZone->findPythonReferenceObject( aResList );
theTreatedObjects.insert( aZone->GetName(), aZone );
// set zone merge type
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() );
}
* 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.