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 // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
169 // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
170 myDisplayMode = AIS_Shaded;
173 updateShape( false, false );
177 QColor aWireColor = aPolyline->GetWireColor();
178 setBorderColor( aWireColor, false, false );
180 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
182 Handle(HYDROData_Polyline3D) aPolyline =
183 Handle(HYDROData_Polyline3D)::DownCast( myObject );
185 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
187 if ( !aPolylineShape.IsNull() ) {
188 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
189 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
190 setWire( aPolylineWire, false, false );
192 myTopoShape = aPolylineShape;
193 // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
194 // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
195 myDisplayMode = AIS_Shaded;
198 updateShape( false, false );
202 QColor aWireColor = aPolyline->GetBorderColor();
203 setBorderColor( aWireColor, false, false );
205 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
207 Handle(HYDROData_Zone) aZone =
208 Handle(HYDROData_Zone)::DownCast( myObject );
210 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
212 setFace( aZoneFace, false, false );
213 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
215 // Red color for a zone with bathymetry conflict
216 setFillingColor( Qt::red );
220 // Generate the filling color for zone
221 QStringList aGeomObjectsNames;
223 HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
224 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
225 for ( ; anIter.More(); anIter.Next() )
227 Handle(HYDROData_Object) aRefbject =
228 Handle(HYDROData_Object)::DownCast( anIter.Value() );
229 if ( aRefbject.IsNull() )
232 QString aRefObjectName = aRefbject->GetName();
233 if ( aRefObjectName.isEmpty() )
236 aGeomObjectsNames.append( aRefObjectName );
239 setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
242 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
244 Handle(HYDROData_Image) anImageObj =
245 Handle(HYDROData_Image)::DownCast( myObject );
249 QString aTextureFileName = generateTextureFileName( anImageObj );
251 QImage anImage = anImageObj->Image();
252 QString aFilePath = anImageObj->GetFilePath();
253 QTransform aTrsf = anImageObj->Trsf();
255 int aWidth = anImage.width();
256 int aHeight = anImage.height();
258 QString anImageError = "";
260 QTransform anInversion = QTransform::fromScale( -1, -1 );
261 anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
263 if ( anImage.isNull() )
264 anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" );
267 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
268 int aTrsfWidth = anImage.width();
269 int aDelta = aTrsfWidth % 4;
272 aTrsfWidth += ( 4 - aDelta );
274 anImage = anImage.scaledToWidth( aTrsfWidth );
276 // temporary optimization, to reduce the saved image size (and the texture quality)
277 QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
279 bool isSaved = anImageToSave.save( aTextureFileName );
281 anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
283 QFile::setPermissions( aTextureFileName, (QFile::Permissions)0x4FFFF );
286 if ( !anImageError.isEmpty() )
288 SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ),
289 QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError );
292 QPointF aPoint1( 0, 0 ); // 1: top left
293 QPointF aPoint2( aWidth, 0 ); // 2: top right
294 QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
295 QPointF aPoint4( 0, aHeight ); // 4: bottom left
297 aPoint1 = aTrsf.map( aPoint1 );
298 aPoint2 = aTrsf.map( aPoint2 );
299 aPoint3 = aTrsf.map( aPoint3 );
300 aPoint4 = aTrsf.map( aPoint4 );
302 QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
303 QRectF aRect = aPolygon.boundingRect();
305 gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
306 gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
307 gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
308 gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
310 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
311 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
312 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
313 TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
315 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
316 aWire.Closed( true );
318 setTextureFileName( aTextureFileName, false, false );
319 setFace( aWire, false, false );
320 isDeactivateSelection = true;
322 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
324 Handle(HYDROData_Profile) aProfile =
325 Handle(HYDROData_Profile)::DownCast( myObject );
327 TopoDS_Wire aProfileWire;
329 if ( aProfile->IsValid() ) {
330 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
332 if ( !aProfileShape.IsNull() &&
333 aProfileShape.ShapeType() == TopAbs_WIRE ) {
334 aProfileWire = TopoDS::Wire( aProfileShape );
338 setWire( aProfileWire, false, false );
340 QColor aWireColor = aProfile->GetBorderColor();
341 setBorderColor( aWireColor, false, false );
343 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
344 myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
345 myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
347 Handle(HYDROData_Object) aGeomObject =
348 Handle(HYDROData_Object)::DownCast( myObject );
350 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
352 setShape( anObjShape, false, false );
354 QColor aFillingColor = aGeomObject->GetFillingColor();
355 QColor aBorderColor = aGeomObject->GetBorderColor();
357 setFillingColor( aFillingColor, false, false );
358 setBorderColor( aBorderColor, false, false );
360 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
362 Handle(HYDROData_DummyObject3D) anObject3D =
363 Handle(HYDROData_DummyObject3D)::DownCast( myObject );
364 TopoDS_Shape aShape3D = anObject3D->GetShape();
366 setShape( aShape3D, false, false );
368 QColor aFillingColor = anObject3D->GetFillingColor();
369 QColor aBorderColor = anObject3D->GetBorderColor();
371 setFillingColor( aFillingColor, false, false );
372 setBorderColor( aBorderColor, false, false );
374 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ShapesGroup) ) )
376 Handle(HYDROData_ShapesGroup) aShapesGroup =
377 Handle(HYDROData_ShapesGroup)::DownCast( myObject );
379 TopTools_SequenceOfShape aShapes;
380 aShapesGroup->GetShapes( aShapes );
382 TopoDS_Compound aCompound;
383 BRep_Builder aCompoundBuilder;
384 aCompoundBuilder.MakeCompound( aCompound );
386 for ( int i = 1, n = aShapes.Length(); i <= n; ++i )
388 const TopoDS_Shape& aShape = aShapes.Value( i );
389 aCompoundBuilder.Add( aCompound, aShape );
392 setShape( aCompound, false, false );
396 if ( myShape.IsNull() || !isVisible() )
399 displayShape( theIsUpdateViewer );
401 if (isDeactivateSelection)
402 myContext->Deactivate(myShape);
405 void HYDROGUI_Shape::setVisible( const bool theState,
406 const bool theIsUpdateViewer )
408 myIsVisible = theState;
410 if ( myShape.IsNull() )
413 if ( ( myIsVisible && myContext->IsDisplayed( myShape ) ) ||
414 ( !myIsVisible && !myContext->IsDisplayed( myShape ) ) )
418 displayShape( theIsUpdateViewer );
421 myContext->Erase( myShape, theIsUpdateViewer );
424 void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
426 if ( myIsHighlight == theIsHighlight )
429 myIsHighlight = theIsHighlight;
431 if ( myContext.IsNull() || myShape.IsNull() )
434 colorShapeBorder( getActiveColor() );
435 displayShape( isUpdateViewer );
438 bool HYDROGUI_Shape::isHighlighted() const
440 return myIsHighlight;
443 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
444 const bool theToDisplay,
445 const bool theIsUpdateViewer )
447 myTopoShape = theWire;
448 // To avoid that hilight presentation is equal to "normal" object presentation.
449 // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
450 myDisplayMode = AIS_Shaded;
453 updateShape( theToDisplay, theIsUpdateViewer );
456 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
457 const bool theToDisplay,
458 const bool theIsUpdateViewer )
460 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
461 TopoDS_Compound aCompound;
462 BRep_Builder aBuilder;
463 aBuilder.MakeCompound( aCompound );
465 for ( ; anExp.More(); anExp.Next() ) {
466 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
467 if ( aWire.IsNull() ) {
471 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
473 if( aMakeFace.IsDone() ) {
474 aBuilder.Add( aCompound, aMakeFace.Face() );
478 myTopoShape = aCompound;
479 myDisplayMode = AIS_Shaded;
482 updateShape( theToDisplay, theIsUpdateViewer );
485 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
486 const bool theToDisplay,
487 const bool theIsUpdateViewer )
489 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
490 aFaceBuilder.Build();
491 if( aFaceBuilder.IsDone() )
493 TopoDS_Face aFace = aFaceBuilder.Face();
494 setFace( aFace, theToDisplay, theIsUpdateViewer );
498 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
499 const bool theToDisplay,
500 const bool theIsUpdateViewer )
502 myTopoShape = theFace;
503 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
504 //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
505 //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
508 updateShape( theToDisplay, theIsUpdateViewer );
511 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
512 const bool theToDisplay,
513 const bool theIsUpdateViewer )
515 myTopoShape = theShape;
516 myDisplayMode = AIS_Shaded;
519 updateShape( theToDisplay, theIsUpdateViewer );
522 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
523 const bool theToDisplay,
524 const bool theIsUpdateViewer )
526 myFillingColor = theColor;
527 updateShape( theToDisplay, theIsUpdateViewer );
530 QColor HYDROGUI_Shape::getFillingColor() const
532 return myFillingColor;
535 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
536 const bool theToDisplay,
537 const bool theIsUpdateViewer )
539 myBorderColor = theColor;
540 updateShape( theToDisplay, theIsUpdateViewer );
543 QColor HYDROGUI_Shape::getBorderColor() const
545 return myBorderColor;
548 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
550 myHighlightColor = theColor;
553 QColor HYDROGUI_Shape::getHighlightColor() const
555 return myHighlightColor;
558 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
559 const bool theToDisplay,
560 const bool theIsUpdateViewer )
562 myTextureFileName = theFileName;
563 updateShape( theToDisplay, theIsUpdateViewer );
566 QString HYDROGUI_Shape::getTextureFileName() const
568 return myTextureFileName;
571 void HYDROGUI_Shape::setZLayer( const int theZLayer )
573 if ( myZLayer == theZLayer )
576 myZLayer = theZLayer;
577 if ( !myShape.IsNull() && isVisible() && !myContext.IsNull() && myZLayer >= 0 )
578 myContext->SetZLayer( myShape, myZLayer );
581 void HYDROGUI_Shape::buildShape()
583 // Erase previously created shape
586 if ( myTopoShape.IsNull() ) {
591 QString aTextureFileName = getTextureFileName();
592 bool anIsTexture = !aTextureFileName.isEmpty();
596 myShape = new AIS_TexturedShape( myTopoShape );
600 myShape = new AIS_Shape( myTopoShape );
603 myShape->SetHLRAngleAndDeviation( 0.001 );
605 if ( !myObject.IsNull() )
606 myShape->SetOwner( myObject );
608 myShape->SetTransparency( 0 );
609 myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
613 Handle(AIS_TexturedShape) aTexturedShape =
614 Handle(AIS_TexturedShape)::DownCast( myShape );
616 aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
617 aTexturedShape->SetTextureMapOn();
618 // Just use the texture image as is
619 aTexturedShape->DisableTextureModulate();
620 aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
623 // Init default params for shape
624 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
625 if ( !anAttributes.IsNull() )
627 Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
628 if ( !anIsoAspect.IsNull() ) {
629 anIsoAspect->SetNumber( 0 );
630 anAttributes->SetUIsoAspect( anIsoAspect );
633 anIsoAspect = anAttributes->VIsoAspect();
634 if ( !anIsoAspect.IsNull() ) {
635 anIsoAspect->SetNumber( 0 );
636 anAttributes->SetVIsoAspect( anIsoAspect );
639 if ( myDisplayMode == AIS_Shaded )
641 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
642 if ( !aShadingAspect.IsNull() )
644 Graphic3d_MaterialAspect aMatAspect( Graphic3d_NOM_PLASTIC );
645 //aMatAspect.SetAmbient( 1 );
646 //aMatAspect.SetDiffuse( 0 );
648 aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
649 aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
652 else if ( myDisplayMode == AIS_WireFrame )
654 anAttributes->SetWireDraw( true );
659 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
660 const bool theIsUpdateViewer )
662 if ( myShape.IsNull() )
665 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
666 if ( !anAttributes.IsNull() )
668 if ( myDisplayMode == AIS_Shaded )
670 // Coloring face filling
671 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
672 if ( !aShadingAspect.IsNull() )
674 Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ),
675 getQuantityColorVal( myFillingColor.green() ),
676 getQuantityColorVal( myFillingColor.blue() ),
679 aShadingAspect->SetColor( aFillingColor );
680 aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
683 else if ( myDisplayMode == AIS_WireFrame )
688 colorShapeBorder( getActiveColor() );
691 if ( !theToDisplay || !isVisible() || myContext.IsNull() )
694 displayShape( theIsUpdateViewer );
697 void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
699 myContext->Display( myShape, Standard_False );
702 myContext->SetZLayer( myShape, myZLayer );
704 myContext->UpdateCurrentViewer();
707 QColor HYDROGUI_Shape::getActiveColor() const
709 return isHighlighted() ? myHighlightColor : myBorderColor;
712 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
714 return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
717 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
719 if ( myShape.IsNull() )
722 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
723 if ( anAttributes.IsNull() )
726 Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ),
727 getQuantityColorVal( theColor.green() ),
728 getQuantityColorVal( theColor.blue() ),
732 if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode
734 myShape->SetColor( aBorderColor );
735 } else if ( myDisplayMode == AIS_Shaded )
737 if ( theColor.alpha() == 0 )
739 anAttributes->SetFaceBoundaryDraw( false );
743 anAttributes->SetFaceBoundaryDraw( true );
745 Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
746 if ( !aBoundaryAspect.IsNull() )
748 aBoundaryAspect->SetColor( aBorderColor );
749 anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
753 else if ( myDisplayMode == AIS_WireFrame )
755 myShape->SetColor( aBorderColor );
759 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
762 if( !theImageObj.IsNull() )
764 QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
766 int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
767 QString aPrefix = QString( "image_%1" ).arg( aStudyId );
769 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
770 anEntry.replace( ':', '_' );
772 QString anExtension = "bmp";
774 aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
779 void HYDROGUI_Shape::removeTextureFile() const
781 QFile aFile( getTextureFileName() );
786 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
788 double aSizeLimit = (double)theSizeLimit;
789 double aWidth = (double)theImage.width();
790 double aHeight = (double)theImage.height();
791 if( aWidth > aSizeLimit || aHeight > aSizeLimit )
793 if( aWidth > aHeight )
795 aHeight /= ( aWidth / aSizeLimit );
800 aWidth /= ( aHeight / aSizeLimit );
801 aHeight = aSizeLimit;
804 return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );