Salome HOME
Bug #487: dump/load script - problem with obstacle.
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index b103d112c9daccc7305f9496dacfe2cbdf285415..ba2cb941f77c21b43c12ba93f98eb9ea7e5c00b9 100644 (file)
@@ -9,6 +9,7 @@
 #include <TDataStd_UAttribute.hxx>
 #include <TDataStd_IntegerArray.hxx>
 #include <TDataStd_BooleanArray.hxx>
+#include <TDataStd_Integer.hxx>
 #include <TDataStd_RealArray.hxx>
 #include <TDataStd_ReferenceList.hxx>
 
@@ -45,7 +46,10 @@ QString HYDROData_Entity::GetName() const
 
 QString HYDROData_Entity::GetObjPyName() const
 {
-  return GetName().replace(" ", "_");
+  QString aName = GetName();
+  aName.replace(QRegExp("[\\W]"), "_");
+
+  return aName;
 }
 
 void HYDROData_Entity::SetName(const QString& theName)
@@ -59,62 +63,31 @@ QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjec
   return anEmptyList;
 }
 
-QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
+void HYDROData_Entity::Update()
 {
-  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( "" );
+  SetToUpdate( false );
+}
 
-  return aResList;
+void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
+{
+  //On the base level no actions are necessary
 }
 
-void HYDROData_Entity::Update()
+bool HYDROData_Entity::IsHas2dPrs() const
 {
-  SetToUpdate( false );
+  return false;
 }
 
-QString HYDROData_Entity::getPyTypeID() const
+void HYDROData_Entity::Show()
 {
-  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
-  }
+  if ( !IsHas2dPrs() )
+    return;
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return;
+
+  aDocument->Show( this );
 }
 
 QVariant HYDROData_Entity::GetDataVariant()
@@ -206,13 +179,44 @@ HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
   return HYDROData_SequenceOfObjects();
 }
 
-void HYDROData_Entity::SetLabel(TDF_Label theLabel)
+Standard_Boolean HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const
+{
+  theLevel = -1;
+
+  TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
+  if ( !aLabel.IsNull() )
+  {
+    Handle(TDataStd_Integer) anIntVal;
+    if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
+    {
+      theLevel = anIntVal->Get();
+      return Standard_True;
+    }
+  }
+
+  return Standard_False;
+}
+
+void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel )
+{
+  TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel );
+}
+
+void HYDROData_Entity::RemoveZLevel()
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
+  if ( !aLabel.IsNull() )
+    aLabel.ForgetAllAttributes();
+}
+
+void HYDROData_Entity::SetLabel( const TDF_Label& theLabel )
 {
   myLab = theLabel;
 }
 
-void HYDROData_Entity::SaveByteArray(const int theTag, 
-  const char* theData, const int theLen)
+void HYDROData_Entity::SaveByteArray( const int   theTag, 
+                                      const char* theData,
+                                      const int   theLen )
 {
   TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
   // array is empty, remove the attribute
@@ -494,6 +498,71 @@ QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
   return aResColor;
 }
 
+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( "" );
+
+  if ( IsHas2dPrs() )
+  {
+    // Dump object z-level in viewer
+    Standard_Integer anObjZLevel = -1;
+    if ( GetZLevel( anObjZLevel ) )
+    {
+      aResList << QString( "%1.SetZLevel( %2 );" )
+                  .arg( aName ).arg( anObjZLevel );
+      aResList << QString( "" );
+    }
+  }
+
+  return aResList;
+}
+
+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
+  }
+}
+
 void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
                                                  QStringList&                    theScript,
                                                  const Handle(HYDROData_Entity)& theRefObject,
@@ -554,4 +623,14 @@ void HYDROData_Entity::setPythonObjectColor( QStringList&         theScript,
               .arg( theColor.blue() ).arg( theColor.alpha() );
 }
 
-
+void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
+                                                  QStringList& theScript ) 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() );
+}