Salome HOME
Get altitude from region implementation.
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index 2e194aa976d180cc95e89397ead2a637bf803a7f..b103d112c9daccc7305f9496dacfe2cbdf285415 100644 (file)
@@ -43,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()));
@@ -63,12 +68,12 @@ QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreate
     return aResList;
 
   QString aDocName = aDocument->GetDocPyName();
-  QString aName = GetName();
+  QString aName = GetObjPyName();
 
   aResList << QString( "%1 = %2.CreateObject( %3 );" )
               .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
   aResList << QString( "%1.SetName( \"%2\" );" )
-              .arg( aName ).arg( aName );
+              .arg( aName ).arg( GetName() );
   aResList << QString( "" );
 
   return aResList;
@@ -494,37 +499,59 @@ void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects&
                                                  const Handle(HYDROData_Entity)& theRefObject,
                                                  const QString&                  theMethod ) const
 {
-  if ( theRefObject.IsNull() )
+  if ( !checkObjectPythonDefinition( theTreatedObjects, theScript, theRefObject ) )
     return;
 
+  QString aRefObjName = theRefObject->GetObjPyName();
+
+  QString anObjName = GetObjPyName();
+  theScript << QString( "%1.%2( %3 );" )
+               .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
+}
+
+bool HYDROData_Entity::checkObjectPythonDefinition( MapOfTreatedObjects&            theTreatedObjects,
+                                                    QStringList&                    theScript,
+                                                    const Handle(HYDROData_Entity)& theRefObject ) const
+{
+  if ( theRefObject.IsNull() )
+    return false;
+
   QString aRefObjName = theRefObject->GetName();
   if ( aRefObjName.isEmpty() )
-    return;
+    return false;
 
-  bool anIsToSetObject = true;
+  if ( theTreatedObjects.contains( aRefObjName ) )
+    return true;
 
   // The definition of reference object must be dumped before this
-  if ( !theTreatedObjects.contains( aRefObjName ) )
-  {
-    // Write definition of reference polyline
-    QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects );
-    if ( ( anIsToSetObject = !aRefObjDump.isEmpty() ) )
-    {
-      QStringList aTmpList = theScript;
-      theScript = aRefObjDump;
+  QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects );
+  if ( aRefObjDump.isEmpty() )
+    return false;
 
-      theScript << QString( "" );
-      theScript << aTmpList;
+  QStringList aTmpList = theScript;
+  theScript = aRefObjDump;
 
-      theTreatedObjects.insert( aRefObjName, theRefObject );
-    }
-  }
+  theScript << QString( "" );
+  theScript << aTmpList;
 
-  if ( anIsToSetObject )
-  {
-    theScript << QString( "%1.%2( %3 );" )
-                 .arg( GetName() ).arg( theMethod ).arg( aRefObjName );
-  }
+  theTreatedObjects.insert( aRefObjName, theRefObject );
+
+  return true;
+}
+
+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() );
 }