New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

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!
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by mariwan »

I am working on a new widget set in the 3D world. They must be used in interfacing the direct modeling tools.
The idea is to draw widgets in the 3D world. A window-widget will take care of the events .. nothing will be drawn by that widgets. It is kinda a container for the events which later will be distributed to the children.
Different kind of widgets will be implemented and drawn on the screen depending on the commands they call them to draw.
I am a fan of FLTK. Naming and the way I write the code will be/should be similar to FLTK. But sure we are not drawing on Windows/Xserver system, but on 3DCoin.
I would appreciate any idea, input for making this happen in the best way.
Any help, idea will be greatly appreciated.
I didn't put the code in the same git rep due to not breaking the Design456. I have a new rep for just that function .. I didn't want to make other branches either so I don't confuse users downloading the Design456.
Here is the new rep :

https://github.com/MariwanJ/newWB
hyarion
Posts: 139
Joined: Fri Jun 26, 2020 6:08 pm

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by hyarion »

If it’s just a different version of the same wb, why not just create an extra branch in your main repo instead? That way you can get merge and cherry pick between the two.

Regarding your widget system. I like the idea of adding widgets in the 3d view but why not use qt and place the widgets according to an anchor point in the 3d scene(update position when model or camera updates)? This way the widget could always be floating on top and rotate with the model of you orbit around it. You would also avoid reinventing a widget system and widgets can be shared between the normal panel-based system and your new in-3d-view system.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by wmayer »

Here is an overview of the classes offered by the official OpenInventor SDK: https://developer.openinventor.com/refm ... g_viz.html

It offers a lot of basic GUI elements but it won't be much fun to try to extend Coin3D by such functionality -- and the good thing is that we don't have to.
When we moved from SoQt to Quarter a couple of years ago we modified the Quarter code and replaced the very base class QOpenGLWidget with QGraphicsView.

This means you can use the functionality offered by QGraphicsView / QGraphicsScene and you can easily embed your custom widgets which I hardly believe is so easily doable with the official OpenInventor API.
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by mariwan »

Hi, this mean I am on the wrong path.
But since I don't know how the exact drawing is going on .. (You need a lot of time to read the code/& understand) I thought that Selection of objects (when the color is changing ) is made in COIN3D? or when the face becomes yellow under the mouse? Isn't the COIN3D?
The relation between QT and TOPOShape is not clear. I don't think drawing from OpenCascad can be selected or highlighted.
I think freecad draw on top of the toposhape a new drawing which simulate selecting or mouse over the object which is the Toposhape object.
I don't know ... this is a guessing. When I looked at the DRAFT I see for every drawing (wire, circle ..etc) there is a GUI version which is COIN3D.
Is that correct?
If that is the case, so you have to have several kind of drawing in COIN3D (square, line, circle, oval, ..etc) which is why I started thinking of making the widgets.
Lack of sample code, and explanation (simple how things are done) make your life much harder in developing here.
I don't complain but that is my reality.
Please look at this image. It is from 123D design. I know some are QT or whatever GUI they uses (like no. 1) but no 2 and 3 (shading or selection) I don't know if they are the 3D Drawing or it is the GUI.
Specially the wheel is it QT/GUI or it is int the 3D world?
I hope you might be able explain simply how freecad interact with the topshapes. thanks.

EDIT: I am sure that Draft draw in the coin world lines, arc ..etc Which is not the real object draft create. It is temporary.
Attachments
123D Design.JPG
123D Design.JPG (245.29 KiB) Viewed 1657 times
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by mariwan »

Look at gui_edit.py in draft .

Code: Select all

class Edit(gui_base_original.Modifier):
    """The Draft_Edit FreeCAD command definition.

    A tool to graphically edit FreeCAD objects.
    Current implementation use many parts of pivy graphics code by user "looo".
    The tool collect editpoints from objects and display Trackers on them
    to allow editing their Shape and their parameters.
This is the object that draw over the Toposhape object a drawing which is the simulation of mouseover, click, ..etc .. So, you must draw in 3DCOIN (not QT) the shapes (line, squre, curve ..etc) to simulate a Toposhape interactive action/command.
Am I wrong?
hyarion
Posts: 139
Joined: Fri Jun 26, 2020 6:08 pm

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by hyarion »

Buttons, input fields and such should be handled in qt if possible (nr1 in your screenshot)

If you are creating a new 3d manipulator then I think it should be done in coin3d.

For simulated objects/previews, look at how Part Design is doing previews of cut volume. You might find something interesting there. My guess is that it uses opencascade to create the geometries, but not storing it in the document. Then drawing it with coin3d with a semi-transparent material.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by ickby »

The FreeCAD 3D visualisation basically works like this:
  1. There is a general rectangular Area in which everything is rendered with OpenGL. This is what you see as 3D view. This are is a QT widget called QGraphicsView. The widget is embedded in the overall UI, and allows to render all kinds of opengl stuff in it.
  2. One thing that is rendered onto the QGraphicsView is the Coin3D scene graph. Hence in this step, everything thats in the scene graph is put onto the render area
  3. Other things can than be rendered on top of that. There are some spare examples around over freeCAD, for example the FEM postprocessing scales. Basically anything OpenGL can be drawn
This means for your idea you have 2 options: First to add everything you need to the scenegraph, and use coin to achieve your functionality. Or second, use OpenGL to draw everything ontop afterwards.

The second step is made very easy by the fact, that a QGraphicsView allows to add default QtWidgets to it which are than rendered via opengl. here is a simple example (works when you have a document open):

Code: Select all

from PySide2 import QtWidgets

def findInChildren(obj, searched):
	for child in obj.children():
		if isinstance(child, searched):
			return child
		else: 
			res = findInChildren(child, searched)
			if res:
				return res

	return None

view = findInChildren(Gui.getMainWindow(), QtWidgets.QGraphicsView)
widget = QtWidgets.QLineEdit()

proxy = view.scene().addWidget(widget)
You can than scale, move and rotate the widget vie the proxy object in the script. This way you have a very powerful widget library usable. The difficult part is to align the position and scale to the 3d View, so that it is automatically moved and transformed when the relevant objects in the 3d view are rotated. This transformation comes for free when using coin, but than you need to implement the whole UI and interaction stuff yourself. You can choose.

Also note: When using the "draw ontop" approach it is impossible to get things "behind objects" in the scene graph. As oth are rendered one after the other every widget is simply put ontop.

With all that said most likely it makes most sense to draw 3D manipulators in coin, and input field with the QtWidget apporach
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by galou_breizh »

ickby wrote: Fri Mar 26, 2021 7:51 am
The code snippet makes a QLineEdit appear but FreeCAD crashes when I click on it.

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
#0  /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7f1e1a099210]
#1  /lib/x86_64-linux-gnu/libc.so.6(+0x18b675) [0x7f1e1a1de675]
#2  0x7f1e1a50e6eb in QByteArray::append(char const*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x1b
#3  0x7f1e1ae237ac in QOpenGLEngineSharedShaders::findProgramInCache(QOpenGLEngineShaderProg const&) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x71c
#4  0x7f1e1ae23abc in QOpenGLEngineShaderManager::useCorrectShaderProg() from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x19c
#5  /lib/x86_64-linux-gnu/libQt5Gui.so.5(+0x49e4f2) [0x7f1e1ae2a4f2]
#6  /lib/x86_64-linux-gnu/libQt5Gui.so.5(+0x49f445) [0x7f1e1ae2b445]
#7  0x7f1e1ad1fe73 in QPaintEngineEx::fillRect(QRectF const&, QBrush const&) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x93
#8  0x7f1e1ad4aa46 in QPainter::fillRect(QRectF const&, QBrush const&) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x126
#9  0x7f1e1abb61f0 in QTextLayout::drawCursor(QPainter*, QPointF const&, int, int) const from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x280
#10  0x7f1e1b232560 in QWidgetLineControl::draw(QPainter*, QPoint const&, QRect const&, int) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x1e0
#11  0x7f1e1b228d4a in QLineEdit::paintEvent(QPaintEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x52a
#12  /usr/lib/python3/dist-packages/PySide2/QtWidgets.cpython-38-x86_64-linux-gnu.so(+0x4386e3) [0x7f1de925e6e3]
#13  0x7f1e1b1242b6 in QWidget::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x286
#14  0x7f1e1b22dd32 in QLineEdit::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0xb2
#15  /usr/lib/python3/dist-packages/PySide2/QtWidgets.cpython-38-x86_64-linux-gnu.so(+0x434803) [0x7f1de925a803]
#16  0x7f1e1b0e1a66 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x86
#17  0x7f1e1b0eb0f0 in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x330
#18  0x7f1e1c78efb8 in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x88
#19  0x7f1e1a6c793a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#20  0x7f1e1b11cf4a in QWidgetPrivate::sendPaintEvent(QRegion const&) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x3a
#21  0x7f1e1b11d799 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x7f9
#22  0x7f1e1b1212d8 in QWidgetPrivate::render(QPaintDevice*, QPoint const&, QRegion const&, QFlags<QWidget::RenderFlag>) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x158
#23  0x7f1e1b1217f3 in QWidget::render(QPainter*, QPoint const&, QRegion const&, QFlags<QWidget::RenderFlag>) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x2e3
#24  0x7f1e1b3fe62a in QGraphicsProxyWidget::paint(QPainter*, QStyleOptionGraphicsItem const*, QWidget*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x13a
#25  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x48d529) [0x7f1e1b404529]
#26  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x49eabe) [0x7f1e1b415abe]
#27  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x4a1511) [0x7f1e1b418511]
#28  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x4a21f0) [0x7f1e1b4191f0]
#29  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x4a2742) [0x7f1e1b419742]
#30  0x7f1e1b43d9f9 in QGraphicsView::paintEvent(QPaintEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x579
#31  0x7f1e1ca67770 in SIM::Coin3D::Quarter::QuarterWidget::paintEvent(QPaintEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0xb0
#32  0x7f1e1ca6f3b6 in SIM::Coin3D::Quarter::SoQTQuarterAdaptor::paintEvent(QPaintEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x46
#33  0x7f1e1b1242b6 in QWidget::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x286
#34  0x7f1e1b1d1d52 in QFrame::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x22
#35  0x7f1e1b43c421 in QGraphicsView::viewportEvent(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x161
#36  0x7f1e1ca679fe in SIM::Coin3D::Quarter::QuarterWidget::viewportEvent(QEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x9e
#37  0x7f1e1a6c764b in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x9b
#38  0x7f1e1b0e1a55 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/li
bQt5Widgets.so.5+0x75
#39  0x7f1e1b0eb0f0 in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x330
#40  0x7f1e1c78efb8 in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x88
#41  0x7f1e1a6c793a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#42  0x7f1e1b11cf4a in QWidgetPrivate::sendPaintEvent(QRegion const&) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x3a
#43  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x17c732) [0x7f1e1b0f3732]
#44  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x17cdc1) [0x7f1e1b0f3dc1]
#45  0x7f1e1b10c385 in QWidgetPrivate::syncBackingStore() from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0xa5
#46  0x7f1e1b124cac in QWidget::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0xc7c
#47  0x7f1e1b239148 in QMainWindow::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x68
#48  0x7f1e1cb50e0b in Gui::MainWindow::event(QEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x7b
#49  0x7f1e1b0e1a66 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x86
#50  0x7f1e1b0eb0f0 in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x330
#51  0x7f1e1c78efb8 in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x88
#52  0x7f1e1a6c793a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#53  0x7f1e1a6ca5b8 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x148
#54  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x49344b) [0x7f1e1b40a44b]
#55  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x49914d) [0x7f1e1b41014d]
#56  0x7f1e1a6f3d5a in QObject::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x23a
#57  0x7f1e1b41dfb3 in QGraphicsScene::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x93
#58  0x7f1e1b0e1a66 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x86
#59  0x7f1e1b0eb0f0 in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x330
#60  0x7f1e1c78efb8 in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x88
#61  0x7f1e1a6c793a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#62  0x7f1e1a6ca5b8 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x148
#63  /lib/x86_64-linux-gnu/libQt5Core.so.5(+0x2def67) [0x7f1e1a71ff67]
#64  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x27d) [0x7f1e1837517d]
#65  /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x52400) [0x7f1e18375400]
#66  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x33) [0x7f1e183754a3]
#67  0x7f1e1a71f565 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x65
#68  0x7f1e1a6c64db in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x12b
#69  0x7f1e1a6ce246 in QCoreApplication::exec() from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x96
#70  0x7f1e1c6fd256 in Gui::Application::runApplication() from /usr/lib/freecad-daily-python3/lib/libFreeCADGui.so+0x1816
#71  freecad-daily(+0x4cde) [0x556f52895cde]
#72  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f1e1a07a0b3]
#73  freecad-daily(+0x506e) [0x556f5289606e]
Gaël

OS: Ubuntu 20.04.2 LTS (i3/i3)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: e8566f22bbeb0b7204e3c45519d0963e8881100b
Python version: 3.8.5
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.5.1
Locale: C/Default (C)
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by ickby »

hm strange, I tested it with 0.18 and 0.19 on Manjaro Linux and it works well. (Except the text in the line edit that is deformed) Maybe my newer Qt version is helping? Don't know

Code: Select all

OS: Manjaro Linux (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24226 (Git)
Build type: Unknown
Branch: master
Hash: 7659bb0dae90bfd3280e9d3d0ce9716ab12b4f5d
Python version: 3.9.1
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/Germany (en_DE)

User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: New Widget system for 3DCoin (Aimed to be used with direct modeling tools)

Post by mariwan »

Thank you very much for your reply and voluble information. I choose coin3d. I will try my best to find the easiest way to implement the desired functionality.
You need sometime to understand how you do things.. So I continue doing what I started with.
There are many questions that I must find an answer for. but step by step.
Note:
The example works and it is good to know.thank you. It didn't crash.
Post Reply