Ejemplo n.º 1
0
void ExcellonProcessor::export_ngc(const string outputname, shared_ptr<Cutter> target, bool mirrored, bool mirror_absolute, bool onedrill) {

	g_assert(mirrored == true);
	g_assert(mirror_absolute == false);
	cerr << "Currently Drilling " << endl;

	// open output file
	std::ofstream of;
	of.open(outputname.c_str());

	shared_ptr<const map<int, drillbit> > bits = get_bits();
	shared_ptr<const map<int, icoords> > holes = get_holes();

	// write header to .ngc file
	BOOST_FOREACH (string s, header) {
		of << "( " << s << " )" << endl;
	}
	of << endl;

	//of << "( This file uses " << bits->size() << " drill bit sizes. )\n\n";
	of << "( This file uses a mill head of " << target->tool_diameter << " to drill the " << bits->size() << "bit sizes. )\n\n";

	of.setf(ios_base::fixed);
	of.precision(5);
	of << setw(7);

	// preamble
	of << preamble << "S" << left << target->speed << "  ( RPM spindle speed.           )\n" << endl;
	of << "F" << target->feed << endl;

	of << "#50=" << target->zwork * cfactor << " ; zwork" << endl;
	of << "#51=" << target->zsafe * cfactor << " ; zsafe" << endl;
	of << "#52=" << target->stepsize * cfactor << " ; stepsize" << endl;

	for (map<int, drillbit>::const_iterator it = bits->begin(); it != bits->end(); it++) {

		float diameter = it->second.diameter;
		//cerr<<"bit:"<<diameter<<endl;
		const icoords drill_coords = holes->at(it->first);
		icoords::const_iterator coord_iter = drill_coords.begin();

		millhole(of, board_width - coord_iter->first, coord_iter->second, target, diameter);
		++coord_iter;

		while (coord_iter != drill_coords.end()) {

			millhole(of, board_width - coord_iter->first, coord_iter->second, target, diameter);
			++coord_iter;
		}

	}

	// retract, end
	of << "G00 Z" << target->zchange * cfactor << " ( All done -- retract )\n" << endl;

	of.close();
}
Ejemplo n.º 2
0
void ExcellonProcessor::calc_dimensions(void) {

   x_min = +INFINITY;
   x_max = -INFINITY;

   shared_ptr<const map<int, drillbit> > bits = get_bits();
   shared_ptr<const map<int, icoords> > holes = get_holes();

   for (map<int, drillbit>::const_iterator it = bits->begin();
            it != bits->end(); it++) {
      const icoords drill_coords = holes->at(it->first);
      icoords::const_iterator coord_iter = drill_coords.begin();
      x_min = (coord_iter->first < x_min) ? coord_iter->first : x_min;
      x_max = (coord_iter->first > x_max) ? coord_iter->first : x_max;
      ++coord_iter;
      while (coord_iter != drill_coords.end()) {
         x_min = (coord_iter->first < x_min) ? coord_iter->first : x_min;
         x_max = (coord_iter->first > x_max) ? coord_iter->first : x_max;
         ++coord_iter;
      }
   }
   width = x_max - x_min;
   x_center = x_min + width / 2;
}
Ejemplo n.º 3
0
void ExcellonProcessor::export_ngc(const string outputname,
                                   shared_ptr<Cutter> target, bool drillfront,
                                   bool mirror_absolute, bool onedrill) {

   g_assert(drillfront == true);
   g_assert(mirror_absolute == false);
   cerr << "Currently Drilling " << "\n";

   // open output file
   std::ofstream of;
   of.open(outputname.c_str());

   shared_ptr<const map<int, drillbit> > bits = get_bits();
   shared_ptr<const map<int, icoords> > holes = get_holes();

   // write header to .ngc file
   BOOST_FOREACH (string s, header) {
      of << "( " << s << " )" << "\n";
   }
   of << "\n";

   of.setf(ios_base::fixed);      //write floating-point values in fixed-point notation
   of.precision(5);              //Set floating-point decimal precision
   of << setw(7);        //Sets the field width to be used on output operations.

   of << "( This file uses a mill head of " << (bMetricOutput ? (target->tool_diameter * 25.4) : target->tool_diameter)
      << (bMetricOutput ? "mm" : "inch") << " to drill the " << bits->size()
      << "bit sizes. )" << "\n";

   of << "( Bit sizes:";
   for (map<int, drillbit>::const_iterator it = bits->begin();
            it != bits->end(); it++) {
      of << " [" << it->second.diameter << "]";
   }
   of << " )\n\n";

   //preamble
   of << preamble_ext << preamble << "S" << left << target->speed
      << "    (RPM spindle speed.)\n" << "F" << target->feed * cfactor
      << " (Feedrate)\n\n";

   of << "#50=" << target->zwork * cfactor << "  (zwork)" << "\n";
   of << "#51=" << target->zsafe * cfactor << "  (zsafe)" << "\n";
   of << "#52=" << target->stepsize * cfactor << "  (stepsize)" << "\n\n";

   of << "G00 Z#51\n";

   for (map<int, drillbit>::const_iterator it = bits->begin();
            it != bits->end(); it++) {

      double diameter = it->second.diameter;

      const icoords drill_coords = holes->at(it->first);
      icoords::const_iterator coord_iter = drill_coords.begin();

      millhole(of, get_xvalue(!drillfront, mirror_absolute, coord_iter->first) - xoffset,
               coord_iter->second - yoffset, target, diameter);
      ++coord_iter;

      while (coord_iter != drill_coords.end()) {

         millhole(of, get_xvalue(!drillfront, mirror_absolute, coord_iter->first) - xoffset,
         	   coord_iter->second - yoffset, target, diameter);
         ++coord_iter;
      }
   }

   // retract, end
   of << "G00 Z" << target->zchange * cfactor << " ( All done -- retract )\n";
   of << postamble_ext;
   of << postamble << endl;
   of.close();
}
Ejemplo n.º 4
0
void ExcellonProcessor::export_ngc(const string of_name,
                                   shared_ptr<Driller> driller, bool drillfront,
                                   bool mirror_absolute, bool onedrill, bool nog81) {

   ivalue_t double_mirror_axis = mirror_absolute ? 0 : board_width;

   //SVG EXPORTER
   int rad = 1.;

   cout << "Exporting dill... ";

   //open output file
   std::ofstream of;
   of.open(of_name.c_str());

   shared_ptr<const map<int, drillbit> > bits = get_bits();
   shared_ptr<const map<int, icoords> > holes = get_holes();

   //write header to .ngc file
   BOOST_FOREACH (string s, header) {
      of << "( " << s << " )" << "\n";
   }

   if (!onedrill) {
      of << "\n( This file uses " << bits->size() << " drill bit sizes. )\n";
      of << "( Bit sizes:";
      for (map<int, drillbit>::const_iterator it = bits->begin();
               it != bits->end(); it++) {
         of << " [" << it->second.diameter << it->second.unit << "]";
      }
      of << " )\n\n";
   } else {
      of << "\n( This file uses only one drill bit. Forced by 'onedrill' option )\n\n";
   }

   of.setf(ios_base::fixed);      //write floating-point values in fixed-point notation
   of.precision(5);           //Set floating-point decimal precision
   of << setw(7);        //Sets the field width to be used on output operations.

   of << preamble_ext;        //insert external preamble file
   of << preamble;            //insert internal preamble
   of << "S" << left << driller->speed << "     (RPM spindle speed.)\n" << "\n";

   for (map<int, drillbit>::const_iterator it = bits->begin();
            it != bits->end(); it++) {
      //if the command line option "onedrill" is given, allow only the inital toolchange
      if ((onedrill == true) && (it != bits->begin())) {
         of << "(Drill change skipped. Forced by 'onedrill' option.)\n" << "\n";
      } else {
         of << "G00 Z" << driller->zchange * cfactor << " (Retract)\n" << "T"
            << it->first << "\n" << "M5      (Spindle stop.)\n"
            << "M6      (Tool change.)\n"
            << "(MSG, Change tool bit to drill size " << it->second.diameter
            << " " << it->second.unit << ")\n"
            << "M0      (Temporary machine stop.)\n"
            << "M3      (Spindle on clockwise.)\n" << "\n";
      }

      const icoords drill_coords = holes->at(it->first);
      icoords::const_iterator coord_iter = drill_coords.begin();
      //coord_iter->first = x-coorinate (top view)
      //coord_iter->second =y-coordinate (top view)

      //SVG EXPORTER
      if (bDoSVG) {
         svgexpo->set_rand_color();      //set a random color
         svgexpo->circle((double_mirror_axis - coord_iter->first),
                         coord_iter->second, rad);      //draw first circle
         svgexpo->stroke();
      }

	  if( nog81 )
		 of << "F" << driller->feed * cfactor << endl;
	  else {
		 of << "G81 R" << driller->zsafe * cfactor << " Z"
			 << driller->zwork * cfactor << " F" << driller->feed * cfactor << " X"
			 << ( get_xvalue(drillfront, mirror_absolute, coord_iter->first) - xoffset ) * cfactor
			 << " Y" << ( ( coord_iter->second - yoffset ) * cfactor) << "\n";
		 ++coord_iter;
	  }

      while (coord_iter != drill_coords.end()) {
         if( nog81 ) {
			 of << "G0 X"
				 << ( get_xvalue(drillfront, mirror_absolute, coord_iter->first) - xoffset ) * cfactor
				 << " Y" << ( ( coord_iter->second - yoffset ) * cfactor) << "\n";
			 of << "G1 Z" << driller->zwork * cfactor << endl;
			 of << "G1 Z" << driller->zsafe * cfactor << endl;
		 }
		 else {
			 of << "X"
				<< ( get_xvalue(drillfront, mirror_absolute, coord_iter->first) - xoffset )
				   * cfactor
				<< " Y" << ( ( coord_iter->second - yoffset ) * cfactor) << "\n";
		 }
         //SVG EXPORTER
         if (bDoSVG) {
            svgexpo->circle((double_mirror_axis - coord_iter->first),
                            coord_iter->second, rad);      //make a whole
            svgexpo->stroke();
         }
         ++coord_iter;
      }
      of << "\n";
   }

   of << "G00 Z" << driller->zchange * cfactor << " (All done -- retract)\n\n";
   of << postamble_ext;          //insert external postamble file
   of << postamble << endl;      //add internal postamble
   of.close();
   cout << "DONE." << endl;
}
Ejemplo n.º 5
0
void ExcellonProcessor::export_ngc(const string outputname, shared_ptr<Cutter> target)
{
    unsigned int badHoles = 0;
    double xoffsetTot;
    double yoffsetTot;
    stringstream zchange;

    //g_assert(drillfront == true);       //WHY?
    //g_assert(mirror_absolute == false); //WHY?
    cout << "Exporting drill... ";

    zchange << setprecision(3) << fixed << target->zchange * cfactor;
    tiling->setGCodeEnd( "G00 Z" + zchange.str() + " ( All done -- retract )\n" +
                         postamble_ext + "\nM5      (Spindle off.)\n"
                         "M9      (Coolant off.)\nM2      (Program end.)\n\n");

    // open output file
    std::ofstream of;
    of.open(outputname.c_str());

    shared_ptr<const map<int, drillbit> > bits = optimise_bits( get_bits(), false );
    shared_ptr<const map<int, icoords> > holes = optimise_path( get_holes(), false );

    // write header to .ngc file
    for (string s : header)
    {
        of << "( " << s << " )" << "\n";
    }

    if( tileInfo.enabled && tileInfo.software != CUSTOM )
        of << "( Gcode for " << getSoftwareString(tileInfo.software) << " )\n";
    else
        of << "( Software-independent Gcode )\n";

    of.setf(ios_base::fixed);      //write floating-point values in fixed-point notation
    of.precision(5);              //Set floating-point decimal precision

    of << "( This file uses a mill head of " << (bMetricOutput ? (target->tool_diameter * 25.4) : target->tool_diameter)
       << (bMetricOutput ? "mm" : "inch") << " to drill the " << bits->size()
       << " bit sizes. )" << "\n";

    of << "( Bit sizes:";
    for (map<int, drillbit>::const_iterator it = bits->begin();
            it != bits->end(); it++)
    {
        of << " [" << it->second.diameter << "]";
    }
    of << " )\n\n";

    //preamble
    of << preamble_ext << preamble << "S" << left << target->speed
       << "    (RPM spindle speed.)\n" << "F" << target->feed * cfactor
       << " (Feedrate)\nM3        (Spindle on clockwise.)\n"
       << "G00 Z" << target->zsafe * cfactor << "\n\n";

    tiling->header( of );

    for( unsigned int i = 0; i < tileInfo.forYNum; i++ )
    {
        yoffsetTot = yoffset - i * tileInfo.boardHeight;
        
        for( unsigned int j = 0; j < tileInfo.forXNum; j++ )
        {
            xoffsetTot = xoffset - ( i % 2 ? tileInfo.forXNum - j - 1 : j ) * tileInfo.boardWidth;

            if( tileInfo.enabled && tileInfo.software == CUSTOM )
                of << "( Piece #" << j + 1 + i * tileInfo.forXNum << ", position [" << j << ";" << i << "] )\n\n";

            for (map<int, drillbit>::const_iterator it = bits->begin();
                    it != bits->end(); it++)
            {

                double diameter = it->second.unit == "mm" ? it->second.diameter / 25.8 : it->second.diameter;

                const icoords drill_coords = holes->at(it->first);
                icoords::const_iterator coord_iter = drill_coords.begin();

                do
                {
                    if( !millhole(of, get_xvalue(coord_iter->first) - xoffsetTot,
                                  coord_iter->second - yoffsetTot, target, diameter) )
                        ++badHoles;

                    ++coord_iter;
                }
                while (coord_iter != drill_coords.end());
            }
        }
    }
    
    tiling->footer( of );

    of.close();

    if( badHoles != 0 )
    {
        badHoles /= tileInfo.tileX * tileInfo.tileY;    //Don't count the same bad hole multiple times
        cerr << "Warning: " << badHoles << ( badHoles == 1 ? " hole was" : " holes were" )
             << " bigger than the milling tool." << endl;
    }
}
Ejemplo n.º 6
0
void ExcellonProcessor::export_ngc(const string of_name, shared_ptr<Driller> driller, bool onedrill, bool nog81)
{
    ivalue_t double_mirror_axis = mirror_absolute ? 0 : board_width;
    double xoffsetTot;
    double yoffsetTot;
    stringstream zchange;

    //SVG EXPORTER
    int rad = 1.;

    cout << "Exporting drill... ";

    zchange << setprecision(3) << fixed << driller->zchange * cfactor;
    tiling->setGCodeEnd( "G00 Z" + zchange.str() + " ( All done -- retract )\n"
                         + postamble_ext + "\nM5      (Spindle off.)\n"
                         "M9      (Coolant off.)\nM2      (Program end.)\n\n");

    //open output file
    std::ofstream of;
    of.open(of_name.c_str());

    shared_ptr<const map<int, drillbit> > bits = optimise_bits( get_bits(), onedrill );
    shared_ptr<const map<int, icoords> > holes = optimise_path( get_holes(), onedrill );

    //write header to .ngc file
    for (string s : header)
    {
        of << "( " << s << " )" << "\n";
    }

    of << "( Software-independent Gcode )\n";

    if (!onedrill)
    {
        of << "\n( This file uses " << bits->size() << " drill bit sizes. )\n";
        of << "( Bit sizes:";
        for (map<int, drillbit>::const_iterator it = bits->begin();
                it != bits->end(); it++)
        {
            of << " [" << it->second.diameter << it->second.unit << "]";
        }
        of << " )\n\n";
    }
    else
    {
        of << "\n( This file uses only one drill bit. Forced by 'onedrill' option )\n\n";
    }

    of.setf(ios_base::fixed);      //write floating-point values in fixed-point notation
    of.precision(5);           //Set floating-point decimal precision

    of << preamble_ext;        //insert external preamble file
    of << preamble;            //insert internal preamble
    of << "S" << left << driller->speed << "     (RPM spindle speed.)\n" << "\n";

    //tiling->header( of );     // See TODO #2

    for (map<int, drillbit>::const_iterator it = bits->begin();
            it != bits->end(); it++)
    {
        //if the command line option "onedrill" is given, allow only the inital toolchange
        if ((onedrill == true) && (it != bits->begin()))
        {
            of << "(Drill change skipped. Forced by 'onedrill' option.)\n" << "\n";
        }
        else
        {
            of << "G00 Z" << driller->zchange * cfactor << " (Retract)\n" << "T"
               << it->first << "\n" << "M5      (Spindle stop.)\n"
               << "(MSG, Change tool bit to drill size " << it->second.diameter
               << " " << it->second.unit << ")\n"
               << "M6      (Tool change.)\n"
               << "M0      (Temporary machine stop.)\n"
               << "M3      (Spindle on clockwise.)\n" << "\n";
        }
        
        if( nog81 )
            of << "F" << driller->feed * cfactor << '\n';
        else
        {
            of << "G81 R" << driller->zsafe * cfactor << " Z"
               << driller->zwork * cfactor << " F" << driller->feed * cfactor << " ";
        }
        
        for( unsigned int i = 0; i < tileInfo.tileY; i++ )
        {
            yoffsetTot = yoffset - i * tileInfo.boardHeight;
            
            for( unsigned int j = 0; j < tileInfo.tileX; j++ )
            {
                xoffsetTot = xoffset - ( i % 2 ? tileInfo.tileX - j - 1 : j ) * tileInfo.boardWidth;

                const icoords drill_coords = holes->at(it->first);
                icoords::const_iterator coord_iter = drill_coords.begin();
                //coord_iter->first = x-coorinate (top view)
                //coord_iter->second =y-coordinate (top view)

                //SVG EXPORTER
                if (bDoSVG)
                {
                    svgexpo->set_rand_color();      //set a random color
                    svgexpo->circle((double_mirror_axis - coord_iter->first),
                                    coord_iter->second, rad);      //draw first circle
                    svgexpo->stroke();
                }

                while (coord_iter != drill_coords.end())
                {
                    if( nog81 )
                    {
                        of << "G0 X"
                           << ( get_xvalue(coord_iter->first) - xoffsetTot ) * cfactor
                           << " Y" << ( ( coord_iter->second - yoffsetTot ) * cfactor) << "\n";
                        of << "G1 Z" << driller->zwork * cfactor << '\n';
                        of << "G1 Z" << driller->zsafe * cfactor << '\n';
                    }
                    else
                    {
                        of << "X"
                           << ( get_xvalue(coord_iter->first) - xoffsetTot )
                           * cfactor
                           << " Y" << ( ( coord_iter->second - yoffsetTot ) * cfactor) << "\n";
                    }
                    //SVG EXPORTER
                    if (bDoSVG)
                    {
                        svgexpo->circle((double_mirror_axis - coord_iter->first),
                                        coord_iter->second, rad);      //make a whole
                        svgexpo->stroke();
                    }
                    ++coord_iter;
                }
            }
        }
        of << "\n";
    }
    
    //tiling->footer( of ); // See TODO #2
    of << tiling->getGCodeEnd();
    
    of.close();
}