Salome HOME
refs #661: implement a transparency feature for land cover maps.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_Shape.h>
20 #include <HYDROGUI_Tool.h>
21 #include <HYDROGUI_Polyline.h>
22
23 #include <HYDROData_Channel.h>
24 #include <HYDROData_Document.h>
25 #include <HYDROData_DummyObject3D.h>
26 #include <HYDROData_ImmersibleZone.h>
27 #include <HYDROData_Obstacle.h>
28 #include <HYDROData_PolylineXY.h>
29 #include <HYDROData_Polyline3D.h>
30 #include <HYDROData_Profile.h>
31 #include <HYDROData_ShapesGroup.h>
32 #include <HYDROData_Stream.h>
33 #include <HYDROData_Zone.h>
34 #include <HYDROData_LandCoverMap.h>
35
36 #include <AIS_Shape.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepBuilderAPI_MakeFace.hxx>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <Prs3d_IsoAspect.hxx>
41 #include <Prs3d_ShadingAspect.hxx>
42 #include <TopoDS.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Wire.hxx>
45 #include <TopExp_Explorer.hxx>
46
47 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
48                                 const Handle(HYDROData_Entity)&       theObject,
49                                 const int                             theZLayer )
50 : myContext( theContext ),
51   myObject( theObject ),
52   myZLayer( theZLayer ),
53   myIsHighlight( false ),
54   myFillingColor( Qt::transparent ),
55   myBorderColor( Qt::black ),
56   myHighlightColor( Qt::white ),
57   myIsToUpdate( false ),
58   myIsVisible( true ),
59   myDisplayMode( AIS_Shaded ),
60   mySelectionMode( AIS_Shape::SelectionMode( TopAbs_SHAPE ) )
61 {
62 }
63
64 HYDROGUI_Shape::~HYDROGUI_Shape()
65 {
66   erase( false );
67
68   if ( !myShape.IsNull() )
69     myShape.Nullify();
70 }
71
72 Handle(AIS_InteractiveContext) HYDROGUI_Shape::getContext() const
73 {
74   return myContext;
75 }
76
77 Handle(HYDROData_Entity) HYDROGUI_Shape::getObject() const
78 {
79   return myObject;
80 }
81
82 TopoDS_Shape HYDROGUI_Shape::getTopoShape() const
83 {
84   return myTopoShape;
85 }
86
87 bool HYDROGUI_Shape::getIsToUpdate() const
88 {
89   return myIsToUpdate;
90 }
91
92 void HYDROGUI_Shape::setIsToUpdate( bool theState )
93 {
94   myIsToUpdate = theState;
95 }
96
97 bool HYDROGUI_Shape::isVisible() const
98 {
99   return myIsVisible;
100 }
101
102 Handle(AIS_InteractiveObject) HYDROGUI_Shape::getAISObject() const
103 {
104   return myShape;
105 }
106
107 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
108 {
109   if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
110     return;
111
112   displayShape( theIsUpdateViewer );
113 }
114
115 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
116 {
117   if ( myContext.IsNull() || myShape.IsNull() )
118     return;
119
120   eraseShape( theIsUpdateViewer );
121 }
122
123 void HYDROGUI_Shape::update( bool isUpdateViewer,
124                              bool isDeactivateSelection )
125
126 {
127   setIsToUpdate( false );
128
129   if ( myContext.IsNull() )
130     return;
131
132   // Try to retrieve information from object
133   if ( !myObject.IsNull() )
134   {
135     Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
136   
137     if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
138     {
139       Handle(HYDROData_ImmersibleZone) aZoneObj =
140         Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
141
142       TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
143       if ( !aZoneShape.IsNull() ) {
144         if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
145           TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
146           setFace( aZoneFace, false, false, "" );
147         } else {
148           myTopoShape = aZoneShape;
149           //TODO: myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
150           myDisplayMode = AIS_Shaded;
151
152           buildShape();
153           updateShape( false, false );
154         }
155       }
156
157       QColor aFillingColor = aZoneObj->GetFillingColor();
158       QColor aBorderColor = aZoneObj->GetBorderColor();
159
160       setFillingColor( aFillingColor, false, false );
161       setBorderColor( aBorderColor, false, false );
162     }
163     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
164     {
165       Handle(HYDROData_PolylineXY) aPolyline =
166         Handle(HYDROData_PolylineXY)::DownCast( myObject );
167
168       TopoDS_Shape aPolylineShape = aPolyline->GetShape();
169
170       if ( !aPolylineShape.IsNull() ) {
171         if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
172           TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
173           setWire( aPolylineWire, false, false );  
174         } else {
175           myTopoShape = aPolylineShape;
176           // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
177           // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
178           myDisplayMode = AIS_Shaded;
179
180           buildShape();
181           updateShape( false, false );
182         }
183       }
184
185       QColor aWireColor = aPolyline->GetWireColor();
186       setBorderColor( aWireColor, false, false );
187     }
188     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
189     {
190       Handle(HYDROData_Polyline3D) aPolyline =
191         Handle(HYDROData_Polyline3D)::DownCast( myObject );
192
193       TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
194
195       if ( !aPolylineShape.IsNull() ) {
196         if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
197           TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
198           setWire( aPolylineWire, false, false );  
199         } else {
200           myTopoShape = aPolylineShape;
201           // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
202           // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
203           myDisplayMode = AIS_Shaded;
204
205           buildShape();
206           updateShape( false, false );
207         }
208       }
209
210       QColor aWireColor = aPolyline->GetBorderColor();
211       setBorderColor( aWireColor, false, false );
212     }
213     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
214     {
215       Handle(HYDROData_Zone) aZone =
216         Handle(HYDROData_Zone)::DownCast( myObject );
217
218       TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
219
220       setFace( aZoneFace, false, false, "" );
221       if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
222       {
223         // Red color for a zone with bathymetry conflict
224         setFillingColor( Qt::red );
225       }
226       else
227       {
228                     // Set the filling color for zone
229         setFillingColor( aZone->GetColor( Qt::darkBlue ) );
230       }
231     }
232     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
233     {
234       Handle(HYDROData_Profile) aProfile =
235         Handle(HYDROData_Profile)::DownCast( myObject );
236
237       TopoDS_Wire aProfileWire;
238
239       if ( aProfile->IsValid() ) {
240         TopoDS_Shape aProfileShape = aProfile->GetShape3D();
241
242         if ( !aProfileShape.IsNull() && 
243              aProfileShape.ShapeType() == TopAbs_WIRE ) {
244           aProfileWire = TopoDS::Wire( aProfileShape );
245         }
246       }
247
248       setWire( aProfileWire, false, false );  
249
250       QColor aWireColor = aProfile->GetBorderColor();
251       setBorderColor( aWireColor, false, false );
252     }
253     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
254               myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
255               myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
256     {
257       Handle(HYDROData_Object) aGeomObject =
258         Handle(HYDROData_Object)::DownCast( myObject );
259
260       TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
261
262       setShape( anObjShape, false, false );
263
264       QColor aFillingColor = aGeomObject->GetFillingColor();
265       QColor aBorderColor = aGeomObject->GetBorderColor();
266
267       setFillingColor( aFillingColor, false, false );
268       setBorderColor( aBorderColor, false, false );
269     }
270     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
271     {
272       Handle(HYDROData_DummyObject3D) anObject3D =
273         Handle(HYDROData_DummyObject3D)::DownCast( myObject );
274       TopoDS_Shape aShape3D = anObject3D->GetShape();
275
276       setShape( aShape3D, false, false );
277
278       QColor aFillingColor = anObject3D->GetFillingColor();
279       QColor aBorderColor = anObject3D->GetBorderColor();
280
281       setFillingColor( aFillingColor, false, false );
282       setBorderColor( aBorderColor, false, false );
283     }
284     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ShapesGroup) ) )
285     {
286       Handle(HYDROData_ShapesGroup) aShapesGroup =
287         Handle(HYDROData_ShapesGroup)::DownCast( myObject );
288
289       TopTools_SequenceOfShape aShapes;
290       aShapesGroup->GetShapes( aShapes );
291
292       TopoDS_Compound aCompound;
293       BRep_Builder aCompoundBuilder;
294       aCompoundBuilder.MakeCompound( aCompound );
295
296       for ( int i = 1, n = aShapes.Length(); i <= n; ++i )
297       {
298         const TopoDS_Shape& aShape = aShapes.Value( i );
299         aCompoundBuilder.Add( aCompound, aShape );
300       }
301
302       setShape( aCompound, false, false );  
303     }
304   }
305  
306   if ( myShape.IsNull() || !isVisible() )
307     return;
308
309   displayShape( isUpdateViewer );
310
311   if (isDeactivateSelection)
312     myContext->Deactivate(myShape);
313 }
314
315 void HYDROGUI_Shape::setVisible( const bool theState,
316                                  const bool theIsUpdateViewer )
317 {
318   myIsVisible = theState;
319
320   if ( myShape.IsNull() )
321     return;
322
323   if ( ( myIsVisible && myContext->IsDisplayed( myShape ) ) ||
324        ( !myIsVisible && !myContext->IsDisplayed( myShape ) ) )
325     return;
326
327   if ( myIsVisible ) {
328     displayShape( theIsUpdateViewer );
329   }
330   else
331     eraseShape( theIsUpdateViewer );
332 }
333
334 void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
335 {
336   if ( myIsHighlight == theIsHighlight )
337     return;
338
339   myIsHighlight = theIsHighlight;
340
341   if ( myContext.IsNull() || myShape.IsNull() )
342     return;
343
344   colorShapeBorder( getActiveColor() );
345   displayShape( isUpdateViewer );
346 }
347
348 bool HYDROGUI_Shape::isHighlighted() const
349 {
350   return myIsHighlight;
351 }
352
353 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
354                               const bool         theToDisplay,
355                               const bool         theIsUpdateViewer )
356 {
357   myTopoShape = theWire;
358   // To avoid that hilight presentation is equal to "normal" object presentation.
359   // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
360   myDisplayMode = AIS_Shaded;
361
362   buildShape();
363   updateShape( theToDisplay, theIsUpdateViewer );
364 }
365
366 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
367                                const bool             theToDisplay,
368                                const bool             theIsUpdateViewer )
369 {
370   TopExp_Explorer anExp( theWires, TopAbs_WIRE );
371   TopoDS_Compound aCompound;
372   BRep_Builder aBuilder;
373     aBuilder.MakeCompound( aCompound );
374
375   for ( ; anExp.More(); anExp.Next() ) {
376     TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
377     if ( aWire.IsNull() ) {
378       continue;
379     }
380
381     BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
382     aMakeFace.Build();
383     if( aMakeFace.IsDone() ) {
384       aBuilder.Add( aCompound, aMakeFace.Face() );
385     }
386   }
387
388   myTopoShape = aCompound;
389   myDisplayMode = AIS_Shaded;
390
391   buildShape();
392   updateShape( theToDisplay, theIsUpdateViewer );
393 }
394
395 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
396                               const bool         theToDisplay,
397                               const bool         theIsUpdateViewer,
398                               const QString&     theTextureFileName )
399 {
400   BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
401   aFaceBuilder.Build();
402   if( aFaceBuilder.IsDone() )
403   {
404     TopoDS_Face aFace = aFaceBuilder.Face();
405     setFace( aFace, theToDisplay, theIsUpdateViewer, theTextureFileName );
406   }
407 }
408
409 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
410                               const bool         theToDisplay,
411                               const bool         theIsUpdateViewer,
412                               const QString&     theTextureFileName )
413 {
414   myTopoShape = theFace;
415   myDisplayMode = theTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
416   //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
417   //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
418
419   buildShape();
420   updateShape( theToDisplay, theIsUpdateViewer );
421 }
422
423 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
424                                const bool          theToDisplay,
425                                const bool          theIsUpdateViewer )
426 {
427   myTopoShape = theShape;
428   myDisplayMode = AIS_Shaded;
429
430   buildShape();
431   updateShape( theToDisplay, theIsUpdateViewer );
432 }
433
434 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
435                                       const bool    theToDisplay,
436                                       const bool    theIsUpdateViewer )
437 {
438   myFillingColor = theColor;
439   updateShape( theToDisplay, theIsUpdateViewer );
440 }
441
442 QColor HYDROGUI_Shape::getFillingColor() const
443 {
444   return myFillingColor;
445 }
446
447 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
448                                      const bool    theToDisplay,
449                                      const bool    theIsUpdateViewer )
450
451   myBorderColor = theColor;
452   updateShape( theToDisplay, theIsUpdateViewer );
453 }
454
455 QColor HYDROGUI_Shape::getBorderColor() const
456 {
457   return myBorderColor;
458 }
459
460 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
461 {
462   myHighlightColor = theColor;
463 }
464
465 QColor HYDROGUI_Shape::getHighlightColor() const
466 {
467   return myHighlightColor;
468 }
469
470 void HYDROGUI_Shape::setZLayer( const int theZLayer )
471 {
472   if ( myZLayer == theZLayer )
473     return;
474
475   myZLayer = theZLayer;
476   if ( !myShape.IsNull() && isVisible() && !myContext.IsNull() && myZLayer >= 0 )
477     myContext->SetZLayer( myShape, myZLayer );
478 }
479
480 Handle_AIS_InteractiveObject HYDROGUI_Shape::createShape() const
481 {
482   if( myTopoShape.IsNull() ) {
483     return Handle_AIS_InteractiveObject();
484   }
485
486   TopAbs_ShapeEnum aShapeType = myTopoShape.ShapeType();
487   bool IsWireEdgeCompound = aShapeType==TopAbs_COMPOUND;
488   if (IsWireEdgeCompound) {
489     TopoDS_Iterator itr(myTopoShape);
490     while (itr.More() && IsWireEdgeCompound) {
491       if (itr.Value().ShapeType() != TopAbs_WIRE && itr.Value().ShapeType() != TopAbs_EDGE)
492         IsWireEdgeCompound = false;
493       itr.Next();
494     }
495   }
496
497   if ( aShapeType==TopAbs_EDGE || aShapeType==TopAbs_WIRE || IsWireEdgeCompound) {
498     return new HYDROGUI_Polyline( myTopoShape );
499   } else {
500     return new AIS_Shape( myTopoShape );
501   }
502 }
503
504 void HYDROGUI_Shape::buildShape()
505 {
506   // Erase previously created shape
507   erase();
508
509   myShape = createShape();
510   if( myShape.IsNull() )
511     return;
512
513   Handle_AIS_Shape anAISShape = Handle_AIS_Shape::DownCast( myShape );
514   if( !anAISShape.IsNull() )
515     anAISShape ->SetHLRAngleAndDeviation( 0.001 );
516
517   if ( !myObject.IsNull() )
518     myShape->SetOwner( myObject );
519
520   if ( !myObject->IsKind( STANDARD_TYPE(HYDROData_LandCoverMap) ) )
521     myShape->SetTransparency( 0 );
522   myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
523   myShape->SetSelectionMode( (Standard_Integer)mySelectionMode );
524
525     // Init default params for shape
526   const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes();
527   if ( !anAttributes.IsNull() )
528   {
529     Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
530     if ( !anIsoAspect.IsNull() ) {
531       anIsoAspect->SetNumber( 0 );
532       anAttributes->SetUIsoAspect( anIsoAspect );
533     }
534       
535     anIsoAspect = anAttributes->VIsoAspect();
536     if ( !anIsoAspect.IsNull() ) {
537       anIsoAspect->SetNumber( 0 );
538       anAttributes->SetVIsoAspect( anIsoAspect );
539     }
540
541     if ( myDisplayMode == AIS_Shaded )
542     {
543       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
544       if ( !aShadingAspect.IsNull() )
545       {
546         Graphic3d_MaterialAspect aMatAspect( Graphic3d_NOM_PLASTIC );
547         //aMatAspect.SetAmbient( 1 );
548         //aMatAspect.SetDiffuse( 0 );
549
550         aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
551         aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
552       }
553     }
554     else if ( myDisplayMode == AIS_WireFrame )
555     {
556       anAttributes->SetWireDraw( true );
557     }
558   }
559 }
560
561 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
562                                   const bool theIsUpdateViewer )
563 {
564   if ( myShape.IsNull() )
565     return;
566
567   const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes();
568   if ( !anAttributes.IsNull() )
569   {
570     if ( myDisplayMode == AIS_Shaded )
571     {
572       // Coloring face filling
573       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
574       if ( !aShadingAspect.IsNull() )
575       {
576         Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ), 
577                                       getQuantityColorVal( myFillingColor.green() ),
578                                       getQuantityColorVal( myFillingColor.blue() ),
579                                       Quantity_TOC_RGB );
580
581         aShadingAspect->SetColor( aFillingColor );
582         aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
583       }
584     }
585     else if ( myDisplayMode == AIS_WireFrame )
586     {
587     }
588
589     // Coloring borders
590     colorShapeBorder( getActiveColor() );
591   }
592
593   if ( !theToDisplay || !isVisible() || myContext.IsNull() )
594     return;
595   
596   displayShape( theIsUpdateViewer );
597 }
598
599 void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
600 {
601   if ( myContext->HasOpenedContext() && mySelectionMode > 0 )
602     myContext->CloseLocalContext();
603
604   if ( mySelectionMode > 0 )
605     // Display object in local context with selection
606     myContext->Display( myShape, myDisplayMode, mySelectionMode, Standard_False, Standard_False );
607   else
608   {
609     if ( !myContext->HasOpenedContext() )
610       // Ordinary display of object published in the Object Browser
611       myContext->Display( myShape, Standard_False );
612     else
613       // Display object in local context without selection
614       myContext->Display( myShape, myDisplayMode, -1, Standard_False, Standard_False );
615   }
616   
617   if ( mySelectionMode > 0 )
618   {
619     myContext->OpenLocalContext();
620     myContext->Activate( myShape, mySelectionMode, Standard_True );
621   }
622
623   if ( myZLayer >= 0 )
624     myContext->SetZLayer( myShape, myZLayer );
625
626   if ( theIsUpdateViewer ) {
627     myContext->UpdateCurrentViewer();
628   }
629 }
630
631 void HYDROGUI_Shape::eraseShape( const bool theIsUpdateViewer )
632 {
633   if ( myContext->HasOpenedContext() && mySelectionMode > 0 )
634     myContext->CloseLocalContext();
635
636   myContext->Erase( myShape, theIsUpdateViewer );
637 }
638
639 QColor HYDROGUI_Shape::getActiveColor() const
640 {
641   return isHighlighted() ? myHighlightColor : myBorderColor;
642 }
643
644 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
645 {
646   return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
647 }
648
649 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
650 {
651   if ( myShape.IsNull() )
652     return;
653
654   const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes();
655   if ( anAttributes.IsNull() )
656     return;
657
658   Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ), 
659                                getQuantityColorVal( theColor.green() ),
660                                getQuantityColorVal( theColor.blue() ),
661                                Quantity_TOC_RGB );
662   
663   if( !myTopoShape.IsNull() )
664   {
665     if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode
666     {
667       myShape->SetColor( aBorderColor );
668     }
669     else if ( myDisplayMode == AIS_Shaded )
670     {
671       if ( theColor.alpha() == 0 )
672       {
673         anAttributes->SetFaceBoundaryDraw( false );
674       }
675       else
676       {
677         anAttributes->SetFaceBoundaryDraw( true );
678   
679         Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
680         if ( !aBoundaryAspect.IsNull() )
681         {
682           aBoundaryAspect->SetColor( aBorderColor );
683           anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
684         }
685         Handle(Prs3d_LineAspect) aWireAspect = anAttributes->WireAspect();
686         if ( !aWireAspect.IsNull() )
687         {
688           aWireAspect->SetColor( aBorderColor );
689           anAttributes->SetWireAspect( aWireAspect );
690         }
691       }
692     }
693     else if ( myDisplayMode == AIS_WireFrame )
694     {
695       myShape->SetColor( aBorderColor );
696     }
697   }
698 }
699
700 void HYDROGUI_Shape::setDisplayMode( int theDisplayMode )
701 {
702   myDisplayMode = theDisplayMode;
703 }
704
705 void HYDROGUI_Shape::setSelectionMode( int theSelectionMode )
706 {
707   mySelectionMode = theSelectionMode;
708 }