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