1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Shape.h"
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Tool.h"
28 #include <AIS_Drawer.hxx>
29 #include <AIS_TexturedShape.hxx>
31 #include <V3d_Viewer.hxx>
33 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <BRepBuilderAPI_MakeWire.hxx>
35 #include <BRepBuilderAPI_MakeFace.hxx>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <Graphic3d_MaterialAspect.hxx>
42 #include <HYDROData_Channel.h>
43 #include <HYDROData_Document.h>
44 #include <HYDROData_DummyObject3D.h>
45 #include <HYDROData_Image.h>
46 #include <HYDROData_ImmersibleZone.h>
47 #include <HYDROData_Obstacle.h>
48 #include <HYDROData_PolylineXY.h>
49 #include <HYDROData_Polyline3D.h>
50 #include <HYDROData_Profile.h>
51 #include <HYDROData_Region.h>
52 #include <HYDROData_ShapesGroup.h>
53 #include <HYDROData_Stream.h>
54 #include <HYDROData_Zone.h>
57 #include <TopoDS_Wire.hxx>
58 #include <TopoDS_Face.hxx>
60 #include <TopExp_Explorer.hxx>
62 #include <BRep_Builder.hxx>
64 #include <Precision.hxx>
66 #include <Prs3d_ShadingAspect.hxx>
67 #include <Prs3d_LineAspect.hxx>
68 #include <Prs3d_IsoAspect.hxx>
70 #include <SUIT_MessageBox.h>
75 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
76 const Handle(HYDROData_Entity)& theObject )
77 : myContext( theContext ),
78 myObject( theObject ),
79 myIsHighlight( false ),
80 myFillingColor( Qt::transparent ),
81 myBorderColor( Qt::black ),
82 myHighlightColor( Qt::white ),
83 myIsToUpdate( false ),
85 myDisplayMode( AIS_WireFrame )
89 HYDROGUI_Shape::~HYDROGUI_Shape()
93 if ( !myShape.IsNull() )
99 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
101 if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
104 myContext->Display( myShape, theIsUpdateViewer );
107 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
109 if ( myContext.IsNull() || myShape.IsNull() )
112 myContext->Erase( myShape, theIsUpdateViewer );
115 void HYDROGUI_Shape::update( const bool theIsUpdateViewer,
116 const bool theIsDisplayOnTop )
118 setIsToUpdate( false );
120 if ( myContext.IsNull() )
123 bool isDeactivateSelection = false;
124 // Try to retrieve information from object
125 if ( !myObject.IsNull() )
127 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
129 if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
131 Handle(HYDROData_ImmersibleZone) aZoneObj =
132 Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
134 TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
135 if ( !aZoneShape.IsNull() ) {
136 if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
137 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
138 setFace( aZoneFace, false, false );
140 myTopoShape = aZoneShape;
141 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
144 updateShape( false, false );
148 QColor aFillingColor = aZoneObj->GetFillingColor();
149 QColor aBorderColor = aZoneObj->GetBorderColor();
151 setFillingColor( aFillingColor, false, false );
152 setBorderColor( aBorderColor, false, false );
154 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
156 Handle(HYDROData_PolylineXY) aPolyline =
157 Handle(HYDROData_PolylineXY)::DownCast( myObject );
159 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
161 if ( !aPolylineShape.IsNull() ) {
162 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
163 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
164 setWire( aPolylineWire, false, false );
166 myTopoShape = aPolylineShape;
167 myDisplayMode = AIS_WireFrame;
170 updateShape( false, false );
174 QColor aWireColor = aPolyline->GetWireColor();
175 setBorderColor( aWireColor, false, false );
177 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
179 Handle(HYDROData_Polyline3D) aPolyline =
180 Handle(HYDROData_Polyline3D)::DownCast( myObject );
182 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
184 if ( !aPolylineShape.IsNull() ) {
185 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
186 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
187 setWire( aPolylineWire, false, false );
189 myTopoShape = aPolylineShape;
190 myDisplayMode = AIS_WireFrame;
193 updateShape( false, false );
197 QColor aWireColor = aPolyline->GetBorderColor();
198 setBorderColor( aWireColor, false, false );
200 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
202 Handle(HYDROData_Zone) aZone =
203 Handle(HYDROData_Zone)::DownCast( myObject );
205 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
207 setFace( aZoneFace, false, false );
208 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
210 // Red color for a zone with bathymetry conflict
211 setFillingColor( Qt::red );
215 // Generate the filling color for zone
216 QStringList aGeomObjectsNames;
218 HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
219 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
220 for ( ; anIter.More(); anIter.Next() )
222 Handle(HYDROData_Object) aRefbject =
223 Handle(HYDROData_Object)::DownCast( anIter.Value() );
224 if ( aRefbject.IsNull() )
227 QString aRefObjectName = aRefbject->GetName();
228 if ( aRefObjectName.isEmpty() )
231 aGeomObjectsNames.append( aRefObjectName );
234 setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
237 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
239 Handle(HYDROData_Image) anImageObj =
240 Handle(HYDROData_Image)::DownCast( myObject );
244 QString aTextureFileName = generateTextureFileName( anImageObj );
246 QImage anImage = anImageObj->Image();
247 QString aFilePath = anImageObj->GetFilePath();
248 QTransform aTrsf = anImageObj->Trsf();
250 int aWidth = anImage.width();
251 int aHeight = anImage.height();
253 QString anImageError = "";
255 QTransform anInversion = QTransform::fromScale( -1, -1 );
256 anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
258 if ( anImage.isNull() )
259 anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" );
262 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
263 int aTrsfWidth = anImage.width();
264 int aDelta = aTrsfWidth % 4;
267 aTrsfWidth += ( 4 - aDelta );
269 anImage = anImage.scaledToWidth( aTrsfWidth );
271 // temporary optimization, to reduce the saved image size (and the texture quality)
272 QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
274 bool isSaved = anImageToSave.save( aTextureFileName );
276 anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
279 if ( !anImageError.isEmpty() )
281 SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ),
282 QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError );
285 QPointF aPoint1( 0, 0 ); // 1: top left
286 QPointF aPoint2( aWidth, 0 ); // 2: top right
287 QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
288 QPointF aPoint4( 0, aHeight ); // 4: bottom left
290 aPoint1 = aTrsf.map( aPoint1 );
291 aPoint2 = aTrsf.map( aPoint2 );
292 aPoint3 = aTrsf.map( aPoint3 );
293 aPoint4 = aTrsf.map( aPoint4 );
295 QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
296 QRectF aRect = aPolygon.boundingRect();
298 gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
299 gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
300 gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
301 gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
303 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
304 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
305 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
306 TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
308 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
309 aWire.Closed( true );
311 setTextureFileName( aTextureFileName, false, false );
312 setFace( aWire, false, false );
313 isDeactivateSelection = true;
315 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
317 Handle(HYDROData_Profile) aProfile =
318 Handle(HYDROData_Profile)::DownCast( myObject );
320 TopoDS_Wire aProfileWire;
322 if ( aProfile->IsValid() ) {
323 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
325 if ( !aProfileShape.IsNull() &&
326 aProfileShape.ShapeType() == TopAbs_WIRE ) {
327 aProfileWire = TopoDS::Wire( aProfileShape );
331 setWire( aProfileWire, false, false );
333 QColor aWireColor = aProfile->GetBorderColor();
334 setBorderColor( aWireColor, false, false );
336 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
337 myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
338 myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
340 Handle(HYDROData_Object) aGeomObject =
341 Handle(HYDROData_Object)::DownCast( myObject );
343 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
345 setShape( anObjShape, false, false );
347 QColor aFillingColor = aGeomObject->GetFillingColor();
348 QColor aBorderColor = aGeomObject->GetBorderColor();
350 setFillingColor( aFillingColor, false, false );
351 setBorderColor( aBorderColor, false, false );
353 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
355 Handle(HYDROData_DummyObject3D) anObject3D =
356 Handle(HYDROData_DummyObject3D)::DownCast( myObject );
357 TopoDS_Shape aShape3D = anObject3D->GetShape();
359 setShape( aShape3D, false, false );
361 QColor aFillingColor = anObject3D->GetFillingColor();
362 QColor aBorderColor = anObject3D->GetBorderColor();
364 setFillingColor( aFillingColor, false, false );
365 setBorderColor( aBorderColor, false, false );
367 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ShapesGroup) ) )
369 Handle(HYDROData_ShapesGroup) aShapesGroup =
370 Handle(HYDROData_ShapesGroup)::DownCast( myObject );
372 TopTools_SequenceOfShape aShapes;
373 aShapesGroup->GetShapes( aShapes );
375 TopoDS_Compound aCompound;
376 BRep_Builder aCompoundBuilder;
377 aCompoundBuilder.MakeCompound( aCompound );
379 for ( int i = 1, n = aShapes.Length(); i <= n; ++i )
381 const TopoDS_Shape& aShape = aShapes.Value( i );
382 aCompoundBuilder.Add( aCompound, aShape );
385 setShape( aCompound, false, false );
389 if ( myShape.IsNull() || !isVisible() )
392 myContext->Display( myShape, theIsUpdateViewer );
394 if ( theIsDisplayOnTop ) {
395 // Display the shape on the top Z layer
396 Standard_Integer aNewLayerId = -1;
397 if ( myContext->CurrentViewer() &&
398 myContext->CurrentViewer()->AddZLayer( aNewLayerId ) &&
400 myContext->SetZLayer( myShape, aNewLayerId );
404 if (isDeactivateSelection)
405 myContext->Deactivate(myShape);
408 void HYDROGUI_Shape::setVisible( const bool theState,
409 const bool theIsUpdateViewer )
411 if ( myIsVisible == theState )
414 myIsVisible = theState;
416 if ( myShape.IsNull() )
420 myContext->Display( myShape, theIsUpdateViewer );
422 myContext->Erase( myShape, theIsUpdateViewer );
425 void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
427 if ( myIsHighlight == theIsHighlight )
430 myIsHighlight = theIsHighlight;
432 if ( myContext.IsNull() || myShape.IsNull() )
435 colorShapeBorder( getActiveColor() );
436 myContext->Display( myShape, isUpdateViewer );
439 bool HYDROGUI_Shape::isHighlighted() const
441 return myIsHighlight;
444 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
445 const bool theToDisplay,
446 const bool theIsUpdateViewer )
448 myTopoShape = theWire;
449 myDisplayMode = AIS_WireFrame;
452 updateShape( theToDisplay, theIsUpdateViewer );
455 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
456 const bool theToDisplay,
457 const bool theIsUpdateViewer )
459 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
460 TopoDS_Compound aCompound;
461 BRep_Builder aBuilder;
462 aBuilder.MakeCompound( aCompound );
464 for ( ; anExp.More(); anExp.Next() ) {
465 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
466 if ( aWire.IsNull() ) {
470 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
472 if( aMakeFace.IsDone() ) {
473 aBuilder.Add( aCompound, aMakeFace.Face() );
477 myTopoShape = aCompound;
478 myDisplayMode = AIS_Shaded;
481 updateShape( theToDisplay, theIsUpdateViewer );
484 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
485 const bool theToDisplay,
486 const bool theIsUpdateViewer )
488 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
489 aFaceBuilder.Build();
490 if( aFaceBuilder.IsDone() )
492 TopoDS_Face aFace = aFaceBuilder.Face();
493 setFace( aFace, theToDisplay, theIsUpdateViewer );
497 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
498 const bool theToDisplay,
499 const bool theIsUpdateViewer )
501 myTopoShape = theFace;
502 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
503 //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
504 //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
507 updateShape( theToDisplay, theIsUpdateViewer );
510 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
511 const bool theToDisplay,
512 const bool theIsUpdateViewer )
514 myTopoShape = theShape;
515 myDisplayMode = AIS_Shaded;
518 updateShape( theToDisplay, theIsUpdateViewer );
521 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
522 const bool theToDisplay,
523 const bool theIsUpdateViewer )
525 myFillingColor = theColor;
526 updateShape( theToDisplay, theIsUpdateViewer );
529 QColor HYDROGUI_Shape::getFillingColor() const
531 return myFillingColor;
534 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
535 const bool theToDisplay,
536 const bool theIsUpdateViewer )
538 myBorderColor = theColor;
539 updateShape( theToDisplay, theIsUpdateViewer );
542 QColor HYDROGUI_Shape::getBorderColor() const
544 return myBorderColor;
547 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
549 myHighlightColor = theColor;
552 QColor HYDROGUI_Shape::getHighlightColor() const
554 return myHighlightColor;
557 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
558 const bool theToDisplay,
559 const bool theIsUpdateViewer )
561 myTextureFileName = theFileName;
562 updateShape( theToDisplay, theIsUpdateViewer );
565 QString HYDROGUI_Shape::getTextureFileName() const
567 return myTextureFileName;
570 void HYDROGUI_Shape::buildShape()
572 // Erase previously created shape
575 if ( myTopoShape.IsNull() ) {
580 QString aTextureFileName = getTextureFileName();
581 bool anIsTexture = !aTextureFileName.isEmpty();
585 myShape = new AIS_TexturedShape( myTopoShape );
589 myShape = new AIS_Shape( myTopoShape );
592 myShape->SetHLRAngleAndDeviation( 0.001 );
594 if ( !myObject.IsNull() )
595 myShape->SetOwner( myObject );
597 myShape->SetTransparency( 0 );
598 myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
602 Handle(AIS_TexturedShape) aTexturedShape =
603 Handle(AIS_TexturedShape)::DownCast( myShape );
605 aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
606 aTexturedShape->SetTextureMapOn();
607 // Just use the texture image as is
608 aTexturedShape->DisableTextureModulate();
609 aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
612 // Init default params for shape
613 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
614 if ( !anAttributes.IsNull() )
616 Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
617 if ( !anIsoAspect.IsNull() ) {
618 anIsoAspect->SetNumber( 0 );
619 anAttributes->SetUIsoAspect( anIsoAspect );
622 anIsoAspect = anAttributes->VIsoAspect();
623 if ( !anIsoAspect.IsNull() ) {
624 anIsoAspect->SetNumber( 0 );
625 anAttributes->SetVIsoAspect( anIsoAspect );
628 if ( myDisplayMode == AIS_Shaded )
630 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
631 if ( !aShadingAspect.IsNull() )
633 Graphic3d_MaterialAspect aMatAspect( Graphic3d_NOM_PLASTIC );
634 //aMatAspect.SetAmbient( 1 );
635 //aMatAspect.SetDiffuse( 0 );
637 aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
638 aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
641 else if ( myDisplayMode == AIS_WireFrame )
643 anAttributes->SetWireDraw( true );
648 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
649 const bool theIsUpdateViewer )
651 if ( myShape.IsNull() )
654 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
655 if ( !anAttributes.IsNull() )
657 if ( myDisplayMode == AIS_Shaded )
659 // Coloring face filling
660 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
661 if ( !aShadingAspect.IsNull() )
663 Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ),
664 getQuantityColorVal( myFillingColor.green() ),
665 getQuantityColorVal( myFillingColor.blue() ),
668 aShadingAspect->SetColor( aFillingColor );
669 aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
672 else if ( myDisplayMode == AIS_WireFrame )
677 colorShapeBorder( getActiveColor() );
680 if ( !theToDisplay || !isVisible() || myContext.IsNull() )
683 myContext->Display( myShape, theIsUpdateViewer );
686 QColor HYDROGUI_Shape::getActiveColor() const
688 return isHighlighted() ? myHighlightColor : myBorderColor;
691 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
693 return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
696 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
698 if ( myShape.IsNull() )
701 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
702 if ( anAttributes.IsNull() )
705 Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ),
706 getQuantityColorVal( theColor.green() ),
707 getQuantityColorVal( theColor.blue() ),
709 if ( myDisplayMode == AIS_Shaded )
711 if ( theColor.alpha() == 0 )
713 anAttributes->SetFaceBoundaryDraw( false );
717 anAttributes->SetFaceBoundaryDraw( true );
719 Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
720 if ( !aBoundaryAspect.IsNull() )
722 aBoundaryAspect->SetColor( aBorderColor );
723 anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
727 else if ( myDisplayMode == AIS_WireFrame )
729 myShape->SetColor( aBorderColor );
733 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
736 if( !theImageObj.IsNull() )
738 QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
740 int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
741 QString aPrefix = QString( "image_%1" ).arg( aStudyId );
743 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
744 anEntry.replace( ':', '_' );
746 QString anExtension = "bmp";
748 aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
753 void HYDROGUI_Shape::removeTextureFile() const
755 QFile aFile( getTextureFileName() );
760 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
762 double aSizeLimit = (double)theSizeLimit;
763 double aWidth = (double)theImage.width();
764 double aHeight = (double)theImage.height();
765 if( aWidth > aSizeLimit || aHeight > aSizeLimit )
767 if( aWidth > aHeight )
769 aHeight /= ( aWidth / aSizeLimit );
774 aWidth /= ( aHeight / aSizeLimit );
775 aHeight = aSizeLimit;
778 return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );