Test request: quarter based viewer

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Test request: quarter based viewer

Post by ickby »

is any of this what you were looking for in a testing report?
Yes, this is exactly what I look for. Currently the user should not see any differences, so the points you made are important and I will fix those. Thanks.

In the end the user will benefit from the possibility to have qt widgets in the 3d scene with nice transpareny. At least thats my reason to do this, what others do with the new gained freedom of this implementation will be interesting to see :)
User avatar
quick61
Veteran
Posts: 3803
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Test request: quarter based viewer

Post by quick61 »

ickby wrote:
is any of this what you were looking for in a testing report?
Yes, this is exactly what I look for. Currently the user should not see any differences, so the points you made are important and I will fix those. Thanks.

In the end the user will benefit from the possibility to have qt widgets in the 3d scene with nice transpareny. At least thats my reason to do this, what others do with the new gained freedom of this implementation will be interesting to see :)
OK, great. I'll go through it more tomorrow and test a few more things I thought of this evening. I just read up a bit on Quarter and what it is designed for so yea, it looks like the thing to be using with Qt widgets in the 3D scene. It would be nice to see the entire combo view in the 3D scene and allow it to even be a mouse click pop in/out tab or enable it to slide off view like the tool boxes in Blender. Now that would be something slick to feature in the 0.15 release. :geek:

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Test request: quarter based viewer

Post by wmayer »

1. Does it compile under Windows? I have only tested it under Kubuntu 14.04
I tested the new branch today evening and there were a couple of things to fix on Windows. Attached is a patch file (remove the .zip extension)
2. Is the behavior the same as with the old viewer? The only notable difference should be that the anti-aliasing settings can not be switch on the fly anymore but requires a reopening of the viewer.
What is the reason that this cannot be done directly? SoQt actually also only uses Qt stuff and there it is possible.
There are no additional features implemented yet compared to current master. This is just to get the porting going.
I appreciate this very much!!! Unfortunately, we sometimes have patches or merge requests which does by far more than the promised fix and this makes the code review unnecessarily complicated.

After it built successfully I played a little bit. Here my observations:
* for Part shapes there is always a face with some light-blueish colour which you cannot get rid of. That looks a bit strange to me
I finished the porting of freecads View3DInventorViewer to a custom quarter based implementation. Before making a pull request I would like to here some opinions, as the internal changes are rather big. It would be fantastic if someone could test the following:
Can we have a test phase of a few weeks to see if it causes some major or minor problems? The recent big merge now appeared to be a middle disaster because it broke FreeCAD on many systems and I don't want to have this a second time. Then we should fix all these little things Mark has already reported.
Unfortunately, from Monday on I will be off for two weeks (maybe I have rarely time to visit the forum) but won't be able to work (a lot) on FreeCAD. So, I would appreciate it if we could do the merge when I am back.
Attachments
quarter.patch.zip
(7.57 KiB) Downloaded 47 times
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Test request: quarter based viewer

Post by wmayer »

Here my observations:
Coin 2.x does not work any more because the class SoRenderManager is now needed which has been added with 3.x (or so).

With the MinGW compiler I have a problem with the line:

Code: Select all

fc_wrap_cpp(Quarter_MOC_SRCS ${Quarter_H_SRC})
After changing it to

Code: Select all

qt4_wrap_cpp(Quarter_MOC_SRCS ${Quarter_H_SRC})
I got it working.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Test request: quarter based viewer

Post by ickby »

Hello Werner,

thanks for the patch, I will integrate it.
What is the reason that this cannot be done directly? SoQt actually also only uses Qt stuff and there it is possible
To change the multisampling you need to create a new QGlWidget. SoQt did this too, but they had the QGLWidget internally and it was not directl added to the layout. So they could easily destroy and recreate it. With quarter, where the Viewer is the QGLWidget, you wouldneed to replace the widget which is added to the layout. Furthermore you invalidate all pointers to the current Viewer which will most likly lead to crashs. This was my initial reasaning, however, in the last commit I switched the base class of the Quarter Widget from QGLWidget to QGraphicsView and we now use a QGLWidget only internally as viewport. So maybe it is possible now to do a viewport switch without Problems. I will look into it. (then the mouse selection changes become unnessecary)
Can we have a test phase of a few weeks to see if it causes some major or minor problems?
Yes of course. I will fix all upcoming and already mentioned issues in my branch and hope users go on testing. Then we see about a merge when you are back in a few weeks. I'm fine with this.
Coin 2.x does not work any more because the class SoRenderManager is now needed which has been added with 3.x (or so).
Yes, but I hope we can easily drop Support for Coin 2? This Version is already very old.

Thanks for your Feedback and have a nice trip :)
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Test request: quarter based viewer

Post by wmayer »

To change the multisampling you need to create a new QGlWidget. SoQt did this too, but they had the QGLWidget internally and it was not directl added to the layout. So they could easily destroy and recreate it. With quarter, where the Viewer is the QGLWidget, you wouldneed to replace the widget which is added to the layout.
Thanks to the patch from Ian a few weeks ago we don't need to change the multi-sampling on the fly any more. So, it's something that is of low (or no) priority. Nevertheless, when checking the Qt API this should be possible (but not tested):

Code: Select all

QGLWidget* gl = ...
if (gl->isValid()) {
    const QGLContext* oldContext = gl->context();
    QGLFormat format(oldContext->requestedFormat());
    format.setSamples(value);
    QGLContext* newContext = new QGLContext(format);
    gl->setContext(newContext);
}
Yes of course. I will fix all upcoming and already mentioned issues in my branch and hope users go on testing. Then we see about a merge when you are back in a few weeks. I'm fine with this.
Thanks!
Yes, but I hope we can easily drop Support for Coin 2? This Version is already very old.
Sure, but I have observed this and just wanted to mention it. With my MinGW environment I still use Coin2 and have to upgrade to Coin3 or Coin4.
Thanks for your Feedback and have a nice trip
Thanks!
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Test request: quarter based viewer

Post by wmayer »

There is an oddness I found in SoQTQuarterAdaptor:
The class has these methods

Code: Select all


QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getGLWidget()
{
    return this;
}

QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getGLWidget() const
{
    return const_cast<SoQTQuarterAdaptor*>(this);
}

but IMO that's wrong because SoQTQuarterAdaptor derives from QGraphicsView and thus is not a GL widget. The GL widget is the viewport of the graphics view and thus the method should be:

Code: Select all


QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getGLWidget()
{
    return this->viewport();
}

wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Test request: quarter based viewer

Post by wmayer »

There is a further issue: when setting the anti-aliasing to None in the settings you get a black screen which starts to flicker when panning or rotating the scene.
So, in the default case in the constructor of View3DInventor you must explicitly set a sampling of "1".

Code: Select all

      case View3DInventorViewer::None:
      default:
          f.setSamples(1);
          break;
Now there is one strange thing. QGLFormat activates multi-sampling if the sampling value is > 0 but SoQt does this if it's > 1.

Code: Select all

void QGLFormat::setSamples(int numSamples)
{
    detach();
    if (numSamples < 0) {
        qWarning("QGLFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples);
        return;
    }
    d->numSamples = numSamples;
    setSampleBuffers(numSamples > 0);
}

Code: Select all

void
SoQtGLWidget::setSampleBuffers(const int numsamples)
{
#if HAVE_QGLFORMAT_SETSAMPLEBUFFERS
  if (numsamples > 1) {
    PRIVATE(this)->glformat->setSampleBuffers(true);
    PRIVATE(this)->glformat->setSamples(numsamples);
  }
  else {
    PRIVATE(this)->glformat->setSampleBuffers(false);
  }
  if (PRIVATE(this)->currentglwidget) PRIVATE(this)->buildGLWidget();
#endif // HAVE_QGLFORMAT_SETSAMPLEBUFFERS
}
But apparently it indeed only works if a sampling of >= 1 is set and setting it to 0 or leaving the default of -1 doesn't work at all.
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Test request: quarter based viewer

Post by wmayer »

According to Quarter it apparently is possible to change the context during runtime:

Code: Select all

  If you want to modify the GL format for an existing QuarterWidget, you can
  set up a new GL context for the widget, e.g.:

  \code
  QGLContext * context = new QGLContext(QGLFormat(QGL::SampleBuffers), viewer);
  if (context->create()) {
    viewer->setContext(context);
  }
When doing so in FreeCAD it gives a couple of warnings (on Windows) and does nothing

Code: Select all


void View3DInventorViewer::setAntiAliasingMode(View3DInventorViewer::AntiAliasing mode)
{
    int buffers = 1;
    SbBool smoothing = false;

    switch(mode) {
    case Smoothing:
        smoothing = true;
        break;

    case MSAA2x:
        buffers = 2;
        break;

    case MSAA4x:
        buffers = 4;
        break;

    case MSAA8x:
        buffers = 8;
        break;

    case None:
    default:
        break;
    };

    if(getSoRenderManager()->getGLRenderAction()->isSmoothing() != smoothing)
        getSoRenderManager()->getGLRenderAction()->setSmoothing(smoothing);

    QGLWidget* gl = static_cast<QGLWidget*>(this->viewport());
    QGLFormat format = gl->format();
    if(format.samples() != buffers) {
        //Base::Console().Message("To change multisampling settings please close and open the 3d view again");
        format.setSamples(buffers);
        QGLContext * context = new QGLContext(format, gl);
        if (context->create())
            gl->setContext(context);
        else
            delete context;
    }
}
Then I have a further question: QuarterWidget was derived from QGLWidget before and now it's QGraphicsView. Wouldn't it work to undo this change and derive SoQTQuarterAdaptor from QGraphicsView and inside SoQTQuarterAdaptor set QuarterWidget as the viewport? This way (if it works) the Quarter sources don't need to be changed that much.


Nevertheless, here is an updated patch which includes some changes to build with Coin3.x and with MinGW.
Attachments
quarter2.patch.zip
(9.13 KiB) Downloaded 53 times
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Test request: quarter based viewer

Post by ickby »

Hello,

the QGLWidget context switching never worked for me so I ommited this option. I think the best way to allow the aliasing-setting change again on the fly is just to set a new viewport to the qgraphicsview.
Then I have a further question: QuarterWidget was derived from QGLWidget before and now it's QGraphicsView. Wouldn't it work to undo this change and derive SoQTQuarterAdaptor from QGraphicsView and inside SoQTQuarterAdaptor set QuarterWidget as the viewport? This way (if it works) the Quarter sources don't need to be changed that much.
This would not work, or to be more clear, it could be made to work but would also need changes in the Quarter code. The thing with a viewport of the QGraphicsView is that it never gets any events, they are captured by the GraphicsView. So you would need to change the QuarterWidget eventhandler setup to catch events on the external QGraphicsView instead of itself. Furthermore it also does not capture repaint events. So you would need to call the render methods of the QuaterWidget from the GraphicsView which currently is protected. So more changes to QuarterWidget. Then the SoRenderManager render callbacks (to update when the scene changes) go to the the QuarterWidget, if it is the ViewPort one needs to change that too. Furthermore one would need to rewrite many of the quarter methods again in the QGraphicsView. All this is IMHO way more work than the very small changes one need to do to port the QuarterWidget to be based on QGraphicsView. This basicly only needs to rename paintGL and resizeGL to the appropriate standart event handlers paintEvent and resizeEvent.
Post Reply