[Feature Request] Wiring plan based on TechDraw
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: [Feature Request] Wiring plan based on TechDraw
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...
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...
- wandererfan
- Veteran
- Posts: 6326
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: [Feature Request] Wiring plan based on TechDraw
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?
Re: [Feature Request] Wiring plan based on TechDraw
What is needed?
The central widget can be accessed via:
Code: Select all
mw = FreeCADGui.getMainWindow()
mw.centralWidget()
Re: [Feature Request] Wiring plan based on TechDraw
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 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.
Re: [Feature Request] Wiring plan based on TechDraw
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).
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).
- wandererfan
- Veteran
- Posts: 6326
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: [Feature Request] Wiring plan based on TechDraw
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.
Re: [Feature Request] Wiring plan based on TechDraw
Creating symbols is not a problem. My prototype does it quickly and conveniently.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().
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.
Re: [Feature Request] Wiring plan based on TechDraw
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.wandererfan wrote: ↑Wed Nov 30, 2022 3:42 pm AFAIK, there is no way to add a new MDIView (tab) using Python.
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?
Yes, I think it's a bad idea. Probably just for the sake of experiments.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.
Re: [Feature Request] Wiring plan based on TechDraw
Find attached a script creating a new MDI view, adding a scene showing some geometric stuff.
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.
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')
Re: [Feature Request] Wiring plan based on TechDraw
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/
If this helps at all..... Either use some of it's code...
https://qelectrotech.org/