From 280a8fc50206c3cbd42e77d9fafdfd745aa043ad Mon Sep 17 00:00:00 2001 From: skv Date: Fri, 12 Sep 2014 10:34:11 +0400 Subject: [PATCH] Definition of IDL interface to CurveCreator --- idl/GEOM_Gen.idl | 80 ++++++++- src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx | 34 ++++ src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx | 13 ++ src/GEOM_I/GEOM_ICurvesOperations_i.cc | 189 ++++++++++++++++++++ src/GEOM_I/GEOM_ICurvesOperations_i.hh | 27 +++ 5 files changed, 337 insertions(+), 6 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index ecf0308db..e3ec6d8b9 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -164,7 +164,8 @@ module GEOM /*! * \brief Kind of the curves. * - * Used in the functions GEOM_ICurvesOperations.MakeCurveParametric(), GEOM_ICurvesOperations.MakeCurveParametricNew() + * Used in the functions GEOM_ICurvesOperations.MakeCurveParametric(), GEOM_ICurvesOperations.MakeCurveParametricNew(), + * GEOM_ICurvesOperations.MakePolyline2D, GEOM_ICurvesOperations.MakePolyline2DOnPlane. */ enum curve_type { /*! Polyline curve */ @@ -221,11 +222,12 @@ module GEOM }; - typedef sequence string_array; - typedef sequence short_array; - typedef sequence ListOfBool; - typedef sequence ListOfLong; - typedef sequence ListOfDouble; + typedef sequence string_array; + typedef sequence short_array; + typedef sequence ListOfBool; + typedef sequence ListOfLong; + typedef sequence ListOfDouble; + typedef sequence ListOfListOfDouble; interface GEOM_Object; interface GEOM_BaseObject; @@ -3319,6 +3321,72 @@ module GEOM * \return New GEOM_Object, containing the created wire. */ GEOM_Object Make3DSketcher (in ListOfDouble theCoordinates); + + /*! + * \brief Create a 2D polyline (wire or a compound of wires). + * + * The polyline can have several sections. Each section represents a set + * of points in the form of list of coordinates of the following order: + * x1, y1, x2, y2, ..., xN, yN + * Each section has its own name, type of curve (can be either + * GEOM::Polyline or GEOM::Interpolation) and Closed flag. + * For each section a wire is created. It represents either a polyline or + * interpolation BSpline either closed or not depending on the Closed flag. + * The result represents a wire if there is only one section is defined. + * Otherwise a compound of wires is returned. + * + * \param theCoordsList the list of coordinates list. theCoordsList[0] + * is the coordinates list of the first section. theCoordsList[1] + * is for the second section etc. + * \param theNamesList the list of names. The order corresponds to + * theCoordsList. + * \param theTypesList the list of curve types. The order corresponds to + * theCoordsList. + * \param theClosedList the list of Closed flags. The order corresponds to + * theCoordsList. + * \param theWorkingPlane 9 double values, defining origin, + * OZ and OX directions of the working plane. + * \return New GEOM_Object, containing the created wire or a compound + * of wires. + */ + GEOM_Object MakePolyline2D (in ListOfListOfDouble theCoordsList, + in string_array theNamesList, + in short_array theTypesList, + in ListOfBool theClosedList, + in ListOfDouble theWorkingPlane); + + /*! + * \brief Create a 2D polyline (wire or a compound of wires). + * + * The polyline can have several sections. Each section represents a set + * of points in the form of list of coordinates of the following order: + * x1, y1, x2, y2, ..., xN, yN + * Each section has its own name, type of curve (can be either + * GEOM::Polyline or GEOM::Interpolation) and Closed flag. + * For each section a wire is created. It represents either a polyline or + * interpolation BSpline either closed or not depending on the Closed flag. + * The result represents a wire if there is only one section is defined. + * Otherwise a compound of wires is returned. + * + * \param theCoordsList the list of coordinates list. theCoordsList[0] + * is the coordinates list of the first section. theCoordsList[1] + * is for the second section etc. + * \param theNamesList the list of names. The order corresponds to + * theCoordsList. + * \param theTypesList the list of curve types. The order corresponds to + * theCoordsList. + * \param theClosedList the list of Closed flags. The order corresponds to + * theCoordsList. + * \param theWorkingPlane planar Face or LCS(Marker) of the working plane. + * \return New GEOM_Object, containing the created wire or a compound + * of wires. + */ + GEOM_Object MakePolyline2DOnPlane (in ListOfListOfDouble theCoordsList, + in string_array theNamesList, + in short_array theTypesList, + in ListOfBool theClosedList, + in GEOM_Object theWorkingPlane); + }; // # GEOM_ILocalOperations: diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index 8046dbb63..12f1a64dc 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -1499,3 +1499,37 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeIsoline SetErrorCode(OK); return anIsoline; } + +//============================================================================= +/*! + * MakePolyline2D + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline2D + (const std::list > &theCoords, + const Handle(TColStd_HArray1OfExtendedString) &theNames, + const Handle(TColStd_HArray1OfByte) &theTypes, + const Handle(TColStd_HArray1OfByte) &theCloseds, + const Handle(TColStd_HArray1OfReal) &theWorkingPlane) +{ + Handle(GEOM_Object) aResult; + + return aResult; +} + +//============================================================================= +/*! + * MakePolyline2DOnPlane + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline2DOnPlane + (const std::list > &theCoords, + const Handle(TColStd_HArray1OfExtendedString) &theNames, + const Handle(TColStd_HArray1OfByte) &theTypes, + const Handle(TColStd_HArray1OfByte) &theCloseds, + const Handle(GEOM_Object) &theWorkingPlane) +{ + Handle(GEOM_Object) aResult; + + return aResult; +} diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx index 15591a64f..fe4278cc6 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx @@ -100,6 +100,19 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations { const bool IsUIso, const double theParameter); + Standard_EXPORT Handle(GEOM_Object) MakePolyline2D + (const std::list > &theCoords, + const Handle(TColStd_HArray1OfExtendedString) &theNames, + const Handle(TColStd_HArray1OfByte) &theTypes, + const Handle(TColStd_HArray1OfByte) &theCloseds, + const Handle(TColStd_HArray1OfReal) &theWorkingPlane); + + Standard_EXPORT Handle(GEOM_Object) MakePolyline2DOnPlane + (const std::list > &theCoords, + const Handle(TColStd_HArray1OfExtendedString) &theNames, + const Handle(TColStd_HArray1OfByte) &theTypes, + const Handle(TColStd_HArray1OfByte) &theCloseds, + const Handle(GEOM_Object) &theWorkingPlane); }; #endif diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.cc b/src/GEOM_I/GEOM_ICurvesOperations_i.cc index f1d2469c0..06d9b66d3 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.cc +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.cc @@ -30,6 +30,9 @@ #include "GEOM_Engine.hxx" #include "GEOM_Object.hxx" +#include +#include + //============================================================================= /*! * constructor: @@ -667,3 +670,189 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::Make3DSketcher return GetObject(anObject); } + +//============================================================================= +/*! + * MakePolyline2D + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline2D + (const GEOM::ListOfListOfDouble &theCoordsList, + const GEOM::string_array &theNamesList, + const GEOM::short_array &theTypesList, + const GEOM::ListOfBool &theClosedList, + const GEOM::ListOfDouble &theWorkingPlane) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + + // Convert input data + Handle(TColStd_HArray1OfExtendedString) aNames = + ConvertStringArray(theNamesList); + Handle(TColStd_HArray1OfByte) aTypes = + ConvertEnumArray(theTypesList); + Handle(TColStd_HArray1OfByte) aCloseds = + ConvertBoolArray(theClosedList); + std::list > aCoords; + + ConvertListListDouble(theCoordsList, aCoords); + + Handle(TColStd_HArray1OfReal) aWorkingPlane; + const int n = theWorkingPlane.length(); + int i; + + if (n > 0) { + aWorkingPlane = new TColStd_HArray1OfReal(1, n); + + for (i = 0; i < n; i++) { + aWorkingPlane->SetValue(i + 1, theWorkingPlane[i]); + } + } + + // Make Polyline + Handle(GEOM_Object) anObject = GetOperations()->MakePolyline2D + (aCoords, aNames, aTypes, aCloseds, aWorkingPlane); + + if (!GetOperations()->IsDone() || anObject.IsNull()) { + return GEOM::GEOM_Object::_nil(); + } + + return GetObject(anObject); +} + +//============================================================================= +/*! + * MakePolylineOnPlane + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline2DOnPlane + (const GEOM::ListOfListOfDouble &theCoordsList, + const GEOM::string_array &theNamesList, + const GEOM::short_array &theTypesList, + const GEOM::ListOfBool &theClosedList, + GEOM::GEOM_Object_ptr theWorkingPlane) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + + // Convert input data + Handle(TColStd_HArray1OfExtendedString) aNames = + ConvertStringArray(theNamesList); + Handle(TColStd_HArray1OfByte) aTypes = + ConvertEnumArray(theTypesList); + Handle(TColStd_HArray1OfByte) aCloseds = + ConvertBoolArray(theClosedList); + std::list > aCoords; + Handle(GEOM_Object) aWorkingPlane = + GetObjectImpl(theWorkingPlane); + + ConvertListListDouble(theCoordsList, aCoords); + + // Make Polyline + Handle(GEOM_Object) anObject = GetOperations()->MakePolyline2DOnPlane + (aCoords, aNames, aTypes, aCloseds, aWorkingPlane); + + if (!GetOperations()->IsDone() || anObject.IsNull()) { + return GEOM::GEOM_Object::_nil(); + } + + return GetObject(anObject); +} + +//============================================================================= +/*! + * ConvertEnumArray + */ +//============================================================================= +Handle(TColStd_HArray1OfByte) GEOM_ICurvesOperations_i::ConvertEnumArray + (const GEOM::short_array &theInArray) +{ + Handle(TColStd_HArray1OfByte) anOutArray; + const int n = theInArray.length(); + int i; + + if (n <= 0) { + return anOutArray; + } + + anOutArray = new TColStd_HArray1OfByte(1, n); + + for (i = 0; i < n; i++) { + bool isOK = true; + GEOMImpl_ICurvesOperations::CurveType aType; + + switch(theInArray[i]) { + case GEOM::Polyline: + aType = GEOMImpl_ICurvesOperations::Polyline; + break; + case GEOM::Bezier: + aType = GEOMImpl_ICurvesOperations::Bezier; + break; + case GEOM::Interpolation: + aType = GEOMImpl_ICurvesOperations::Interpolation; + break; + default: + isOK = false; + break; + } + + if (isOK) { + anOutArray->SetValue(i + 1, aType); + } else { + anOutArray.Nullify(); + break; + } + } + + return anOutArray; +} + +//============================================================================= +/*! + * ConvertBoolArray + */ +//============================================================================= +Handle(TColStd_HArray1OfByte) GEOM_ICurvesOperations_i::ConvertBoolArray + (const GEOM::ListOfBool &theInArray) +{ + Handle(TColStd_HArray1OfByte) anOutArray; + const int n = theInArray.length(); + int i; + + if (n <= 0) { + return anOutArray; + } + + anOutArray = new TColStd_HArray1OfByte(1, n); + + for (i = 0; i < n; i++) { + anOutArray->SetValue(i + 1, theInArray[i]); + } + + return anOutArray; +} + +//============================================================================= +/*! + * ConvertListListDouble + */ +//============================================================================= +void GEOM_ICurvesOperations_i::ConvertListListDouble + (const GEOM::ListOfListOfDouble &theInList, + std::list > &theOutList) +{ + const int n = theInList.length(); + int i; + std::list anEmptyList; + + for (i = 0; i < n; i++) { + theOutList.push_back(anEmptyList); + + const int m = theInList[i].length(); + int j; + + for (j = 0; j < m; j++) { + theOutList.back().push_back(theInList[i][j]); + } + } +} diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.hh b/src/GEOM_I/GEOM_ICurvesOperations_i.hh index c08cb0156..90cbb2114 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.hh +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.hh @@ -112,8 +112,35 @@ class GEOM_I_EXPORT GEOM_ICurvesOperations_i : GEOM::GEOM_Object_ptr Make3DSketcher (const GEOM::ListOfDouble& theCoordinates); + GEOM::GEOM_Object_ptr MakePolyline2D + (const GEOM::ListOfListOfDouble &theCoordsList, + const GEOM::string_array &theNamesList, + const GEOM::short_array &theTypesList, + const GEOM::ListOfBool &theClosedList, + const GEOM::ListOfDouble &theWorkingPlane); + + GEOM::GEOM_Object_ptr MakePolyline2DOnPlane + (const GEOM::ListOfListOfDouble &theCoordsList, + const GEOM::string_array &theNamesList, + const GEOM::short_array &theTypesList, + const GEOM::ListOfBool &theClosedList, + GEOM::GEOM_Object_ptr theWorkingPlane); + ::GEOMImpl_ICurvesOperations* GetOperations() { return (::GEOMImpl_ICurvesOperations*)GetImpl(); } + +private: + + Handle(TColStd_HArray1OfByte) + ConvertEnumArray(const GEOM::short_array &theInArray); + + Handle(TColStd_HArray1OfByte) + ConvertBoolArray(const GEOM::ListOfBool &theInArray); + + void ConvertListListDouble + (const GEOM::ListOfListOfDouble &theCoordsList, + std::list > &theCoords); + }; #endif -- 2.39.2