예제 #1
0
void pocket_files(const _TCHAR* dxf_file, const _TCHAR* txt_file, const PocketParams &params)
{
	// this reads the dxf file and creates a text file with the pocketing path in

	// read the dxf file into a CArea object
	CArea area;
	AreaDxfRead dxf_read(dxf_file, &area);
	dxf_read.DoRead(false);
	if(dxf_read.Failed())
	{
		printf("dxf read failed, opening file %s", Ttc(dxf_file));
		return;
	}

	// open a text file to write to
	CTextPath text_path(txt_file, params.m_format_style);
	if(text_path.Failed())
	{
		printf("text write failed, opening file %s", Ttc(txt_file));
		return;
	}

	// make pocketing path
	pocket_area(area, params, text_path);
}
예제 #2
0
CAutoSave::CAutoSave(const int interval, const bool skip_recovery /* = false */ )
{
	// We need to see if our backup file already exists.  If so, we should
	// prompt the user to see if they want to use its contents or ignore it.

	wxStandardPaths standard_paths;
	wxFileName path( standard_paths.GetTempDir().c_str(), _(".HeeksCAD_Backup_Data_File.heeks"));
	m_backup_file_name = path.GetFullPath();

	printf("Using backup file path '%s'\n", Ttc(m_backup_file_name) );

	m_save_interval = interval;	// Minutes
	m_auto_recover_requested = false;

	struct stat statbuf;
	if ((stat(Ttc(m_backup_file_name.c_str()), &statbuf) != -1) && (! skip_recovery))
	{
		// The file was found.  If it still has size then we must have crashed.
		if (statbuf.st_size > 0)
		{
			int answer = wxMessageBox(_("Do you want to recover using the automatic backup file?"),
						_T("Confirm"), wxYES_NO );
			if (answer == wxYES)
			{
				// We need to recover but it must be deferred until the rest of
				// HeeksCAD has finished initializing.

				m_auto_recover_requested = true;
			}
		}
	}

	wxTimer::Start( m_save_interval * 60 * 1000, false );	// Save interval - minutes -> milliseconds
} // End default constructor
예제 #3
0
/* static */ std::list<wxString> VectorFonts::GetFileNames( const wxString & Root )
#ifdef WIN32
{
	std::list<wxString>	results;

	WIN32_FIND_DATA file_data;
	HANDLE hFind;

	std::string pattern = std::string(Ttc(Root.c_str())) + "\\*";
	hFind = FindFirstFile(Ctt(pattern.c_str()), &file_data);

	// Now recurse down until we find document files within 'current' directories.
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if ((file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) continue;

			results.push_back(file_data.cFileName);
		} while (FindNextFile( hFind, &file_data));

		FindClose(hFind);
	} // End if - then

	return(results);
} // End of GetFileNames() method.
예제 #4
0
파일: Simulate.cpp 프로젝트: play113/swer
void RunVoxelcutSimulation()
{
#ifdef FREE_VERSION
	::wxLaunchDefaultBrowser(_T("http://heeks.net/help/buy-heekscnc-1-0"));
#endif

	// write initial.py
	wxStandardPaths &standard_paths = wxStandardPaths::Get();
	wxString initial_py(standard_paths.GetTempDir() + _T("/initial.py"));

	{
		std::wofstream ofs(Ttc(initial_py.c_str()));

		ofs << _T("sys.path.insert(0,'") << wxGetApp().GetResFolder().c_str() << _T("')\n");
		ofs<< _T("import nc.") << wxGetApp().m_program->m_machine.reader.c_str() << _T("\n");

		WriteCoords(ofs);
		WriteSolids(ofs);
		WriteTools(ofs);

		ofs<<_T("parser = nc.") << wxGetApp().m_program->m_machine.reader.c_str() << _T(".Parser(toolpath)\n");

		ofs<<_T("parser.Parse('")<<GetOutputFileNameForPython(wxGetApp().m_program->GetOutputFileName().c_str())<<_T("')\n");
		ofs<<_T("toolpath.rewind()\n");
	}	

	// Set the working directory to the area that contains the DLL so that
	// the system can find the voxelcut.bat file correctly.
	::wxSetWorkingDirectory(wxGetApp().GetDllFolder());
	wxExecute(wxString(_T("\"")) + wxGetApp().GetDllFolder() + _T("\\VoxelCut.bat\""));
}
예제 #5
0
	void ThenDo(void)
	{
	    wxString xml_file_str = m_filename + wxString(_T(".nc.xml"));

		if (m_program->m_use_internal_backplotting == true)
		{
			wxString xml = ParseGCodeFile(m_filename);

			FILE *fp = fopen(Ttc(xml_file_str.c_str()),"w");
			if (fp == NULL)
			{
				wxString error;
				error << _T("Could not open ") << xml_file_str << _T(" for writing");
				wxMessageBox(error);
			}
			else
			{
				fprintf(fp, "%s\n", Ttc(xml));
				fclose(fp);
			}
		}

		// there should now be a .nc.xml written

		wxFile ofs(xml_file_str.c_str());
		if(!ofs.IsOpened())
		{
			wxMessageBox(wxString(_("Couldn't open file")) + _T(" - ") + xml_file_str);
			return;
		}

		// read the xml file, just like paste, into the program
		heeksCAD->CreateUndoPoint();

		heeksCAD->OpenXMLFile(xml_file_str, m_into);
		heeksCAD->Repaint();

		// in Windows, at least, executing the bat file was making HeeksCAD change it's Z order
		heeksCAD->GetMainFrame()->Raise();
		heeksCAD->Repaint();

        heeksCAD->Changed();

		delete m_busy_cursor;
		m_busy_cursor = NULL;

	}
예제 #6
0
파일: dxf.cpp 프로젝트: Heeks/libarea-old
CDxfRead::CDxfRead(const _TCHAR* filepath)
{
	// start the file
	m_fail = false;
	m_ifs = new ifstream(Ttc(filepath));
	if(!(*m_ifs)){
		m_fail = true;
		return;
	}
	m_ifs->imbue(std::locale("C"));
}
예제 #7
0
CAutoSave::~CAutoSave()
{
	// We need to delete the backup file on the assumption that the operator has
	// successfully saved or discarded their data in the 'normal way'.

	wxTimer::Stop();

	// Empty the file
	FILE *fp = fopen(Ttc(m_backup_file_name.c_str()),"w");
	if (fp) fclose(fp);

} // End destructor
예제 #8
0
파일: HDxf.cpp 프로젝트: play113/swer
HeeksDxfRead::HeeksDxfRead(const wxChar* filepath, bool undoable) : CDxfRead(Ttc(filepath)), m_undoable(undoable)
{
	HeeksConfig config;

	config.Read(_T("ImportDxfAsSketches"), &m_make_as_sketch);
	config.Read(_T("IgnoreDxfReadErrors"), &m_ignore_errors);
	config.Read(_T("DxfReadPoints"), &m_read_points);
	config.Read(_T("LayerNameSuffixesToDiscard"), m_layer_name_suffixes_to_discard);

	m_current_block = NULL;
	extract(gp_Trsf(), m_ucs_matrix);
}
예제 #9
0
파일: dxf.cpp 프로젝트: Heeks/libarea-old
CDxfWrite::CDxfWrite(const _TCHAR* filepath)
{
	// start the file
	m_fail = false;
#ifdef __WXMSW__
	m_ofs = new ofstream(filepath, ios::out);
#else
	m_ofs = new ofstream(Ttc(filepath), ios::out);
#endif
	if(!(*m_ofs)){
		m_fail = true;
		return;
	}
	m_ofs->imbue(std::locale("C"));

	// start
	(*m_ofs) << 0          << endl;
	(*m_ofs) << "SECTION"  << endl;
	(*m_ofs) << 2          << endl;
	(*m_ofs) << "ENTITIES" << endl;
}
예제 #10
0
void CAutoSave::Recover() const
{
	printf("Recovering from backup file %s\n", Ttc(m_backup_file_name.c_str()));
	wxGetApp().OpenFile(m_backup_file_name.c_str(), false, NULL, NULL, false );
}
예제 #11
0
bool CShape::ExportSolidsFile(const std::list<HeeksObj*>& objects, const wxChar* filepath, std::map<int, CShapeData> *index_map)
{
	// returns true, if suffix handled
	wxString wf(filepath);
	wf.LowerCase();

	if(wf.EndsWith(_T(".stp")) || wf.EndsWith(_T(".step")))
	{
		char oldlocale[1000];
		strcpy(oldlocale, setlocale(LC_NUMERIC, "C"));

		Standard_CString aFileName = (Standard_CString) (Ttc(filepath));
		STEPControl_Writer writer;
		// add all the solids
		int i = 1;
		for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++)
		{
			HeeksObj* object = *It;
			WriteShapeOrGroup(writer, object, index_map, i);
		}
		writer.Write(aFileName);

		setlocale(LC_NUMERIC, oldlocale);

		return true;
	}
	else if(wf.EndsWith(_T(".igs")) || wf.EndsWith(_T(".iges")))
	{
		char oldlocale[1000];
		strcpy(oldlocale, setlocale(LC_NUMERIC, "C"));

		Standard_CString aFileName = (Standard_CString) (Ttc(filepath));

		IGESControl_Controller::Init();
		IGESControl_Writer writer;

		// add all the solids
		for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++)
		{
			HeeksObj* object = *It;
			if(CShape::IsTypeAShape(object->GetType())){
				writer.AddShape(((CShape*)object)->Shape());
			}
			else if(object->GetType() == WireType){
				writer.AddShape(((CWire*)object)->Shape());
			}
		}
		writer.Write(aFileName);

		setlocale(LC_NUMERIC, oldlocale);

		return true;
	}
	else if(wf.EndsWith(_T(".brep")))
	{
#ifdef __WXMSW__
		ofstream ofs(filepath);
#else
		ofstream ofs(Ttc(filepath));
#endif
		for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++)
		{
			HeeksObj* object = *It;
			if(CShape::IsTypeAShape(object->GetType())){
				BRepTools::Write(((CShape*)object)->Shape(), ofs);
			}
		}
	}

	return false;
}
예제 #12
0
bool CShape::ImportSolidsFile(const wxChar* filepath, std::map<int, CShapeData> *index_map, HeeksObj* paste_into)
{
	// only allow paste of solids at top level or to groups
	if(paste_into && paste_into->GetType() != GroupType)return false;

	// returns true, if suffix handled
	wxString wf(filepath);

	HeeksObj* add_to = &wxGetApp();
	if(paste_into)add_to = paste_into;

	if(wf.EndsWith(_T(".stp")) || wf.EndsWith(_T(".STP")) || wf.EndsWith(_T(".step")) || wf.EndsWith(_T(".STEP")))
	{
		char oldlocale[1000];
		strcpy(oldlocale, setlocale(LC_NUMERIC, "C"));

		Standard_CString aFileName = (Standard_CString) (Ttc(filepath));
		STEPControl_Reader Reader;
		int status = Reader.ReadFile( aFileName );

		if ( status == IFSelect_RetDone )
		{
			int num = Reader.NbRootsForTransfer();
			for(int i = 1; i<=num; i++)
			{
				Handle_Standard_Transient root = Reader.RootForTransfer(i);
				Reader.TransferEntity(root);
				TopoDS_Shape rShape = Reader.Shape(i);
				if(index_map)
				{
					// change the id ( and any other data ), to the one in the step file index
					std::map<int, CShapeData>::iterator FindIt = index_map->find(i);
					if(FindIt != index_map->end())
					{
						CShapeData& shape_data = FindIt->second;
						HeeksObj* new_object = MakeObject(rShape, _("STEP solid"), shape_data.m_solid_type, HeeksColor(191, 191, 191), 1.0f);
						if(new_object)
						{
							add_to->Add(new_object, NULL);
							shape_data.SetShape((CShape*)new_object);
						}
					}
				}
				else
				{
					HeeksObj* new_object = MakeObject(rShape, _("STEP solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f);
					add_to->Add(new_object, NULL);
				}
			}
		}
		else{
			wxMessageBox(_("STEP import not done!"));
		}

		setlocale(LC_NUMERIC, oldlocale);

		return true;
	}
	else if(wf.EndsWith(_T(".igs")) || wf.EndsWith(_T(".IGS")) || wf.EndsWith(_T(".iges")) || wf.EndsWith(_T(".IGES")))
	{
		char oldlocale[1000];
		strcpy(oldlocale, setlocale(LC_NUMERIC, "C"));

		Standard_CString aFileName = (Standard_CString) (Ttc(filepath));
//
//#ifdef WIN32
//#ifdef UNICODE
//		// if the const char* filename is different to the original unicode filename, then copy the file to a temporary file with a simple name
//		if(stricmp(Ctt(aFileName), filepath))
//		{
//			wxStandardPaths standard_paths;
//			wxFileName path( standard_paths.GetTempDir().c_str(), _("temp_iges.igs"));
//			copy_file; // to do
//	m_backup_file_name = path.GetFullPath();
//#endif
//#endif

		IGESControl_Reader Reader;
		int status = Reader.ReadFile( aFileName );

		if ( status == IFSelect_RetDone )
		{
			Reader.TransferRoots();
			TopoDS_Shape shape = Reader.OneShape();
			HeeksObj* new_object = MakeObject(shape, _("IGES shape"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f);
			add_to->Add(new_object, NULL);
#if 0
			Reader.TransferRoots();
			int num_shapes = Reader.NbShapes();
			if(num_shapes > 0)
			{
				BRepOffsetAPI_Sewing face_sewing (0.001);
				int shapes_added_for_sewing = 0;
				for(int j = 1; j<= num_shapes; j++)
				{
					TopoDS_Shape rShape = Reader.Shape(j);
					if(rShape.ShapeType() == TopAbs_EDGE)
					{
						HeeksObj* new_object = new CEdge(TopoDS::Edge(rShape));
						add_to->Add(new_object, NULL);
					}
					else
					{
						face_sewing.Add (rShape);
						shapes_added_for_sewing++;
					}
				}

				if(shapes_added_for_sewing > 0)
				{
					face_sewing.Perform ();

					if(!face_sewing.SewedShape().IsNull())
					{
						HeeksObj* new_object = MakeObject(face_sewing.SewedShape(), _("sewed IGES solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191));
						add_to->Add(new_object, NULL);
					}
				}
			}
#endif

		}
		else{
			wxMessageBox(_("IGES import not done!"));
		}

		setlocale(LC_NUMERIC, oldlocale);

		return true;
	}
	else if(wf.EndsWith(_T(".brep")) || wf.EndsWith(_T(".BREP")))
	{
		char oldlocale[1000];
		strcpy(oldlocale, setlocale(LC_NUMERIC, "C"));

		TopoDS_Shape shape;
		BRep_Builder builder;
		Standard_Boolean result = BRepTools::Read(  shape,(char *) Ttc(filepath), builder );

		if(result)
		{
			HeeksObj* new_object = MakeObject(shape, _("BREP solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f);
			add_to->Add(new_object, NULL);
		}
		else{
			wxMessageBox(_("STEP import not done!"));
		}

		setlocale(LC_NUMERIC, oldlocale);

		return true;
	}
	return false;
}
예제 #13
0
void ReadPluginsList(std::list<PluginData> &plugins)
{
	plugins.clear();

	HeeksConfig plugins_config;
	plugins_config.SetPath(_T("/plugins"));

	wxString key;
	long Index;
	wxString str;

	bool entry_found = false;
	bool hCncConfigured = false;  //if true, heekscnc is a plugin already. don't automatically add it in that case

	entry_found = plugins_config.GetFirstEntry(key, Index);

	while(entry_found)
	{
		plugins_config.Read(key, &str);

		PluginData pd;
		if(str[0] == '#')
		{
			str = str.Mid(1);
			pd.enabled = false;
		}
		else
		{
			pd.enabled = true;
		}

		pd.name = key;
		pd.path = str;
		plugins.push_back(pd);
		if( str.Lower().Matches(_T("*heekscnc*")) )
			hCncConfigured = true; 

		entry_found = plugins_config.GetNextEntry(key, Index);
	}

	//look for heekscnc in the standard install location and automatically add it, if it isn't already configured
	if( !hCncConfigured ) {
#ifdef WIN32
		//this code should work on windows given the correct path
		// FIXME: put the right path under Windows
		wxString sCncplugPath = wxT("standard\\windows\\path\\to\\heekscnc.dll");
#else
  #if wxCHECK_VERSION(3, 0, 0)
		wxStandardPaths& sp = wxStandardPaths::Get();
  #else
		wxStandardPaths sp;
  #endif
		wxString sCncplugPath = sp.GetInstallPrefix()  + wxT("/lib/libheekscnc.so");
#endif
		wprintf(_T("Attempt to automatically load HeeksCNC: ") + sCncplugPath  + wxT("\n"));
		if (wxFileName::FileExists(sCncplugPath)) {
			PluginData pd;
			pd.enabled = true;
			pd.hard_coded = false; //if this was true, the plugin wouldn't be added to the config - meaning the user couldn't disable it
			pd.name = _T("HeeksCNC (Automatically added)");
			pd.path = sCncplugPath;
			plugins.push_back(pd);
		}
	}

	// add plugins from the command line
	std::list<wxString> command_line_plugins;
	wxGetApp().GetPluginsFromCommandLineParams(command_line_plugins);
	for(std::list<wxString>::iterator It = command_line_plugins.begin(); It != command_line_plugins.end(); It++)
	{
		PluginData pd;
		pd.enabled = true;
		pd.hard_coded = true;
		pd.name = _T("CommandLinePlugin");
		pd.path = *It;
		plugins.push_back(pd);
	}

	// add code to always start your dll here.
#ifdef MY_OWN_HARDCODED_PLUGIN
	{
		PluginData pd;
		pd.enabled = true;
		pd.hard_coded = true;
		pd.name = _T("MyPlugin");
		pd.path = _T("$(MYEXEPATH)/mypluing/PluginForHeeksCAD.dll");
		plugins.push_back(pd);
	}
#endif


	wxString plugins_file = wxGetApp().GetExeFolder() + _T("/plugins.txt");
    ifstream ifs(Ttc(plugins_file.c_str()));
	if(!(!ifs))
	{
		char s[1024] = "";

		while(!(ifs.eof()))
		{
			ifs.getline(s, 1024);
			wxString str(Ctt(s));

			PluginData pd;
			if(str[0] == '#')
			{
				str = str.Mid(1);
				pd.enabled = false;
			}
			else
			{
				pd.enabled = true;
			}
			pd.hard_coded = true;
			pd.name = str;
			str.Replace(_T("{app}"), wxGetApp().GetExeFolder().c_str());
			pd.path = str;
			plugins.push_back(pd);
		}
	}

}
예제 #14
0
CTextPath::CTextPath(const _TCHAR* txt_file, int format_style)
{
	m_ofs = new ofstream(Ttc(txt_file));
	m_number_format = format_style;
}
예제 #15
0
VectorFont::Glyph::Glyph( const std::list<std::string> &cxf_glyph_definition, const double word_space_percentage, const double character_space_percentage )
{
	m_word_space_percentage = word_space_percentage;
	m_character_space_percentage = character_space_percentage;

	for (std::list<std::string>::const_iterator l_itLine = cxf_glyph_definition.begin(); l_itLine != cxf_glyph_definition.end(); l_itLine++)
	{
		wxString line( Ctt(l_itLine->c_str()) );
		wxString delimiters( _T(" \t\r\n,") );

		std::vector<wxString> tokens = Tokens( line, delimiters );
		if (tokens.size() == 0)
		{
			std::ostringstream l_ossError;
			l_ossError << "Expected tokens in glyph definition";
			throw(std::runtime_error(l_ossError.str().c_str()));
		}

		// Replace dot (.) for comma (,) if the locale settings require it.
		for (std::vector<wxString>::iterator token = tokens.begin(); token != tokens.end(); token++)
		{
			*token = PrepareStringForConversion( *token );
		}
		const wxChar * c_str = tokens[0].c_str();
		switch (c_str[0])
		{
		case 'L':
			if (tokens.size() != 5)
			{
				std::ostringstream l_ossError;
				l_ossError << "Expected 5 tokens when defining a line.  We got "
							<< tokens.size() << " tokens from '" << l_itLine->c_str() << "\n";
				throw(std::runtime_error(l_ossError.str().c_str()));
			}
			else
			{
				GlyphLine *line = new GlyphLine(	 PointToMM(strtod( Ttc(tokens[1].c_str()), NULL )),
										 PointToMM(strtod( Ttc(tokens[2].c_str()), NULL )),
										 PointToMM(strtod( Ttc(tokens[3].c_str()), NULL )),
										 PointToMM(strtod( Ttc(tokens[4].c_str()), NULL )) );
				m_graphics_list.push_back( line );
				m_bounding_box.Insert( line->BoundingBox() );
			}
			break;

		case 'A':

			if (tokens.size() != 6)
			{
				std::ostringstream l_ossError;
				l_ossError << "Expected 6 tokens when defining an arc";
				throw(std::runtime_error(l_ossError.str().c_str()));
			}
			else
			{
				if ((tokens[0].size() == 2) && (c_str[1] == 'R'))
				{
					// Reverse the starting and ending points.
					GlyphArc *arc = new GlyphArc( PointToMM(strtod( Ttc(tokens[1].c_str()), NULL )),
										 PointToMM(strtod( Ttc(tokens[2].c_str()), NULL )),
										 PointToMM(strtod( Ttc(tokens[3].c_str()), NULL )),
										 strtod( Ttc(tokens[5].c_str()), NULL) ,
										 strtod( Ttc(tokens[4].c_str()), NULL ));
					m_graphics_list.push_back( arc );
					m_bounding_box.Insert( arc->BoundingBox() );
				} // End if - then
				else
				{
					GlyphArc *arc = new GlyphArc( PointToMM(strtod( Ttc(tokens[1].c_str()), NULL )),
										 PointToMM(strtod( Ttc(tokens[2].c_str()), NULL )),
										 PointToMM(strtod( Ttc(tokens[3].c_str()), NULL )),
										 strtod( Ttc(tokens[4].c_str()), NULL ),
										 strtod( Ttc(tokens[5].c_str()), NULL ) );
					m_graphics_list.push_back( arc );
					m_bounding_box.Insert( arc->BoundingBox() );
				}
			}
			break;

		default:
			std::ostringstream l_ossError;
			l_ossError << "Unexpected graphics element type '" << c_str[0] << "'";
			throw(std::runtime_error(l_ossError.str().c_str()));
		} // End switch
	} // End for
} // End constructor