From: mbs Date: Mon, 29 May 2023 17:01:36 +0000 (+0100) Subject: added support for all type of edges in KindOfShape method X-Git-Tag: V9_12_0a1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cfc267474fbe4c092b88a40e8d28031a00950450;p=modules%2Fgeom.git added support for all type of edges in KindOfShape method --- diff --git a/doc/salome/examples/kind_of_shape.py b/doc/salome/examples/kind_of_shape.py new file mode 100644 index 000000000..b2f9db8cf --- /dev/null +++ b/doc/salome/examples/kind_of_shape.py @@ -0,0 +1,63 @@ +# Sample: KindOfShape method for Edges + +import salome +from inspect import getfile +from os.path import abspath, dirname, join +salome.salome_init_without_session() +import GEOM + +from salome.geom import geomBuilder +geompy = geomBuilder.New() + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Vertex_1 = geompy.MakeVertex(0, 0, 0) +Vertex_2 = geompy.MakeVertex(50, 100, 0) +Vertex_3 = geompy.MakeVertex(-10, 60, 0) +Vertex_4 = geompy.MakeVertex(0, 100, 0) +Vertex_5 = geompy.MakeVertex(-100, 100, 0) +Vertex_6 = geompy.MakeVertex(-100, 0, 0) +Vertex_7 = geompy.MakeVertex(-200, 0, 0) +Vertex_8 = geompy.MakeVertex(-200, 100, 0) + +# create some curves +Line_1 = geompy.MakeLineTwoPnt(Vertex_1, Vertex_2) +Circle_1 = geompy.MakeCircle(Vertex_2, OZ, 50) +Ellipse_1 = geompy.MakeEllipse(Vertex_1, OZ, 200, 100, Line_1) +Arc_1 = geompy.MakeArc(Vertex_2, Vertex_3, Vertex_1) +Curve_1 = geompy.MakeCurveParametric("t", "50*sin(t)", "0", 0, 360, 30, GEOM.Interpolation, True) +Curve_2 = geompy.MakeCurveParametric("-t", "50*cos(t)", "t", 0, 360, 14, GEOM.Bezier, True) +Curve_5 = geompy.MakeInterpol([Vertex_1, Vertex_4, Vertex_5, Vertex_6, Vertex_7, Vertex_8], False, False) +Curve_7 = geompy.MakeBezier([Vertex_5, Vertex_6, Vertex_7, Vertex_8], True) +Curve_8 = geompy.MakeBezier([Vertex_5, Vertex_6, Vertex_1, Vertex_4], False) + +# show information for all curves +props = geompy.KindOfShape(Line_1) +print("KindOfShape(Line_1): ", props) +# [SEGMENT, 0.,0.,0., 50.,100.,0.] +props = geompy.KindOfShape(Circle_1) +print("KindOfShape(Circle_1): ", props) +# [CIRCLE, 50.,100.,0., 0.,0.,1., 50.] +props = geompy.KindOfShape(Ellipse_1) +print("KindOfShape(Ellipse_1): ", props) +# [ELLIPSE, 0.,0.,0., 0.,0.,1., 200., 100., 0.44721,0.89443,0., 0.44721,0.89443,0.] +props = geompy.KindOfShape(Arc_1) +print("KindOfShape(Arc_1): ", props) +# [ARC_CIRCLE, 47.5,38.75,0., 0.,0.,1., 61.301, 50.,100.,0., 0.,0.,0.] +props = geompy.KindOfShape(Curve_1) +print("KindOfShape(Curve_1): ", props) +# [CRV_BSPLINE, 0, 3, 33, 31, 0, 31, 0.,0.,0.,..., 4,1,...,1,4] +props = geompy.KindOfShape(Curve_2) +print("KindOfShape(Curve_2): ", props) +# [CRV_BEZIER, 15, 0, 0.,50.,0.,...,-360.,-14.18455,360.] +props = geompy.KindOfShape(Curve_5) +print("KindOfShape(Curve_5): ", props) +# [CRV_BSPLINE, 0, 3, 8, 6, 0, 6, 0.,0.,0.,..., 100.,0.,0.,100.,200.,300.,400.,500., 4,1,1,1,1,4] +props = geompy.KindOfShape(Curve_7) +print("KindOfShape(Curve_7): ", props) +# [CRV_BEZIER, 5, 0, -100.,100.,0., -100.,0.,0., -200.,0.,0., -200.,100.,0., -100.,100.,0.] +props = geompy.KindOfShape(Curve_8) +print("KindOfShape(Curve_8): ", props) +# [CRV_BEZIER, 4, 0, -100.,100.,0., -100.,0.,0., 0.,0.,0., 0.,100.,0.] diff --git a/doc/salome/gui/GEOM/input/tui_kind_of_shape.doc b/doc/salome/gui/GEOM/input/tui_kind_of_shape.doc new file mode 100644 index 000000000..f8219bb5e --- /dev/null +++ b/doc/salome/gui/GEOM/input/tui_kind_of_shape.doc @@ -0,0 +1,7 @@ +/*! + +\page tui_kind_of_shape_page Get information about a shape + +\tui_script{kind_of_shape.py} + +*/ diff --git a/doc/salome/gui/GEOM/input/tui_measurement_tools.doc b/doc/salome/gui/GEOM/input/tui_measurement_tools.doc index 59eea50df..e0ce0be61 100644 --- a/doc/salome/gui/GEOM/input/tui_measurement_tools.doc +++ b/doc/salome/gui/GEOM/input/tui_measurement_tools.doc @@ -24,6 +24,7 @@
  • \subpage tui_check_conformity_page
  • \subpage tui_shape_proximity_page
  • \subpage tui_xyz_to_uv_page
  • +
  • \subpage tui_kind_of_shape_page
  • */ diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 8d9e2ff2b..ee4467fe4 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -4305,6 +4305,14 @@ module GEOM LINE, /*! segment */ SEGMENT, + /*! B-Spline curve */ + CRV_BSPLINE, + /*! Bezier curve */ + CRV_BEZIER, + /*! hyperbola */ + HYPERBOLA, + /*! parabola */ + PARABOLA, /*! other edge */ EDGE, // VERTEX diff --git a/src/GEOMAlgo/CMakeLists.txt b/src/GEOMAlgo/CMakeLists.txt index ffc21ec91..d620e4e3b 100644 --- a/src/GEOMAlgo/CMakeLists.txt +++ b/src/GEOMAlgo/CMakeLists.txt @@ -83,6 +83,7 @@ SET(GEOMAlgo_HEADERS GEOMAlgo_KindOfClosed.hxx GEOMAlgo_KindOfDef.hxx GEOMAlgo_KindOfName.hxx + GEOMAlgo_KindOfPeriod.hxx GEOMAlgo_KindOfShape.hxx GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx GEOMAlgo_ListIteratorOfListOfPnt.hxx diff --git a/src/GEOMAlgo/GEOMAlgo_KindOfName.hxx b/src/GEOMAlgo/GEOMAlgo_KindOfName.hxx index b0de007a1..90fe883a4 100644 --- a/src/GEOMAlgo/GEOMAlgo_KindOfName.hxx +++ b/src/GEOMAlgo/GEOMAlgo_KindOfName.hxx @@ -45,7 +45,11 @@ GEOMAlgo_KN_RECTANGLE, GEOMAlgo_KN_TRIANGLE, GEOMAlgo_KN_QUADRANGLE, GEOMAlgo_KN_ARCELLIPSE, -GEOMAlgo_KN_SOLID +GEOMAlgo_KN_SOLID, +GEOMAlgo_KN_CURVEBSPLINE, +GEOMAlgo_KN_CURVEBEZIER, +GEOMAlgo_KN_HYPERBOLA, +GEOMAlgo_KN_PARABOLA }; #ifndef _Standard_PrimitiveTypes_HeaderFile diff --git a/src/GEOMAlgo/GEOMAlgo_KindOfPeriod.hxx b/src/GEOMAlgo/GEOMAlgo_KindOfPeriod.hxx new file mode 100644 index 000000000..05bb8ed1b --- /dev/null +++ b/src/GEOMAlgo/GEOMAlgo_KindOfPeriod.hxx @@ -0,0 +1,36 @@ +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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, or (at your option) any later version. +// +// 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. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef _GEOMAlgo_KindOfPeriod_HeaderFile +#define _GEOMAlgo_KindOfPeriod_HeaderFile + + +enum GEOMAlgo_KindOfPeriod { +GEOMAlgo_KP_UNKNOWN, +GEOMAlgo_KP_PERIODIC, +GEOMAlgo_KP_NONPERIODIC +}; + +#ifndef _Standard_PrimitiveTypes_HeaderFile +#include +#endif + +#endif diff --git a/src/GEOMAlgo/GEOMAlgo_KindOfShape.hxx b/src/GEOMAlgo/GEOMAlgo_KindOfShape.hxx index 99e001366..83ff2ea5a 100644 --- a/src/GEOMAlgo/GEOMAlgo_KindOfShape.hxx +++ b/src/GEOMAlgo/GEOMAlgo_KindOfShape.hxx @@ -35,7 +35,10 @@ GEOMAlgo_KS_PLANE, GEOMAlgo_KS_CIRCLE, GEOMAlgo_KS_LINE, GEOMAlgo_KS_DEGENERATED, -GEOMAlgo_KS_BSPLINE +GEOMAlgo_KS_BSPLINE, +GEOMAlgo_KS_BEZIER, +GEOMAlgo_KS_HYPERBOLA, +GEOMAlgo_KS_PARABOLA }; #ifndef _Standard_PrimitiveTypes_HeaderFile diff --git a/src/GEOMAlgo/GEOMAlgo_ShapeInfo.cxx b/src/GEOMAlgo/GEOMAlgo_ShapeInfo.cxx index 4659afaa3..1d856ba3f 100644 --- a/src/GEOMAlgo/GEOMAlgo_ShapeInfo.cxx +++ b/src/GEOMAlgo/GEOMAlgo_ShapeInfo.cxx @@ -31,6 +31,8 @@ static void DumpKindOfName(const GEOMAlgo_KindOfName aKS); static void DumpKindOfDef(const GEOMAlgo_KindOfDef aKD); +static + void DumpKindOfPeriod(const GEOMAlgo_KindOfPeriod aKP); static void DumpPosition(const gp_Ax3& aAx3); static @@ -72,6 +74,7 @@ void GEOMAlgo_ShapeInfo::Reset() myKindOfClosed=GEOMAlgo_KC_UNKNOWN; myKindOfName=GEOMAlgo_KN_UNKNOWN; myKindOfDef=GEOMAlgo_KD_UNKNOWN; + myKindOfPeriod=GEOMAlgo_KP_UNKNOWN; // myLocation.SetCoord(99., 99., 99.); myDirection.SetCoord(1.,0.,0.); @@ -81,6 +84,15 @@ void GEOMAlgo_ShapeInfo::Reset() myLength=-3.; myWidth=-3.; myHeight=-3.; + myDegree=0; + myNbPoles=0; + myNbKnots=0; + myNbWeights=0; + myNbMultiplicities=0; + myPoles = Handle(TColgp_HArray1OfPnt)(); + myKnots = Handle(TColStd_HArray1OfReal)(); + myWeights = Handle(TColStd_HArray1OfReal)(); + myMultiplicities = Handle(TColStd_HArray1OfInteger)(); } //======================================================================= //function : SetType @@ -208,6 +220,22 @@ GEOMAlgo_KindOfDef GEOMAlgo_ShapeInfo::KindOfDef() const return myKindOfDef; } //======================================================================= +//function : SetKindOfPeriod +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetKindOfPeriod(const GEOMAlgo_KindOfPeriod aT) +{ + myKindOfPeriod=aT; +} +//======================================================================= +//function : KindOfPeriod +//purpose : +//======================================================================= +GEOMAlgo_KindOfPeriod GEOMAlgo_ShapeInfo::KindOfPeriod() const +{ + return myKindOfPeriod; +} +//======================================================================= //function : SetLocation //purpose : //======================================================================= @@ -378,6 +406,150 @@ Standard_Real GEOMAlgo_ShapeInfo::Height() const return myHeight; } //======================================================================= +//function : SetDegree +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetDegree(const Standard_Integer aD) +{ + myDegree=aD; +} +//======================================================================= +//function : Degree +//purpose : +//======================================================================= +Standard_Integer GEOMAlgo_ShapeInfo::Degree() const +{ + return myDegree; +} +//======================================================================= +//function : SetNbPoles +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetNbPoles(const Standard_Integer aNb) +{ + myNbPoles=aNb; +} +//======================================================================= +//function : NbPoles +//purpose : +//======================================================================= +Standard_Integer GEOMAlgo_ShapeInfo::NbPoles() const +{ + return myNbPoles; +} +//======================================================================= +//function : SetNbKnots +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetNbKnots(const Standard_Integer aNb) +{ + myNbKnots=aNb; +} +//======================================================================= +//function : NbKnots +//purpose : +//======================================================================= +Standard_Integer GEOMAlgo_ShapeInfo::NbKnots() const +{ + return myNbKnots; +} +//======================================================================= +//function : SetNbWeights +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetNbWeights(const Standard_Integer aNb) +{ + myNbWeights=aNb; +} +//======================================================================= +//function : NbWeights +//purpose : +//======================================================================= +Standard_Integer GEOMAlgo_ShapeInfo::NbWeights() const +{ + return myNbWeights; +} +//======================================================================= +//function : SetNbMultiplicities +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetNbMultiplicities(const Standard_Integer aNb) +{ + myNbMultiplicities=aNb; +} +//======================================================================= +//function : NbWeights +//purpose : +//======================================================================= +Standard_Integer GEOMAlgo_ShapeInfo::NbMultiplicities() const +{ + return myNbMultiplicities; +} +//======================================================================= +//function : SetPoles +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetPoles(Handle(TColgp_HArray1OfPnt) P) +{ + myPoles = P; +} +//======================================================================= +//function : Poles +//purpose : +//======================================================================= +Handle(TColgp_HArray1OfPnt) GEOMAlgo_ShapeInfo::Poles() const +{ + return myPoles; +} +//======================================================================= +//function : SetKnots +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetKnots(Handle(TColStd_HArray1OfReal) K) +{ + myKnots = K; +} +//======================================================================= +//function : Knots +//purpose : +//======================================================================= +Handle(TColStd_HArray1OfReal) GEOMAlgo_ShapeInfo::Knots() const +{ + return myKnots; +} +//======================================================================= +//function : SetWeights +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetWeights(Handle(TColStd_HArray1OfReal) W) +{ + myWeights = W; +} +//======================================================================= +//function : Weights +//purpose : +//======================================================================= +Handle(TColStd_HArray1OfReal) GEOMAlgo_ShapeInfo::Weights() const +{ + return myWeights; +} +//======================================================================= +//function : SetMultiplicities +//purpose : +//======================================================================= +void GEOMAlgo_ShapeInfo::SetMultiplicities(Handle(TColStd_HArray1OfInteger) M) +{ + myMultiplicities = M; +} +//======================================================================= +//function : Multiplicities +//purpose : +//======================================================================= +Handle(TColStd_HArray1OfInteger) GEOMAlgo_ShapeInfo::Multiplicities() const +{ + return myMultiplicities; +} +//======================================================================= //function : TypeToInteger //purpose : //======================================================================= @@ -711,6 +883,7 @@ void GEOMAlgo_ShapeInfo::DumpEdge()const GEOMAlgo_KindOfName aKN; GEOMAlgo_KindOfBounds aKB; GEOMAlgo_KindOfClosed aKC; + GEOMAlgo_KindOfPeriod aKP; // aNbV=NbSubShapes(TopAbs_VERTEX); aKS=KindOfShape(); @@ -770,6 +943,84 @@ void GEOMAlgo_ShapeInfo::DumpEdge()const myPnt2.Coord(aX, aY, aZ); printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ); } + else if (aKN==GEOMAlgo_KN_CURVEBSPLINE) { + aKP=KindOfPeriod(); + DumpKindOfPeriod(aKP); + printf(" Degree : %d\n", myDegree); + printf(" NbPoles : %d\n", myNbPoles); + printf(" NbKnots : %d\n", myNbKnots); + printf(" NbWeights : %d\n", myNbWeights); + printf(" NbMultis : %d\n", myNbMultiplicities); + + if (aKB == GEOMAlgo_KB_TRIMMED) { + myPnt1.Coord(aX, aY, aZ); + printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ); + myPnt2.Coord(aX, aY, aZ); + printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ); + } + + Standard_Integer i; + if (myNbPoles > 0 && !myPoles.IsNull() && myPoles->Length() == myNbPoles) { + bool aHasWeight = (myNbWeights == myNbPoles); + printf(" Poles\n"); + for (i=1; i<=myNbPoles; i++) { + const gp_Pnt &aP = myPoles->Value(i); + if (aHasWeight) + printf(" %3d : %.3lf %.3lf %.3lf %.3lf\n", i, aP.X(), aP.Y(), aP.Z(), myWeights->Value(i)); + else + printf(" %3d : %.3lf %.3lf %.3lf\n", i, aP.X(), aP.Y(), aP.Z()); + } + } + + if (myNbKnots > 0 && !myKnots.IsNull() && myKnots->Length() == myNbKnots) { + bool aHasMulti = (myNbMultiplicities == myNbKnots); + printf(" Knots\n"); + for (i=1; i<=myNbKnots; i++) { + if (aHasMulti) + printf(" %3d : %.3lf %.3lf\n", i, myKnots->Value(i), myMultiplicities->Value(i)); + else + printf(" %3d : %.3lf\n", i, myKnots->Value(i)); + } + } + + } + else if (aKN==GEOMAlgo_KN_CURVEBEZIER) { + aKP=KindOfPeriod(); + DumpKindOfPeriod(aKP); + printf(" Degree : %d\n", myDegree); + printf(" NbPoles : %d\n", myNbPoles); + printf(" NbWeights : %d\n", myNbWeights); + if (aKB == GEOMAlgo_KB_TRIMMED) { + myPnt1.Coord(aX, aY, aZ); + printf(" Pnt1 : %.3lf %.3lf %.3lf\n", aX, aY, aZ); + myPnt2.Coord(aX, aY, aZ); + printf(" Pnt2 : %.3lf %.3lf %.3lf\n", aX, aY, aZ); + } + + Standard_Integer i; + if (myNbPoles > 0 && !myPoles.IsNull() && myPoles->Length() == myNbPoles) { + bool aHasWeight = (myNbWeights == myNbPoles); + printf(" Poles\n"); + for (i=1; i<=myNbPoles; i++) { + const gp_Pnt &aP = myPoles->Value(i); + if (aHasWeight) + printf(" %3d : %.3lf %.3lf %.3lf %.3lf\n", i, aP.X(), aP.Y(), aP.Z(), myWeights->Value(i)); + else + printf(" %3d : %.3lf %.3lf %.3lf\n", i, aP.X(), aP.Y(), aP.Z()); + } + } + } + else if (aKN==GEOMAlgo_KN_HYPERBOLA) { + DumpLocation (myLocation); + DumpPosition (myPosition); + printf(" Radius1 : %.3lf\n", myRadius1); + printf(" Radius2 : %.3lf\n", myRadius2); + } + else if (aKN==GEOMAlgo_KN_PARABOLA) { + DumpLocation (myLocation); + DumpPosition (myPosition); + printf(" Focal : %.3lf\n", myRadius1); + } printf("\n"); } //======================================================================= @@ -869,7 +1120,10 @@ void DumpKindOfShape(const GEOMAlgo_KindOfShape aKS) "KS_CIRCLE", "KS_LINE", "KS_DEGENERATED", - "KS_BSPLINE" + "KS_BSPLINE", + "KS_BEZIER", + "KS_HYPERBOLA", + "KS_PARABOLA" }; int i; // @@ -903,7 +1157,11 @@ void DumpKindOfName(const GEOMAlgo_KindOfName aKS) "KN_TRIANGLE", "KN_QUADRANGLE", "KN_ARCELLIPSE", - "KN_SOLID" + "KN_SOLID", + "KN_CURVEBSPLINE", + "KN_CURVEBEZIER", + "KN_HYPERBOLA", + "KN_PARABOLA" }; int i; // @@ -919,10 +1177,26 @@ void DumpKindOfDef(const GEOMAlgo_KindOfDef aKD) const char *pStr[]={ "KD_UNKNOWN", "KD_SPECIFIED", - "KB_ARBITRARY" + "KD_ARBITRARY" }; int i; // i=(Standard_Integer)aKD; printf(" KindOfDef: %s\n", pStr[i]); } +//======================================================================= +//function : DumpKindOfPeriod +//purpose : +//======================================================================= +void DumpKindOfPeriod(const GEOMAlgo_KindOfPeriod aKP) +{ + const char *pStr[]={ + "KP_UNKNOWN", + "KP_PERIODIC", + "KP_NONPERIODIC" + }; + int i; + // + i=(Standard_Integer)aKP; + printf(" KindOfPeriod: %s\n", pStr[i]); +} diff --git a/src/GEOMAlgo/GEOMAlgo_ShapeInfo.hxx b/src/GEOMAlgo/GEOMAlgo_ShapeInfo.hxx index 01d7027c0..c0a8baf90 100644 --- a/src/GEOMAlgo/GEOMAlgo_ShapeInfo.hxx +++ b/src/GEOMAlgo/GEOMAlgo_ShapeInfo.hxx @@ -38,6 +38,11 @@ #include #include #include +#include + +#include +#include +#include //======================================================================= @@ -99,6 +104,12 @@ class GEOMAlgo_ShapeInfo Standard_EXPORT GEOMAlgo_KindOfDef KindOfDef() const; + Standard_EXPORT + void SetKindOfPeriod(const GEOMAlgo_KindOfPeriod aT) ; + + Standard_EXPORT + GEOMAlgo_KindOfPeriod KindOfPeriod() const; + Standard_EXPORT void SetLocation(const gp_Pnt& aP) ; @@ -162,6 +173,60 @@ class GEOMAlgo_ShapeInfo Standard_EXPORT Standard_Real Height() const; + Standard_EXPORT + void SetDegree(const Standard_Integer aDeg) ; + + Standard_EXPORT + Standard_Integer Degree() const; + + Standard_EXPORT + void SetNbPoles(const Standard_Integer aNb) ; + + Standard_EXPORT + Standard_Integer NbPoles() const; + + Standard_EXPORT + void SetNbKnots(const Standard_Integer aNb) ; + + Standard_EXPORT + Standard_Integer NbKnots() const; + + Standard_EXPORT + void SetNbWeights(const Standard_Integer aNb) ; + + Standard_EXPORT + Standard_Integer NbWeights() const; + + Standard_EXPORT + void SetNbMultiplicities(const Standard_Integer aNb) ; + + Standard_EXPORT + Standard_Integer NbMultiplicities() const; + + Standard_EXPORT + void SetPoles(Handle(TColgp_HArray1OfPnt) P) ; + + Standard_EXPORT + Handle(TColgp_HArray1OfPnt) Poles() const; + + Standard_EXPORT + void SetKnots(Handle(TColStd_HArray1OfReal) K) ; + + Standard_EXPORT + Handle(TColStd_HArray1OfReal) Knots() const; + + Standard_EXPORT + void SetWeights(Handle(TColStd_HArray1OfReal) W) ; + + Standard_EXPORT + Handle(TColStd_HArray1OfReal) Weights() const; + + Standard_EXPORT + void SetMultiplicities(Handle(TColStd_HArray1OfInteger) M) ; + + Standard_EXPORT + Handle(TColStd_HArray1OfInteger) Multiplicities() const; + Standard_EXPORT void Dump() const; @@ -208,6 +273,16 @@ class GEOMAlgo_ShapeInfo Standard_Real myHeight; gp_Pnt myPnt1; gp_Pnt myPnt2; + GEOMAlgo_KindOfPeriod myKindOfPeriod; Standard_Integer myNbTypes; + Standard_Integer myNbKnots; + Standard_Integer myNbPoles; + Standard_Integer myNbWeights; + Standard_Integer myNbMultiplicities; + Standard_Integer myDegree; + Handle(TColgp_HArray1OfPnt) myPoles; + Handle(TColStd_HArray1OfReal) myKnots; + Handle(TColStd_HArray1OfReal) myWeights; + Handle(TColStd_HArray1OfInteger) myMultiplicities; }; #endif diff --git a/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller.cxx b/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller.cxx index c5adbc9cd..954d9c3bb 100644 --- a/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller.cxx +++ b/src/GEOMAlgo/GEOMAlgo_ShapeInfoFiller.cxx @@ -33,10 +33,13 @@ #include #include #include +#include +#include #include #include #include +#include #include #include @@ -525,45 +528,122 @@ void GEOMAlgo_ShapeInfoFiller::FillEdge(const TopoDS_Shape& aS) } // BSplineCurve if (aCT==GeomAbs_BSplineCurve) { - Standard_Integer aNbKnots, aNbPoles, aDegree; + Standard_Integer aNbKnots, aNbPoles, aNbWeights, aNbMultiplicities, aDegree, i; Standard_Real aLength; gp_XYZ aXYZ1, aXYZ2, aXYZc; Handle(Geom_BSplineCurve) aBSp; // aBSp=aGAC.BSpline(); - aNbKnots=aBSp->NbKnots(); - aNbPoles=aBSp->NbPoles(); - aDegree =aBSp->Degree(); - if (!(aDegree==1 && aNbKnots==2 && aNbPoles==2)) { - return; // unallowed B-Spline curve + aDegree = aBSp->Degree(); + aNbPoles = aBSp->NbPoles(); + aNbKnots = aBSp->NbKnots(); + aNbWeights = (aBSp->IsRational() ? aNbPoles : 0); + aNbMultiplicities = (aBSp->KnotDistribution() == GeomAbs_Uniform ? 0 : aNbKnots); + if (aDegree==1 && aNbKnots==2 && aNbPoles==2) { + // This is a single line segment + aInfo.SetKindOfShape(GEOMAlgo_KS_BSPLINE); + aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED); + // + aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED); + aInfo.SetKindOfName(GEOMAlgo_KN_SEGMENT); + aGAC.D0(aT1, aP1); + aGAC.D0(aT2, aP2); + aInfo.SetPnt1(aP1); + aInfo.SetPnt2(aP2); + // + aLength=aP1.Distance(aP2); + aInfo.SetLength(aLength); + // + aXYZ1=aP1.XYZ(); + aXYZ2=aP2.XYZ(); + aXYZc=aXYZ1+aXYZ2; + aXYZc.Multiply(0.5); + aPc.SetXYZ(aXYZc); + aInfo.SetLocation(aPc); + // + if ( aLength >= gp::Resolution() ) { + gp_Vec aVec(aPc, aP2); + gp_Dir aDir(aVec); + aInfo.SetDirection(aDir); + } } - // - aInfo.SetKindOfShape(GEOMAlgo_KS_BSPLINE); - aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED); - // + else { + // We have a higher degree B-Spline curve + aInfo.SetKindOfShape(GEOMAlgo_KS_BSPLINE); + aInfo.SetKindOfName(GEOMAlgo_KN_CURVEBSPLINE); + aInfo.SetKindOfPeriod(aBSp->IsPeriodic() ? GEOMAlgo_KP_PERIODIC : GEOMAlgo_KP_NONPERIODIC); + aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED); + aInfo.SetKindOfClosed(aBSp->IsClosed() ? GEOMAlgo_KC_CLOSED : GEOMAlgo_KC_NOTCLOSED); + aGAC.D0(aT1, aP1); + aGAC.D0(aT2, aP2); + aInfo.SetPnt1(aP1); + aInfo.SetPnt2(aP2); + // + aInfo.SetDegree(aDegree); + aInfo.SetNbKnots(aNbKnots); + aInfo.SetNbPoles(aNbPoles); + aInfo.SetNbWeights(aNbWeights); + aInfo.SetNbMultiplicities(aNbMultiplicities); + // Fill the poles + Handle(TColgp_HArray1OfPnt) poles = new TColgp_HArray1OfPnt(1, aNbPoles); + for (i=1; i<=aNbPoles; i++) + poles->SetValue(i, aBSp->Pole(i)); + aInfo.SetPoles(poles); + // Fill the knots + Handle(TColStd_HArray1OfReal) knots = new TColStd_HArray1OfReal(1, aNbKnots); + for (i=1; i<=aNbKnots; i++) + knots->SetValue(i, aBSp->Knot(i)); + aInfo.SetKnots(knots); + // Fill the weights + if (aNbWeights > 0) { + Handle(TColStd_HArray1OfReal) weights = new TColStd_HArray1OfReal(1, aNbWeights); + for (i=1; i<=aNbWeights; i++) + weights->SetValue(i, aBSp->Weight(i)); + aInfo.SetWeights(weights); + } + // Fill the multiplicities + if (aNbMultiplicities > 0) { + Handle(TColStd_HArray1OfInteger) mults = new TColStd_HArray1OfInteger(1, aNbMultiplicities); + for (i=1; i<=aNbMultiplicities; i++) + mults->SetValue(i, aBSp->Multiplicity(i)); + aInfo.SetMultiplicities(mults); + } + } + }//if (aCT==GeomAbs_BSplineCurve) { + // Bezier + else if (aCT==GeomAbs_BezierCurve) { + Standard_Integer aNbPoles, aNbWeights, aDegree, i; + Handle(Geom_BezierCurve) aBC; + aBC=aGAC.Bezier(); + aNbPoles = aBC->NbPoles(); + aNbWeights = (aBC->IsRational() ? aNbPoles : 0); + aDegree = aBC->Degree(); + aInfo.SetKindOfShape(GEOMAlgo_KS_BEZIER); + aInfo.SetKindOfName(GEOMAlgo_KN_CURVEBEZIER); + aInfo.SetKindOfPeriod(aBC->IsPeriodic() ? GEOMAlgo_KP_PERIODIC : GEOMAlgo_KP_NONPERIODIC); aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED); - aInfo.SetKindOfName(GEOMAlgo_KN_SEGMENT); + aInfo.SetKindOfClosed(aBC->IsClosed() ? GEOMAlgo_KC_CLOSED : GEOMAlgo_KC_NOTCLOSED); aGAC.D0(aT1, aP1); aGAC.D0(aT2, aP2); aInfo.SetPnt1(aP1); aInfo.SetPnt2(aP2); // - aLength=aP1.Distance(aP2); - aInfo.SetLength(aLength); - // - aXYZ1=aP1.XYZ(); - aXYZ2=aP2.XYZ(); - aXYZc=aXYZ1+aXYZ2; - aXYZc.Multiply(0.5); - aPc.SetXYZ(aXYZc); - aInfo.SetLocation(aPc); - // - if ( aLength >= gp::Resolution() ) { - gp_Vec aVec(aPc, aP2); - gp_Dir aDir(aVec); - aInfo.SetDirection(aDir); + aInfo.SetDegree(aDegree); + aInfo.SetNbPoles(aNbPoles); + aInfo.SetNbWeights(aNbWeights); + // Fill the poles + Handle(TColgp_HArray1OfPnt) poles = new TColgp_HArray1OfPnt(1, aNbPoles); + for (i=1; i<=aNbPoles; i++) + poles->SetValue(i, aBC->Pole(i)); + aInfo.SetPoles(poles); + // Fill the weights + if (aNbWeights > 0) { + Handle(TColStd_HArray1OfReal) weights = new TColStd_HArray1OfReal(1, aNbWeights); + for (i=1; i<=aNbWeights; i++) + weights->SetValue(i, aBC->Weight(i)); + aInfo.SetWeights(weights); } - } + }// if (aCT==GeomAbs_BezierCurve) { // Line else if (aCT==GeomAbs_Line) { Standard_Boolean bInf1, bInf2; @@ -684,13 +764,50 @@ void GEOMAlgo_ShapeInfoFiller::FillEdge(const TopoDS_Shape& aS) else { aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED); aInfo.SetKindOfName(GEOMAlgo_KN_ARCELLIPSE); - // - gp_Vec aVecX(aP, aP1); - gp_Dir aDirX(aVecX); - gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX); - aInfo.SetPosition(aAx2new); } }// else if (aCT==GeomAbs_Ellipse) { + // Hyperbola + else if (aCT==GeomAbs_Hyperbola) { + gp_Hypr aHyp; + aHyp=aGAC.Hyperbola(); + aP=aHyp.Location(); + aAx2=aHyp.Position(); + aR1=aHyp.MajorRadius(); + aR2=aHyp.MinorRadius(); + aInfo.SetKindOfShape(GEOMAlgo_KS_HYPERBOLA); + aInfo.SetKindOfName(GEOMAlgo_KN_HYPERBOLA); + aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED); + aInfo.SetLocation(aP); + aInfo.SetPosition(aAx2); + aInfo.SetRadius1(aR1); + aInfo.SetRadius2(aR2); + // + aGAC.D0(aT1, aP1); + aGAC.D0(aT2, aP2); + aInfo.SetPnt1(aP1); + aInfo.SetPnt2(aP2); + // + }// if (aCT==GeomAbs_Hyperbola) { + // Parabola + else if (aCT==GeomAbs_Parabola) { + gp_Parab aPara; + aPara=aGAC.Parabola(); + aP=aPara.Location(); + aAx2=aPara.Position(); + aR1=aPara.Focal(); + aInfo.SetKindOfShape(GEOMAlgo_KS_PARABOLA); + aInfo.SetKindOfName(GEOMAlgo_KN_PARABOLA); + aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED); + aInfo.SetLocation(aP); + aInfo.SetPosition(aAx2); + aInfo.SetRadius1(aR1); + // + aGAC.D0(aT1, aP1); + aGAC.D0(aT2, aP2); + aInfo.SetPnt1(aP1); + aInfo.SetPnt2(aP2); + // + }// if (aCT==GeomAbs_Parabola) { // FillSubShapes(aS); } @@ -807,7 +924,10 @@ Standard_Boolean GEOMAlgo_ShapeInfoFiller::IsAllowedType GeomAbs_Line, GeomAbs_Circle, GeomAbs_Ellipse, - GeomAbs_BSplineCurve + GeomAbs_BSplineCurve, + GeomAbs_BezierCurve, + GeomAbs_Hyperbola, + GeomAbs_Parabola }; // bRet=Standard_False; diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx index 00bcb04e0..6b507190f 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx @@ -646,7 +646,7 @@ GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape break; case GEOMAlgo_KN_ELLIPSE: { - // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2 + // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2 xVx yVx zVx xVy yVy zVy aKind = SK_ELLIPSE; gp_Pnt aC = anInfo.Location(); @@ -662,11 +662,21 @@ GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape theDoubles->Append(anInfo.Radius1()); theDoubles->Append(anInfo.Radius2()); + + gp_Dir aXD = anAx3.XDirection(); + theDoubles->Append(aXD.X()); + theDoubles->Append(aXD.Y()); + theDoubles->Append(aXD.Z()); + + gp_Dir aYD = anAx3.YDirection(); + theDoubles->Append(aYD.X()); + theDoubles->Append(aYD.Y()); + theDoubles->Append(aYD.Z()); } break; case GEOMAlgo_KN_ARCELLIPSE: { - // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2 + // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2 xVx yVx zVx xVy yVy zVy aKind = SK_ARC_ELLIPSE; gp_Pnt aC = anInfo.Location(); @@ -692,6 +702,16 @@ GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape theDoubles->Append(aP2.X()); theDoubles->Append(aP2.Y()); theDoubles->Append(aP2.Z()); + + gp_Dir aXD = anAx3.XDirection(); + theDoubles->Append(aXD.X()); + theDoubles->Append(aXD.Y()); + theDoubles->Append(aXD.Z()); + + gp_Dir aYD = anAx3.YDirection(); + theDoubles->Append(aYD.X()); + theDoubles->Append(aYD.Y()); + theDoubles->Append(aYD.Z()); } break; case GEOMAlgo_KN_LINE: @@ -727,6 +747,163 @@ GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape theDoubles->Append(aP2.Z()); } break; + case GEOMAlgo_KN_CURVEBSPLINE: + { + // (+) geompy.kind.CRV_BSPLINE np nk nw nm x1 y1 z1 ... xnp ynp znp k1 ... knk w1 ... wnw m1 ... mnm + aKind = SK_CRV_BSPLINE; + Standard_Integer aNbPoles = anInfo.NbPoles(); + Standard_Integer aNbKnots = anInfo.NbKnots(); + Standard_Integer aNbWeights = anInfo.NbWeights(); + Standard_Integer aNbMultiplicities = anInfo.NbMultiplicities(); + + theIntegers->Append(anInfo.KindOfPeriod() == GEOMAlgo_KP_PERIODIC ? 1 : 0); + theIntegers->Append(anInfo.Degree()); + theIntegers->Append(aNbPoles); + theIntegers->Append(aNbKnots); + theIntegers->Append(aNbWeights); + theIntegers->Append(aNbMultiplicities); + // + Standard_Integer i; + if (aNbPoles > 0) { + Handle(TColgp_HArray1OfPnt) aPoles = anInfo.Poles(); + if (aPoles.IsNull() || aPoles->Length() != aNbPoles) { + SetErrorCode("B-Spline Curve: no or wrong number of poles given"); + return aKind; + } + for (i=1; i<=aNbPoles; i++) { + const gp_Pnt &aP = aPoles->Value(i); + theDoubles->Append(aP.X()); + theDoubles->Append(aP.Y()); + theDoubles->Append(aP.Z()); + } + } + // + if (aNbKnots > 0) { + Handle(TColStd_HArray1OfReal) aKnots = anInfo.Knots(); + if (aKnots.IsNull() || aKnots->Length() != aNbKnots) { + SetErrorCode("B-Spline Curve: no or wrong number of knots given"); + return aKind; + } + for (i=1; i<=aNbKnots; i++) + theDoubles->Append(aKnots->Value(i)); + } + // + if (aNbWeights > 0) { + Handle(TColStd_HArray1OfReal) aWeights = anInfo.Weights(); + if (aNbWeights > 0 && (aWeights.IsNull() || aWeights->Length() != aNbWeights)) { + SetErrorCode("B-Spline Curve: no or wrong number of weights given"); + return aKind; + } + for (i=1; i<=aNbWeights; i++) + theDoubles->Append(aWeights->Value(i)); + } + // + if (aNbMultiplicities > 0) { + Handle(TColStd_HArray1OfInteger) aMults = anInfo.Multiplicities(); + if (aMults.IsNull() || aMults->Length() != aNbMultiplicities) { + SetErrorCode("B-Spline Curve: no or wrong number of multiplicities given"); + return aKind; + } + for (i=1; i<=aNbMultiplicities; i++) + theIntegers->Append(aMults->Value(i)); + } + } + break; + case GEOMAlgo_KN_CURVEBEZIER: + { + // (+) geompy.kind.CRV_BEZIER np nw x1 y1 z1 ... xnp ynp znp w1 ... wnw + aKind = SK_CRV_BEZIER; + Standard_Integer aNbPoles = anInfo.NbPoles(); + Standard_Integer aNbWeights = anInfo.NbWeights(); + + theIntegers->Append(aNbPoles); + theIntegers->Append(aNbWeights); + // + Standard_Integer i; + if (aNbPoles > 0) { + Handle(TColgp_HArray1OfPnt) aPoles = anInfo.Poles(); + if (aPoles.IsNull() || aPoles->Length() != aNbPoles) { + SetErrorCode("Bezier Curve: no or wrong number of poles given"); + return aKind; + } + for (i=1; i<=aNbPoles; i++) { + const gp_Pnt &aP = aPoles->Value(i); + theDoubles->Append(aP.X()); + theDoubles->Append(aP.Y()); + theDoubles->Append(aP.Z()); + } + } + // + if (aNbWeights > 0) { + Handle(TColStd_HArray1OfReal) aWeights = anInfo.Weights(); + if (aNbWeights > 0 && (aWeights.IsNull() || aWeights->Length() != aNbWeights)) { + SetErrorCode("B-Spline Curve: no or wrong number of weights given"); + return aKind; + } + for (i=1; i<=aNbWeights; i++) + theDoubles->Append(aWeights->Value(i)); + } + } + break; + case GEOMAlgo_KN_HYPERBOLA: + { + // (+) geompy.kind.HYPERBOLA xc yc zc dx dy dz R_1 R_2 xVx yVx zVx xVy yVy zVy + aKind = SK_HYPERBOLA; + + gp_Pnt aC = anInfo.Location(); + theDoubles->Append(aC.X()); + theDoubles->Append(aC.Y()); + theDoubles->Append(aC.Z()); + + gp_Ax3 anAx3 = anInfo.Position(); + gp_Dir aD = anAx3.Direction(); + theDoubles->Append(aD.X()); + theDoubles->Append(aD.Y()); + theDoubles->Append(aD.Z()); + + theDoubles->Append(anInfo.Radius1()); + theDoubles->Append(anInfo.Radius2()); + + gp_Dir aXD = anAx3.XDirection(); + theDoubles->Append(aXD.X()); + theDoubles->Append(aXD.Y()); + theDoubles->Append(aXD.Z()); + + gp_Dir aYD = anAx3.YDirection(); + theDoubles->Append(aYD.X()); + theDoubles->Append(aYD.Y()); + theDoubles->Append(aYD.Z()); + } + break; + case GEOMAlgo_KN_PARABOLA: + { + // (+) geompy.kind.PARABOLA xc yc zc dx dy dz F xVx yVx zVx xVy yVy zVy + aKind = SK_PARABOLA; + + gp_Pnt aC = anInfo.Location(); + theDoubles->Append(aC.X()); + theDoubles->Append(aC.Y()); + theDoubles->Append(aC.Z()); + + gp_Ax3 anAx3 = anInfo.Position(); + gp_Dir aD = anAx3.Direction(); + theDoubles->Append(aD.X()); + theDoubles->Append(aD.Y()); + theDoubles->Append(aD.Z()); + + theDoubles->Append(anInfo.Radius1()); + + gp_Dir aXD = anAx3.XDirection(); + theDoubles->Append(aXD.X()); + theDoubles->Append(aXD.Y()); + theDoubles->Append(aXD.Z()); + + gp_Dir aYD = anAx3.YDirection(); + theDoubles->Append(aYD.X()); + theDoubles->Append(aYD.Y()); + theDoubles->Append(aYD.Z()); + } + break; default: // ??? geompy.kind.EDGE nb_vertices _curve_type_id_ // (+) geompy.kind.EDGE nb_vertices diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx index af0410ba6..ee03e9a62 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx @@ -78,6 +78,10 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { SK_ARC_ELLIPSE, // arc of ellipse SK_LINE, // infinite segment SK_SEGMENT, // segment + SK_CRV_BSPLINE, // B-Spline curve (open or closed) + SK_CRV_BEZIER, // Bezier curve (open or closed) + SK_HYPERBOLA, // hyperbola + SK_PARABOLA, // parabola SK_EDGE, // other edge // VERTEX SK_VERTEX, // vertex diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 00e58ed8a..f4da65595 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -2854,6 +2854,18 @@ char* GEOM_Gen_i::getObjectInfo(const char* entry) case GEOM::GEOM_IKindOfShape::SEGMENT: aTypeInfo = "Segment"; break; + case GEOM::GEOM_IKindOfShape::CRV_BSPLINE: + aTypeInfo = "Crv BSpline"; + break; + case GEOM::GEOM_IKindOfShape::CRV_BEZIER: + aTypeInfo = "Crv Bezier"; + break; + case GEOM::GEOM_IKindOfShape::HYPERBOLA: + aTypeInfo = "Hyperbola"; + break; + case GEOM::GEOM_IKindOfShape::PARABOLA: + aTypeInfo = "Parabola"; + break; case GEOM::GEOM_IKindOfShape::EDGE: aTypeInfo = "Edge"; break; diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index 6b7947e0d..7907c7b32 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -683,10 +683,14 @@ class geomBuilder(GEOM._objref_GEOM_Gen): # # - CIRCLE: [xc yc zc dx dy dz R] # - ARC_CIRCLE: [xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2] - # - ELLIPSE: [xc yc zc dx dy dz R_1 R_2] - # - ARC_ELLIPSE: [xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2] + # - ELLIPSE: [xc yc zc dx dy dz R_1 R_2 v1x v1y v1z v2x v2y v2z] + # - ARC_ELLIPSE: [xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2 v1x v1y v1z v2x v2y v2z] # - LINE: [xo yo zo dx dy dz] # - SEGMENT: [x1 y1 z1 x2 y2 z2] + # - CRV_BSPLINE: [periodicity degree nb_poles nb_knots nb_weights nb_multiplicities xi yi zi ki wi mi] + # - CRV_BEZIER: [nb_poles nb_weights xi yi zi wi] + # - HYPERBOLA: [xc yc zc dx dy dz R_1 R_2 v1x v1y v1z v2x v2y v2z] + # - PARABOLA: [xc yc zc dx dy dz F v1x v1y v1z v2x v2y v2z] # - EDGE: [nb_vertices] # # - VERTEX: [x y z] @@ -11852,6 +11856,10 @@ class geomBuilder(GEOM._objref_GEOM_Gen): #if aKind == kind.SOME_KIND: # # SOME_KIND int int double int double double # aKindTuple = [aKind, anInts[0], anInts[1], aDbls[0], anInts[2], aDbls[1], aDbls[2]] + if aKind == self.kind.CRV_BSPLINE: + aKindTuple = [aKind] + anInts[:6] + aDbls + anInts[6:] + elif aKind == self.kind.CRV_BEZIER: + aKindTuple = [aKind] + anInts[:2] + aDbls + anInts[2:] return aKindTuple diff --git a/test/data/KindOfShape_Curve10.brep b/test/data/KindOfShape_Curve10.brep new file mode 100755 index 000000000..2efa30db2 --- /dev/null +++ b/test/data/KindOfShape_Curve10.brep @@ -0,0 +1,55 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 1 +1 + 1 0 0 -50 + 0 1 0 0 + 0 0 1 0 +Curve2ds 2 +8 -132.28756555322954 132.28756555322963 +4 340 315.48573660309904 -1.3586236395872709e-16 -1 1 -1.3586236395872709e-16 13.867504905630716 +8 -132.28756555322954 132.28756555322963 +7 0 0 8 51 8 0.722734247813415 -3.7837266715443717e-13 0.76407411204879916 39.435717075387053 0.81058069772893759 76.054597216847469 0.86333712790747086 109.85664042370627 0.92373293963282777 140.84184669796377 0.99374321759023587 169.01021603675326 1.0759136624494658 194.36174844310153 1.1743082728010958 216.89644391463054 1.3396677297426323 244.00849940395941 1.3878402708536062 251.00657866175425 1.439386042779802 257.60854022571675 1.4946291510977829 263.81438409584047 1.5539262525010975 269.62411027212192 1.6176561781971539 275.03771875456647 1.6861920117449656 280.05520954318069 1.8243112797239756 288.72028409587813 1.8926931818048145 292.46070794446166 1.9652130488717003 295.89785418369655 2.0420563040416813 299.0317228135869 2.1233422404046745 301.86231383413553 2.2090815929216268 304.38962724534059 2.2991315140696154 306.61366304719826 2.4754123375026116 310.21508465816311 2.5607140976241731 311.66355115695944 2.6488254910765074 312.87982073610181 2.7394077559327799 313.86389339558934 2.8319968443872954 314.61576913542166 2.9260166915141053 315.1354479555996 3.0208200192583119 315.42292985612431 3.2818958243631009 315.57496355351697 3.4484415546735363 314.96060920305899 3.6119098712897539 313.63515178789385 3.7687040424752922 311.59859130391851 3.9161881660238578 308.85092775546946 4.0534163229503974 305.39216113899602 4.1801732694165823 301.22229145738459 4.4717398358323992 289.01985958596777 4.623885503080146 280.09841856328421 4.7543429159341031 269.57699564215727 4.8668661357150995 257.45559081924148 4.964650295645697 243.73420410044491 5.0502542944996094 228.41283547898638 5.1257535186641459 211.49148495951397 5.2598175641448162 174.44882012091162 5.318382818223391 154.3275058021172 5.3701242801189952 132.60620958382972 5.416261756368808 109.28493146604946 5.4577162356651003 84.363671448776387 5.4952031821752776 57.842429532010456 5.5292947700852562 29.721205715751502 5.560451059366172 -7.2521427871267128e-13 + -132.28756555322954 9 -66.143782776626111 7 -41.339864235399588 7 -19.636435511826431 7 -0.64593537870134909 7 32.587439854281101 7 82.437502703755172 7 132.28756555322963 9 +Curves 1 +4 -24.999999999999982 2.0575957707676544e-16 262.5 -0.83205029433784372 6.8480926667821216e-18 -0.55470019622522904 0.55470019622522904 -4.56539511118808e-18 -0.83205029433784372 -8.2303830830706228e-18 -1 0 13.867504905630716 +Polygon3D 1 +26 1 +1.05830058320163 +150 132.28756555323 0 97.6764398868482 110.759396841464 78.4853401697277 58.510436807218 91.3840450008742 137.234344789173 28.7115945291821 73.2881944989656 181.932608206227 7.37202416257552 56.8964183078122 213.941963756137 -7.22175527456788 42.1642558637433 235.832632911852 -15.8040217387008 30.3248714115974 248.706032608051 -20.4009768941005 21.4453330724881 255.601465341151 -22.8138368710065 14.785679318156 259.22075530651 -24.14696897759 9.23596785621269 261.220453466385 -24.8201198895001 4.24122754046367 262.23017983425 -24.9993546431669 -0.254038743710453 262.49903196475 -24.8151190571547 -4.29977839946716 262.222678585732 -24.3035232838993 -8.34551805522387 261.455284925849 -23.4645673234006 -12.3912577109806 260.196850985101 -22.2982511756587 -16.4369973667373 258.447376763488 -20.8045748406735 -20.482737022494 256.20686226101 -18.3037794360927 -25.8770565635029 252.455669154139 -14.7947442080473 -31.945666047138 247.192116312071 -8.97026991530217 -40.0371453586514 238.455404872953 2.22164292813993 -52.1743643259215 221.66753560779 18.33422439134 -65.8287356641004 197.49866341299 44.2525096789088 -83.2180927917173 158.621235481637 80.0378771853595 -102.487988167082 104.943184221961 112.798901561697 -117.387776860156 55.8016476574539 150 -132.28756555323 0 +-132.28756555323 -110.759396841464 -91.3840450008742 -73.2881944989656 -56.8964183078122 -42.1642558637433 -30.3248714115974 -21.4453330724881 -14.785679318156 -9.23596785621269 -4.24122754046367 0.254038743710453 4.29977839946716 8.34551805522387 12.3912577109806 16.4369973667373 20.482737022494 25.8770565635029 31.945666047138 40.0371453586514 52.1743643259215 65.8287356641004 83.2180927917173 102.487988167082 117.387776860156 132.28756555323 +PolygonOnTriangulations 0 +Surfaces 2 +1 200.00000000000003 339.99999999999994 -3.8435068773240004e-14 -0.83205029433784372 6.8480926667821216e-18 -0.55470019622522904 -8.3593263030600021e-17 -1 1.1304431992129413e-16 -0.55470019622522904 1.4042775906991517e-16 0.83205029433784372 +3 0 0 0 0 0 1 1 0 -0 -0 1 0 200 +-0.5880026035475675 +Triangulations 0 + +TShapes 3 +Ve +7.34697470131475e-06 +150 132.28756555323 0 +0 0 + +0101101 +* +Ve +7.34697509667305e-06 +150 -132.28756555323 0 +0 0 + +0101101 +* +Ed + 7.34697430646774e-06 1 1 0 +1 1 0 -132.28756555323 132.28756555323 +2 1 1 1 -132.28756555323 132.28756555323 +2 2 2 0 -132.28756555323 132.28756555323 +5 1 0 +0 + +0101000 ++3 0 -2 0 * + ++1 0 \ No newline at end of file diff --git a/test/data/KindOfShape_Curve3.brep b/test/data/KindOfShape_Curve3.brep new file mode 100755 index 000000000..a932484d4 --- /dev/null +++ b/test/data/KindOfShape_Curve3.brep @@ -0,0 +1,33 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 0 +Curve2ds 0 +Curves 1 +7 0 1 3 8 9 -100 0 0 -200 200 0 0 100 0 200 200 0 100 0 0 200 -200 0 0 -100 0 -200 -200 0 + 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 +Polygon3D 0 +PolygonOnTriangulations 0 +Surfaces 0 +Triangulations 0 + +TShapes 2 +Ve +1e-07 +-150 150 0 +0 0 + +0101101 +* +Ed + 1e-07 1 1 0 +1 1 0 0 8 +5 1 0 +0 + +1101000 ++2 0 -2 0 * + ++1 0 +0 + diff --git a/test/data/KindOfShape_Curve4.brep b/test/data/KindOfShape_Curve4.brep new file mode 100755 index 000000000..7fad3b62d --- /dev/null +++ b/test/data/KindOfShape_Curve4.brep @@ -0,0 +1,33 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 0 +Curve2ds 0 +Curves 1 +7 1 1 2 3 4 0 0 0 200 100 200 0 100 200 0 0 100 + 0 1 1 1 2 1 3 1 +Polygon3D 0 +PolygonOnTriangulations 0 +Surfaces 0 +Triangulations 0 + +TShapes 2 +Ve +1e-07 +33.3333333333333 66.6666666666667 0 +0 0 + +0101101 +* +Ed + 1e-07 1 1 0 +1 1 0 0 3 +5 1 0 +0 + +1101000 ++2 0 -2 0 * + ++1 0 +0 + diff --git a/test/data/KindOfShape_Curve6.brep b/test/data/KindOfShape_Curve6.brep new file mode 100755 index 000000000..b06785f4f --- /dev/null +++ b/test/data/KindOfShape_Curve6.brep @@ -0,0 +1,49 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 0 +Curve2ds 2 +7 0 0 8 44 7 6.28318530717958 126.49110640673518 6.1584073516232243 126.49110640673518 6.03362947549771 125.84803414687136 5.9094150207291705 124.56189114958852 5.7863294117394162 122.64589554676786 5.6648846324858937 120.12650015353393 5.54549772011468 117.04268536994019 5.4284719614072143 113.44462845614626 5.1137001325914317 102.29948970016818 4.921240451124504 93.81454574700183 4.7377118900913047 84.256033707148163 4.5632229512848426 74.030607049062382 4.397033588928025 63.602641482139006 4.2381575906165381 53.449736070906511 4.0854629052390701 44.015856146907062 3.8270272714482192 29.421321131272506 3.7190912160212974 23.78197666484084 3.6134854850770353 18.91633840585564 3.5097056832673843 14.960854402874247 3.4072538769833045 12.021771401705337 3.3056390595825178 10.168633215735099 3.2043733060670294 9.4312912458091382 3.0269139347799494 10.077243798233877 2.9507813920120052 10.976463244287553 2.8743641769089976 12.49412419695426 2.7974558941141368 14.613890317398727 2.7198491058760084 17.307132114094998 2.6413344785686395 20.533686208932011 2.5617010668343156 24.243171506407222 2.3592957337009661 34.577147634830929 2.2348631022484744 41.731770617236798 2.1067313138356951 49.642080465040408 1.9742003309155507 58.066784329999791 1.8365888023656396 66.735079678119746 1.693295859924242 75.365027387261421 1.5439152143595885 83.683090087545125 1.2328868921475886 99.198631136983835 1.0712391290359733 106.39610895952501 0.90340851386281429 112.7848816543119 0.729707051992591 118.1416613048641 0.5509128122380389 122.28495914826635 0.36848476642205696 125.08905695252179 0.18424245000118436 126.49110640673518 4.6694967520238038e-16 126.49110640673518 + 3.1415926535897931 9 3.9269908169872401 7 5.3014376029327721 7 6.3322726923919213 7 7.105399009486284 7 8.2650884851278299 7 9.4247779607693793 9 +3 112.04658794368747 -100 -1 0 -0 -1 96.039932523160658 76.25866911626909 +Curves 1 +3 -18.46153846153846 0 64.615384615384627 0.57668319759865538 0 -0.81696786326476167 -0.81696786326476167 -0 -0.57668319759865538 -0 1 0 96.039932523160658 76.25866911626909 +Polygon3D 1 +39 1 +0.610069365987925 +50 -37.2543859613389 112.941176470588 43.5880674292195 -46.673207693842 108.415106420626 35.8151783839059 -55.0683290613502 102.928361212169 26.8518184540995 -62.2556168269867 96.6012836146585 16.8945842588267 -68.077429605628 89.572647712113 6.16187142126587 -72.4060754694873 81.9966151208936 -5.11091558153751 -75.1466126614042 74.03935370715 -19.0435686922269 -76.2565709367343 64.2045397466634 -31.6131968125667 -75.1797477836914 55.3318610734823 -43.8115865103297 -72.1688127271111 46.721233051532 -55.2776554743336 -67.3424016160983 38.6275373122351 -65.6970726091178 -60.8910119307455 31.272654628858 -74.8197631124895 -53.0564119779614 24.8331083911839 -81.8757760289204 -44.907184757395 19.8523933913503 -87.6947660658254 -35.881952129668 15.7448710123585 -92.1632220609244 -26.1567694993995 12.5906667805239 -95.1939777481841 -15.9213462107795 10.4513098248112 -96.7279121120217 -5.37534488336087 9.3685326268082 -96.8033254352886 4.21163276268513 9.31529969273748 -95.8121333802339 12.787305284216 10.014964672776 -93.8304107132644 21.1992270635422 11.4138277318134 -90.8835348341015 29.3396773257139 13.4939754112225 -87.0092426311415 37.104411685954 16.2287699074295 -82.2571472331596 44.393997074804 19.5831901883579 -76.6881026771207 51.1150850508794 23.514280463209 -70.3734246279872 57.181607195538 27.9717002625973 -63.3939771297737 62.5158772815641 32.8983690848656 -55.8391370826644 67.0495861017951 38.2311973534134 -47.8056497068176 70.7246762181899 43.9018943245994 -36.5282980309635 74.2094861469109 51.8623778604964 -22.7234166390356 76.146087275228 61.6070000195043 -8.71892653878124 75.6684949701785 71.4925224432133 3.61800536709324 73.1769658117673 80.200944965007 15.3174483289402 68.8297560753093 88.4593752910166 26.05020979487 62.799522257575 96.0354422081435 35.5474786871062 55.3163994541851 102.73939672031 42.9797313088074 47.4273461692171 107.98569268857 46.7003637557376 42.4780866848608 110.612021474638 50 37.2543859613389 112.941176470588 +3.65199295515956 3.80022779966159 3.94846264416362 4.09669748866565 4.24493233316769 4.39316717766972 4.54140202217175 4.71980708077055 4.88080315846458 5.04138055183158 5.20080196553975 5.35841938292808 5.51373194832228 5.65351325717705 5.79329456603182 5.9330758748866 6.07285718374137 6.21263849259615 6.33844167056544 6.45166453073781 6.56488739091018 6.67811025108255 6.79133311125491 6.90455597142728 7.01777883159965 7.13100169177202 7.24422455194438 7.35744741211675 7.47067027228912 7.62163408585227 7.79963683278398 7.97847349611623 8.13924058867037 8.29904657771952 8.45721313736856 8.61319385187279 8.7535764949266 8.83397707706311 8.91437765919962 +PolygonOnTriangulations 0 +Surfaces 2 +3 0 0 0 0 0 1 1 0 -0 -0 1 0 100 +-0.32175055439664219 +1 -110 -100 0 0.57668319759865538 0 -0.81696786326476167 0.81696786326476167 0 0.57668319759865538 0 -1 0 +Triangulations 0 + +TShapes 3 +Ve +1.6322216083449e-06 +50 -37.2543859613389 112.941176470588 +0 0 + +0101101 +* +Ve +1.63222162424756e-06 +50 37.2543859613389 112.941176470588 +0 0 + +0101101 +* +Ed + 1.63222157819913e-06 1 1 0 +1 1 0 3.65199295515956 8.91437765919962 +2 1 1 0 3.65199295515956 8.91437765919962 +2 2 2 0 3.65199295515956 8.91437765919962 +5 1 0 +0 + +0101000 ++3 0 -2 0 * + ++1 0 \ No newline at end of file diff --git a/test/data/KindOfShape_Curve9.brep b/test/data/KindOfShape_Curve9.brep new file mode 100755 index 000000000..9fda94d58 --- /dev/null +++ b/test/data/KindOfShape_Curve9.brep @@ -0,0 +1,55 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 1 +1 + 1 0 0 -50 + 0 1 0 0 + 0 0 1 0 +Curve2ds 2 +8 -2.0634370688955608 2.0634370688955608 +5 0 300 0 -1 1 0 75 50 +8 -2.0634370688955608 2.0634370688955608 +7 0 0 8 30 5 4.4597087252426109 -7.8827638990507737e-14 4.4274675210411178 45.022391476982129 4.3906251658136171 83.1913827250537 4.3484672676386253 115.64801319560502 4.3001744812136167 143.29016905790195 4.2448403293528827 166.83324775326764 4.1814869564805122 186.84949414111907 4.1092342892090539 203.79586913150507 3.9664963935124211 228.71119711713283 3.900085050044924 237.86535774408642 3.8282611736143224 245.64790333359178 3.7509977699901356 252.18065382612986 3.6684919050547649 257.55955073830046 3.5812841487561373 261.85774885490838 3.4903020914425427 265.12753377729564 3.2563194678036358 270.81200726266258 3.1100551434960835 271.98170041560661 2.9618503514557233 271.0198041908443 2.8168183221696381 267.93508097017184 2.6804852559453138 262.64304135146085 2.5552929808450244 254.96197593715624 2.4422308683121212 244.599441831039 2.2401505791195655 217.64691353134484 2.151133111136005 201.056918429691 2.074044407871952 180.92093656799989 2.0077408086453943 156.66685047524516 1.9507768946796205 127.55370899959235 1.9018428015583595 92.626546602667077 1.8597479366636549 50.650190411604896 1.8234765819369751 -7.8827638990507737e-14 + -2.0634370688955608 9 -1.0317185344477846 7 -0.25792963361194843 7 0.90275371764180579 7 2.0634370688955608 9 +Curves 1 +5 -50 0 300 1 0 0 0 -0 -1 -0 1 -0 75 50 +Polygon3D 1 +18 1 +1.54919336040805 +-50.0000000000001 -193.649167310371 0 -50 -100.162222794724 132.077221708445 -50 -61.3268215618448 181.310477098961 -50 -36.07227484963 207.519081541859 -50 -25.271297143767 215.964670920563 -50 -17.7530285515364 220.412736250131 -50 -10.6855693195119 223.3064009758 -50 -4.95237402527411 224.633007761395 -50 0.880368499625663 224.988375170484 -50 6.72507162583066 224.324641898183 -50 12.661140924837 222.632790528436 -50 18.7692232601295 219.889835732135 -50 25.1323024476704 216.058511990657 -50 34.1631311768744 209.164880434004 -50 49.3313861059531 194.640768206802 -50 77.4246170339179 161.751001897265 -50 124.351140656155 98.9596709349202 -50 193.649167310371 0 +-2.06343706889556 -1.44508549915884 -1.03285111933436 -0.670146895181744 -0.486059661805338 -0.347994236773033 -0.212117148727491 -0.0988862420228719 0.0176064603481351 0.134099162719142 0.250591865090149 0.367084567461156 0.483577269832163 0.638900872993506 0.871886277735519 1.22136438484854 1.64240072687205 2.06343706889556 +PolygonOnTriangulations 0 +Surfaces 2 +1 0 0 0 1 0 -0 0 1 0 0 -0 1 +3 0 0 0 0 0 1 1 0 -0 -0 1 0 200 +-0.5880026035475675 +Triangulations 0 + +TShapes 3 +Ve +2.74063527112943e-06 +-50.0000000000001 -193.649167310371 0 +0 0 + +0101101 +* +Ve +2.74063525157436e-06 +-50 193.649167310371 0 +0 0 + +0101101 +* +Ed + 2.74063516840746e-06 1 1 0 +1 1 0 -2.06343706889556 2.06343706889556 +2 1 1 1 -2.06343706889556 2.06343706889556 +2 2 2 0 -2.06343706889556 2.06343706889556 +5 1 0 +0 + +0101000 ++3 0 -2 0 * + ++1 0 \ No newline at end of file diff --git a/test/test_kind_of_shape.py b/test/test_kind_of_shape.py new file mode 100644 index 000000000..220585416 --- /dev/null +++ b/test/test_kind_of_shape.py @@ -0,0 +1,249 @@ +# Test KindOfShape method for Edges + +import math +import salome +from inspect import getfile +from os.path import abspath, dirname, join +salome.salome_init_without_session() +import GEOM + +from salome.geom import geomBuilder +geompy = geomBuilder.New() + + +def isEqual(v1, v2, tol=1.e-5): + return abs(v1 - v2) < tol + +def isEqualPoint(p1, p2, tol=1.e-5): + return isEqual(p1[0], p2[0], tol) and isEqual(p1[1], p2[1], tol) and isEqual(p1[2], p2[2], tol) + +def assertEqualType(props, t): + assert (props[0]==t), f"Expected type {t}, but was {props[0]}" + +def checkSegment(props, p1, p2): + assertEqualType(props, geompy.kind.SEGMENT) + p = props[1:4] + assert isEqualPoint(p, p1), f"Expected SEGMENT start point ({p1[0]:.4f}, {p1[1]:.4f}, {p1[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[4:7] + assert isEqualPoint(p, p2), f"Expected SEGMENT end point ({p2[0]:.4f}, {p2[1]:.4f}, {p2[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + +def checkCircle(props, c, d, r): + assertEqualType(props, geompy.kind.CIRCLE) + p = props[1:4] + assert isEqualPoint(p, c), f"Expected CIRCLE center point ({c[0]:.4f}, {c[1]:.4f}, {c[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[4:7] + assert isEqualPoint(p, d), f"Expected CIRCLE direction ({d[0]:.4f}, {d[1]:.4f}, {d[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + assert isEqual(props[7], r), f"Expected CIRCLE radius {r:.4f}, but was {props[7]:.4f}" + +def checkArcCircle(props, c, d, r, p1, p2): + assertEqualType(props, geompy.kind.ARC_CIRCLE) + p = props[1:4] + assert isEqualPoint(p, c), f"Expected ARC_CIRCLE center point ({c[0]:.4f}, {c[1]:.4f}, {c[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[4:7] + assert isEqualPoint(p, d), f"Expected ARC_CIRCLE direction ({d[0]:.4f}, {d[1]:.4f}, {d[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + assert isEqual(props[7], r), f"Expected ARC_CIRCLE radius {r:.4f}, but was {props[7]:.4f}" + p = props[8:11] + assert isEqualPoint(p, p1), f"Expected ARC_CIRCLE start point ({p1[0]:.4f}, {p1[1]:.4f}, {p1[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[11:14] + assert isEqualPoint(p, p2), f"Expected ARC_CIRCLE end point ({p2[0]:.4f}, {p2[1]:.4f}, {p2[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + +def checkEllipse(props, c, d, r1, r2, vx, vy): + assertEqualType(props, geompy.kind.ELLIPSE) + p = props[1:4] + assert isEqualPoint(p, c), f"Expected ELLIPSE center point ({c[0]:.4f}, {c[1]:.4f}, {c[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[4:7] + assert isEqualPoint(p, d), f"Expected ELLIPSE direction ({d[0]:.4f}, {d[1]:.4f}, {d[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + assert isEqual(props[7], r1), f"Expected ELLIPSE major radius {r1:.4f}, but was {props[7]:.4f}" + assert isEqual(props[8], r2), f"Expected ELLIPSE minor radius {r2:.4f}, but was {props[8]:.4f}" + p = props[9:12] + assert isEqualPoint(p, vx), f"Expected ELLIPSE x-direction ({vx[0]:.4f}, {vx[1]:.4f}, {vx[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[12:15] + assert isEqualPoint(p, vy), f"Expected ELLIPSE y-direction ({vy[0]:.4f}, {vy[1]:.4f}, {vy[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + +def checkArcEllipse(props, c, d, r1, r2, p1, p2, vx, vy): + assertEqualType(props, geompy.kind.ARC_ELLIPSE) + p = props[1:4] + assert isEqualPoint(p, c), f"Expected ARC_ELLIPSE center point ({c[0]:.4f}, {c[1]:.4f}, {c[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[4:7] + assert isEqualPoint(props[4:7], d), f"Expected ARC_ELLIPSE direction ({d[0]:.4f}, {d[1]:.4f}, {d[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + assert isEqual(props[7], r1), f"Expected ARC_ELLIPSE major radius {r1:.4f}, but was {props[7]:.4f}" + assert isEqual(props[8], r2), f"Expected ARC_ELLIPSE minor radius {r2:.4f}, but was {props[8]:.4f}" + p = props[9:12] + assert isEqualPoint(props[9:12], p1), f"Expected ARC_ELLIPSE start point ({p1[0]:.4f}, {p1[1]:.4f}, {p1[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[12:15] + assert isEqualPoint(props[12:15], p2), f"Expected ARC_ELLIPSE end point ({p2[0]:.4f}, {p2[1]:.4f}, {p2[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[15:18] + assert isEqualPoint(props[15:18], vx), f"Expected ARC_ELLIPSE x-direction ({vx[0]:.4f}, {vx[1]:.4f}, {vx[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[18:21] + assert isEqualPoint(props[18:21], vy), f"Expected ARC_ELLIPSE y-direction ({vy[0]:.4f}, {vy[1]:.4f}, {vy[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + +def checkHyperbola(props, c, d, r1, r2, vx, vy): + assertEqualType(props, geompy.kind.HYPERBOLA) + p = props[1:4] + assert isEqualPoint(p, c), f"Expected HYPERBOLA center point ({c[0]:.4f}, {c[1]:.4f}, {c[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[4:7] + assert isEqualPoint(p, d), f"Expected HYPERBOLA direction ({d[0]:.4f}, {d[1]:.4f}, {d[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + assert isEqual(props[7], r1), f"Expected HYPERBOLA major radius {r1:.4f}, but was {props[7]:.4f}" + assert isEqual(props[8], r2), f"Expected HYPERBOLA minor radius {r2:.4f}, but was {props[8]:.4f}" + p = props[9:12] + assert isEqualPoint(p, vx), f"Expected HYPERBOLA x-direction ({vx[0]:.4f}, {vx[1]:.4f}, {vx[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[12:15] + assert isEqualPoint(p, vy), f"Expected HYPERBOLA y-direction ({vy[0]:.4f}, {vy[1]:.4f}, {vy[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + +def checkParabola(props, c, d, f, vx, vy): + assertEqualType(props, geompy.kind.PARABOLA) + p = props[1:4] + assert isEqualPoint(p, c), f"Expected PARABOLA center point ({c[0]:.4f}, {c[1]:.4f}, {c[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[4:7] + assert isEqualPoint(p, d), f"Expected PARABOLA direction ({d[0]:.4f}, {d[1]:.4f}, {d[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + assert isEqual(props[7], f), f"Expected PARABOLA focal length {f:.4f}, but was {props[7]:.4f}" + p = props[8:11] + assert isEqualPoint(p, vx), f"Expected PARABOLA x-direction ({vx[0]:.4f}, {vx[1]:.4f}, {vx[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + p = props[11:14] + assert isEqualPoint(p, vy), f"Expected PARABOLA y-direction ({vy[0]:.4f}, {vy[1]:.4f}, {vy[2]:.4f}), but was ({p[0]:.4f}, {p[1]:.4f}, {p[2]:.4f})" + +def assertPoles(props, np, pfirst, poles): + n = len(poles) + assert (n<=np), f"Too much poles given ({n}), but should not be more than {np}" + for i in range(0,n-1): + p1 = poles[i] + p2 = props[pfirst+i*3:pfirst+(i+1)*3] + assert isEqualPoint(p1, p2), f"Expected pole #{i+1} ({p1[0]:.4f}, {p1[1]:.4f}, {p1[2]:.4f}), but was ({p2[0]:.4f}, {p2[1]:.4f}, {p2[2]:.4f})" + +def assertKnots(props, nk, kfirst, knots): + n = len(knots) + assert (n<=nk), f"Too much knots given ({n}), but should not be more than {nk}" + try: + for i in range(0,n-1): + assert isEqual(knots[i], props[kfirst+i]), f"Expected knot #{i+1} {knots[i]:.4f}, but was {props[kfirst+i]:.4f}" + except: + assert("Number of knots does not match expected number") + +def assertWeights(props, nw, wfirst, weights): + n = len(weights) + assert (n<=nw), f"Too much weights given ({n}), but should not be more than {nw}" + try: + for i in range(0,n-1): + assert isEqual(weights[i], props[wfirst+i]), f"Expected weight #{i+1} {weights[i]:.4f}, but was {props[wfirst+i]:.4f}" + except: + assert("Number of weights does not match expected number") + +def assertMultiplicities(props, nm, mfirst, multis): + n = len(multis) + assert (n<=nm), f"Too much multiplicities given ({n}), but should not be more than {nm}" + try: + for i in range(0,n-1): + assert isEqual(multis[i], props[mfirst+i]), f"Expected multiplicity #{i+1} {multis[i]:.4f}, but was {props[mfirst+i]:.4f}" + except: + assert("Number of multiplicities does not match expected number") + +def checkBSpline(props, period, deg, np, nk, nw, nm, poles=[], knots=[], weights=[], multis=[]): + assertEqualType(props, geompy.kind.CRV_BSPLINE) + assert (period==props[1]), f"Expected CRV_BSPLINE periodicity ({period}), but was ({props[1]})" + assert (deg==props[2]), f"Expected CRV_BSPLINE degree ({deg}), but was ({props[2]})" + assert (np==props[3]), f"Expected CRV_BSPLINE number of poles ({np}), but was ({props[3]})" + assert (nk==props[4]), f"Expected CRV_BSPLINE number of knots ({nk}), but was ({props[4]})" + assert (nw==props[5]), f"Expected CRV_BSPLINE number of weights ({nw}), but was ({props[5]})" + assert (nm==props[6]), f"Expected CRV_BSPLINE number of multiplicities ({nm}), but was ({props[6]})" + if poles and len(poles): + assertPoles(props, np, 7, poles) + if knots and len(knots): + assertKnots(props, nk, 7+3*np, knots) + if weights and len(weights): + assertWeights(props, nw, 7+3*np+nk, weights) + +def checkBezier(props, np, nw, poles=[]): + assertEqualType(props, geompy.kind.CRV_BEZIER) + assert (np==props[1]), f"Expected CRV_BEZIER number of poles ({np}), but was ({props[1]})" + assert (nw==props[2]), f"Expected CRV_BEZIER number of weights ({nw}), but was ({props[2]})" + if poles and len(poles): + assertPoles(props, np, 3, poles) + + +data_dir = abspath(join(dirname(getfile(lambda: None)), 'data')) + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Vertex_1 = geompy.MakeVertex(0, 0, 0) +Vertex_2 = geompy.MakeVertex(50, 100, 0) +Vertex_3 = geompy.MakeVertex(-10, 60, 0) +Vertex_4 = geompy.MakeVertex(0, 100, 0) +Vertex_5 = geompy.MakeVertex(-100, 100, 0) +Vertex_6 = geompy.MakeVertex(-100, 0, 0) +Vertex_7 = geompy.MakeVertex(-200, 0, 0) +Vertex_8 = geompy.MakeVertex(-200, 100, 0) + +# create or import some curves +Line_1 = geompy.MakeLineTwoPnt(Vertex_1, Vertex_2) +Circle_1 = geompy.MakeCircle(Vertex_2, OZ, 50) +Ellipse_1 = geompy.MakeEllipse(Vertex_1, OZ, 200, 100, Line_1) +Arc_1 = geompy.MakeArc(Vertex_2, Vertex_3, Vertex_1) +Curve_1 = geompy.MakeCurveParametric("t", "50*sin(t)", "0", 0, 360, 30, GEOM.Interpolation, True) +Curve_2 = geompy.MakeCurveParametric("-t", "50*cos(t)", "t", 0, 360, 14, GEOM.Bezier, True) +Curve_3 = geompy.ImportBREP(join(data_dir, "KindOfShape_Curve3.brep")) +Curve_4 = geompy.ImportBREP(join(data_dir, "KindOfShape_Curve4.brep")) +Curve_5 = geompy.MakeInterpol([Vertex_1, Vertex_4, Vertex_5, Vertex_6, Vertex_7, Vertex_8], False, False) +Curve_6 = geompy.ImportBREP(join(data_dir, "KindOfShape_Curve6.brep")) +Curve_7 = geompy.MakeBezier([Vertex_5, Vertex_6, Vertex_7, Vertex_8], True) +Curve_8 = geompy.MakeBezier([Vertex_5, Vertex_6, Vertex_1, Vertex_4], False) +Curve_9 = geompy.ImportBREP(join(data_dir, "KindOfShape_Curve9.brep")) +Curve_10 = geompy.ImportBREP(join(data_dir, "KindOfShape_Curve10.brep")) + +# check all curves +props = geompy.KindOfShape(Line_1) +# [SEGMENT, 0.,0.,0., 50.,100.,0.] +checkSegment(props, [0,0,0], [50,100,0]) + +props = geompy.KindOfShape(Circle_1) +# [CIRCLE, 50.,100.,0., 0.,0.,1., 50.] +checkCircle(props, [50,100,0], [0,0,1], 50) + +props = geompy.KindOfShape(Ellipse_1) +# [ELLIPSE, 0.,0.,0., 0.,0.,1., 200., 100., 0.44721,0.89443,0., 0.44721,0.89443,0.] +checkEllipse(props, [0,0,0], [0,0,1], 200, 100, [0.4472136,0.8944272,0], [-0.8944272,0.4472136,0]) + +props = geompy.KindOfShape(Arc_1) +# [ARC_CIRCLE, 47.5,38.75,0., 0.,0.,1., 61.301, 50.,100.,0., 0.,0.,0.] +checkArcCircle(props, [47.5,38.75,0], [0,0,1], 61.301, [50,100,0], [0,0,0]) + +props = geompy.KindOfShape(Curve_1) +# [CRV_BSPLINE, 0, 3, 33, 31, 0, 31, 0.,0.,0.,..., 4,1,...,1,4] +checkBSpline(props, 0, 3, 33, 31, 0, 31, [[0,0,0],[5.246092,-6.374961,0],[10.613646,-25.338811,0],[19.662636,-44.299221,0]], [0,29.39007,51.399444,64.149986], [], [4,1,1,1,1]) + +props = geompy.KindOfShape(Curve_2) +# [CRV_BEZIER, 15, 0, 0.,50.,0.,...,-360.,-14.18455,360.] +checkBezier(props, 15, 0, [[0,50,0],[-25.714286,41.780762,25.714286],[-51.428571,19.825283,51.428571],[-77.142857,-8.648146,77.142857]]) + +props = geompy.KindOfShape(Curve_3) +# [CRV_BSPLINE, 1, 3, 8, 9, 0, 0, -100.,0.,0.,..., 0.,1.,2.,3.,4.,5.,6.,7.,8.] +checkBSpline(props, 1, 3, 8, 9, 0, 0, [[-100,0,0],[-200,200,0],[0,100,0],[200,200,0],[100,0,0],[200,-200,0],[0,-100,0],[-200,-200,0]], [0,1,2,3,4,5,6,7,8]) + +props = geompy.KindOfShape(Curve_4) +# [CRV_BSPLINE, 1, 2, 3, 4, 3, 0, 0.,0.,0., 100.,200.,0., 200.,0.,0., 0,1,2,3, 200.,100.,100.] +checkBSpline(props, 1, 2, 3, 4, 3, 0, [[0,0,0],[100,200,0],[200,0,0]], [0,1,2,3], [200,100,100]) + +props = geompy.KindOfShape(Curve_5) +# [CRV_BSPLINE, 0, 3, 8, 6, 0, 6, 0.,0.,0.,..., 100.,0.,0.,100.,200.,300.,400.,500., 4,1,1,1,1,4] +checkBSpline(props, 0, 3, 8, 6, 0, 6, [[0,0,0],[38.888889,50,0],[23.684211,113.157895,0]], [0,100,200,300,400,500], [], [4,1,1,1,1,4]) + +props = geompy.KindOfShape(Curve_6) +# [ARC_ELLIPSE, -18.46154,0.,64.61538, 0.57668,0.,-0.81697, 96.03993, 76.25867, 50.,-37.25439,112.94118, 50.,37.25439,112.94118, -0.81697,0.,-0.57668, 0.,1.,0.] +checkArcEllipse(props, [-18.46154,0,64.61538], [0.57668,0,-0.81697], 96.03993, 76.25867, [50,-37.25439,112.94118], [50,37.25439,112.94118], [-0.81697,0,-0.57668], [0,1,0]) + +props = geompy.KindOfShape(Curve_7) +# [CRV_BEZIER, 5, 0, -100.,100.,0., -100.,0.,0., -200.,0.,0., -200.,100.,0., -100.,100.,0.] +checkBezier(props, 5, 0, [[-100,100,0],[-100,0,0],[-200,0,0],[-200,100,0],[-100,100,0]]) + +props = geompy.KindOfShape(Curve_8) +# [CRV_BEZIER, 4, 0, -100.,100.,0., -100.,0.,0., 0.,0.,0., 0.,100.,0.] +checkBezier(props, 4, 0, [[-100,100,0],[-100,0,0],[0,0,0],[0,100,0]]) + +props = geompy.KindOfShape(Curve_9) +# [HYPERBOLA, -50., 0., 300., 1., 0., 0., 75., 50., 0., 0., -1., 0., 1., 0.] +checkHyperbola(props, [-50,0,300], [1,0,0], 75, 50, [0,0,-1], [0,1,0]) + +props = geompy.KindOfShape(Curve_10) +# [PARABOLA, -25.,0.,262.5, -0.83205,0.,-0.5547, 13.8675, 0.5547,0.,-0.83205, 0.,-1.,0.] +checkParabola(props, [-25,0,262.5], [-0.83205,0,-0.5547], 13.867505, [0.5547,0,-0.83205], [0,-1,0]) diff --git a/test/tests.set b/test/tests.set index 7a002556f..f505c9120 100644 --- a/test/tests.set +++ b/test/tests.set @@ -27,6 +27,7 @@ IF(${OpenCASCADE_VERSION}.${OpenCASCADE_SP_VERSION} VERSION_GREATER "7.5.3.3") test_point_cloud_on_face.py test_CR.py test_conformity.py + test_kind_of_shape.py test_proximity_edge_edge.py test_proximity_face_face.py )