//
#include "CurveCreator_Utils.h"
+#include "CurveCreator.hxx"
+#include "CurveCreator_UtilsICurve.hxx"
#include <GEOMUtils.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Edge.hxx>
+#include <TopoDS_Compound.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <Geom_Line.hxx>
#include <TopExp_Explorer.hxx>
-#include <BRep_Tool.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+
+#include <TColgp_HArray1OfPnt.hxx>
+#include <GeomAPI_Interpolate.hxx>
#include <ProjLib.hxx>
#include <ElSLib.hxx>
+#include "CurveCreator_ICurve.hxx"
+
const double LOCAL_SELECTION_TOLERANCE = 0.0001;
-const int SCENE_PIXEL_TOLERANCE = 10;
+const int SCENE_PIXEL_TOLERANCE = 10;
//=======================================================================
// function : ConvertClickToPoint()
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;
- */
}
+void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve,
+ TopoDS_Shape& theShape )
+{
+ BRep_Builder aBuilder;
+ TopoDS_Compound aComp;
+ aBuilder.MakeCompound( aComp );
+ for( int iSection = 0 ; iSection < theCurve->getNbSections() ; iSection++ )
+ {
+ int theISection = iSection;
+
+ CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection );
+ int aPointSize = theCurve->getNbPoints( theISection );
+ bool aSectIsClosed = theCurve->isClosed( theISection );
+ bool isPolyline = aSectType == CurveCreator::Polyline;
+ int iPoint = 0;
+ gp_Pnt aPrevPoint, aPoint;
+ if ( aPointSize == 1 ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ }
+ else if ( aPointSize > 1 ) {
+ Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aPointSize);
+ int aHIndex = 1;
+
+ TopoDS_Edge aPointEdge;
+ TopoDS_Vertex aVertex;
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ aHCurvePoints->SetValue(aHIndex++, aPoint);
+ aPrevPoint = aPoint;
+ iPoint++;
+ for( ; iPoint < aPointSize; iPoint++ ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ aHCurvePoints->SetValue(aHIndex++, aPoint);
+ if ( isPolyline ) {
+ aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+ aBuilder.Add( aComp, aPointEdge );
+ }
+ aPrevPoint = aPoint;
+ }
+ if( aSectIsClosed && ( aPointSize > 2 ) ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, 0, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ if ( isPolyline ) {
+ aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+ aBuilder.Add( aComp, aPointEdge );
+ }
+ }
+ if( !isPolyline ) {
+ // compute BSpline
+ Handle(Geom_BSplineCurve) aBSplineCurve;
+ GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
+ aGBC.Perform();
+ if ( aGBC.IsDone() )
+ aBSplineCurve = aGBC.Curve();
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
+ TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
+ aBuilder.Add( aComp, aWire );
+ }
+ }
+ }
+ theShape = aComp;
+}
+
+class ComparePnt
+{
+public:
+ ComparePnt( const gp_Pnt& thePoint ) : myPoint( thePoint) {};
+ ~ComparePnt() {}
+
+ bool operator < ( const ComparePnt& theOtherPoint ) const
+ {
+ bool isLess = myPoint.X() < theOtherPoint.myPoint.X();
+ if ( !isLess && myPoint.X() == theOtherPoint.myPoint.X() ) {
+ isLess = myPoint.Y() < theOtherPoint.myPoint.Y();
+ if ( !isLess && myPoint.Y() == theOtherPoint.myPoint.Y() )
+ isLess = myPoint.Z() < theOtherPoint.myPoint.Z();
+ }
+ return isLess;
+ }
+private:
+ gp_Pnt myPoint;
+};
+
+std::list<float> CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext )
+{
+ std::list<float> aSelectedPoints;
+
+ gp_Pnt aPnt;
+ std::map<ComparePnt, int> aPntMap;
+
+ 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() );
+
+ if ( aVertex.IsNull() )
+ continue;
+ aPnt = BRep_Tool::Pnt( aVertex );
+ if ( aPntMap.find( aPnt ) != aPntMap.end() )
+ continue;
+ aPntMap[aPnt] = 0;
+ 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_GLOBAL_SELECTION
void CurveCreator_Utils::setLocalPointContext(
Handle(AIS_InteractiveContext) theContext,
const bool theOpen )
{
+#ifdef USE_GLOBAL_SELECTION
+ return;
+#endif
if ( !theContext )
return;
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) )
{
}
}
+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,