From d3b7ae43861d9942fcd1b0acf55d3e4c4984e3c6 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 4 Apr 2018 10:57:24 +0200 Subject: [PATCH] Visitor for AbstractPoint --- src/engine/AbstractPoint.hxx | 2 + src/engine/BagPoint.cxx | 10 ++++ src/engine/BagPoint.hxx | 1 + src/engine/ElementaryPoint.cxx | 7 +++ src/engine/ElementaryPoint.hxx | 1 + src/engine/ForkBlocPoint.cxx | 9 +++ src/engine/ForkBlocPoint.hxx | 1 + src/engine/LinkedBlocPoint.cxx | 9 +++ src/engine/LinkedBlocPoint.hxx | 1 + src/engine/PointVisitor.hxx | 43 ++++++++++++++ src/engine/SetOfPoints.cxx | 5 ++ src/engine/SetOfPoints.hxx | 2 + src/engine_swig/pilot.i | 103 +++++++++++++++++++++++++++++++++ 13 files changed, 194 insertions(+) create mode 100644 src/engine/PointVisitor.hxx diff --git a/src/engine/AbstractPoint.hxx b/src/engine/AbstractPoint.hxx index 2aceabfdf..e75f07739 100644 --- a/src/engine/AbstractPoint.hxx +++ b/src/engine/AbstractPoint.hxx @@ -39,6 +39,7 @@ namespace YACS class BlocPoint; class ComposedNode; class ForkBlocPoint; + class PointVisitor; class LinkedBlocPoint; class YACSLIBENGINE_EXPORT AbstractPoint @@ -70,6 +71,7 @@ namespace YACS virtual void getWeightRegardingDPL(ComplexWeight *weight) = 0; virtual void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const = 0; virtual std::string getRepr() const = 0; + virtual void accept(PointVisitor *pv) = 0; virtual ~AbstractPoint(); public: static bool IsGatherB4Ext(Node *node); diff --git a/src/engine/BagPoint.cxx b/src/engine/BagPoint.cxx index 2492813df..c27ba4426 100644 --- a/src/engine/BagPoint.cxx +++ b/src/engine/BagPoint.cxx @@ -64,6 +64,16 @@ AbstractPoint *BagPoint::getUniqueAndReleaseIt() return ret; } +void BagPoint::accept(PointVisitor *pv) +{ + if(_nodes.size()!=1) + throw YACS::Exception("BagPoint::accept : simplification has failed !"); + AbstractPoint *ret(*_nodes.begin()); + if(!ret) + throw YACS::Exception("BagPoint::accept : Ooops !"); + ret->accept(pv); +} + Node *BagPoint::getFirstNode() { return getUnique()->getFirstNode(); diff --git a/src/engine/BagPoint.hxx b/src/engine/BagPoint.hxx index 9e97acd25..b45cece9b 100644 --- a/src/engine/BagPoint.hxx +++ b/src/engine/BagPoint.hxx @@ -41,6 +41,7 @@ namespace YACS void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; AbstractPoint *getUniqueAndReleaseIt(); + void accept(PointVisitor *pv) override; public: int size() const { return (int)_nodes.size(); } void replaceInMe(BlocPoint *aSet); diff --git a/src/engine/ElementaryPoint.cxx b/src/engine/ElementaryPoint.cxx index 7d161b9c2..72dd58c35 100644 --- a/src/engine/ElementaryPoint.cxx +++ b/src/engine/ElementaryPoint.cxx @@ -18,6 +18,7 @@ // #include "ElementaryPoint.hxx" +#include "PointVisitor.hxx" #include "Node.hxx" using namespace YACS::ENGINE; @@ -73,3 +74,9 @@ std::string ElementaryPoint::getRepr() const { return _node->getName(); } + +void ElementaryPoint::accept(PointVisitor *pv) +{ + pv->beginElementaryPoint(this); + pv->endElementaryPoint(this); +} diff --git a/src/engine/ElementaryPoint.hxx b/src/engine/ElementaryPoint.hxx index f5ac56538..559a92c99 100644 --- a/src/engine/ElementaryPoint.hxx +++ b/src/engine/ElementaryPoint.hxx @@ -46,6 +46,7 @@ namespace YACS void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; + void accept(PointVisitor *pv) override; virtual ~ElementaryPoint(); }; } diff --git a/src/engine/ForkBlocPoint.cxx b/src/engine/ForkBlocPoint.cxx index 8b8768f1c..5234cecf3 100644 --- a/src/engine/ForkBlocPoint.cxx +++ b/src/engine/ForkBlocPoint.cxx @@ -18,6 +18,7 @@ // #include "ForkBlocPoint.hxx" +#include "PointVisitor.hxx" #include "Exception.hxx" #include @@ -109,3 +110,11 @@ std::string ForkBlocPoint::getRepr() const ret+="]"; return ret; } + +void ForkBlocPoint::accept(PointVisitor *pv) +{ + pv->beginForkBlocPoint(this); + for(auto it:_nodes) + it->accept(pv); + pv->endForkBlocPoint(this); +} diff --git a/src/engine/ForkBlocPoint.hxx b/src/engine/ForkBlocPoint.hxx index 2c347caf2..067155d80 100644 --- a/src/engine/ForkBlocPoint.hxx +++ b/src/engine/ForkBlocPoint.hxx @@ -37,6 +37,7 @@ namespace YACS void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; + void accept(PointVisitor *pv) override; virtual ~ForkBlocPoint(); }; } diff --git a/src/engine/LinkedBlocPoint.cxx b/src/engine/LinkedBlocPoint.cxx index b4d2e7f2f..e9c32e8f5 100644 --- a/src/engine/LinkedBlocPoint.cxx +++ b/src/engine/LinkedBlocPoint.cxx @@ -18,6 +18,7 @@ // #include "LinkedBlocPoint.hxx" +#include "PointVisitor.hxx" #include "Exception.hxx" using namespace YACS::ENGINE; @@ -79,6 +80,14 @@ std::string LinkedBlocPoint::getRepr() const return ret; } +void LinkedBlocPoint::accept(PointVisitor *pv) +{ + pv->beginLinkedBlocPoint(this); + for(auto it:_nodes) + it->accept(pv); + pv->endLinkedBlocPoint(this); +} + LinkedBlocPoint::~LinkedBlocPoint() { } diff --git a/src/engine/LinkedBlocPoint.hxx b/src/engine/LinkedBlocPoint.hxx index 3491ed407..d0f5f20ac 100644 --- a/src/engine/LinkedBlocPoint.hxx +++ b/src/engine/LinkedBlocPoint.hxx @@ -39,6 +39,7 @@ namespace YACS void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; std::string getRepr() const; + void accept(PointVisitor *pv) override; virtual ~LinkedBlocPoint(); }; } diff --git a/src/engine/PointVisitor.hxx b/src/engine/PointVisitor.hxx new file mode 100644 index 000000000..9d9b17f7d --- /dev/null +++ b/src/engine/PointVisitor.hxx @@ -0,0 +1,43 @@ +// Copyright (C) 2015-2016 CEA/DEN, 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 +// + +#pragma once + +#include "YACSlibEngineExport.hxx" + +namespace YACS +{ + namespace ENGINE + { + class ElementaryPoint; + class LinkedBlocPoint; + class ForkBlocPoint; + + class YACSLIBENGINE_EXPORT PointVisitor + { + public: + virtual void beginForkBlocPoint(ForkBlocPoint *pt) = 0; + virtual void endForkBlocPoint(ForkBlocPoint *pt) = 0; + virtual void beginLinkedBlocPoint(LinkedBlocPoint *pt) = 0; + virtual void endLinkedBlocPoint(LinkedBlocPoint *pt) = 0; + virtual void beginElementaryPoint(ElementaryPoint *pt) = 0; + virtual void endElementaryPoint(ElementaryPoint *pt) = 0; + }; + } +} diff --git a/src/engine/SetOfPoints.cxx b/src/engine/SetOfPoints.cxx index 76f892577..f7b229088 100644 --- a/src/engine/SetOfPoints.cxx +++ b/src/engine/SetOfPoints.cxx @@ -101,3 +101,8 @@ AbstractPoint *SetOfPoints::getUniqueAndReleaseIt() const { return _bp->getUniqueAndReleaseIt(); } + +void SetOfPoints::accept(PointVisitor *pv) +{ + _bp->accept(pv); +} diff --git a/src/engine/SetOfPoints.hxx b/src/engine/SetOfPoints.hxx index bc29934b0..11e07eeef 100644 --- a/src/engine/SetOfPoints.hxx +++ b/src/engine/SetOfPoints.hxx @@ -22,6 +22,7 @@ #include "YACSlibEngineExport.hxx" #include "PlayGround.hxx" +#include "PointVisitor.hxx" #include "AutoRefCnt.hxx" #include @@ -50,6 +51,7 @@ namespace YACS void getWeightRegardingDPL(ComplexWeight *weight); void partitionRegardingDPL(const PartDefinition *pd, std::map >& zeMap) const; AbstractPoint *getUniqueAndReleaseIt() const; + void accept(PointVisitor *pv); private: BagPoint *_bp; }; diff --git a/src/engine_swig/pilot.i b/src/engine_swig/pilot.i index b89d32ab7..96c467d8c 100644 --- a/src/engine_swig/pilot.i +++ b/src/engine_swig/pilot.i @@ -60,6 +60,10 @@ #include "DataNode.hxx" #include "PlayGround.hxx" #include "SetOfPoints.hxx" +#include "PointVisitor.hxx" +#include "ForkBlocPoint.hxx" +#include "LinkedBlocPoint.hxx" +#include "ElementaryPoint.hxx" using namespace YACS::ENGINE; @@ -453,6 +457,48 @@ namespace YACS { namespace ENGINE { + class AbstractPoint + { + protected: + virtual ~AbstractPoint(); + AbstractPoint(); + AbstractPoint(const AbstractPoint&); + }; + + class ElementaryPoint : public AbstractPoint + { + public: + Node *getFirstNode(); + private: + ~ElementaryPoint(); + ElementaryPoint(); + ElementaryPoint(const ElementaryPoint&); + }; + + class BlocPoint : public AbstractPoint + { + protected: + ~BlocPoint(); + BlocPoint(); + BlocPoint(const BlocPoint&); + }; + + class LinkedBlocPoint : public BlocPoint + { + private: + ~LinkedBlocPoint(); + LinkedBlocPoint(); + LinkedBlocPoint(const LinkedBlocPoint&); + }; + + class ForkBlocPoint : public BlocPoint + { + private: + ~ForkBlocPoint(); + ForkBlocPoint(); + ForkBlocPoint(const ForkBlocPoint&); + }; + class SetOfPoints { public: @@ -460,6 +506,63 @@ namespace YACS ~SetOfPoints(); void simplify(); std::string getRepr() const; + %extend + { + void accept(PyObject *pv) + { + class MyPointVisitor : public YACS::ENGINE::PointVisitor + { + public: + MyPointVisitor(PyObject *py):_py(py) { } + void beginForkBlocPoint(ForkBlocPoint *pt) + { + PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0)); + PyObject *meth(PyString_FromString("beginForkBlocPoint")); + PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr)); + Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy); + } + void endForkBlocPoint(ForkBlocPoint *pt) + { + PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0)); + PyObject *meth(PyString_FromString("endForkBlocPoint")); + PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr)); + Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy); + } + void beginLinkedBlocPoint(LinkedBlocPoint *pt) + { + PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0)); + PyObject *meth(PyString_FromString("beginLinkedBlocPoint")); + PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr)); + Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy); + } + void endLinkedBlocPoint(LinkedBlocPoint *pt) + { + PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0)); + PyObject *meth(PyString_FromString("endLinkedBlocPoint")); + PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr)); + Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy); + } + void beginElementaryPoint(ElementaryPoint *pt) + { + PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0));//$descriptor(YACS::ENGINE::ElementaryPoint *) + PyObject *meth(PyString_FromString("beginElementaryPoint")); + PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr)); + Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy); + } + void endElementaryPoint(ElementaryPoint *pt) + { + PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0)); + PyObject *meth(PyString_FromString("endElementaryPoint")); + PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr)); + Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy); + } + private: + PyObject *_py; + }; + MyPointVisitor mpv(pv); + self->accept(&mpv); + } + } }; } } -- 2.39.2