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