From c03ec28a438b3499223cd60f614db21c253ef2b3 Mon Sep 17 00:00:00 2001 From: rkv Date: Thu, 28 Nov 2013 10:28:12 +0000 Subject: [PATCH] Fix for the bug #124: Split is shown wrong in OCC 3D viewer --- src/HYDROGUI/HYDROGUI_DataModel.cxx | 181 ++++++++++++++-------------- src/HYDROGUI/HYDROGUI_Shape.cxx | 23 +++- 2 files changed, 110 insertions(+), 94 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index f3440a44..675d2f48 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -262,116 +262,119 @@ void HYDROGUI_DataModel::update( const int theStudyId ) for( ; anIterator.More(); anIterator.Next() ) { Handle(HYDROData_Entity) anObj = anIterator.Current(); - switch ( anObj->GetKind() ) { - case KIND_IMAGE: - { - Handle(HYDROData_Image) anImageObj = - Handle(HYDROData_Image)::DownCast( anObj ); - if( !anImageObj.IsNull() ) { - createObject( anImageRootObj, anImageObj ); - } + if ( !anObj.IsNull() ) + { + switch ( anObj->GetKind() ) { + case KIND_IMAGE: + { + Handle(HYDROData_Image) anImageObj = + Handle(HYDROData_Image)::DownCast( anObj ); + if( !anImageObj.IsNull() ) { + createObject( anImageRootObj, anImageObj ); + } - break; - } - case KIND_BATHYMETRY: - { - Handle(HYDROData_Bathymetry) aBathymetryObj = - Handle(HYDROData_Bathymetry)::DownCast( anObj ); - if( !aBathymetryObj.IsNull() ) { - createObject( aBathymetryRootObj, aBathymetryObj ); + break; } + case KIND_BATHYMETRY: + { + Handle(HYDROData_Bathymetry) aBathymetryObj = + Handle(HYDROData_Bathymetry)::DownCast( anObj ); + if( !aBathymetryObj.IsNull() ) { + createObject( aBathymetryRootObj, aBathymetryObj ); + } - break; - } - case KIND_CHANNEL: - { - Handle(HYDROData_Channel) aChannelObj = - Handle(HYDROData_Channel)::DownCast( anObj ); - if( !aChannelObj.IsNull() ) { - createObject( anArtificialObjectsRootObj, aChannelObj ); + break; } + case KIND_CHANNEL: + { + Handle(HYDROData_Channel) aChannelObj = + Handle(HYDROData_Channel)::DownCast( anObj ); + if( !aChannelObj.IsNull() ) { + createObject( anArtificialObjectsRootObj, aChannelObj ); + } - break; - } - case KIND_DIGUE: - { - Handle(HYDROData_Digue) aDigueObj = - Handle(HYDROData_Digue)::DownCast( anObj ); - if( !aDigueObj.IsNull() ) { - createObject( anArtificialObjectsRootObj, aDigueObj ); + break; } + case KIND_DIGUE: + { + Handle(HYDROData_Digue) aDigueObj = + Handle(HYDROData_Digue)::DownCast( anObj ); + if( !aDigueObj.IsNull() ) { + createObject( anArtificialObjectsRootObj, aDigueObj ); + } - break; - } - case KIND_IMMERSIBLE_ZONE: - { - Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj = - Handle(HYDROData_ImmersibleZone)::DownCast( anObj ); - if( !anImmersibleZoneObj.IsNull() ) { - createObject( aNaturalObjectsRootObj, anImmersibleZoneObj ); + break; } + case KIND_IMMERSIBLE_ZONE: + { + Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj = + Handle(HYDROData_ImmersibleZone)::DownCast( anObj ); + if( !anImmersibleZoneObj.IsNull() ) { + createObject( aNaturalObjectsRootObj, anImmersibleZoneObj ); + } - break; - } - case KIND_RIVER: - { - Handle(HYDROData_River) aRiverObj = - Handle(HYDROData_River)::DownCast( anObj ); - if( !aRiverObj.IsNull() ) { - createObject( aNaturalObjectsRootObj, aRiverObj ); + break; } + case KIND_RIVER: + { + Handle(HYDROData_River) aRiverObj = + Handle(HYDROData_River)::DownCast( anObj ); + if( !aRiverObj.IsNull() ) { + createObject( aNaturalObjectsRootObj, aRiverObj ); + } - break; - } - case KIND_OBSTACLE: - { - Handle(HYDROData_Obstacle) anObstacleObj = - Handle(HYDROData_Obstacle)::DownCast( anObj ); - if( !anObstacleObj.IsNull() ) { - createObject( anObstaclesRootObj, anObstacleObj ); + break; } + case KIND_OBSTACLE: + { + Handle(HYDROData_Obstacle) anObstacleObj = + Handle(HYDROData_Obstacle)::DownCast( anObj ); + if( !anObstacleObj.IsNull() ) { + createObject( anObstaclesRootObj, anObstacleObj ); + } - break; - } - case KIND_CALCULATION: - { - Handle(HYDROData_CalculationCase) aCalculObj = - Handle(HYDROData_CalculationCase)::DownCast( anObj ); - if( !aCalculObj.IsNull() ) { - createObject( aCalculRootObj, aCalculObj ); + break; } + case KIND_CALCULATION: + { + Handle(HYDROData_CalculationCase) aCalculObj = + Handle(HYDROData_CalculationCase)::DownCast( anObj ); + if( !aCalculObj.IsNull() ) { + createObject( aCalculRootObj, aCalculObj ); + } - break; - } - case KIND_POLYLINEXY: - { - Handle(HYDROData_PolylineXY) aPolylineObj = - Handle(HYDROData_PolylineXY)::DownCast( anObj ); - if( !aPolylineObj.IsNull() ) { - createObject( aPolylineRootObj, aPolylineObj ); + break; } + case KIND_POLYLINEXY: + { + Handle(HYDROData_PolylineXY) aPolylineObj = + Handle(HYDROData_PolylineXY)::DownCast( anObj ); + if( !aPolylineObj.IsNull() ) { + createObject( aPolylineRootObj, aPolylineObj ); + } - break; - } - case KIND_PROFILE: - { - Handle(HYDROData_Profile) aProfileObj = - Handle(HYDROData_Profile)::DownCast( anObj ); - if( !aProfileObj.IsNull() ) { - createObject( aProfileRootObj, aProfileObj ); + break; } + case KIND_PROFILE: + { + Handle(HYDROData_Profile) aProfileObj = + Handle(HYDROData_Profile)::DownCast( anObj ); + if( !aProfileObj.IsNull() ) { + createObject( aProfileRootObj, aProfileObj ); + } - break; - } - case KIND_VISUAL_STATE: - { - Handle(HYDROData_VisualState) aVisualStateObj = - Handle(HYDROData_VisualState)::DownCast( anObj ); - if( !aVisualStateObj.IsNull() ) { - createObject( aVisualStateRootObj, aVisualStateObj ); + break; } + case KIND_VISUAL_STATE: + { + Handle(HYDROData_VisualState) aVisualStateObj = + Handle(HYDROData_VisualState)::DownCast( anObj ); + if( !aVisualStateObj.IsNull() ) { + createObject( aVisualStateRootObj, aVisualStateObj ); + } - break; + break; + } } } } diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 5c4aa75a..799c09f2 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -217,8 +217,18 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) QTransform anInversion = QTransform::fromScale( -1, -1 ); anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation ); + // 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 = reduceTexture( anImage, 500 ); + QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 ); + bool isSaved = anImageToSave.save( aTextureFileName ); if ( !isSaved ) { QString aTitle = QObject::tr( "FILE_ERROR" ); @@ -226,10 +236,10 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) SUIT_MessageBox::warning( 0, aTitle, aMessage ); } - QPointF aPoint1( 0, 0 ); - QPointF aPoint2( aWidth, 0 ); - QPointF aPoint3( aWidth, aHeight ); - QPointF aPoint4( 0, aHeight ); + 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 ); @@ -250,6 +260,7 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) 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 ); @@ -477,7 +488,9 @@ void HYDROGUI_Shape::buildShape() 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 } // Init default params for shape -- 2.39.2