2013-04-01 18:25:01 +06:00
|
|
|
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
|
2005-12-05 21:23:52 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
2005-12-05 21:23:52 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License.
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
2013-04-01 18:25:01 +06:00
|
|
|
//
|
2005-08-11 10:43:57 +06:00
|
|
|
|
2013-06-17 18:44:32 +06:00
|
|
|
#include "GEOMImpl_SplineDriver.hxx"
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2013-06-17 18:44:32 +06:00
|
|
|
#include "GEOMImpl_ISpline.hxx"
|
|
|
|
#include "GEOMImpl_Types.hxx"
|
|
|
|
#include "GEOMImpl_ICurveParametric.hxx"
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2013-06-17 18:44:32 +06:00
|
|
|
#include "GEOM_Function.hxx"
|
|
|
|
#include "GEOMUtils.hxx"
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
#include <BRepBuilderAPI_MakeEdge.hxx>
|
2012-08-09 13:58:02 +06:00
|
|
|
#include <BRepBuilderAPI_MakeVertex.hxx>
|
2004-12-01 15:39:14 +05:00
|
|
|
#include <BRep_Tool.hxx>
|
|
|
|
|
|
|
|
#include <TopAbs.hxx>
|
|
|
|
#include <TopExp.hxx>
|
|
|
|
#include <TopoDS.hxx>
|
|
|
|
#include <TopoDS_Shape.hxx>
|
|
|
|
#include <TopoDS_Edge.hxx>
|
|
|
|
#include <TopoDS_Vertex.hxx>
|
|
|
|
|
|
|
|
#include <Geom_BezierCurve.hxx>
|
|
|
|
#include <GeomAPI_Interpolate.hxx>
|
|
|
|
|
|
|
|
#include <gp.hxx>
|
|
|
|
#include <gp_Pnt.hxx>
|
|
|
|
#include <gp_Circ.hxx>
|
|
|
|
#include <Precision.hxx>
|
|
|
|
#include <TColgp_Array1OfPnt.hxx>
|
|
|
|
#include <TColgp_HArray1OfPnt.hxx>
|
|
|
|
|
2013-02-12 17:35:16 +06:00
|
|
|
#include <Standard_NullObject.hxx>
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
//=======================================================================
|
|
|
|
//function : GetID
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
const Standard_GUID& GEOMImpl_SplineDriver::GetID()
|
|
|
|
{
|
|
|
|
static Standard_GUID aSplineDriver("FF1BBB33-5D14-4df2-980B-3A668264EA16");
|
|
|
|
return aSplineDriver;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : GEOMImpl_SplineDriver
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
GEOMImpl_SplineDriver::GEOMImpl_SplineDriver()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : Execute
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const
|
|
|
|
{
|
|
|
|
if (Label().IsNull()) return 0;
|
|
|
|
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
|
|
|
|
|
|
|
|
GEOMImpl_ISpline aCI (aFunction);
|
|
|
|
Standard_Integer aType = aFunction->GetType();
|
|
|
|
|
|
|
|
TopoDS_Shape aShape;
|
|
|
|
|
2013-02-12 17:35:16 +06:00
|
|
|
if (aType == SPLINE_BEZIER ||
|
|
|
|
aType == SPLINE_INTERPOLATION ||
|
|
|
|
aType == SPLINE_INTERPOL_TANGENTS) {
|
2012-08-09 13:58:02 +06:00
|
|
|
|
|
|
|
bool useCoords = aCI.GetConstructorType() == COORD_CONSTRUCTOR;
|
2013-02-12 17:35:16 +06:00
|
|
|
|
|
|
|
Handle(TColStd_HArray1OfReal) aCoordsArray; // parametric case
|
|
|
|
Handle(TColStd_HSequenceOfTransient) aPoints; // points case
|
|
|
|
|
|
|
|
int aLen = 0;
|
|
|
|
if (useCoords) {
|
|
|
|
aCoordsArray = aCI.GetCoordinates();
|
|
|
|
aLen = aCoordsArray->Length() / 3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aPoints = aCI.GetPoints();
|
|
|
|
aLen = aPoints->Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLen < 2) return 0;
|
|
|
|
|
|
|
|
TColgp_Array1OfPnt points (1, (useCoords ? aLen : 1));
|
|
|
|
if (useCoords) {
|
2012-08-09 13:58:02 +06:00
|
|
|
int anArrayLength = aCoordsArray->Length();
|
|
|
|
for (int i = 0, j = 1; i <= (anArrayLength-3); i += 3) {
|
2013-06-17 18:44:32 +06:00
|
|
|
gp_Pnt aPnt = gp_Pnt(aCoordsArray->Value(i+1), aCoordsArray->Value(i+2), aCoordsArray->Value(i+3));
|
|
|
|
points.SetValue(j, aPnt);
|
|
|
|
j++;
|
2013-02-12 17:35:16 +06:00
|
|
|
}
|
2012-08-09 13:58:02 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
int aRealLen = aLen;
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2012-08-09 13:58:02 +06:00
|
|
|
if (aType == SPLINE_BEZIER && aCI.GetIsClosed()) {
|
|
|
|
TopoDS_Vertex aV1;
|
2013-02-12 17:35:16 +06:00
|
|
|
if (useCoords) {
|
2013-06-17 18:44:32 +06:00
|
|
|
aV1 = BRepBuilderAPI_MakeVertex(points.Value(1));
|
2013-02-12 17:35:16 +06:00
|
|
|
}
|
|
|
|
else {
|
2013-06-17 18:44:32 +06:00
|
|
|
Handle(GEOM_Function) aFPoint = Handle(GEOM_Function)::DownCast(aPoints->Value(1));
|
|
|
|
TopoDS_Shape aFirstPnt = aFPoint->GetValue();
|
|
|
|
aV1 = TopoDS::Vertex(aFirstPnt);
|
2012-08-09 13:58:02 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
TopoDS_Vertex aV2;
|
2013-02-12 17:35:16 +06:00
|
|
|
if (useCoords) {
|
2013-06-17 18:44:32 +06:00
|
|
|
aV2 = BRepBuilderAPI_MakeVertex(points.Value(aLen));
|
2013-02-12 17:35:16 +06:00
|
|
|
}
|
|
|
|
else {
|
2013-06-17 18:44:32 +06:00
|
|
|
Handle(GEOM_Function) aLPoint = Handle(GEOM_Function)::DownCast(aPoints->Value(aLen));
|
|
|
|
TopoDS_Shape aLastPnt = aLPoint->GetValue();
|
|
|
|
aV2 = TopoDS::Vertex(aLastPnt);
|
2012-08-09 13:58:02 +06:00
|
|
|
}
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2012-08-09 13:58:02 +06:00
|
|
|
if (!aV1.IsNull() && !aV2.IsNull() && !aV1.IsSame(aV2)) {
|
|
|
|
aRealLen++;
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 17:35:16 +06:00
|
|
|
|
|
|
|
int ind;
|
|
|
|
Standard_Boolean isSeveral = Standard_False;
|
|
|
|
gp_Pnt aPrevP;
|
|
|
|
|
2012-08-09 13:58:02 +06:00
|
|
|
TColgp_Array1OfPnt CurvePoints (1, aRealLen);
|
2004-12-01 15:39:14 +05:00
|
|
|
for (ind = 1; ind <= aLen; ind++) {
|
2012-08-09 13:58:02 +06:00
|
|
|
gp_Pnt aP;
|
2013-02-12 17:35:16 +06:00
|
|
|
if (useCoords) {
|
2013-06-17 18:44:32 +06:00
|
|
|
aP = points.Value(ind);
|
2004-12-01 15:39:14 +05:00
|
|
|
if (!isSeveral && ind > 1) {
|
|
|
|
if (aP.Distance(aPrevP) > Precision::Confusion()) {
|
|
|
|
isSeveral = Standard_True;
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 13:58:02 +06:00
|
|
|
CurvePoints.SetValue(ind, aP);
|
2004-12-01 15:39:14 +05:00
|
|
|
aPrevP = aP;
|
2013-02-12 17:35:16 +06:00
|
|
|
}
|
|
|
|
else {
|
2013-06-17 18:44:32 +06:00
|
|
|
Handle(GEOM_Function) aRefPoint = Handle(GEOM_Function)::DownCast(aPoints->Value(ind));
|
|
|
|
TopoDS_Shape aShapePnt = aRefPoint->GetValue();
|
|
|
|
if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
|
|
|
|
aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
|
|
|
|
if (!isSeveral && ind > 1) {
|
|
|
|
if (aP.Distance(aPrevP) > Precision::Confusion()) {
|
|
|
|
isSeveral = Standard_True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CurvePoints.SetValue(ind, aP);
|
|
|
|
aPrevP = aP;
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
}
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
if (aType == SPLINE_BEZIER) {
|
|
|
|
if (!isSeveral) {
|
|
|
|
Standard_ConstructionError::Raise("Points for Bezier Curve are too close");
|
|
|
|
}
|
2012-08-09 13:58:02 +06:00
|
|
|
if (aRealLen > aLen) { // set last point equal to first for the closed curve
|
|
|
|
CurvePoints.SetValue(aRealLen, CurvePoints.Value(1));
|
|
|
|
}
|
2013-02-12 17:35:16 +06:00
|
|
|
Handle(Geom_BezierCurve) GBC = new Geom_BezierCurve (CurvePoints);
|
2004-12-01 15:39:14 +05:00
|
|
|
aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
|
2013-02-12 17:35:16 +06:00
|
|
|
}
|
|
|
|
else {
|
2012-08-09 13:58:02 +06:00
|
|
|
//GeomAPI_PointsToBSpline GBC (CurvePoints);
|
|
|
|
//aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
|
|
|
|
|
|
|
|
if (aCI.GetDoReordering()) {
|
|
|
|
for (int curInd = 1; curInd < aLen - 1; curInd++) {
|
|
|
|
gp_Pnt curPnt = CurvePoints.Value(curInd);
|
|
|
|
int nearInd = 0;
|
|
|
|
double nearDist = RealLast();
|
|
|
|
for (ind = curInd + 1; ind <= aLen; ind++) {
|
|
|
|
double dist = curPnt.SquareDistance(CurvePoints.Value(ind));
|
|
|
|
if (dist < nearDist && (nearDist - dist) > Precision::Confusion()) {
|
|
|
|
nearInd = ind;
|
|
|
|
nearDist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nearInd > 0 && nearInd != curInd + 1) {
|
|
|
|
// Keep given order of points to use it in case of equidistant candidates
|
|
|
|
// .-<---<-.
|
|
|
|
// / \
|
|
|
|
// o o o c o->o->o->o->n o o
|
|
|
|
// | | |
|
|
|
|
// curInd curInd+1 nearInd
|
|
|
|
gp_Pnt nearPnt = CurvePoints.Value(nearInd);
|
|
|
|
for (ind = nearInd; ind > curInd + 1; ind--) {
|
|
|
|
CurvePoints.SetValue(ind, CurvePoints.Value(ind - 1));
|
|
|
|
}
|
|
|
|
CurvePoints.SetValue(curInd + 1, nearPnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 17:35:16 +06:00
|
|
|
|
|
|
|
Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
|
|
|
|
for (ind = 1; ind <= aLen; ind++) {
|
|
|
|
aHCurvePoints->SetValue(ind, CurvePoints.Value(ind));
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
2013-02-12 17:35:16 +06:00
|
|
|
|
|
|
|
bool isClosed = Standard_False;
|
|
|
|
if (aType == SPLINE_INTERPOLATION)
|
|
|
|
isClosed = aCI.GetIsClosed();
|
|
|
|
|
2012-08-09 13:58:02 +06:00
|
|
|
GeomAPI_Interpolate GBC (aHCurvePoints, isClosed, gp::Resolution());
|
2013-02-12 17:35:16 +06:00
|
|
|
|
|
|
|
if (aType == SPLINE_INTERPOL_TANGENTS) {
|
|
|
|
Handle(GEOM_Function) aVec1Ref = aCI.GetFirstVector();
|
|
|
|
Handle(GEOM_Function) aVec2Ref = aCI.GetLastVector();
|
|
|
|
|
|
|
|
if (aVec1Ref.IsNull() || aVec2Ref.IsNull())
|
|
|
|
Standard_NullObject::Raise("Null object is given for a vector");
|
|
|
|
|
|
|
|
TopoDS_Shape aVec1Sh = aVec1Ref->GetValue();
|
|
|
|
TopoDS_Shape aVec2Sh = aVec2Ref->GetValue();
|
|
|
|
|
2013-04-01 18:25:01 +06:00
|
|
|
// take orientation of edge into account to avoid regressions, as it was implemented so
|
|
|
|
gp_Vec aV1 = GEOMUtils::GetVector(aVec1Sh, Standard_True);
|
|
|
|
gp_Vec aV2 = GEOMUtils::GetVector(aVec2Sh, Standard_True);
|
2013-02-12 17:35:16 +06:00
|
|
|
|
|
|
|
GBC.Load(aV1, aV2, /*Scale*/Standard_True);
|
|
|
|
}
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
GBC.Perform();
|
|
|
|
if (GBC.IsDone())
|
2005-08-11 10:43:57 +06:00
|
|
|
aShape = BRepBuilderAPI_MakeEdge(GBC.Curve()).Edge();
|
2004-12-01 15:39:14 +05:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
}
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
if (aShape.IsNull()) return 0;
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
aFunction->SetValue(aShape);
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
log.SetTouched(Label());
|
2013-02-12 17:35:16 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-06-17 18:44:32 +06:00
|
|
|
//================================================================================
|
|
|
|
/*!
|
|
|
|
* \brief Returns a name of creation operation and names and values of creation parameters
|
|
|
|
*/
|
|
|
|
//================================================================================
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2013-06-17 18:44:32 +06:00
|
|
|
bool GEOMImpl_SplineDriver::
|
|
|
|
GetCreationInformation(std::string& theOperationName,
|
|
|
|
std::vector<GEOM_Param>& theParams)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
2013-06-17 18:44:32 +06:00
|
|
|
if (Label().IsNull()) return 0;
|
|
|
|
Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
|
|
|
|
|
|
|
|
GEOMImpl_ISpline aCI( function );
|
|
|
|
GEOMImpl_ICurveParametric aPI( function );
|
|
|
|
Standard_Integer aType = function->GetType();
|
|
|
|
|
|
|
|
theOperationName = "CURVE";
|
|
|
|
|
|
|
|
switch ( aType ) {
|
|
|
|
case SPLINE_BEZIER:
|
|
|
|
case SPLINE_INTERPOLATION:
|
|
|
|
case SPLINE_INTERPOL_TANGENTS:
|
|
|
|
|
|
|
|
AddParam( theParams, "Type", ( aType == SPLINE_BEZIER ? "Bezier" : "Interpolation"));
|
|
|
|
|
|
|
|
if ( aPI.HasData() )
|
|
|
|
{
|
|
|
|
AddParam( theParams, "X(t) equation", aPI.GetExprX() );
|
|
|
|
AddParam( theParams, "Y(t) equation", aPI.GetExprY() );
|
|
|
|
AddParam( theParams, "Z(t) equation", aPI.GetExprZ() );
|
|
|
|
AddParam( theParams, "Min t", aPI.GetParamMin() );
|
|
|
|
AddParam( theParams, "Max t", aPI.GetParamMax() );
|
|
|
|
if ( aPI.GetParamNbStep() )
|
|
|
|
AddParam( theParams, "Number of steps", aPI.GetParamNbStep() );
|
|
|
|
else
|
|
|
|
AddParam( theParams, "t step", aPI.GetParamStep() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( aCI.GetConstructorType() == COORD_CONSTRUCTOR )
|
|
|
|
{
|
|
|
|
Handle(TColStd_HArray1OfReal) coords = aCI.GetCoordinates();
|
|
|
|
GEOM_Param& pntParam = AddParam( theParams, "Points");
|
|
|
|
pntParam << ( coords->Length() ) / 3 << " points: ";
|
|
|
|
for ( int i = coords->Lower(), nb = coords->Upper(); i <= nb; )
|
|
|
|
pntParam << "( " << coords->Value( i++ )
|
|
|
|
<< ", " << coords->Value( i++ )
|
|
|
|
<< ", " << coords->Value( i++ ) << " ) ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AddParam( theParams, "Points", aCI.GetPoints() );
|
|
|
|
}
|
|
|
|
Handle(GEOM_Function) v1 = aCI.GetFirstVector();
|
|
|
|
Handle(GEOM_Function) v2 = aCI.GetLastVector();
|
|
|
|
if ( !v1.IsNull() ) AddParam( theParams, "First tangent vector", v1 );
|
|
|
|
if ( !v2.IsNull() ) AddParam( theParams, "Last tangent vector", v2 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
2013-06-17 18:44:32 +06:00
|
|
|
return true;
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
2013-06-17 18:44:32 +06:00
|
|
|
|
|
|
|
IMPLEMENT_STANDARD_HANDLE (GEOMImpl_SplineDriver,GEOM_BaseDriver);
|
|
|
|
IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_SplineDriver,GEOM_BaseDriver);
|