From: asl Date: Wed, 20 Sep 2017 14:01:08 +0000 (+0300) Subject: refs #1330: basic implementation of the not zoomable polyline arrows X-Git-Tag: v2.1~66^2~13^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=26197be88e35b978201cdd05c4b34d4acbfad111;p=modules%2Fhydro.git refs #1330: basic implementation of the not zoomable polyline arrows --- diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index ecae1836..c4a5a0d5 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx @@ -311,7 +311,7 @@ void HYDROGUI_ImportLandCoverMapOp::onSelectionChanged( const QStringList& theSe foreach ( QString aName, myPolygonName2PrsShape.keys() ) { Handle(AIS_InteractiveObject) anObject = - myPolygonName2PrsShape.value(aName)->getAISObject(); + myPolygonName2PrsShape.value(aName)->getAISObjects()[0]; bool isSelected = theSelectedNames.contains( aName ); if ( ( isSelected && !aCtx->IsSelected( anObject) ) || ( !isSelected && aCtx->IsSelected( anObject) ) ) @@ -353,7 +353,7 @@ void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() { QStringList aSelectedNames; foreach ( QString aName, myPolygonName2PrsShape.keys() ) { - bool isSelected = aCtx->IsSelected( myPolygonName2PrsShape.value(aName)->getAISObject() ); + bool isSelected = aCtx->IsSelected( myPolygonName2PrsShape.value(aName)->getAISObjects()[0] ); if ( isSelected ) aSelectedNames << aName; } diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index f0386a46..d447abbe 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -398,8 +398,11 @@ void HYDROGUI_OCCDisplayer::SetZLayer( const OCCViewer_Viewer* theViewer, HYDROGUI_Shape* anObjShape = module()->getObjectShape( aViewerId, theObject ); // Set Z layer - if ( anObjShape ) { - aCtx->SetZLayer( anObjShape->getAISObject(), theZLayerId ); + if ( anObjShape ) + { + QList shapes = anObjShape->getAISObjects(); + foreach( Handle(AIS_InteractiveObject) shape, shapes ) + aCtx->SetZLayer( shape, theZLayerId ); } } @@ -517,7 +520,7 @@ void HYDROGUI_OCCDisplayer::UpdateColorScale( const OCCViewer_Viewer* theViewer if( isScalarMode != isLandCoverColoringOn ) { aLandCoverMapShape->setScalarMapModeEnabled( isLandCoverColoringOn ); - theViewer->getAISContext()->Redisplay( aLandCoverMapShape->getAISObject() ); + theViewer->getAISContext()->Redisplay( aLandCoverMapShape->getAISObjects()[0], Standard_False ); } } diff --git a/src/HYDROGUI/HYDROGUI_Polyline.cxx b/src/HYDROGUI/HYDROGUI_Polyline.cxx index b9a7a2aa..e640f9a7 100644 --- a/src/HYDROGUI/HYDROGUI_Polyline.cxx +++ b/src/HYDROGUI/HYDROGUI_Polyline.cxx @@ -17,29 +17,21 @@ // #include - -#include +#include +#include #include #include -#include -#include -#include -#include +#include +#include #include -#include -#include +#include +#include +#include #include #include #include #include -#include #include -#include -#include -#include -#include -#include -#include IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Polyline, AIS_Shape) @@ -75,6 +67,7 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre const Standard_Integer aMode) { //AIS_Shape::Compute(aPresentationManager, aPrs, aMode); + //return; aPrs->Clear(); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs ); @@ -106,79 +99,76 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre aGroup->AddPrimitiveArray( anArray ); } } +} - - TopExp_Explorer Exp ( myshape, TopAbs_EDGE ); - for ( ; Exp.More(); Exp.Next() ) { - TopoDS_Vertex aV1, aV2; +QList HYDROGUI_Polyline::createPresentations( const TopoDS_Shape& shape ) +{ + QList shapes; + + // 1. Main shape + shapes.append( new HYDROGUI_Polyline( shape ) ); + + // 2. Shapes for direction arrows on edges + TopExp_Explorer Exp ( shape, TopAbs_EDGE ); + for ( ; Exp.More(); Exp.Next() ) + { TopoDS_Edge anEdge = TopoDS::Edge(Exp.Current()); - - if ( anEdge.IsNull() ) - continue; - TopExp::Vertices(anEdge, aV1, aV2); - gp_Pnt aP = BRep_Tool::Pnt(aV1); - gp_Vec aDirVec; - double aFp, aLp; - Handle(Geom_Curve) C = BRep_Tool::Curve(anEdge,aFp,aLp); - if ( C.IsNull() ) - continue; - - Bnd_Box aBB; - BRepBndLib::Add(anEdge, aBB); - Standard_Real aXmin,aYmin,aZmin,aXmax,aYmax,aZmax; - aBB.Get(aXmin,aYmin,aZmin,aXmax,aYmax,aZmax); - Standard_Real aLen = Max(Abs(aXmax - aXmin), Max (Abs(aZmax - aZmin), Abs(aYmax - aYmin))); - - GeomAdaptor_Curve aAdC; - aAdC.Load(C, aFp, aLp); - double aLenC; - double aLenH; - int aNbSegments = 20; - double aArrLen = aLen / 10.; - double anIncr = (aLp-aFp)/aNbSegments; - double aMaxRatio = 0; - double aMaxRatioStep = 1; - for (double t = aFp; t < aLp - anIncr; t += anIncr) - { - aLenC = GCPnts_AbscissaPoint::Length(aAdC, t, t + anIncr); - aLenH = C->Value (t).Distance (C->Value (t + anIncr)); - if ( aLenH / aLenC > aMaxRatio) { - aMaxRatio = aLenH / aLenC; - aMaxRatioStep = t; - } - } + if ( !anEdge.IsNull() ) + shapes.append( new HYDROGUI_Arrow( anEdge ) ); + } - bool UseD1 = false; - if (Abs(aMaxRatioStep) < Precision::Confusion()) - { - aMaxRatioStep = (aLp - aFp)/2.0; - UseD1 = true; - } + return shapes; +} - if (Abs(aLp - aMaxRatioStep) < Precision::Confusion()) - { - aMaxRatioStep = (aLp - aFp)/2.0; - UseD1 = true; - } - - gp_Pnt aPnt1 = C->Value (aMaxRatioStep); - gp_Vec aDir; - if (!UseD1) - { - GCPnts_AbscissaPoint aAbsPoint(aAdC, -aArrLen, aMaxRatioStep); - double aParam = aAbsPoint.Parameter(); - gp_Pnt aPnt2 = C->Value (aParam); - gp_XYZ D = aPnt1.XYZ(); - D.Subtract (aPnt2.XYZ()); - aDir = D; - } - if (UseD1 || aDir.IsEqual (gp_Vec(0,0,0), Precision::Confusion(), Precision::Angular())) - C->D1(aMaxRatioStep, aPnt1, aDir); - - if ( anEdge.Orientation() == TopAbs_REVERSED ) - aDir = -aDir; - - Prs3d_Arrow::Draw(aPrs, aPnt1, aDir, M_PI/180.*12., aArrLen); - } + + + +IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Arrow, AIS_Shape) + + +HYDROGUI_Arrow::HYDROGUI_Arrow( const TopoDS_Edge& edge ) + : AIS_Shape( edge ) +{ +} + +HYDROGUI_Arrow::~HYDROGUI_Arrow() +{ +} + +void HYDROGUI_Arrow::Compute( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, + const Handle(Prs3d_Presentation)& aPrs, + const Standard_Integer aMode ) +{ + aPrs->Clear(); + + TopoDS_Edge anEdge = TopoDS::Edge( myshape ); + if( anEdge.IsNull() ) + return; + + BRepAdaptor_Curve anAdaptor( anEdge ); + double curveLen = GCPnts_AbscissaPoint::Length( anAdaptor, anAdaptor.FirstParameter(), anAdaptor.LastParameter() ); + double arrowLen = qMin( curveLen/10, 35.0 ); + + double t = ( anAdaptor.FirstParameter() + anAdaptor.LastParameter() ) / 2; + gp_Pnt P; + gp_Vec V; + anAdaptor.D1( t, P, V ); + + gp_Trsf tr; + tr.SetTranslation( -gp_Vec( gp_Pnt(), P ) ); + aPrs->SetTransformation( new Geom_Transformation( tr ) ); + + Handle(Graphic3d_TransformPers) tp = new Graphic3d_TransformPers( Graphic3d_TMF_ZoomPers, P ); + SetTransformPersistence( tp ); + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs ); + Quantity_Color aColor; + Aspect_TypeOfLine aType; + Standard_Real anWidth; + Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth ); + anWidth = 1; + Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth ); + aGroup->SetPrimitivesAspect( anAspect ); + Prs3d_Arrow::Draw( aGroup, gp_Pnt(), V, M_PI/180.*12., arrowLen ); } diff --git a/src/HYDROGUI/HYDROGUI_Polyline.h b/src/HYDROGUI/HYDROGUI_Polyline.h index 7b70a15f..130dc879 100644 --- a/src/HYDROGUI/HYDROGUI_Polyline.h +++ b/src/HYDROGUI/HYDROGUI_Polyline.h @@ -20,30 +20,39 @@ #define _HYDROGUI_Polyline_HeaderFile #include -#include - -#include -#include -#include -#include -#include -#include +#include class TopoDS_Shape; +class TopoDS_Edge; class HYDROGUI_Polyline : public AIS_Shape { public: - - Standard_EXPORT HYDROGUI_Polyline(const TopoDS_Shape& shape); - Standard_EXPORT ~HYDROGUI_Polyline(); + HYDROGUI_Polyline( const TopoDS_Shape& shape ); + virtual ~HYDROGUI_Polyline(); - Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, + virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0); + static QList createPresentations( const TopoDS_Shape& shape ); + public: DEFINE_STANDARD_RTTIEXT(HYDROGUI_Polyline, AIS_Shape); }; +class HYDROGUI_Arrow : public AIS_Shape +{ +public: + HYDROGUI_Arrow( const TopoDS_Edge& edge ); + virtual ~HYDROGUI_Arrow(); + + virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, + const Handle(Prs3d_Presentation)& aPresentation, + const Standard_Integer aMode = 0 ); + +public: + DEFINE_STANDARD_RTTIEXT(HYDROGUI_Arrow, AIS_Shape); +}; + #endif diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx index dfb279ff..20220731 100644 --- a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx @@ -443,7 +443,7 @@ void HYDROGUI_RecognizeContoursOp::onSelectionChanged( const QStringList& theSel if ( !aCtx.IsNull() ) { foreach ( QString aName, myPolylineShapes.keys() ) { Handle(AIS_InteractiveObject) anObject = - myPolylineShapes.value(aName)->getAISObject(); + myPolylineShapes.value(aName)->getAISObjects()[0]; bool isSelected = theSelectedNames.contains( aName ); if ( ( isSelected && !aCtx->IsSelected( anObject) ) || @@ -481,7 +481,7 @@ void HYDROGUI_RecognizeContoursOp::onViewerSelectionChanged() QStringList aSelectedNames; foreach ( QString aName, myPolylineShapes.keys() ) { - bool isSelected = aCtx->IsSelected( myPolylineShapes.value(aName)->getAISObject() ); + bool isSelected = aCtx->IsSelected( myPolylineShapes.value(aName)->getAISObjects()[0] ); if ( isSelected ) { aSelectedNames << aName; } diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index c34f2cc9..8f271e54 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -62,9 +62,6 @@ HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext HYDROGUI_Shape::~HYDROGUI_Shape() { erase( false ); - - if ( !myShape.IsNull() ) - myShape.Nullify(); } Handle(AIS_InteractiveContext) HYDROGUI_Shape::getContext() const @@ -97,14 +94,14 @@ bool HYDROGUI_Shape::isVisible() const return myIsVisible; } -Handle(AIS_InteractiveObject) HYDROGUI_Shape::getAISObject() const +QList HYDROGUI_Shape::getAISObjects() const { - return myShape; + return myShapes; } void HYDROGUI_Shape::display( const bool theIsUpdateViewer ) { - if ( myContext.IsNull() || myShape.IsNull() || !isVisible() ) + if ( myContext.IsNull() || myShapes.empty() || !isVisible() ) return; displayShape( theIsUpdateViewer ); @@ -112,7 +109,7 @@ void HYDROGUI_Shape::display( const bool theIsUpdateViewer ) void HYDROGUI_Shape::erase( const bool theIsUpdateViewer ) { - if ( myContext.IsNull() || myShape.IsNull() ) + if ( myContext.IsNull() || myShapes.empty() ) return; eraseShape( theIsUpdateViewer ); @@ -305,13 +302,14 @@ void HYDROGUI_Shape::update( bool isUpdateViewer, } } - if ( myShape.IsNull() || !isVisible() ) + if ( myShapes.empty() || !isVisible() ) return; displayShape( isUpdateViewer ); if (isDeactivateSelection) - myContext->Deactivate(myShape); + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) + myContext->Deactivate( aShape ); } void HYDROGUI_Shape::setVisible( const bool theState, @@ -319,11 +317,11 @@ void HYDROGUI_Shape::setVisible( const bool theState, { myIsVisible = theState; - if ( myShape.IsNull() ) + if ( myShapes.empty() ) return; - if ( ( myIsVisible && myContext->IsDisplayed( myShape ) ) || - ( !myIsVisible && !myContext->IsDisplayed( myShape ) ) ) + if ( ( myIsVisible && myContext->IsDisplayed( myShapes[0] ) ) || + ( !myIsVisible && !myContext->IsDisplayed( myShapes[0] ) ) ) return; if ( myIsVisible ) { @@ -340,7 +338,7 @@ void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer ) myIsHighlight = theIsHighlight; - if ( myContext.IsNull() || myShape.IsNull() ) + if ( myContext.IsNull() || myShapes.empty() ) return; colorShapeBorder( getActiveColor() ); @@ -476,14 +474,16 @@ void HYDROGUI_Shape::setZLayer( const int theZLayer ) return; myZLayer = theZLayer; - if ( !myShape.IsNull() && isVisible() && !myContext.IsNull() && myZLayer >= 0 ) - myContext->SetZLayer( myShape, myZLayer ); + if( isVisible() && !myContext.IsNull() && myZLayer >= 0 ) + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) + myContext->SetZLayer( aShape, myZLayer ); } -Handle(AIS_InteractiveObject) HYDROGUI_Shape::createShape() const +QList HYDROGUI_Shape::createShape() const { + QList shapes; if( myTopoShape.IsNull() ) { - return Handle(AIS_InteractiveObject)(); + return shapes; } TopAbs_ShapeEnum aShapeType = myTopoShape.ShapeType(); @@ -497,11 +497,15 @@ Handle(AIS_InteractiveObject) HYDROGUI_Shape::createShape() const } } - if ( aShapeType==TopAbs_EDGE || aShapeType==TopAbs_WIRE || IsWireEdgeCompound) { - return new HYDROGUI_Polyline( myTopoShape ); - } else { - return new HYDROGUI_AISShape( myTopoShape ); + if ( aShapeType==TopAbs_EDGE || aShapeType==TopAbs_WIRE || IsWireEdgeCompound) + { + shapes.append( HYDROGUI_Polyline::createPresentations( myTopoShape ) ); + } + else + { + shapes.append( new HYDROGUI_AISShape( myTopoShape ) ); } + return shapes; } void HYDROGUI_Shape::buildShape() @@ -509,45 +513,48 @@ void HYDROGUI_Shape::buildShape() // Erase previously created shape erase(false); - myShape = createShape(); - if( myShape.IsNull() ) + myShapes = createShape(); + if( myShapes.empty() ) return; - Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( myShape ); - if( !anAISShape.IsNull() ) - anAISShape ->SetHLRAngleAndDeviation( 0.001 ); + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) + { + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( aShape ); + if( !anAISShape.IsNull() ) + anAISShape ->SetHLRAngleAndDeviation( 0.001 ); - if ( !myObject.IsNull() ) - myShape->SetOwner( myObject ); + if ( !myObject.IsNull() ) + aShape->SetOwner( myObject ); - if ( !myObject.IsNull() && !myObject->IsKind( STANDARD_TYPE(HYDROData_LandCoverMap) ) ) - myShape->SetTransparency( 0 ); - myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode ); + if ( !myObject.IsNull() && !myObject->IsKind( STANDARD_TYPE(HYDROData_LandCoverMap) ) ) + aShape->SetTransparency( 0 ); + aShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode ); - // Init default params for shape - const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes(); - if ( !anAttributes.IsNull() ) - { - Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect(); - if ( !anIsoAspect.IsNull() ) { - anIsoAspect->SetNumber( 0 ); - anAttributes->SetUIsoAspect( anIsoAspect ); - } - - anIsoAspect = anAttributes->VIsoAspect(); - if ( !anIsoAspect.IsNull() ) + // Init default params for shape + const Handle(Prs3d_Drawer)& anAttributes = aShape->Attributes(); + if ( !anAttributes.IsNull() ) { - anIsoAspect->SetNumber( 0 ); - anAttributes->SetVIsoAspect( anIsoAspect ); - } + Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect(); + if ( !anIsoAspect.IsNull() ) { + anIsoAspect->SetNumber( 0 ); + anAttributes->SetUIsoAspect( anIsoAspect ); + } + + anIsoAspect = anAttributes->VIsoAspect(); + if ( !anIsoAspect.IsNull() ) + { + anIsoAspect->SetNumber( 0 ); + anAttributes->SetVIsoAspect( anIsoAspect ); + } - if ( myDisplayMode == AIS_Shaded ) - { - myShape->SetMaterial( Graphic3d_NOM_PLASTIC ); - } - else if ( myDisplayMode == AIS_WireFrame ) - { - anAttributes->SetWireDraw( true ); + if ( myDisplayMode == AIS_Shaded ) + { + aShape->SetMaterial( Graphic3d_NOM_PLASTIC ); + } + else if ( myDisplayMode == AIS_WireFrame ) + { + anAttributes->SetWireDraw( true ); + } } } } @@ -555,30 +562,30 @@ void HYDROGUI_Shape::buildShape() void HYDROGUI_Shape::updateShape( const bool theToDisplay, const bool theIsUpdateViewer ) { - if ( myShape.IsNull() ) - return; - - const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes(); - if ( !anAttributes.IsNull() ) + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) { - if ( myDisplayMode == AIS_Shaded && myFillingColor.isValid() ) - { - Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ), - getQuantityColorVal( myFillingColor.green() ), - getQuantityColorVal( myFillingColor.blue() ), - Quantity_TOC_RGB ); - - myShape->SetColor( aFillingColor ); - myShape->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) ); - } - else if ( myDisplayMode == AIS_WireFrame ) + const Handle(Prs3d_Drawer)& anAttributes = aShape->Attributes(); + if ( !anAttributes.IsNull() ) { + if ( myDisplayMode == AIS_Shaded && myFillingColor.isValid() ) + { + Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ), + getQuantityColorVal( myFillingColor.green() ), + getQuantityColorVal( myFillingColor.blue() ), + Quantity_TOC_RGB ); + + aShape->SetColor( aFillingColor ); + aShape->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) ); + } + else if ( myDisplayMode == AIS_WireFrame ) + { + } + + // Coloring borders } - - // Coloring borders - colorShapeBorder( myBorderColor ); } - + + colorShapeBorder( myBorderColor ); if ( !theToDisplay || !isVisible() || myContext.IsNull() ) return; @@ -590,27 +597,34 @@ void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer ) if ( myContext->HasOpenedContext() && mySelectionMode > 0 ) myContext->CloseLocalContext(); - if ( mySelectionMode > 0 ) - // Display object in local context with selection - myContext->Display( myShape, myDisplayMode, mySelectionMode, Standard_False, Standard_False ); - else + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) { - if ( !myContext->HasOpenedContext() ) - // Ordinary display of object published in the Object Browser - myContext->Display( myShape, Standard_False ); + if ( mySelectionMode > 0 ) + // Display object in local context with selection + myContext->Display( aShape, myDisplayMode, mySelectionMode, Standard_False, Standard_False ); else - // Display object in local context without selection - myContext->Display( myShape, myDisplayMode, -1, Standard_False, Standard_False ); + { + if ( !myContext->HasOpenedContext() ) + // Ordinary display of object published in the Object Browser + myContext->Display( aShape, Standard_False ); + else + // Display object in local context without selection + myContext->Display( aShape, myDisplayMode, -1, Standard_False, Standard_False ); + } } if ( mySelectionMode > 0 ) { myContext->OpenLocalContext(); - myContext->Activate( myShape, mySelectionMode, Standard_True ); + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) + myContext->Activate( aShape, mySelectionMode, Standard_True ); } if ( myZLayer >= 0 ) - myContext->SetZLayer( myShape, myZLayer ); + { + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) + myContext->SetZLayer( aShape, myZLayer ); + } if ( theIsUpdateViewer ) { myContext->UpdateCurrentViewer(); @@ -622,7 +636,11 @@ void HYDROGUI_Shape::eraseShape( const bool theIsUpdateViewer ) if ( myContext->HasOpenedContext() && mySelectionMode > 0 ) myContext->CloseLocalContext(); - myContext->Erase( myShape, theIsUpdateViewer ); + foreach( Handle(AIS_InteractiveObject) aShape, myShapes ) + myContext->Erase( aShape, Standard_False ); + + if( theIsUpdateViewer ) + myContext->UpdateCurrentViewer(); } QColor HYDROGUI_Shape::getActiveColor() const @@ -637,33 +655,33 @@ double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal ) void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor ) { - if ( myShape.IsNull() ) - return; - - const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes(); - if ( anAttributes.IsNull() ) - return; + foreach( Handle(AIS_InteractiveObject) aShape1, myShapes ) + { + const Handle(Prs3d_Drawer)& anAttributes = aShape1->Attributes(); + if ( anAttributes.IsNull() ) + continue; - Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ), - getQuantityColorVal( theColor.green() ), - getQuantityColorVal( theColor.blue() ), - Quantity_TOC_RGB ); + Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ), + getQuantityColorVal( theColor.green() ), + getQuantityColorVal( theColor.blue() ), + Quantity_TOC_RGB ); - if( !myTopoShape.IsNull() ) - { - if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode - { - myShape->SetColor( aBorderColor ); - } - else if ( myDisplayMode == AIS_Shaded ) + if( !myTopoShape.IsNull() ) { - Handle(HYDROGUI_AISShape) aShape = Handle(HYDROGUI_AISShape)::DownCast( myShape ); - if( !aShape.IsNull() ) - aShape->SetBorderColor( aBorderColor ); - } - else if ( myDisplayMode == AIS_WireFrame ) - { - myShape->SetColor( aBorderColor ); + if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode + { + aShape1->SetColor( aBorderColor ); + } + else if ( myDisplayMode == AIS_Shaded ) + { + Handle(HYDROGUI_AISShape) aShape = Handle(HYDROGUI_AISShape)::DownCast( aShape1 ); + if( !aShape.IsNull() ) + aShape->SetBorderColor( aBorderColor ); + } + else if ( myDisplayMode == AIS_WireFrame ) + { + aShape1->SetColor( aBorderColor ); + } } } } diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 76113ba1..76b002ca 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -95,12 +95,11 @@ public: virtual void setHighlightColor( const QColor& theColor ); virtual QColor getHighlightColor() const; - virtual Handle(AIS_InteractiveObject) getAISObject() const; - void setZLayer( const int theZLayer ); - void setSelectionMode( int theSelectionMode ); + QList getAISObjects() const; + protected: virtual void buildShape(); virtual void updateShape( const bool theToDisplay = true, @@ -109,7 +108,7 @@ protected: virtual void eraseShape( const bool theIsUpdateViewer ); virtual QColor getActiveColor() const; - virtual Handle(AIS_InteractiveObject) createShape() const; + virtual QList createShape() const; void setDisplayMode( int theDisplayMode ); @@ -120,7 +119,7 @@ private: private: Handle(AIS_InteractiveContext) myContext; Handle(HYDROData_Entity) myObject; - Handle(AIS_InteractiveObject) myShape; + QList myShapes; int myZLayer; diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx index a88b5069..3a72a138 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx @@ -58,8 +58,10 @@ void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivate } -Handle(AIS_InteractiveObject) HYDROGUI_ShapeBathymetry::createShape() const +QList HYDROGUI_ShapeBathymetry::createShape() const { + QList shapes; + Handle(AIS_InteractiveObject) aPntCloud; Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() ); @@ -78,9 +80,11 @@ Handle(AIS_InteractiveObject) HYDROGUI_ShapeBathymetry::createShape() const aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper ); for( int i=aLower; i<=anUpper; i++ ) aThat->myCoords->SetValue( i, gp_Pnt( aBathPoints[i].X, aBathPoints[i].Y, aBathPoints[i].Z ) ); + + shapes.append( aPntCloud ); } - return aPntCloud; + return shapes; } void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const @@ -113,7 +117,7 @@ void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale theColorScale->FindColor( z, aColor ); myColors->SetValue( i, aColor ); } - Handle(AIS_PointCloud) aPntCloud = Handle(AIS_PointCloud)::DownCast( getAISObject() ); + Handle(AIS_PointCloud) aPntCloud = Handle(AIS_PointCloud)::DownCast( getAISObjects()[0] ); aPntCloud->SetPoints( myCoords, myColors ); getContext()->Redisplay( aPntCloud, Standard_False ); } @@ -121,7 +125,7 @@ void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale void HYDROGUI_ShapeBathymetry::setVisible( const bool theState, const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( isShown != theState ); HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer ); setToUpdateColorScale( isChanged ); @@ -129,7 +133,7 @@ void HYDROGUI_ShapeBathymetry::setVisible( const bool theState, void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( !isShown ); HYDROGUI_Shape::displayShape( theIsUpdateViewer ); setToUpdateColorScale( isChanged ); @@ -137,7 +141,7 @@ void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer ) void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( !isShown ); HYDROGUI_Shape::display( theIsUpdateViewer ); setToUpdateColorScale( isChanged ); @@ -145,7 +149,7 @@ void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer ) void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( isShown ); HYDROGUI_Shape::erase( theIsUpdateViewer ); setToUpdateColorScale( isChanged ); diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h index c736c60f..91a0a772 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h @@ -48,7 +48,7 @@ public: virtual void setVisible( const bool theState, const bool theIsUpdateViewer = true ); protected: - virtual Handle(AIS_InteractiveObject) createShape() const; + virtual QList createShape() const; virtual void displayShape( const bool theIsUpdateViewer ); void setToUpdateColorScale( bool isChanged ); diff --git a/src/HYDROGUI/HYDROGUI_ShapeImage.cxx b/src/HYDROGUI/HYDROGUI_ShapeImage.cxx index 4f832399..d57f726d 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeImage.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeImage.cxx @@ -46,17 +46,20 @@ void HYDROGUI_ShapeImage::update( bool theIsUpdateViewer, bool isDeactivateSelec HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection ); } -Handle(AIS_InteractiveObject) HYDROGUI_ShapeImage::createShape() const +QList HYDROGUI_ShapeImage::createShape() const { + QList shapes; + Handle(HYDROGUI_ImagePrs) aPrs; Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() ); if ( !anImageObj.IsNull() ) { aPrs = new HYDROGUI_ImagePrs( imagePixMap( anImageObj ), imageContour( anImageObj ) ); + shapes.append( aPrs ); } - return aPrs; + return shapes; } Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Image)& theImageObj ) const diff --git a/src/HYDROGUI/HYDROGUI_ShapeImage.h b/src/HYDROGUI/HYDROGUI_ShapeImage.h index aba5b82b..17c6dec0 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeImage.h +++ b/src/HYDROGUI/HYDROGUI_ShapeImage.h @@ -36,7 +36,7 @@ public: virtual void update( bool isUpdateViewer, bool isDeactivateSelection ); protected: - virtual Handle(AIS_InteractiveObject) createShape() const; + virtual QList createShape() const; Handle(Image_PixMap) imagePixMap( const Handle(HYDROData_Image)& ) const; QPolygonF imageContour( const Handle(HYDROData_Image)& ) const; }; diff --git a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx index 3446545e..66e56301 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx @@ -60,7 +60,8 @@ void HYDROGUI_ShapeLandCoverMap::update( bool theIsUpdateViewer, bool isDeactiva setShape( aLandCoverMapShape, false, false ); } - Handle(HYDROGUI_LandCoverMapPrs) aLandCoverMapPrs = Handle(HYDROGUI_LandCoverMapPrs)::DownCast( getAISObject() ); + Handle(HYDROGUI_LandCoverMapPrs) aLandCoverMapPrs = + Handle(HYDROGUI_LandCoverMapPrs)::DownCast( getAISObjects()[0] ); if ( !aLandCoverMapPrs.IsNull() ) aLandCoverMapPrs->UpdateColors(); @@ -91,8 +92,10 @@ void HYDROGUI_ShapeLandCoverMap::displayShape( const bool theIsUpdateViewer ) myDisplayer->SetToUpdateColorScale(); } -Handle(AIS_InteractiveObject) HYDROGUI_ShapeLandCoverMap::createShape() const +QList HYDROGUI_ShapeLandCoverMap::createShape() const { + QList shapes; + Handle(HYDROData_LandCoverMap) aLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast( getObject() ); if ( !aLandCoverMap.IsNull() ) { @@ -119,9 +122,9 @@ Handle(AIS_InteractiveObject) HYDROGUI_ShapeLandCoverMap::createShape() const } } } - return aLandCoverMapPrs; + shapes.append( aLandCoverMapPrs ); } - return NULL; + return shapes; } void HYDROGUI_ShapeLandCoverMap::display( const bool theIsUpdateViewer ) diff --git a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h index 526c52e5..a030a370 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h +++ b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h @@ -54,7 +54,7 @@ public: protected: virtual void displayShape( const bool theIsUpdateViewer ); - virtual Handle(AIS_InteractiveObject) createShape() const; + virtual QList createShape() const; private: HYDROGUI_OCCDisplayer* myDisplayer; diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 5ef6d2d9..71cd941b 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -142,10 +142,13 @@ void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject, } if( isFitAll ) - { - viewWindow()->onTopView(); - viewWindow()->onFitAll(); - } + fitAll(); +} + +void TestViewer::fitAll() +{ + viewWindow()->onTopView(); + viewWindow()->onFitAll(); } void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor, @@ -167,10 +170,7 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, context()->Display( aShape, theMode, 0, Standard_False ); if( isFitAll ) - { - viewWindow()->onTopView(); - viewWindow()->onFitAll(); - } + fitAll(); } void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey, int theUIANb, int theVIANb) @@ -217,10 +217,7 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, show( aLE.Value(), theMode, false, GetColor(i) ); if( isFitAll ) - { - viewWindow()->onTopView(); - viewWindow()->onFitAll(); - } + fitAll(); } /*void TestViewer::ShowShape(const TopoDS_Shape& theShape, int theMode, int& i) diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index 90aac840..8a0db3c9 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -60,6 +60,8 @@ public: int theLinesToOmit, QString& theMsg ); + static void fitAll(); + private: static OCCViewer_ViewManager* myViewManager; static OCCViewer_ViewWindow* myViewWindow; diff --git a/src/HYDRO_tests/reference_data/Polyline_Presentation.png b/src/HYDRO_tests/reference_data/Polyline_Presentation.png index 1a4f14fd..0e9f0134 100644 Binary files a/src/HYDRO_tests/reference_data/Polyline_Presentation.png and b/src/HYDRO_tests/reference_data/Polyline_Presentation.png differ diff --git a/src/HYDRO_tests/test_HYDROData_DTM.cxx b/src/HYDRO_tests/test_HYDROData_DTM.cxx index d4338722..9c06cc7e 100644 --- a/src/HYDRO_tests/test_HYDROData_DTM.cxx +++ b/src/HYDRO_tests/test_HYDROData_DTM.cxx @@ -48,7 +48,7 @@ class DTM_item : public QGraphicsItem public: DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d ) { - Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() ); + Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObjects()[0] ); Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints(); myBB = QRectF(); double xmin, xmax, ymin, ymax; diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx index 57d6435f..b3af935f 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -253,15 +254,19 @@ void test_HYDROData_PolylineXY::test_presentation() aPointsPrs->SetColor( Quantity_NOC_BLUE1 ); aPointsPrs->Attributes()->PointAspect()->SetTypeOfMarker( Aspect_TOM_O ); - Handle(HYDROGUI_Polyline) aNewPolylinePrs = new HYDROGUI_Polyline( aPolyline2d->GetShape() ); - aNewPolylinePrs->SetColor( Quantity_NOC_DARKGREEN ); + aPolyline2d->SetWireColor( Qt::darkGreen ); + HYDROGUI_Shape* aNewPolylinePrs = new HYDROGUI_Shape( TestViewer::context(), aPolyline2d ); + aNewPolylinePrs->update( true, true ); TestViewer::show( aPointsPrs, AIS_PointCloud::DM_Points, 0, true, "Polyline_Presentation" ); TestViewer::show( aPolyline2d->GetShape(), 0, true, Qt::red ); - TestViewer::show( aNewPolylinePrs, AIS_PointCloud::DM_Points, 0, true, "" ); + //TestViewer::show( aNewPolylinePrs, AIS_PointCloud::DM_Points, 0, true, "" ); + aNewPolylinePrs->display(); + TestViewer::fitAll(); CPPUNIT_ASSERT_IMAGES aDoc->Close(); + //QTest::qWait( 50000 ); } void test_HYDROData_PolylineXY::test_split_refs_627() diff --git a/src/HYDRO_tests/test_HYDROGUI_Shape.cxx b/src/HYDRO_tests/test_HYDROGUI_Shape.cxx index ee5ca41f..30b2d776 100644 --- a/src/HYDRO_tests/test_HYDROGUI_Shape.cxx +++ b/src/HYDRO_tests/test_HYDROGUI_Shape.cxx @@ -39,7 +39,7 @@ void test_HYDROGUI_Shape::test_face_in_preview() aPreview->setFillingColor( Qt::red, false, false ); aPreview->setBorderColor( Qt::darkBlue, false, false ); - TestViewer::show( aPreview->getAISObject(), AIS_Shaded, 0, true, "Shape_preview_im_zone" ); + TestViewer::show( aPreview->getAISObjects()[0], AIS_Shaded, 0, true, "Shape_preview_im_zone" ); CPPUNIT_ASSERT_IMAGES delete aPreview;