Salome HOME
IPAL9192: string resources added for SPlot2d_SetupPlot2dDlg
[modules/gui.git] / src / SalomeApp / SalomeApp_DataObject.cxx
index 2822ed556869fffdaa760e665fd45518742ebd04..e7a922be8f9e89cd8ba5db8db13cd793d38959d6 100644 (file)
@@ -1,13 +1,20 @@
 #include "SalomeApp_DataObject.h"
-#include "SalomeApp_RootObject.h"
+
 #include "SalomeApp_Study.h"
+#include "SalomeApp_RootObject.h"
 
-#include <SUIT_DataObjectKey.h>
 #include <SUIT_Application.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_DataObjectKey.h>
 
 #include <qobject.h>
 
+#include <SALOMEDSClient_AttributeReal.hxx>
+#include <SALOMEDSClient_AttributeInteger.hxx>
+#include <SALOMEDSClient_AttributeComment.hxx>
+#include <SALOMEDSClient_AttributeTableOfReal.hxx>
+#include <SALOMEDSClient_AttributeTableOfInteger.hxx>
+
 /*!
        Class: SalomeApp_DataObject::Key
        Level: Internal
@@ -83,10 +90,22 @@ SUIT_DataObjectKey* SalomeApp_DataObject::key() const
 
 QString SalomeApp_DataObject::name() const
 {
+  QString str;
+
   if ( myObject )
-    return myObject->GetName().c_str();
-  return QString::null;
-  //return QString( "%1 [%2]" ).arg( myName ).arg( myEntry ); // for debug
+    str = myObject->GetName().c_str();
+
+  if ( str.isEmpty() )
+  {
+    _PTR(SObject) refObj = referencedObject();
+    if ( refObj )
+      str = refObj->GetName().c_str();
+  }
+
+  if ( isReference() )
+    str = QString( "* " ) + str;
+
+  return str;
 }
 
 QPixmap SalomeApp_DataObject::icon() const
@@ -106,15 +125,57 @@ QPixmap SalomeApp_DataObject::icon() const
   return QPixmap();
 }
 
-QColor SalomeApp_DataObject::color() const
+QString SalomeApp_DataObject::text( const int id ) const
 {
-  _PTR(GenericAttribute) anAttr;
-  if ( myObject && myObject->FindAttribute( anAttr, "AttributeTextColor" ) ){
-    _PTR(AttributeTextColor) aColAttr (  anAttr );
-    QColor color( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
-    return color;
+  QString txt;
+  switch ( id )
+  {
+  case CT_Value:
+    if ( componentObject() != this )
+      txt = value( referencedObject() );
+    break;
+  case CT_Entry:
+    txt = entry( referencedObject() );
+    break;
+  case CT_IOR:
+    txt = ior( referencedObject() );
+    break;
+  case CT_RefEntry:
+    if ( isReference() )
+      txt = entry( object() );
+    break;
   }
-  return QColor();
+  return txt;
+}
+
+QColor SalomeApp_DataObject::color( const ColorRole cr ) const
+{
+  QColor clr;
+  switch ( cr )
+  {
+  case Text:
+    if ( isReference() )
+      clr = QColor( 255, 0, 0 );
+    else if ( myObject )
+    {
+      _PTR(GenericAttribute) anAttr;
+      if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
+      {
+       _PTR(AttributeTextColor) aColAttr = anAttr;
+       clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
+      }
+    }
+    break;
+  case Highlight:
+    if ( isReference() )
+      clr = QColor( 255, 0, 0 );
+    break;
+  case HighlightedText:
+    if ( isReference() )
+      clr = QColor( 255, 255, 255 );
+    break;
+  }
+  return clr;
 }
 
 QString SalomeApp_DataObject::toolTip() const
@@ -144,7 +205,7 @@ QString SalomeApp_DataObject::componentDataType() const
   const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
   if ( compObj && compObj->object() )
   {
-    _PTR(SComponent) aComp ( compObj->object() );
+    _PTR(SComponent) aComp( compObj->object() );
     if ( aComp )
       return aComp->ComponentDataType().c_str();
   }
@@ -157,6 +218,104 @@ _PTR(SObject) SalomeApp_DataObject::object() const
   return myObject;
 }
 
+bool SalomeApp_DataObject::isReference() const
+{
+  bool isRef = false;
+  if ( myObject )
+  {
+    _PTR(SObject) refObj;
+    isRef = myObject->ReferencedObject( refObj );
+  }
+  return isRef;
+}
+
+_PTR(SObject) SalomeApp_DataObject::referencedObject() const
+{
+  _PTR(SObject) refObj;
+  _PTR(SObject) obj = myObject;
+  while ( obj && obj->ReferencedObject( refObj ) )
+    obj = refObj;
+
+  return obj;
+}
+
+QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
+{
+  QString txt;
+  if ( obj )
+  {
+    _PTR(GenericAttribute) attr;
+    if ( obj->FindAttribute( attr, "AttributeIOR" ) )
+    {
+      _PTR(AttributeIOR) iorAttr = attr;
+      if ( iorAttr )
+      {
+       std::string str = iorAttr->Value();
+       txt = QString( str.c_str() );
+      }
+    }
+  }
+  return txt;
+}
+
+QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
+{
+  QString txt;
+  if ( obj )
+  {
+    std::string str = obj->GetID();
+    txt = QString( str.c_str() );
+  }
+  return txt;
+}
+
+QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
+{
+  if ( !obj )
+    return QString::null;
+
+  QString val;
+  _PTR(GenericAttribute) attr;
+
+  if ( obj->FindAttribute( attr, "AttributeInteger" ) )
+  {
+    _PTR(AttributeInteger) intAttr = attr;
+    if ( intAttr )
+      val = QString::number( intAttr->Value() );
+  }
+  else if ( obj->FindAttribute( attr, "AttributeReal" ) )
+  {
+    _PTR(AttributeReal) realAttr = attr;
+    if ( realAttr )
+      val = QString::number( realAttr->Value() );
+  }
+  else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
+  {
+    _PTR(AttributeTableOfInteger) tableAttr = attr;
+    std::string title = tableAttr->GetTitle();
+    val = QString( title.c_str() );
+    if ( !val.isEmpty() )
+      val += QString( " " );
+    val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
+  }
+  else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
+  {
+    _PTR(AttributeTableOfReal) tableAttr = attr;
+    std::string title = tableAttr->GetTitle();
+    val = QString( title.c_str() );
+    if ( !val.isEmpty() )
+      val += QString( " " );
+    val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
+  }
+  else if ( obj->FindAttribute( attr, "AttributeComment") )
+  {
+    _PTR(AttributeComment) comm = attr;
+    std::string str = comm->Value();
+    val = QString( str.c_str() );
+  }
+
+  return val;
+}
 
 /*!
        Class: SalomeApp_ModuleObject