Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Stuff
Thursday, February 28th, 2008 at 3:32:18am UTC 

  1. /* Copyright 2008 Chris Radek
  2.    License GPL2 */
  3.  
  4. #include "realize.h"
  5.  
  6. Realize::Realize() {
  7.     printf("g20g90\n");
  8. }
  9.  
  10. Realize::~Realize() {
  11.     printf("g0z%g\nm2\n", safety);
  12. }
  13.  
  14. #define SQ(a) ((a)*(a))
  15. #define hypot3(a,b,c) (sqrt(SQ(a)+SQ(b)+SQ(c)))
  16.  
  17. void Realize::addLayer(const DL_LayerData& d) {
  18.     printf(";layer %s flags 0x%02x\n", d.name.c_str(), d.flags);
  19. }
  20.  
  21.  
  22.  
  23. void Realize::addPolyline(const DL_PolylineData& d) {
  24.     printf(";start polyline vertices %d flags 0x%02x\n",
  25.            d.number, d.flags);
  26.  
  27.     // this makes a runtime error: *** glibc detected *** corrupted double-linked list: 0x08065038 *** Aborted
  28.     // closed = d.flags;
  29.  
  30.     down = 0;
  31.     // save close point
  32. }
  33.  
  34. void Realize::addVertex(const DL_VertexData& d) {
  35.     printf(";vertex %g,%g,%g bulge %g\n", d.x,d.y,d.z, d.bulge);
  36.     if(down)
  37.         cutto(d.x, d.y, d.bulge);
  38.     else
  39.         startcut(d.x, d.y, d.z);
  40.     down=1;
  41. }
  42.  
  43. void Realize::endEntity(void) {
  44.     printf(";end entity\n");
  45.     // handle close point
  46. }
  47.  
  48.  
  49.  
  50. void Realize::addArc(const DL_ArcData& d) {
  51.     printf(";arc center %g,%g,%g radius %g startangle %g endangle %g\n",
  52.            d.cx,d.cy,d.cz, d.radius, d.angle1, d.angle2);
  53. }
  54.  
  55. void Realize::addCircle(const DL_CircleData& d) {
  56.     double y = d.cy + d.radius;
  57.     printf(";circle center %g,%g,%g radius %g\n", d.cx,d.cy,d.cz, d.radius);
  58.    
  59.     printf("g0 z%g\ng0 x%g y%g\ng0 z%g\n", safety, d.cx, y, d.cz);
  60.     printf("g3 x%g y%g i0 j%g f%g\n", d.cx, y, d.radius, hfeed);
  61.     prev_x = d.cx;
  62.     prev_y = y;
  63. }
  64.  
  65. void Realize::addLine(const DL_LineData& d) {
  66.     //    double l = hypot3(d.x2-d.x1,d.y2-d.y1,d.z2-d.z1);
  67.     printf(";line %g,%g,%g to %g,%g,%g\n",
  68.            d.x1,d.y1,d.z1,
  69.            d.x2,d.y2,d.z2);
  70. }
  71.  
  72.  
  73. void Realize::addText(const DL_TextData& d) {
  74.     printf(";text \"%s\"\n", d.text.c_str());
  75. }
  76.  
  77.  
  78.  
  79. void Realize::toolchange(string layer, string description) {
  80.     printf("m5\ng0 z1\nt%s m6 ;%s\ns1000 m3\n", layer.c_str(), description.c_str());
  81. }
  82.  
  83. string Realize::getvalue(string layer, string key, string def) {
  84.     return "whatever";
  85. }
  86.  
  87. double Realize::getvalue(string layer, string key, double def) {
  88.     return 13.0;
  89. }
  90.  
  91. void Realize::startcut(double x, double y, double depth) {
  92.     printf("g0 z%g\n", safety);
  93.     printf("g0 x%g y%g\n", x, y);
  94.     printf("g1 z%g f%g\n", depth, vfeed);
  95. }
  96.  
  97. void Realize::cutto(double x, double y, double bulge) {
  98.     if(bulge) {
  99.         double cot = 0.5 * ((1.0 / bulge) - bulge);
  100.         double cx = ((prev_x + x) - (cot * (y - prev_y))) / 2.0;
  101.         double cy = ((prev_y + y) + (cot * (x - prev_x))) / 2.0;
  102.         //        double rad = hypot(cy - prev_y, cx - prev_y);
  103.         string arcdir = (bulge < 0.0) ? "g2" : "g3";
  104.         double i = cx - prev_x;
  105.         double j = cy - prev_y;
  106.        
  107.         printf("%s x%g y%g i%g j%g f%g\n", arcdir.c_str(), x, y, i, j, hfeed);
  108.     } else {
  109.         printf("g1 x%g y%g f%g\n", x, y, hfeed);
  110.     }
  111.     prev_x = x;
  112.     prev_y = y;
  113. }

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right