Skip to content

Commit

Permalink
Flake8 cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
TimStrauven committed Apr 18, 2024
1 parent 06f1d40 commit 743946c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 8 additions & 6 deletions operators/add_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ class VIEW3D_OT_slvs_add_distance(Operator, GenericConstraintOp):
property_keys = ("value", "align", "flip")

def main(self, context):
if type(self.entity1) == SlvsLine2D and self.entity2 == None:
if isinstance(self.entity1, SlvsLine2D) and self.entity2 is None:
dependencies = self.entity1.dependencies()
if type(dependencies[0]) == SlvsPoint2D and type(dependencies[1]) == SlvsPoint2D:
# for loop changes the values of self.entity1 and self.entity2 from a line to its endpoints
for i in range(0,2):
self.state_index = i # set index to access i state_data
if (isinstance(dependencies[0], SlvsPoint2D) and
isinstance(dependencies[1], SlvsPoint2D)):
# for loop changes the values of self.entity1 and self.entity2
# from a line entity to its endpoints
for i in range(0, 2):
self.state_index = i # set index to access i state_data
self.state_data["hovered"] = -1
self.state_data["type"] = type(dependencies[i])
self.state_data["is_existing_entity"] = True
self.state_data["entity_index"] = dependencies[i].slvs_index
self.state_data["entity_index"] = dependencies[i].slvs_index

if not self.exists(context, SlvsDistance):
self.target = context.scene.sketcher.constraints.add_distance(
Expand Down
20 changes: 9 additions & 11 deletions operators/base_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,34 +131,32 @@ def draw(self, context: Context):
for key in self.property_keys:
layout.prop(self, key)


def exists(self, context, constraint_type=None) -> bool:
if hasattr(self, "entity2"):
new_dependencies = [i for i in [self.entity1, self.entity2, self.sketch] if i is not None]

if ((SlvsPoint3D == type(self.entity1) or SlvsPoint3D == type(self.entity2)) or
(SlvsLine3D == type(self.entity1) or SlvsLine3D == type(self.entity2))):
max_distance_dof = 3
elif ((type(self.entity1) == SlvsLine2D and self.entity2 == None) or
type(self.entity1) == SlvsPoint2D and type(self.entity2) == SlvsPoint2D):
if (isinstance(self.entity1, (SlvsPoint3D, SlvsLine3D)) or
isinstance(self.entity2, (SlvsPoint3D, SlvsLine3D))):
max_distance_dof = 3
elif ((isinstance(self.entity1, SlvsLine2D) and self.entity2 is None) or
isinstance(self.entity1, SlvsPoint2D) and isinstance(self.entity2, SlvsPoint2D)):
max_distance_dof = 2
else:
max_distance_dof = 1
else:
new_dependencies = [i for i in [self.entity1, self.sketch] if i is not None]
max_distance_dof = 1


distance_dof = 0
for c in context.scene.sketcher.constraints.all:
if type(c) == constraint_type:
if isinstance(c, constraint_type):
if set(c.dependencies()) == set(new_dependencies):
if constraint_type == SlvsDistance:
distance_dof +=1
distance_dof += 1
else:
return True

if distance_dof < max_distance_dof:
return False
else:
return True
return True

0 comments on commit 743946c

Please sign in to comment.