// 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;
// JLH 05/10/2010 Created this file. :-)
// JLH 08/28/2010 Restored functionality to library browser
// JLH 09/06/2010 Partially fixed thumbnail rendering
+// JLH 09/07/2010 Fully fixed thumbnail rendering
//
/*
-BUGS:
-
-- Picks up thumbnail directories twice--only once if thumbnail dir doesn't exist
+Note that this is basically just a way to get a block from a file; it's unclear
+that it does so and the doco (such as it was) didn't mention it either. So what
+we need is to make it very clear that inserting is to the BLOCK list and not
+the document--perhaps we need to fold it into the block list, and make the
+insert function insert into the block list only...
*/
#include "librarywidget.h"
* @param dir Library directory (e.g. "/mechanical/screws")
* @param dxfFile File name (e.g. "screw1.dxf")
* @param dxfPath Full path to the existing DXF file on disk
- * (e.g. /home/tux/.qcad/library/mechanical/screws/screw1.dxf)
+ * (e.g. /home/tux/.architektonas/library/mechanical/screws/screw1.dxf)
*/
QPixmap LibraryWidget::getPixmap(const QString & dir, const QString & dxfFile,
const QString & dxfPath)
for(it=directoryList.begin(); it!=directoryList.end(); ++it)
{
itemDir = (*it) + dir;
-// pngPath = itemDir + "/" + fiDxf.baseName(true) + ".png";
pngPath = itemDir + "/" + fiDxf.completeBaseName() + ".png";
RS_DEBUG->print("LibraryWidget::getPathToPixmap: checking: '%s'",
pngPath.toLatin1().data());
// The thumbnail must be created in the user's home.
// So, create all directories needed:
RS_SYSTEM->createHomePath("/.architektonas/library" + dir);
-
QString d = RS_SYSTEM->getHomeDir() + "/.architektonas/library" + dir;
-//printf("librarywidget: d = \"%s\"\n", d.toAscii().data());
-
-// pngPath = d + "/" + fiDxf.baseName(true) + ".png";
pngPath = d + "/" + fiDxf.completeBaseName() + ".png";
-//printf("librarywidget: pngPath = \"%s\"\n", pngPath.toAscii().data());
-
- // Ugh. This is a mess and doesn't work right anyway...
- // Problem is StaticGraphicView doesn't follow a standard rendering path,
- // so all this crap just ends in failure. Not sure how to fix.
-/**
-I suppose one way to do it would be to make a CreateImage() function in GraphicView,
-then we wouldn't have all this messiness...
-I think the way the redraw works is like that--it creates its own PaintInterface
-and QPainter and sets "painter" equal to it... That being the case, it would be
-a simple matter to modify StaticGraphicView to utilize that... Let's see...
-Which it should be doing, but, for some reason, it fails. Dunno why.
-
-It only fails for certain DXFs. Dunno why.
-*/
QPixmap buffer(128, 128);
QPainter qpntr(&buffer);
qpntr.setBackground(Qt::white);
qpntr.eraseRect(0, 0, 128, 128);
- RS_StaticGraphicView gv(128, 128, painter);
+ RS_StaticGraphicView view(128, 128, painter);
Drawing drawing;
if (drawing.open(dxfPath, RS2::FormatUnknown))
e->setPen(pen);
}
- gv.setContainer(&drawing);
- gv.zoomAuto(false);
-//This works, but somehow doesn't work ALL the time
- gv.drawEntity(&drawing, true);
+ view.setContainer(&drawing);
+ view.zoomAuto(false);
+ view.drawEntity(&drawing, true);
QImageWriter writer;
QImage image = buffer.toImage();
return pngPath;
}
-
-#if 0
-
-QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible
-QPaintDevice: Cannot destroy paint device that is being painted
-
-Program received signal SIGSEGV, Segmentation fault.
-0x085cd068 in ?? ()
-(gdb) bt
-#0 0x085cd068 in ?? ()
-#1 0xb7818bd0 in QPainter::~QPainter() () from /usr/lib/qt4/libQtGui.so.4
-#2 0x081c1e8e in LibraryWidget::getPathToPixmap(QString const&, QString const&, QString const&) ()
-#3 0x081c0fa6 in LibraryWidget::getPixmap(QString const&, QString const&, QString const&) ()
-#4 0x081c0775 in LibraryWidget::updatePreview(QTreeWidgetItem*, int) ()
-#5 0x08237d5e in LibraryWidget::qt_metacall(QMetaObject::Call, int, void**) ()
-
-#endif