1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_Tool.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_DataObject.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Prs.h"
26 #include <HYDROData_Document.h>
27 #include <HYDROData_Iterator.h>
28 #include <HYDROData_ImmersibleZone.h>
29 #include <HYDROData_Tool.h>
30 #include <HYDROData_Profile.h>
31 #include <HYDROData_LandCover.h>
35 #include <GraphicsView_Viewer.h>
37 #include <SalomeApp_Study.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_DataOwner.h>
41 #include <LightApp_SelectionMgr.h>
43 #include <OCCViewer_ViewModel.h>
44 #include <OCCViewer_ViewFrame.h>
46 #include <QtxWorkstack.h>
47 #include <QtxActionToolMgr.h>
49 #include <STD_TabDesktop.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_Study.h>
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_ViewWindow.h>
56 #include <SALOMEDSClient.hxx>
58 #include <SVTK_ViewModel.h>
62 #include <QDockWidget>
65 // Definition of this id allows to use 'latin1' (Qt alias for 'ISO-8859-1')
66 // encoding instead of default 'System'
67 #define USE_LATIN1_ENCODING
69 // #define DEB_GROUPS 1
71 QString HYDROGUI_Tool::ToQString( const TCollection_AsciiString& src )
73 #ifdef USE_LATIN1_ENCODING
74 QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
76 QTextCodec* codec = QTextCodec::codecForLocale();
80 res = codec ? codec->toUnicode( (char*)src.ToCString(), src.Length() ) :
81 QString( (char*)src.ToCString() );
85 QString HYDROGUI_Tool::ToQString( const TCollection_ExtendedString& src )
87 return QString( (QChar*)src.ToExtString(), src.Length() );
90 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HAsciiString)& src )
95 return ToQString( src->String() );
98 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HExtendedString)& src )
102 return ToQString( src->String() );
105 TCollection_AsciiString HYDROGUI_Tool::ToAsciiString( const QString& src )
107 TCollection_AsciiString res;
110 #ifdef USE_LATIN1_ENCODING
111 QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
113 QTextCodec* codec = QTextCodec::codecForLocale();
117 QByteArray str = codec->fromUnicode( src );
118 res = TCollection_AsciiString( (Standard_CString)str.constData() );
121 res = TCollection_AsciiString( src.toLatin1().data() );
126 TCollection_ExtendedString HYDROGUI_Tool::ToExtString( const QString& src )
129 return TCollection_ExtendedString();
131 Standard_Integer len = src.length();
132 Standard_ExtString extStr = new Standard_ExtCharacter[ ( len + 1 ) * 2 ];
133 memcpy( (void*)extStr, src.unicode(), len * 2 );
134 ((short*)extStr)[ len ] = 0;
136 TCollection_ExtendedString trg( extStr );
141 Handle(TCollection_HAsciiString) HYDROGUI_Tool::ToHAsciiString( const QString& src )
143 return new TCollection_HAsciiString( ToAsciiString( src ) );
146 Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString& src )
148 return new TCollection_HExtendedString( ToExtString( src ) );
151 int HYDROGUI_Tool::GetActiveStudyId()
153 if( SUIT_Session* aSession = SUIT_Session::session() )
154 if( SUIT_Application* anApp = aSession->activeApplication() )
155 if( SUIT_Study* aStudy = anApp->activeStudy() )
160 QString HYDROGUI_Tool::GetTempDir( const bool theToCreate )
164 char* tmpdir = getenv ( "HYDRO_TMP_DIR" );
167 // try to create folder if it does not exist
168 QFileInfo fi( tmpdir );
169 if ( !fi.exists() && theToCreate )
171 if ( QDir().mkdir( tmpdir ) )
172 QFile::setPermissions( tmpdir, (QFile::Permissions)0x4FFFF );
173 QFileInfo fi( tmpdir );
174 if ( !fi.exists() || !fi.isWritable() )
179 tmpdir = getenv ( "TEMP" );
181 tmpdir = getenv ( "TMP" );
192 QFileInfo fi( aRes );
193 if ( !fi.exists() || !fi.isWritable() )
194 aRes = QString::null;
199 void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
200 SUIT_ViewManager* theViewManager )
203 if( SUIT_ViewWindow* aViewWindow = theViewManager->getActiveView() )
204 if( STD_TabDesktop* aTabDesktop = dynamic_cast<STD_TabDesktop*>( theModule->getApp()->desktop() ) )
205 if( QtxWorkstack* aWorkstack = aTabDesktop->workstack() )
206 aWorkstack->setActiveWindow( aViewWindow );
209 bool HYDROGUI_Tool::IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject,
210 const QString& theViewerType )
213 if ( theObject.IsNull() )
216 ObjectKind anObjectKind = theObject->GetKind();
217 if ( theViewerType.isEmpty() || theViewerType == OCCViewer_Viewer::Type() )
219 if ( anObjectKind == KIND_IMAGE ||
220 anObjectKind == KIND_POLYLINEXY ||
221 anObjectKind == KIND_POLYLINE ||
222 anObjectKind == KIND_IMMERSIBLE_ZONE ||
223 anObjectKind == KIND_REGION ||
224 anObjectKind == KIND_ZONE ||
225 anObjectKind == KIND_OBSTACLE ||
226 anObjectKind == KIND_PROFILE ||
227 anObjectKind == KIND_STREAM ||
228 anObjectKind == KIND_CHANNEL ||
229 anObjectKind == KIND_DIGUE ||
230 anObjectKind == KIND_DUMMY_3D ||
231 anObjectKind == KIND_BATHYMETRY
233 || anObjectKind == KIND_SHAPES_GROUP ||
234 anObjectKind == KIND_SPLITTED_GROUP
242 if ( theViewerType.isEmpty() || theViewerType == SVTK_Viewer::Type() )
244 if ( anObjectKind == KIND_BATHYMETRY )
248 if ( theViewerType.isEmpty() || theViewerType == GraphicsView_Viewer::Type() )
250 if ( anObjectKind == KIND_IMAGE ||
251 anObjectKind == KIND_POLYLINEXY )
258 void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule,
259 HYDROData_SequenceOfObjects& theSeq )
261 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
262 if( !aDocument.IsNull() )
264 HYDROData_Iterator anIterator( aDocument );
265 for( ; anIterator.More(); anIterator.Next() )
267 Handle(HYDROData_Entity) anObject = anIterator.Current();
268 if ( !IsObjectHasPresentation( anObject ) )
271 theSeq.Append( anObject );
276 HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Entity)& theObj,
277 const GraphicsView_ObjectList& theObjects )
279 if( !theObj.IsNull() )
281 GraphicsView_ObjectListIterator anIter( theObjects );
282 while( anIter.hasNext() )
284 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
286 Handle(HYDROData_Entity) anObj = aPrs->getObject();
287 if( IsEqual( anObj, theObj ) )
295 GraphicsView_ObjectList HYDROGUI_Tool::GetPrsList( GraphicsView_ViewPort* theViewPort )
297 GraphicsView_ObjectList aList;
300 GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() );
301 while( anIter.hasNext() )
302 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
303 aList.append( aPrs );
308 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module* theModule )
310 HYDROData_SequenceOfObjects aSeq;
312 HYDROGUI_DataModel* aModel = theModule->getDataModel();
314 SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
315 SUIT_DataOwnerPtrList anOwners;
316 aSelectionMgr->selected( anOwners );
318 QStringList aCollectedNameList; // to avoid duplication
319 foreach( SUIT_DataOwner* aSUITOwner, anOwners )
321 if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
323 Handle(HYDROData_Entity) anObject = aModel->objectByEntry( anOwner->entry() );
324 if( !anObject.IsNull() )
326 QString aName = anObject->GetName();
327 if( !aCollectedNameList.contains( aName ) )
329 aSeq.Append( anObject );
330 aCollectedNameList.append( aName );
338 Handle(HYDROData_Entity) HYDROGUI_Tool::GetSelectedObject( HYDROGUI_Module* theModule )
340 HYDROData_SequenceOfObjects aSeq = GetSelectedObjects( theModule );
341 if( !aSeq.IsEmpty() )
346 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetGeometryObjects(
347 HYDROGUI_Module* theModule )
349 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
351 HYDROData_SequenceOfObjects aResSeq;
353 HYDROData_Iterator anIter( aDocument );
354 for ( ; anIter.More(); anIter.Next() )
356 Handle(HYDROData_Entity) anObj = anIter.Current();
357 if ( !HYDROData_Tool::IsGeometryObject( anObj ) )
360 aResSeq.Append( anObj );
366 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetLandCovers( HYDROGUI_Module* theModule )
368 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
370 HYDROData_SequenceOfObjects aResSeq;
372 HYDROData_Iterator anIter( aDocument );
373 for ( ; anIter.More(); anIter.Next() )
375 Handle(HYDROData_Entity) anObj = anIter.Current();
376 if ( !anObj.IsNull() && anObj->IsKind( STANDARD_TYPE(HYDROData_LandCover) ))
377 aResSeq.Append( anObj );
383 ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule )
385 HYDROGUI_DataModel* aModel = theModule->getDataModel();
387 SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
388 SUIT_DataOwnerPtrList anOwners;
389 aSelectionMgr->selected( anOwners );
391 if( anOwners.size() != 1 )
394 if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( anOwners.first().operator->() ) )
396 QString anEntry = anOwner->entry();
397 QString aPrefix = HYDROGUI_DataObject::entryPrefix();
398 if( anEntry.left( aPrefix.length() ) == aPrefix )
400 anEntry.remove( aPrefix );
401 for( ObjectKind anObjectKind = KIND_UNKNOWN + 1; anObjectKind <= KIND_LAST; anObjectKind++ )
402 if( HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( anObjectKind ).toAscii() ) == anEntry )
409 QStringList HYDROGUI_Tool::GetSelectedGeomObjects( HYDROGUI_Module* theModule,
410 QList<GEOM::shape_type> theTypes )
412 QStringList anEntryList;
414 // Get active SalomeApp_Study
415 SalomeApp_Study* aStudy = NULL;
416 if ( theModule && theModule->getApp() ) {
417 aStudy = dynamic_cast<SalomeApp_Study*>( theModule->getApp()->activeStudy() );
424 SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
425 SUIT_DataOwnerPtrList anOwners;
426 aSelectionMgr->selected( anOwners );
428 // Check if the selected objects belong to GEOM and have a shape
429 foreach( SUIT_DataOwner* aSUITOwner, anOwners )
431 if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
433 QString anEntry = anOwner->entry();
434 _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID(qPrintable(anEntry)) );
436 _PTR(SComponent) aSComponent = aSObject->GetFatherComponent();
437 if ( aSComponent && aSComponent->ComponentDataType() == "GEOM" ) {
438 GEOM::GEOM_Object_var aGeomObj =
439 GEOMBase::GetObjectFromIOR( aSObject->GetIOR().c_str() );
441 if ( !aGeomObj->_is_nil() && aGeomObj->IsShape() &&
442 theTypes.contains( aGeomObj->GetShapeType() ) ) {
443 anEntryList << anEntry;
453 Handle(HYDROData_Entity) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule,
454 const QString& theName,
455 const ObjectKind theObjectKind )
457 Handle(HYDROData_Entity) aResObj;
459 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
460 if ( !aDocument.IsNull() )
461 aResObj = aDocument->FindObjectByName( theName, theObjectKind );
466 HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module* theModule,
467 const QStringList& theNames,
468 const ObjectKind theObjectKind )
470 HYDROData_SequenceOfObjects aResSeq;
472 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
473 if ( !aDocument.IsNull() )
474 aResSeq = aDocument->FindObjectsByNames( theNames, theObjectKind );
479 QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule,
480 const QString& thePrefix,
481 const QStringList& theUsedNames,
482 const bool theIsTryToUsePurePrefix)
484 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
485 return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames, theIsTryToUsePurePrefix );
488 size_t HYDROGUI_Tool::GetActiveViewId( HYDROGUI_Module* theModule,
489 const QString& theViewId )
492 SUIT_ViewManager* aViewMgr = theModule->getApp()->activeViewManager();
493 if( !aViewMgr || ( !theViewId.isEmpty() && aViewMgr->getType() != theViewId ) )
496 if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
497 aViewId = (size_t)aViewer;
501 size_t HYDROGUI_Tool::GetActiveGraphicsViewId( HYDROGUI_Module* theModule )
503 return GetActiveViewId( theModule, GraphicsView_Viewer::Type() );
506 size_t HYDROGUI_Tool::GetActiveOCCViewId( HYDROGUI_Module* theModule )
508 return GetActiveViewId( theModule, OCCViewer_Viewer::Type() );
511 QList<size_t> getViewIdList( HYDROGUI_Module* theModule,
512 const QString& theViewId )
515 ViewManagerList aViewMgrs;
516 theModule->getApp()->viewManagers( theViewId, aViewMgrs );
517 QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
518 while( anIter.hasNext() )
520 if( SUIT_ViewManager* aViewMgr = anIter.next() )
522 if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
523 aList.append( (size_t)aViewer );
529 QList<size_t> HYDROGUI_Tool::GetGraphicsViewIdList( HYDROGUI_Module* theModule )
531 return getViewIdList( theModule, GraphicsView_Viewer::Type() );
534 QList<size_t> HYDROGUI_Tool::GetOCCViewIdList( HYDROGUI_Module* theModule )
536 return getViewIdList( theModule, OCCViewer_Viewer::Type() );
539 void HYDROGUI_Tool::setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
540 const int theActionId,
546 OCCViewer_ViewWindow* aView = theViewFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW );
548 aView->toolMgr()->setShown( theActionId, isShown );
549 if ( theActionId == OCCViewer_ViewWindow::MaximizedId )
550 theViewFrame->onMaximizedView( aView, true );
554 void HYDROGUI_Tool::setOCCActionShown( HYDROGUI_Module* theModule,
555 const int theActionId,
559 ViewManagerList aViewMgrs;
560 theModule->getApp()->viewManagers( OCCViewer_Viewer::Type(), aViewMgrs );
561 QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
562 while( anIter.hasNext() )
564 if( SUIT_ViewManager* aViewMgr = anIter.next() )
566 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>
567 ( aViewMgr->getActiveView() );
569 setOCCActionShown( aViewFrame, theActionId, isShown );
574 void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
575 HYDROData_SequenceOfObjects& theRefObjects,
576 QStringList& theRefNames )
578 if( theObj.IsNull() )
581 HYDROData_SequenceOfObjects anAllRefObjects = theObj->GetAllReferenceObjects();
582 theRefObjects.Append( anAllRefObjects );
584 for( int i = 1, n = anAllRefObjects.Length(); i <= n; ++i )
586 Handle(HYDROData_Entity) aRefObj = theRefObjects.Value( i );
587 if( aRefObj.IsNull() || aRefObj->IsRemoved() )
590 QString aRefObjectName = aRefObj->GetName();
591 if( theRefNames.contains( aRefObjectName ) )
594 theRefObjects.Append( aRefObj );
595 theRefNames.append( aRefObjectName );
597 GetObjectReferences( aRefObj, theRefObjects, theRefNames );
601 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetObjectBackReferences(
602 HYDROGUI_Module* theModule,
603 const Handle(HYDROData_Entity)& theObj )
605 if( theObj.IsNull() )
606 return HYDROData_SequenceOfObjects();
608 QString anObjName = theObj->GetName();
610 QMap<QString,HYDROData_SequenceOfObjects> aMapOfBackRefs =
611 GetObjectsBackReferences( theModule, QStringList() << anObjName );
613 return aMapOfBackRefs[ anObjName ];
616 QMap<QString,HYDROData_SequenceOfObjects> HYDROGUI_Tool::GetObjectsBackReferences(
617 HYDROGUI_Module* theModule, const QStringList& theObjectNames )
619 QMap<QString,HYDROData_SequenceOfObjects> aResMap;
621 if( theObjectNames.isEmpty() )
624 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
625 if( aDocument.IsNull() )
628 HYDROData_Iterator anIterator( aDocument );
629 for( ; anIterator.More(); anIterator.Next() )
631 Handle(HYDROData_Entity) anObject = anIterator.Current();
632 if( anObject.IsNull() || anObject->IsRemoved() )
635 QString anObjectName = anObject->GetName();
636 if ( theObjectNames.contains( anObjectName ) )
639 HYDROData_SequenceOfObjects aRefObjects = anObject->GetAllReferenceObjects();
640 for ( int i = 1, n = aRefObjects.Length(); i <= n; ++i )
642 Handle(HYDROData_Entity) aRefObject = aRefObjects.Value( i );
643 if( aRefObject.IsNull() || aRefObject->IsRemoved() )
646 QString aRefObjectName = aRefObject->GetName();
647 if ( !theObjectNames.contains( aRefObjectName ) )
650 aResMap[ aRefObjectName ].Append( anObject );
657 QDockWidget* HYDROGUI_Tool::WindowDock( QWidget* wid )
662 QDockWidget* dock = 0;
663 QWidget* w = wid->parentWidget();
666 dock = ::qobject_cast<QDockWidget*>( w );
667 w = w->parentWidget();
672 QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module* theModule,
673 const QStringList& theZoneNames )
675 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
676 return GenerateFillingColor( aDocument, theZoneNames );
679 QColor HYDROGUI_Tool::GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
680 const QStringList& theZoneNames )
682 QColor aFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
685 int aR = 0, aG = 0, aB = 0;
686 QStringListIterator aZoneNameIter( theZoneNames );
687 while( aZoneNameIter.hasNext() )
689 const QString& aZoneName = aZoneNameIter.next();
690 Handle(HYDROData_ImmersibleZone) aRefZone =
691 Handle(HYDROData_ImmersibleZone)::DownCast( theDoc->FindObjectByName( aZoneName, KIND_IMMERSIBLE_ZONE ) );
692 if( !aRefZone.IsNull() )
694 QColor aRefColor = aRefZone->GetFillingColor();
695 aR += aRefColor.red();
696 aG += aRefColor.green();
697 aB += aRefColor.blue();
704 aFillingColor = QColor( aR / aCounter, aG / aCounter, aB / aCounter );
707 return aFillingColor;
710 QStringList HYDROGUI_Tool::FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc,
711 const ObjectKind theObjectKind,
712 bool isCheckValidProfile )
716 HYDROData_Iterator anIter( theDoc, theObjectKind );
717 for ( ; anIter.More(); anIter.Next() ) {
718 Handle(HYDROData_Entity) anObject = anIter.Current();
720 bool isOK = !anObject.IsNull();
722 if( isOK && isCheckValidProfile )
724 Handle_HYDROData_Profile aProfile = Handle_HYDROData_Profile::DownCast( anObject );
725 if( !aProfile.IsNull() && !aProfile->IsValid() )
730 aNames.append( anObject->GetName() );
736 QString HYDROGUI_Tool::GetCoordinateString( const double theNumber, bool isInLocale )
740 static QLocale aLocale( QLocale::English, QLocale::France );
741 return aLocale.toString( theNumber, 'f', 2 );
744 return QString::number( theNumber, 'f', 2 );
747 Handle(Image_PixMap) HYDROGUI_Tool::Pixmap( const QImage& theImage )
749 Handle(Image_PixMap) pix;
750 if ( theImage.isNull() || theImage.format() == QImage::Format_Invalid )
753 Handle(Image_PixMap) tmpPix = new Image_PixMap();
754 tmpPix->SetTopDown( false );
755 QImage anImage = theImage.mirrored();
756 if ( !anImage.hasAlphaChannel() && anImage.allGray() )
758 tmpPix->InitTrash( Image_PixMap::ImgGray, anImage.width(), anImage.height(), anImage.width() );
759 for ( int r = 0; r < anImage.height(); r++ )
761 Standard_Byte* aRowData = tmpPix->ChangeRow( anImage.height() - r - 1 );
762 for ( int p = 0; p < anImage.width(); p++ )
763 aRowData[p] = qRed( anImage.pixel( p, r ) );
768 Image_PixMap::ImgFormat aFormat;
769 if ( anImage.hasAlphaChannel() )
771 if ( anImage.format() != QImage::Format_ARGB32 )
772 anImage = anImage.convertToFormat( QImage::Format_ARGB32 );
773 aFormat = Image_PixMap::ImgRGBA;
777 if ( anImage.format() != QImage::Format_RGB888 )
778 anImage = anImage.convertToFormat( QImage::Format_RGB888 );
779 aFormat = Image_PixMap::ImgRGB;
782 tmpPix->InitWrapper( aFormat, (Standard_Byte*)anImage.bits(), anImage.width(), anImage.height(), anImage.bytesPerLine() );
785 if ( !tmpPix.IsNull() )
787 pix = new Image_PixMap();
788 pix->InitCopy( *tmpPix.operator->() );
789 pix->SetTopDown( tmpPix->IsTopDown() );