1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Tool.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Prs.h"
29 #include <HYDROData_Document.h>
30 #include <HYDROData_Image.h>
31 #include <HYDROData_Iterator.h>
33 #include <LightApp_Application.h>
35 #include <QtxWorkstack.h>
37 #include <STD_TabDesktop.h>
39 #include <SUIT_Study.h>
40 #include <SUIT_ViewManager.h>
41 #include <SUIT_ViewWindow.h>
45 // Definition of this id allows to use 'latin1' (Qt alias for 'ISO-8859-1')
46 // encoding instead of default 'System'
47 #define USE_LATIN1_ENCODING
49 QString HYDROGUI_Tool::ToQString( const TCollection_AsciiString& src )
51 #ifdef USE_LATIN1_ENCODING
52 QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
54 QTextCodec* codec = QTextCodec::codecForLocale();
58 res = codec ? codec->toUnicode( (char*)src.ToCString(), src.Length() ) :
59 QString( (char*)src.ToCString() );
63 QString HYDROGUI_Tool::ToQString( const TCollection_ExtendedString& src )
65 return QString( (QChar*)src.ToExtString(), src.Length() );
68 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HAsciiString)& src )
73 return ToQString( src->String() );
76 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HExtendedString)& src )
80 return ToQString( src->String() );
83 TCollection_AsciiString HYDROGUI_Tool::ToAsciiString( const QString& src )
85 TCollection_AsciiString res;
88 #ifdef USE_LATIN1_ENCODING
89 QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
91 QTextCodec* codec = QTextCodec::codecForLocale();
95 QByteArray str = codec->fromUnicode( src );
96 res = TCollection_AsciiString( (Standard_CString)str.constData() );
99 res = TCollection_AsciiString( src.toLatin1().data() );
104 TCollection_ExtendedString HYDROGUI_Tool::ToExtString( const QString& src )
107 return TCollection_ExtendedString();
109 Standard_Integer len = src.length();
110 Standard_ExtString extStr = new Standard_ExtCharacter[ ( len + 1 ) * 2 ];
111 memcpy( (void*)extStr, src.unicode(), len * 2 );
112 ((short*)extStr)[ len ] = 0;
114 TCollection_ExtendedString trg( extStr );
119 Handle(TCollection_HAsciiString) HYDROGUI_Tool::ToHAsciiString( const QString& src )
121 return new TCollection_HAsciiString( ToAsciiString( src ) );
124 Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString& src )
126 return new TCollection_HExtendedString( ToExtString( src ) );
129 void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
130 SUIT_ViewManager* theViewManager )
133 if( SUIT_ViewWindow* aViewWindow = theViewManager->getActiveView() )
134 if( STD_TabDesktop* aTabDesktop = dynamic_cast<STD_TabDesktop*>( theModule->getApp()->desktop() ) )
135 if( QtxWorkstack* aWorkstack = aTabDesktop->workstack() )
136 aWorkstack->setActiveWindow( aViewWindow );
139 void HYDROGUI_Tool::GetPrsSubObjects( const HYDROGUI_DataModel* theModel,
140 const int theViewerId, // currently unused
141 HYDROData_SequenceOfObjects& theSeq )
146 const int aStudyId = theModel->module()->application()->activeStudy()->id();
148 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
149 if( aDocument.IsNull() )
152 HYDROData_Iterator anIterator( aDocument, KIND_IMAGE );
153 for( ; anIterator.More(); anIterator.Next() )
155 Handle(HYDROData_Image) anImageObj =
156 Handle(HYDROData_Image)::DownCast( anIterator.Current() );
157 if( !anImageObj.IsNull() )
158 theSeq.Append( anImageObj );
162 HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Object)& theObj,
163 const GraphicsView_ObjectList& theObjects )
165 GraphicsView_ObjectListIterator anIter( theObjects );
166 while( anIter.hasNext() )
167 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
168 if( aPrs->getObject()->Label() == theObj->Label() )