Salome HOME
Bugs 153, 154.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Shape.h"
24
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Tool.h"
27
28 #include <AIS_Drawer.hxx>
29 #include <AIS_TexturedShape.hxx>
30
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <BRepBuilderAPI_MakeWire.hxx>
33 #include <BRepBuilderAPI_MakeFace.hxx>
34
35 #include <gp_Pnt.hxx>
36
37 #include <Graphic3d_AspectFillArea3d.hxx>
38 #include <Graphic3d_MaterialAspect.hxx>
39
40 #include <HYDROData_Channel.h>
41 #include <HYDROData_Document.h>
42 #include <HYDROData_Image.h>
43 #include <HYDROData_ImmersibleZone.h>
44 #include <HYDROData_Obstacle.h>
45 #include <HYDROData_PolylineXY.h>
46 #include <HYDROData_Profile.h>
47 #include <HYDROData_Region.h>
48 #include <HYDROData_Stream.h>
49 #include <HYDROData_Zone.h>
50
51 #include <TopoDS.hxx>
52 #include <TopoDS_Wire.hxx>
53 #include <TopoDS_Face.hxx>
54
55 #include <TopExp_Explorer.hxx>
56
57 #include <BRep_Builder.hxx>
58
59 #include <Precision.hxx>
60
61 #include <Prs3d_ShadingAspect.hxx>
62 #include <Prs3d_LineAspect.hxx>
63 #include <Prs3d_IsoAspect.hxx>
64
65 #include <SUIT_MessageBox.h>
66
67 #include <QColor>
68 #include <QFile>
69
70 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
71                                 const Handle(HYDROData_Entity)&       theObject )
72 : myContext( theContext ),
73   myObject( theObject ),
74   myIsHighlight( false ),
75   myFillingColor( Qt::transparent ),
76   myBorderColor( Qt::black ),
77   myHighlightColor( Qt::white ),
78   myIsToUpdate( false ),
79   myIsVisible( true ),
80   myDisplayMode( AIS_WireFrame )
81 {
82 }
83
84 HYDROGUI_Shape::~HYDROGUI_Shape()
85 {
86   erase( false );
87
88   if ( !myShape.IsNull() )
89     myShape.Nullify();
90
91   removeTextureFile();
92 }
93
94 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
95 {
96   if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
97     return;
98
99   myContext->Display( myShape, theIsUpdateViewer );
100 }
101
102 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
103 {
104   if ( myContext.IsNull() || myShape.IsNull() )
105     return;
106
107   myContext->Erase( myShape, theIsUpdateViewer );
108 }
109
110 void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
111 {
112   setIsToUpdate( false );
113
114   if ( myContext.IsNull() )
115     return;
116
117   // Try to retrieve information from object
118   if ( !myObject.IsNull() )
119   {
120     Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
121   
122     if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
123     {
124       Handle(HYDROData_ImmersibleZone) aZoneObj =
125         Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
126
127       TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
128       if ( !aZoneShape.IsNull() ) {
129         if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
130           TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
131           setFace( aZoneFace, false, false );
132         } else {
133           myTopoShape = aZoneShape;
134           myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
135
136           buildShape();
137           updateShape( false, false );
138         }
139       }
140
141       QColor aFillingColor = aZoneObj->GetFillingColor();
142       QColor aBorderColor = aZoneObj->GetBorderColor();
143
144       setFillingColor( aFillingColor, false, false );
145       setBorderColor( aBorderColor, false, false );
146     }
147     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
148     {
149       Handle(HYDROData_PolylineXY) aPolyline =
150         Handle(HYDROData_PolylineXY)::DownCast( myObject );
151
152       TopoDS_Shape aPolylineShape = aPolyline->GetShape();
153
154       if ( !aPolylineShape.IsNull() ) {
155         if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
156           TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
157           setWire( aPolylineWire, false, false );  
158         } else {
159           myTopoShape = aPolylineShape;
160           myDisplayMode = AIS_WireFrame;
161
162           buildShape();
163           updateShape( false, false );
164         }
165       }
166     }
167     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
168     {
169       Handle(HYDROData_Zone) aZone =
170         Handle(HYDROData_Zone)::DownCast( myObject );
171
172       TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
173
174       setFace( aZoneFace, false, false );
175       if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
176       {
177         // Red color for a zone with bathymetry conflict
178         setFillingColor( Qt::red );
179       }
180       else
181       {
182         // Generate the filling color for zone
183         QStringList aGeomObjectsNames;
184
185         HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
186         HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
187         for ( ; anIter.More(); anIter.Next() )
188         {
189           Handle(HYDROData_Object) aRefbject = 
190             Handle(HYDROData_Object)::DownCast( anIter.Value() );
191           if ( aRefbject.IsNull() )
192             continue;
193
194           QString aRefObjectName = aRefbject->GetName();
195           if ( aRefObjectName.isEmpty() )
196             continue;
197
198           aGeomObjectsNames.append( aRefObjectName );
199         }
200
201         setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
202       }
203     }
204     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
205     {
206       Handle(HYDROData_Image) anImageObj =
207         Handle(HYDROData_Image)::DownCast( myObject );
208
209       removeTextureFile();
210
211       QString aTextureFileName = generateTextureFileName( anImageObj );
212
213       QImage anImage = anImageObj->Image();
214       QString aFilePath = anImageObj->GetFilePath();
215       QTransform aTrsf = anImageObj->Trsf();
216
217       int aWidth = anImage.width();
218       int aHeight = anImage.height();
219
220       QTransform anInversion = QTransform::fromScale( -1, -1 );
221       anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
222
223       // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
224       int aTrsfWidth = anImage.width();
225       int aDelta = aTrsfWidth % 4;
226       if ( aDelta > 0 )
227       {
228         aTrsfWidth += ( 4 - aDelta );
229       }
230       anImage = anImage.scaledToWidth( aTrsfWidth );
231
232       // temporary optimization, to reduce the saved image size (and the texture quality)
233       QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
234
235       bool isSaved = anImageToSave.save( aTextureFileName );
236       if ( !isSaved ) {
237         QString aTitle = QObject::tr( "FILE_ERROR" );
238         QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
239         SUIT_MessageBox::warning( 0, aTitle, aMessage );
240       }
241
242       QPointF aPoint1( 0, 0 );            // 1: top left
243       QPointF aPoint2( aWidth, 0 );       // 2: top right
244       QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
245       QPointF aPoint4( 0, aHeight );      // 4: bottom left
246
247       aPoint1 = aTrsf.map( aPoint1 );
248       aPoint2 = aTrsf.map( aPoint2 );
249       aPoint3 = aTrsf.map( aPoint3 );
250       aPoint4 = aTrsf.map( aPoint4 );
251
252       QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
253       QRectF aRect = aPolygon.boundingRect();
254
255       gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
256       gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
257       gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
258       gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
259
260       TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
261       TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
262       TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
263       TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
264
265       TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
266       aWire.Closed( true );
267
268       setTextureFileName( aTextureFileName, false, false );
269       setFace( aWire, false, false );
270     }
271     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
272     {
273       Handle(HYDROData_Obstacle) anObstacle =
274         Handle(HYDROData_Obstacle)::DownCast( myObject );
275
276       //TODO BEGIN of the block of code to be reimplemented
277       //TODO GetTopShape() to be used in future
278       myTopoShape = anObstacle->GetShape3D();
279       myDisplayMode = AIS_Shaded;
280
281       QColor aFillingColor = anObstacle->GetFillingColor();
282       QColor aBorderColor = anObstacle->GetBorderColor();
283
284       setFillingColor( aFillingColor, false, false );
285       setBorderColor( aBorderColor, false, false );
286
287       buildShape();
288       updateShape( false, false );
289       //TODO END of the block of code to be reimplemented
290     }
291     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
292     {
293       Handle(HYDROData_Profile) aProfile =
294         Handle(HYDROData_Profile)::DownCast( myObject );
295
296       TopoDS_Wire aProfileWire;
297
298       if ( aProfile->IsValid() ) {
299         TopoDS_Shape aProfileShape = aProfile->GetShape3D();
300
301         if ( !aProfileShape.IsNull() && 
302              aProfileShape.ShapeType() == TopAbs_WIRE ) {
303           aProfileWire = TopoDS::Wire( aProfileShape );
304         }
305       }
306
307       setWire( aProfileWire, false, false );  
308     }
309     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) )
310     {
311       Handle(HYDROData_Stream) aStream =
312         Handle(HYDROData_Stream)::DownCast( myObject );
313
314       TopoDS_Shell aStreamShape = TopoDS::Shell( aStream->GetTopShape() );
315
316       setShape( aStreamShape, false, false );
317
318       QColor aFillingColor = aStream->GetFillingColor();
319       QColor aBorderColor = aStream->GetBorderColor();
320
321       setFillingColor( aFillingColor, false, false );
322       setBorderColor( aBorderColor, false, false );
323     }
324     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) )
325     {
326       Handle(HYDROData_Channel) aChannel =
327         Handle(HYDROData_Channel)::DownCast( myObject );
328
329       TopoDS_Face aChannelShape = TopoDS::Face( aChannel->GetTopShape() );
330
331       setShape( aChannelShape, false, false );
332
333       QColor aFillingColor = aChannel->GetFillingColor();
334       QColor aBorderColor = aChannel->GetBorderColor();
335
336       setFillingColor( aFillingColor, false, false );
337       setBorderColor( aBorderColor, false, false );
338     }
339   }
340  
341   if ( myShape.IsNull() || !isVisible() )
342     return;
343
344   myContext->Display( myShape, theIsUpdateViewer );
345 }
346
347 void HYDROGUI_Shape::setVisible( const bool theState,
348                                  const bool theIsUpdateViewer )
349 {
350   if ( myIsVisible == theState )
351     return;
352
353   myIsVisible = theState;
354
355   if ( myShape.IsNull() )
356     return;
357
358   if ( myIsVisible )
359     myContext->Display( myShape, theIsUpdateViewer );
360   else
361     myContext->Erase( myShape, theIsUpdateViewer );
362 }
363
364 void HYDROGUI_Shape::highlight( bool theIsHighlight )
365 {
366   if ( myIsHighlight == theIsHighlight )
367     return;
368
369   myIsHighlight = theIsHighlight;
370
371   if ( myContext.IsNull() || myShape.IsNull() )
372     return;
373
374   colorShapeBorder( getActiveColor() );
375   myContext->Display( myShape );
376 }
377
378 bool HYDROGUI_Shape::isHighlighted() const
379 {
380   return myIsHighlight;
381 }
382
383 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
384                               const bool         theToDisplay,
385                               const bool         theIsUpdateViewer )
386 {
387   myTopoShape = theWire;
388   myDisplayMode = AIS_WireFrame;
389
390   buildShape();
391   updateShape( theToDisplay, theIsUpdateViewer );
392 }
393
394 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
395                                const bool             theToDisplay,
396                                const bool             theIsUpdateViewer )
397 {
398   TopExp_Explorer anExp( theWires, TopAbs_WIRE );
399   TopoDS_Compound aCompound;
400   BRep_Builder aBuilder;
401     aBuilder.MakeCompound( aCompound );
402
403   for ( ; anExp.More(); anExp.Next() ) {
404     TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
405     if ( aWire.IsNull() ) {
406       continue;
407     }
408
409     BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
410     aMakeFace.Build();
411     if( aMakeFace.IsDone() ) {
412       aBuilder.Add( aCompound, aMakeFace.Face() );
413     }
414   }
415
416   myTopoShape = aCompound;
417   myDisplayMode = AIS_Shaded;
418
419   buildShape();
420   updateShape( theToDisplay, theIsUpdateViewer );
421 }
422
423 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
424                               const bool         theToDisplay,
425                               const bool         theIsUpdateViewer )
426 {
427   BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
428   aFaceBuilder.Build();
429   if( aFaceBuilder.IsDone() )
430   {
431     TopoDS_Face aFace = aFaceBuilder.Face();
432     setFace( aFace, theToDisplay, theIsUpdateViewer );
433   }
434 }
435
436 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
437                               const bool         theToDisplay,
438                               const bool         theIsUpdateViewer )
439 {
440   myTopoShape = theFace;
441   myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
442   //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
443   //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
444
445   buildShape();
446   updateShape( theToDisplay, theIsUpdateViewer );
447 }
448
449 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
450                                const bool          theToDisplay,
451                                const bool          theIsUpdateViewer )
452 {
453   myTopoShape = theShape;
454   myDisplayMode = AIS_Shaded;
455
456   buildShape();
457   updateShape( theToDisplay, theIsUpdateViewer );
458 }
459
460 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
461                                       const bool    theToDisplay,
462                                       const bool    theIsUpdateViewer )
463 {
464   myFillingColor = theColor;
465   updateShape( theToDisplay, theIsUpdateViewer );
466 }
467
468 QColor HYDROGUI_Shape::getFillingColor() const
469 {
470   return myFillingColor;
471 }
472
473 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
474                                      const bool    theToDisplay,
475                                      const bool    theIsUpdateViewer )
476 {
477   myBorderColor = theColor;
478   updateShape( theToDisplay, theIsUpdateViewer );
479 }
480
481 QColor HYDROGUI_Shape::getBorderColor() const
482 {
483   return myBorderColor;
484 }
485
486 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
487 {
488   myHighlightColor = theColor;
489 }
490
491 QColor HYDROGUI_Shape::getHighlightColor() const
492 {
493   return myHighlightColor;
494 }
495
496 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
497                                          const bool     theToDisplay,
498                                          const bool     theIsUpdateViewer )
499 {
500   myTextureFileName = theFileName;
501   updateShape( theToDisplay, theIsUpdateViewer );
502 }
503
504 QString HYDROGUI_Shape::getTextureFileName() const
505 {
506   return myTextureFileName;
507 }
508
509 void HYDROGUI_Shape::buildShape()
510 {
511   // Erase previously created shape
512   erase();
513
514   if ( myTopoShape.IsNull() ) {
515     myShape.Nullify();
516     return;
517   }
518
519   QString aTextureFileName = getTextureFileName();
520   bool anIsTexture = !aTextureFileName.isEmpty();
521
522   if ( anIsTexture )
523   {
524     myShape = new AIS_TexturedShape( myTopoShape );
525   }
526   else
527   {
528     myShape = new AIS_Shape( myTopoShape );
529   }
530
531   if ( !myObject.IsNull() )
532     myShape->SetOwner( myObject );
533
534   myShape->SetTransparency( 0 );
535   myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
536
537   if( anIsTexture )
538   {
539     Handle(AIS_TexturedShape) aTexturedShape = 
540       Handle(AIS_TexturedShape)::DownCast( myShape );
541
542     aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
543     aTexturedShape->SetTextureMapOn();
544     // Just use the texture image as is
545     aTexturedShape->DisableTextureModulate();
546     aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
547   }
548
549     // Init default params for shape
550   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
551   if ( !anAttributes.IsNull() )
552   {
553     Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
554     if ( !anIsoAspect.IsNull() ) {
555       anIsoAspect->SetNumber( 0 );
556       anAttributes->SetUIsoAspect( anIsoAspect );
557     }
558       
559     anIsoAspect = anAttributes->VIsoAspect();
560     if ( !anIsoAspect.IsNull() ) {
561       anIsoAspect->SetNumber( 0 );
562       anAttributes->SetVIsoAspect( anIsoAspect );
563     }
564
565     if ( myDisplayMode == AIS_Shaded )
566     {
567       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
568       if ( !aShadingAspect.IsNull() )
569       {
570         Graphic3d_MaterialAspect aMatAspect;
571         aMatAspect.SetAmbient( 1 );
572         aMatAspect.SetDiffuse( 0 );
573
574         aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
575         aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
576       }
577     }
578     else if ( myDisplayMode == AIS_WireFrame )
579     {
580       anAttributes->SetWireDraw( true );
581     }
582   }
583 }
584
585 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
586                                   const bool theIsUpdateViewer )
587 {
588   if ( myShape.IsNull() )
589     return;
590
591   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
592   if ( !anAttributes.IsNull() )
593   {
594     if ( myDisplayMode == AIS_Shaded )
595     {
596       // Coloring face filling
597       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
598       if ( !aShadingAspect.IsNull() )
599       {
600         Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ), 
601                                       getQuantityColorVal( myFillingColor.green() ),
602                                       getQuantityColorVal( myFillingColor.blue() ),
603                                       Quantity_TOC_RGB );
604
605         aShadingAspect->SetColor( aFillingColor );
606         aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
607       }
608     }
609     else if ( myDisplayMode == AIS_WireFrame )
610     {
611     }
612
613     // Coloring borders
614     colorShapeBorder( getActiveColor() );
615   }
616
617   if ( !theToDisplay || !isVisible() || myContext.IsNull() )
618     return;
619   
620   myContext->Display( myShape, theIsUpdateViewer );
621 }
622
623 QColor HYDROGUI_Shape::getActiveColor() const
624 {
625   return isHighlighted() ? myHighlightColor : myBorderColor;
626 }
627
628 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
629 {
630   return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
631 }
632
633 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
634 {
635   if ( myShape.IsNull() )
636     return;
637
638   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
639   if ( anAttributes.IsNull() )
640     return;
641
642   Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ), 
643                                getQuantityColorVal( theColor.green() ),
644                                getQuantityColorVal( theColor.blue() ),
645                                Quantity_TOC_RGB );
646   if ( myDisplayMode == AIS_Shaded )
647   {
648     if ( theColor.alpha() == 0 )
649     {
650       anAttributes->SetFaceBoundaryDraw( false );
651     }
652     else
653     {
654       anAttributes->SetFaceBoundaryDraw( true );
655
656       Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
657       if ( !aBoundaryAspect.IsNull() )
658         aBoundaryAspect->SetColor( aBorderColor );
659     }
660   }
661   else if ( myDisplayMode == AIS_WireFrame )
662   {
663     myShape->SetColor( aBorderColor );
664   }
665 }
666
667 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
668 {
669   QString aResult;
670   if( !theImageObj.IsNull() )
671   {
672     QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
673
674     int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
675     QString aPrefix = QString( "image_%1" ).arg( aStudyId );
676
677     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
678     anEntry.replace( ':', '_' );
679
680     QString anExtension = "bmp";
681
682     aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
683   }
684   return aResult;
685 }
686
687 void HYDROGUI_Shape::removeTextureFile() const
688 {
689   QFile aFile( getTextureFileName() );
690   if( aFile.exists() )
691     aFile.remove();
692 }
693
694 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
695 {
696   double aSizeLimit = (double)theSizeLimit;
697   double aWidth = (double)theImage.width();
698   double aHeight = (double)theImage.height();
699   if( aWidth > aSizeLimit || aHeight > aSizeLimit )
700   {
701     if( aWidth > aHeight )
702     {
703       aHeight /= ( aWidth / aSizeLimit );
704       aWidth = aSizeLimit;
705     }
706     else
707     {
708       aWidth /= ( aHeight / aSizeLimit );
709       aHeight = aSizeLimit;
710     }
711   }
712   return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );
713 }