#include "CurveCreator_NewSectionDlg.h"
#include "CurveCreator_Utils.h"
-#include <GEOMUtils.hxx>
-
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Edge.hxx>
#include <gp_Lin.hxx>
#include <gp_Dir.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
const double LOCAL_SELECTION_TOLERANCE = 0.0001;
const int POINT_INDEX_COLUMN_WIDTH = 50;
+const int SCENE_PIXEL_TOLERANCE = 4;
+
CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
CurveCreator_ICurve *theCurve,
Qt::WindowFlags fl)
{
OCCViewer_ViewPort3d* vp =
((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort();
- aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
+ aPnt = CurveCreator_Utils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
}
// set the coordinates into dialog
CurveCreator::Coordinates aCoords;
//setLocalPointContext( false );
OCCViewer_ViewWindow* aWindow =
(OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView();
- gp_Pnt aStartPnt = GEOMUtils::ConvertClickToPoint( myDragStartPosition.x(), myDragStartPosition.y(),
+ gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(), myDragStartPosition.y(),
aWindow->getViewPort()->getView() );
- gp_Pnt anEndPnt = GEOMUtils::ConvertClickToPoint( aPos.x(), aPos.y(),
+ gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( aPos.x(), aPos.y(),
aWindow->getViewPort()->getView() );
double aXDelta = aStartPnt.X() - anEndPnt.X();
double anYDelta = aStartPnt.Y() - anEndPnt.Y();
if ( theOpen ) {
// Open local context if there is no one
- bool allObjects = true;
if ( !ic->HasOpenedContext() ) {
ic->ClearCurrents( false );
- ic->OpenLocalContext( allObjects, true, true );
+ ic->OpenLocalContext( false/*use displayed objects*/, true/*allow shape decomposition*/ );
}
AIS_ListOfInteractive aList;
ic->DisplayedObjects( aList );
for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
aLSize++;
- int theMode = TopAbs_VERTEX;
for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
{
Handle(AIS_InteractiveObject) anAIS = it.Value();
{
if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
{
- ic->Load( anAIS, -1, false );
- ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
+ ic->Load( anAIS, -1/*selection mode*/, true/*allow decomposition*/ );
+ ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) );
}
else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
{
- ic->Load( anAIS, -1, false );
- ic->Activate( anAIS, theMode );
+ ic->Load( anAIS, -1/*selection mode*/, false/*allow decomposition*/ );
+ ic->Activate( anAIS, TopAbs_VERTEX );
}
}
continue;
if ( theObject.IsNull() || !aViewer )
return isFound;
- OCCViewer_ViewWindow* aWindow =
- (OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView();
- thePoint = GEOMUtils::ConvertClickToPoint( theX, theY,
- aWindow->getViewPort()->getView() );
-
+ gp_Pnt aPoint;
+ gp_Pnt aPnt1, aPnt2;
Handle(AIS_Line) aLine = Handle(AIS_Line)::DownCast( theObject );
if ( !aLine.IsNull() ) {
+ const Handle(Geom_Line) aGLine = aLine->Line();
Handle(Geom_Point) aPStart;
Handle(Geom_Point) aPEnd;
aLine->Points( aPStart, aPEnd );
-
- Standard_Real aStartX = aPStart->X(),
- aStartY = aPStart->Y(),
- aStartZ = aPStart->Z();
- Standard_Real anEndX = aPEnd->X(),
- anEndY = aPEnd->Y(),
- anEndZ = aPEnd->Z();
- // TODO: check whether the point belong to the selected line
- gp_Lin aLin( gp_Pnt( aPStart->X(), aPStart->Y(), aPStart->Z() ),
- gp_Dir( gp_Vec( gp_Pnt( aPStart->X(), aPStart->Y(), aPStart->Z() ),
- gp_Pnt( aPEnd->X(), aPEnd->Y(), aPEnd->Z() ) ) ) );
- double aDistance = aLin.Distance( thePoint );
-
-
- if ( aLin.Contains( thePoint, LOCAL_SELECTION_TOLERANCE ) ) {
- // find the neighbour points
- thePoint1 = findLocalPointIndex( 0, aPStart->X(), aPStart->Y() );
- thePoint2 = findLocalPointIndex( 0, aPEnd->X(), aPEnd->Y() );
-
- isFound = thePoint1 >= 0 && thePoint2 >= 0;
- }
+ aPnt1 = aPStart->Pnt();
+ aPnt2 = aPEnd->Pnt();
+ isFound = hasProjectPointOnCurve( theX, theY, aGLine, aPoint );
}
else {
Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast( theObject );
if ( !aShape.IsNull() ) {
- // find the neighbour points
+ const TopoDS_Wire& aWire = TopoDS::Wire( aShape->Shape() );
+ if ( !aWire.IsNull() ) {
+ TopExp_Explorer anExp( aWire, TopAbs_EDGE );
+ for ( ; anExp.More(); anExp.Next())
+ {
+ const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
+ if ( !anEdge.IsNull() ) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aFirst, aLast );
+ aCurve->D0(aFirst,aPnt1);
+ aCurve->D0(aLast,aPnt2);
+ isFound = hasProjectPointOnCurve( theX, theY, aCurve, aPoint );
+ }
+ }
+ }
+ }
+ }
+ if ( isFound ) {
+ thePoint = aPoint;
+ thePoint1 = findLocalPointIndex( 0, aPnt1.X(), aPnt1.Y() );
+ thePoint2 = findLocalPointIndex( 0, aPnt2.X(), aPnt2.Y() );
+ isFound = thePoint1 >= 0 && thePoint2 >= 0;
+ }
+ return isFound;
+}
+
+/**
+ * Returns whether the clicked point belong to the curve or has a very near projection
+ * \param theX the X coordinate of a point clicked in the OCC viewer
+ * \param theY the Y coordinate of a point clicked in the OCC viewer
+ * \param theCurve a geometry curve
+ * \param theOutPoint a found projected point on the curve
+ */
+bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY,
+ const Handle(Geom_Curve)& theCurve,
+ gp_Pnt& theOutPoint )
+{
+ bool isFound = false;
+ OCCViewer_Viewer* aViewer = getOCCViewer();
+ if ( !aViewer )
+ return isFound;
+
+ OCCViewer_ViewWindow* aWindow =
+ (OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView();
+ Handle(V3d_View) aView = aWindow->getViewPort()->getView();
+ gp_Pnt aPoint = CurveCreator_Utils::ConvertClickToPoint( theX, theY, aView );
+
+ GeomAPI_ProjectPointOnCurve aProj( aPoint, theCurve );
+ Standard_Integer aNbPoint = aProj.NbPoints();
+ if (aNbPoint > 0) {
+ for (Standard_Integer j = 1; j <= aNbPoint && !isFound; j++) {
+ gp_Pnt aNewPoint = aProj.Point(j);
+
+ int aX, anY;
+ CurveCreator_Utils::ConvertPointToClick( aNewPoint, aView, aX, anY );
+
+ int aXDelta = abs( aX - theX );
+ int anYDelta = abs( anY - theY );
+ isFound = aXDelta < SCENE_PIXEL_TOLERANCE && anYDelta < SCENE_PIXEL_TOLERANCE;
+ if ( isFound ) {
+ theOutPoint = aNewPoint;
+ }
}
}
return isFound;