//
#include <HYDROGUI_BathymetryPrs.h>
-#include <Prs3d_Presentation.hxx>
+#include <HYDROGUI_Tool.h>
+
#include <Prs3d_Root.hxx>
#include <Prs3d_LineAspect.hxx>
-#include <SelectMgr_EntityOwner.hxx>
-#include <SelectMgr_Selection.hxx>
+#include <Prs3d_Text.hxx>
+#include <Prs3d_TextAspect.hxx>
#include <Select3D_SensitiveBox.hxx>
-#include <Graphic3d_Group.hxx>
+#include <Select3D_SensitivePoint.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Image_PixMap.hxx>
+#include <Graphic3d_MarkerImage.hxx>
+
+#include <QImage>
const int BATH_HIGHLIGHT_MODE = 10;
-HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs()
+HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs( const HYDROGUI_ShapeBathymetry* theShape )
+ : myShape( theShape )
{
SetHilightMode( BATH_HIGHLIGHT_MODE );
+ SetAutoHilight( Standard_True );
}
HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
{
}
-void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords,
- const Handle(Quantity_HArray1OfColor)& theColors )
+HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const
+{
+ return const_cast<HYDROGUI_ShapeBathymetry*>( myShape );
+}
+
+void HYDROGUI_BathymetryPrs::UpdateBound()
{
+ Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
myBound.SetVoid();
- if( !theCoords.IsNull() )
+ if( !points.IsNull() )
{
- int aLower = theCoords->Lower();
- int anUpper = theCoords->Upper();
+ int aLower = 1;
+ int anUpper = points->VertexNumber();
for( int i = aLower; i <= anUpper; i++ )
{
+ gp_Pnt p = points->Vertice( i );
if( i==aLower )
- myBound.Set( theCoords->Value( i ) );
+ myBound.Set( p );
else
- {
- gp_Pnt aPnt = theCoords->Value( i );
- myBound.Update( aPnt.X(), aPnt.Y(), aPnt.Z() );
- }
+ myBound.Update( p.X(), p.Y(), p.Z() );
}
}
+}
+
+void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords,
+ const Handle(Quantity_HArray1OfColor)& theColors )
+{
AIS_PointCloud::SetPoints( theCoords, theColors );
+ UpdateBound();
}
void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode )
{
+ thePresentation->Clear();
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
+
if( theMode==BATH_HIGHLIGHT_MODE )
{
- thePresentation->Clear();
+ if( myBound.IsVoid() )
+ UpdateBound();
+
+
if( myBound.IsVoid() ||
myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0 );
aGroup->SetPrimitivesAspect( aWireAspect->Aspect() );
aGroup->AddPrimitiveArray( aLines );
}
else
+ {
+ Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_USERDEFINED, Quantity_NOC_WHITE, 1.0 );
+ QImage qtMark( 4, 4, QImage::Format_RGB888 );
+ Handle(Image_PixMap) aMark = HYDROGUI_Tool::Pixmap( qtMark );
+ Handle(Graphic3d_MarkerImage) gMark = new Graphic3d_MarkerImage(aMark);
+ anAspect->SetMarkerImage(gMark);
AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode );
+ aGroup->SetGroupPrimitivesAspect( anAspect );
+
+ Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
+ if( !myTextIndices.empty() && !points.IsNull() )
+ {
+ char aBuf[1024];
+ Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect();
+
+ foreach( int index, myTextIndices )
+ {
+ gp_Pnt p = points->Vertice( index );
+ sprintf( aBuf, "%.2f", p.Z() );
+ Prs3d_Text::Draw( aGroup, anAspect, aBuf, p );
+ }
+ }
+ }
}
void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
{
if( theMode == 0 )
{
+ if( myBound.IsVoid() )
+ UpdateBound();
+
if( myBound.IsVoid() ||
myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
theSelection->Add( aSensitiveBox );
}
+ if( theMode == 1 )
+ {
+ Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
+ int n = points.IsNull() ? 0 : points->VertexNumber();
+ for( int i=1; i<=n; i++ )
+ {
+ gp_Pnt p = points->Vertice( i );
+ Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i );
+ Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p );
+ theSelection->Add( aSensitivePoint );
+ }
+ }
+}
+
+int HYDROGUI_BathymetryPrs::NbPoints() const
+{
+ Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
+ int n = points.IsNull() ? 0 : points->VertexNumber();
+ return n;
+}
+
+gp_Pnt HYDROGUI_BathymetryPrs::GetPoint( int theIndex ) const
+{
+ Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
+ if( points.IsNull() )
+ return gp_Pnt();
+ else
+ return points->Vertice( theIndex );
+}
+
+void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& thePoints,
+ const Handle(SelectMgr_EntityOwner)& theOwner )
+{
+ Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwner );
+ if( anOwner.IsNull() )
+ return;
+ gp_Pnt p = GetPoint( anOwner->GetIndex() );
+ thePoints->AddVertex( p );
+}
+
+void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const Handle(Graphic3d_HighlightStyle)& theColor,
+ const Handle(SelectMgr_EntityOwner)& theOwner )
+{
+ Handle(Prs3d_Presentation) aHilightPrs = GetHilightPresentation( thePM );
+ aHilightPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
+ aHilightPrs->Clear();
+ Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( 1 );
+ AddPoint( points, theOwner );
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aHilightPrs );
+ Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
+ aGroup->SetGroupPrimitivesAspect( anAspect );
+ aGroup->AddPrimitiveArray( points );
+
+ if( thePM->IsImmediateModeOn() )
+ thePM->AddToImmediateList( aHilightPrs );
+}
+
+void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const SelectMgr_SequenceOfOwner& theOwners )
+{
+ Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM );
+ aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
+ aSelectPrs->Clear();
+
+ Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() );
+ for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ )
+ AddPoint( points, theOwners.Value( i ) );
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs );
+ Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
+ aGroup->SetGroupPrimitivesAspect( anAspect );
+ aGroup->AddPrimitiveArray( points );
+
+ aSelectPrs->SetDisplayPriority(9);
+ aSelectPrs->Display();
+}
+
+void HYDROGUI_BathymetryPrs::ClearSelected()
+{
+ Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( NULL );
+ if( !aSelectPrs.IsNull() )
+ aSelectPrs->Clear();
+}
+
+void HYDROGUI_BathymetryPrs::SetTextLabels( const QVector<int>& theTextIndices )
+{
+ myTextIndices = theTextIndices;
+}
+
+
+
+
+
+
+
+HYDROGUI_BathymetryPointOwner::HYDROGUI_BathymetryPointOwner
+ ( const Handle(HYDROGUI_BathymetryPrs)& theBathymetry, int theIndex )
+ : SelectMgr_EntityOwner( Handle(SelectMgr_SelectableObject)::DownCast( theBathymetry ), 0 ),
+ myIndex( theIndex )
+{
+}
+
+HYDROGUI_BathymetryPointOwner::~HYDROGUI_BathymetryPointOwner()
+{
+}
+
+Standard_Boolean HYDROGUI_BathymetryPointOwner::IsAutoHilight() const
+{
+ return Standard_False;
+}
+
+int HYDROGUI_BathymetryPointOwner::GetIndex() const
+{
+ return myIndex;
}