1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
21 #include "QDS_Datum.h"
23 #include <qtextcodec.h>
25 #include <DDS_DicItem.h>
26 #include <DDS_Dictionary.h>
28 #include <TCollection_HAsciiString.hxx>
29 #include <TCollection_HExtendedString.hxx>
31 QValueList<QDS_Datum*> QDS::_datumList;
33 QString QDS::toQString( const TCollection_AsciiString& src )
35 QTextCodec* codec = QTextCodec::codecForLocale();
38 res = codec ? codec->toUnicode( (char*)src.ToCString(), src.Length() ) :
39 QString( (char*)src.ToCString() );
43 QString QDS::toQString( const TCollection_ExtendedString& src )
46 return toQString( TCollection_AsciiString( src ) );
48 return QString( (QChar*)src.ToExtString(), src.Length() );
51 QString QDS::toQString( const Handle(TCollection_HAsciiString)& src )
56 return toQString( src->String() );
59 QString QDS::toQString( const Handle(TCollection_HExtendedString)& src )
64 return toQString( src->String() );
67 TCollection_AsciiString QDS::toAsciiString( const QString& src )
69 TCollection_AsciiString res;
72 QTextCodec* codec = QTextCodec::codecForLocale();
76 QCString str = codec->fromUnicode( src, len );
77 res = TCollection_AsciiString( (Standard_CString)(const char*)str, len );
80 res = TCollection_AsciiString( (char*)src.latin1() );
85 TCollection_AsciiString QDS::toAsciiString( const TCollection_ExtendedString& src )
87 return TCollection_AsciiString( src );
90 TCollection_AsciiString QDS::toAsciiString( const Handle(TCollection_HExtendedString)& src )
92 TCollection_AsciiString res;
94 res = toAsciiString( src->String() );
98 TCollection_ExtendedString QDS::toExtString( const QString& src )
101 return TCollection_ExtendedString();
103 Standard_Integer len = src.length();
104 Standard_ExtString extStr = new Standard_ExtCharacter[( len + 1 ) * 2];
105 memcpy( extStr, src.unicode(), len * 2 );
108 TCollection_ExtendedString trg( extStr );
115 TCollection_ExtendedString QDS::toExtString( const TCollection_AsciiString& src )
117 return TCollection_ExtendedString( src );
120 bool QDS::load( const QString& dictPath )
122 if ( dictPath.isEmpty() )
125 return DDS_Dictionary::Load( toAsciiString( dictPath ) );
128 QString QDS::unitSystemLabel( const QString& sys, const QString& comp )
131 TCollection_AsciiString system = toAsciiString( sys );
132 Handle(DDS_Dictionary) dic = DDS_Dictionary::Get();
134 lab = toQString( comp.isEmpty() ? dic->GetUnitSystemLabel( system ) :
135 dic->GetUnitSystemLabel( system, toAsciiString( comp ) ) );
139 QString QDS::activeUnitSystem( const QString& comp )
142 Handle(DDS_Dictionary) dic = DDS_Dictionary::Get();
144 sys = toQString( comp.isEmpty() ? dic->GetActiveUnitSystem() :
145 dic->GetActiveUnitSystem( toAsciiString( comp ) ) );
149 void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
151 Handle(DDS_Dictionary) dic = DDS_Dictionary::Get();
155 TCollection_AsciiString system = toAsciiString( sys );
156 comp.isEmpty() ? dic->SetActiveUnitSystem( system ) :
157 dic->SetActiveUnitSystem( system, toAsciiString( comp ) );
159 QString unitSys = activeUnitSystem( comp );
160 if ( sys == unitSys )
163 TCollection_AsciiString aComp = toAsciiString( comp );
164 for ( QValueList<QDS_Datum*>::iterator it = _datumList.begin(); it != _datumList.end(); ++it )
166 QDS_Datum* datum = *it;
170 bool ok = aComp.IsEmpty();
173 Handle(DDS_DicItem) item = datum->dicItem();
174 ok = !item.IsNull() && aComp == item->GetComponent();
178 datum->unitSystemChanged( unitSys );
182 void QDS::insertDatum( QDS_Datum* datum )
187 _datumList.append( datum );
190 void QDS::removeDatum( QDS_Datum* datum )
195 _datumList.remove( datum );