major rework of Sketch creation, now properly handles Arcs in addition to Points on a Polygon
This commit is contained in:
parent
35363fac75
commit
6a639f2c7f
1 changed files with 74 additions and 18 deletions
|
@ -3,6 +3,7 @@ import os
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
from . import settings
|
from . import settings
|
||||||
import Part
|
import Part
|
||||||
|
import Sketcher
|
||||||
|
|
||||||
from kipy.board_types import Footprint3DModel, BoardPolygon, BoardSegment, PadStackShape
|
from kipy.board_types import Footprint3DModel, BoardPolygon, BoardSegment, PadStackShape
|
||||||
from kipy.geometry import PolygonWithHoles, PolyLine, PolyLineNode, Vector2
|
from kipy.geometry import PolygonWithHoles, PolyLine, PolyLineNode, Vector2
|
||||||
|
@ -39,6 +40,7 @@ class BoardSketchObject(BaseObject):
|
||||||
def setup_properties(self, feature):
|
def setup_properties(self, feature):
|
||||||
super(BoardSketchObject, self).setup_properties(feature)
|
super(BoardSketchObject, self).setup_properties(feature)
|
||||||
|
|
||||||
|
# TODO remove in favor of getting BoardOffset from parent Board object
|
||||||
feature.addProperty('App::PropertyPlacement', 'BoardOffset', 'KiConnect', 'Internal offset for zeroing out Footprint offset', hidden=True, read_only=True)
|
feature.addProperty('App::PropertyPlacement', 'BoardOffset', 'KiConnect', 'Internal offset for zeroing out Footprint offset', hidden=True, read_only=True)
|
||||||
feature.addProperty('App::PropertyVectorList', 'Vectors', 'KiConnect', 'Board Outline as Vectors', hidden=True)
|
feature.addProperty('App::PropertyVectorList', 'Vectors', 'KiConnect', 'Board Outline as Vectors', hidden=True)
|
||||||
|
|
||||||
|
@ -47,41 +49,95 @@ class BoardSketchObject(BaseObject):
|
||||||
vectors = []
|
vectors = []
|
||||||
|
|
||||||
# board.get_shapes needs to be called to ensure polygons are actually up to date
|
# board.get_shapes needs to be called to ensure polygons are actually up to date
|
||||||
|
# XXX get_polygon should be moved to the Sketches parent Board object
|
||||||
|
# then the board should be making the api refresh board call and process
|
||||||
|
# the polygon, instead of that functionality being in the API
|
||||||
board_polygon = self.get_api().get_polygon(self.polygon_id)
|
board_polygon = self.get_api().get_polygon(self.polygon_id)
|
||||||
|
|
||||||
if not board_polygon:
|
if not board_polygon:
|
||||||
raise BoardPolyNotFoundException('Board Polygon not found: ' + self.polygon_id)
|
raise BoardPolyNotFoundException('Board Polygon not found: ' + self.polygon_id)
|
||||||
|
|
||||||
for node in board_polygon.polygons[0].outline:
|
arc_count = 0
|
||||||
vectors.append(self.point_to_vector(node.point))
|
|
||||||
|
|
||||||
self.feature.Vectors = vectors
|
|
||||||
|
|
||||||
begin = None
|
|
||||||
start = None
|
start = None
|
||||||
|
|
||||||
# this probably needs a bit more control..
|
outline = board_polygon.polygons[0].outline
|
||||||
feature.Constraints = []
|
line = []
|
||||||
feature.Geometry = []
|
|
||||||
|
|
||||||
for vector in self.feature.Vectors:
|
for node in outline:
|
||||||
if not start:
|
if node.has_arc:
|
||||||
start = vector
|
arc_count = arc_count + 1
|
||||||
begin = vector
|
|
||||||
|
|
||||||
continue
|
if arc_count % 2 == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
feature.addGeometry(Part.LineSegment(start, vector))
|
arc = node.arc
|
||||||
start = vector
|
|
||||||
|
|
||||||
feature.addGeometry(Part.LineSegment(start, begin))
|
|
||||||
|
arc_start = self.point_to_vector(arc.start)
|
||||||
|
arc_mid = self.point_to_vector(arc.mid)
|
||||||
|
arc_end = self.point_to_vector(arc.end)
|
||||||
|
|
||||||
|
if not start:
|
||||||
|
start = arc_start
|
||||||
|
|
||||||
|
# if there is already part of a LineSegment, connect it to the start of this Arc
|
||||||
|
if len(line) == 1:
|
||||||
|
idx = feature.addGeometry(Part.LineSegment(line[0], arc_start))
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Coincident", idx - 1, 2, idx, 1))
|
||||||
|
|
||||||
|
if line[0].x == arc_start.x:
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Vertical", idx))
|
||||||
|
|
||||||
|
if line[0].y == arc_start.y:
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Horizontal", idx))
|
||||||
|
|
||||||
|
line = []
|
||||||
|
|
||||||
|
idx = feature.addGeometry(Part.Arc(arc_start, arc_mid, arc_end))
|
||||||
|
if idx > 1:
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Coincident", idx - 1, 2, idx, 1))
|
||||||
|
|
||||||
|
line.append(arc_end)
|
||||||
|
elif node.has_point:
|
||||||
|
vector = self.point_to_vector(node.point)
|
||||||
|
|
||||||
|
if not start:
|
||||||
|
start = vector
|
||||||
|
|
||||||
|
line.append(vector)
|
||||||
|
else:
|
||||||
|
raise Exception('Hit unknown geometry type in board polygon')
|
||||||
|
|
||||||
|
if len(line) > 2: raise Exception('Too many points in line segment', line)
|
||||||
|
|
||||||
|
if len(line) == 2:
|
||||||
|
idx = feature.addGeometry(Part.LineSegment(line[0], line[1]))
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Coincident", idx - 1, 2, idx, 1))
|
||||||
|
|
||||||
|
if line[0].x == line[1].x:
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Vertical", idx))
|
||||||
|
|
||||||
|
if line[0].y == line[1].y:
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Horizontal", idx))
|
||||||
|
|
||||||
|
line = [ line[1] ]
|
||||||
|
|
||||||
|
|
||||||
|
if len(line) == 1:
|
||||||
|
idx = feature.addGeometry(Part.LineSegment(start, line[0]))
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Coincident", 0, 1, idx, 1))
|
||||||
|
feature.addConstraint(Sketcher.Constraint("Coincident", idx - 1, 2, idx, 2))
|
||||||
|
else:
|
||||||
|
FreeCAD.Console.PrintError("Bad line segment:", line)
|
||||||
|
|
||||||
feature.recompute()
|
feature.recompute()
|
||||||
|
|
||||||
|
|
||||||
class BoardSketchViewProvider(BaseViewProvider):
|
class BoardSketchViewProvider(BaseViewProvider):
|
||||||
TYPE = 'KiConnect::BoardSketch'
|
TYPE = 'KiConnect::BoardSketch'
|
||||||
#ICON = 'kicad/board.svg'
|
#ICON = 'kicad/board.svg'
|
||||||
|
|
||||||
|
|
||||||
def makeBoardSketch(parent, kicad_board, polygon):
|
def makeBoardSketch(parent, kicad_board, polygon):
|
||||||
feature = App.ActiveDocument.addObject('Sketcher::SketchObjectPython', 'BoardSketch')
|
feature = App.ActiveDocument.addObject('Sketcher::SketchObjectPython', 'BoardSketch')
|
||||||
parent.addObject(feature)
|
parent.addObject(feature)
|
||||||
|
|
Loading…
Add table
Reference in a new issue