1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Shape.h"
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Tool.h"
28 #include <AIS_Drawer.hxx>
29 #include <AIS_TexturedShape.hxx>
30 #include <AIS_PointCloud.hxx>
31 #include <V3d_Viewer.hxx>
33 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <BRepBuilderAPI_MakeWire.hxx>
35 #include <BRepBuilderAPI_MakeFace.hxx>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <Graphic3d_MaterialAspect.hxx>
42 #include <Aspect_ColorScale.hxx>
44 #include <HYDROData_Channel.h>
45 #include <HYDROData_Document.h>
46 #include <HYDROData_Bathymetry.h>
47 #include <HYDROData_DummyObject3D.h>
48 #include <HYDROData_Image.h>
49 #include <HYDROData_ImmersibleZone.h>
50 #include <HYDROData_Obstacle.h>
51 #include <HYDROData_PolylineXY.h>
52 #include <HYDROData_Polyline3D.h>
53 #include <HYDROData_Profile.h>
54 #include <HYDROData_Region.h>
55 #include <HYDROData_ShapesGroup.h>
56 #include <HYDROData_Stream.h>
57 #include <HYDROData_Zone.h>
60 #include <TopoDS_Wire.hxx>
61 #include <TopoDS_Face.hxx>
63 #include <TopExp_Explorer.hxx>
65 #include <BRep_Builder.hxx>
67 #include <Precision.hxx>
69 #include <Prs3d_ShadingAspect.hxx>
70 #include <Prs3d_LineAspect.hxx>
71 #include <Prs3d_IsoAspect.hxx>
72 #include <Prs3d_PointAspect.hxx>
73 #include <SUIT_MessageBox.h>
78 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
79 const Handle(HYDROData_Entity)& theObject,
81 : myContext( theContext ),
82 myObject( theObject ),
83 myZLayer( theZLayer ),
84 myIsHighlight( false ),
85 myFillingColor( Qt::transparent ),
86 myBorderColor( Qt::black ),
87 myHighlightColor( Qt::white ),
88 myIsToUpdate( false ),
90 myDisplayMode( AIS_WireFrame )
94 HYDROGUI_Shape::~HYDROGUI_Shape()
98 if ( !myShape.IsNull() )
104 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
106 if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
109 displayShape( theIsUpdateViewer );
112 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
114 if ( myContext.IsNull() || myShape.IsNull() )
117 myContext->Erase( myShape, theIsUpdateViewer );
120 void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
122 setIsToUpdate( false );
124 if ( myContext.IsNull() )
127 bool isDeactivateSelection = false;
128 // Try to retrieve information from object
129 if ( !myObject.IsNull() )
131 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
133 if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
135 Handle(HYDROData_ImmersibleZone) aZoneObj =
136 Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
138 TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
139 if ( !aZoneShape.IsNull() ) {
140 if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
141 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
142 setFace( aZoneFace, false, false );
144 myTopoShape = aZoneShape;
145 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
148 updateShape( false, false );
152 QColor aFillingColor = aZoneObj->GetFillingColor();
153 QColor aBorderColor = aZoneObj->GetBorderColor();
155 setFillingColor( aFillingColor, false, false );
156 setBorderColor( aBorderColor, false, false );
158 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
160 Handle(HYDROData_PolylineXY) aPolyline =
161 Handle(HYDROData_PolylineXY)::DownCast( myObject );
163 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
165 if ( !aPolylineShape.IsNull() ) {
166 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
167 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
168 setWire( aPolylineWire, false, false );
170 myTopoShape = aPolylineShape;
171 // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
172 // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
173 myDisplayMode = AIS_Shaded;
176 updateShape( false, false );
180 QColor aWireColor = aPolyline->GetWireColor();
181 setBorderColor( aWireColor, false, false );
183 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
185 Handle(HYDROData_Polyline3D) aPolyline =
186 Handle(HYDROData_Polyline3D)::DownCast( myObject );
188 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
190 if ( !aPolylineShape.IsNull() ) {
191 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
192 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
193 setWire( aPolylineWire, false, false );
195 myTopoShape = aPolylineShape;
196 // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
197 // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
198 myDisplayMode = AIS_Shaded;
201 updateShape( false, false );
205 QColor aWireColor = aPolyline->GetBorderColor();
206 setBorderColor( aWireColor, false, false );
208 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
210 Handle(HYDROData_Zone) aZone =
211 Handle(HYDROData_Zone)::DownCast( myObject );
213 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
215 setFace( aZoneFace, false, false );
216 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
218 // Red color for a zone with bathymetry conflict
219 setFillingColor( Qt::red );
223 // Generate the filling color for zone
224 QStringList aGeomObjectsNames;
226 HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
227 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
228 for ( ; anIter.More(); anIter.Next() )
230 Handle(HYDROData_Object) aRefbject =
231 Handle(HYDROData_Object)::DownCast( anIter.Value() );
232 if ( aRefbject.IsNull() )
235 QString aRefObjectName = aRefbject->GetName();
236 if ( aRefObjectName.isEmpty() )
239 aGeomObjectsNames.append( aRefObjectName );
242 setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
245 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
247 Handle(HYDROData_Image) anImageObj =
248 Handle(HYDROData_Image)::DownCast( myObject );
252 QString aTextureFileName = generateTextureFileName( anImageObj );
254 QImage anImage = anImageObj->Image();
255 QString aFilePath = anImageObj->GetFilePath();
256 QTransform aTrsf = anImageObj->Trsf();
258 int aWidth = anImage.width();
259 int aHeight = anImage.height();
261 QString anImageError = "";
263 QTransform anInversion = QTransform::fromScale( -1, -1 );
264 anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
266 if ( anImage.isNull() )
267 anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" );
270 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
271 int aTrsfWidth = anImage.width();
272 int aDelta = aTrsfWidth % 4;
275 aTrsfWidth += ( 4 - aDelta );
277 anImage = anImage.scaledToWidth( aTrsfWidth );
279 // temporary optimization, to reduce the saved image size (and the texture quality)
280 QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
282 bool isSaved = anImageToSave.save( aTextureFileName );
284 anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
286 QFile::setPermissions( aTextureFileName, (QFile::Permissions)0x4FFFF );
289 if ( !anImageError.isEmpty() )
291 SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ),
292 QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError );
295 QPointF aPoint1( 0, 0 ); // 1: top left
296 QPointF aPoint2( aWidth, 0 ); // 2: top right
297 QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
298 QPointF aPoint4( 0, aHeight ); // 4: bottom left
300 aPoint1 = aTrsf.map( aPoint1 );
301 aPoint2 = aTrsf.map( aPoint2 );
302 aPoint3 = aTrsf.map( aPoint3 );
303 aPoint4 = aTrsf.map( aPoint4 );
305 QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
306 QRectF aRect = aPolygon.boundingRect();
308 gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
309 gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
310 gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
311 gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
313 Handle_HYDROData_Document aDoc = HYDROData_Document::Document( anImageObj->Label() );
314 aDoc->Transform( aPnt1, true );
315 aDoc->Transform( aPnt2, true );
316 aDoc->Transform( aPnt3, true );
317 aDoc->Transform( aPnt4, true );
319 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
320 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
321 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
322 TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
324 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
325 aWire.Closed( true );
327 setTextureFileName( aTextureFileName, false, false );
328 setFace( aWire, false, false );
329 isDeactivateSelection = true;
331 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
333 Handle(HYDROData_Profile) aProfile =
334 Handle(HYDROData_Profile)::DownCast( myObject );
336 TopoDS_Wire aProfileWire;
338 if ( aProfile->IsValid() ) {
339 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
341 if ( !aProfileShape.IsNull() &&
342 aProfileShape.ShapeType() == TopAbs_WIRE ) {
343 aProfileWire = TopoDS::Wire( aProfileShape );
347 setWire( aProfileWire, false, false );
349 QColor aWireColor = aProfile->GetBorderColor();
350 setBorderColor( aWireColor, false, false );
352 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
353 myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
354 myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
356 Handle(HYDROData_Object) aGeomObject =
357 Handle(HYDROData_Object)::DownCast( myObject );
359 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
361 setShape( anObjShape, false, false );
363 QColor aFillingColor = aGeomObject->GetFillingColor();
364 QColor aBorderColor = aGeomObject->GetBorderColor();
366 setFillingColor( aFillingColor, false, false );
367 setBorderColor( aBorderColor, false, false );
369 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
371 Handle(HYDROData_DummyObject3D) anObject3D =
372 Handle(HYDROData_DummyObject3D)::DownCast( myObject );
373 TopoDS_Shape aShape3D = anObject3D->GetShape();
375 setShape( aShape3D, false, false );
377 QColor aFillingColor = anObject3D->GetFillingColor();
378 QColor aBorderColor = anObject3D->GetBorderColor();
380 setFillingColor( aFillingColor, false, false );
381 setBorderColor( aBorderColor, false, false );
383 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ShapesGroup) ) )
385 Handle(HYDROData_ShapesGroup) aShapesGroup =
386 Handle(HYDROData_ShapesGroup)::DownCast( myObject );
388 TopTools_SequenceOfShape aShapes;
389 aShapesGroup->GetShapes( aShapes );
391 TopoDS_Compound aCompound;
392 BRep_Builder aCompoundBuilder;
393 aCompoundBuilder.MakeCompound( aCompound );
395 for ( int i = 1, n = aShapes.Length(); i <= n; ++i )
397 const TopoDS_Shape& aShape = aShapes.Value( i );
398 aCompoundBuilder.Add( aCompound, aShape );
401 setShape( aCompound, false, false );
403 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Bathymetry) ) )
406 updateShape( false, false );
410 if ( myShape.IsNull() || !isVisible() )
413 displayShape( theIsUpdateViewer );
415 if (isDeactivateSelection)
416 myContext->Deactivate(myShape);
419 void HYDROGUI_Shape::setVisible( const bool theState,
420 const bool theIsUpdateViewer )
422 myIsVisible = theState;
424 if ( myShape.IsNull() )
427 if ( ( myIsVisible && myContext->IsDisplayed( myShape ) ) ||
428 ( !myIsVisible && !myContext->IsDisplayed( myShape ) ) )
432 displayShape( theIsUpdateViewer );
435 myContext->Erase( myShape, theIsUpdateViewer );
438 void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
440 if ( myIsHighlight == theIsHighlight )
443 myIsHighlight = theIsHighlight;
445 if ( myContext.IsNull() || myShape.IsNull() )
448 colorShapeBorder( getActiveColor() );
449 displayShape( isUpdateViewer );
452 bool HYDROGUI_Shape::isHighlighted() const
454 return myIsHighlight;
457 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
458 const bool theToDisplay,
459 const bool theIsUpdateViewer )
461 myTopoShape = theWire;
462 // To avoid that hilight presentation is equal to "normal" object presentation.
463 // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
464 myDisplayMode = AIS_Shaded;
467 updateShape( theToDisplay, theIsUpdateViewer );
470 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
471 const bool theToDisplay,
472 const bool theIsUpdateViewer )
474 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
475 TopoDS_Compound aCompound;
476 BRep_Builder aBuilder;
477 aBuilder.MakeCompound( aCompound );
479 for ( ; anExp.More(); anExp.Next() ) {
480 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
481 if ( aWire.IsNull() ) {
485 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
487 if( aMakeFace.IsDone() ) {
488 aBuilder.Add( aCompound, aMakeFace.Face() );
492 myTopoShape = aCompound;
493 myDisplayMode = AIS_Shaded;
496 updateShape( theToDisplay, theIsUpdateViewer );
499 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
500 const bool theToDisplay,
501 const bool theIsUpdateViewer )
503 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
504 aFaceBuilder.Build();
505 if( aFaceBuilder.IsDone() )
507 TopoDS_Face aFace = aFaceBuilder.Face();
508 setFace( aFace, theToDisplay, theIsUpdateViewer );
512 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
513 const bool theToDisplay,
514 const bool theIsUpdateViewer )
516 myTopoShape = theFace;
517 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
518 //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
519 //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
522 updateShape( theToDisplay, theIsUpdateViewer );
525 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
526 const bool theToDisplay,
527 const bool theIsUpdateViewer )
529 myTopoShape = theShape;
530 myDisplayMode = AIS_Shaded;
533 updateShape( theToDisplay, theIsUpdateViewer );
536 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
537 const bool theToDisplay,
538 const bool theIsUpdateViewer )
540 myFillingColor = theColor;
541 updateShape( theToDisplay, theIsUpdateViewer );
544 QColor HYDROGUI_Shape::getFillingColor() const
546 return myFillingColor;
549 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
550 const bool theToDisplay,
551 const bool theIsUpdateViewer )
553 myBorderColor = theColor;
554 updateShape( theToDisplay, theIsUpdateViewer );
557 QColor HYDROGUI_Shape::getBorderColor() const
559 return myBorderColor;
562 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
564 myHighlightColor = theColor;
567 QColor HYDROGUI_Shape::getHighlightColor() const
569 return myHighlightColor;
572 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
573 const bool theToDisplay,
574 const bool theIsUpdateViewer )
576 myTextureFileName = theFileName;
577 updateShape( theToDisplay, theIsUpdateViewer );
580 QString HYDROGUI_Shape::getTextureFileName() const
582 return myTextureFileName;
585 void HYDROGUI_Shape::setZLayer( const int theZLayer )
587 if ( myZLayer == theZLayer )
590 myZLayer = theZLayer;
591 if ( !myShape.IsNull() && isVisible() && !myContext.IsNull() && myZLayer >= 0 )
592 myContext->SetZLayer( myShape, myZLayer );
595 #include <NCollection_Sequence.hxx>
596 void HYDROGUI_Shape::buildShape()
598 // Erase previously created shape
601 Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( myObject );
602 bool isBath = !aBath.IsNull();
604 if( !isBath && myTopoShape.IsNull() ) {
609 QString aTextureFileName = getTextureFileName();
610 bool anIsTexture = !aTextureFileName.isEmpty();
613 myShape = new AIS_TexturedShape( myTopoShape );
617 Handle_AIS_PointCloud aPntCloud = new AIS_PointCloud();
618 aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0));
621 const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
622 int aLower = aBathPoints.Lower();
623 int anUpper = aBathPoints.Upper();
624 myCoords = new TColgp_HArray1OfPnt( aLower, anUpper );
625 myColors = new Quantity_HArray1OfColor( aLower, anUpper );
626 for( int i=aLower; i<=anUpper; i++ )
627 myCoords->SetValue( i, aBathPoints.Value( i ) );
631 myShape = new AIS_Shape( myTopoShape );
634 Handle_AIS_Shape anAISShape = Handle_AIS_Shape::DownCast( myShape );
635 if( !anAISShape.IsNull() )
636 anAISShape ->SetHLRAngleAndDeviation( 0.001 );
638 if ( !myObject.IsNull() )
639 myShape->SetOwner( myObject );
641 myShape->SetTransparency( 0 );
642 myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
646 Handle(AIS_TexturedShape) aTexturedShape =
647 Handle(AIS_TexturedShape)::DownCast( myShape );
649 aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
650 aTexturedShape->SetTextureMapOn();
651 // Just use the texture image as is
652 aTexturedShape->DisableTextureModulate();
653 aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
656 // Init default params for shape
657 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
658 if ( !anAttributes.IsNull() )
660 Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
661 if ( !anIsoAspect.IsNull() ) {
662 anIsoAspect->SetNumber( 0 );
663 anAttributes->SetUIsoAspect( anIsoAspect );
666 anIsoAspect = anAttributes->VIsoAspect();
667 if ( !anIsoAspect.IsNull() ) {
668 anIsoAspect->SetNumber( 0 );
669 anAttributes->SetVIsoAspect( anIsoAspect );
672 if ( myDisplayMode == AIS_Shaded )
674 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
675 if ( !aShadingAspect.IsNull() )
677 Graphic3d_MaterialAspect aMatAspect( Graphic3d_NOM_PLASTIC );
678 //aMatAspect.SetAmbient( 1 );
679 //aMatAspect.SetDiffuse( 0 );
681 aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
682 aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
685 else if ( myDisplayMode == AIS_WireFrame )
687 anAttributes->SetWireDraw( true );
692 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
693 const bool theIsUpdateViewer )
695 if ( myShape.IsNull() )
698 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
699 if ( !anAttributes.IsNull() )
701 if ( myDisplayMode == AIS_Shaded )
703 // Coloring face filling
704 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
705 if ( !aShadingAspect.IsNull() )
707 Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ),
708 getQuantityColorVal( myFillingColor.green() ),
709 getQuantityColorVal( myFillingColor.blue() ),
712 aShadingAspect->SetColor( aFillingColor );
713 aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
716 else if ( myDisplayMode == AIS_WireFrame )
721 colorShapeBorder( getActiveColor() );
724 if ( !theToDisplay || !isVisible() || myContext.IsNull() )
727 displayShape( theIsUpdateViewer );
730 void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
732 myContext->Display( myShape, Standard_False );
735 myContext->SetZLayer( myShape, myZLayer );
737 myContext->UpdateCurrentViewer();
740 QColor HYDROGUI_Shape::getActiveColor() const
742 return isHighlighted() ? myHighlightColor : myBorderColor;
745 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
747 return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
750 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
752 if ( myShape.IsNull() )
755 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
756 if ( anAttributes.IsNull() )
759 Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ),
760 getQuantityColorVal( theColor.green() ),
761 getQuantityColorVal( theColor.blue() ),
764 if( !myTopoShape.IsNull() )
766 if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode
768 myShape->SetColor( aBorderColor );
770 else if ( myDisplayMode == AIS_Shaded )
772 if ( theColor.alpha() == 0 )
774 anAttributes->SetFaceBoundaryDraw( false );
778 anAttributes->SetFaceBoundaryDraw( true );
780 Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
781 if ( !aBoundaryAspect.IsNull() )
783 aBoundaryAspect->SetColor( aBorderColor );
784 anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
786 Handle(Prs3d_LineAspect) aWireAspect = anAttributes->WireAspect();
787 if ( !aWireAspect.IsNull() )
789 aWireAspect->SetColor( aBorderColor );
790 anAttributes->SetWireAspect( aWireAspect );
794 else if ( myDisplayMode == AIS_WireFrame )
796 myShape->SetColor( aBorderColor );
801 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
804 if( !theImageObj.IsNull() )
806 QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
808 int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
809 QString aPrefix = QString( "image_%1" ).arg( aStudyId );
811 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
812 anEntry.replace( ':', '_' );
814 QString anExtension = "bmp";
816 aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
821 void HYDROGUI_Shape::removeTextureFile() const
823 QFile aFile( getTextureFileName() );
828 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
830 double aSizeLimit = (double)theSizeLimit;
831 double aWidth = (double)theImage.width();
832 double aHeight = (double)theImage.height();
833 if( aWidth > aSizeLimit || aHeight > aSizeLimit )
835 if( aWidth > aHeight )
837 aHeight /= ( aWidth / aSizeLimit );
842 aWidth /= ( aHeight / aSizeLimit );
843 aHeight = aSizeLimit;
846 return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );
849 void HYDROGUI_Shape::GetRange( double& theMin, double& theMax ) const
853 if( myCoords.IsNull() )
857 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
859 double aValue = myCoords->Value( i ).Z();
860 if( isFirst || aValue < theMin )
862 if( isFirst || aValue > theMax )
868 void HYDROGUI_Shape::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
870 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
872 double z = myCoords->Value( i ).Z();
873 Quantity_Color aColor;
874 theColorScale->FindColor( z, aColor );
875 myColors->SetValue( i, aColor );
877 Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( myShape );
878 aPntCloud->SetPoints( myCoords, myColors );
879 myContext->Redisplay( aPntCloud, Standard_False );