Salome HOME
Merge from OCC_development_generic_2006
[modules/gui.git] / src / SalomeApp / SalomeApp_DataObject.cxx
index 70e0e154662cf0cfbee894898f22bcbc287d131a..ef7b8df7b6289f991b54d3395ffeae683f85dc59 100644 (file)
@@ -1,7 +1,25 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 #include "SalomeApp_DataObject.h"
 
 #include "SalomeApp_Study.h"
-#include "SalomeApp_RootObject.h"
+#include "LightApp_RootObject.h"
 
 #include <SUIT_Application.h>
 #include <SUIT_ResourceMgr.h>
 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
 
-/*!
-       Class: SalomeApp_DataObject::Key
-       Level: Internal
-*/
-class SalomeApp_DataObject::Key : public SUIT_DataObjectKey
-{
-public:
-  Key( const QString& );
-  virtual ~Key();
-
-  virtual bool isLess( const SUIT_DataObjectKey* ) const;
-  virtual bool isEqual( const SUIT_DataObjectKey* ) const;
-
-private:
-  QString myEntry;
-};
-
-/*!Constructor. Initialize by \a entry.*/
-SalomeApp_DataObject::Key::Key( const QString& entry )
-: SUIT_DataObjectKey(),
-  myEntry( entry )
-{
-}
-
-/*!Destructor. Do nothing.*/
-SalomeApp_DataObject::Key::~Key()
-{
-}
-
-/*!Checks: Is current key less than \a other.*/
-bool SalomeApp_DataObject::Key::isLess( const SUIT_DataObjectKey* other ) const
-{
-  Key* that = (Key*)other;
-  return myEntry < that->myEntry;
-}
-
-/*!Checks: Is current key equal with \a other.*/
-bool SalomeApp_DataObject::Key::isEqual( const SUIT_DataObjectKey* other ) const
-{
-  Key* that = (Key*)other;
-  return myEntry == that->myEntry;
-}
-
 /*
        Class: SalomeApp_DataObject
        Level: Public
 */
 /*!Constructor. Initialize by \a parent*/
 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
-: CAM_DataObject( parent )
+: LightApp_DataObject( parent ),
+  CAM_DataObject( parent ),
+  myEntry( "" ),
+  myName( "" )
 {
 }
 
 /*!Constructor. Initialize by \a parent and SObject*/
 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
-: CAM_DataObject( parent )
+: LightApp_DataObject( parent ),
+  CAM_DataObject( parent ),
+  myName( "" )
 {
   myObject = sobj;
+  myEntry = myObject->GetID().c_str();
 }
 
 /*!Destructor. Do nothing.*/
@@ -85,37 +66,39 @@ SalomeApp_DataObject::~SalomeApp_DataObject()
  */
 QString SalomeApp_DataObject::entry() const
 {
 if ( myObject )
+ if ( myObject )
     return myObject->GetID().c_str();
   return QString::null;
-}
-
-/*!Create and return new key object.*/
-SUIT_DataObjectKey* SalomeApp_DataObject::key() const
-{
-  QString str = entry();
-  return new Key( str );
+  //return myEntry;
 }
 
 /*!Gets name of object.*/
 QString SalomeApp_DataObject::name() const
 {
-  QString str;
-
-  if ( myObject )
-    str = myObject->GetName().c_str();
-
-  if ( str.isEmpty() )
+  //if ( myName.isEmpty() )
   {
-    _PTR(SObject) refObj = referencedObject();
-    if ( refObj )
-      str = refObj->GetName().c_str();
-  }
+    QString str;
+    if ( myObject )
+      str = myObject->GetName().c_str();
 
-  if ( isReference() )
-    str = QString( "* " ) + str;
+    if ( str.isEmpty() )
+    {
+      _PTR(SObject) refObj = referencedObject();
+      if ( refObj )
+        str = refObj->GetName().c_str();
+    }
 
-  return str;
+    if ( isReference() )
+      {
+        if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
+         str = QString( "* " ) + str;
+        else
+         str = QString( "<Invalid Reference>" );
+      }
+    SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
+    that->myName = str;
+  }
+  return myName;
 }
 
 /*!Gets icon picture of object.*/
@@ -126,10 +109,10 @@ QPixmap SalomeApp_DataObject::icon() const
     _PTR(AttributePixMap) aPixAttr ( anAttr );
     if ( aPixAttr->HasPixMap() ){
       QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
-      SalomeApp_RootObject* aRoot = dynamic_cast<SalomeApp_RootObject*>( root() );
+      LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
       if ( aRoot && aRoot->study() ) {
-       QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false ); 
-       return pixmap;
+       SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr();
+       return mgr->loadPixmap( componentDataType(), pixmapName, false ); 
       }
     }
   }
@@ -148,18 +131,22 @@ QString SalomeApp_DataObject::text( const int id ) const
   switch ( id )
   {
   case CT_Value:
+#ifndef WNT
     if ( componentObject() != this )
+#else
+    if ( componentObject() != (SUIT_DataObject*)this )
+#endif
       txt = value( referencedObject() );
     break;
   case CT_Entry:
-    txt = entry( referencedObject() );
+    txt = entry( object() );
     break;
   case CT_IOR:
     txt = ior( referencedObject() );
     break;
   case CT_RefEntry:
     if ( isReference() )
-      txt = entry( object() );
+      txt = entry( referencedObject() );
     break;
   }
   return txt;
@@ -177,7 +164,12 @@ QColor SalomeApp_DataObject::color( const ColorRole cr ) const
   {
   case Text:
     if ( isReference() )
-      clr = QColor( 255, 0, 0 );
+      {
+       if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
+         clr = QColor( 255, 0, 0 );
+       else
+         clr = QColor( 200, 200, 200 );
+      }
     else if ( myObject )
     {
       _PTR(GenericAttribute) anAttr;
@@ -190,7 +182,12 @@ QColor SalomeApp_DataObject::color( const ColorRole cr ) const
     break;
   case Highlight:
     if ( isReference() )
-      clr = QColor( 255, 0, 0 );
+      {
+       if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
+         clr = QColor( 255, 0, 0 );
+       else
+         clr = QColor( 200, 200, 200 );
+      }
     break;
   case HighlightedText:
     if ( isReference() )
@@ -207,37 +204,21 @@ QString SalomeApp_DataObject::toolTip() const
   return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
 }
 
-/*!Gets component object.
- *\retval SUIT_DataObject.
- */
-SUIT_DataObject* SalomeApp_DataObject::componentObject() const
-{
-  SUIT_DataObject* compObj = 0;  // for root object (invisible SALOME_ROOT_OBJECT) 
-
-  if ( parent() && parent() == root() ) 
-    compObj = (SUIT_DataObject*)this; // for component-level objects
-  else 
-  {
-    compObj = parent(); // for lower level objects
-    while ( compObj && compObj->parent() != root() )
-      compObj = compObj->parent();
-  }
-
-  return compObj;
-}
-
 /*!Get component type.*/
 QString SalomeApp_DataObject::componentDataType() const
 {
-  const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
-  if ( compObj && compObj->object() )
-  {
-    _PTR(SComponent) aComp( compObj->object() );
-    if ( aComp )
-      return aComp->ComponentDataType().c_str();
-  }
-
-  return "";
+  //  if ( myCompDataType.isEmpty() ) {
+    const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
+    if ( compObj && compObj->object() )
+    {
+      _PTR(SComponent) aComp( compObj->object() );
+      if ( aComp ) {
+        SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
+        that->myCompDataType = aComp->ComponentDataType().c_str();
+      }
+    }
+    //  }
+  return myCompDataType;
 }
 
 /*!Gets object.*/
@@ -357,7 +338,7 @@ QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
 
 /*!Constructor.Initialize by \a parent.*/
 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
-: SalomeApp_DataObject( parent ), 
+: SalomeApp_DataObject( parent ),
   CAM_RootObject( parent ),
   CAM_DataObject( parent )
 {
@@ -365,7 +346,7 @@ SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
 
 /*!Constructor.Initialize by \a parent and SObject.*/
 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
-: SalomeApp_DataObject( sobj, parent ), 
+: SalomeApp_DataObject( sobj, parent ),
   CAM_RootObject( 0, parent ),
   CAM_DataObject( parent )
 {
@@ -373,9 +354,9 @@ SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_
 
 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
-: SalomeApp_DataObject( sobj, parent ), 
+: SalomeApp_DataObject( sobj, parent ),
   CAM_RootObject( dm, parent ),
-  CAM_DataObject( parent )  
+  CAM_DataObject( parent )
 {
 }
 
@@ -383,3 +364,10 @@ SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SO
 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()
 {
 }
+
+/*!Returns module name */
+QString SalomeApp_ModuleObject::name() const
+{
+  return SalomeApp_DataObject::name();
+}
+