FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
topods_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "occtools.h"
19 
20 #include <BRep_Builder.hxx>
21 #include <Handle_ShapeExtend_WireData.hxx>
22 #include <TopAbs_ShapeEnum.hxx>
23 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Compound.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopoDS_Wire.hxx>
27 #include <gp_Vec.hxx>
28 
29 #include <string>
30 
31 namespace occ {
32 
34 {
35 public:
36  // Make facilities
37  template<typename FWD_ITERATOR>
38  static TopoDS_Compound makeCompoundFromShapeRange(
39  FWD_ITERATOR iBegin, FWD_ITERATOR iEnd);
40 
41  template<typename CONTAINER>
42  static TopoDS_Compound makeCompoundFromShapeContainer(CONTAINER cnter);
43 
44  template<typename FWD_ITERATOR>
45  static TopoDS_Wire makeWireFromEdgeRange(
46  FWD_ITERATOR iBegin, FWD_ITERATOR iEnd);
47 
48  // TopoDS_Shape <-> std::string
49  static std::string shapeToString(const TopoDS_Shape& shape);
50  static TopoDS_Shape shapeFromString(const std::string& str);
51 
52  // TopExp_Explorer facilities
53  template<typename FUNC>
54  static void forEach(
55  const TopoDS_Shape& shape, TopAbs_ShapeEnum shapeType, FUNC fn);
56 
57  template<typename FUNC>
58  static void forEach(TopExp_Explorer& explorer, FUNC fn);
59 
60  template<typename FUNC>
61  static void forEachVertex(const TopoDS_Shape& shape, FUNC fn);
62 
63  template<typename FUNC>
64  static void forEachEdge(const TopoDS_Shape& shape, FUNC fn);
65 
66  template<typename FUNC>
67  static void forEachWire(const TopoDS_Shape& shape, FUNC fn);
68 
69  template<typename FUNC>
70  static void forEachFace(const TopoDS_Shape& shape, FUNC fn);
71 
72  // Misc
73  static gp_Vec normalToFaceAtUV(
74  const TopoDS_Face& face, Standard_Real u, Standard_Real v);
75 
76 private:
77  static Handle_ShapeExtend_WireData createShapeExtendWireData();
78  static void addEdge(
79  const Handle_ShapeExtend_WireData& wireData,
80  const TopoDS_Edge& edge);
81  static TopoDS_Wire fixedWire(const Handle_ShapeExtend_WireData& wireData);
82 };
83 
84 
85 
86 // --
87 // -- Implementation
88 // --
89 
96 template<typename FWD_ITERATOR>
98  FWD_ITERATOR iBegin, FWD_ITERATOR iEnd)
99 {
100  TopoDS_Compound cmpd;
101  BRep_Builder builder;
102  builder.MakeCompound(cmpd);
103 
104  while (iBegin != iEnd) {
105  builder.Add(cmpd, *iBegin);
106  ++iBegin;
107  }
108 
109  return cmpd;
110 }
111 
113 template<typename CONTAINER>
114 TopoDS_Compound TopoDsUtils::makeCompoundFromShapeContainer(CONTAINER cnter)
115 {
116  return TopoDsUtils::makeCompoundFromShapeRange(cnter.begin(), cnter.end());
117 }
118 
125 template<typename FWD_ITERATOR>
127  FWD_ITERATOR iBegin, FWD_ITERATOR iEnd)
128 {
129  Handle_ShapeExtend_WireData wireData =
130  TopoDsUtils::createShapeExtendWireData();
131  while (iBegin != iEnd) {
132  TopoDsUtils::addEdge(wireData, *iBegin);
133  ++iBegin;
134  }
135  return TopoDsUtils::fixedWire(wireData);
136 }
137 
139 template<typename FUNC>
141  const TopoDS_Shape &shape, TopAbs_ShapeEnum shapeType, FUNC fn)
142 {
143  TopoDsUtils::forEach(TopExp_Explorer(shape, shapeType), std::move(fn));
144 }
145 
147 template<typename FUNC>
148 void TopoDsUtils::forEach(TopExp_Explorer &explorer, FUNC fn)
149 {
150  while (explorer.More()) {
151  fn(explorer.Current());
152  explorer.Next();
153  }
154 }
155 
156 template<typename FUNC>
157 void TopoDsUtils::forEachVertex(const TopoDS_Shape& shape, FUNC fn)
158 {
159  TopoDsUtils::forEach(shape, TopAbs_VERTEX, std::move(fn));
160 }
161 
162 template<typename FUNC>
163 void TopoDsUtils::forEachEdge(const TopoDS_Shape& shape, FUNC fn)
164 {
165  TopoDsUtils::forEach(shape, TopAbs_EDGE, std::move(fn));
166 }
167 
168 template<typename FUNC>
169 void TopoDsUtils::forEachWire(const TopoDS_Shape& shape, FUNC fn)
170 {
171  TopoDsUtils::forEach(shape, TopAbs_WIRE, std::move(fn));
172 }
173 
174 template<typename FUNC>
175 void TopoDsUtils::forEachFace(const TopoDS_Shape& shape, FUNC fn)
176 {
177  TopoDsUtils::forEach(shape, TopAbs_FACE, std::move(fn));
178 }
179 
180 } // namespace occ
static TopoDS_Compound makeCompoundFromShapeRange(FWD_ITERATOR iBegin, FWD_ITERATOR iEnd)
Definition: topods_utils.h:97
static void forEach(const TopoDS_Shape &shape, TopAbs_ShapeEnum shapeType, FUNC fn)
Definition: topods_utils.h:140
#define OCCTOOLS_EXPORT
Definition: occtools.h:27
static void forEachVertex(const TopoDS_Shape &shape, FUNC fn)
Definition: topods_utils.h:157
static void forEachWire(const TopoDS_Shape &shape, FUNC fn)
Definition: topods_utils.h:169
static void forEachEdge(const TopoDS_Shape &shape, FUNC fn)
Definition: topods_utils.h:163
static TopoDS_Wire makeWireFromEdgeRange(FWD_ITERATOR iBegin, FWD_ITERATOR iEnd)
Definition: topods_utils.h:126
Definition: ais_text.cpp:31
static void forEachFace(const TopoDS_Shape &shape, FUNC fn)
Definition: topods_utils.h:175
static TopoDS_Compound makeCompoundFromShapeContainer(CONTAINER cnter)
Same as occ::makeCompoundFromShapeRange(cnter.begin(), cnter.end())
Definition: topods_utils.h:114
Collection of tools for the TopoDS package.
Definition: topods_utils.h:33