]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
debug dump Python calculation case with new region names
authorPaul RASCLE <paul.rascle@edf.fr>
Fri, 1 Jul 2016 11:57:26 +0000 (13:57 +0200)
committerPaul RASCLE <paul.rascle@edf.fr>
Fri, 1 Jul 2016 11:57:26 +0000 (13:57 +0200)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_Entity.cxx
src/HYDROData/HYDROData_Entity.h
src/HYDROData/HYDROData_Region.cxx
src/HYDROData/HYDROData_Region.h

index 78c2de6856e3c2f11592ace8fb0bce9a866fc68a..de643ebba34e2712e453207b3a6ae7ea90d911ba 100644 (file)
@@ -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, 
index db2a8cdc4be7e353ace80a76cfcf436e59488a8a..4b8a76ede2252fff6b4f2700f68fba7273368190 100644 (file)
@@ -24,6 +24,7 @@
 #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>
@@ -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 )
index ab2ca47bcf8171ac696d45d5c3e16801405ccb3f..51186e607beed5a9c755f78d1b15c17e2875d2f0 100644 (file)
@@ -23,9 +23,9 @@
 #include <NCollection_Sequence.hxx>
 #include <TDF_Label.hxx>
 #include <QMap>
+#include <QString>
 
 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
index 60210bbc30e700e689d31d8d9f0f40faac5b8262..0a0604d84e71dbcee638c651714de1a63149b205 100644 (file)
@@ -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() );
       }
index f92ae0e11de28c4e0203634126b38c0511b650ca..08af0ab65ef6c53ce724bcedf726a64baab2077c 100644 (file)
@@ -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.