X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Utils.cxx;h=12d7ee7d84cf92d6a17a80aef4630e1eaf760122;hb=1e9be94cc5ff4ad886099c507462d5b70f6d71f9;hp=15396cdc6626a8105e7884dc537285d32efc324a;hpb=f5d741e54ea475315ee8f7ca822d1ecba030fc21;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.cxx b/src/HYDROCurveCreator/CurveCreator_Utils.cxx index 15396cdc..12d7ee7d 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Utils.cxx @@ -42,12 +42,13 @@ #include #include #include +#include #include #include const double LOCAL_SELECTION_TOLERANCE = 0.0001; -const int SCENE_PIXEL_TOLERANCE = 10; +const int SCENE_PIXEL_TOLERANCE = 10; //======================================================================= // function : ConvertClickToPoint() @@ -68,36 +69,64 @@ void CurveCreator_Utils::ConvertPointToClick( const gp_Pnt& thePoint, gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) { return GEOMUtils::ConvertClickToPoint( x, y, aView ); - /* - V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; - aView->Eye( XEye, YEye, ZEye ); - - aView->At( XAt, YAt, ZAt ); - gp_Pnt EyePoint( XEye, YEye, ZEye ); - gp_Pnt AtPoint( XAt, YAt, ZAt ); - - gp_Vec EyeVector( EyePoint, AtPoint ); - gp_Dir EyeDir( EyeVector ); - - gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); - Standard_Real X, Y, Z; - aView->Convert( x, y, X, Y, Z ); - gp_Pnt ConvertedPoint( X, Y, Z ); - - gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); - gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); - return ResultPoint; - */ } +std::list CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext ) +{ + std::list aSelectedPoints; + + gp_Pnt aPnt; + for ( theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected() ) { + TopoDS_Vertex aVertex; + TopoDS_Shape aShape = theContext->SelectedShape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aVertex = TopoDS::Vertex( theContext->SelectedShape() ); + else { + Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner(); + if ( !anOwner.IsNull() ) { + Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( anOwner->Selectable() ); + if ( !anAIS.IsNull() ) { + Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS); + if ( !aPoint.IsNull() ) + aVertex = TopoDS::Vertex( aPoint->Vertex() ); + } + if ( aVertex.IsNull() ) { + // the following happens if there are no points in the current curve, there is only a shape + /*Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if ( aBrepOwner.IsNull() ) + continue; + if ( aBrepOwner->HasShape() ) { + const TopoDS_Shape& aShape = aBrepOwner->Shape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + { + aVertex = TopoDS::Vertex( aShape ); + } + }*/ + } + } + } + if ( aVertex.IsNull() ) + continue; + aPnt = BRep_Tool::Pnt( aVertex ); + aSelectedPoints.push_back( aPnt.X() ); + aSelectedPoints.push_back( aPnt.Y() ); + aSelectedPoints.push_back( aPnt.Z() ); + } + + return aSelectedPoints; +} //======================================================================= // function : setLocalPointContext // purpose : Open/close the viewer local context //======================================================================= +//#define USE_COMPOUND void CurveCreator_Utils::setLocalPointContext( Handle(AIS_InteractiveContext) theContext, const bool theOpen ) { +#ifdef USE_COMPOUND + return; +#endif if ( !theContext ) return; @@ -121,8 +150,8 @@ void CurveCreator_Utils::setLocalPointContext( if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) ) { theContext->Load( anAIS, -1/*selection mode*/, true/*allow decomposition*/ ); - theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) ); - //theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) ); + //theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) ); + theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) ); } else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) ) { @@ -139,6 +168,35 @@ void CurveCreator_Utils::setLocalPointContext( } } +bool CurveCreator_Utils::getNeighbourPoints( Handle(AIS_InteractiveContext) theContext, + Handle(V3d_View) theView, + const int theX, const int theY, + gp_Pnt& thePoint, gp_Pnt& thePoint1, + gp_Pnt& thePoint2 ) +{ + bool isFoundPoint = false; + if ( theContext.IsNull() ) + return isFoundPoint; + + for ( theContext->InitSelected(); theContext->MoreSelected() && !isFoundPoint; + theContext->NextSelected() ) { + TopoDS_Shape aTShape = theContext->SelectedShape(); + if ( !aTShape.IsNull() && aTShape.ShapeType() == TopAbs_VERTEX ) + continue; + else { + Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner(); + if ( anOwner.IsNull() ) + continue; + const TopLoc_Location& aLocation = anOwner->Location(); + Handle(AIS_InteractiveObject) anAIS = + Handle(AIS_InteractiveObject)::DownCast( anOwner->Selectable() ); + isFoundPoint = CurveCreator_Utils::pointOnObject( theView, anAIS, theX, theY, thePoint, + thePoint1, thePoint2 ); + } + } + return isFoundPoint; +} + bool CurveCreator_Utils::pointOnObject( Handle(V3d_View) theView, Handle(AIS_InteractiveObject) theObject, const int theX, const int theY,