//
#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;
return GEOMUtils::ConvertClickToPoint( x, y, aView );
}
+
+//#define USE_COMPOUND
+#include "CurveCreator_Curve.hxx" // TODO - remove
+void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve,
+ const int theISection, TopoDS_Shape& theShape,
+ std::vector<Handle_AIS_InteractiveObject>& aSectionRepresentation )
+{
+ CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection );
+
+
+ int aPointSize = theCurve->getNbPoints( theISection );
+ bool aSectIsClosed = theCurve->isClosed( theISection );
+ if( aSectType == CurveCreator::Polyline )
+ {
+#ifdef USE_COMPOUND
+ BRep_Builder aBuilder;
+ TopoDS_Compound aComp;
+ aBuilder.MakeCompound(aComp);
+
+ int iPoint = 0;
+ gp_Pnt aPrevPoint, aPoint;
+ if ( aPointSize == 1 ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPrevPoint );
+ TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ }
+ else if ( aPointSize > 1 ) {
+ TopoDS_Edge aPointEdge;
+ TopoDS_Vertex aVertex;
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPrevPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ iPoint++;
+ for( ; iPoint < aPointSize; iPoint++ ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ 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 );
+ aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+ aBuilder.Add( aComp, aPointEdge );
+ }
+ theShape = aComp;
+ }
+#endif
+ }
+ else if( aSectType == CurveCreator::Spline )
+ {
+ std::vector<double> aPoints;
+ for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
+ {
+ CurveCreator::Coordinates aCoords = theCurve->getPoint( theISection, iPoint );
+ double aX = aCoords[0];
+ double aY = aCoords[1];
+ double aZ = aCoords[2];
+ aPoints.push_back( aX );
+ aPoints.push_back( aY );
+ }
+
+ if( aPointSize > 1 )
+ {
+ Handle(Geom_BSplineCurve) aBSplineCurve;
+ // fill array for algorithm by the received coordinates
+ int aLen = aPoints.size() / 2;
+ Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
+ std::vector<double>::const_iterator aListIter = aPoints.begin();
+ for (int ind = 1; ind <= aLen; ind++) {
+ gp_Pnt aPnt(gp::Origin());
+ aPnt.SetX(*aListIter);
+ aListIter++;
+ aPnt.SetY(*aListIter);
+ aListIter++;
+ aPnt.SetZ(0);
+ aHCurvePoints->SetValue(ind, aPnt);
+ }
+ // compute BSpline
+ 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();
+ theShape = aWire;
+ }
+ }
+
+ const CurveCreator_Curve* aCurve = dynamic_cast<const CurveCreator_Curve*>( theCurve );
+ if ( !aCurve )
+ return;
+
+ if( aSectType == CurveCreator::Polyline )
+ {
+#ifndef USE_COMPOUND
+ int iPoint = 0;
+ for( ; iPoint < ( aPointSize - 1 ) ; iPoint++ ){
+ Handle_AIS_Point anAISPnt = aCurve->getAISPoint(theISection, iPoint);
+ aSectionRepresentation.push_back( anAISPnt );
+ Handle_AIS_Line aLine = aCurve->getAISLine( theISection, iPoint, iPoint+1 );
+ aSectionRepresentation.push_back( aLine );
+ }
+ if( aPointSize != 0 ){
+ Handle_AIS_Point anAISPnt = aCurve->getAISPoint(theISection, iPoint);
+ aSectionRepresentation.push_back( anAISPnt );
+ if( aSectIsClosed && ( aPointSize > 1 ) ){
+ Handle_AIS_Line aLine = aCurve->getAISLine( theISection, iPoint, 0 );
+ aSectionRepresentation.push_back( aLine );
+ }
+ }
+#endif
+ }
+ else if( aSectType == CurveCreator::Spline )
+ {
+ std::vector<double> aPoints;
+ for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
+ {
+ Handle_AIS_Point anAISPnt = aCurve->getAISPoint( theISection, iPoint );
+ aSectionRepresentation.push_back( anAISPnt );
+ }
+ }
+}
+
+std::list<float> CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext )
+{
+ std::list<float> 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_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) )
{