From: ouv Date: Thu, 3 Oct 2013 09:50:20 +0000 (+0000) Subject: Feature 32: Image presentation in OCCViewer. X-Git-Tag: BR_hydro_v_0_3~99 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca0e09c1e1bb19c9855e2f3839243da36097ee1c;p=modules%2Fhydro.git Feature 32: Image presentation in OCCViewer. --- diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.cxx b/src/HYDROGUI/HYDROGUI_AISCurve.cxx index 67265afd..c8366ebc 100755 --- a/src/HYDROGUI/HYDROGUI_AISCurve.cxx +++ b/src/HYDROGUI/HYDROGUI_AISCurve.cxx @@ -189,6 +189,13 @@ void HYDROGUI_AISCurve::Display() } } +void HYDROGUI_AISCurve::Erase() +{ + for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){ + myCurveRepresentation[i]->Erase(); + } +} + void HYDROGUI_AISCurve::buildCurve() { for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){ diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.h b/src/HYDROGUI/HYDROGUI_AISCurve.h index 5750ae6a..f1fca75a 100755 --- a/src/HYDROGUI/HYDROGUI_AISCurve.h +++ b/src/HYDROGUI/HYDROGUI_AISCurve.h @@ -56,6 +56,7 @@ public: void setCurve( CurveCreator_Curve* theCurve ); void Display(); + void Erase(); virtual void pointInserted( int theSection, int theIndx ); diff --git a/src/HYDROGUI/HYDROGUI_DataObject.cxx b/src/HYDROGUI/HYDROGUI_DataObject.cxx index f0b47e22..b2b4d05e 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.cxx +++ b/src/HYDROGUI/HYDROGUI_DataObject.cxx @@ -72,14 +72,17 @@ QFont HYDROGUI_DataObject::font( const int theId ) const return aFont; } -QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& theObject ) +QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& theObject, + const bool theWithPrefix ) { QString aEntryStr = QString::null; if( !theObject.IsNull() ) { TCollection_AsciiString aLabEntr; TDF_Tool::Entry( theObject->Label(), aLabEntr ); - aEntryStr = HYDROGUI_DataObject::entryPrefix() + QString( aLabEntr.ToCString() ); + aEntryStr = aLabEntr.ToCString(); + if( theWithPrefix ) + aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() ); } return aEntryStr; } diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index edb79f02..69693349 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -91,7 +91,8 @@ public: /** * Returns the full entry for the specified data object. */ - static QString dataObjectEntry( const Handle(HYDROData_Object)& theObject ); + static QString dataObjectEntry( const Handle(HYDROData_Object)& theObject, + const bool theWithPrefix = true ); protected: Handle(HYDROData_Object) myData; ///< object from data model diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx index a8ccf8a5..01a4b155 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx @@ -512,19 +512,21 @@ void HYDROGUI_ImportImageDlg::initializePointSelection() blockSignalsLambert( false ); */ - double aCartX0 = 600000; - double aCartY0 = 6800000; + //double aCartX0 = 600000; + //double aCartY0 = 6800000; + double aCartX0 = 0; + double aCartY0 = 0; blockSignalsCartesian( true ); myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 ); myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 ); - myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 1000 ); + myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 ); myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 ); myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 ); - myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 + 1000 ); + myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 + 500 ); for( int aPointType = HYDROGUI_PrsImage::PointA; aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ ) diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 5f73b4b0..46cbd7eb 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -339,7 +339,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, if( myIsEdit ) anImageObj->Update(); - theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced; + theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced; return true; } diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index d20db248..8be446e4 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -145,7 +145,8 @@ HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int return aResShape; ObjectKind anObjectKind = theObject->GetKind(); - if ( anObjectKind != KIND_POLYLINE && + if ( anObjectKind != KIND_IMAGE && + anObjectKind != KIND_POLYLINE && anObjectKind != KIND_ZONE ) return aResShape; diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index b8b19f76..2aa8ccac 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -45,100 +45,14 @@ HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit ) : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL), - myActiveViewManager(NULL), myPreviewViewManager(NULL), myAISCurve(NULL) + myViewManager(NULL), myAISCurve(NULL) { setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) ); } HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp() { - closePreview(); -} - -HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const -{ - HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() ); - connect( aDlg ,SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) ); - return aDlg; -} - -bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, - QString& theErrorMsg ) -{ - HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel(); - - int aStudyId = module()->getStudyId(); - bool aHasDoc = HYDROData_Document::HasDocument(aStudyId); - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId ); - if( aDocument.IsNull() ) - return false; - - Handle(HYDROData_Polyline) aPolylineObj; - if( myIsEdit ){ - aPolylineObj = myEditedObject; - } - else{ - aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) ); - } - - if( aPolylineObj.IsNull() ) - return false; - - QString aPolylineName = aPanel->getPolylineName(); - aPolylineObj->SetName(aPolylineName); - int aDimInt = 3; - if( myCurve->getDimension() == CurveCreator::Dim2d ) - aDimInt = 2; - aPolylineObj->setDimension(aDimInt); - QList aPolylineData; - for( int i=0 ; i < myCurve->getNbSections() ; i++ ){ - PolylineSection aSect; - aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str())); - aSect.myIsClosed = myCurve->isClosed(i); - aSect.myType = PolylineSection::SECTION_POLYLINE; - if( myCurve->getType(i) == CurveCreator::BSpline ){ - aSect.myType = PolylineSection::SECTION_SPLINE; - } - CurveCreator::Coordinates aCoords = myCurve->getPoints(i); - for( int j = 0 ; j < aCoords.size() ; j++ ){ - aSect.myCoords << aCoords.at(j); - } - aPolylineData << aSect; - } - aPolylineObj->setPolylineData(aPolylineData); - - theUpdateFlags = UF_Model; - module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true ); - return true; -} - -void HYDROGUI_PolylineOp::onCreatePreview() -{ - LightApp_Application* anApp = module()->getApp(); - - myActiveViewManager = anApp->activeViewManager(); - - myPreviewViewManager = - dynamic_cast( anApp->createViewManager( OCCViewer_Viewer::Type() ) ); - if( myPreviewViewManager ) - { - connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), - this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); - - //anApp->selectionMgr()->setEnabled(false); // what the hell?! - myPreviewViewManager->setTitle( tr( "CREATE_POLYLINE" ) ); - OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer(); - aViewer->enableSelection(true); - aViewer->enableMultiselection(true); - Handle_AIS_InteractiveContext aCtx = aViewer->getAISContext(); - - OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView(); - vw->onTopView(); - - myAISCurve = new HYDROGUI_AISCurve(myCurve, aCtx); - - myAISCurve->Display(); - } + erasePreview(); } void HYDROGUI_PolylineOp::startOperation() @@ -189,23 +103,80 @@ void HYDROGUI_PolylineOp::startOperation() myAISCurve->setCurve(myCurve); if( anOldCurve ) delete anOldCurve; - onCreatePreview(); + displayPreview(); } void HYDROGUI_PolylineOp::abortOperation() { - closePreview(); + erasePreview(); HYDROGUI_Operation::abortOperation(); } void HYDROGUI_PolylineOp::commitOperation() { - closePreview(); + erasePreview(); HYDROGUI_Operation::commitOperation(); } +HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const +{ + HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() ); + connect( aDlg, SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) ); + return aDlg; +} + +bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, + QString& theErrorMsg ) +{ + HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel(); + + int aStudyId = module()->getStudyId(); + bool aHasDoc = HYDROData_Document::HasDocument(aStudyId); + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId ); + if( aDocument.IsNull() ) + return false; + + Handle(HYDROData_Polyline) aPolylineObj; + if( myIsEdit ){ + aPolylineObj = myEditedObject; + } + else{ + aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) ); + } + + if( aPolylineObj.IsNull() ) + return false; + + QString aPolylineName = aPanel->getPolylineName(); + aPolylineObj->SetName(aPolylineName); + int aDimInt = 3; + if( myCurve->getDimension() == CurveCreator::Dim2d ) + aDimInt = 2; + aPolylineObj->setDimension(aDimInt); + QList aPolylineData; + for( int i=0 ; i < myCurve->getNbSections() ; i++ ){ + PolylineSection aSect; + aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str())); + aSect.myIsClosed = myCurve->isClosed(i); + aSect.myType = PolylineSection::SECTION_POLYLINE; + if( myCurve->getType(i) == CurveCreator::BSpline ){ + aSect.myType = PolylineSection::SECTION_SPLINE; + } + CurveCreator::Coordinates aCoords = myCurve->getPoints(i); + for( int j = 0 ; j < aCoords.size() ; j++ ){ + aSect.myCoords << aCoords.at(j); + } + aPolylineData << aSect; + } + aPolylineObj->setPolylineData(aPolylineData); + + theUpdateFlags = UF_Model; + module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true ); + return true; +} + void HYDROGUI_PolylineOp::onEditorSelectionChanged() { HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel(); @@ -224,25 +195,39 @@ void HYDROGUI_PolylineOp::onEditorSelectionChanged() } } -void HYDROGUI_PolylineOp::onLastViewClosed( SUIT_ViewManager* theViewManager ) +void HYDROGUI_PolylineOp::displayPreview() { - closePreview(); -} + LightApp_Application* anApp = module()->getApp(); -void HYDROGUI_PolylineOp::closePreview() -{ - if( myPreviewViewManager ) + myViewManager = + dynamic_cast( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ); + if( myViewManager ) { - disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), - this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); - - module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here - myPreviewViewManager = 0; + if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if( !aCtx.IsNull() ) + { + myAISCurve = new HYDROGUI_AISCurve( myCurve, aCtx ); + myAISCurve->Display(); + } + } } +} - if( myActiveViewManager ) +void HYDROGUI_PolylineOp::erasePreview() +{ + if( myViewManager ) { - HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager ); - myActiveViewManager = 0; + if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if( !aCtx.IsNull() && myAISCurve ) + { + myAISCurve->Erase(); + delete myAISCurve; + myAISCurve = 0; + } + } } } diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.h b/src/HYDROGUI/HYDROGUI_PolylineOp.h index 28667125..614960df 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.h +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.h @@ -28,7 +28,6 @@ #include class OCCViewer_ViewManager; -class SUIT_ViewManager; class CurveCreator_Curve; class HYDROGUI_AISCurve; @@ -49,20 +48,15 @@ protected: virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); - void onCreatePreview(); - protected slots: void onEditorSelectionChanged(); - void onLastViewClosed( SUIT_ViewManager* ); - private: - void closePreview(); + void displayPreview(); + void erasePreview(); private: - SUIT_ViewManager* myActiveViewManager; - - OCCViewer_ViewManager* myPreviewViewManager; + OCCViewer_ViewManager* myViewManager; bool myIsEdit; Handle(HYDROData_Polyline) myEditedObject; diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 1a69cfb9..4b78aae4 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -22,6 +22,9 @@ #include "HYDROGUI_Shape.h" +#include "HYDROGUI_DataObject.h" +#include "HYDROGUI_Tool.h" + #include #include @@ -34,6 +37,7 @@ #include #include +#include #include #include @@ -46,6 +50,7 @@ #include #include +#include HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext, const Handle(HYDROData_Object)& theObject ) @@ -67,6 +72,8 @@ HYDROGUI_Shape::~HYDROGUI_Shape() if ( !myShape.IsNull() ) myShape.Nullify(); + + removeTextureFile(); } void HYDROGUI_Shape::display( const bool theIsUpdateViewer ) @@ -117,6 +124,56 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) setWire( aPolylineWire, false, false ); } + else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) ) + { + Handle(HYDROData_Image) anImageObj = + Handle(HYDROData_Image)::DownCast( myObject ); + + removeTextureFile(); + + QString aTextureFileName = generateTextureFileName( anImageObj ); + + QImage anImage = anImageObj->Image(); + QString aFilePath = anImageObj->GetFilePath(); + QTransform aTrsf = anImageObj->Trsf(); + + int aWidth = anImage.width(); + int aHeight = anImage.height(); + + anImage = anImage.transformed( aTrsf, Qt::SmoothTransformation ); + + // temporary optimization, to reduce the saved image size (and the texture quality) + QImage anImageToSave = reduceTexture( anImage, 500 ); + anImageToSave.save( aTextureFileName ); + + QPointF aPoint1( 0, 0 ); + QPointF aPoint2( aWidth, 0 ); + QPointF aPoint3( aWidth, aHeight ); + QPointF aPoint4( 0, aHeight ); + + aPoint1 = aTrsf.map( aPoint1 ); + aPoint2 = aTrsf.map( aPoint2 ); + aPoint3 = aTrsf.map( aPoint3 ); + aPoint4 = aTrsf.map( aPoint4 ); + + QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4; + QRectF aRect = aPolygon.boundingRect(); + + gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 ); + gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 ); + gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 ); + gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 ); + + TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(); + TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge(); + TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge(); + TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge(); + + TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire(); + + setTextureFileName( aTextureFileName, false, false ); + setFace( aWire, false, false ); + } } if ( myShape.IsNull() || !isVisible() ) @@ -190,7 +247,7 @@ void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace, const bool theIsUpdateViewer ) { myTopoShape = theFace; - myDisplayMode = AIS_Shaded; + myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_ExactHLR; buildShape(); updateShape( theToDisplay, theIsUpdateViewer ); @@ -232,6 +289,19 @@ QColor HYDROGUI_Shape::getHighlightColor() const return myHighlightColor; } +void HYDROGUI_Shape::setTextureFileName( const QString& theFileName, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + myTextureFileName = theFileName; + updateShape( theToDisplay, theIsUpdateViewer ); +} + +QString HYDROGUI_Shape::getTextureFileName() const +{ + return myTextureFileName; +} + void HYDROGUI_Shape::buildShape() { // Erase previously created shape @@ -240,7 +310,7 @@ void HYDROGUI_Shape::buildShape() if ( myTopoShape.IsNull() ) return; - myShape = new AIS_Shape( myTopoShape ); + myShape = new AIS_TexturedShape( myTopoShape ); if ( !myObject.IsNull() ) myShape->SetOwner( myObject ); @@ -248,6 +318,14 @@ void HYDROGUI_Shape::buildShape() myShape->SetTransparency( 0 ); myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode ); + QString aTextureFileName = getTextureFileName(); + if( !aTextureFileName.isEmpty() ) + { + myShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) ); + myShape->SetTextureMapOn(); + myShape->DisableTextureModulate(); + } + // Init default params for shape const Handle(AIS_Drawer)& anAttributes = myShape->Attributes(); if ( !anAttributes.IsNull() ) @@ -362,4 +440,50 @@ void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor ) } } +QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Object)& theImageObj ) +{ + QString aResult; + if( !theImageObj.IsNull() ) + { + QString aTempDir = HYDROGUI_Tool::GetTempDir( true ); + + int aStudyId = HYDROGUI_Tool::GetActiveStudyId(); + QString aPrefix = QString( "image_%1" ).arg( aStudyId ); + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false ); + anEntry.replace( ':', '_' ); + + QString anExtension = "bmp"; + + aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension ); + } + return aResult; +} + +void HYDROGUI_Shape::removeTextureFile() const +{ + QFile aFile( getTextureFileName() ); + if( aFile.exists() ) + aFile.remove(); +} + +QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit ) +{ + double aSizeLimit = (double)theSizeLimit; + double aWidth = (double)theImage.width(); + double aHeight = (double)theImage.height(); + if( aWidth > aSizeLimit || aHeight > aSizeLimit ) + { + if( aWidth > aHeight ) + { + aHeight /= ( aWidth / aSizeLimit ); + aWidth = aSizeLimit; + } + else + { + aWidth /= ( aHeight / aSizeLimit ); + aHeight = aSizeLimit; + } + } + return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation ); +} diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 7e67eb08..6757079e 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -24,11 +24,12 @@ #define HYDROGUI_SHAPE_H #include -#include +#include #include #include +#include #include #include @@ -83,6 +84,11 @@ public: virtual void setHighlightColor( const QColor& theColor ); virtual QColor getHighlightColor() const; + virtual void setTextureFileName( const QString& theFileName, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); + virtual QString getTextureFileName() const; + protected: virtual void buildShape(); virtual void updateShape( const bool theToDisplay = true, @@ -93,10 +99,15 @@ private: static double getQuantityColorVal( const int theColorVal ); void colorShapeBorder( const QColor& theColor ); + static QString generateTextureFileName( const Handle(HYDROData_Object)& theImageObj ); + void removeTextureFile() const; + + static QImage reduceTexture( const QImage& theImage, const int theSizeLimit ); + private: Handle(AIS_InteractiveContext) myContext; Handle(HYDROData_Object) myObject; - Handle(AIS_Shape) myShape; + Handle(AIS_TexturedShape) myShape; bool myIsToUpdate; bool myIsVisible; @@ -108,6 +119,8 @@ private: QColor myFillingColor; QColor myBorderColor; QColor myHighlightColor; + + QString myTextureFileName; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 27d50dcb..67abb156 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -43,12 +43,15 @@ #include +#include #include #include #include -#include +#include +#include #include +#include // Definition of this id allows to use 'latin1' (Qt alias for 'ISO-8859-1') // encoding instead of default 'System' @@ -134,6 +137,54 @@ Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString& return new TCollection_HExtendedString( ToExtString( src ) ); } +int HYDROGUI_Tool::GetActiveStudyId() +{ + if( SUIT_Session* aSession = SUIT_Session::session() ) + if( SUIT_Application* anApp = aSession->activeApplication() ) + if( SUIT_Study* aStudy = anApp->activeStudy() ) + return aStudy->id(); + return 0; +} + +QString HYDROGUI_Tool::GetTempDir( const bool theToCreate ) +{ + QString aRes; + + char* tmpdir = getenv ( "HYDRO_TMP_DIR" ); + if ( tmpdir ) + { + // try to create folder if it does not exist + QFileInfo fi( tmpdir ); + if ( !fi.exists() && theToCreate ) + { + if ( QDir().mkdir( tmpdir ) ) + QFile::setPermissions( tmpdir, (QFile::Permissions)0x4FFFF ); + QFileInfo fi( tmpdir ); + if ( !fi.exists() || !fi.isWritable() ) + tmpdir = 0; + } + } + if ( !tmpdir ) + tmpdir = getenv ( "TEMP" ); + if ( !tmpdir ) + tmpdir = getenv ( "TMP" ); + if ( !tmpdir ) + { +#ifdef WNT + tmpdir = "C:\\"; +#else + tmpdir = "/tmp"; +#endif + } + aRes = tmpdir; + + QFileInfo fi( aRes ); + if ( !fi.exists() || !fi.isWritable() ) + aRes = QString::null; + + return aRes; +} + bool HYDROGUI_Tool::IsEqual( const Handle(HYDROData_Object)& theObj1, const Handle(HYDROData_Object)& theObj2 ) { diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index fc60e3b5..869dd4d2 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -88,6 +88,19 @@ public: */ static Handle(TCollection_HExtendedString) ToHExtString( const QString& ); + /** + * \brief Get the active study id. + * \return active study id + */ + static int GetActiveStudyId(); + + /** + * \brief Get path to the temporary directory. + * \param theToCreate flag used to create a directory if it doesn't exist + * \return path + */ + static QString GetTempDir( const bool theToCreate ); + /** * \brief Check that the specified objects are equal. * \param theObj1 first object diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index 3def5370..d946766c 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -228,6 +228,6 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, module()->setObjectVisible( aViewId, aResult, true ); } - theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced; + theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced; return true; } diff --git a/src/HYDROGUI/HYDROGUI_UpdateImageOp.cxx b/src/HYDROGUI/HYDROGUI_UpdateImageOp.cxx index 0ac92a74..e0777f23 100644 --- a/src/HYDROGUI/HYDROGUI_UpdateImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_UpdateImageOp.cxx @@ -56,6 +56,6 @@ void HYDROGUI_UpdateImageOp::startOperation() commitDocOperation(); - module()->update( UF_Model | UF_Viewer | UF_GV_Forced ); + module()->update( UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced ); commit(); }