[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 »

edi wrote: Thu Dec 01, 2022 1:36 pm a script creating a new MDI view, adding a scene showing some geometric stuff.
This is a very interesting example, I was just thinking of attaching a scene to a window.
How to add SVG item https://doc.qt.io/qt-6/qgraphicssvgitem.html to scene? I think it should not be difficult...
If i understand the sheet template in TechDraw is qgraphicssvgitem?
edi wrote: Thu Dec 01, 2022 1:36 pm 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.
I'm also trying to figure out how this happens and whether it can be repeated through Python.
What about MDI in Tech Draw happens here...

https://github.com/FreeCAD/FreeCAD/blob ... erPage.cpp
user1234
Veteran
Posts: 3336
Joined: Mon Jul 11, 2016 5:08 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by user1234 »

czinehuba wrote: Thu Dec 01, 2022 5:24 pm 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/
I also do not understand why not use this or helping them, to bundle the spare resources. I tried it a little bit (the last electrical plans for me are many years ago), it is far from perfect, but it is not bad. Cross references on different pages seems that does not work atm, or the terminal block is atm just a plugin, but they are already far. Besides i do not think that FreeCAD is made for it, especially for the whole elements and their terminals and contacts, wiring and their path linking and much more. That is a complete different natter and logical, structural build up. Just "drawing" is for wiring plans way too less, equivalent like 3D CAD modeling without parametric. Then you can use MS paint (when you have Windows OS).


Greetings
user1234
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: Thu Dec 01, 2022 1:36 pm 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.
If look at the source code of Tech Draw, it all starts with setEdit:

Code: Select all

bool ViewProviderPage::setEdit(int ModNum)
{
    if (ModNum == _SHOWDRAWING) {
        showMDIViewPage();   // show the drawing
        return false;  //finished editing
    } else if (ModNum == _TOGGLEUPDATE) {
         auto page = getDrawPage();
         if (page) {
             page->KeepUpdated.setValue(!page->KeepUpdated.getValue());
             page->recomputeFeature();
         }
         return false;
    } else {
        return Gui::ViewProviderDocumentObject::setEdit(ModNum);
    }
}
Next, showMDIViewPage() is called:

Code: Select all

bool ViewProviderPage::showMDIViewPage()
{
    if (m_mdiView.isNull()){
        createMDIViewPage();
        m_graphicsScene->addChildrenToPage();
        m_graphicsScene->updateTemplate(true);
        m_graphicsScene->redrawAllViews();
        m_graphicsScene->fixOrphans(true);
    } else {
        m_graphicsScene->redrawAllViews();
        m_graphicsScene->fixOrphans(true);
    }
    m_graphicsView->centerOnPage();

    m_mdiView->viewAll();
    m_mdiView->showMaximized();

    setGrid();

    Visibility.setValue(true);

    return true;
}
In turn, this calls createMDIViewPage()

Code: Select all

void ViewProviderPage::createMDIViewPage()
{
    Gui::Document* doc = Gui::Application::Instance->getDocument
        (pcObject->getDocument());
    m_mdiView = new MDIViewPage(this, doc, Gui::getMainWindow());
    if (!m_graphicsView) {
        m_graphicsView = new QGVPage(this, m_graphicsScene, m_mdiView);
        std::string objName = m_pageName + "View";
        m_graphicsView->setObjectName(QString::fromLocal8Bit(objName.c_str()));
    }
    m_mdiView->setScene(m_graphicsScene, m_graphicsView);
    QString tabTitle = QString::fromUtf8(getDrawPage()->Label.getValue());

    m_mdiView->setDocumentObject(getDrawPage()->getNameInDocument());
    m_mdiView->setDocumentName(pcObject->getDocument()->getName());

    m_mdiView->setWindowTitle(tabTitle + QString::fromLatin1("[*]"));
    m_mdiView->setWindowIcon(Gui::BitmapFactory().pixmap("TechDraw_TreePage"));
    Gui::getMainWindow()->addWindow(m_mdiView);
    Gui::getMainWindow()->setActiveWindow(m_mdiView);
}
This is link to ViewProviderPythonFeature.setEdit

https://github.com/FreeCAD/FreeCAD/blob ... #L350-L388

That's all I could find...

By the way, i found that Tech Draw have a grid. But it not have a attraction function.
grid.png
grid.png (25.57 KiB) Viewed 1802 times
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by Evgeniy »

Added a simple wire editor to the repository (BluePrint class). It's not entirely clear how events work in Qt. Of course, it is difficult to implement this alone.
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by edi »

Evgeniy wrote: Fri Dec 02, 2022 7:47 am If look at the source code of Tech Draw, it all starts with setEdit:
The setEdit methods are executed every time a dialog to edit an object is opened.

Viewproviders are 100% interrupt driven. The interrupts are triggered by the "Selection Manager". This is (for me) one of the most intransparent parts of FreeCAD. The selection manager watches the mouse (and the keyboard) all the time.
An example: you have created a Balloon. Now double-click it. In the Task tab of the Combo view the dialog "Balloon" openes, and you can edit the balloons properties.

What proceeds inside FreeCAD:
1. The Selection Manager observes you have double-clicked a balloon.
2. The function ViewProviderBalloon::setEdit (source: https://github.com/FreeCAD/FreeCAD/blob ... alloon.cpp) is invoked, which calls several other functions.

If you double-click a dimension a similar task proceeds, which openes a dialog to edit the dimensions properties.
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: Fri Dec 02, 2022 9:36 am Added a simple wire editor to the repository (BluePrint class). It's not entirely clear how events work in Qt.
QGraphicsScene (Mod/TechDraw/Gui.QGSPage.cpp) and QGraphicsItem (QGXXXX.cpp) have methods for MouseButtonPress, MouseMove, etc. The way to get access to the events is to derive a new class that overrides those methods.

The full stack would be something like:
App/WiringSymbol - a document object to hold your svg and any other parameters you need
Gui/QGWiringSymbol - a QGraphicsItem that paints the symbol and handles events in the item's bounding rect.
Gui/ViewProvider - (a ViewObject in Python) this is the connection between the document object and the QGraphicsItem.
Gui/TaskWiringSymboil - a dialog for creating a WiringSymbol and setting its properties. This dialog is invoked from a command and from the ViewProvider's setEdit method.
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: Fri Dec 02, 2022 2:30 pm QGraphicsScene (Mod/TechDraw/Gui.QGSPage.cpp) and QGraphicsItem (QGXXXX.cpp) have methods for MouseButtonPress, MouseMove, etc. The way to get access to the events is to derive a new class that overrides those methods.
Can you provide a working example in Python?

May try it based on the code from the repository... It's been cleaned.
https://github.com/FreeCAD-Tools/FreeCA ... /tree/main

wandererfan wrote: Fri Dec 02, 2022 2:30 pm The full stack would be something like:
App/WiringSymbol - a document object to hold your svg and any other parameters you need
Gui/QGWiringSymbol - a QGraphicsItem that paints the symbol and handles events in the item's bounding rect.
Gui/ViewProvider - (a ViewObject in Python) this is the connection between the document object and the QGraphicsItem.
Gui/TaskWiringSymboil - a dialog for creating a WiringSymbol and setting its properties. This dialog is invoked from a command and from the ViewProvider's setEdit method.
The more I study this question, the more it seems to me that it makes sense to use Tech Draw as a basis. Because needs to create a sheet feature, FeaturePython for each element, etc. Rewriting Tech Draw in Python requires the efforts of several people who do not exist. Although what Python is convenient for is for quick and easy code editing and making changes, even for novice programmers.
Too much time spent on code for drawing is not the main task for a good electrician's workbench.



I have a few questions, maybe you could answer them...

1) Even if I add mouse events to QtGui.QGraphicsScene then objects in QtGui.QGraphicsView become stationary. There is some kind of interception of events. Is there anyway to make events not eaten up and work there and there without blocking each other?

2) I can get mouse Events to QtGui.QGraphicsScene. But QtGui.QGraphicsView does not respond to the mouse in any way. Maybe QtGui.QGraphicsView does not accept mouse events at all and they need to be caught from QtGui.QGraphicsScene? I try to do sheet scaling, for via QtGui.QGraphicsView.wheelEvent(self, event) but it doesn't react in any way...

3) For some reason, when moving objects by mouse (setFlag(QtGui.QGraphicsItem.ItemIsMovable)), artifacts (arrays of lines) appear on the QtGui.QGraphicsView...
artefacts.png
artefacts.png (6.37 KiB) Viewed 1680 times

Perhaps this is a BoundingBox error... But the objects are created by means of the library, so Boundingbox should be fine.
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: Fri Dec 02, 2022 9:51 am The setEdit methods are executed every time a dialog to edit an object is opened.
While nothing is clear to me, if there is time, I will watch FeaturePython.
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: Fri Dec 02, 2022 4:04 pm 3) For some reason, when moving objects by mouse (setFlag(QtGui.QGraphicsItem.ItemIsMovable)), artifacts (arrays of lines) appear on the QtGui.QGraphicsView.

Perhaps this is a BoundingBox error... But the objects are created by means of the library, so Boundingbox should be fine.
That definitely looks like BoundingRect issue to me. If the BR is too small, the old graphic doesn't get erased completely.
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: Fri Dec 02, 2022 4:04 pm 1) Even if I add mouse events to QtGui.QGraphicsScene then objects in QtGui.QGraphicsView become stationary. There is some kind of interception of events. Is there anyway to make events not eaten up and work there and there without blocking each other?
IIRC, mouse events go to the widget (QGraphicsView) event handler first, then get forwarded
to the scene's event handler. Unless you have done absolutely everything that should be done
on an event, you have to give it to the parent class. If you don't do this, the event dies
in your event handler.

Code: Select all

class GraphicsView(QtGui.QGraphicsView):
...
    def mousePressEvent(self, event):
        print("md event", event)
        super().mousePressEvent(event);     #let father forward this event to interested parties.
A similar thing happens with QGraphicsScene and QGraphicsItem. The scene gets the event first,
then forwards it to the focus item. If you don't call the ancestor's event handler, then
the item will never see the event.

I'll try to spend some time on this on the weekend.
Post Reply