From: Paul RASCLE Date: Wed, 30 Sep 2020 15:44:54 +0000 (+0200) Subject: Python for completeCase, without new regions X-Git-Tag: SH_V2_2_0~32 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d111bcca0224ade7039dbbdeccad89342c175f97;p=modules%2Fhydro.git Python for completeCase, without new regions --- diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index 866baef2..6e26c713 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -36,6 +36,7 @@ SET(_add_SOURCES sipHYDROPyHYDROData_BathymetryAltitudePoint.cc sipHYDROPyHYDROData_Bathymetry.cc sipHYDROPyHYDROData_CalculationCase.cc + sipHYDROPyHYDROData_CompleteCalcCase.cc sipHYDROPyHYDROData_Channel.cc sipHYDROPyHYDROData_Confluence.cc sipHYDROPyHYDROData_Digue.cc @@ -70,10 +71,12 @@ SET(_add_SOURCES sipHYDROPyNCollection_Sequence0100gp_XYZ.cc sipHYDROPyNCollection_Sequence0100HYDROData_IPolylineSectionType.cc sipHYDROPyNCollection_Sequence0100TCollection_AsciiString.cc + sipHYDROPyNCollection_Sequence0600opencascadehandle0100HYDROData_Entity.cc sipHYDROPyNCollection_Sequence1800.cc sipHYDROPyNCollection_Sequence2400.cc sipHYDROPyNCollection_Sequence2600.cc sipHYDROPystdvector0100HYDROData_BathymetryAltitudePoint.cc + sipHYDROPystdvector0101HYDROData_Entity.cc sipHYDROPystdvector1800.cc sipHYDROPystdvector2400.cc sipHYDROPystdvector2600.cc diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index 20643fe7..16e56bc0 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -54,6 +54,7 @@ %Include HYDROData_ArtificialObject.sip %Include HYDROData_Bathymetry.sip %Include HYDROData_CalculationCase.sip +%Include HYDROData_CompleteCalcCase.sip %Include HYDROData_Channel.sip %Include HYDROData_Confluence.sip %Include HYDROData_Digue.sip diff --git a/src/HYDROPy/HYDROData_CalculationCase.sip b/src/HYDROPy/HYDROData_CalculationCase.sip index b46ac06e..9bd7af3f 100644 --- a/src/HYDROPy/HYDROData_CalculationCase.sip +++ b/src/HYDROPy/HYDROData_CalculationCase.sip @@ -218,6 +218,45 @@ public: } %End + + /** + * Add a polyline (as a constraint for the mesh). + */ + bool AddInterPoly( HYDROData_PolylineXY theInterPolyline ) [bool ( opencascade::handle& )]; + %MethodCode + Handle(HYDROData_PolylineXY) aRef = + Handle(HYDROData_PolylineXY)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + if ( sipSelfWasArg ) { + sipRes = sipCpp->HYDROData_CalculationCase::AddInterPoly( aRef ); + } else { + sipRes = sipCpp->AddInterPoly( aRef ); + } + Py_END_ALLOW_THREADS + } + %End + + /** + * Remove a polyline (as a constraint for the mesh). + */ + void RemoveInterPolyObject( HYDROData_PolylineXY theInterPolyline ) [void ( opencascade::handle& )]; + %MethodCode + Handle(HYDROData_PolylineXY) aRef = + Handle(HYDROData_PolylineXY)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + if ( sipSelfWasArg ) { + sipCpp->HYDROData_CalculationCase::RemoveInterPolyObject( aRef ); + } else { + sipCpp->RemoveInterPolyObject( aRef ); + } + Py_END_ALLOW_THREADS + } + %End + /** * Sets reference boundary polyline object for calculation case. */ diff --git a/src/HYDROPy/HYDROData_CompleteCalcCase.sip b/src/HYDROPy/HYDROData_CompleteCalcCase.sip new file mode 100644 index 00000000..894a564a --- /dev/null +++ b/src/HYDROPy/HYDROData_CompleteCalcCase.sip @@ -0,0 +1,103 @@ +// Copyright (C) 2014-2015 EDF-R&D +// 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 +// + +%ExportedHeaderCode +#include +#include +%End + +class HYDROData_CompleteCalcCase +{ + +%TypeHeaderCode +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" +#include +#include +%End + +public: + + /** + * Add new geometry object for calculation case. + */ + static SIP_PYTUPLE AddObjects( HYDROData_Document doc, + HYDROData_CalculationCase theCalcCase, + std::vector theNewObjects, + bool IsUseOrigNamingOfNewRegions) + [ bool ( const opencascade::handle&, + opencascade::handle&, + NCollection_Sequence >, + bool, + bool&, + NCollection_Sequence< opencascade::handle >& )]; + %MethodCode + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); + Handle(HYDROData_CalculationCase) aCase = Handle(HYDROData_CalculationCase)::DownCast( createHandle( a1 ) ); + NCollection_Sequence objs; + for (size_t i = 0; i != a2->size(); i++) + { + DEBTRACE("item " << i); + Handle(HYDROData_Entity) anEnt = createHandle( (*a2)[i] ); + objs.Append(anEnt); + } + bool res = false; + bool isIntersectionOfNewObj = false; + NCollection_Sequence theNewRegions; + DEBTRACE(" --- 0"); + if ( !aDoc.IsNull() && !aCase.IsNull() ) + { + DEBTRACE("before HYDROData_CompleteCalcCase::AddObjects"); + Py_BEGIN_ALLOW_THREADS + res = HYDROData_CompleteCalcCase::AddObjects( aDoc, aCase, objs, a3, isIntersectionOfNewObj, theNewRegions ); + Py_END_ALLOW_THREADS + DEBTRACE("after"); + DEBTRACE("res " << res); + DEBTRACE("isIntersectionOfNewObj " << isIntersectionOfNewObj); + DEBTRACE("theNewRegions size " << theNewRegions.Size()); + } + PyObject* t; + if (res && isIntersectionOfNewObj) + { + DEBTRACE(" --- 1a"); + t = Py_BuildValue("(iiO)", res, isIntersectionOfNewObj, theNewRegions); + DEBTRACE(" --- 2a"); + } + else + { + DEBTRACE(" --- 1b"); + t = Py_BuildValue("(ii)", res, isIntersectionOfNewObj); + DEBTRACE(" --- 2b"); + } + + sipRes = t; + %End + +protected: + + /** + * Creates new object in the internal data structure. Use higher level objects + * to create objects with real content. + */ + HYDROData_CompleteCalcCase(); + + /** + * Destructs properties of the object and object itself, removes it from the document. + */ + ~HYDROData_CompleteCalcCase(); +}; diff --git a/src/HYDROPy/HYDROData_Entity.sip b/src/HYDROPy/HYDROData_Entity.sip index 42e8b332..344d691a 100644 --- a/src/HYDROPy/HYDROData_Entity.sip +++ b/src/HYDROPy/HYDROData_Entity.sip @@ -277,3 +277,91 @@ protected: virtual ~HYDROData_Entity(); }; + + +%MappedType std::vector +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ( ( l = PyList_New( sipCpp->size() ) ) == NULL ) + return NULL; + + // Set the list elements. + for ( int i = 0, n = sipCpp->size(); i < n; ++i ) + { + HYDROData_Entity* t = (*sipCpp)[i]; //new HYDROData_Entity( ( sipCpp)[i] ); + + PyObject* pobj; + if ( ( pobj = sipConvertFromNewType( t, sipType_HYDROData_Entity, sipTransferObj ) ) == NULL ) + { + Py_DECREF( l ); + //delete t; + + return NULL; + } + + PyList_SET_ITEM( l, i, pobj ); + } + + return l; +%End + +%ConvertToTypeCode + SIP_SSIZE_T len; + + // Check the type if that is all that is required. + if (sipIsErr == NULL) + { + if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0) + return 0; + + for (SIP_SSIZE_T i = 0; i < len; ++i) + { + PyObject *itm = PySequence_ITEM(sipPy, i); + bool ok = (itm && sipCanConvertToType(itm, sipType_HYDROData_Entity, SIP_NOT_NONE)); + + Py_XDECREF(itm); + + if (!ok) + return 0; + } + + return 1; + } + + std::vector *aSeq = new std::vector; + len = PySequence_Size(sipPy); + aSeq->reserve( len ); + + for (SIP_SSIZE_T i = 0; i < len; ++i) + { + PyObject *itm = PySequence_ITEM(sipPy, i); + int state; + HYDROData_Entity *t = reinterpret_cast(sipConvertToType(itm, sipType_HYDROData_Entity, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + Py_DECREF(itm); + + if (*sipIsErr) + { + sipReleaseType(t, sipType_HYDROData_Entity, state); + + delete aSeq; + return 0; + } + + aSeq->push_back(t); + + sipReleaseType(t, sipType_HYDROData_Entity, state); + } + + *sipCppPtr = aSeq; + + return sipGetState(sipTransferObj); +%End +};