Salome HOME
Dump to python corrected.
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index f8238ec656dbde367949cbcb1104f7ec09497f40..af16992f00e20e3650b3aad5bf2602def70de7b9 100644 (file)
@@ -2,6 +2,7 @@
 #include "HYDROData_Entity.h"
 
 #include "HYDROData_Iterator.h"
+#include "HYDROData_Tool.h"
 
 #include <TDataStd_Name.hxx>
 #include <TDataStd_ByteArray.hxx>
@@ -42,6 +43,11 @@ QString HYDROData_Entity::GetName() const
   return QString();
 }
 
+QString HYDROData_Entity::GetObjPyName() const
+{
+  return GetName().replace(" ", "_");
+}
+
 void HYDROData_Entity::SetName(const QString& theName)
 {
   TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
@@ -53,8 +59,62 @@ QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjec
   return anEmptyList;
 }
 
+QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
+{
+  QStringList aResList;
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return aResList;
+
+  QString aDocName = aDocument->GetDocPyName();
+  QString aName = GetObjPyName();
+
+  aResList << QString( "%1 = %2.CreateObject( %3 );" )
+              .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
+  aResList << QString( "%1.SetName( \"%2\" );" )
+              .arg( aName ).arg( GetName() );
+  aResList << QString( "" );
+
+  return aResList;
+}
+
 void HYDROData_Entity::Update()
 {
+  SetToUpdate( false );
+}
+
+QString HYDROData_Entity::getPyTypeID() const
+{
+  switch( GetKind() )
+  {
+    case KIND_IMAGE:             return "KIND_IMAGE";
+    case KIND_POLYLINE:          return "KIND_POLYLINE";
+    case KIND_BATHYMETRY:        return "KIND_BATHYMETRY";
+    case KIND_ALTITUDE:          return "KIND_ALTITUDE";
+    case KIND_IMMERSIBLE_ZONE:   return "KIND_IMMERSIBLE_ZONE";
+    case KIND_RIVER:             return "KIND_RIVER";
+    case KIND_STREAM:            return "KIND_STREAM";
+    case KIND_CONFLUENCE:        return "KIND_CONFLUENCE";
+    case KIND_CHANNEL:           return "KIND_CHANNEL";
+    case KIND_OBSTACLE:          return "KIND_OBSTACLE";
+    case KIND_DIGUE:             return "KIND_DIGUE";
+    case KIND_PROFILE:           return "KIND_PROFILE";
+    case KIND_PROFILEUZ:         return "KIND_PROFILEUZ";
+    case KIND_POLYLINEXY:        return "KIND_POLYLINEXY";
+    case KIND_CALCULATION:       return "KIND_CALCULATION";
+    case KIND_ZONE:              return "KIND_ZONE";
+    case KIND_REGION:            return "KIND_REGION";
+    case KIND_VISUAL_STATE:      return "KIND_VISUAL_STATE";
+    case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT";
+    case KIND_NATURAL_OBJECT:    return "KIND_NATURAL_OBJECT";
+    case KIND_DUMMY_3D:          return "KIND_DUMMY_3D";
+    case KIND_SHAPES_GROUP:      return "KIND_SHAPES_GROUP";
+    case KIND_SPLITTED_GROUP:    return "KIND_SPLITTED_GROUP";
+    case KIND_STREAM_ALTITUDE:   return "KIND_STREAM_ALTITUDE";
+    case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
+    default:                     return "KIND_UNKNOWN"; ///! Unrecognized object
+  }
 }
 
 QVariant HYDROData_Entity::GetDataVariant()
@@ -62,11 +122,21 @@ QVariant HYDROData_Entity::GetDataVariant()
   return QVariant();
 }
 
-void HYDROData_Entity::SetToUpdate(bool theFlag)
+void HYDROData_Entity::SetToUpdate( bool theFlag )
 {
+  if ( IsMustBeUpdated() == theFlag )
+    return;
+
   if ( theFlag )
   {
     TDataStd_UAttribute::Set( myLab, GUID_MUST_BE_UPDATED );
+
+    Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+    if ( !aDocument.IsNull() )
+    {
+      // Change the states of this and all depended objects
+      HYDROData_Tool::SetMustBeUpdatedObjects( aDocument );
+    }
   }
   else
   {
@@ -79,6 +149,11 @@ bool HYDROData_Entity::IsMustBeUpdated() const
   return myLab.IsAttribute( GUID_MUST_BE_UPDATED );
 }
 
+bool HYDROData_Entity::CanBeUpdated() const
+{
+  return true;
+}
+
 bool HYDROData_Entity::IsRemoved() const
 {
   return !myLab.HasAttribute();
@@ -89,6 +164,11 @@ void HYDROData_Entity::Remove()
   return myLab.ForgetAllAttributes( true );
 }
 
+bool HYDROData_Entity::CanRemove()
+{
+  return true;
+}
+
 HYDROData_Entity::HYDROData_Entity()
 {
 }
@@ -97,7 +177,7 @@ HYDROData_Entity::~HYDROData_Entity()
 {
 }
 
-void HYDROData_Entity::CopyTo(Handle_HYDROData_Entity theDestination) const
+void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const
 {
   TDF_CopyLabel aCopy(myLab, theDestination->Label());
   aCopy.Perform();
@@ -121,6 +201,11 @@ Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const
   return aFather;
 }
 
+HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
+{
+  return HYDROData_SequenceOfObjects();
+}
+
 void HYDROData_Entity::SetLabel(TDF_Label theLabel)
 {
   myLab = theLabel;
@@ -417,7 +502,7 @@ void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects&
   if ( theRefObject.IsNull() )
     return;
 
-  QString aRefObjName = theRefObject->GetName();
+  QString aRefObjName = theRefObject->GetObjPyName();
   if ( aRefObjName.isEmpty() )
     return;
 
@@ -442,9 +527,25 @@ void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects&
 
   if ( anIsToSetObject )
   {
+    QString anObjName = GetObjPyName();
     theScript << QString( "%1.%2( %3 );" )
-                 .arg( GetName() ).arg( theMethod ).arg( aRefObjName );
+                 .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
   }
 }
 
+void HYDROData_Entity::setPythonObjectColor( QStringList&         theScript,
+                                             const QColor&        theColor,
+                                             const QColor&        theDefaultColor,
+                                             const QString&       theMethod ) const
+{
+  if ( theColor == theDefaultColor )
+    return; //Do not set the color for object if it like default
+
+  QString anObjName = GetObjPyName();
+  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() );
+}
+