Files
create/src/Mod/Draft/draftviewproviders
alafr 30f5e0eaac Draft: Enable Draft Edit for Draft Labels (#13445)
* Draft: implement DraftLabelGuiTools

TODO:
1- support for custom StraightDirection with any number of points
2- fix EditNode positions when the label is inside a Part

* Draft: enable Draft Edit for Draft Label object

TODO:
Make the edition possible also with double-click in the tree view

* Draft: Trigger Edit on double click on Label in the tree view

Fix part 1/2 of comment https://github.com/FreeCAD/FreeCAD/pull/13445#issuecomment-2079672899

* Draft: Edit Label: enable to move one or move both nodes

The following apply to both edit points of the straight segment:
- If a point is moved exactly on the direction of the straight segment (set the WP to the Label object and use Shift key while moving the node), then it's length is changed without moving the other point.
- If a point is moved in any other direction, both points are moved and the straight segment's length is unchanged

Part 2/2 of https://github.com/FreeCAD/FreeCAD/pull/13445#issuecomment-2079672899
2025-07-27 17:26:12 +02:00
..
2024-11-25 17:43:56 +01:00

2020 May

These files define the viewprovider classes for "scripted objects" defined within the workbench. The corresponding proxy object classes should be defined in the modules in draftobjects/.

Each scripted object has a creation function like make_rectangle, a proxy class like Rectangle, and a viewprovider class like ViewProviderRectangle. The view providers define how they are displayed in the tree view and in the 3D view, that is, visual properties such as line thickness, line color, face color, and transparency. These properties are only available when the graphical interface is loaded; in a console only session, these properties cannot be read nor set. These properties aren't very "real" because they don't affect the actual geometrical shape of the object. Each make function in draftmake/ should import its corresponding viewprovider from this package in order to set the visual properties of the new scripted object, as long the graphical interface is available.

These classes were previously defined in the Draft.py module, which was very large. Now Draft.py is an auxiliary module which just loads the individual classes in order to provide backwards compatibility for older files. Other workbenches can import these classes for their own use, including creating derived classes.

import Draft

new_obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", "New")

if App.GuiUp:
    Draft.ViewProviderRectangle(new_obj.ViewObject)


# Subclass
class NewViewProvider(Draft.ViewProviderRectangle):
   ...

As the scripted objects are rebuilt every time a document is loaded, this means that, in general, these modules cannot be renamed without risking breaking previously saved files. They can be renamed only if the old class can be migrated to point to a new class, for example, by creating a reference to the new class named the same as the older class.

For more information see the thread: [Discussion] Splitting Draft tools into their own modules