[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!
aapo
Posts: 615
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by aapo »

tobiasfalk wrote: Fri Jan 13, 2023 8:50 am I have looked a bit in to FreeCAD Workbench development and if I understand it correctly, the main Adwanteg of using C++ for it would be the speed, but I wodered, would be there other benefites to developing, a Workbensch like this, in C++.
Using certain Qt functionalities nowadays requires subclassing relevant Qt classes and overriding the methods there in order to make your own painting or UI logic, especially for mouse + keyboard. I'm not fully sure, but in the FreeCAD codebase this kind of functionality requires using C++, because the FreeCAD core is coded in C++. If everything would have been coded with Python from the start, that wouldn't be a problem, but currently you can't do the subclassing with Python, because there are no Python classes in the base code, just C++. Some of the functionality has been exported to Python, but I guess not everything. Thus, making a similar 2D paper and 2D UI logic as is present in TechDraw and attaching it to FreeCAD might be difficult.

I'm not 100 % sure, though, because there might be some way to steal the 'focus' and use 100 % Python drawing for the Workbench canvas. So, doing everything in Python is certainly not a problem, but attaching it cleanly to FreeCAD might be.
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 »

tobiasfalk wrote: Fri Jan 13, 2023 8:50 am
aapo wrote: Fri Jan 13, 2023 12:19 pm
A hybrid approach is probably best. Some C++ to connect to the existed TD functions, with new dialog and painting functions in Python.

I have some experimental code that draws on top of a Page. All the drawing is done in Python. I can push it to Github if anybody is interested, but it is a bit rough.
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by edi »

wandererfan wrote: Fri Jan 13, 2023 3:05 pm I have some experimental code that draws on top of a Page. All the drawing is done in Python. I can push it to Github if anybody is interested, but it is a bit rough.
Yes please push it to Github.

I experimented creating drawings in Python. See attached testmacro.
QtGraphic03.FCMacro
(4.38 KiB) Downloaded 54 times
The testmacro creates two testsymbols (each a rectangle with a X inside) which are connected by a horizontal/vertical line. The symbols can be moved using a 25 pixel grid. The connection line is following the movement.

I could not solve the two problems:

1. How to make the graphic scene visible to Python ? I think it is the attribute: ViewProviderPage::m_graphicScene

2. How to create a QGraphicsItem (an item having lines shown in the scene) which inherits App::DocumentObject. I mean which is shown in the model tree, and can be managed like a Part::FeaturePython. Is this possible without creating a new App::Draw... and a new Gui::Viewprovider... ?
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: Fri Jan 13, 2023 4:23 pm 1. How to make the graphic scene visible to Python ? I think it is the attribute: ViewProviderPage::m_graphicScene

2. How to create a QGraphicsItem (an item having lines shown in the scene) which inherits App::DocumentObject. I mean which is shown in the model tree, and can be managed like a Part::FeaturePython. Is this possible without creating a new App::Draw... and a new Gui::Viewprovider... ?
https://github.com/WandererFan/FreeCAD/ ... sAndTraces. It is quite limited in function - it can create a new Diagram (derived from Page), add a Symbol (based on an Svg file) to the Diagram and add a Trace between 2 Symbols. Save and restore works too.
No editing, no deletes, no autoroute and Traces are not attached to the endpoint Symbols.


For 1) I added a new function in TechDrawGui - getSceneForPage(DrawPage). This isn't in master branch yet.

For 2) In TechDrawGu, we don't use inheritance to connect QGI's to the DocumentObject. Each QGI carries the name and a pointer to the "owner" DocumentObject. If we have the QGI and want the DocumentObject, we call getViewObject. If we have the DocumentObject and want the QGI, we get all the QGIs from the scene, then look for one with the same name.

In the SymbolsAndTraces branch, my plan was to use the data()/setData() methods of QGI to carry an identifier back to the selection mechanism in MDIViewPage.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by Evgeniy »

Thank to all for the answers.

I have suspended the development of Electrician for now, because without a drawing editor it makes little sense.

And the development of such an scheme editor consumed a lot of time.

I named it as Schematics.

Topic on forum: https://forum.freecadweb.org/viewtopic.php?f=8&t=75340
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by edi »

wandererfan wrote: Sat Jan 14, 2023 3:38 pm https://github.com/WandererFan/FreeCAD/ ... sAndTraces. It is quite limited in function - ...
Thank you for publishing the code in Github.
I fetched and compiled the SymbolsAndTraces branch. Very interesting idea to create an extension of a c++ workbench in Python. I will need some time to recognise the code.

First tests:

- Add Diagram command is working fine.
- Add Symbol command is working fine, using symbols imported from svg files.
- Remove Symbol command does nothing, because everything inside Activated is commented. The file TaskRemoveSymbol.ui is missing.
- Add Trace command: the dialog openes, but the command does nothing. How to define ports ?
- Remove Trace command does nothing.

A proposal for the Add Symbol command: "Add from directory", imports all svg files in a directory to the selection list.
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: Wed Jan 18, 2023 4:50 pm - Remove Symbol command does nothing, because everything inside Activated is commented. The file TaskRemoveSymbol.ui is missing.
- Remove Trace command does nothing.
Well, I did say it was a bit rough. I haven't got to removing things yet.
A proposal for the Add Symbol command: "Add from directory", imports all svg files in a directory to the selection list.
good idea.
- Add Trace command: the dialog openes, but the command does nothing. How to define ports ?
try the latest version, it should make traces. Only the "default" port at local (0,0) is available. I'm thinking that eventually we might have xml definitions of symbols with attributes for a file for the svg/jpeg/??? representation and port definitions.

Still learning how to make a decent video....
Attachments
addTrace.gif
addTrace.gif (523.03 KiB) Viewed 1748 times
User avatar
tobiasfalk
Posts: 93
Joined: Fri Feb 05, 2021 2:35 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by tobiasfalk »

wandererfan wrote: Wed Jan 18, 2023 11:36 pm
A proposal for the Add Symbol command: "Add from directory", imports all svg files in a directory to the selection list.
good idea.
- Add Trace command: the dialog openes, but the command does nothing. How to define ports ?
try the latest version, it should make traces. Only the "default" port at local (0,0) is available. I'm thinking that eventually we might have xml definitions of symbols with attributes for a file for the svg/jpeg/??? representation and port definitions.
I think that using svg's with extra atributs would be the esyest and fastestway, this would have the advantage that the symbols could be seen without a special edior. What defenetly would be needed are special attributtes, for this I used @Evgeniy Lamp https://gitlab.com/FreeCAD-Tools/FreeCA ... vg?plain=1 as base and changed it a bit:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<svg width="30mm" height="10mm" version="1.1" viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg">
    <description 
                    name="Lamp"
                    designator="L"
                    description="This is the Simbol for a lamp"
                    origin="https://forum.freecadweb.org/viewtopic.php?f=8&t=75340"
                    name-alias="Glühbirne; ランプ; light bulbs"
                    symbol-alias="Lamp-Some-Other-Style.svg"
                    3d-model-name="model name"/>
    <g stroke="#000000" fill="none" stroke-width=".5">
        <circle cx="15" cy="5" r="3" fill="#ffffff"/>
        <path d="m18 5h7"/>
        <path d="m12 5h-7"/>
        <path d="m13 3 4 4"/>
        <path d="m13 7 4-4"/>
        <pin pin="1" x="5" y="5" type="electric" e-type="passiv" 3d-model-ref="point-name" connection-type="screw-terminal"/>
        <pin pin="2" x="25" y="5" type="fiber"/>
    </g>
</svg>
The description tag is for general information about the symbol with:
  • name for the name of the symbol, should also be the file name
  • designator for the symbol designator, like "L1", "L2", "K1", "K2", ..
  • description for a descripion about the symbol
  • origin for puting the origin of the model, where it comes from/who it created
  • name-alias for synonyms and translations, makes searching for something easyer
  • symbol-alias for referencing a other symbol that displays the same thing but in a different form, like there is a US and European version for resistors
  • 3d-model-name for linking the symbol to a FreeCAD model/file, this would allow future fetures where this WB interacts with the 3D space

Than I changed the circle that where use as pins to a pin tag, this tag has the folowing options:
  • pin is the pin number, could also be "A1", "B2" and so on, in some cases you want those numbbers also be displayed nearr the pin but I would do this with svg tex
  • x and y for the location
  • type for diferentiate betwen diferent types of pins, for example a electricla, fiber or hydrolic connection, with this itt would be posible to prevent th connection betwen a hydraulic and a fiber connection :D
  • e-type this is a Idea for not only saying that general type but also how the pin interacts with other pins, posible value options would be "passive" for pins that are passive and do not much or "input" for pins that only take signals in, ther could than also be a h-type for hydrolics and so on, if done correctly a rule check could be implemented/done where FeeCAD checks that you do not connect two input to each othe witthout a output on the line
  • 3d-model-ref this is for location the pin in the 3D space, I only say toponaming problem
  • connection-type this is for defing how this pin is representaed in the 3D space, is it a "screw terminal" or a othe connection type, for fibers the connector name("LC") and hydrolics the thrread pich(?)
Attachments
Lamp.svg
(989 Bytes) Downloaded 47 times
User avatar
tobiasfalk
Posts: 93
Joined: Fri Feb 05, 2021 2:35 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by tobiasfalk »

I do not know if this is of any help but I made a repo(https://github.com/tobiasfalk/FreeCAD_T ... an_Symbols) with some symbols. If I find the time for it I will work on it but I hapaly welcome other if the want to add some. In the readme there is a explanation for the added tags that are not normal SVG tags and a small collection of refference links, if you add symbolse and "copy"/base your desing on alrady existing ones please add where you got it, I think it also is no proble if you put the name of a Book or so there.
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 »

tobiasfalk wrote: Thu Jan 19, 2023 8:21 am I think that using svg's with extra atributs would be the esyest and fastestway
Actually, I was thinking about keeping the Svg representation separate from the symbol definition. That way we could use other representations (like jpeg).

Code: Select all

<?xml version='1.0' encoding='utf-8'?>
<!--
 FreeCAD Diagram Symbol Definition, see https://www.freecadweb.org for more information...
-->    
<Symbol Name="TestSymbol2" Anchor="(5,5)">
    <Representation Type="svg" File="testSymbol2.svg"/>
    <Ports Count="2">
        <Port Name="In" Anchor="(0,5)" MaxConnect="1"/>
        <Port Name="Out" Anchor="(10,5)" MaxConnect="1"/>
    </Ports>
</Symbol>
Post Reply