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