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