libsurf
Programmer's Documentation

igesentity.h (r6227/r5927)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_IGESENTITY_H
16 #define SURF_IGESENTITY_H
17 
18 #include "forward.h"
19 #include "igesdirentry.h"
20 #include <vector>
21 
33 {
34 public:
35 
36  enum IgesEntityClass { NoClass = 0,
37  PointClass = 1,
38  LineClass = 2,
39  CurveClass = 4,
40  SurfaceClass = 8,
41  StructureClass = 16,
42  AnyClass = 31};
43 
45  IgesEntity(int ety) : plcpre(-1), plcpost(-1) {
46  entry.etype = ety;
47  }
48 
50  virtual ~IgesEntity() {}
51 
53  int etype() const {return entry.etype;}
54 
56  int classOf() const {return IgesEntity::classOf(entry.etype);}
57 
59  void form(int f) {entry.form = f;}
60 
62  void blank(int b) {entry.blank = b;}
63 
65  void subswitch(int b) {entry.subswitch = b;}
66 
68  void useflag(int b) {entry.useflag = b;}
69 
71  void hierarchy(int b) {entry.hierarchy = b;}
72 
74  void trafoMatrix(int tfi) {entry.trafm = tfi;}
75 
77  int trafoMatrix() {return entry.trafm;}
78 
80  void label(const char *s);
81 
83  std::string label() const {return entry.label();}
84 
86  void subscript(int s) {entry.esubscript = s;}
87 
89  void addNoteRef(int ide) {addprop1.push_back(ide);}
90 
92  void addPropRef(int ide) {addprop2.push_back(ide);}
93 
95  uint pindex() const {return entry.pdata;}
96 
98  uint nNoteRef() const {return addprop1.size();}
99 
101  uint nPropRef() const {return addprop2.size();}
102 
104  int noteRef(uint k) const {assert(k<nNoteRef()); return addprop1[k];}
105 
107  int propRef(uint k) const {assert(k<nPropRef()); return addprop2[k];}
108 
110  int append(IgesFile & igfile);
111 
113  bool retrieve(const IgesFile & igfile);
114 
116  virtual void definition(IgesFile & file) = 0;
117 
119  virtual uint parse(const std::string & pds, const Indices & vpos);
120 
122  static IgesEntity *create(const IgesDirEntry & e);
123 
125  template <class EType>
126  static bool as(const IgesEntityPtr & ep, EType & t) {
127  const EType *et = dynamic_cast<const EType*>(ep.get());
128  if (et == 0)
129  return false;
130  else
131  t = *et;
132  return true;
133  }
134 
136  static int classOf(int etype) {
137  switch (etype) {
138  case 100:
139  case 102:
140  case 104:
141  return CurveClass;
142  case 108:
143  return SurfaceClass;
144  case 110:
145  return LineClass;
146  case 112:
147  return CurveClass;
148  case 114:
149  return SurfaceClass;
150  case 116:
151  return PointClass;
152  case 118:
153  case 120:
154  case 122:
155  return SurfaceClass;
156  case 124:
157  return StructureClass;
158  case 126:
159  return CurveClass;
160  case 128:
161  return SurfaceClass;
162  case 134:
163  return PointClass;
164  case 142:
165  return CurveClass;
166  case 144:
167  return SurfaceClass;
168  case 190:
169  case 192:
170  case 194:
171  case 196:
172  case 198:
173  return SurfaceClass;
174  case 308:
175  case 314:
176  case 402:
177  case 406:
178  case 408:
179  return StructureClass;
180  default:
181  return NoClass;
182  };
183  return NoClass;
184  }
185 
186 protected:
187 
189  static int asInt(const char *s, int k) {
190  char *tail;
191  int v = strtol(&s[k], &tail, 10);
192  assert(tail != &s[k]);
193  return v;
194  }
195 
197  static double asDouble(const char *s, int k) {
198  char *tail;
199  double v = strtod(&s[k], &tail);
200  if (tail != &s[k] and tail != 0 and *tail == 'D') { // catch Rhino's format: 3.141D0
201  long xp = strtol(tail+1, 0, 10);
202  v *= exp(2.30258509299405*xp);
203  }
204  return v;
205  }
206 
207 protected:
208 
211 
213  int plcpre, plcpost;
214 
216  std::vector<int> addprop1, addprop2;
217 };
218 
220 
221 // Entity 402, form 7, unordered group without back pointers.
222 
223 // */
224 //class IgesGroupAssoc : public IgesEntity
225 //{
226 //public:
227 
228 // /// create empty entry
229 // IgesGroupAssoc() : IgesEntity(402) { form(7); }
230 
231 // /// add pointer to DE of group member
232 // void addGroupMember(int ide) {mptr.push_back(ide);}
233 
234 // /// assemble definition
235 // void definition(IgesFile & igfile);
236 
237 //private:
238 
239 // /// directory entry pointers of the group members
240 // std::vector<int> mptr;
241 //};
242 
243 
244 
245 #endif
void subswitch(int b)
access status field: subordinate switch (0-3)
Definition: igesentity.h:65
static int asInt(const char *s, int k)
convenience conversion function
Definition: igesentity.h:189
int plcpre
line counts in parameter section
Definition: igesentity.h:213
std::string label() const
return label, if present
Definition: igesentity.h:83
std::vector< int > addprop1
additional properties (two groups)
Definition: igesentity.h:216
uint nPropRef() const
number of property references
Definition: igesentity.h:101
Base class for entities in IGES files.
Definition: igesentity.h:32
Data in each directory entry of an IGES file.
Definition: igesdirentry.h:31
IgesEntity(int ety)
create entity type etype
Definition: igesentity.h:45
void addNoteRef(int ide)
add reference to assoc/note DE
Definition: igesentity.h:89
bool retrieve(const IgesFile &igfile)
retrieve entity from file
Definition: igesentity.cpp:83
Main interface to IGES files.
Definition: igesfile.h:32
virtual void definition(IgesFile &file)=0
this function must be overloaded by entities
virtual uint parse(const std::string &pds, const Indices &vpos)
parse parameter data from string
Definition: igesentity.cpp:140
static double asDouble(const char *s, int k)
convenience conversion function
Definition: igesentity.h:197
int trafoMatrix()
access transformation matrix field
Definition: igesentity.h:77
int etype
integer directory entries
Definition: igesdirentry.h:58
int etype() const
entity type
Definition: igesentity.h:53
int append(IgesFile &igfile)
append entity to file
Definition: igesentity.cpp:44
int classOf() const
entity class identifier
Definition: igesentity.h:56
uint pindex() const
parameter data index
Definition: igesentity.h:95
static IgesEntity * create(const IgesDirEntry &e)
generate a new entity from code, return zero if not implemented
Definition: igesentity.cpp:146
void addPropRef(int ide)
add reference to property/attribute table DE
Definition: igesentity.h:92
void form(int f)
access the form field of the directory entry
Definition: igesentity.h:59
int noteRef(uint k) const
access note reference k
Definition: igesentity.h:104
static bool as(const IgesEntityPtr &ep, EType &t)
convenience function
Definition: igesentity.h:126
int propRef(uint k) const
access property reference k
Definition: igesentity.h:107
uint nNoteRef() const
number of notes
Definition: igesentity.h:98
std::string label() const
return label as std::string
Definition: igesdirentry.h:48
void useflag(int b)
access status field: use flag (0-6)
Definition: igesentity.h:68
void trafoMatrix(int tfi)
access transformation matrix field
Definition: igesentity.h:74
virtual ~IgesEntity()
destroy
Definition: igesentity.h:50
void hierarchy(int b)
access status field: hierachy flag (0-2)
Definition: igesentity.h:71
void blank(int b)
access status field: blank (0/1)
Definition: igesentity.h:62
static int classOf(int etype)
identity class of entity number
Definition: igesentity.h:136
void subscript(int s)
set entity subscript
Definition: igesentity.h:86
IgesDirEntry entry
directory entry
Definition: igesentity.h:210
Generated on Mon Jan 24 2022 03:03:16 for libsurf by   doxygen 1.8.5