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,
118 const bool theIsDisplayOnTop )
120 setIsToUpdate( false );
122 if ( myContext.IsNull() )
125 bool isDeactivateSelection = false;
126 // Try to retrieve information from object
127 if ( !myObject.IsNull() )
129 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
131 if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
133 Handle(HYDROData_ImmersibleZone) aZoneObj =
134 Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
136 TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
137 if ( !aZoneShape.IsNull() ) {
138 if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
139 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
140 setFace( aZoneFace, false, false );
142 myTopoShape = aZoneShape;
143 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
146 updateShape( false, false );
150 QColor aFillingColor = aZoneObj->GetFillingColor();
151 QColor aBorderColor = aZoneObj->GetBorderColor();
153 setFillingColor( aFillingColor, false, false );
154 setBorderColor( aBorderColor, false, false );
156 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
158 Handle(HYDROData_PolylineXY) aPolyline =
159 Handle(HYDROData_PolylineXY)::DownCast( myObject );
161 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
163 if ( !aPolylineShape.IsNull() ) {
164 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
165 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
166 setWire( aPolylineWire, false, false );
168 myTopoShape = aPolylineShape;
169 myDisplayMode = AIS_WireFrame;
172 updateShape( false, false );
176 QColor aWireColor = aPolyline->GetWireColor();
177 setBorderColor( aWireColor, false, false );
179 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
181 Handle(HYDROData_Polyline3D) aPolyline =
182 Handle(HYDROData_Polyline3D)::DownCast( myObject );
184 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
186 if ( !aPolylineShape.IsNull() ) {
187 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
188 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
189 setWire( aPolylineWire, false, false );
191 myTopoShape = aPolylineShape;
192 myDisplayMode = AIS_WireFrame;
195 updateShape( false, false );
199 QColor aWireColor = aPolyline->GetBorderColor();
200 setBorderColor( aWireColor, false, false );
202 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
204 Handle(HYDROData_Zone) aZone =
205 Handle(HYDROData_Zone)::DownCast( myObject );
207 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
209 setFace( aZoneFace, false, false );
210 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
212 // Red color for a zone with bathymetry conflict
213 setFillingColor( Qt::red );
217 // Generate the filling color for zone
218 QStringList aGeomObjectsNames;
220 HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
221 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
222 for ( ; anIter.More(); anIter.Next() )
224 Handle(HYDROData_Object) aRefbject =
225 Handle(HYDROData_Object)::DownCast( anIter.Value() );
226 if ( aRefbject.IsNull() )
229 QString aRefObjectName = aRefbject->GetName();
230 if ( aRefObjectName.isEmpty() )
233 aGeomObjectsNames.append( aRefObjectName );
236 setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
239 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
241 Handle(HYDROData_Image) anImageObj =
242 Handle(HYDROData_Image)::DownCast( myObject );
246 QString aTextureFileName = generateTextureFileName( anImageObj );
248 QImage anImage = anImageObj->Image();
249 QString aFilePath = anImageObj->GetFilePath();
250 QTransform aTrsf = anImageObj->Trsf();
252 int aWidth = anImage.width();
253 int aHeight = anImage.height();
255 QString anImageError = "";
257 QTransform anInversion = QTransform::fromScale( -1, -1 );
258 anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
260 if ( anImage.isNull() )
261 anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" );
264 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
265 int aTrsfWidth = anImage.width();
266 int aDelta = aTrsfWidth % 4;
269 aTrsfWidth += ( 4 - aDelta );
271 anImage = anImage.scaledToWidth( aTrsfWidth );
273 // temporary optimization, to reduce the saved image size (and the texture quality)
274 QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
276 bool isSaved = anImageToSave.save( aTextureFileName );
278 anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
281 if ( !anImageError.isEmpty() )
283 SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ),
284 QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError );
287 QPointF aPoint1( 0, 0 ); // 1: top left
288 QPointF aPoint2( aWidth, 0 ); // 2: top right
289 QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
290 QPointF aPoint4( 0, aHeight ); // 4: bottom left
292 aPoint1 = aTrsf.map( aPoint1 );
293 aPoint2 = aTrsf.map( aPoint2 );
294 aPoint3 = aTrsf.map( aPoint3 );
295 aPoint4 = aTrsf.map( aPoint4 );
297 QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
298 QRectF aRect = aPolygon.boundingRect();
300 gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
301 gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
302 gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
303 gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
305 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
306 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
307 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
308 TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
310 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
311 aWire.Closed( true );
313 setTextureFileName( aTextureFileName, false, false );
314 setFace( aWire, false, false );
315 isDeactivateSelection = true;
317 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
319 Handle(HYDROData_Profile) aProfile =
320 Handle(HYDROData_Profile)::DownCast( myObject );
322 TopoDS_Wire aProfileWire;
324 if ( aProfile->IsValid() ) {
325 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
327 if ( !aProfileShape.IsNull() &&
328 aProfileShape.ShapeType() == TopAbs_WIRE ) {
329 aProfileWire = TopoDS::Wire( aProfileShape );
333 setWire( aProfileWire, false, false );
335 QColor aWireColor = aProfile->GetBorderColor();
336 setBorderColor( aWireColor, false, false );
338 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
339 myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
340 myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
342 Handle(HYDROData_Object) aGeomObject =
343 Handle(HYDROData_Object)::DownCast( myObject );
345 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
347 setShape( anObjShape, false, false );
349 QColor aFillingColor = aGeomObject->GetFillingColor();
350 QColor aBorderColor = aGeomObject->GetBorderColor();
352 setFillingColor( aFillingColor, false, false );
353 setBorderColor( aBorderColor, false, false );
355 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
357 Handle(HYDROData_DummyObject3D) anObject3D =
358 Handle(HYDROData_DummyObject3D)::DownCast( myObject );
359 TopoDS_Shape aShape3D = anObject3D->GetShape();
361 setShape( aShape3D, false, false );
363 QColor aFillingColor = anObject3D->GetFillingColor();
364 QColor aBorderColor = anObject3D->GetBorderColor();
366 setFillingColor( aFillingColor, false, false );
367 setBorderColor( aBorderColor, false, false );
369 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ShapesGroup) ) )
371 Handle(HYDROData_ShapesGroup) aShapesGroup =
372 Handle(HYDROData_ShapesGroup)::DownCast( myObject );
374 TopTools_SequenceOfShape aShapes;
375 aShapesGroup->GetShapes( aShapes );
377 TopoDS_Compound aCompound;
378 BRep_Builder aCompoundBuilder;
379 aCompoundBuilder.MakeCompound( aCompound );
381 for ( int i = 1, n = aShapes.Length(); i <= n; ++i )
383 const TopoDS_Shape& aShape = aShapes.Value( i );
384 aCompoundBuilder.Add( aCompound, aShape );
387 setShape( aCompound, false, false );
391 if ( myShape.IsNull() || !isVisible() )
394 displayShape( theIsUpdateViewer );
395 // the following code is not necessary if the Z layer is set for the shape
396 if ( myZLayer && theIsDisplayOnTop )
398 // Display the shape on the top Z layer
399 Standard_Integer aNewLayerId = -1;
400 if ( myContext->CurrentViewer() &&
401 myContext->CurrentViewer()->AddZLayer( aNewLayerId ) &&
403 myContext->SetZLayer( myShape, aNewLayerId );
407 if (isDeactivateSelection)
408 myContext->Deactivate(myShape);
411 void HYDROGUI_Shape::setVisible( const bool theState,
412 const bool theIsUpdateViewer )
414 myIsVisible = theState;
416 if ( myShape.IsNull() )
419 if ( ( myIsVisible && myContext->IsDisplayed( myShape ) ) ||
420 ( !myIsVisible && !myContext->IsDisplayed( myShape ) ) )
424 displayShape( theIsUpdateViewer );
427 myContext->Erase( myShape, theIsUpdateViewer );
430 void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
432 if ( myIsHighlight == theIsHighlight )
435 myIsHighlight = theIsHighlight;
437 if ( myContext.IsNull() || myShape.IsNull() )
440 colorShapeBorder( getActiveColor() );
441 displayShape( isUpdateViewer );
444 bool HYDROGUI_Shape::isHighlighted() const
446 return myIsHighlight;
449 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
450 const bool theToDisplay,
451 const bool theIsUpdateViewer )
453 myTopoShape = theWire;
454 myDisplayMode = AIS_WireFrame;
457 updateShape( theToDisplay, theIsUpdateViewer );
460 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
461 const bool theToDisplay,
462 const bool theIsUpdateViewer )
464 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
465 TopoDS_Compound aCompound;
466 BRep_Builder aBuilder;
467 aBuilder.MakeCompound( aCompound );
469 for ( ; anExp.More(); anExp.Next() ) {
470 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
471 if ( aWire.IsNull() ) {
475 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
477 if( aMakeFace.IsDone() ) {
478 aBuilder.Add( aCompound, aMakeFace.Face() );
482 myTopoShape = aCompound;
483 myDisplayMode = AIS_Shaded;
486 updateShape( theToDisplay, theIsUpdateViewer );
489 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
490 const bool theToDisplay,
491 const bool theIsUpdateViewer )
493 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
494 aFaceBuilder.Build();
495 if( aFaceBuilder.IsDone() )
497 TopoDS_Face aFace = aFaceBuilder.Face();
498 setFace( aFace, theToDisplay, theIsUpdateViewer );
502 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
503 const bool theToDisplay,
504 const bool theIsUpdateViewer )
506 myTopoShape = theFace;
507 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
508 //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
509 //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
512 updateShape( theToDisplay, theIsUpdateViewer );
515 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
516 const bool theToDisplay,
517 const bool theIsUpdateViewer )
519 myTopoShape = theShape;
520 myDisplayMode = AIS_Shaded;
523 updateShape( theToDisplay, theIsUpdateViewer );
526 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
527 const bool theToDisplay,
528 const bool theIsUpdateViewer )
530 myFillingColor = theColor;
531 updateShape( theToDisplay, theIsUpdateViewer );
534 QColor HYDROGUI_Shape::getFillingColor() const
536 return myFillingColor;
539 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
540 const bool theToDisplay,
541 const bool theIsUpdateViewer )
543 myBorderColor = theColor;
544 updateShape( theToDisplay, theIsUpdateViewer );
547 QColor HYDROGUI_Shape::getBorderColor() const
549 return myBorderColor;
552 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
554 myHighlightColor = theColor;
557 QColor HYDROGUI_Shape::getHighlightColor() const
559 return myHighlightColor;
562 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
563 const bool theToDisplay,
564 const bool theIsUpdateViewer )
566 myTextureFileName = theFileName;
567 updateShape( theToDisplay, theIsUpdateViewer );
570 QString HYDROGUI_Shape::getTextureFileName() const
572 return myTextureFileName;
575 void HYDROGUI_Shape::setZLayer( const int theZLayer )
577 if ( myZLayer == theZLayer )
580 myZLayer = theZLayer;
581 if ( !myShape.IsNull() && isVisible() && !myContext.IsNull() && myZLayer >= 0 )
582 myContext->SetZLayer( myShape, myZLayer );
585 void HYDROGUI_Shape::buildShape()
587 // Erase previously created shape
590 if ( myTopoShape.IsNull() ) {
595 QString aTextureFileName = getTextureFileName();
596 bool anIsTexture = !aTextureFileName.isEmpty();
600 myShape = new AIS_TexturedShape( myTopoShape );
604 myShape = new AIS_Shape( myTopoShape );
607 myShape->SetHLRAngleAndDeviation( 0.001 );
609 if ( !myObject.IsNull() )
610 myShape->SetOwner( myObject );
612 myShape->SetTransparency( 0 );
613 myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
617 Handle(AIS_TexturedShape) aTexturedShape =
618 Handle(AIS_TexturedShape)::DownCast( myShape );
620 aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
621 aTexturedShape->SetTextureMapOn();
622 // Just use the texture image as is
623 aTexturedShape->DisableTextureModulate();
624 aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
627 // Init default params for shape
628 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
629 if ( !anAttributes.IsNull() )
631 Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
632 if ( !anIsoAspect.IsNull() ) {
633 anIsoAspect->SetNumber( 0 );
634 anAttributes->SetUIsoAspect( anIsoAspect );
637 anIsoAspect = anAttributes->VIsoAspect();
638 if ( !anIsoAspect.IsNull() ) {
639 anIsoAspect->SetNumber( 0 );
640 anAttributes->SetVIsoAspect( anIsoAspect );
643 if ( myDisplayMode == AIS_Shaded )
645 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
646 if ( !aShadingAspect.IsNull() )
648 Graphic3d_MaterialAspect aMatAspect( Graphic3d_NOM_PLASTIC );
649 //aMatAspect.SetAmbient( 1 );
650 //aMatAspect.SetDiffuse( 0 );
652 aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
653 aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
656 else if ( myDisplayMode == AIS_WireFrame )
658 anAttributes->SetWireDraw( true );
663 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
664 const bool theIsUpdateViewer )
666 if ( myShape.IsNull() )
669 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
670 if ( !anAttributes.IsNull() )
672 if ( myDisplayMode == AIS_Shaded )
674 // Coloring face filling
675 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
676 if ( !aShadingAspect.IsNull() )
678 Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ),
679 getQuantityColorVal( myFillingColor.green() ),
680 getQuantityColorVal( myFillingColor.blue() ),
683 aShadingAspect->SetColor( aFillingColor );
684 aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
687 else if ( myDisplayMode == AIS_WireFrame )
692 colorShapeBorder( getActiveColor() );
695 if ( !theToDisplay || !isVisible() || myContext.IsNull() )
698 displayShape( theIsUpdateViewer );
701 void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
703 myContext->Display( myShape, Standard_False );
706 myContext->SetZLayer( myShape, myZLayer );
708 myContext->UpdateCurrentViewer();
711 QColor HYDROGUI_Shape::getActiveColor() const
713 return isHighlighted() ? myHighlightColor : myBorderColor;
716 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
718 return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
721 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
723 if ( myShape.IsNull() )
726 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
727 if ( anAttributes.IsNull() )
730 Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ),
731 getQuantityColorVal( theColor.green() ),
732 getQuantityColorVal( theColor.blue() ),
734 if ( myDisplayMode == AIS_Shaded )
736 if ( theColor.alpha() == 0 )
738 anAttributes->SetFaceBoundaryDraw( false );
742 anAttributes->SetFaceBoundaryDraw( true );
744 Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
745 if ( !aBoundaryAspect.IsNull() )
747 aBoundaryAspect->SetColor( aBorderColor );
748 anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
752 else if ( myDisplayMode == AIS_WireFrame )
754 myShape->SetColor( aBorderColor );
758 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
761 if( !theImageObj.IsNull() )
763 QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
765 int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
766 QString aPrefix = QString( "image_%1" ).arg( aStudyId );
768 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
769 anEntry.replace( ':', '_' );
771 QString anExtension = "bmp";
773 aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
778 void HYDROGUI_Shape::removeTextureFile() const
780 QFile aFile( getTextureFileName() );
785 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
787 double aSizeLimit = (double)theSizeLimit;
788 double aWidth = (double)theImage.width();
789 double aHeight = (double)theImage.height();
790 if( aWidth > aSizeLimit || aHeight > aSizeLimit )
792 if( aWidth > aHeight )
794 aHeight /= ( aWidth / aSizeLimit );
799 aWidth /= ( aHeight / aSizeLimit );
800 aHeight = aSizeLimit;
803 return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );