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>
33 #include <GeometryGUI.h>
36 #include <GraphicsView_Viewer.h>
38 #include <SalomeApp_Study.h>
40 #include <LightApp_Application.h>
41 #include <LightApp_DataOwner.h>
42 #include <LightApp_SelectionMgr.h>
44 #include <OCCViewer_ViewModel.h>
45 #include <OCCViewer_ViewFrame.h>
47 #include <QtxWorkstack.h>
48 #include <QtxActionToolMgr.h>
50 #include <STD_TabDesktop.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_Study.h>
54 #include <SUIT_ViewManager.h>
55 #include <SUIT_ViewWindow.h>
57 #include <SALOMEDSClient.hxx>
59 #include <SVTK_ViewModel.h>
63 #include <QDockWidget>
66 // Definition of this id allows to use 'latin1' (Qt alias for 'ISO-8859-1')
67 // encoding instead of default 'System'
68 #define USE_LATIN1_ENCODING
70 // #define DEB_GROUPS 1
72 QString HYDROGUI_Tool::ToQString( const TCollection_AsciiString& src )
74 #ifdef USE_LATIN1_ENCODING
75 QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
77 QTextCodec* codec = QTextCodec::codecForLocale();
81 res = codec ? codec->toUnicode( (char*)src.ToCString(), src.Length() ) :
82 QString( (char*)src.ToCString() );
86 QString HYDROGUI_Tool::ToQString( const TCollection_ExtendedString& src )
88 return QString( (QChar*)src.ToExtString(), src.Length() );
91 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HAsciiString)& src )
96 return ToQString( src->String() );
99 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HExtendedString)& src )
103 return ToQString( src->String() );
106 TCollection_AsciiString HYDROGUI_Tool::ToAsciiString( const QString& src )
108 TCollection_AsciiString res;
111 #ifdef USE_LATIN1_ENCODING
112 QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
114 QTextCodec* codec = QTextCodec::codecForLocale();
118 QByteArray str = codec->fromUnicode( src );
119 res = TCollection_AsciiString( (Standard_CString)str.constData() );
122 res = TCollection_AsciiString( src.toLatin1().data() );
127 TCollection_ExtendedString HYDROGUI_Tool::ToExtString( const QString& src )
130 return TCollection_ExtendedString();
132 Standard_Integer len = src.length();
133 Standard_ExtString extStr = new Standard_ExtCharacter[ ( len + 1 ) * 2 ];
134 memcpy( (void*)extStr, src.unicode(), len * 2 );
135 ((short*)extStr)[ len ] = 0;
137 TCollection_ExtendedString trg( extStr );
142 Handle(TCollection_HAsciiString) HYDROGUI_Tool::ToHAsciiString( const QString& src )
144 return new TCollection_HAsciiString( ToAsciiString( src ) );
147 Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString& src )
149 return new TCollection_HExtendedString( ToExtString( src ) );
152 int HYDROGUI_Tool::GetActiveStudyId()
154 if( SUIT_Session* aSession = SUIT_Session::session() )
155 if( SUIT_Application* anApp = aSession->activeApplication() )
156 if( SUIT_Study* aStudy = anApp->activeStudy() )
161 QString HYDROGUI_Tool::GetTempDir( const bool theToCreate )
165 char* tmpdir = getenv ( "HYDRO_TMP_DIR" );
168 // try to create folder if it does not exist
169 QFileInfo fi( tmpdir );
170 if ( !fi.exists() && theToCreate )
172 if ( QDir().mkdir( tmpdir ) )
173 QFile::setPermissions( tmpdir, (QFile::Permissions)0x4FFFF );
174 QFileInfo fi( tmpdir );
175 if ( !fi.exists() || !fi.isWritable() )
180 tmpdir = getenv ( "TEMP" );
182 tmpdir = getenv ( "TMP" );
188 tmpdir = strdup( "/tmp" );
193 QFileInfo fi( aRes );
194 if ( !fi.exists() || !fi.isWritable() )
195 aRes = QString::null;
200 void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
201 SUIT_ViewManager* theViewManager )
204 if( SUIT_ViewWindow* aViewWindow = theViewManager->getActiveView() )
205 if( STD_TabDesktop* aTabDesktop = dynamic_cast<STD_TabDesktop*>( theModule->getApp()->desktop() ) )
206 if( QtxWorkstack* aWorkstack = aTabDesktop->workstack() )
207 aWorkstack->setActiveWindow( aViewWindow );
210 bool HYDROGUI_Tool::IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject,
211 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 ||
232 anObjectKind == KIND_LAND_COVER
234 || anObjectKind == KIND_SHAPES_GROUP ||
235 anObjectKind == KIND_SPLITTED_GROUP
243 if ( theViewerType.isEmpty() || theViewerType == SVTK_Viewer::Type() )
245 if ( anObjectKind == KIND_BATHYMETRY )
249 if ( theViewerType.isEmpty() || theViewerType == GraphicsView_Viewer::Type() )
251 if ( anObjectKind == KIND_IMAGE ||
252 anObjectKind == KIND_POLYLINEXY )
259 void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule,
260 HYDROData_SequenceOfObjects& theSeq )
262 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
263 if( !aDocument.IsNull() )
265 HYDROData_Iterator anIterator( aDocument );
266 for( ; anIterator.More(); anIterator.Next() )
268 Handle(HYDROData_Entity) anObject = anIterator.Current();
269 if ( !IsObjectHasPresentation( anObject ) )
272 theSeq.Append( anObject );
277 HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Entity)& theObj,
278 const GraphicsView_ObjectList& theObjects )
280 if( !theObj.IsNull() )
282 GraphicsView_ObjectListIterator anIter( theObjects );
283 while( anIter.hasNext() )
285 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
287 Handle(HYDROData_Entity) anObj = aPrs->getObject();
288 if( IsEqual( anObj, theObj ) )
296 GraphicsView_ObjectList HYDROGUI_Tool::GetPrsList( GraphicsView_ViewPort* theViewPort )
298 GraphicsView_ObjectList aList;
301 GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() );
302 while( anIter.hasNext() )
303 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
304 aList.append( aPrs );
309 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module* theModule )
311 HYDROData_SequenceOfObjects aSeq;
313 HYDROGUI_DataModel* aModel = theModule->getDataModel();
315 SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
316 SUIT_DataOwnerPtrList anOwners;
317 aSelectionMgr->selected( anOwners );
319 QStringList aCollectedNameList; // to avoid duplication
320 foreach( SUIT_DataOwner* aSUITOwner, anOwners )
322 if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
324 Handle(HYDROData_Entity) anObject = aModel->objectByEntry( anOwner->entry() );
325 if( !anObject.IsNull() )
327 QString aName = anObject->GetName();
328 if( !aCollectedNameList.contains( aName ) )
330 aSeq.Append( anObject );
331 aCollectedNameList.append( aName );
339 Handle(HYDROData_Entity) HYDROGUI_Tool::GetSelectedObject( HYDROGUI_Module* theModule )
341 HYDROData_SequenceOfObjects aSeq = GetSelectedObjects( theModule );
342 if( !aSeq.IsEmpty() )
347 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetGeometryObjects(
348 HYDROGUI_Module* theModule )
350 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
352 HYDROData_SequenceOfObjects aResSeq;
354 HYDROData_Iterator anIter( aDocument );
355 for ( ; anIter.More(); anIter.Next() )
357 Handle(HYDROData_Entity) anObj = anIter.Current();
358 if ( !HYDROData_Tool::IsGeometryObject( anObj ) )
361 aResSeq.Append( anObj );
367 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetLandCovers( HYDROGUI_Module* theModule )
369 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
371 HYDROData_SequenceOfObjects aResSeq;
373 HYDROData_Iterator anIter( aDocument );
374 for ( ; anIter.More(); anIter.Next() )
376 Handle(HYDROData_Entity) anObj = anIter.Current();
377 if ( !anObj.IsNull() && anObj->IsKind( STANDARD_TYPE(HYDROData_LandCover) ))
378 aResSeq.Append( anObj );
384 ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule )
386 HYDROGUI_DataModel* aModel = theModule->getDataModel();
388 SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
389 SUIT_DataOwnerPtrList anOwners;
390 aSelectionMgr->selected( anOwners );
392 if( anOwners.size() != 1 )
395 if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( anOwners.first().operator->() ) )
397 QString anEntry = anOwner->entry();
398 QString aPrefix = HYDROGUI_DataObject::entryPrefix();
399 if( anEntry.left( aPrefix.length() ) == aPrefix )
401 anEntry.remove( aPrefix );
402 for( ObjectKind anObjectKind = KIND_UNKNOWN + 1; anObjectKind <= KIND_LAST; anObjectKind++ )
403 if( HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( anObjectKind ).toAscii() ) == anEntry )
410 QStringList HYDROGUI_Tool::GetSelectedGeomObjects( HYDROGUI_Module* theModule,
411 QList<GEOM::shape_type> theTypes )
413 QStringList anEntryList;
415 // Get active SalomeApp_Study
416 SalomeApp_Study* aStudy = NULL;
417 if ( theModule && theModule->getApp() ) {
418 aStudy = dynamic_cast<SalomeApp_Study*>( theModule->getApp()->activeStudy() );
425 SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
426 SUIT_DataOwnerPtrList anOwners;
427 aSelectionMgr->selected( anOwners );
429 // Check if the selected objects belong to GEOM and have a shape
430 foreach( SUIT_DataOwner* aSUITOwner, anOwners )
432 if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
434 QString anEntry = anOwner->entry();
435 _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID(qPrintable(anEntry)) );
437 _PTR(SComponent) aSComponent = aSObject->GetFatherComponent();
438 if ( aSComponent && aSComponent->ComponentDataType() == "GEOM" ) {
439 GEOM::GEOM_Object_var aGeomObj =
440 GEOMBase::GetObjectFromIOR( aSObject->GetIOR().c_str() );
442 if ( !aGeomObj->_is_nil() && aGeomObj->IsShape() &&
443 theTypes.contains( aGeomObj->GetShapeType() ) ) {
444 anEntryList << anEntry;
454 Handle(HYDROData_Entity) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule,
455 const QString& theName,
456 const ObjectKind theObjectKind )
458 Handle(HYDROData_Entity) aResObj;
460 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
461 if ( !aDocument.IsNull() )
462 aResObj = aDocument->FindObjectByName( theName, theObjectKind );
467 HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module* theModule,
468 const QStringList& theNames,
469 const ObjectKind theObjectKind )
471 HYDROData_SequenceOfObjects aResSeq;
473 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
474 if ( !aDocument.IsNull() )
475 aResSeq = aDocument->FindObjectsByNames( theNames, theObjectKind );
480 QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule,
481 const QString& thePrefix,
482 const QStringList& theUsedNames,
483 const bool theIsTryToUsePurePrefix)
485 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
486 return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames, theIsTryToUsePurePrefix );
489 size_t HYDROGUI_Tool::GetActiveViewId( HYDROGUI_Module* theModule,
490 const QString& theViewId )
493 SUIT_ViewManager* aViewMgr = theModule->getApp()->activeViewManager();
494 if( !aViewMgr || ( !theViewId.isEmpty() && aViewMgr->getType() != theViewId ) )
497 if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
498 aViewId = (size_t)aViewer;
502 size_t HYDROGUI_Tool::GetActiveGraphicsViewId( HYDROGUI_Module* theModule )
504 return GetActiveViewId( theModule, GraphicsView_Viewer::Type() );
507 size_t HYDROGUI_Tool::GetActiveOCCViewId( HYDROGUI_Module* theModule )
509 return GetActiveViewId( theModule, OCCViewer_Viewer::Type() );
512 QList<size_t> getViewIdList( HYDROGUI_Module* theModule,
513 const QString& theViewId )
516 ViewManagerList aViewMgrs;
517 theModule->getApp()->viewManagers( theViewId, aViewMgrs );
518 QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
519 while( anIter.hasNext() )
521 if( SUIT_ViewManager* aViewMgr = anIter.next() )
523 if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
524 aList.append( (size_t)aViewer );
530 QList<size_t> HYDROGUI_Tool::GetGraphicsViewIdList( HYDROGUI_Module* theModule )
532 return getViewIdList( theModule, GraphicsView_Viewer::Type() );
535 QList<size_t> HYDROGUI_Tool::GetOCCViewIdList( HYDROGUI_Module* theModule )
537 return getViewIdList( theModule, OCCViewer_Viewer::Type() );
540 void HYDROGUI_Tool::setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
541 const int theActionId,
547 OCCViewer_ViewWindow* aView = theViewFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW );
549 aView->toolMgr()->setShown( theActionId, isShown );
550 if ( theActionId == OCCViewer_ViewWindow::MaximizedId )
551 theViewFrame->onMaximizedView( aView, true );
555 void HYDROGUI_Tool::setOCCActionShown( HYDROGUI_Module* theModule,
556 const int theActionId,
560 ViewManagerList aViewMgrs;
561 theModule->getApp()->viewManagers( OCCViewer_Viewer::Type(), aViewMgrs );
562 QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
563 while( anIter.hasNext() )
565 if( SUIT_ViewManager* aViewMgr = anIter.next() )
567 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>
568 ( aViewMgr->getActiveView() );
570 setOCCActionShown( aViewFrame, theActionId, isShown );
575 void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
576 HYDROData_SequenceOfObjects& theRefObjects,
577 QStringList& theRefNames )
579 if( theObj.IsNull() )
582 HYDROData_SequenceOfObjects anAllRefObjects = theObj->GetAllReferenceObjects();
583 theRefObjects.Append( anAllRefObjects );
585 for( int i = 1, n = anAllRefObjects.Length(); i <= n; ++i )
587 Handle(HYDROData_Entity) aRefObj = theRefObjects.Value( i );
588 if( aRefObj.IsNull() || aRefObj->IsRemoved() )
591 QString aRefObjectName = aRefObj->GetName();
592 if( theRefNames.contains( aRefObjectName ) )
595 theRefObjects.Append( aRefObj );
596 theRefNames.append( aRefObjectName );
598 GetObjectReferences( aRefObj, theRefObjects, theRefNames );
602 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetObjectBackReferences(
603 HYDROGUI_Module* theModule,
604 const Handle(HYDROData_Entity)& theObj )
606 if( theObj.IsNull() )
607 return HYDROData_SequenceOfObjects();
609 QString anObjName = theObj->GetName();
611 QMap<QString,HYDROData_SequenceOfObjects> aMapOfBackRefs =
612 GetObjectsBackReferences( theModule, QStringList() << anObjName );
614 return aMapOfBackRefs[ anObjName ];
617 QMap<QString,HYDROData_SequenceOfObjects> HYDROGUI_Tool::GetObjectsBackReferences(
618 HYDROGUI_Module* theModule, const QStringList& theObjectNames )
620 QMap<QString,HYDROData_SequenceOfObjects> aResMap;
622 if( theObjectNames.isEmpty() )
625 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
626 if( aDocument.IsNull() )
629 HYDROData_Iterator anIterator( aDocument );
630 for( ; anIterator.More(); anIterator.Next() )
632 Handle(HYDROData_Entity) anObject = anIterator.Current();
633 if( anObject.IsNull() || anObject->IsRemoved() )
636 QString anObjectName = anObject->GetName();
637 if ( theObjectNames.contains( anObjectName ) )
640 HYDROData_SequenceOfObjects aRefObjects = anObject->GetAllReferenceObjects();
641 for ( int i = 1, n = aRefObjects.Length(); i <= n; ++i )
643 Handle(HYDROData_Entity) aRefObject = aRefObjects.Value( i );
644 if( aRefObject.IsNull() || aRefObject->IsRemoved() )
647 QString aRefObjectName = aRefObject->GetName();
648 if ( !theObjectNames.contains( aRefObjectName ) )
651 aResMap[ aRefObjectName ].Append( anObject );
658 QDockWidget* HYDROGUI_Tool::WindowDock( QWidget* wid )
663 QDockWidget* dock = 0;
664 QWidget* w = wid->parentWidget();
667 dock = ::qobject_cast<QDockWidget*>( w );
668 w = w->parentWidget();
673 QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module* theModule,
674 const QStringList& theZoneNames )
676 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
677 return GenerateFillingColor( aDocument, theZoneNames );
680 QColor HYDROGUI_Tool::GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
681 const QStringList& theZoneNames )
683 QColor aFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
686 int aR = 0, aG = 0, aB = 0;
687 QStringListIterator aZoneNameIter( theZoneNames );
688 while( aZoneNameIter.hasNext() )
690 const QString& aZoneName = aZoneNameIter.next();
691 Handle(HYDROData_ImmersibleZone) aRefZone =
692 Handle(HYDROData_ImmersibleZone)::DownCast( theDoc->FindObjectByName( aZoneName, KIND_IMMERSIBLE_ZONE ) );
693 if( !aRefZone.IsNull() )
695 QColor aRefColor = aRefZone->GetFillingColor();
696 aR += aRefColor.red();
697 aG += aRefColor.green();
698 aB += aRefColor.blue();
705 aFillingColor = QColor( aR / aCounter, aG / aCounter, aB / aCounter );
708 return aFillingColor;
711 QStringList HYDROGUI_Tool::FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc,
712 const ObjectKind theObjectKind,
713 bool isCheckValidProfile )
717 HYDROData_Iterator anIter( theDoc, theObjectKind );
718 for ( ; anIter.More(); anIter.Next() ) {
719 Handle(HYDROData_Entity) anObject = anIter.Current();
721 bool isOK = !anObject.IsNull();
723 if( isOK && isCheckValidProfile )
725 Handle_HYDROData_Profile aProfile = Handle_HYDROData_Profile::DownCast( anObject );
726 if( !aProfile.IsNull() && !aProfile->IsValid() )
731 aNames.append( anObject->GetName() );
737 QString HYDROGUI_Tool::GetCoordinateString( const double theNumber, bool isInLocale )
741 static QLocale aLocale( QLocale::English, QLocale::France );
742 return aLocale.toString( theNumber, 'f', 2 );
745 return QString::number( theNumber, 'f', 2 );
748 Handle(Image_PixMap) HYDROGUI_Tool::Pixmap( const QImage& theImage )
750 Handle(Image_PixMap) pix;
751 if ( theImage.isNull() || theImage.format() == QImage::Format_Invalid )
754 Handle(Image_PixMap) tmpPix = new Image_PixMap();
755 tmpPix->SetTopDown( false );
756 QImage anImage = theImage.mirrored();
757 if ( !anImage.hasAlphaChannel() && anImage.allGray() )
759 tmpPix->InitTrash( Image_PixMap::ImgGray, anImage.width(), anImage.height(), anImage.width() );
760 for ( int r = 0; r < anImage.height(); r++ )
762 Standard_Byte* aRowData = tmpPix->ChangeRow( anImage.height() - r - 1 );
763 for ( int p = 0; p < anImage.width(); p++ )
764 aRowData[p] = qRed( anImage.pixel( p, r ) );
769 Image_PixMap::ImgFormat aFormat;
770 if ( anImage.hasAlphaChannel() )
772 if ( anImage.format() != QImage::Format_ARGB32 )
773 anImage = anImage.convertToFormat( QImage::Format_ARGB32 );
774 aFormat = Image_PixMap::ImgRGBA;
778 if ( anImage.format() != QImage::Format_RGB888 )
779 anImage = anImage.convertToFormat( QImage::Format_RGB888 );
780 aFormat = Image_PixMap::ImgRGB;
783 tmpPix->InitWrapper( aFormat, (Standard_Byte*)anImage.bits(), anImage.width(), anImage.height(), anImage.bytesPerLine() );
786 if ( !tmpPix.IsNull() )
788 pix = new Image_PixMap();
789 pix->InitCopy( *tmpPix.operator->() );
790 pix->SetTopDown( tmpPix->IsTopDown() );
796 void HYDROGUI_Tool::DeleteGeomObjects( HYDROGUI_Module* theModule, const QStringList& theEntries )
798 QStringList anEntryList;
800 // Get active SalomeApp_Study
801 SalomeApp_Study* aStudy = NULL;
802 if ( theModule && theModule->getApp() ) {
803 aStudy = dynamic_cast<SalomeApp_Study*>( theModule->getApp()->activeStudy() );
810 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
811 if ( aGeomEngine->_is_nil() ) {
815 // Delete GEOM objects
816 _PTR(StudyBuilder) aStudyBuilder( aStudy->studyDS()->NewBuilder() );
817 foreach ( const QString anEntry, theEntries ) {
818 _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable(anEntry) ) );
820 GEOM::GEOM_Object_var aGeomObj =
821 GEOMBase::GetObjectFromIOR( aSObject->GetIOR().c_str() );
823 if ( !aGeomObj->_is_nil() ) {
824 aGeomEngine->RemoveObject( aGeomObj );
827 aStudyBuilder->RemoveObject( aSObject );