Salome HOME
Copyright update 2022
[modules/gui.git] / src / SalomeApp / SalomeApp_DataObject.cxx
index 468473a47773e2c0cff1b4e33b5103088cdd0424..08f86a8e84014ad501f2bfe27240546f02551663 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include <QObject>
 #include <QVariant>
 
+//VSR: uncomment below macro to support unicode text properly in SALOME
+//     current commented out due to regressions
+//#define PAL22528_UNICODE
+
+namespace
+{
+  QString fromUtf8( const char* txt )
+  {
+#ifdef PAL22528_UNICODE
+    return QString::fromUtf8( txt );
+#else
+    return QString( txt );
+#endif
+  }
+
+  QString fromUtf8( const std::string& txt )
+  {
+    return fromUtf8( txt.c_str() );
+  }
+}
+
 /*!
   \class SalomeApp_DataObject
   \brief Implementation of the data object for use in CORBA-based
@@ -82,12 +103,12 @@ QString SalomeApp_DataObject::name() const
 {
   QString str;
   if ( myObject )
-    str = QString::fromUtf8( myObject->GetName().c_str() );
+    str = fromUtf8( myObject->GetName() );
   
   if ( str.isEmpty() ) {
     _PTR(SObject) refObj = referencedObject();
     if ( refObj )
-      str = QString::fromUtf8( refObj->GetName().c_str() );
+      str = fromUtf8( refObj->GetName() );
   }
   
   if ( isReference() ) {
@@ -129,14 +150,10 @@ QString SalomeApp_DataObject::text( const int id ) const
   switch ( id )
   {
   case ValueId:
-#ifndef WIN32
-    if ( componentObject() != this )
-#else
     if ( componentObject() != (SUIT_DataObject*)this )
-#endif
       txt = value( object() );
-      if ( txt.isEmpty() )
-        txt = value( referencedObject() );
+    if ( txt.isEmpty() )
+      txt = value( referencedObject() );
     break;
   case IORId:
     txt = ior( referencedObject() );
@@ -164,7 +181,7 @@ QPixmap SalomeApp_DataObject::icon( const int id ) const
       _PTR(AttributePixMap) aPixAttr ( anAttr );
       if ( aPixAttr->HasPixMap() ) {
         QString componentType = componentDataType();
-        QString pixmapID      = QString::fromUtf8(aPixAttr->GetPixMap().c_str());
+        QString pixmapID      = fromUtf8( aPixAttr->GetPixMap() );
         // select a plugin within a component
         QStringList plugin_pixmap = pixmapID.split( "::", QString::KeepEmptyParts );
         if ( plugin_pixmap.size() == 2 ) {
@@ -269,8 +286,15 @@ QString SalomeApp_DataObject::toolTip( const int /*id*/ ) const
       
       if ( !CORBA::is_nil(aComponent) && aComponent->hasObjectInfo() ) {
         LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
-        if ( aRoot && aRoot->study() )
-          return QString( (CORBA::String_var)aComponent->getObjectInfo( aRoot->study()->id(), entry().toLatin1().constData()) );
+        if ( aRoot && aRoot->study() ) {
+          CORBA::String_var data = aComponent->getObjectInfo( entry().toUtf8().constData());
+          QString objInfo = data.in();
+          QStringList l;
+          l << name();
+          if ( !objInfo.isEmpty() )
+            l << objInfo;
+          return l.join("\n");
+        }
       }
     }
   }
@@ -377,13 +401,13 @@ bool SalomeApp_DataObject::hasChildren() const
   bool ok = false;
 
   // tmp??
-  _PTR(UseCaseBuilder) aUseCaseBuilder = myObject->GetStudy()->GetUseCaseBuilder();
+  _PTR(UseCaseBuilder) aUseCaseBuilder = SalomeApp_Application::getStudy()->GetUseCaseBuilder();
   if (aUseCaseBuilder->IsUseCaseNode(myObject)) {
     ok = aUseCaseBuilder->HasChildren(myObject);
     // TODO: check name as below?
   }
   else {
-    _PTR(ChildIterator) it ( myObject->GetStudy()->NewChildIterator( myObject ) );
+    _PTR(ChildIterator) it ( SalomeApp_Application::getStudy()->NewChildIterator( myObject ) );
     for ( ; it->More() && !ok; it->Next() ) {
       _PTR(SObject) obj = it->Value();
       if ( obj ) {
@@ -517,39 +541,31 @@ QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
   {
     _PTR(AttributeString) strAttr = attr;
     std::string str = strAttr->Value();
-    QString aStrings = QString::fromUtf8( str.c_str() );
+    QString aStrings = fromUtf8( str );
     
     //Special case to show NoteBook variables in the "Value" column of the OB 
-    if ( LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() ) )
+    bool ok = false;
+    QStringList aSectionList = aStrings.split( "|" );
+    if ( !aSectionList.isEmpty() )
     {
-      if ( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( aRoot->study() ) )
+      QString aLastSection = aSectionList.last();
+      QStringList aStringList = aLastSection.split( ":" );
+      if ( !aStringList.isEmpty() )
       {
-        _PTR(Study) studyDS( aStudy->studyDS() );
-
-        bool ok = false;
-        QStringList aSectionList = aStrings.split( "|" );
-        if ( !aSectionList.isEmpty() )
+        ok = true;
+        for ( int i = 0, n = aStringList.size(); i < n; i++ )
         {
-          QString aLastSection = aSectionList.last();
-          QStringList aStringList = aLastSection.split( ":" );
-          if ( !aStringList.isEmpty() )
-          {
-            ok = true;
-            for ( int i = 0, n = aStringList.size(); i < n; i++ )
-            {
-              QString aStr = aStringList[i];
-              if ( studyDS->IsVariable( aStr.toStdString() ) )
-                val.append( aStr + ", " );
-            }
-
-            if ( !val.isEmpty() )
-              val.remove( val.length() - 2, 2 );
-          }
+          QString aStr = aStringList[i];
+          if ( SalomeApp_Application::getStudy()->IsVariable( aStr.toStdString() ) )
+            val.append( aStr + ", " );
         }
-        if( !ok )
-          val = aStrings;
+
+        if ( !val.isEmpty() )
+          val.remove( val.length() - 2, 2 );
       }
     }
+    if( !ok )
+      val = aStrings;
   }
   else if ( obj->FindAttribute( attr, "AttributeInteger" ) )
   {
@@ -585,7 +601,7 @@ QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
   {
     _PTR(AttributeComment) comm = attr;
     std::string str = comm->Value();
-    val = QString::fromUtf8( str.c_str() );
+    val = fromUtf8( str );
   }
 
   return val;
@@ -807,13 +823,13 @@ QString SalomeApp_RootObject::toolTip( const int id ) const
   \param id save point ID
   \param study study
 */
-SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* parent, 
-                                                      const int id, 
+SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* parent,
+                                                      const int id,
                                                       SalomeApp_Study* study )
-: LightApp_DataObject( parent ), 
-  CAM_DataObject( parent ),
-  myId( id ),
-  myStudy( study )
+  : CAM_DataObject( parent ),
+    LightApp_DataObject( parent ),
+    myId( id ),
+    myStudy( study )
 {
 }