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/ or email : webmaster.salome@opencascade.com
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;
34 Convert the OpenCascade ascii string to Qt string.
36 QString QDS::toQString( const TCollection_AsciiString& src )
38 QTextCodec* codec = QTextCodec::codecForLocale();
41 res = codec ? codec->toUnicode( (char*)src.ToCString(), src.Length() ) :
42 QString( (char*)src.ToCString() );
47 Convert the OpenCascade unicode string to Qt string.
49 QString QDS::toQString( const TCollection_ExtendedString& src )
52 return toQString( TCollection_AsciiString( src ) );
54 return QString( (QChar*)src.ToExtString(), src.Length() );
58 Convert the OpenCascade ascii string to Qt string.
60 QString QDS::toQString( const Handle(TCollection_HAsciiString)& src )
65 return toQString( src->String() );
69 Convert the OpenCascade unicode string to Qt string.
71 QString QDS::toQString( const Handle(TCollection_HExtendedString)& src )
76 return toQString( src->String() );
80 Convert the Qt string to OpenCascade ascii string.
82 TCollection_AsciiString QDS::toAsciiString( const QString& src )
84 TCollection_AsciiString res;
87 QTextCodec* codec = QTextCodec::codecForLocale();
91 QCString str = codec->fromUnicode( src, len );
92 res = TCollection_AsciiString( (Standard_CString)(const char*)str, len );
95 res = TCollection_AsciiString( (char*)src.latin1() );
101 Convert the OpenCascade unicode string to OpenCascade ascii string.
103 TCollection_AsciiString QDS::toAsciiString( const TCollection_ExtendedString& src )
105 return TCollection_AsciiString( src );
109 Convert the OpenCascade unicode string to OpenCascade ascii string.
111 TCollection_AsciiString QDS::toAsciiString( const Handle(TCollection_HExtendedString)& src )
113 TCollection_AsciiString res;
115 res = toAsciiString( src->String() );
120 Convert the Qt string to OpenCascade unicode string.
122 TCollection_ExtendedString QDS::toExtString( const QString& src )
125 return TCollection_ExtendedString();
127 Standard_Integer len = src.length();
128 Standard_ExtString extStr = new Standard_ExtCharacter[( len + 1 ) * 2];
129 memcpy( extStr, src.unicode(), len * 2 );
132 TCollection_ExtendedString trg( extStr );
140 Convert the OpenCascade ascii string to OpenCascade unicode string.
142 TCollection_ExtendedString QDS::toExtString( const TCollection_AsciiString& src )
144 return TCollection_ExtendedString( src );
148 Load datum definitions in the dictionary from XML file \adictPath.
149 Returns true if load successed or false otherwise.
151 bool QDS::load( const QString& dictPath )
153 if ( dictPath.isEmpty() )
156 return DDS_Dictionary::Load( toAsciiString( dictPath ) );
160 Returns the label of unit system \asys. If component \acomp specified and not empty then
161 function find the given unit system in the given component otherwise all components will be searched.
162 If unit system not found then empty string returned.
164 QString QDS::unitSystemLabel( const QString& sys, const QString& comp )
167 TCollection_AsciiString system = toAsciiString( sys );
168 Handle(DDS_Dictionary) dic = DDS_Dictionary::Get();
170 lab = toQString( comp.isEmpty() ? dic->GetUnitSystemLabel( system ) :
171 dic->GetUnitSystemLabel( system, toAsciiString( comp ) ) );
176 Gets the name of active unit system from the specified component \acomp.
177 If component not specified or component is empty string then first got component will be used.
178 If component exist then active unit system name returned or empty string otherwise.
180 QString QDS::activeUnitSystem( const QString& comp )
183 Handle(DDS_Dictionary) dic = DDS_Dictionary::Get();
185 sys = toQString( comp.isEmpty() ? dic->GetActiveUnitSystem() :
186 dic->GetActiveUnitSystem( toAsciiString( comp ) ) );
191 Sets the active unit system named \asys. If not empty component name \acomp specified then
192 unit system will be activated in the given component otherwise all components will be processed.
194 After the changing of active unit system function notify about it to all registered datums
195 from processed components using method QDS_Datum::unitSystemChanged();
197 void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
199 Handle(DDS_Dictionary) dic = DDS_Dictionary::Get();
203 TCollection_AsciiString system = toAsciiString( sys );
204 comp.isEmpty() ? dic->SetActiveUnitSystem( system ) :
205 dic->SetActiveUnitSystem( system, toAsciiString( comp ) );
207 QString unitSys = activeUnitSystem( comp );
208 if ( sys == unitSys )
211 TCollection_AsciiString aComp = toAsciiString( comp );
212 for ( QValueList<QDS_Datum*>::iterator it = _datumList.begin(); it != _datumList.end(); ++it )
214 QDS_Datum* datum = *it;
218 bool ok = aComp.IsEmpty();
221 Handle(DDS_DicItem) item = datum->dicItem();
222 ok = !item.IsNull() && aComp == item->GetComponent();
226 datum->unitSystemChanged( unitSys );
231 Register given datum \adatum in the static list.
232 This function invoked by QDS_Datum constructor.
234 void QDS::insertDatum( QDS_Datum* datum )
239 _datumList.append( datum );
243 Remove given datum \adatum from the static list.
244 This function invoked by QDS_Datum destructor.
246 void QDS::removeDatum( QDS_Datum* datum )
251 _datumList.remove( datum );