Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
mydxfentities.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2010-2011,2014 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef MY_DXF_ENTITIES_HPP
44 #define MY_DXF_ENTITIES_HPP 1
45 
46 
47 #include <stdint.h>
48 #include <vector>
49 #include <cairo.h>
50 #include "mydxffile.hpp"
51 #include "vec3d.hpp"
52 #include "transformation.hpp"
53 
54 
55 #define MYDXF_PERT_EPS 1.1e-12
56 
57 
60 enum EntityType {
61  ENTITY_UNKNOWN = 0,
62  ENTITY_LINE,
63  ENTITY_LWPOLYLINE,
64  ENTITY_SPLINE,
65  ENTITY_ARC,
66  ENTITY_CIRCLE,
67  ENTITY_MTEXT,
68  ENTITY_INSERT
69 };
70 
71 
78 {
79 
80 protected:
81 
82  std::string _handle;
83  std::string _layer;
84 
85  MyDXFEntity();
86 
87  //MyDXFEntity( const MyDXFEntity &ent );
88 
94  static void bbox_ppoint( Vec3D &min, Vec3D &max, const Vec3D &p );
95 
96  void write_common( class MyDXFFile *dxf, std::ofstream &ostr );
97  void process_group( class MyDXFFile *dxf );
98  void constructor_debug_print( void ) const;
99  void debug_print_base( std::ostream &os ) const;
100 
101 public:
102 
105  virtual ~MyDXFEntity() {}
106 
109  virtual MyDXFEntity *copy( void ) const = 0;
110 
117  virtual void explode( class MyDXFEntities *ent, MyDXFFile *dxf, const Transformation *t ) const = 0;
118 
121  virtual void write( class MyDXFFile *dxf, std::ofstream &ostr ) = 0;
122 
125  virtual void scale( class MyDXFFile *dxf, double s ) = 0;
126 
129  virtual void translate( class MyDXFFile *dxf, const Vec3D &dx ) = 0;
130 
135  virtual void rotate_z( class MyDXFFile *dxf, double a ) = 0;
136 
139  void set_layer( const std::string &layer ) { _layer = layer; }
140 
143  std::string get_layer( void ) const { return( _layer ); }
144 
147  virtual EntityType get_type( void ) const = 0;
148 
151  void set_handle( const std::string &handle ) { _handle = handle; }
152 
155  std::string get_handle( void ) const { return( _handle ); }
156 
164  virtual void plot( const class MyDXFFile *dxf, cairo_t *cairo,
165  const Transformation *t, const double range[4] ) const = 0;
166 
169  virtual void get_bbox( Vec3D &min, Vec3D &max,
170  const class MyDXFFile *dxf, const Transformation *t ) const = 0;
171 
174  virtual void debug_print( std::ostream &os ) const = 0;
175 
176  friend std::ostream &operator<<( std::ostream &os, const MyDXFEntity &ent );
177 };
178 
179 
187 {
188 
189 protected:
190 
191  MyDXFPathEntity() {}
192 
193  MyDXFPathEntity( const MyDXFEntity &ent ) : MyDXFEntity(ent) {}
194 
195 public:
196 
199  virtual ~MyDXFPathEntity() {}
200 
203  virtual Vec3D start( void ) const = 0;
204 
207  virtual Vec3D end( void ) const = 0;
208 
211  virtual void set_start( const Vec3D &s ) = 0;
212 
215  virtual void set_end( const Vec3D &e ) = 0;
216 
225  virtual int ray_cross( double x, double y ) const = 0;
226 };
227 
228 
229 
230 
237 {
238 
239  std::vector<uint32_t> _selection;
240 
241 public:
242 
246 
250 
253  uint32_t size() const { return( _selection.size() ); }
254 
257  void add_entity( uint32_t a ) { _selection.push_back( a ); }
258 
261  const uint32_t &operator()( int a ) const {
262  if( a < 0 || a >= (int)_selection.size() )
263  throw( Error( ERROR_LOCATION, "index out of range" ) );
264  return( _selection[a] );
265  }
266 
269  uint32_t &operator()( int a ) {
270  if( a < 0 || a >= (int)_selection.size() )
271  throw( Error( ERROR_LOCATION, "index out of range" ) );
272  return( _selection[a] );
273  }
274 
275  friend std::ostream &operator<<( std::ostream &os, const MyDXFEntitySelection &sel );
276 };
277 
278 
286 {
287 
288  MyDXFFile *_dxf;
289  std::vector<MyDXFEntity *> _entities;
291 public:
292 
293 
296  MyDXFEntities( class MyDXFFile *dxf );
297 
300  MyDXFEntities( class MyDXFFile *dxf, MyDXFEntities *ent, MyDXFEntitySelection *sel );
301 
307  MyDXFEntities( class MyDXFFile *dxf, bool reading_blocks );
308 
311  ~MyDXFEntities();
312 
313 
316  void write( class MyDXFFile *dxf, std::ofstream &ostr );
317 
323  void write_entities( class MyDXFFile *dxf, std::ofstream &ostr );
324 
327  uint32_t size() const { return( _entities.size() ); }
328 
331  const MyDXFEntity *get_entity( uint32_t a ) const { return( _entities[a] ); }
332 
335  MyDXFEntity *get_entity( uint32_t a ) { return( _entities[a] ); }
336 
337 
338 
339 
344  void add_entity( MyDXFEntity *e ) { _entities.push_back( e ); }
345 
346 
349  MyDXFEntitySelection *selection_all( void ) const;
350 
353  MyDXFEntitySelection *selection_layer( const std::string &layername ) const;
354 
358 
368  double eps = 1.0e-6 );
369 
370 
371 
372 
373 
379  bool geom_same( uint32_t a, uint32_t b, double eps = 1.0e-6 ) const;
380 
381  /* ! \brief Check if point is inside a loop defined by a selection
382  * of entities.
383  *
384  * The check is done assuming a 2D drawing in xy-plane. The
385  * check is done using ray shooting algorithm. If exact crossing
386  * happens perturbation algorithm is used. New test is performed
387  * at eps distance from the first.
388  */
389  bool inside_loop( MyDXFEntitySelection *selection, double x, double y, double eps = 1.0e-6 );
390 
400  void plot( const MyDXFEntitySelection *selection, const class MyDXFFile *dxf,
401  cairo_t *cairo, const Transformation *t, const double range[4] ) const;
402 
405  void get_bbox( const MyDXFEntitySelection *selection, Vec3D &min, Vec3D &max,
406  const class MyDXFFile *dxf, const Transformation *t ) const;
407 
412  void scale( MyDXFEntitySelection *selection, class MyDXFFile *dxf, double s );
413 
416  void translate( MyDXFEntitySelection *selection, class MyDXFFile *dxf, const Vec3D &dx );
417 
422  void rotate_z( MyDXFEntitySelection *selection, double a );
423 
431  void remove( MyDXFEntitySelection *selection );
432 
433 
440  void explode( MyDXFEntitySelection *selection, class MyDXFFile *dxf );
441 
447  void explode( MyDXFEntities *ent, class MyDXFFile *dxf, const Transformation *t ) const;
448 
449 
452  void debug_print( std::ostream &os ) const;
453 
454 
455 };
456 
457 
458 
459 
460 
461 #endif
462 
463 
464 
465 
Basic error class.
Definition: error.hpp:153
DXF entity database.
Definition: mydxfentities.hpp:286
void write_entities(class MyDXFFile *dxf, std::ofstream &ostr)
Write a list of entities to stream.
Definition: mydxfentities.cpp:214
uint32_t size() const
Return number of entities.
Definition: mydxfentities.hpp:327
MyDXFEntitySelection * selection_layer(const std::string &layername) const
Make a new selection containg entities from named layer.
Definition: mydxfentities.cpp:275
void scale(MyDXFEntitySelection *selection, class MyDXFFile *dxf, double s)
Scale selected entities by factor s.
Definition: mydxfentities.cpp:681
void add_entity(MyDXFEntity *e)
Add entity to list.
Definition: mydxfentities.hpp:344
void explode(MyDXFEntitySelection *selection, class MyDXFFile *dxf)
Explode selected insert entities.
Definition: mydxfentities.cpp:754
MyDXFEntitySelection * selection_all(void) const
Make a new selection containg all entities from database.
Definition: mydxfentities.cpp:301
void write(class MyDXFFile *dxf, std::ofstream &ostr)
Write entities section of dxf file to stream.
Definition: mydxfentities.cpp:203
~MyDXFEntities()
Destructor.
Definition: mydxfentities.cpp:195
void get_bbox(const MyDXFEntitySelection *selection, Vec3D &min, Vec3D &max, const class MyDXFFile *dxf, const Transformation *t) const
Get bounding box containing all entities in selection.
Definition: mydxfentities.cpp:636
MyDXFEntitySelection * selection_path_loop(MyDXFEntitySelection *selection, double eps=1.0e-6)
Build complete loops.
Definition: mydxfentities.cpp:358
void translate(MyDXFEntitySelection *selection, class MyDXFFile *dxf, const Vec3D &dx)
Translate selected entities by dx.
Definition: mydxfentities.cpp:699
void remove(MyDXFEntitySelection *selection)
Remove selected entities.
Definition: mydxfentities.cpp:718
const MyDXFEntity * get_entity(uint32_t a) const
Return const pointer to entity a.
Definition: mydxfentities.hpp:331
MyDXFEntities(class MyDXFFile *dxf)
Construct empty entities database.
Definition: mydxfentities.cpp:128
MyDXFEntity * get_entity(uint32_t a)
Return pointer to entity a.
Definition: mydxfentities.hpp:335
void debug_print(std::ostream &os) const
Print debugging information to os.
Definition: mydxfentities.cpp:787
bool geom_same(uint32_t a, uint32_t b, double eps=1.0e-6) const
Check if two entities are geometrically same.
Definition: mydxfentities.cpp:328
void rotate_z(MyDXFEntitySelection *selection, double a)
Rotate selected entities around origin.
MyDXFEntitySelection * selection_type(EntityType type) const
Make a new selection containg entities of given type.
Definition: mydxfentities.cpp:288
void plot(const MyDXFEntitySelection *selection, const class MyDXFFile *dxf, cairo_t *cairo, const Transformation *t, const double range[4]) const
Plot selected entities with cairo.
Definition: mydxfentities.cpp:613
DXF entity selection.
Definition: mydxfentities.hpp:237
uint32_t size() const
Return number of entities in selection.
Definition: mydxfentities.hpp:253
~MyDXFEntitySelection()
Destructor.
Definition: mydxfentities.hpp:249
MyDXFEntitySelection()
Construct empty selection.
Definition: mydxfentities.hpp:245
const uint32_t & operator()(int a) const
Get a const reference to entity number in selection at location a.
Definition: mydxfentities.hpp:261
uint32_t & operator()(int a)
Get reference to entity number in selection at location a.
Definition: mydxfentities.hpp:269
void add_entity(uint32_t a)
Add entity number a in selection.
Definition: mydxfentities.hpp:257
DXF entity base class.
Definition: mydxfentities.hpp:78
std::string get_layer(void) const
Get layer.
Definition: mydxfentities.hpp:143
virtual void rotate_z(class MyDXFFile *dxf, double a)=0
Rotate entity around origin.
virtual MyDXFEntity * copy(void) const =0
Get a new copy of entity.
virtual void scale(class MyDXFFile *dxf, double s)=0
Scale entity by factor s.
static void bbox_ppoint(Vec3D &min, Vec3D &max, const Vec3D &p)
Propose a point to bounding box.
Definition: mydxfentities.cpp:80
virtual void translate(class MyDXFFile *dxf, const Vec3D &dx)=0
Translate entity by dx.
virtual ~MyDXFEntity()
Virtual destructor.
Definition: mydxfentities.hpp:105
virtual void get_bbox(Vec3D &min, Vec3D &max, const class MyDXFFile *dxf, const Transformation *t) const =0
Return bounding box of entity.
void set_handle(const std::string &handle)
Set entity handle.
Definition: mydxfentities.hpp:151
virtual void debug_print(std::ostream &os) const =0
Print debugging information to stream os.
void set_layer(const std::string &layer)
Set layer.
Definition: mydxfentities.hpp:139
virtual EntityType get_type(void) const =0
Get entity type.
std::string get_handle(void) const
Get entity handle.
Definition: mydxfentities.hpp:155
virtual void explode(class MyDXFEntities *ent, MyDXFFile *dxf, const Transformation *t) const =0
Explode into entities.
virtual void write(class MyDXFFile *dxf, std::ofstream &ostr)=0
Write dxf file to stream.
virtual void plot(const class MyDXFFile *dxf, cairo_t *cairo, const Transformation *t, const double range[4]) const =0
Plot entity with cairo.
DXF file class.
Definition: mydxffile.hpp:70
DXF path entity base class.
Definition: mydxfentities.hpp:187
virtual ~MyDXFPathEntity()
Virtual destructor.
Definition: mydxfentities.hpp:199
virtual Vec3D start(void) const =0
Get start point of path entity.
virtual Vec3D end(void) const =0
Get end point of path entity.
virtual void set_start(const Vec3D &s)=0
Set start point of path entity.
virtual int ray_cross(double x, double y) const =0
Check for ray crossing.
virtual void set_end(const Vec3D &e)=0
Set end point of path entity.
Transformation for homogenous three dimensional space.
Definition: transformation.hpp:70
Three dimensional vector.
Definition: vec3d.hpp:58
#define ERROR_LOCATION
Macro for setting error location when throwing errors.
Definition: error.hpp:83
EntityType
Entity type.
Definition: mydxfentities.hpp:60
DXF File.
Full transformation for three dimensional homogenous space.
Three dimensional vectors.


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.