]> Shamusworld >> Repos - architektonas/commitdiff
Fixed thumbnail rendering in LibraryWidget and DXF detection.
authorShamus Hammons <jlhamm@acm.org>
Tue, 7 Sep 2010 22:38:49 +0000 (22:38 +0000)
committerShamus Hammons <jlhamm@acm.org>
Tue, 7 Sep 2010 22:38:49 +0000 (22:38 +0000)
src/base/rs_debug.cpp
src/base/rs_fileio.cpp
src/forms/librarywidget.cpp

index 20435cdb3e34340838e14c952780c1dbe1345969..5d0cdde5617ad4cd9e60a0249eb04721b029d757 100644 (file)
@@ -39,7 +39,8 @@ RS_Debug * RS_Debug::instance()
 
                uniqueInstance = new RS_Debug;
                //uniqueInstance->stream = fopen(fName.latin1(), "wt");
-               uniqueInstance->stream = stderr;
+//             uniqueInstance->stream = stderr;
+               uniqueInstance->stream = stdout;
        }
 
        return uniqueInstance;
index 8e59307019c80e92b37e1b658faeb4a47878d425..dc29997524d716cf30ba82a81cc1fbca75d60f66 100644 (file)
@@ -12,6 +12,7 @@
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  05/28/2010  Added this text. :-)
+// JLH  09/07/2010  Fixed file detection algorithm.
 //
 
 #include "rs_fileio.h"
@@ -33,7 +34,7 @@ RS_FileIO::RS_FileIO()
  */
 /*static*/ RS_FileIO * RS_FileIO::instance()
 {
-       if (uniqueInstance == NULL)
+       if (!uniqueInstance)
                uniqueInstance = new RS_FileIO();
 
        return uniqueInstance;
@@ -60,7 +61,6 @@ QList<RS_FilterInterface *> RS_FileIO::getFilterList()
  */
 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];
@@ -77,7 +77,6 @@ RS_FilterInterface * RS_FileIO::getImportFilter(RS2::FormatType t)
  */
 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];
@@ -100,43 +99,18 @@ RS_FilterInterface * RS_FileIO::getExportFilter(RS2::FormatType t)
  */
 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;
@@ -151,13 +125,10 @@ bool RS_FileIO::fileImport(Drawing & graphic, const QString & file, RS2::FormatT
 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;
@@ -167,7 +138,7 @@ bool RS_FileIO::fileExport(Drawing & graphic, const QString & file, RS2::FormatT
 
        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");
@@ -181,10 +152,8 @@ bool RS_FileIO::fileExport(Drawing & graphic, const QString & file, RS2::FormatT
 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")
        {
@@ -199,21 +168,23 @@ RS2::FormatType RS_FileIO::detectFormat(const QString & file)
                {
                        // 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;
index 3f8d67ecc89450329b289b14e417733d75e75820..edacdc1131266cdd4844a0d2ba45dac5d4388638 100644 (file)
 // 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"
@@ -278,7 +281,7 @@ QString LibraryWidget::getItemPath(QListWidgetItem * item)
  * @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)
@@ -318,7 +321,6 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF
        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());
@@ -347,27 +349,8 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF
        // 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);
@@ -375,7 +358,7 @@ It only fails for certain DXFs. Dunno why.
        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))
@@ -390,10 +373,9 @@ It only fails for certain DXFs. Dunno why.
                        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();
@@ -418,20 +400,3 @@ It only fails for certain DXFs. Dunno why.
 
        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