[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
wandererfan
Veteran
Posts: 6265
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
I get "19:56:14 During initialization the error "No module named 'TranslateUtils'" occurred in /home/wile/.local/share/FreeCAD/Mod/FreeCAD_Electric/InitGui.py" at start up.

Where do I find "TranslateUtils"?
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: Sat Dec 03, 2022 2:31 am Where do I find "TranslateUtils"?
This is for the future. I have removed this module. The repository has been updated. It should work now.
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 7:50 pm That definitely looks like BoundingRect issue to me. If the BR is too small, the old graphic doesn't get erased completely.
After the addition,

Code: Select all

super().mousePressEvent(event);
these artifacts disappeared.
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 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.
I haven't looked at the code. But if I understood everything correctly:
1) when an object is created, a tab is created in the main window.
2) when the user closes the window, the visibility property of the feature sheet changes to false
3) when the user changes visibility to true again, the "Change property: Visibility True" event occurs, which creates the tab again

Now I have a question how to track that the user has closed the tab. The tab should have an event something like on Close...
is there a code example how to catch this event?
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: [Feature Request] Wiring plan based on TechDraw

Post by edi »

Evgeniy wrote: Sat Dec 03, 2022 7:38 pm Now I have a question how to track that the user has closed the tab. The tab should have an event something like on Close...
is there a code example how to catch this event?
Using

Code: Select all

subWindow = mdiArea.addSubWindow(view)
a new subwindow becomes created (exact: a new instance of typ QMdiSubWindow). Save this object (exact: its pointer) in a local variable.

Using:

Code: Select all

subList = mainWindow.findChildren(QtGui.QMdiSubWindow)
you receive a list of all existing subwindows (exact: a list of pointers). Check, using a loop, if your saved object is existing in the list.
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: Sun Dec 04, 2022 9:14 am

Code: Select all

subList = mainWindow.findChildren(QtGui.QMdiSubWindow)
you receive a list of all existing subwindows (exact: a list of pointers). Check, using a loop, if your saved object is existing in the list.

Code: Select all

class MDIViewBluePrint(QtGui.QMdiSubWindow):

    def __init__(self, obj):
        super().__init__()
        self.obj = obj
        self.setMouseTracking(True)
        self.setWindowTitle(self.obj.Name)

    def closeEvent(self, event):
        #print("Tab is closed")
        setattr(self.obj, "Visibility", False)
        super().closeEvent(event)
Thanks i create class inherited from QMdiSubWindow
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

Would you tell how the contents of the Tech Draw sheet are transferred to the print preview window when the user selects "Print Preview" in the main menu?

https://github.com/FreeCAD/FreeCAD/blob ... #L304-L322

Code: Select all

void MDIViewPage::print()
{
//    Base::Console().Message("MDIVP::print()\n");
    getPaperAttributes();

    QPrinter printer(QPrinter::HighResolution);
    printer.setFullPage(true);
    if (m_paperSize == QPageSize::Custom) {
        printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter));
    } else {
        printer.setPageSize(QPageSize(m_paperSize));
    }
    printer.setPageOrientation(m_orientation);

    QPrintDialog dlg(&printer, this);
    if (dlg.exec() == QDialog::Accepted) {
        print(&printer);
    }
}
I understand you are creating your own QPrintDialog

But how do you manage to use it instead of the standard one? Is there some kind of interception of messages?
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

Code: Select all

...
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)
This code is slightly incorrect. No need to search for QTabBar and change the text via setTabText().

Code: Select all

    tab = mainWindow.findChildren(QtGui.QTabBar)[0]
    tab.setTabText(tab.count()-1,tabText)
Just need to set the window title via setWindowTitle and then the tab name will be changed automatically.

Code: Select all

        self.frame = QtGui.QMdiSubWindow()
        self.frame.setWindowTitle(Name)
        self.frame.setWidget(Widget)  

Also made in TechDraw:
https://github.com/FreeCAD/FreeCAD/blob ... #L234-L242

Code: Select all

//called by ViewProvider when Page feature Label changes
void MDIViewPage::setTabText(std::string tabText)
{
    if (!isPassive() && !tabText.empty()) {
        QString cap = QString::fromLatin1("%1 [*]")
            .arg(QString::fromUtf8(tabText.c_str()));
        setWindowTitle(cap);
    }
}
User avatar
wandererfan
Veteran
Posts: 6265
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Wiring plan based on TechDraw

Post by wandererfan »

Evgeniy wrote: Mon Dec 19, 2022 10:48 pm Would you tell how the contents of the Tech Draw sheet are transferred to the print preview window when the user selects "Print Preview" in the main menu?
It has been a while since I looked at this area, but from what I remember, the print preview command sends a message to the MDIView, which calls a print preview method (does nothing in the base MDIView, but is overridden in MDIViewPage) to do the work.

The scene is then rendered onto a QPrinter that is returned by the QPrintPreview dialog.
Evgeniy wrote: Mon Dec 19, 2022 10:48 pm I understand you are creating your own QPrintDialog

But how do you manage to use it instead of the standard one? Is there some kind of interception of messages?
It is just the regular Qt print dialog. This works the same way as print preview. The print command sends a message to the MDIView, which calls the print() method defined in that MDIView (in our case the override method in MDIViewPage).
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 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++.
Post Reply