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,
78 : myContext( theContext ),
79 myObject( theObject ),
80 myZLayer( theZLayer ),
81 myIsHighlight( false ),
82 myFillingColor( Qt::transparent ),
83 myBorderColor( Qt::black ),
84 myHighlightColor( Qt::white ),
85 myIsToUpdate( false ),
87 myDisplayMode( AIS_WireFrame )
91 HYDROGUI_Shape::~HYDROGUI_Shape()
95 if ( !myShape.IsNull() )
101 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
103 if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
106 displayShape( theIsUpdateViewer );
109 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
111 if ( myContext.IsNull() || myShape.IsNull() )
114 myContext->Erase( myShape, theIsUpdateViewer );
117 void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
119 setIsToUpdate( false );
121 if ( myContext.IsNull() )
124 bool isDeactivateSelection = false;
125 // Try to retrieve information from object
126 if ( !myObject.IsNull() )
128 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
130 if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
132 Handle(HYDROData_ImmersibleZone) aZoneObj =
133 Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
135 TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
136 if ( !aZoneShape.IsNull() ) {
137 if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
138 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
139 setFace( aZoneFace, false, false );
141 myTopoShape = aZoneShape;
142 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
145 updateShape( false, false );
149 QColor aFillingColor = aZoneObj->GetFillingColor();
150 QColor aBorderColor = aZoneObj->GetBorderColor();
152 setFillingColor( aFillingColor, false, false );
153 setBorderColor( aBorderColor, false, false );
155 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
157 Handle(HYDROData_PolylineXY) aPolyline =
158 Handle(HYDROData_PolylineXY)::DownCast( myObject );
160 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
162 if ( !aPolylineShape.IsNull() ) {
163 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
164 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
165 setWire( aPolylineWire, false, false );
167 myTopoShape = aPolylineShape;
168 myDisplayMode = AIS_WireFrame;
171 updateShape( false, false );
175 QColor aWireColor = aPolyline->GetWireColor();
176 setBorderColor( aWireColor, false, false );
178 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
180 Handle(HYDROData_Polyline3D) aPolyline =
181 Handle(HYDROData_Polyline3D)::DownCast( myObject );
183 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
185 if ( !aPolylineShape.IsNull() ) {
186 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
187 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
188 setWire( aPolylineWire, false, false );
190 myTopoShape = aPolylineShape;
191 myDisplayMode = AIS_WireFrame;
194 updateShape( false, false );
198 QColor aWireColor = aPolyline->GetBorderColor();
199 setBorderColor( aWireColor, false, false );
201 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
203 Handle(HYDROData_Zone) aZone =
204 Handle(HYDROData_Zone)::DownCast( myObject );
206 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
208 setFace( aZoneFace, false, false );
209 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
211 // Red color for a zone with bathymetry conflict
212 setFillingColor( Qt::red );
216 // Generate the filling color for zone
217 QStringList aGeomObjectsNames;
219 HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
220 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
221 for ( ; anIter.More(); anIter.Next() )
223 Handle(HYDROData_Object) aRefbject =
224 Handle(HYDROData_Object)::DownCast( anIter.Value() );
225 if ( aRefbject.IsNull() )
228 QString aRefObjectName = aRefbject->GetName();
229 if ( aRefObjectName.isEmpty() )
232 aGeomObjectsNames.append( aRefObjectName );
235 setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
238 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
240 Handle(HYDROData_Image) anImageObj =
241 Handle(HYDROData_Image)::DownCast( myObject );
245 QString aTextureFileName = generateTextureFileName( anImageObj );
247 QImage anImage = anImageObj->Image();
248 QString aFilePath = anImageObj->GetFilePath();
249 QTransform aTrsf = anImageObj->Trsf();
251 int aWidth = anImage.width();
252 int aHeight = anImage.height();
254 QString anImageError = "";
256 QTransform anInversion = QTransform::fromScale( -1, -1 );
257 anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
259 if ( anImage.isNull() )
260 anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" );
263 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
264 int aTrsfWidth = anImage.width();
265 int aDelta = aTrsfWidth % 4;
268 aTrsfWidth += ( 4 - aDelta );
270 anImage = anImage.scaledToWidth( aTrsfWidth );
272 // temporary optimization, to reduce the saved image size (and the texture quality)
273 QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
275 bool isSaved = anImageToSave.save( aTextureFileName );
277 anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
279 QFile::setPermissions( aTextureFileName, (QFile::Permissions)0x4FFFF );
282 if ( !anImageError.isEmpty() )
284 SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ),
285 QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError );
288 QPointF aPoint1( 0, 0 ); // 1: top left
289 QPointF aPoint2( aWidth, 0 ); // 2: top right
290 QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
291 QPointF aPoint4( 0, aHeight ); // 4: bottom left
293 aPoint1 = aTrsf.map( aPoint1 );
294 aPoint2 = aTrsf.map( aPoint2 );
295 aPoint3 = aTrsf.map( aPoint3 );
296 aPoint4 = aTrsf.map( aPoint4 );
298 QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
299 QRectF aRect = aPolygon.boundingRect();
301 gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
302 gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
303 gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
304 gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
306 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
307 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
308 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
309 TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
311 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
312 aWire.Closed( true );
314 setTextureFileName( aTextureFileName, false, false );
315 setFace( aWire, false, false );
316 isDeactivateSelection = true;
318 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
320 Handle(HYDROData_Profile) aProfile =
321 Handle(HYDROData_Profile)::DownCast( myObject );
323 TopoDS_Wire aProfileWire;
325 if ( aProfile->IsValid() ) {
326 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
328 if ( !aProfileShape.IsNull() &&
329 aProfileShape.ShapeType() == TopAbs_WIRE ) {
330 aProfileWire = TopoDS::Wire( aProfileShape );
334 setWire( aProfileWire, false, false );
336 QColor aWireColor = aProfile->GetBorderColor();
337 setBorderColor( aWireColor, false, false );
339 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
340 myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
341 myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
343 Handle(HYDROData_Object) aGeomObject =
344 Handle(HYDROData_Object)::DownCast( myObject );
346 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
348 setShape( anObjShape, false, false );
350 QColor aFillingColor = aGeomObject->GetFillingColor();
351 QColor aBorderColor = aGeomObject->GetBorderColor();
353 setFillingColor( aFillingColor, false, false );
354 setBorderColor( aBorderColor, false, false );
356 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
358 Handle(HYDROData_DummyObject3D) anObject3D =
359 Handle(HYDROData_DummyObject3D)::DownCast( myObject );
360 TopoDS_Shape aShape3D = anObject3D->GetShape();
362 setShape( aShape3D, false, false );
364 QColor aFillingColor = anObject3D->GetFillingColor();
365 QColor aBorderColor = anObject3D->GetBorderColor();
367 setFillingColor( aFillingColor, false, false );
368 setBorderColor( aBorderColor, false, false );
370 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ShapesGroup) ) )
372 Handle(HYDROData_ShapesGroup) aShapesGroup =
373 Handle(HYDROData_ShapesGroup)::DownCast( myObject );
375 TopTools_SequenceOfShape aShapes;
376 aShapesGroup->GetShapes( aShapes );
378 TopoDS_Compound aCompound;
379 BRep_Builder aCompoundBuilder;
380 aCompoundBuilder.MakeCompound( aCompound );
382 for ( int i = 1, n = aShapes.Length(); i <= n; ++i )
384 const TopoDS_Shape& aShape = aShapes.Value( i );
385 aCompoundBuilder.Add( aCompound, aShape );
388 setShape( aCompound, false, false );
392 if ( myShape.IsNull() || !isVisible() )
395 displayShape( theIsUpdateViewer );
397 if (isDeactivateSelection)
398 myContext->Deactivate(myShape);
401 void HYDROGUI_Shape::setVisible( const bool theState,
402 const bool theIsUpdateViewer )
404 myIsVisible = theState;
406 if ( myShape.IsNull() )
409 if ( ( myIsVisible && myContext->IsDisplayed( myShape ) ) ||
410 ( !myIsVisible && !myContext->IsDisplayed( myShape ) ) )
414 displayShape( theIsUpdateViewer );
417 myContext->Erase( myShape, theIsUpdateViewer );
420 void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
422 if ( myIsHighlight == theIsHighlight )
425 myIsHighlight = theIsHighlight;
427 if ( myContext.IsNull() || myShape.IsNull() )
430 colorShapeBorder( getActiveColor() );
431 displayShape( isUpdateViewer );
434 bool HYDROGUI_Shape::isHighlighted() const
436 return myIsHighlight;
439 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
440 const bool theToDisplay,
441 const bool theIsUpdateViewer )
443 myTopoShape = theWire;
444 myDisplayMode = AIS_WireFrame;
447 updateShape( theToDisplay, theIsUpdateViewer );
450 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
451 const bool theToDisplay,
452 const bool theIsUpdateViewer )
454 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
455 TopoDS_Compound aCompound;
456 BRep_Builder aBuilder;
457 aBuilder.MakeCompound( aCompound );
459 for ( ; anExp.More(); anExp.Next() ) {
460 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
461 if ( aWire.IsNull() ) {
465 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
467 if( aMakeFace.IsDone() ) {
468 aBuilder.Add( aCompound, aMakeFace.Face() );
472 myTopoShape = aCompound;
473 myDisplayMode = AIS_Shaded;
476 updateShape( theToDisplay, theIsUpdateViewer );
479 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
480 const bool theToDisplay,
481 const bool theIsUpdateViewer )
483 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
484 aFaceBuilder.Build();
485 if( aFaceBuilder.IsDone() )
487 TopoDS_Face aFace = aFaceBuilder.Face();
488 setFace( aFace, theToDisplay, theIsUpdateViewer );
492 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
493 const bool theToDisplay,
494 const bool theIsUpdateViewer )
496 myTopoShape = theFace;
497 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
498 //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
499 //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
502 updateShape( theToDisplay, theIsUpdateViewer );
505 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
506 const bool theToDisplay,
507 const bool theIsUpdateViewer )
509 myTopoShape = theShape;
510 myDisplayMode = AIS_Shaded;
513 updateShape( theToDisplay, theIsUpdateViewer );
516 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
517 const bool theToDisplay,
518 const bool theIsUpdateViewer )
520 myFillingColor = theColor;
521 updateShape( theToDisplay, theIsUpdateViewer );
524 QColor HYDROGUI_Shape::getFillingColor() const
526 return myFillingColor;
529 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
530 const bool theToDisplay,
531 const bool theIsUpdateViewer )
533 myBorderColor = theColor;
534 updateShape( theToDisplay, theIsUpdateViewer );
537 QColor HYDROGUI_Shape::getBorderColor() const
539 return myBorderColor;
542 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
544 myHighlightColor = theColor;
547 QColor HYDROGUI_Shape::getHighlightColor() const
549 return myHighlightColor;
552 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
553 const bool theToDisplay,
554 const bool theIsUpdateViewer )
556 myTextureFileName = theFileName;
557 updateShape( theToDisplay, theIsUpdateViewer );
560 QString HYDROGUI_Shape::getTextureFileName() const
562 return myTextureFileName;
565 void HYDROGUI_Shape::setZLayer( const int theZLayer )
567 if ( myZLayer == theZLayer )
570 myZLayer = theZLayer;
571 if ( !myShape.IsNull() && isVisible() && !myContext.IsNull() && myZLayer >= 0 )
572 myContext->SetZLayer( myShape, myZLayer );
575 void HYDROGUI_Shape::buildShape()
577 // Erase previously created shape
580 if ( myTopoShape.IsNull() ) {
585 QString aTextureFileName = getTextureFileName();
586 bool anIsTexture = !aTextureFileName.isEmpty();
590 myShape = new AIS_TexturedShape( myTopoShape );
594 myShape = new AIS_Shape( myTopoShape );
597 myShape->SetHLRAngleAndDeviation( 0.001 );
599 if ( !myObject.IsNull() )
600 myShape->SetOwner( myObject );
602 myShape->SetTransparency( 0 );
603 myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
607 Handle(AIS_TexturedShape) aTexturedShape =
608 Handle(AIS_TexturedShape)::DownCast( myShape );
610 aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
611 aTexturedShape->SetTextureMapOn();
612 // Just use the texture image as is
613 aTexturedShape->DisableTextureModulate();
614 aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
617 // Init default params for shape
618 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
619 if ( !anAttributes.IsNull() )
621 Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
622 if ( !anIsoAspect.IsNull() ) {
623 anIsoAspect->SetNumber( 0 );
624 anAttributes->SetUIsoAspect( anIsoAspect );
627 anIsoAspect = anAttributes->VIsoAspect();
628 if ( !anIsoAspect.IsNull() ) {
629 anIsoAspect->SetNumber( 0 );
630 anAttributes->SetVIsoAspect( anIsoAspect );
633 if ( myDisplayMode == AIS_Shaded )
635 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
636 if ( !aShadingAspect.IsNull() )
638 Graphic3d_MaterialAspect aMatAspect( Graphic3d_NOM_PLASTIC );
639 //aMatAspect.SetAmbient( 1 );
640 //aMatAspect.SetDiffuse( 0 );
642 aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
643 aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
646 else if ( myDisplayMode == AIS_WireFrame )
648 anAttributes->SetWireDraw( true );
653 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
654 const bool theIsUpdateViewer )
656 if ( myShape.IsNull() )
659 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
660 if ( !anAttributes.IsNull() )
662 if ( myDisplayMode == AIS_Shaded )
664 // Coloring face filling
665 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
666 if ( !aShadingAspect.IsNull() )
668 Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ),
669 getQuantityColorVal( myFillingColor.green() ),
670 getQuantityColorVal( myFillingColor.blue() ),
673 aShadingAspect->SetColor( aFillingColor );
674 aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
677 else if ( myDisplayMode == AIS_WireFrame )
682 colorShapeBorder( getActiveColor() );
685 if ( !theToDisplay || !isVisible() || myContext.IsNull() )
688 displayShape( theIsUpdateViewer );
691 void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
693 myContext->Display( myShape, Standard_False );
696 myContext->SetZLayer( myShape, myZLayer );
698 myContext->UpdateCurrentViewer();
701 QColor HYDROGUI_Shape::getActiveColor() const
703 return isHighlighted() ? myHighlightColor : myBorderColor;
706 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
708 return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
711 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
713 if ( myShape.IsNull() )
716 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
717 if ( anAttributes.IsNull() )
720 Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ),
721 getQuantityColorVal( theColor.green() ),
722 getQuantityColorVal( theColor.blue() ),
724 if ( myDisplayMode == AIS_Shaded )
726 if ( theColor.alpha() == 0 )
728 anAttributes->SetFaceBoundaryDraw( false );
732 anAttributes->SetFaceBoundaryDraw( true );
734 Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
735 if ( !aBoundaryAspect.IsNull() )
737 aBoundaryAspect->SetColor( aBorderColor );
738 anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
742 else if ( myDisplayMode == AIS_WireFrame )
744 myShape->SetColor( aBorderColor );
748 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
751 if( !theImageObj.IsNull() )
753 QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
755 int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
756 QString aPrefix = QString( "image_%1" ).arg( aStudyId );
758 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
759 anEntry.replace( ':', '_' );
761 QString anExtension = "bmp";
763 aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
768 void HYDROGUI_Shape::removeTextureFile() const
770 QFile aFile( getTextureFileName() );
775 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
777 double aSizeLimit = (double)theSizeLimit;
778 double aWidth = (double)theImage.width();
779 double aHeight = (double)theImage.height();
780 if( aWidth > aSizeLimit || aHeight > aSizeLimit )
782 if( aWidth > aHeight )
784 aHeight /= ( aWidth / aSizeLimit );
789 aWidth /= ( aHeight / aSizeLimit );
790 aHeight = aSizeLimit;
793 return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );