// Who When What
// --- ---------- -----------------------------------------------------------
// JLH 05/28/2010 Added this text. :-)
+// JLH 09/07/2010 Fixed file detection algorithm.
//
#include "rs_fileio.h"
*/
/*static*/ RS_FileIO * RS_FileIO::instance()
{
- if (uniqueInstance == NULL)
+ if (!uniqueInstance)
uniqueInstance = new RS_FileIO();
return uniqueInstance;
*/
RS_FilterInterface * RS_FileIO::getImportFilter(RS2::FormatType t)
{
-// for(RS_FilterInterface * f=filterList.first(); f!=NULL; f=filterList.next())
for(int i=0; i<filterList.size(); i++)
{
RS_FilterInterface * f = filterList[i];
*/
RS_FilterInterface * RS_FileIO::getExportFilter(RS2::FormatType t)
{
-// for(RS_FilterInterface * f=filterList.first(); f!=NULL; f=filterList.next())
for(int i=0; i<filterList.size(); i++)
{
RS_FilterInterface * f = filterList[i];
*/
bool RS_FileIO::fileImport(Drawing & graphic, const QString & file, RS2::FormatType type)
{
- RS_DEBUG->print("Trying to import file '%s'...", file.toLatin1().data());
+ RS_DEBUG->print("Trying to import file '%s'...", file.toAscii().data());
RS_FilterInterface * filter = NULL;
- RS2::FormatType t;
-
- if (type == RS2::FormatUnknown)
- t = detectFormat(file);
- else
- t = type;
-
+ RS2::FormatType t = (type == RS2::FormatUnknown ? detectFormat(file) : type);
filter = getImportFilter(t);
- /*
- switch (t) {
- case RS2::FormatCXF:
- filter = new RS_FilterCXF(graphic);
- break;
-
- case RS2::FormatDXF1:
- filter = new RS_FilterDXF1(graphic);
- break;
-
- case RS2::FormatDXF:
- filter = new RS_FilterDXF(graphic);
- break;
-
- default:
- break;
- }
- */
-
if (filter)
return filter->fileImport(graphic, file, t);
else
{
RS_DEBUG->print(RS_Debug::D_WARNING, "RS_FileIO::fileImport: failed to import file: %s",
- file.toLatin1().data());
+ file.toAscii().data());
}
return false;
bool RS_FileIO::fileExport(Drawing & graphic, const QString & file, RS2::FormatType type)
{
RS_DEBUG->print("RS_FileIO::fileExport");
- //RS_DEBUG->print("Trying to export file '%s'...", file.latin1());
if (type == RS2::FormatUnknown)
{
- QString extension;
-// extension = QFileInfo(file).extension(false).toLower();
- extension = QFileInfo(file).suffix().toLower();
+ QString extension = QFileInfo(file).suffix().toLower();
if (extension == "dxf")
type = RS2::FormatDXF;
RS_FilterInterface * filter = getExportFilter(type);
- if (filter != NULL)
+ if (filter)
return filter->fileExport(graphic, file, type);
RS_DEBUG->print("RS_FileIO::fileExport: no filter found");
RS2::FormatType RS_FileIO::detectFormat(const QString & file)
{
RS2::FormatType type = RS2::FormatUnknown;
- QFileInfo f(file);
-
-// QString ext = f.extension(false).toLower();
- QString ext = f.suffix().toLower();
+ QFileInfo info(file);
+ QString ext = info.suffix().toLower();
if (ext == "cxf")
{
{
// Error opening file:
RS_DEBUG->print(RS_Debug::D_WARNING,
- "RS_FileIO::detectFormat: Cannot open file: %s", file.toLatin1().data());
+ "RS_FileIO::detectFormat: Cannot open file: %s", file.toAscii().data());
type = RS2::FormatUnknown;
}
else
{
RS_DEBUG->print("RS_FileIO::detectFormat: Successfully opened DXF file: %s",
- file.toLatin1().data());
+ file.toAscii().data());
QTextStream ts(&f);
- QString line;
int c = 0;
- while (!f.atEnd() && ++c < 100)
+//I think this is wrong... We're mixing classes here...
+//AND THAT WAS THE PROBLEM!!!
+// while (!f.atEnd() && ++c < 100)
+ while (!ts.atEnd() && ++c < 100)
{
- line = ts.readLine();
+ QString line = ts.readLine();
if (line == "$ACADVER")
type = RS2::FormatDXF;