Salome HOME
Bug #334: Different behavior in Edit calculation case input panel.
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index 797973eaef0d0f273a94d6efdcd6db55ca93602e..f3f37eeb9f0fab5e5dde63df7420ea9eddaf7537 100644 (file)
@@ -499,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->GetObjPyName();
   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( GetObjPyName() ).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() );
 }