-// Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "CurveCreator_Utils.hxx"
#include "CurveCreator.hxx"
#include "CurveCreator_Curve.hxx"
+#include "CurveCreator_Section.hxx"
#include "CurveCreator_UtilsICurve.hxx"
#include <Basics_OCCTVersion.hxx>
// we need the projection to the XOY plane
// 1. find a point in the plane of the eye and the normal to the plane
Standard_Real X, Y, Z;
- Quantity_Parameter Vx, Vy, Vz;
+ Standard_Real Vx, Vy, Vz;
aView->ConvertWithProj( x, y, X, Y, Z, Vx, Vy, Vz );
// 2. build a ray from the point by the normal to the XOY plane and intersect it
//=======================================================================
// function : constructBSpline
// purpose :
-// The algorithm builds the cubic B-spline passing through the points that the
-// tangent vector in each given point P is calculated by the following way:
-// if point P is preceded by a point A and is followed by a point B then
-// the tangent vector is equal to (P - A) / |P - A| + (B - P) / |B - P|;
-// if point P is preceded by a point A but is not followed by any point then
-// the tangent vector is equal to P - A;
-// if point P is followed by a point B but is not preceded by any point then
-// the tangent vector is equal to B - P.
//=======================================================================
-static bool constructBSpline(
+bool CurveCreator_Utils::constructBSpline(
const Handle(TColgp_HArray1OfPnt)& thePoints,
const Standard_Boolean theIsClosed,
Handle(Geom_BSplineCurve)& theBSpline)
return aResult;
}
+//=======================================================================
+// function : constructWire
+// purpose :
+//=======================================================================
+TopoDS_Wire CurveCreator_Utils::ConstructWire(
+ Handle(TColgp_HArray1OfPnt) thePoints,
+ const bool theIsPolyline,
+ const bool theIsClosed)
+{
+ TopoDS_Wire aWire;
+ BRep_Builder aBuilder;
+ aBuilder.MakeWire(aWire);
+ const int aPointCount = thePoints->Length();
+ if (theIsPolyline)
+ {
+ const TopoDS_Vertex aFirstVertex =
+ BRepBuilderAPI_MakeVertex(thePoints->Value(1));
+ TopoDS_Vertex aVertex = aFirstVertex;
+ for (Standard_Integer aPN = 1; aPN < aPointCount; ++aPN)
+ {
+ const TopoDS_Vertex aVertex2 =
+ BRepBuilderAPI_MakeVertex(thePoints->Value(aPN + 1));
+ aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aVertex, aVertex2));
+ aVertex = aVertex2;
+ }
+ if (theIsClosed && aPointCount > 1)
+ {
+ aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aVertex, aFirstVertex));
+ }
+ }
+ else
+ {
+ Handle(Geom_BSplineCurve) aBSpline;
+ if (constructBSpline(thePoints, theIsClosed, aBSpline))
+ {
+ aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aBSpline));
+ }
+ }
+ return aWire;
+}
+
//=======================================================================
// function : constructShape
// purpose :
}
// Get the different points.
- std::vector<gp_Pnt> aTmpPoints;
- gp_Pnt aFirstPoint;
- CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, 0, aFirstPoint);
- gp_Pnt aPoint = aFirstPoint;
- aTmpPoints.push_back(aPoint);
- for (int aPI = 1; aPI < aTmpPointCount; ++aPI)
- {
- gp_Pnt aPoint2;
- CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, aPI, aPoint2);
- if (!isEqualPoints(aPoint, aPoint2))
- {
- aPoint = aPoint2;
- aTmpPoints.push_back(aPoint);
- }
- }
+ const CurveCreator_ISection* aSection = theCurve->getSection(aSectionI);
+ Handle(TColgp_HArray1OfPnt) aPoints;
+ aSection->GetDifferentPoints(theCurve->getDimension(), aPoints);
+ const int aPointCount = aPoints->Length();
const bool isClosed = theCurve->isClosed(aSectionI);
- int aPointCount = aTmpPoints.size();
- if (isClosed)
- {
- while (aPointCount > 1 &&
- isEqualPoints(aFirstPoint, aTmpPoints[aPointCount - 1]))
- {
- --aPointCount;
- }
- }
// Add the vertices to the shape.
- Handle(TColgp_HArray1OfPnt) aPoints =
- new TColgp_HArray1OfPnt(1, aPointCount);
- for (Standard_Integer aPI = 0; aPI < aPointCount; ++aPI)
+ for (Standard_Integer aPN = 1; aPN <= aPointCount; ++aPN)
{
- aPoints->SetValue(aPI + 1, aTmpPoints[aPI]);
- aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aTmpPoints[aPI]));
- }
- if (aPointCount == 1)
- {
- continue;
+ aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aPoints->Value(aPN)));
}
- // Add the edges to the shape.
+ // Add the wire to the shape.
const bool isPolyline =
(theCurve->getSectionType(aSectionI) == CurveCreator::Polyline);
- if (isPolyline)
+ const TopoDS_Wire aWire = ConstructWire(aPoints, isPolyline, isClosed);
+ if (!aWire.IsNull())
{
- for (Standard_Integer aPN = 1; aPN < aPointCount; ++aPN)
- {
- aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge(
- BRepBuilderAPI_MakeVertex(aPoints->Value(aPN)),
- BRepBuilderAPI_MakeVertex(aPoints->Value(aPN + 1))));
- }
- if (isClosed)
- {
- aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge(
- BRepBuilderAPI_MakeVertex(aPoints->Value(aPointCount)),
- BRepBuilderAPI_MakeVertex(aPoints->Value(1))));
- }
- }
- else
- {
- Handle(Geom_BSplineCurve) aBSpline;
- if (constructBSpline(aPoints, isClosed, aBSpline))
- {
- aBuilder.Add(aShape,
- BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(aBSpline)));
- }
+ aBuilder.Add(aShape, aWire);
}
}
theShape = aShape;
{
thePoints.clear();
- std::list<float> aSelectedPoints;
+ std::list<double> aSelectedPoints;
gp_Pnt aPnt;
std::map<CompareSectionToPoint, int> aPointsMap;
//ASL: we switch off automatic highlight to improve performance of selection
theContext->SetAutomaticHilight( Standard_False );
- Handle_SelectMgr_Selection aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
+ Handle(SelectMgr_Selection) aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
for( aSelection->Init(); aSelection->More(); aSelection->Next() )
{
#if OCC_VERSION_LARGE > 0x06080100
const Handle(SelectMgr_SensitiveEntity) aHSenEntity = aSelection->Sensitive();
if( aHSenEntity.IsNull() )
continue;
- Handle_SelectBasics_SensitiveEntity aSenEntity = aHSenEntity->BaseSensitive();
+ Handle(SelectBasics_SensitiveEntity) aSenEntity = aHSenEntity->BaseSensitive();
#else
- Handle_SelectBasics_SensitiveEntity aSenEntity = aSelection->Sensitive();
+ Handle(SelectBasics_SensitiveEntity) aSenEntity = aSelection->Sensitive();
#endif
- Handle_Select3D_SensitivePoint aSenPnt = Handle_Select3D_SensitivePoint::DownCast( aSenEntity );
+ Handle(Select3D_SensitivePoint) aSenPnt = Handle(Select3D_SensitivePoint)::DownCast( aSenEntity );
gp_Pnt anOwnerPnt = aSenPnt->Point();
- Handle_SelectMgr_EntityOwner anOwner = Handle_SelectMgr_EntityOwner::DownCast( aSenPnt->OwnerId() );
+ Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast( aSenPnt->OwnerId() );
CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
}
else {
if ( theContext->HasOpenedContext() )
- theContext->CloseAllContexts();
+ theContext->CloseAllContexts( Standard_True );
}
}
// purpose :
//=======================================================================
void CurveCreator_Utils::FindPlane
- (const Handle_TColgp_HArray1OfPnt &thePoints,
+ (const Handle(TColgp_HArray1OfPnt) &thePoints,
gp_Pln &thePlane,
Standard_Integer &thePlnStatus)
{