Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 53 additions & 14 deletions freecad/gridfinity_workbench/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,59 @@ def __init__(self) -> None:
)


class CreatePartsBin(CreateCommand):
def __init__(self) -> None:
super().__init__(
name="PartsBin",
gridfinity_function=features.PartsBin,
pixmap=ICONDIR / "parts_bin.svg",
)


class CreateBaseplate(CreateCommand):
def __init__(self) -> None:
super().__init__(
name="Baseplate",
gridfinity_function=features.Baseplate,
class CreatePartsBin(CreateCommand):
def __init__(self) -> None:
super().__init__(
name="PartsBin",
gridfinity_function=features.PartsBin,
pixmap=ICONDIR / "parts_bin.svg",
)


class CreateLid(CreateCommand):
def __init__(self) -> None:
super().__init__(
name="Lid",
gridfinity_function=features.Lid,
pixmap=ICONDIR / "Lid.svg",
)


class CreateLidFromSelection(BaseCommand):
def __init__(self) -> None:
super().__init__(
name="LidFromSelection",
pixmap=ICONDIR / "Lid.svg",
menu_text="Gridfinity Lid From Selection",
tooltip="Create a Gridfinity lid from a selected bin.",
)

def IsActive(self) -> bool:
selection = fcg.Selection.getSelection()
return len(selection) == 1 and hasattr(selection[0], "Baseplate") and not selection[0].Baseplate

def Activated(self) -> None:
selection = fcg.Selection.getSelection()
if len(selection) != 1:
return
target_obj = selection[0]

obj = utils.new_object("Lid")
if fc.GuiUp:
view_object: fcg.ViewProviderDocumentObject = obj.ViewObject
ViewProviderGridfinity(view_object, str(self.pixmap))

features.LidFromSelection(obj, target_obj)

fc.ActiveDocument.recompute()
fcg.SendMsgToActiveView("ViewFit")


class CreateBaseplate(CreateCommand):
def __init__(self) -> None:
super().__init__(
name="Baseplate",
gridfinity_function=features.Baseplate,
pixmap=ICONDIR / "Baseplate.svg",
)

Expand Down
31 changes: 23 additions & 8 deletions freecad/gridfinity_workbench/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
LABEL_SHELF_STYLE = "Standard"

SCOOP = True
SCOOP_RADIUS = 21
# Eco Bin Specific
ECO_WALL_THICKNESS = 0.8
ECO_DIVIDER_THICKNESS = 0.8
SCOOP_RADIUS = 21

# Eco Bin Specific
ECO_WALL_THICKNESS = 0.8
ECO_DIVIDER_THICKNESS = 0.8
BASE_WALL_THICKNESS = 0.8
ECO_INSIDE_FILLET_RADIUS = 1

Expand Down Expand Up @@ -102,6 +102,21 @@
MAGNET_BASE_HOLE = 3

# Screw Together Baseplate Specific
CONNECTION_HOLE_DIAMETER = 3.2
MAGNET_BOTTOM_CHAMFER = 2
BASE_THICKNESS = 6.4
CONNECTION_HOLE_DIAMETER = 3.2
MAGNET_BOTTOM_CHAMFER = 2
BASE_THICKNESS = 6.4

# Lids
LID_THICKNESS = 2.0
LID_INSET_CLEARANCE = 0.25
LID_CHAMFER = 0.6
LID_HANDLE_ENABLED = False
LID_HANDLE_LENGTH = 30.0
LID_HANDLE_WIDTH = 10.0
LID_HANDLE_HEIGHT = 10.0
LID_HANDLE_OFFSET_X = 0.0
LID_HANDLE_OFFSET_Y = 0.0
LID_HANDLE_ROTATION = 0.0
LID_HANDLE_CORNER_RADIUS = 5.0
LID_HANDLE_BASE_RADIUS = 1.5
LID_HANDLE_TOP_RADIUS = 1.5
77 changes: 62 additions & 15 deletions freecad/gridfinity_workbench/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import FreeCAD as fc # noqa: N813
import Part

from . import baseplate_feature_construction as baseplate_feat
from . import check_version, const, grid_initial_layout, label_shelf, utils
from . import feature_construction as feat
from . import baseplate_feature_construction as baseplate_feat
from . import check_version, const, grid_initial_layout, label_shelf, lid_feature_construction as lid_feat, utils
from . import feature_construction as feat
from .custom_shape_features import (
clean_up_layout,
custom_shape_solid,
Expand Down Expand Up @@ -256,7 +256,7 @@ def __init__(self, obj: fc.DocumentObject) -> None:
)


class EcoBin(FoundationGridfinity):
class EcoBin(FoundationGridfinity):
def __init__(self, obj: fc.DocumentObject) -> None:
super().__init__(obj)

Expand Down Expand Up @@ -332,10 +332,25 @@ def generate_gridfinity_shape(self, obj: fc.DocumentObject) -> Part.Shape:
if obj.LabelShelfStyle != "Off":
fuse_total = fuse_total.fuse(feat.make_label_shelf(obj, "eco"))

return fuse_total.removeSplitter()


class Baseplate(FoundationGridfinity):
return fuse_total.removeSplitter()


class Lid(FoundationGridfinity):
"""Gridfinity lid object with explicit parameters."""

def __init__(self, obj: fc.DocumentObject) -> None:
super().__init__(obj)

grid_initial_layout.rectangle_layout_properties(obj, baseplate_default=False)
lid_feat.lid_base_properties(obj)
lid_feat.lid_properties(obj)

def generate_gridfinity_shape(self, obj: fc.DocumentObject) -> Part.Shape:
grid_initial_layout.make_rectangle_layout(obj)
return lid_feat.make_lid_rect(obj)


class Baseplate(FoundationGridfinity):
def __init__(self, obj: fc.DocumentObject) -> None:
super().__init__(obj)

Expand Down Expand Up @@ -900,7 +915,7 @@ def loads(self, state: dict) -> None:
self.layout = state["layout"]


class CustomScrewTogetherBaseplate(FoundationGridfinity):
class CustomScrewTogetherBaseplate(FoundationGridfinity):
"""Gridfinity CustomScrewTogetherBaseplate object."""

def __init__(self, obj: fc.DocumentObject, layout: list[list[bool]]) -> None:
Expand Down Expand Up @@ -947,12 +962,44 @@ def dumps(self) -> dict:
"""Needed for JSON Serialization when saving a file containing gridfinity object."""
return {"layout": self.layout}

def loads(self, state: dict) -> None:
"""Needed for JSON Serialization when opening a file containing gridfinity object."""
self.layout = state["layout"]


class StandaloneLabelShelf:
def loads(self, state: dict) -> None:
"""Needed for JSON Serialization when opening a file containing gridfinity object."""
self.layout = state["layout"]


class LidFromSelection(FoundationGridfinity):
"""Gridfinity lid object created from an existing bin selection."""

def __init__(self, obj: fc.DocumentObject, attachment: fc.DocumentObject) -> None:
super().__init__(obj)

obj.addProperty(
"App::PropertyLink",
"Attachment",
"Base",
"Object this lid is attached to.",
read_only=True,
).Attachment = attachment

lid_feat.lid_properties(obj)
lid_feat.add_attachment_reference_properties(obj)
lid_feat.bind_attachment_expressions(obj)

obj.Proxy = self

def generate_gridfinity_shape(self, obj: fc.DocumentObject) -> Part.Shape:
attachment = obj.Attachment
if attachment is None:
raise RuntimeError("Lid must be created from a Gridfinity bin selection.")

layout = getattr(getattr(attachment, "Proxy", None), "layout", None)
if layout is not None:
return lid_feat.make_lid_custom(obj, layout)

return lid_feat.make_lid_rect(obj)


class StandaloneLabelShelf:
def __init__(
self,
obj: fc.DocumentObject,
Expand Down
4 changes: 4 additions & 0 deletions freecad/gridfinity_workbench/icons/Lid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions freecad/gridfinity_workbench/init_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ def Initialize(self) -> None: # noqa: N802
workbench_commands = OrderedDict(
[
("CreateBinBlank", commands.CreateBinBlank()),
("CreateBinBase", commands.CreateBinBase()),
("CreateSimpleStorageBin", commands.CreateSimpleStorageBin()),
("CreateEcoBin", commands.CreateEcoBin()),
("CreatePartsBin", commands.CreatePartsBin()),
("CreateBaseplate", commands.CreateBaseplate()),
("CreateMagnetBaseplate", commands.CreateMagnetBaseplate()),
("CreateScrewTogetherBaseplate", commands.CreateScrewTogetherBaseplate()),
("CreateBinBase", commands.CreateBinBase()),
("CreateSimpleStorageBin", commands.CreateSimpleStorageBin()),
("CreateEcoBin", commands.CreateEcoBin()),
("CreatePartsBin", commands.CreatePartsBin()),
("CreateLid", commands.CreateLid()),
("CreateLidFromSelection", commands.CreateLidFromSelection()),
("CreateBaseplate", commands.CreateBaseplate()),
("CreateMagnetBaseplate", commands.CreateMagnetBaseplate()),
("CreateScrewTogetherBaseplate", commands.CreateScrewTogetherBaseplate()),
("CreateCustomBin", commands.DrawBin()),
("CreateCustomBaseplate", commands.DrawBaseplate()),
("ChangeLayout", commands.ChangeLayout()),
Expand Down
Loading