From decdafe51b17380933aed157a2b25d13f8fd469a Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 1 Oct 2010 13:54:22 +0000 Subject: [PATCH] Additional improvement for the issue 0020985 (handling point marker of the compound of vertices) --- src/GEOMGUI/GEOMGUI_Selection.cxx | 30 ++++++++++++++++++++++++ src/GEOMGUI/GEOMGUI_Selection.h | 8 ++++--- src/GEOMGUI/GEOM_Displayer.cxx | 39 ++++++++++++++++++++++++++++--- src/GEOMGUI/GeometryGUI.cxx | 2 +- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/GEOMGUI/GEOMGUI_Selection.cxx b/src/GEOMGUI/GEOMGUI_Selection.cxx index e30f447a9..f4aeb8ccf 100644 --- a/src/GEOMGUI/GEOMGUI_Selection.cxx +++ b/src/GEOMGUI/GEOMGUI_Selection.cxx @@ -98,6 +98,8 @@ QVariant GEOMGUI_Selection::parameter( const int ind, const QString& p ) const return QVariant( hasHiddenChildren( ind ) ); else if ( p == "hasShownChildren" ) return QVariant( hasShownChildren( ind ) ); + else if ( p == "compoundOfVertices" ) + return QVariant( compoundOfVertices( ind ) ); else return LightApp_Selection::parameter( ind, p ); } @@ -274,6 +276,29 @@ bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj ) return exp; } +bool GEOMGUI_Selection::isCompoundOfVertices( GEOM::GEOM_Object_ptr obj ) +{ + bool ret = false; + SalomeApp_Study* appStudy = dynamic_cast + (SUIT_Session::session()->activeApplication()->activeStudy()); + if ( appStudy && !CORBA::is_nil( obj ) && obj->GetShapeType() == GEOM::COMPOUND ) { + GEOM::GEOM_IMeasureOperations_var anOper = GeometryGUI::GetGeomGen()->GetIMeasureOperations( appStudy->id() ); + QString whatIs = anOper->WhatIs( obj ); + QStringList data = whatIs.split( "\n", QString::SkipEmptyParts ); + int nbVertices = 0, nbCompounds = 0, nbOther = 0; + foreach ( QString s, data ) { + QString type = s.section( ":", 0, 0 ).trimmed().toLower(); + int cnt = s.section( ":", 1, 1 ).trimmed().toInt(); + if ( type == "vertex" ) nbVertices += cnt; + else if ( type == "compound" ) nbCompounds += cnt; + else if ( type != "shape" ) nbOther += cnt; + } + ret = nbVertices > 0 && nbCompounds == 1 && nbOther == 0; + anOper->Destroy(); + } + return ret; +} + bool GEOMGUI_Selection::hasHiddenChildren( const int index ) const { bool OK = false; @@ -310,6 +335,11 @@ bool GEOMGUI_Selection::hasShownChildren( const int index ) const return OK; } +bool GEOMGUI_Selection::compoundOfVertices( const int index ) const +{ + return isCompoundOfVertices( getObject( index ) ); +} + bool GEOMGUI_Selection::isComponent( const int index ) const { SalomeApp_Study* appStudy = dynamic_cast diff --git a/src/GEOMGUI/GEOMGUI_Selection.h b/src/GEOMGUI/GEOMGUI_Selection.h index e6cb762e8..9911ad4df 100644 --- a/src/GEOMGUI/GEOMGUI_Selection.h +++ b/src/GEOMGUI/GEOMGUI_Selection.h @@ -48,6 +48,10 @@ public: virtual bool processOwner( const LightApp_DataOwner* ); + static bool hasChildren( const _PTR(SObject)& ); + static bool expandable( const _PTR(SObject)& ); + static bool isCompoundOfVertices( GEOM::GEOM_Object_ptr ); + private: bool isVisible( const int ) const; bool isAutoColor( const int ) const; @@ -58,9 +62,7 @@ private: bool isVectorsMode( const int ) const; bool hasHiddenChildren( const int ) const; bool hasShownChildren( const int ) const; - - static bool hasChildren( const _PTR(SObject)& ); - static bool expandable( const _PTR(SObject)& ); + bool compoundOfVertices( const int ) const; bool isComponent( const int ) const; GEOM::GEOM_Object_ptr getObject( const int ) const; diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 82853c712..3196289e5 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -81,6 +81,9 @@ #include #include #include +#include +#include +#include // VTK Includes #include @@ -126,6 +129,36 @@ static inline int getTopAbsMode( const int implType ) } } +static bool isCompoundOfVertices( const TopoDS_Shape& theShape ) +{ + bool ret = false; + if ( !theShape.IsNull() ) { + int iType, nbTypes [TopAbs_SHAPE]; + for (iType = 0; iType < TopAbs_SHAPE; ++iType) + nbTypes[iType] = 0; + nbTypes[theShape.ShapeType()]++; + + TopTools_MapOfShape aMapOfShape; + aMapOfShape.Add(theShape); + TopTools_ListOfShape aListOfShape; + aListOfShape.Append(theShape); + + TopTools_ListIteratorOfListOfShape itL (aListOfShape); + for (; itL.More(); itL.Next()) { + TopoDS_Iterator it (itL.Value()); + for (; it.More(); it.Next()) { + TopoDS_Shape s = it.Value(); + if (aMapOfShape.Add(s)) { + aListOfShape.Append(s); + nbTypes[s.ShapeType()]++; + } + } + } + ret = nbTypes[TopAbs_VERTEX] > 0 && nbTypes[TopAbs_COMPOUND] == 1; + } + return ret; +} + //================================================================ // Function : getFilter // Purpose : Get filter corresponding to the type of object @@ -579,7 +612,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); anAspect->SetColor( (Quantity_NameOfColor)GetColor() ); - if ( myShape.ShapeType() == TopAbs_VERTEX ) + if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) ) { anAspect->SetScale( myScaleOfMarker ); anAspect->SetTypeOfMarker( myTypeOfMarker ); @@ -588,7 +621,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) } else { - if ( myShape.ShapeType() == TopAbs_VERTEX ) + if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) ) { col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ); aColor = SalomeApp_Tools::color( col ); @@ -727,7 +760,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); AISShape->SetColor( aQuanColor ); AISShape->SetShadingColor( aQuanColor ); - if ( myShape.ShapeType() == TopAbs_VERTEX ) { + if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) ) { Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); anAspect->SetColor( aQuanColor ); anAspect->SetScale( myScaleOfMarker ); diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 740792c7b..3ee06d2df 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -1121,7 +1121,7 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->setRule( action( GEOMOp::OpDeflection ), "selcount>0 and isVisible and client='OCCViewer'", QtxPopupMgr::VisibleRule ); mgr->insert( action( GEOMOp::OpPointMarker ), -1, -1 ); // point marker //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule ); - mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1 %2}" ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule ); + mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule ); mgr->insert( separator(), -1, -1 ); // ----------- mgr->insert( action( GEOMOp::OpAutoColor ), -1, -1 ); // auto color mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule ); -- 2.39.2