Salome HOME
porting on linux
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index d10c3b09eb00b4f5608d239c401749a1922ed6a9..4b8a76ede2252fff6b4f2700f68fba7273368190 100644 (file)
 #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>
+#include <TDataStd_Real.hxx>
 #include <TDF_CopyLabel.hxx>
 #include <TDF_ListIteratorOfLabelList.hxx>
 #include <TNaming_Builder.hxx>
@@ -37,6 +39,9 @@
 #include <QStringList>
 #include <QVariant>
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects()
   : NCollection_Sequence<Handle_HYDROData_Entity>()
 {
@@ -52,7 +57,6 @@ HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const NCollection_Sequ
 {
 }
 
-
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Entity,MMgt_TShared)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Entity,MMgt_TShared)
 
@@ -82,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,
@@ -598,9 +633,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( "" );
 
@@ -610,7 +645,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( "" );
     }
@@ -621,6 +656,7 @@ QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreate
 
 QString HYDROData_Entity::getPyTypeID() const
 {
+  DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind());
   switch( GetKind() )
   {
     case KIND_IMAGE:             return "KIND_IMAGE";
@@ -650,6 +686,7 @@ QString HYDROData_Entity::getPyTypeID() const
     case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
     case KIND_STRICKLER_TABLE:   return "KIND_STRICKLER_TABLE";
     case KIND_LAND_COVER_OBSOLETE: return "";
+    case KIND_CHANNEL_ALTITUDE:  return "KIND_CHANNEL_ALTITUDE";
     case KIND_LAND_COVER_MAP:    return "KIND_LAND_COVER_MAP";
     default:                     return "KIND_UNKNOWN"; ///! Unrecognized object
   }
@@ -667,7 +704,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 );
 }
 
@@ -711,22 +748,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;
-    
-  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 )
@@ -746,3 +803,22 @@ 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();
+}