Generating my own warnings

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Generating my own warnings

adrian
When a warning appears on the output pane, there is another message that pops up at the top of the preview window.  Is there a way to generate text in the output pane such that I can get such a message at the top of the preview window?
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

tp3
On 01/16/2017 03:26 PM, adrian wrote:
> When a warning appears on the output pane, there is another message
> that pops up at the top of the preview window.  Is there a way to
> generate text in the output pane such that I can get such a message
> at the top of the preview window?
>
I don't think that's possible. Right now the ECHO: prefix prevents
that. The dev snapshot will show the popup when assert() fails.

ciao,
  Torsten.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

adrian
How does OpenSCAD determine what is a Warning and what is not?  Does it look for a new line?  Colour?  Particular tag?
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

MichaelAtOz
Administrator
The message has WARNING: or ERROR: at the beginning.

Then this outputs the message.

void MainWindow::consoleOutput(const QString &msg)
{
        QString qmsg;
        if (msg.startsWith("WARNING:") || msg.startsWith("DEPRECATED:")) {
                this->compileWarnings++;
                qmsg = "<html>" + QT_HTML_ESCAPE(QString(msg)) + "</html>\n";
        } else if (msg.startsWith("ERROR:")) {
                this->compileErrors++;
                qmsg = "<html>" + QT_HTML_ESCAPE(QString(msg)) + "</html>\n";
        }
        else {
                qmsg = msg;
        }
        QTextCursor c = this->console->textCursor();
        c.movePosition(QTextCursor::End);
        this->console->setTextCursor(c);
        this->console->append(qmsg);
        if (this->procevents) QApplication::processEvents();
}


After compile this does the message at the top:

void MainWindow::updateCompileResult()
{
        if ((compileErrors == 0) && (compileWarnings == 0)) {
                frameCompileResult->hide();
                return;
        }

        Settings::Settings *s = Settings::Settings::inst();
        if (!s->get(Settings::Settings::showWarningsIn3dView).toBool()) {
                return;
        }

        QString msg;
        if (compileErrors > 0) {
                if (fileName.isEmpty()) {
                        msg = QString(_("Compile error."));
                } else {
                        QFileInfo fileInfo(fileName);
                        msg = QString(_("Error while compiling '%1'.")).arg(fileInfo.fileName());
                }
                toolButtonCompileResultIcon->setIcon(QIcon(QString::fromUtf8(":/icons/information-icons-error.png")));
        } else {
                const char *fmt = ngettext("Compilation generated %1 warning.", "Compilation generated %1 warnings.", compileWarnings);
                msg = QString(fmt).arg(compileWarnings);
                toolButtonCompileResultIcon->setIcon(QIcon(QString::fromUtf8(":/icons/information-icons-warning.png")));
        }
        QFontMetrics fm(labelCompileResultMessage->font());
        int sizeIcon = std::max(12, std::min(32, fm.height()));
        int sizeClose = std::max(10, std::min(32, fm.height()) - 4);
        toolButtonCompileResultIcon->setIconSize(QSize(sizeIcon, sizeIcon));
        toolButtonCompileResultClose->setIconSize(QSize(sizeClose, sizeClose));

        msg += _(" For details see <a href=\"#console\">console window.");
        labelCompileResultMessage->setText(msg);
        frameCompileResult->show();
}


Both bits of code are here:
https://github.com/openscad/openscad/blob/1fd9f05b441e85d5f827ce96154ce79ca334ce32/src/mainwin.cc
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

adrian
Beginning of what?  How is the console output broken up?  Is it a line?  Some arbitrary thing such that echo() cannot cause this to work? Why doesn't this show up as a warning?

echo(str(chr(13),"WARNING: blah"));
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

MichaelAtOz
Administrator
> Beginning of what?  

The error message in the application. eg

if (steps >= 10000) {
                                PRINTB("WARNING: Bad range parameter in for statement: too many elements (%lu).", steps);

> Some arbitrary thing such that echo() cannot cause this to work?

Correct, as tp3 mentioned above, "I don't think that's possible. Right now the ECHO: prefix prevents
that."

> Why doesn't this show up as a warning?

Because it is the string 'ECHO: <cr>"
WARNING: blah" '

It begins with "ECHO:"
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

MichaelAtOz
Administrator
In reply to this post by adrian
Note that you can use HTML to highlight echo() output, see HTML references in the wiki
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

adrian
Thanks Michael.  I do realize I can do my own highlighting.  However, I would like to make it such that if I have an issue, that it is visible at the top of the GUI, making it immediately visible to the user in case it gets scrolled off screen.
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

MichaelAtOz
Administrator
You could stick a big  'ERROR' in the middle of the preview, using

color("magenta") %text("ERROR!",size=50);

That would be noticeable.
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Generating my own warnings

Neon22
I agree - this is what I prefer to do in the thingiverse customiser.
So when a parameter creates a weird result I can test for - I print a warning as text in the scene.
E.g. if an angle results in self intersecting geometery...