/*************************************************************************** * Copyright (c) 2016 WandererFan * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ /* * Some material based on Boost sample code */ // Distributed under the Boost Software License, Version 1.0. (See // http://www.boost.org/LICENSE_1_0.txt) //************************************************************************** #ifndef TECHDRAW_EDGEWALKER_H #define TECHDRAW_EDGEWALKER_H #include #include #include #include #include #include #include #include #include #include namespace TechDraw { //using namespace boost; using graph = boost::adjacency_list < boost::vecS, boost::vecS, boost::bidirectionalS, boost::property, boost::property >; using vertex_t = boost::graph_traits < graph >::vertex_descriptor; using edge_t = boost::graph_traits < graph >::edge_descriptor; using planar_embedding_storage_t = std::vector< std::vector >; using planar_embedding_t = boost::iterator_property_map< planar_embedding_storage_t::iterator, boost::property_map::type >; class TechDrawExport WalkerEdge { public: static bool weCompare(WalkerEdge i, WalkerEdge j); bool isEqual(WalkerEdge w); std::string dump(); std::size_t v1; std::size_t v2; edge_t ed; std::size_t idx; }; class TechDrawExport ewWire { public: bool isEqual(ewWire w); std::vector wedges; //[WE] representing 1 wire void push_back(WalkerEdge w); void clear() {wedges.clear();} std::size_t size(void); }; class TechDrawExport ewWireList { public: ewWireList removeDuplicateWires(); std::vector wires; void push_back(ewWire e); std::size_t size(void); }; class TechDrawExport edgeVisitor : public boost::planar_face_traversal_visitor { public: template void next_edge(Edge e); void begin_face(); void end_face(); ewWireList getResult(); //a list of many wires void setGraph(graph& g); private: ewWire wireEdges; ewWireList graphWires; TechDraw::graph m_g; }; class TechDrawExport incidenceItem { public: incidenceItem() {iEdge = 0; angle = 0.0;} incidenceItem(std::size_t idx, double a, edge_t ed) {iEdge = idx; angle = a; eDesc = ed;} ~incidenceItem() = default; static bool iiCompare(const incidenceItem& i1, const incidenceItem& i2); static bool iiEqual(const incidenceItem& i1, const incidenceItem& i2); std::size_t iEdge; double angle; edge_t eDesc; }; class TechDrawExport embedItem { public: embedItem(); embedItem(std::size_t i, std::vector list) { iVertex = i; incidenceList = list;} ~embedItem() = default; std::size_t iVertex; std::vector incidenceList; std::string dump(); static std::vector sortIncidenceList (std::vector &list, bool ascend); }; class TechDrawExport EdgeWalker { public: EdgeWalker(); virtual ~EdgeWalker(); bool loadEdges(std::vector& edges); bool loadEdges(std::vector edges); bool setSize(std::size_t size); std::vector execute(std::vector edgeList, bool biggie = true); ewWireList getResult(); std::vector getResultWires(); std::vector getResultNoDups(); std::vector makeUniqueVList(std::vector edges); std::vector makeWalkerEdges(std::vector edges, std::vector verts); size_t findUniqueVert(TopoDS_Vertex vx, std::vector &uniqueVert); std::vector sortStrip(std::vector fw, bool includeBiggest); std::vector sortWiresBySize(std::vector& w, bool reverse = false); static TopoDS_Wire makeCleanWire(std::vector edges, double tol = 0.10); std::vector getEmbeddingRowIx(int v); std::vector getEmbeddingRow(int v); std::vector makeEmbedding(const std::vector edges, const std::vector uniqueVList); protected: bool prepare(); static bool wireCompare(const TopoDS_Wire& w1, const TopoDS_Wire& w2); std::vector m_saveWalkerEdges; std::vector m_saveInEdges; std::vector m_embedding; private: edgeVisitor m_eV; TechDraw::graph m_g; }; } //end namespace TechDraw #endif //TECHDRAW_EDGEWALKER_H