Salome HOME
Copyright update 2022
[modules/gui.git] / src / QDS / QDS.cxx
index 7b3f984b2c77263a4031ba81f28d782c9ec33775..ef75b071b6444eae30b6da662831ea83ca5c7d6e 100644 (file)
@@ -1,11 +1,14 @@
-// Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
+// 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
 //
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
-// This library is distributed in the hope that it will be useful
+// 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.
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "QDS.h"
 
 #include "QDS_Datum.h"
 
-#include <qtextcodec.h>
+#include <QTextCodec>
 
 #include <DDS_DicItem.h>
 #include <DDS_Dictionary.h>
 
-#include <TCollection_HAsciiString.hxx>
-#include <TCollection_HExtendedString.hxx>
+QList<QDS_Datum*> QDS::_datumList;
 
-QValueList<QDS_Datum*> QDS::_datumList;
+/*!
+  \class QDS
+  \brief A set of usefull static functions.
+*/
 
+/*!
+  \brief Convert the OpenCascade ASCII string to Qt string.
+  \param src OCC ASCII string
+  \return Qt string
+*/
 QString QDS::toQString( const TCollection_AsciiString& src )
 {
   QTextCodec* codec = QTextCodec::codecForLocale();
@@ -40,6 +51,11 @@ QString QDS::toQString( const TCollection_AsciiString& src )
   return res;
 }
 
+/*!
+  \brief Convert the OpenCascade Unicode string to Qt string.
+  \param src OCC Unicode string
+  \return Qt string
+*/
 QString QDS::toQString( const TCollection_ExtendedString& src )
 {
   if ( src.IsAscii() )
@@ -48,45 +64,69 @@ QString QDS::toQString( const TCollection_ExtendedString& src )
     return QString( (QChar*)src.ToExtString(), src.Length() );
 }
 
+/*!
+  \brief Convert the OpenCascade ASCII string to Qt string.
+  \param src handle to OCC ASCII string
+  \return Qt string
+*/
 QString QDS::toQString( const Handle(TCollection_HAsciiString)& src )
 {
   if ( src.IsNull() )
-    return QString::null;
+    return QString();
   else
     return toQString( src->String() );
 }
 
+/*!
+  \brief Convert the OpenCascade Unicode string to Qt string.
+  \param src handle to OCC Unicode string
+  \return Qt string
+*/
 QString QDS::toQString( const Handle(TCollection_HExtendedString)& src )
 {
   if ( src.IsNull() )
-    return QString::null;
+    return QString();
   else
     return toQString( src->String() );
 }
 
+/*!
+  \brief Convert the Qt string to OpenCascade ASCII string.
+  \param src Qt string
+  \return OCC ASCII string
+*/
 TCollection_AsciiString QDS::toAsciiString( const QString& src )
 {
   TCollection_AsciiString res;
-  if ( src.latin1() )
+  if ( src.toLatin1().constData() )
   {
     QTextCodec* codec = QTextCodec::codecForLocale();
     if ( codec )
     {
-      int len = -1;
-      QCString str = codec->fromUnicode( src, len );
-      res = TCollection_AsciiString( (Standard_CString)(const char*)str, len );
+      QByteArray str = codec->fromUnicode( src );
+      res = TCollection_AsciiString( (Standard_CString)(const char*)str, str.size() );
     }
     else
-      res = TCollection_AsciiString( (char*)src.latin1() );
+      res = TCollection_AsciiString( (char*)src.toLatin1().constData() );
   }
   return res;
 }
 
+/*!
+  \brief Convert the OpenCascade Unicode string to OpenCascade ASCII string.
+  \param src OCC Unicode string
+  \return OCC ASCII string
+*/
 TCollection_AsciiString QDS::toAsciiString( const TCollection_ExtendedString& src )
 {
   return TCollection_AsciiString( src );
 }
 
+/*!
+  \brief Convert the OpenCascade Unicode string to OpenCascade ASCII string.
+  \param src handle to OCC Unicode string
+  \return OCC ASCII string
+*/
 TCollection_AsciiString QDS::toAsciiString( const Handle(TCollection_HExtendedString)& src )
 {
   TCollection_AsciiString res;
@@ -95,13 +135,18 @@ TCollection_AsciiString QDS::toAsciiString( const Handle(TCollection_HExtendedSt
   return res;
 }
 
+/*!
+  \brief Convert the Qt string to OpenCascade Unicode string.
+  \param src Qt string
+  \return OCC Unicode string
+*/
 TCollection_ExtendedString QDS::toExtString( const QString& src )
 {
   if ( src.isEmpty() )
     return TCollection_ExtendedString();
 
   Standard_Integer len = src.length();
-  Standard_ExtString extStr = new Standard_ExtCharacter[( len + 1 ) * 2];
+  Standard_ExtCharacter* extStr = new Standard_ExtCharacter[( len + 1 ) * 2];
   memcpy( extStr, src.unicode(), len * 2 );
   extStr[len] = 0;
 
@@ -112,11 +157,20 @@ TCollection_ExtendedString QDS::toExtString( const QString& src )
   return trg;
 }
 
+/*!
+  \brief Convert the OpenCascade ASCII string to OpenCascade Unicode string.
+  \param src OCC ASCII string
+  \return OCC Unicode string
+*/
 TCollection_ExtendedString QDS::toExtString( const TCollection_AsciiString& src )
 {
   return TCollection_ExtendedString( src );
 }
 
+/*!
+  \brief Load datum definitions from XML file \a dictPath to the dictionary.
+  \return \c true if loading is successed or \c false otherwise.
+*/
 bool QDS::load( const QString& dictPath )
 {
   if ( dictPath.isEmpty() )
@@ -125,6 +179,17 @@ bool QDS::load( const QString& dictPath )
   return DDS_Dictionary::Load( toAsciiString( dictPath ) );
 }
 
+/*!
+  \brief Get the label of unit system \a sys.
+
+  If component \a comp is specified and not empty then the function 
+  searches the given unit system in the specified component, otherwise 
+  all components will be searched.
+
+  \param sys unit system
+  \param comp component
+  \return unit system lavel or empty string if unit system is not found
+*/
 QString QDS::unitSystemLabel( const QString& sys, const QString& comp )
 {
   QString lab;
@@ -136,6 +201,18 @@ QString QDS::unitSystemLabel( const QString& sys, const QString& comp )
   return lab;
 }
 
+/*!
+  \brief Get the name of active unit system from the specified component \a comp.
+
+  If component is not specified or empty string, then the first found 
+  component will be used.
+  
+  If component exists, then active unit system name is returned. Otherwise, 
+  empty string is returned.
+  
+  \param comp component
+  \return name of the active unit system
+*/
 QString QDS::activeUnitSystem( const QString& comp )
 {
   QString sys;
@@ -146,6 +223,20 @@ QString QDS::activeUnitSystem( const QString& comp )
   return sys;
 }
 
+/*!
+  \brief Set the active unit system.
+
+  If not empty component name \a comp is specified, then the unit system
+  will be activated in the given component, otherwise all components 
+  will be processed.
+
+  After the changing of active unit system function notifies about it all
+  registered datums from processed components using method 
+  QDS_Datum::unitSystemChanged()
+
+  \param unit system to be set active
+  \param comp component
+*/
 void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
 {
   Handle(DDS_Dictionary) dic = DDS_Dictionary::Get();
@@ -161,7 +252,7 @@ void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
     return;
 
   TCollection_AsciiString aComp = toAsciiString( comp );
-  for ( QValueList<QDS_Datum*>::iterator it = _datumList.begin(); it != _datumList.end(); ++it )
+  for ( QList<QDS_Datum*>::iterator it = _datumList.begin(); it != _datumList.end(); ++it )
   {
     QDS_Datum* datum = *it;
     if ( !datum )
@@ -179,6 +270,13 @@ void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
   }
 }
 
+/*!
+  \brief Register given datum \a datum in the global list.
+  
+  This function is invoked automatically by QDS_Datum constructor.
+  
+  \param datum datum being registered
+*/
 void QDS::insertDatum( QDS_Datum* datum )
 {
   if ( !datum )
@@ -187,10 +285,17 @@ void QDS::insertDatum( QDS_Datum* datum )
   _datumList.append( datum );
 }
 
+/*!
+  \brief Remove given datum \a datum from the global list.
+
+  This function is invoked automatically by QDS_Datum destructor.
+
+  \param datum datum being unregistered
+*/
 void QDS::removeDatum( QDS_Datum* datum )
 {
   if ( !datum )
     return;
 
-  _datumList.remove( datum );
+  _datumList.removeAt( _datumList.indexOf(datum) );
 }