[Feature Request] Wiring plan based on TechDraw

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by Evgeniy »

Ok im create coustom workbench Python Qt example:

https://github.com/FreeCAD-Tools/FreeCA ... ch_Example

It creates a Spreadsheet widget.
I wonder if it is possible to create FeaturePython so that when it is selected, a window with QGraphicsScene opens?
Just not a widget, but a normal tab...
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Wiring plan based on TechDraw

Post by wandererfan »

edi wrote: Tue Nov 29, 2022 9:13 am Before thinking of the creation of a whole Python created workbench in FreeCAD I have three questions:
Not everything needed is exposed to python yet.

1) The constructor for Gui::GraphvizView.cpp shows how to create a new tab with a QGraphicsView (GraphvizGraphicsView) as central widget. You would then need to get the QGraphics scene back as a QtGui.QGraphicsScene. Maybe Gui::PythonWrapper::fromQWidget(QGraphicsView) to get a python QGraphicsView, then myView.scene() to get the python QGraphicsScene.

2) new_obj = myDocument.addObject("App::FeaturePython", "myObject")
but you would want to create a new type derived from App::FeaturePython.
see Draft/draftobjects/base.py?

3) see Draft/draftviewproviders?
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by Evgeniy »

wandererfan wrote: Tue Nov 29, 2022 2:30 pm Not everything needed is exposed to python yet.
What is needed?

The central widget can be accessed via:

Code: Select all

mw = FreeCADGui.getMainWindow()
mw.centralWidget()
But how does QGraphicsView connect to FeaturePython? That is possible?
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by Evgeniy »

edi wrote: Tue Nov 29, 2022 9:13 am Documentation of the Qt graphic system: https://doc.qt.io/qt-6/qgraphicsscene.html Scroll down to Detailed Description. Some 100 pages. Without understanding this documentation it is not possible to create graphics in Qt. The Viewproviders use Qt graphics very intensive.
qgraphicsscene - this is the simplest part. It is much more difficult to create and embed this class in Python Feature so that it looks normal.
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by edi »

Qt organizes its windows (called widgets) like a Matrjoschka. Included in the main window is a container object, which has included the next objects, which have included the next containers, which have included ...

As an example creating a non graphic dialog, download TechDrawTools.FCMacro: https://forum.freecadweb.org/viewtopic.php?f=35&t=55029 . Have a look at function setupUi().

As an example creating a graphic dialog, download SurfaceSymbols.FCMacro: https://forum.freecadweb.org/viewtopic. ... 1&start=10 . Have a look at function createSceneItems(). The scene is just the main graphic container.

Look at Detailed Description of all used Qt functions in the official dokumentation (see my last post).
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Wiring plan based on TechDraw

Post by wandererfan »

Evgeniy wrote: Tue Nov 29, 2022 7:04 pm The central widget can be accessed via:
AFAIK, there is no way to add a new MDIView (tab) using Python. Once you have the interesting MDIView, then yes, you can retrieve the central widget.

You could create the QGraphicsView in a dialog as in @edi macro, but it would not look like the other tabs.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by Evgeniy »

edi wrote: Wed Nov 30, 2022 10:08 am As an example creating a graphic dialog, download SurfaceSymbols.FCMacro: https://forum.freecadweb.org/viewtopic. ... 1&start=10 . Have a look at function createSceneItems().
Creating symbols is not a problem. My prototype does it quickly and conveniently.

https://github.com/FreeCAD-Tools/FreeCAD_Electric

For example when you click on a lamp, node, or switch, they are added to the center of the sheet.
By using svg, is possible to generate any symbols easily.

What should be changed in TechDraw:

Problem #1 - is the lack of a convenient and fast tool for drawing wires in Tech Draw.
For example, I don't like the fact that to add an Annotation Line, you first need to click in the Task panel, pick points, then save points and press Confirm. This is too slow and long for the wire editor, there needs some other class similar to the Annotation Line. So that it joins two svg symbols. Ideally, the symbol should have pins (it's like the vertices of 2D projections) so that the wire connects only to these pins, and not to the picture itself. In theory, if we move the symbol, then one of the ends of the wire also moves.
It would be great if the mechanics of this class could be modeled in Python. To do this, I suppose this needs direct access to the QGraphicsObject of the TechDraw sheet and access to the mouse events like : mouseReleaseEvent(self, event), mousePressEvent(self, event), mouseMoveEvent(self, event). And I think the setMouseTracking() parameter of the sheet must be manageable so that it can be set as True. It is not yet clear exactly how this can be done, but in general it is something like this.

In addition, I do not like that annotations (lines and text) when added are added not to the sheet itself, such as svg symbols, but to the root of the project. Which in my opinion clogs up the project. The contents of the sheet can be collapsed, but there is no annotation.

Problem #2 - it would be nice if the sheet had a grid with possibility to set grid step and the positions of the symbols could be tied to this grid (to do this, needs to add a new boolean property: "snap to grid" true/false). (However, the wires should also be tied to the grid. But it's too early to talk about it yet)

This is probably the minimum, but this basis would be enough for at least some drawing.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by Evgeniy »

wandererfan wrote: Wed Nov 30, 2022 3:42 pm AFAIK, there is no way to add a new MDIView (tab) using Python.
I don't know about tabs, but I think it's quite possible to attach custom form on top of all tabs. However, it does not matter.

And how does TechDraw add its sheet tab to the list of tabs? Is there some special C++ function in the FreeCAD kernel?
Is it really impossible to repeat this through Python?

wandererfan wrote: Wed Nov 30, 2022 3:42 pm You could create the QGraphicsView in a dialog as in @edi macro, but it would not look like the other tabs.
Yes, I think it's a bad idea. Probably just for the sake of experiments.
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by edi »

Find attached a script creating a new MDI view, adding a scene showing some geometric stuff.

Code: Select all

''
Create a new Tab in the main window, an do some graphic stuff
'''
from PySide import QtGui
def createTestScene():
    '''create test scene'''
    scene = QtGui.QGraphicsScene()
    scene.line1 = scene.addLine(-10,-115,90,-116)
    scene.ellipse = scene.addEllipse(20,20,100,50)
    pen = QtGui.QPen(QtGui.Qt.red)
    scene.rect = scene.addRect(-20,-20,40,40,pen)
    scene.rect.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
    scene.line2 = scene.addLine(0,0,50,50)
    scene.line2.setFlag(QtGui.QGraphicsItem.ItemIsSelectable)
    scene.text = scene.addText('Hello world')
    return scene

def addMDIView(view,tabText):
    '''add new MDIView and set tab text'''
    mainWindow = FreeCADGui.getMainWindow()
    mdiArea = mainWindow.findChild(QtGui.QMdiArea)
    subWindow = mdiArea.addSubWindow(view)
    subWindow.show()
    mdiArea.setActiveSubWindow(subWindow)
    tab = mainWindow.findChildren(QtGui.QTabBar)[0]
    tab.setTabText(tab.count()-1,tabText)

scene = createTestScene()
view = QtGui.QGraphicsView()
view.setScene(scene)
addMDIView(view,'New  tab')
Everything is made in Qt. The problem is, how to announce FreeCAD what happened ? That means to create an item in the Combo view, which can be selected/deselected/deleted.
User avatar
czinehuba
Posts: 159
Joined: Mon Oct 15, 2018 4:59 am
Location: UK
Contact:

Re: [Feature Request] Wiring plan based on TechDraw

Post by czinehuba »

Not sure if this is relevant, but there is another FOSS software for electrical drawings.
If this helps at all..... Either use some of it's code...
https://qelectrotech.org/
Post Reply