/*************************************************************************** * 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 #include #include #include namespace TechDraw { //using namespace boost; typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, boost::property, boost::property > graph; typedef boost::graph_traits < graph >::vertex_descriptor vertex_t; typedef boost::graph_traits < graph >::edge_descriptor edge_t; typedef std::vector< std::vector > planar_embedding_storage_t; typedef boost::iterator_property_map< planar_embedding_storage_t::iterator, boost::property_map::type > planar_embedding_t; class WalkerEdge { public: static bool weCompare(WalkerEdge i, WalkerEdge j); bool isEqual(WalkerEdge w); std::string dump(void); std::size_t v1; std::size_t v2; edge_t ed; int idx; }; class ewWire { public: bool isEqual(ewWire w); std::vector wedges; //[WE] representing 1 wire void push_back(WalkerEdge w); void clear() {wedges.clear();}; int size(void); }; class ewWireList { public: ewWireList removeDuplicateWires(); std::vector wires; void push_back(ewWire e); int size(void); }; class edgeVisitor : public boost::planar_face_traversal_visitor { public: template void next_edge(Edge e); void begin_face(); void end_face(); ewWireList getResult(void); //a list of many wires void setGraph(graph& g); private: ewWire wireEdges; ewWireList graphWires; TechDraw::graph m_g; }; class incidenceItem { public: incidenceItem() {} incidenceItem(int idx, double a, edge_t ed) {iEdge = idx; angle = a; eDesc = ed;} ~incidenceItem() {} static bool iiCompare(const incidenceItem& i1, const incidenceItem& i2); static bool iiEqual(const incidenceItem& i1, const incidenceItem& i2); int iEdge; double angle; edge_t eDesc; }; class embedItem { public: embedItem(); embedItem(int i, std::vector list) { iVertex = i; incidenceList = list;} ~embedItem() {} int iVertex; std::vector incidenceList; std::string dump(void); static std::vector sortIncidenceList (std::vector &list, bool ascend); }; class EdgeWalker { public: EdgeWalker(void); virtual ~EdgeWalker(); bool loadEdges(std::vector& edges); bool loadEdges(std::vector edges); bool setSize(int size); bool perform(); ewWireList getResult(); std::vector getResultWires(); std::vector getResultNoDups(); std::vector makeUniqueVList(std::vector edges); std::vector makeWalkerEdges(std::vector edges, std::vector verts); int 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: 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