HYDROGUI_Displayer.h
HYDROGUI_ExportImageOp.h
HYDROGUI_GVSelector.h
+ HYDROGUI_ImagePrs.h
HYDROGUI_ImmersibleZoneDlg.h
HYDROGUI_ImmersibleZoneOp.h
HYDROGUI_ImportBathymetryDlg.h
HYDROGUI_Displayer.cxx
HYDROGUI_ExportImageOp.cxx
HYDROGUI_GVSelector.cxx
+ HYDROGUI_ImagePrs.cxx
HYDROGUI_ImmersibleZoneDlg.cxx
HYDROGUI_ImmersibleZoneOp.cxx
HYDROGUI_ImportBathymetryDlg.cxx
--- /dev/null
+#include "HYDROGUI_ImagePrs.h"
+
+#include <Prs3d_Root.hxx>
+
+#include <Graphic3d_Group.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <Graphic3d_ArrayOfTriangles.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
+
+IMPLEMENT_STANDARD_TYPE(HYDROGUI_ImagePrs)
+IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
+ STANDARD_TYPE(AIS_InteractiveObject),
+ STANDARD_TYPE(SelectMgr_SelectableObject),
+ STANDARD_TYPE(PrsMgr_PresentableObject),
+ STANDARD_TYPE(MMgt_TShared),
+ STANDARD_TYPE(Standard_Transient),
+IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
+IMPLEMENT_STANDARD_TYPE_END(HYDROGUI_ImagePrs)
+
+IMPLEMENT_DOWNCAST(HYDROGUI_ImagePrs,Standard_Transient)
+IMPLEMENT_STANDARD_RTTI(HYDROGUI_ImagePrs)
+
+HYDROGUI_ImagePrs::HYDROGUI_ImagePrs()
+ : AIS_InteractiveObject()
+{
+// SetTransformPersistence( Graphic3d_TMF_2d );
+// SetZLayer( Graphic3d_ZLayerId_TopOSD );
+}
+
+HYDROGUI_ImagePrs::HYDROGUI_ImagePrs( const Handle(Image_PixMap)& theImage, const QPolygonF& theContour )
+ : AIS_InteractiveObject(),
+ myImage( theImage ),
+ myContour( theContour )
+{
+}
+
+HYDROGUI_ImagePrs::~HYDROGUI_ImagePrs()
+{
+}
+
+QPolygonF HYDROGUI_ImagePrs::GetContour() const
+{
+ return myContour;
+}
+
+void HYDROGUI_ImagePrs::SetContour( const QPolygonF& theRect )
+{
+ if ( myContour != theRect )
+ SetToUpdate();
+
+ myContour = theRect;
+}
+
+Handle(Image_PixMap) HYDROGUI_ImagePrs::GetImage() const
+{
+ return myImage;
+}
+
+void HYDROGUI_ImagePrs::SetImage( const Handle(Image_PixMap)& theImage )
+{
+ if ( myImage != theImage )
+ SetToUpdate();
+
+ myImage = theImage;
+}
+
+void HYDROGUI_ImagePrs::ComputeSelection( const Handle(SelectMgr_Selection)&, const Standard_Integer )
+{
+}
+
+void HYDROGUI_ImagePrs::Compute( const Handle(PrsMgr_PresentationManager3d)&,
+ const Handle(Prs3d_Presentation)& aPrs, const Standard_Integer )
+{
+ aPrs->Clear();
+
+ if ( aPrs.IsNull() || myImage.IsNull() )
+ return;
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
+
+ Graphic3d_MaterialAspect aMat( Graphic3d_NOM_PLASTIC );
+ aMat.SetTransparency( 0.5 );
+ Handle(Graphic3d_AspectFillArea3d) aFillAspect =
+ new Graphic3d_AspectFillArea3d( Aspect_IS_SOLID, Quantity_NOC_WHITE, Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0, aMat, aMat );
+
+ Handle(Graphic3d_TextureMap) aTex = new Graphic3d_Texture2Dmanual( myImage );
+ aFillAspect->SetTextureMapOn();
+ aFillAspect->SetTextureMap( aTex );
+
+ Handle(Graphic3d_ArrayOfTriangles) aTriangles = new Graphic3d_ArrayOfTriangles( 6, 0, Standard_False, Standard_False, Standard_True );
+
+ aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) );
+ aTriangles->AddVertex( convert( myContour[1] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 0 : 1 ) );
+ aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) );
+
+ aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) );
+ aTriangles->AddVertex( convert( myContour[3] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 1 : 0 ) );
+ aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) );
+
+ aGroup->SetGroupPrimitivesAspect( aFillAspect );
+ aGroup->AddPrimitiveArray( aTriangles );
+}
+
+gp_Pnt HYDROGUI_ImagePrs::convert( const QPointF& thePoint ) const
+{
+ return gp_Pnt( thePoint.x(), thePoint.y(), 0 );
+}
--- /dev/null
+#ifndef HYDROGUI_IMAGEPRS_H
+#define HYDROGUI_IMAGEPRS_H
+
+#include <AIS_InteractiveObject.hxx>
+
+#include <Image_PixMap.hxx>
+
+#include <QPolygonF>
+
+class Font_FTFont;
+class HYDROGUI_ImagePrs;
+
+DEFINE_STANDARD_HANDLE(HYDROGUI_ImagePrs, AIS_InteractiveObject)
+
+class HYDROGUI_ImagePrs : public AIS_InteractiveObject
+{
+public:
+ HYDROGUI_ImagePrs();
+ HYDROGUI_ImagePrs( const Handle(Image_PixMap)&, const QPolygonF& );
+ virtual ~HYDROGUI_ImagePrs();
+
+ QPolygonF GetContour() const;
+ void SetContour( const QPolygonF& );
+
+ Handle(Image_PixMap) GetImage() const;
+ void SetImage( const Handle(Image_PixMap)& );
+
+ virtual void Compute( const Handle(PrsMgr_PresentationManager3d)&,
+ const Handle(Prs3d_Presentation)&, const Standard_Integer = 0 );
+ virtual void ComputeSelection( const Handle(SelectMgr_Selection)&, const Standard_Integer );
+
+ DEFINE_STANDARD_RTTI(HYDROGUI_ImagePrs)
+
+private:
+ gp_Pnt convert( const QPointF& ) const;
+
+private:
+ Handle(Image_PixMap) myImage;
+ QPolygonF myContour;
+};
+
+#endif
connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileFinishChanged( const QString& ) ) );
connect( myProfileNumber, SIGNAL( valueChanged( int ) ), this, SIGNAL( profileNumberChanged( int ) ) );
- connect( myParams, SIGNAL( textChanged( const QString& ) ), this, SIGNAL( interpolatorParametersChanged( const QString& ) ) );
+ connect( myParams, SIGNAL( editingFinished() ), this, SIGNAL( onParametersEditingFinished() ) );
new HYDROGUI_OCCSelector( module(), viewer(), selectionMgr() );
myDescr->clear();
}
+void HYDROGUI_ProfileInterpolateDlg::onParametersEditingFinished()
+{
+ emit interpolatorParametersChanged( myParams->text() );
+}
+
void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName )
{
myRiverProfiles.clear();
void profileFinishChanged( const QString& );
private slots:
+ void onParametersEditingFinished();
void onRiverChanged( const QString& );
void onInterpolatorIndexChanged( int );
void onProfileChanged( const QString& );
//
#include <HYDROGUI_ShapeImage.h>
-#include <HYDROGUI_DataObject.h>
+
#include <HYDROGUI_Tool.h>
-#include <HYDROData_Document.h>
+#include <HYDROGUI_ImagePrs.h>
+
#include <HYDROData_Image.h>
+#include <HYDROData_Document.h>
-#include <AIS_TexturedShape.hxx>
-#include <BRepBuilderAPI_MakeEdge.hxx>
-#include <BRepBuilderAPI_MakeWire.hxx>
#include <gp_Pnt.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Wire.hxx>
-
-#include <SUIT_MessageBox.h>
-#include <QFile>
HYDROGUI_ShapeImage::HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& theContext,
const Handle_HYDROData_Image& theImage,
HYDROGUI_ShapeImage::~HYDROGUI_ShapeImage()
{
- removeTextureFile();
}
void HYDROGUI_ShapeImage::update( bool theIsUpdateViewer, bool isDeactivateSelection )
{
setIsToUpdate( false );
- // Try to retrieve information from object
- Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() );
-
- if( !anImageObj.IsNull() )
- {
- 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();
-
- QString anImageError = "";
-
- QTransform anInversion = QTransform::fromScale( -1, -1 );
- anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
-
- if ( anImage.isNull() )
- anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" );
- else
- {
- // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
- int aTrsfWidth = anImage.width();
- int aDelta = aTrsfWidth % 4;
- if ( aDelta > 0 )
- {
- aTrsfWidth += ( 4 - aDelta );
- }
- anImage = anImage.scaledToWidth( aTrsfWidth );
-
- // temporary optimization, to reduce the saved image size (and the texture quality)
- QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
-
- bool isSaved = anImageToSave.save( aTextureFileName );
- if ( !isSaved )
- anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
- else
- QFile::setPermissions( aTextureFileName, (QFile::Permissions)0x4FFFF );
- }
-
- if ( !anImageError.isEmpty() )
- {
- SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ),
- QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError );
- }
+ buildShape();
- QPointF aPoint1( 0, 0 ); // 1: top left
- QPointF aPoint2( aWidth, 0 ); // 2: top right
- QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
- QPointF aPoint4( 0, aHeight ); // 4: bottom left
-
- 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 );
-
- Handle_HYDROData_Document aDoc = HYDROData_Document::Document( anImageObj->Label() );
- aDoc->Transform( aPnt1, true );
- aDoc->Transform( aPnt2, true );
- aDoc->Transform( aPnt3, true );
- aDoc->Transform( aPnt4, true );
-
- 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();
- aWire.Closed( true );
-
- setTextureFileName( aTextureFileName, false, false );
- setFace( aWire, false, false, aTextureFileName );
- isDeactivateSelection = true;
- }
-
HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
}
-void HYDROGUI_ShapeImage::setTextureFileName( const QString& theFileName,
- const bool theToDisplay,
- const bool theIsUpdateViewer )
+Handle(AIS_InteractiveObject) HYDROGUI_ShapeImage::createShape() const
{
- myTextureFileName = theFileName;
- updateShape( theToDisplay, theIsUpdateViewer );
-}
-
-QString HYDROGUI_ShapeImage::getTextureFileName() const
-{
- return myTextureFileName;
-}
-
-QString HYDROGUI_ShapeImage::generateTextureFileName( const Handle(HYDROData_Entity)& 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";
+ Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() );
+ if ( anImageObj.IsNull() )
+ return Handle_AIS_InteractiveObject();
- aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
- }
- return aResult;
+ Handle(HYDROGUI_ImagePrs) aPrs = new HYDROGUI_ImagePrs( imagePixMap( anImageObj ), imageContour( anImageObj ) );
+ return aPrs;
}
-void HYDROGUI_ShapeImage::removeTextureFile() const
+Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Image)& theImageObj ) const
{
- QFile aFile( getTextureFileName() );
- if( aFile.exists() )
- aFile.remove();
-}
-
-QImage HYDROGUI_ShapeImage::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
+ Handle(Image_PixMap) aPix;
+ if ( !theImageObj.IsNull() )
{
- aWidth /= ( aHeight / aSizeLimit );
- aHeight = aSizeLimit;
+ QTransform aTrsf = theImageObj->Trsf();
+ QImage anImage = theImageObj->Image();
+// anImage = anImage.transformed( QTransform::fromScale( -1, -1 ) * aTrsf, Qt::SmoothTransformation );
+
+ if ( !anImage.isNull() )
+ {
+ // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
+ int aTrsfWidth = anImage.width();
+ int aDelta = aTrsfWidth % 4;
+ if ( aDelta > 0 )
+ aTrsfWidth += ( 4 - aDelta );
+
+ anImage = anImage.scaledToWidth( aTrsfWidth );
+
+ aPix = HYDROGUI_Tool::Pixmap( anImage );
+ }
}
- }
- return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+ return aPix;
}
-Handle_AIS_InteractiveObject HYDROGUI_ShapeImage::createShape() const
+QPolygonF HYDROGUI_ShapeImage::imageContour( const Handle_HYDROData_Image& theImageObj ) const
{
- QString aTextureFileName = getTextureFileName();
- bool anIsTexture = !aTextureFileName.isEmpty();
- if ( anIsTexture )
- {
- Handle_AIS_TexturedShape aTexturedShape = new AIS_TexturedShape( getTopoShape() );
-
- aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
- aTexturedShape->SetTextureMapOn();
- // Just use the texture image as is
- aTexturedShape->DisableTextureModulate();
- aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
-
- return aTexturedShape;
- }
- else
- return Handle_AIS_InteractiveObject();
+ QPolygonF aContour;
+ if ( !theImageObj.IsNull() )
+ {
+ QTransform aTrsf = theImageObj->Trsf();
+ QImage anImage = theImageObj->Image();
+
+ QPolygonF aPolygon = QPolygonF() << QPointF( 0, 0 ) << QPointF( anImage.width(), 0 )
+ << QPointF( anImage.width(), anImage.height() ) << QPointF( 0, anImage.height() );
+ aPolygon = aTrsf.map( aPolygon );
+
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( theImageObj->Label() );
+ for ( QPolygonF::iterator it = aPolygon.begin(); it != aPolygon.end(); ++it )
+ {
+ gp_Pnt aPnt( (*it).x(), (*it).y(), 0 );
+ aDoc->Transform( aPnt, true );
+ aContour.append( QPointF( aPnt.X(), aPnt.Y() ) );
+ }
+ }
+ return aContour;
}
-
#include <HYDROGUI_Shape.h>
+#include <QPolygonF>
+
class Handle_HYDROData_Image;
-class QImage;
class HYDROGUI_ShapeImage : public HYDROGUI_Shape
{
const int theZLayer = -1 );
virtual ~HYDROGUI_ShapeImage();
- virtual void setTextureFileName( const QString& theFileName,
- const bool theToDisplay = true,
- const bool theIsUpdateViewer = true );
- virtual QString getTextureFileName() const;
-
- virtual void update( bool isUpdateViewer,
- bool isDeactivateSelection );
+ virtual void update( bool isUpdateViewer, bool isDeactivateSelection );
protected:
virtual Handle_AIS_InteractiveObject createShape() const;
-
-private:
- static QString generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj );
- void removeTextureFile() const;
-
- static QImage reduceTexture( const QImage& theImage, const int theSizeLimit );
-
-private:
- QString myTextureFileName;
+ Handle(Image_PixMap) imagePixMap( const Handle_HYDROData_Image& ) const;
+ QPolygonF imageContour( const Handle_HYDROData_Image& ) const;
};
#endif
return QString::number( theNumber, 'f', 2 );
}
+Handle(Image_PixMap) HYDROGUI_Tool::Pixmap( const QImage& theImage )
+{
+ Handle(Image_PixMap) pix;
+ if ( theImage.isNull() || theImage.format() == QImage::Format_Invalid )
+ return pix;
+
+ Handle(Image_PixMap) tmpPix = new Image_PixMap();
+ tmpPix->SetTopDown( false );
+ QImage anImage = theImage.mirrored();
+ if ( !anImage.hasAlphaChannel() && anImage.allGray() )
+ {
+ tmpPix->InitTrash( Image_PixMap::ImgGray, anImage.width(), anImage.height(), anImage.width() );
+ for ( int r = 0; r < anImage.height(); r++ )
+ {
+ Standard_Byte* aRowData = tmpPix->ChangeRow( anImage.height() - r - 1 );
+ for ( int p = 0; p < anImage.width(); p++ )
+ aRowData[p] = qRed( anImage.pixel( p, r ) );
+ }
+ }
+ else
+ {
+ Image_PixMap::ImgFormat aFormat;
+ if ( anImage.hasAlphaChannel() )
+ {
+ if ( anImage.format() != QImage::Format_ARGB32 )
+ anImage = anImage.convertToFormat( QImage::Format_ARGB32 );
+ aFormat = Image_PixMap::ImgRGBA;
+ }
+ else
+ {
+ if ( anImage.format() != QImage::Format_RGB888 )
+ anImage = anImage.convertToFormat( QImage::Format_RGB888 );
+ aFormat = Image_PixMap::ImgRGB;
+ }
+
+ tmpPix->InitWrapper( aFormat, (Standard_Byte*)anImage.bits(), anImage.width(), anImage.height(), anImage.bytesPerLine() );
+ }
+
+ if ( !tmpPix.IsNull() )
+ {
+ pix = new Image_PixMap();
+ pix->InitCopy( *tmpPix.operator->() );
+ pix->SetTopDown( tmpPix->IsTopDown() );
+ }
+
+ return pix;
+}
#include <TCollection_HAsciiString.hxx>
#include <TCollection_HExtendedString.hxx>
+#include <Image_PixMap.hxx>
+
// IDL includes
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(GEOM_Gen)
* \return coordinate as a string
*/
static QString GetCoordinateString( const double theNumber, bool isInLocale );
+
+ /**
+ * \brief Converts Qt QImage object to OCCT Image_PixMap object.
+ * \param theImage QImage object
+ * \return Image_PixMap object
+ */
+ static Handle(Image_PixMap) Pixmap( const QImage& theImage );
};
#endif