[Feature Request] Manipulation with cosmetic objects

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
xtemp09
Posts: 72
Joined: Tue Jul 12, 2022 2:16 pm

[Feature Request] Manipulation with cosmetic objects

Post by xtemp09 »

I added a cosmetic line through two points. I realized I need to delete it. If I select it and press "Delete", FreeCAD shows a warning:

Code: Select all

You cannot delete the anchor view of a projection group.
To delete the cosmetic line I need to execute TechDrawRemove Cosmetic Object. To change the appearance I need to execute TechDrawChange Appearance of Lines

It would be great if I just select the line/vertex and press "Delete" to delete it. Or double click the line to change its appearance instead of going into the menu.
User avatar
mhalil
Posts: 213
Joined: Tue Dec 01, 2020 6:42 pm
Location: İstanbul / Türkiye
Contact:

Re: [Feature Request] Manipulation with cosmetic objects

Post by mhalil »

You can remove cosmetic lines with Remove Cosmetic Object button (on toolbar)
Attachments
Cosmetic_line_add.png
Cosmetic_line_add.png (198.62 KiB) Viewed 1301 times
Cosmetic_lines.png
Cosmetic_lines.png (204.88 KiB) Viewed 1301 times
Cosmetic_line_remove.png
Cosmetic_line_remove.png (237.22 KiB) Viewed 1301 times
cosmetic lines removed.png
cosmetic lines removed.png (215.43 KiB) Viewed 1301 times
xtemp09
Posts: 72
Joined: Tue Jul 12, 2022 2:16 pm

Re: [Feature Request] Manipulation with cosmetic objects

Post by xtemp09 »

Yes, but I'm talking about Delete button on keyboard. And changing appearance of the lines by double clicking on them. Perhaps, clicking with the right mouse button and choosing an option in context menu to change appearance or to delete the cosmetic object is also good.

Should I make the feature request on Github or the forum is enough?
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Manipulation with cosmetic objects

Post by wandererfan »

xtemp09 wrote: Sat May 20, 2023 9:58 am Should I make the feature request on Github or the forum is enough?
Github please. Too easy to get lost on on the forum.

I thought we already had a request for an event filter on the delete key, but I can't find it.
User avatar
bensay
Posts: 202
Joined: Wed Dec 22, 2021 8:14 pm
Location: Danmark
Contact:

Re: [Feature Request] Manipulation with cosmetic objects

Post by bensay »

@wandererfan I tried looking at this, but when selecting a cosmetic vertex and pressing delete, MDIViewPage::onDeleteObject is called with the view and not the vertex. Why is this? Is it because it doesn't have a view provider?

In general, what is a viewprovider and why is everything going through the view provider? Like startDefaultEditMode
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Manipulation with cosmetic objects

Post by wandererfan »

bensay wrote: Sat Jul 15, 2023 1:27 pm I tried looking at this, but when selecting a cosmetic vertex and pressing delete, MDIViewPage::onDeleteObject is called with the view and not the vertex. Why is this? Is it because it doesn't have a view provider?

In general, what is a viewprovider and why is everything going through the view provider? Like startDefaultEditMode
The ViewProvider is the link between the App side and the Gui side. The ViewProvider performs scene graph manipulation in the Coin3d world. In TechDraw the ViewProvider calls QGIV* to perform the drawing.

The ViewProvider also provides some service functions for double clicks and determining if an object is eligible for deletion.

Changes to properties on the App side are signaled to the ViewProvider which changes the graphics if required.

If no widget in the stack handles the delete key, then if propagates upward until it eventually arrives at the MDIView (QMainWindow widget).

There are a few ways of handling this. We could install an event filter, or modify MDIViewPage::onDeleteObject or QGVPage::keyPressEvent (QGraphicsView widget) to check the selection for a sub-element and consume the key event so it does not get propagated.
User avatar
bensay
Posts: 202
Joined: Wed Dec 22, 2021 8:14 pm
Location: Danmark
Contact:

Re: [Feature Request] Manipulation with cosmetic objects

Post by bensay »

@wandererfan

It seems as MDIViewPage::onDeleteObject currently handles all deletions. Are you sure it's supposed to travel up the stack if there is no event filter? Currently, it doesn't seem to be a Qt event but a FreeCAD call such that it works together with App.getDocument('PartDesignExample').removeObject('View') command.

Hmmm... if I try to delete a dimension, MDIViewPage::onDeleteObject is called with the dimension as argument. If I try to delete a vertex, MDIViewPage::onDeleteObject is called with the view as parameter... why isn't the vertex passed as parameter?

If I try to Gui.Selection.addSelection('PartDesignExample','Vertex1'), I get an error that the object isn't found. Same goes for .removeObject
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Manipulation with cosmetic objects

Post by wandererfan »

bensay wrote: Sun Jul 16, 2023 6:05 pm It seems as MDIViewPage::onDeleteObject currently handles all deletions. Are you sure it's supposed to travel up the stack if there is no event filter? Currently, it doesn't seem to be a Qt event but a FreeCAD call such that it works together with App.getDocument('PartDesignExample').removeObject('View') command.

Hmmm... if I try to delete a dimension, MDIViewPage::onDeleteObject is called with the dimension as argument. If I try to delete a vertex, MDIViewPage::onDeleteObject is called with the view as parameter... why isn't the vertex passed as parameter?
It looks like ShortcutManager.cpp traps DEL and invokes Std_Delete process which eventually gets to onDeleteObject. There is no sub-element because Std_Delete only deals with DocumentObjects.

So 2 possibilities, in onDeleteObject or in QGVPage(QGraphicsView)::keyPressEvent. In either case, we need to call getSelectionEx to find out if a vertex/edge/etc is selected - something like:

Code: Select all

    Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement;//mystery
    bool single = false;
    auto selection = Gui::Selection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(),
                                                   resolve, single);
    if (!selection.empty()) {
        auto firstObject = selection.front().getObject();
        Base::Console().Message("MDIVP::onDeleteObject - obj: %s\n", firstObject->getNameInDocument());
        if (!selection.front().getSubNames().empty()) {
            auto firstSub = selection.front().getSubNames().front();
            Base::Console().Message("MDIVP::onDeleteObject - subs: %s\n", firstSub.c_str());
        }
    }
Post Reply