]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Python for completeCase, without new regions
authorPaul RASCLE <paul.rascle@openfields.fr>
Wed, 30 Sep 2020 15:44:54 +0000 (17:44 +0200)
committerYOANN AUDOUIN <B61570@dsp0851742.postes.calibre.edf.fr>
Fri, 30 Oct 2020 16:08:09 +0000 (17:08 +0100)
src/HYDROPy/CMakeLists.txt
src/HYDROPy/HYDROData.sip
src/HYDROPy/HYDROData_CalculationCase.sip
src/HYDROPy/HYDROData_CompleteCalcCase.sip [new file with mode: 0644]
src/HYDROPy/HYDROData_Entity.sip

index 866baef2e229baafa55539dd2c63aaa7b3f2cc03..6e26c713dd58b4a7b801810a42e1519ee8119c6a 100644 (file)
@@ -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
index 20643fe76bbddcf2912d2d96fc7f6b743128c39b..16e56bc0c938550a028108e8a6e7b39e4d01e27a 100644 (file)
@@ -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
index b46ac06e9fae3f101d947f93f57c42df27666c33..9bd7af3ff1ce555a6ed4ae493222a787bf025081 100644 (file)
@@ -218,6 +218,45 @@ public:
     }
   %End
 
+
+  /**
+   * Add a polyline (as a constraint for the mesh).
+   */
+  bool AddInterPoly( HYDROData_PolylineXY theInterPolyline ) [bool ( opencascade::handle<HYDROData_PolylineXY>& )];
+  %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<HYDROData_PolylineXY>& )];
+  %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 (file)
index 0000000..894a564
--- /dev/null
@@ -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 <HYDROData_CompleteCalcCase.h>
+#include <HYDROData_Document.h>
+%End
+
+class HYDROData_CompleteCalcCase
+{
+
+%TypeHeaderCode
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+#include <HYDROData_CompleteCalcCase.h>
+#include <HYDROData_Document.h>
+%End
+
+public:
+
+  /**
+   * Add new geometry object for calculation case.
+   */
+  static SIP_PYTUPLE AddObjects( HYDROData_Document doc,
+                                 HYDROData_CalculationCase theCalcCase,
+                                 std::vector<HYDROData_Entity*> theNewObjects, 
+                                 bool IsUseOrigNamingOfNewRegions)
+                        [ bool ( const opencascade::handle<HYDROData_Document>&,
+                                 opencascade::handle<HYDROData_CalculationCase>&,
+                                 NCollection_Sequence<opencascade::handle<HYDROData_Entity> >,
+                                 bool,
+                                 bool&,
+                                 NCollection_Sequence< opencascade::handle<HYDROData_Region> >& )];
+  %MethodCode
+    Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
+    Handle(HYDROData_CalculationCase) aCase = Handle(HYDROData_CalculationCase)::DownCast( createHandle( a1 ) );
+    NCollection_Sequence<Handle(HYDROData_Entity)> 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<Handle(HYDROData_Region)> 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();
+};
index 42e8b3325726cab81924cabe1bedc9ddfe758a80..344d691a3f7db18c609d49ef90108a1c9d1b23fd 100644 (file)
@@ -277,3 +277,91 @@ protected:
   virtual ~HYDROData_Entity();
 
 };
+
+
+%MappedType std::vector<HYDROData_Entity*>
+{
+%TypeHeaderCode
+#include <vector>
+%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<HYDROData_Entity*> *aSeq = new std::vector<HYDROData_Entity*>;
+    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<HYDROData_Entity *>(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
+};