From 6bdbfba4e48e3568a955258e45eb54c92cc0b6ce Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 26 Jun 2014 11:37:29 +0000 Subject: [PATCH] Fix endlines: Source and header files should stick to DOS (CR/LF) --- contrib/MIDI to GCode/main.cpp | 778 ++++++++++++++++----------------- src/Drilling.h | 2 +- src/DrillingDlg.cpp | 2 +- src/HeeksCNCTypes.h | 12 +- src/Interface.cpp | 4 +- src/OpDlg.cpp | 12 +- src/Operations.cpp | 296 ++++++------- src/OutputCanvas.cpp | 26 +- src/Pattern.cpp | 70 +-- src/Pattern.h | 2 +- src/ProfileDlg.cpp | 2 +- src/Reselect.h | 88 ++-- src/ScriptOpDlg.cpp | 8 +- src/SolidsDlg.cpp | 4 +- src/Stock.h | 2 +- src/stdafx.h | 8 +- 16 files changed, 658 insertions(+), 658 deletions(-) diff --git a/contrib/MIDI to GCode/main.cpp b/contrib/MIDI to GCode/main.cpp index b24886cd..8e7ab148 100644 --- a/contrib/MIDI to GCode/main.cpp +++ b/contrib/MIDI to GCode/main.cpp @@ -1,389 +1,389 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "juce.h" - -using namespace std; - - -double dist(double a,double b) -{ - if (a < b) return(b-a); - else return(a-b); -} - -/** - This program was written so that a CNC machine could be used to - produce paper tapes for a music box such as http://kikkerland.com/S06/1200.htm - - These music boxes accept a paper tape with holes punched where notes - are to be played. - - This program accepts a MIDI filename as a command line argument - and generates a HeeksCAD file representing it. Lines and points - are placed for the various notes that make up the tune. - - Separate sets of lines/points are generated for each track within - the MIDI file. - - Text is overlayed if the MIDI file has words included (as a text track) - - The points placed in the HeeksCAD file can then be used as drilling locations - for the generation of a GCode program. - */ - -int main(int argc, char **argv) -{ - if (argc < 2) - { - printf("Usage %s file.mid\n", argv[0]); - return(-1); - } - - const char *l_pszFileName = argv[1]; - File file(l_pszFileName); - - const double mm_per_second = 1000.0 / 60.0; // How fast does the tape move through the music box? (1 meter per minute - by observation) - const double distance_between_notes_in_mm = 2.0; // across the paper. - const double min_distance_between_notes = 7.0; // Cannot have two consecutive notes appear less than this distance between each other. - - std::list gcode; - std::list heeks; - - int id=1; - - typedef std::vector Keys_t; - Keys_t keys, legal_keys; - Keys_t::size_type middle_c_key; - - // Which integer tells us it's the 'C' in the middle or the 'C' in the - // octave above or below. - const int middle_c_octave = 5; - - for (int octave=2; octave <= 8; octave++) - { - for (char key='A'; key<='G'; key++) - { - std::ostringstream l_ossKey; - - // l_ossKey << key << middle_c_octave - 0; - l_ossKey << key << octave; - keys.push_back( l_ossKey.str() ); - - if ((key == 'C') && (octave == middle_c_octave)) middle_c_key = keys.size()-1; - } - } - - // Setup our scale of notes that will work with the music box. It covers from 'C' to 'C' over two octaves. - // Octave below middle C - for (char key='C'; key<='G'; key++) - { - std::ostringstream l_ossKey; - - l_ossKey << key << middle_c_octave - 1; - legal_keys.push_back( l_ossKey.str() ); - } - - // Octave that includes middle C - for (char key='A'; key<='G'; key++) - { - std::ostringstream l_ossKey; - - l_ossKey << key << middle_c_octave - 0; - legal_keys.push_back( l_ossKey.str() ); - } - - // Octave above middle C - for (char key='A'; key<='C'; key++) - { - std::ostringstream l_ossKey; - - l_ossKey << key << middle_c_octave + 1; - legal_keys.push_back( l_ossKey.str() ); - } - - - const double track_width = distance_between_notes_in_mm * keys.size(); - const double space_between_tracks = track_width * 0.75; - - MidiFile midi_file; - FileInputStream midi_input_stream(file); - - if (! midi_file.readFrom( midi_input_stream )) - { - fprintf(stderr,"Could not open '%s' for reading\n", l_pszFileName); - return(-1); - } - - midi_file.convertTimestampTicksToSeconds(); - std::set notes; - - double time_scale = 1.0; - bool time_scale_changed = false; - - do { - std::map key_position; - time_scale_changed = false; - gcode.clear(); - heeks.clear(); - key_position.clear(); - - std::ostringstream l_ossGCode; - - for (int track = 0; trackgetStartTime(); - double end_time = pMessageSequence->getEndTime(); - double duration = end_time - start_time; - - if (duration <= 0.0001) continue; - - l_ossGCode.str(""); - l_ossGCode << "(Duration of track " << track << " is " << duration << " seconds)"; - gcode.push_back( l_ossGCode.str() ); - printf("%s\n", l_ossGCode.str().c_str()); - - // printf("Duration of track %d is %lf seconds\n", track, duration); - - for (int event = 0; event < pMessageSequence->getNumEvents(); event++) - { - MidiMessageSequence::MidiEventHolder *pEvent = pMessageSequence->getEventPointer(event); - MidiMessage message = pEvent->message; - double time_stamp = message.getTimeStamp(); - - if (message.isTextMetaEvent()) - { - String text = message.getTextFromTextMetaEvent(); - char buf[1024]; - memset( buf, '\0', sizeof(buf) ); - text.copyToBuffer( buf, sizeof(buf)-1 ); - // printf("Track %d is %s\n", track, buf ); - l_ossGCode.str(""); - l_ossGCode << "(Text track " << track << " is " << buf << ")"; - gcode.push_back(l_ossGCode.str()); - printf("%s\n", l_ossGCode.str().c_str()); - - std::ostringstream l_ossHeeks; - l_ossHeeks << ""; - heeks.push_back( l_ossHeeks.str() ); - } - - if (message.isTrackNameEvent()) - { - String text = message.getTextFromTextMetaEvent(); - char buf[1024]; - memset( buf, '\0', sizeof(buf) ); - text.copyToBuffer( buf, sizeof(buf)-1 ); - printf("Track %d is %s\n", track, buf ); - } - - if (message.isNoteOn()) - { - char note_name[256]; - memset( note_name, '\0', sizeof(note_name) ); - message.getMidiNoteName(message.getNoteNumber(), true, true, middle_c_octave).copyToBuffer( note_name, sizeof(note_name)-1 ); - - notes.insert( message.getNoteNumber() ); - - // printf("time %lf note %s\n", time_stamp, note_name ); - std::string l_ssNoteName(note_name); - std::string::size_type offset; - bool sharp_found = false; - while ((offset = l_ssNoteName.find("#")) != std::string::npos) - { - l_ssNoteName = l_ssNoteName.erase(offset,1); - sharp_found = true; - } - - strncpy( note_name, l_ssNoteName.c_str(), sizeof(note_name)-1 ); - - const int blue = 16711680; - const int black = 0; - const int red = 255; - - int colour = blue; - Keys_t::iterator l_itLegalKey = std::find( legal_keys.begin(), legal_keys.end(), note_name ); - if (l_itLegalKey == legal_keys.end()) - { - colour = red; - } - - // Find the note name in the keys we're interested in. - Keys_t::iterator l_itKey = std::find( keys.begin(), keys.end(), note_name ); - if (l_itKey != keys.end()) - { - double x = time_stamp * mm_per_second * time_scale; - double y = double(double(std::distance( keys.begin(), l_itKey )) - double(middle_c_key)) * distance_between_notes_in_mm; - - y += ((track_width + space_between_tracks) * track); - - if (sharp_found) - { - y += (distance_between_notes_in_mm / 2.0); - colour = red; - } - - // Check to see if we have two notes that are too close to each other for the mechanism to play them. - if (key_position.find(note_name) == key_position.end()) - { - key_position[note_name] = x; - } - - - // Measure the distance between this note and the previous equivalent note. If we need to expand our - // time scale to ensure consecutive notes are not too close together, do it now. - if ((dist(x, key_position[note_name]) < min_distance_between_notes) && (dist(x, key_position[note_name]) > 0.0)) - { - // Need to scale the whole piece up. - double increase_in_time_scale = double(double(min_distance_between_notes) / double(dist(x, key_position[note_name]))); - - if (increase_in_time_scale > 1.0) - { - time_scale = increase_in_time_scale * time_scale; - time_scale_changed = true; - } - } - - key_position[note_name] = x; - - // It's a key we have to play. Generate the GCode. - l_ossGCode.str(""); - l_ossGCode << "G83 X " << x << " Y " << y << "\t(" << note_name << ")"; - gcode.push_back( l_ossGCode.str() ); - - if (sharp_found) - { - std::ostringstream l_ossHeeks; - l_ossHeeks << "\n"; - l_ossHeeks << " \n"; - l_ossHeeks << "\n"; - heeks.push_back( l_ossHeeks.str() ); - } - else - { - std::ostringstream l_ossHeeks; - l_ossHeeks << ""; - heeks.push_back( l_ossHeeks.str() ); - } - - // printf("G83 Want hole for key %s at %lf,%lf\n", note_name, x, y ); - number_of_notes_included++; - } - else - { - // This key doesn't fall exactly on our scale. Ignore it. - number_of_notes_ignored++; - printf("Missed note %s\n", note_name); - } - } // End if - then - } // End for - - - l_ossGCode.str(""); - l_ossGCode << "(" << (double(number_of_notes_included)/double(number_of_notes_included + number_of_notes_ignored)) * 100.0 - << " % utilisation of notes)"; - gcode.push_back(l_ossGCode.str()); - printf("%s\n", l_ossGCode.str().c_str()); - - l_ossGCode.str(""); - l_ossGCode << "(Of the " << (number_of_notes_included + number_of_notes_ignored) << " notes, we are using " - << number_of_notes_included << " (whole notes) and ignoring " << number_of_notes_ignored << " (sharps and flats))"; - gcode.push_back(l_ossGCode.str()); - printf("%s\n", l_ossGCode.str().c_str()); - - printf("At %lf mm per second (%lf mm per minute), we will need %lf mm of paper for this tune\n", - mm_per_second, mm_per_second * 60.0 * time_scale, (end_time - start_time) * mm_per_second * time_scale ); - - printf("We have had to scale the tune %lf times to ensure no two consecutive notes were less than %lf mm apart\n", - time_scale, min_distance_between_notes); - - // Draw a line for each possible note. - for (Keys_t::iterator l_itKey = keys.begin(); l_itKey != keys.end(); l_itKey++) - { - double y = double(double(std::distance( keys.begin(), l_itKey )) - double(middle_c_key)) * distance_between_notes_in_mm; - - y += ((track_width + space_between_tracks) * track); - - if (std::find(legal_keys.begin(), legal_keys.end(), *l_itKey) != legal_keys.end()) - { - std::ostringstream l_ossHeeks; - l_ossHeeks.str(""); - l_ossHeeks << "\n"; - l_ossHeeks << "\n"; - l_ossHeeks << "\n"; - l_ossHeeks << "\n"; - l_ossHeeks << "\n"; - l_ossHeeks << "\n"; - heeks.push_back(l_ossHeeks.str()); - } - } // End for - } - } while (time_scale_changed == true); - -/* - for (std::set::const_iterator l_itNote = notes.begin(); l_itNote != notes.end(); l_itNote++) - { - char note_name[256]; - memset( note_name, '\0', sizeof(note_name) ); - MidiMessage::getMidiNoteName(*l_itNote, true, true, 5).copyToBuffer( note_name, sizeof(note_name)-1 ); - - printf("Note %d %s\n", *l_itNote, note_name); - } -*/ - - { - String gcode_file_name(l_pszFileName); - gcode_file_name = gcode_file_name.dropLastCharacters(4); - gcode_file_name << ".ngc"; - char buf[1024]; - memset( buf, '\0', sizeof(buf) ); - gcode_file_name.copyToBuffer(buf,sizeof(buf)-1); - FILE *fp = fopen( buf, "w+t"); - if (fp == NULL) - { - fprintf(stderr,"Could not open %s for writing\n", buf); - return(-1); - } - for (std::list::const_iterator l_itLine = gcode.begin(); l_itLine != gcode.end(); l_itLine++) - { - fprintf(fp,"%s\n", l_itLine->c_str()); - } - fclose(fp); - } - - { - String gcode_file_name(l_pszFileName); - gcode_file_name = gcode_file_name.dropLastCharacters(4); - gcode_file_name << ".heeks"; - char buf[1024]; - memset( buf, '\0', sizeof(buf) ); - gcode_file_name.copyToBuffer(buf,sizeof(buf)-1); - FILE *fp = fopen( buf, "w+t"); - if (fp == NULL) - { - fprintf(stderr,"Could not open %s for writing\n", buf); - return(-1); - } - for (std::list::const_iterator l_itLine = heeks.begin(); l_itLine != heeks.end(); l_itLine++) - { - fprintf(fp,"%s\n", l_itLine->c_str()); - } - - fclose(fp); - } - - - return 0; -} - +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "juce.h" + +using namespace std; + + +double dist(double a,double b) +{ + if (a < b) return(b-a); + else return(a-b); +} + +/** + This program was written so that a CNC machine could be used to + produce paper tapes for a music box such as http://kikkerland.com/S06/1200.htm + + These music boxes accept a paper tape with holes punched where notes + are to be played. + + This program accepts a MIDI filename as a command line argument + and generates a HeeksCAD file representing it. Lines and points + are placed for the various notes that make up the tune. + + Separate sets of lines/points are generated for each track within + the MIDI file. + + Text is overlayed if the MIDI file has words included (as a text track) + + The points placed in the HeeksCAD file can then be used as drilling locations + for the generation of a GCode program. + */ + +int main(int argc, char **argv) +{ + if (argc < 2) + { + printf("Usage %s file.mid\n", argv[0]); + return(-1); + } + + const char *l_pszFileName = argv[1]; + File file(l_pszFileName); + + const double mm_per_second = 1000.0 / 60.0; // How fast does the tape move through the music box? (1 meter per minute - by observation) + const double distance_between_notes_in_mm = 2.0; // across the paper. + const double min_distance_between_notes = 7.0; // Cannot have two consecutive notes appear less than this distance between each other. + + std::list gcode; + std::list heeks; + + int id=1; + + typedef std::vector Keys_t; + Keys_t keys, legal_keys; + Keys_t::size_type middle_c_key; + + // Which integer tells us it's the 'C' in the middle or the 'C' in the + // octave above or below. + const int middle_c_octave = 5; + + for (int octave=2; octave <= 8; octave++) + { + for (char key='A'; key<='G'; key++) + { + std::ostringstream l_ossKey; + + // l_ossKey << key << middle_c_octave - 0; + l_ossKey << key << octave; + keys.push_back( l_ossKey.str() ); + + if ((key == 'C') && (octave == middle_c_octave)) middle_c_key = keys.size()-1; + } + } + + // Setup our scale of notes that will work with the music box. It covers from 'C' to 'C' over two octaves. + // Octave below middle C + for (char key='C'; key<='G'; key++) + { + std::ostringstream l_ossKey; + + l_ossKey << key << middle_c_octave - 1; + legal_keys.push_back( l_ossKey.str() ); + } + + // Octave that includes middle C + for (char key='A'; key<='G'; key++) + { + std::ostringstream l_ossKey; + + l_ossKey << key << middle_c_octave - 0; + legal_keys.push_back( l_ossKey.str() ); + } + + // Octave above middle C + for (char key='A'; key<='C'; key++) + { + std::ostringstream l_ossKey; + + l_ossKey << key << middle_c_octave + 1; + legal_keys.push_back( l_ossKey.str() ); + } + + + const double track_width = distance_between_notes_in_mm * keys.size(); + const double space_between_tracks = track_width * 0.75; + + MidiFile midi_file; + FileInputStream midi_input_stream(file); + + if (! midi_file.readFrom( midi_input_stream )) + { + fprintf(stderr,"Could not open '%s' for reading\n", l_pszFileName); + return(-1); + } + + midi_file.convertTimestampTicksToSeconds(); + std::set notes; + + double time_scale = 1.0; + bool time_scale_changed = false; + + do { + std::map key_position; + time_scale_changed = false; + gcode.clear(); + heeks.clear(); + key_position.clear(); + + std::ostringstream l_ossGCode; + + for (int track = 0; trackgetStartTime(); + double end_time = pMessageSequence->getEndTime(); + double duration = end_time - start_time; + + if (duration <= 0.0001) continue; + + l_ossGCode.str(""); + l_ossGCode << "(Duration of track " << track << " is " << duration << " seconds)"; + gcode.push_back( l_ossGCode.str() ); + printf("%s\n", l_ossGCode.str().c_str()); + + // printf("Duration of track %d is %lf seconds\n", track, duration); + + for (int event = 0; event < pMessageSequence->getNumEvents(); event++) + { + MidiMessageSequence::MidiEventHolder *pEvent = pMessageSequence->getEventPointer(event); + MidiMessage message = pEvent->message; + double time_stamp = message.getTimeStamp(); + + if (message.isTextMetaEvent()) + { + String text = message.getTextFromTextMetaEvent(); + char buf[1024]; + memset( buf, '\0', sizeof(buf) ); + text.copyToBuffer( buf, sizeof(buf)-1 ); + // printf("Track %d is %s\n", track, buf ); + l_ossGCode.str(""); + l_ossGCode << "(Text track " << track << " is " << buf << ")"; + gcode.push_back(l_ossGCode.str()); + printf("%s\n", l_ossGCode.str().c_str()); + + std::ostringstream l_ossHeeks; + l_ossHeeks << ""; + heeks.push_back( l_ossHeeks.str() ); + } + + if (message.isTrackNameEvent()) + { + String text = message.getTextFromTextMetaEvent(); + char buf[1024]; + memset( buf, '\0', sizeof(buf) ); + text.copyToBuffer( buf, sizeof(buf)-1 ); + printf("Track %d is %s\n", track, buf ); + } + + if (message.isNoteOn()) + { + char note_name[256]; + memset( note_name, '\0', sizeof(note_name) ); + message.getMidiNoteName(message.getNoteNumber(), true, true, middle_c_octave).copyToBuffer( note_name, sizeof(note_name)-1 ); + + notes.insert( message.getNoteNumber() ); + + // printf("time %lf note %s\n", time_stamp, note_name ); + std::string l_ssNoteName(note_name); + std::string::size_type offset; + bool sharp_found = false; + while ((offset = l_ssNoteName.find("#")) != std::string::npos) + { + l_ssNoteName = l_ssNoteName.erase(offset,1); + sharp_found = true; + } + + strncpy( note_name, l_ssNoteName.c_str(), sizeof(note_name)-1 ); + + const int blue = 16711680; + const int black = 0; + const int red = 255; + + int colour = blue; + Keys_t::iterator l_itLegalKey = std::find( legal_keys.begin(), legal_keys.end(), note_name ); + if (l_itLegalKey == legal_keys.end()) + { + colour = red; + } + + // Find the note name in the keys we're interested in. + Keys_t::iterator l_itKey = std::find( keys.begin(), keys.end(), note_name ); + if (l_itKey != keys.end()) + { + double x = time_stamp * mm_per_second * time_scale; + double y = double(double(std::distance( keys.begin(), l_itKey )) - double(middle_c_key)) * distance_between_notes_in_mm; + + y += ((track_width + space_between_tracks) * track); + + if (sharp_found) + { + y += (distance_between_notes_in_mm / 2.0); + colour = red; + } + + // Check to see if we have two notes that are too close to each other for the mechanism to play them. + if (key_position.find(note_name) == key_position.end()) + { + key_position[note_name] = x; + } + + + // Measure the distance between this note and the previous equivalent note. If we need to expand our + // time scale to ensure consecutive notes are not too close together, do it now. + if ((dist(x, key_position[note_name]) < min_distance_between_notes) && (dist(x, key_position[note_name]) > 0.0)) + { + // Need to scale the whole piece up. + double increase_in_time_scale = double(double(min_distance_between_notes) / double(dist(x, key_position[note_name]))); + + if (increase_in_time_scale > 1.0) + { + time_scale = increase_in_time_scale * time_scale; + time_scale_changed = true; + } + } + + key_position[note_name] = x; + + // It's a key we have to play. Generate the GCode. + l_ossGCode.str(""); + l_ossGCode << "G83 X " << x << " Y " << y << "\t(" << note_name << ")"; + gcode.push_back( l_ossGCode.str() ); + + if (sharp_found) + { + std::ostringstream l_ossHeeks; + l_ossHeeks << "\n"; + l_ossHeeks << " \n"; + l_ossHeeks << "\n"; + heeks.push_back( l_ossHeeks.str() ); + } + else + { + std::ostringstream l_ossHeeks; + l_ossHeeks << ""; + heeks.push_back( l_ossHeeks.str() ); + } + + // printf("G83 Want hole for key %s at %lf,%lf\n", note_name, x, y ); + number_of_notes_included++; + } + else + { + // This key doesn't fall exactly on our scale. Ignore it. + number_of_notes_ignored++; + printf("Missed note %s\n", note_name); + } + } // End if - then + } // End for + + + l_ossGCode.str(""); + l_ossGCode << "(" << (double(number_of_notes_included)/double(number_of_notes_included + number_of_notes_ignored)) * 100.0 + << " % utilisation of notes)"; + gcode.push_back(l_ossGCode.str()); + printf("%s\n", l_ossGCode.str().c_str()); + + l_ossGCode.str(""); + l_ossGCode << "(Of the " << (number_of_notes_included + number_of_notes_ignored) << " notes, we are using " + << number_of_notes_included << " (whole notes) and ignoring " << number_of_notes_ignored << " (sharps and flats))"; + gcode.push_back(l_ossGCode.str()); + printf("%s\n", l_ossGCode.str().c_str()); + + printf("At %lf mm per second (%lf mm per minute), we will need %lf mm of paper for this tune\n", + mm_per_second, mm_per_second * 60.0 * time_scale, (end_time - start_time) * mm_per_second * time_scale ); + + printf("We have had to scale the tune %lf times to ensure no two consecutive notes were less than %lf mm apart\n", + time_scale, min_distance_between_notes); + + // Draw a line for each possible note. + for (Keys_t::iterator l_itKey = keys.begin(); l_itKey != keys.end(); l_itKey++) + { + double y = double(double(std::distance( keys.begin(), l_itKey )) - double(middle_c_key)) * distance_between_notes_in_mm; + + y += ((track_width + space_between_tracks) * track); + + if (std::find(legal_keys.begin(), legal_keys.end(), *l_itKey) != legal_keys.end()) + { + std::ostringstream l_ossHeeks; + l_ossHeeks.str(""); + l_ossHeeks << "\n"; + l_ossHeeks << "\n"; + l_ossHeeks << "\n"; + l_ossHeeks << "\n"; + l_ossHeeks << "\n"; + l_ossHeeks << "\n"; + heeks.push_back(l_ossHeeks.str()); + } + } // End for + } + } while (time_scale_changed == true); + +/* + for (std::set::const_iterator l_itNote = notes.begin(); l_itNote != notes.end(); l_itNote++) + { + char note_name[256]; + memset( note_name, '\0', sizeof(note_name) ); + MidiMessage::getMidiNoteName(*l_itNote, true, true, 5).copyToBuffer( note_name, sizeof(note_name)-1 ); + + printf("Note %d %s\n", *l_itNote, note_name); + } +*/ + + { + String gcode_file_name(l_pszFileName); + gcode_file_name = gcode_file_name.dropLastCharacters(4); + gcode_file_name << ".ngc"; + char buf[1024]; + memset( buf, '\0', sizeof(buf) ); + gcode_file_name.copyToBuffer(buf,sizeof(buf)-1); + FILE *fp = fopen( buf, "w+t"); + if (fp == NULL) + { + fprintf(stderr,"Could not open %s for writing\n", buf); + return(-1); + } + for (std::list::const_iterator l_itLine = gcode.begin(); l_itLine != gcode.end(); l_itLine++) + { + fprintf(fp,"%s\n", l_itLine->c_str()); + } + fclose(fp); + } + + { + String gcode_file_name(l_pszFileName); + gcode_file_name = gcode_file_name.dropLastCharacters(4); + gcode_file_name << ".heeks"; + char buf[1024]; + memset( buf, '\0', sizeof(buf) ); + gcode_file_name.copyToBuffer(buf,sizeof(buf)-1); + FILE *fp = fopen( buf, "w+t"); + if (fp == NULL) + { + fprintf(stderr,"Could not open %s for writing\n", buf); + return(-1); + } + for (std::list::const_iterator l_itLine = heeks.begin(); l_itLine != heeks.end(); l_itLine++) + { + fprintf(fp,"%s\n", l_itLine->c_str()); + } + + fclose(fp); + } + + + return 0; +} + diff --git a/src/Drilling.h b/src/Drilling.h index cf09e34a..fe35e0df 100755 --- a/src/Drilling.h +++ b/src/Drilling.h @@ -71,7 +71,7 @@ class CDrilling: public CDepthOp { bool CanAddTo(HeeksObj* owner); bool CanAdd(HeeksObj* object); void GetTools(std::list* t_list, const wxPoint* p); - void GetOnEdit(bool(**callback)(HeeksObj*)); + void GetOnEdit(bool(**callback)(HeeksObj*)); // This is the method that gets called when the operator hits the 'Python' button. It generates a Python // program whose job is to generate RS-274 GCode. diff --git a/src/DrillingDlg.cpp b/src/DrillingDlg.cpp index d3635f2f..79501064 100644 --- a/src/DrillingDlg.cpp +++ b/src/DrillingDlg.cpp @@ -7,7 +7,7 @@ #include "interface/PictureFrame.h" #include "interface/NiceTextCtrl.h" #include "Drilling.h" -#include "CTool.h" +#include "CTool.h" enum { diff --git a/src/HeeksCNCTypes.h b/src/HeeksCNCTypes.h index fe3d6fb9..c47a1d95 100644 --- a/src/HeeksCNCTypes.h +++ b/src/HeeksCNCTypes.h @@ -18,11 +18,11 @@ enum{ TagsType, TagType, ScriptOpType, - PatternType, - PatternsType, - SurfaceType, - SurfacesType, - StockType, - StocksType, + PatternType, + PatternsType, + SurfaceType, + SurfacesType, + StockType, + StocksType, HeeksCNCMaximumType }; diff --git a/src/Interface.cpp b/src/Interface.cpp index 68d99e14..a97c14ba 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -1,6 +1,6 @@ // defines all the exported functions for HeeksCAD -// Copyright (c) 2009, Dan Heeks -// This program is released under the BSD license. See the file COPYING for details. +// Copyright (c) 2009, Dan Heeks +// This program is released under the BSD license. See the file COPYING for details. #include "stdafx.h" #include "Interface.h" diff --git a/src/OpDlg.cpp b/src/OpDlg.cpp index 97d30d3d..23cabe93 100644 --- a/src/OpDlg.cpp +++ b/src/OpDlg.cpp @@ -7,12 +7,12 @@ #include "interface/PictureFrame.h" #include "interface/NiceTextCtrl.h" #include "Profile.h" -#include "CTool.h" -#include "Program.h" -#include "Tools.h" -#include "Patterns.h" -#include "Surfaces.h" -#include "PatternDlg.h" +#include "CTool.h" +#include "Program.h" +#include "Tools.h" +#include "Patterns.h" +#include "Surfaces.h" +#include "PatternDlg.h" BEGIN_EVENT_TABLE(OpDlg, HeeksObjDlg) EVT_COMBOBOX(ID_TOOL,HeeksObjDlg::OnComboOrCheck) diff --git a/src/Operations.cpp b/src/Operations.cpp index bb38de52..f91a2c6a 100644 --- a/src/Operations.cpp +++ b/src/Operations.cpp @@ -1,148 +1,148 @@ -// Operations.cpp -// Copyright (c) 2009, Dan Heeks -// This program is released under the BSD license. See the file COPYING for details. - -#include "stdafx.h" -#include "Operations.h" -#include "Op.h" -#include "interface/Tool.h" -#include "tinyxml/tinyxml.h" -#include "Excellon.h" - -#include - -bool COperations::CanAdd(HeeksObj* object) -{ - return ((object != NULL) && (IsAnOperation(object->GetType()))); -} - -COperations & COperations::operator= ( const COperations & rhs ) -{ - if (this != &rhs) - { - ObjList::operator=( rhs ); - } - - return(*this); -} - -COperations::COperations( const COperations & rhs ) : ObjList(rhs) -{ -} - -const wxBitmap &COperations::GetIcon() -{ - static wxBitmap* icon = NULL; - if(icon == NULL)icon = new wxBitmap(wxImage(theApp.GetResFolder() + _T("/icons/operations.png"))); - return *icon; -} - -/** - This is ALMOST the same as the assignment operator. The difference is that - this method augments its local list of operations with those passed in rather - than replacing them. - */ -void COperations::CopyFrom(const HeeksObj *object) -{ - if (object->GetType() == GetType()) - { - COperations *rhs = (COperations*)object; - for (HeeksObj *child = rhs->GetFirstChild(); child != NULL; child = rhs->GetNextChild()) - { - child->SetID( heeksCAD->GetNextID(child->GetType()) ); - Add(child, NULL); - } // End for - } -} - -void COperations::ReloadPointers() -{ - ObjList::ReloadPointers(); -} - -void COperations::glCommands(bool select, bool marked, bool no_color) -{ - ObjList::glCommands(select, marked, no_color); -} - -void COperations::WriteXML(TiXmlNode *root) -{ - TiXmlElement * element; - element = heeksCAD->NewXMLElement( "Operations" ); - heeksCAD->LinkXMLEndChild( root, element ); - WriteBaseXML(element); -} - -//static -HeeksObj* COperations::ReadFromXMLElement(TiXmlElement* pElem) -{ - COperations* new_object = new COperations; - new_object->ReadBaseXML(pElem); - return new_object; -} - -static COperations* object_for_tools = NULL; - -class SetAllActive: public Tool{ - // Tool's virtual functions - const wxChar* GetTitle(){return _("Set All Operations Active");} - void Run() - { - for(HeeksObj* object = object_for_tools->GetFirstChild(); object; object = object_for_tools->GetNextChild()) - { - if(COperations::IsAnOperation(object->GetType())) - { - ((COp*)object)->m_active = true; - // to do, make undoable properties - } - } - } - wxString BitmapPath(){ return _T("setactive");} -}; - -static SetAllActive set_all_active; - -class SetAllInactive: public Tool{ - // Tool's virtual functions - const wxChar* GetTitle(){return _("Set All Operations Inactive");} - void Run() - { - for(HeeksObj* object = object_for_tools->GetFirstChild(); object; object = object_for_tools->GetNextChild()) - { - if(COperations::IsAnOperation(object->GetType())) - { - ((COp*)object)->m_active = false; - // to do, make undoable properties - } - } - } - wxString BitmapPath(){ return _T("setinactive");} -}; - -static SetAllInactive set_all_inactive; - -void COperations::GetTools(std::list* t_list, const wxPoint* p) -{ - object_for_tools = this; - - t_list->push_back(&set_all_active); - t_list->push_back(&set_all_inactive); - - ObjList::GetTools(t_list, p); -} - -//static -bool COperations::IsAnOperation(int object_type) -{ - switch(object_type) - { - case ProfileType: - case PocketType: - case DrillingType: - case ScriptOpType: - return true; - default: - return theApp.m_external_op_types.find(object_type) != theApp.m_external_op_types.end(); - } -} - +// Operations.cpp +// Copyright (c) 2009, Dan Heeks +// This program is released under the BSD license. See the file COPYING for details. + +#include "stdafx.h" +#include "Operations.h" +#include "Op.h" +#include "interface/Tool.h" +#include "tinyxml/tinyxml.h" +#include "Excellon.h" + +#include + +bool COperations::CanAdd(HeeksObj* object) +{ + return ((object != NULL) && (IsAnOperation(object->GetType()))); +} + +COperations & COperations::operator= ( const COperations & rhs ) +{ + if (this != &rhs) + { + ObjList::operator=( rhs ); + } + + return(*this); +} + +COperations::COperations( const COperations & rhs ) : ObjList(rhs) +{ +} + +const wxBitmap &COperations::GetIcon() +{ + static wxBitmap* icon = NULL; + if(icon == NULL)icon = new wxBitmap(wxImage(theApp.GetResFolder() + _T("/icons/operations.png"))); + return *icon; +} + +/** + This is ALMOST the same as the assignment operator. The difference is that + this method augments its local list of operations with those passed in rather + than replacing them. + */ +void COperations::CopyFrom(const HeeksObj *object) +{ + if (object->GetType() == GetType()) + { + COperations *rhs = (COperations*)object; + for (HeeksObj *child = rhs->GetFirstChild(); child != NULL; child = rhs->GetNextChild()) + { + child->SetID( heeksCAD->GetNextID(child->GetType()) ); + Add(child, NULL); + } // End for + } +} + +void COperations::ReloadPointers() +{ + ObjList::ReloadPointers(); +} + +void COperations::glCommands(bool select, bool marked, bool no_color) +{ + ObjList::glCommands(select, marked, no_color); +} + +void COperations::WriteXML(TiXmlNode *root) +{ + TiXmlElement * element; + element = heeksCAD->NewXMLElement( "Operations" ); + heeksCAD->LinkXMLEndChild( root, element ); + WriteBaseXML(element); +} + +//static +HeeksObj* COperations::ReadFromXMLElement(TiXmlElement* pElem) +{ + COperations* new_object = new COperations; + new_object->ReadBaseXML(pElem); + return new_object; +} + +static COperations* object_for_tools = NULL; + +class SetAllActive: public Tool{ + // Tool's virtual functions + const wxChar* GetTitle(){return _("Set All Operations Active");} + void Run() + { + for(HeeksObj* object = object_for_tools->GetFirstChild(); object; object = object_for_tools->GetNextChild()) + { + if(COperations::IsAnOperation(object->GetType())) + { + ((COp*)object)->m_active = true; + // to do, make undoable properties + } + } + } + wxString BitmapPath(){ return _T("setactive");} +}; + +static SetAllActive set_all_active; + +class SetAllInactive: public Tool{ + // Tool's virtual functions + const wxChar* GetTitle(){return _("Set All Operations Inactive");} + void Run() + { + for(HeeksObj* object = object_for_tools->GetFirstChild(); object; object = object_for_tools->GetNextChild()) + { + if(COperations::IsAnOperation(object->GetType())) + { + ((COp*)object)->m_active = false; + // to do, make undoable properties + } + } + } + wxString BitmapPath(){ return _T("setinactive");} +}; + +static SetAllInactive set_all_inactive; + +void COperations::GetTools(std::list* t_list, const wxPoint* p) +{ + object_for_tools = this; + + t_list->push_back(&set_all_active); + t_list->push_back(&set_all_inactive); + + ObjList::GetTools(t_list, p); +} + +//static +bool COperations::IsAnOperation(int object_type) +{ + switch(object_type) + { + case ProfileType: + case PocketType: + case DrillingType: + case ScriptOpType: + return true; + default: + return theApp.m_external_op_types.find(object_type) != theApp.m_external_op_types.end(); + } +} + diff --git a/src/OutputCanvas.cpp b/src/OutputCanvas.cpp index 9e922c8b..023b08ac 100644 --- a/src/OutputCanvas.cpp +++ b/src/OutputCanvas.cpp @@ -1,9 +1,9 @@ // OutputCanvas.cpp -/* - * Copyright (c) 2009, Dan Heeks - * This program is released under the BSD license. See the file COPYING for - * details. - */ +/* + * Copyright (c) 2009, Dan Heeks + * This program is released under the BSD license. See the file COPYING for + * details. + */ #include "stdafx.h" #include "OutputCanvas.h" @@ -32,10 +32,10 @@ void COutputTextCtrl::OnMouse( wxMouseEvent& event ) bool painting = false; void COutputTextCtrl::OnPaint(wxPaintEvent& event) -{ - // this is here to Format the text ( which seems to be slow in Windows, if all done at once in CNCCode::SetTextCtrl ) - // OnPaint doesn't seem to get called from Linux, though - wxPaintDC dc(this); +{ + // this is here to Format the text ( which seems to be slow in Windows, if all done at once in CNCCode::SetTextCtrl ) + // OnPaint doesn't seem to get called from Linux, though + wxPaintDC dc(this); if (!painting && theApp.m_program && theApp.m_program->NCCode()) { @@ -98,8 +98,8 @@ void COutputCanvas::Resize() void COutputCanvas::Clear() { m_textCtrl->Clear(); -} - +} + BEGIN_EVENT_TABLE(CPrintCanvas, wxScrolledWindow) EVT_SIZE(CPrintCanvas::OnSize) @@ -138,5 +138,5 @@ void CPrintCanvas::Resize() void CPrintCanvas::Clear() { m_textCtrl->Clear(); -} - +} + diff --git a/src/Pattern.cpp b/src/Pattern.cpp index 9c796765..8fbd5d5a 100644 --- a/src/Pattern.cpp +++ b/src/Pattern.cpp @@ -59,44 +59,44 @@ HeeksObj* CPattern::ReadFromXMLElement(TiXmlElement* element) return new_object; } -static void on_set_copies1(int value, HeeksObj* object) -{ - ((CPattern*)object)->m_copies1 = value; -} - -static void on_set_x_shift1(double value, HeeksObj* object) -{ - ((CPattern*)object)->m_x_shift1 = value; -} - -static void on_set_y_shift1(double value, HeeksObj* object) -{ - ((CPattern*)object)->m_y_shift1 = value; -} - -static void on_set_copies2(int value, HeeksObj* object) -{ - ((CPattern*)object)->m_copies2 = value; -} - -static void on_set_x_shift2(double value, HeeksObj* object) -{ - ((CPattern*)object)->m_x_shift2 = value; -} - -static void on_set_y_shift2(double value, HeeksObj* object) -{ - ((CPattern*)object)->m_y_shift2 = value; -} +static void on_set_copies1(int value, HeeksObj* object) +{ + ((CPattern*)object)->m_copies1 = value; +} + +static void on_set_x_shift1(double value, HeeksObj* object) +{ + ((CPattern*)object)->m_x_shift1 = value; +} + +static void on_set_y_shift1(double value, HeeksObj* object) +{ + ((CPattern*)object)->m_y_shift1 = value; +} + +static void on_set_copies2(int value, HeeksObj* object) +{ + ((CPattern*)object)->m_copies2 = value; +} + +static void on_set_x_shift2(double value, HeeksObj* object) +{ + ((CPattern*)object)->m_x_shift2 = value; +} + +static void on_set_y_shift2(double value, HeeksObj* object) +{ + ((CPattern*)object)->m_y_shift2 = value; +} void CPattern::GetProperties(std::list *list) { - list->push_back(new PropertyInt(_("number of copies 1"), m_copies1, this, on_set_copies1)); - list->push_back(new PropertyDouble(_("x shift 1"), m_x_shift1, this, on_set_x_shift1)); - list->push_back(new PropertyDouble(_("y shift 1"), m_y_shift1, this, on_set_y_shift1)); - list->push_back(new PropertyInt(_("number of copies 2"), m_copies2, this, on_set_copies2)); - list->push_back(new PropertyDouble(_("x shift 2"), m_x_shift2, this, on_set_x_shift2)); - list->push_back(new PropertyDouble(_("y shift 2"), m_y_shift2, this, on_set_y_shift2)); + list->push_back(new PropertyInt(_("number of copies 1"), m_copies1, this, on_set_copies1)); + list->push_back(new PropertyDouble(_("x shift 1"), m_x_shift1, this, on_set_x_shift1)); + list->push_back(new PropertyDouble(_("y shift 1"), m_y_shift1, this, on_set_y_shift1)); + list->push_back(new PropertyInt(_("number of copies 2"), m_copies2, this, on_set_copies2)); + list->push_back(new PropertyDouble(_("x shift 2"), m_x_shift2, this, on_set_x_shift2)); + list->push_back(new PropertyDouble(_("y shift 2"), m_y_shift2, this, on_set_y_shift2)); IdNamedObj::GetProperties(list); } diff --git a/src/Pattern.h b/src/Pattern.h index 29b74ac6..0f3bca14 100644 --- a/src/Pattern.h +++ b/src/Pattern.h @@ -32,7 +32,7 @@ class CPattern: public IdNamedObj { void CopyFrom(const HeeksObj* object); bool CanAddTo(HeeksObj* owner); const wxBitmap &GetIcon(); - void GetOnEdit(bool(**callback)(HeeksObj*)); + void GetOnEdit(bool(**callback)(HeeksObj*)); HeeksObj* PreferredPasteTarget(); static HeeksObj* ReadFromXMLElement(TiXmlElement* pElem); diff --git a/src/ProfileDlg.cpp b/src/ProfileDlg.cpp index dffe5404..1d04b3ea 100644 --- a/src/ProfileDlg.cpp +++ b/src/ProfileDlg.cpp @@ -7,7 +7,7 @@ #include "interface/PictureFrame.h" #include "interface/NiceTextCtrl.h" #include "Profile.h" -#include "CTool.h" +#include "CTool.h" BEGIN_EVENT_TABLE(ProfileDlg, SketchOpDlg) EVT_COMBOBOX(ID_TOOL_ON_SIDE,HeeksObjDlg::OnComboOrCheck) diff --git a/src/Reselect.h b/src/Reselect.h index ddab16a7..5e888681 100644 --- a/src/Reselect.h +++ b/src/Reselect.h @@ -1,45 +1,45 @@ // Reselect.h -// Copyright (c) 2010, Dan Heeks -// This program is released under the BSD license. See the file COPYING for details. - -#include "interface/Tool.h" - -class ReselectSketches: public Tool{ -public: - std::list *m_sketches; - HeeksObj* m_object; - ReselectSketches(): m_sketches(NULL), m_object(NULL){} - - // Tool's virtual functions - const wxChar* GetTitle(){return _("Re-select sketches");} - void Run(); - wxString BitmapPath(){ return _T("selsketch");} -}; - -class ReselectSketch: public Tool{ -public: - int m_sketch; - HeeksObj* m_object; - ReselectSketch(): m_sketch(0), m_object(NULL){} - - // Tool's virtual functions - const wxChar* GetTitle(){return _("Re-select sketch");} - void Run(); - wxString BitmapPath(){ return _T("selsketch");} -}; - -class ReselectSolids: public Tool{ -public: - std::list *m_solids; - HeeksObj* m_object; - ReselectSolids(): m_solids(NULL), m_object(NULL){} - - static bool GetSolids(std::list& solids ); - - // Tool's virtual functions - const wxChar* GetTitle(){return _("Re-select solids");} - void Run(); - wxString BitmapPath(){ return _T("selsolid");} -}; - -void AddSolidsProperties(std::list *list, const std::list &sketches); +// Copyright (c) 2010, Dan Heeks +// This program is released under the BSD license. See the file COPYING for details. + +#include "interface/Tool.h" + +class ReselectSketches: public Tool{ +public: + std::list *m_sketches; + HeeksObj* m_object; + ReselectSketches(): m_sketches(NULL), m_object(NULL){} + + // Tool's virtual functions + const wxChar* GetTitle(){return _("Re-select sketches");} + void Run(); + wxString BitmapPath(){ return _T("selsketch");} +}; + +class ReselectSketch: public Tool{ +public: + int m_sketch; + HeeksObj* m_object; + ReselectSketch(): m_sketch(0), m_object(NULL){} + + // Tool's virtual functions + const wxChar* GetTitle(){return _("Re-select sketch");} + void Run(); + wxString BitmapPath(){ return _T("selsketch");} +}; + +class ReselectSolids: public Tool{ +public: + std::list *m_solids; + HeeksObj* m_object; + ReselectSolids(): m_solids(NULL), m_object(NULL){} + + static bool GetSolids(std::list& solids ); + + // Tool's virtual functions + const wxChar* GetTitle(){return _("Re-select solids");} + void Run(); + wxString BitmapPath(){ return _T("selsolid");} +}; + +void AddSolidsProperties(std::list *list, const std::list &sketches); diff --git a/src/ScriptOpDlg.cpp b/src/ScriptOpDlg.cpp index b1055434..2c576832 100644 --- a/src/ScriptOpDlg.cpp +++ b/src/ScriptOpDlg.cpp @@ -7,10 +7,10 @@ #include "interface/PictureFrame.h" #include "interface/NiceTextCtrl.h" #include "ScriptOp.h" -#include "Program.h" -#include "Tools.h" -#include "Patterns.h" -#include "Surfaces.h" +#include "Program.h" +#include "Tools.h" +#include "Patterns.h" +#include "Surfaces.h" BEGIN_EVENT_TABLE(ScriptOpDlg, OpDlg) EVT_TEXT(ID_SCRIPT_TXT, ScriptOpDlg::OnScriptText) diff --git a/src/SolidsDlg.cpp b/src/SolidsDlg.cpp index 6143fc8b..7a4fcfcc 100644 --- a/src/SolidsDlg.cpp +++ b/src/SolidsDlg.cpp @@ -50,10 +50,10 @@ void SolidsDlg::PickSolids() heeksCAD->ClearMarkedList(); heeksCAD->PickObjects(_("Pick solids"), MARKING_FILTER_SOLIDS_GROUP); - std::list solids; + std::list solids; ReselectSolids::GetSolids( solids ); m_idsSolids->SetFromIDList(solids); Fit(); - heeksCAD->ClearMarkedList(); + heeksCAD->ClearMarkedList(); } diff --git a/src/Stock.h b/src/Stock.h index 97ec3f2f..521e685d 100644 --- a/src/Stock.h +++ b/src/Stock.h @@ -29,7 +29,7 @@ class CStock: public IdNamedObj { const wxBitmap &GetIcon(); void WriteDefaultValues(); void ReadDefaultValues(); - void GetOnEdit(bool(**callback)(HeeksObj*)); + void GetOnEdit(bool(**callback)(HeeksObj*)); HeeksObj* PreferredPasteTarget(); static HeeksObj* ReadFromXMLElement(TiXmlElement* pElem); diff --git a/src/stdafx.h b/src/stdafx.h index 37d0ed55..b3ad7b4a 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -32,16 +32,16 @@ extern "C" { #include "tinyxml/tinyxml.h" #include "gp_Pnt.hxx" -#include +#include #include "gp_Lin.hxx" #include "gp_Circ.hxx" #include "gp_Pln.hxx" #include "Geom_Plane.hxx" #include "GeomAPI_IntSS.hxx" #include "Geom_Line.hxx" -#include "gp_Elips.hxx" -#include "TopoDS_Shape.hxx" -#include "TopoDS_Face.hxx" +#include "gp_Elips.hxx" +#include "TopoDS_Shape.hxx" +#include "TopoDS_Face.hxx" // TODO: reference additional headers your program requires here