Skip to content

Commit

Permalink
Merge pull request #174 from kbwbe/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
kbwbe authored Feb 10, 2019
2 parents 5a856fe + 050a46d commit 413663e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 34 deletions.
2 changes: 1 addition & 1 deletion InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__title__ = 'A2plus assembly Workbench - InitGui file'
__author__ = 'kbwbe'

A2P_VERSION = 'V0.3.1'
A2P_VERSION = 'V0.3.2'

import sys
PyVersion = sys.version_info[0]
Expand Down
22 changes: 19 additions & 3 deletions a2p_MuxAssembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def muxAssemblyWithTopoNames(doc, withColor=False):
# solid = Part.Solid(shell)
# solid = Part.makeCompound (shape_list)
if a2plib.getUseSolidUnion():
if len(shape_list) > 0:
if len(shape_list) > 1:
shape_base=shape_list[0]
shapes=shape_list[1:]
solid = shape_base.fuse(shapes)
Expand Down Expand Up @@ -298,11 +298,27 @@ def createOrUpdateSimpleAssemblyShape(doc):
#sas.ViewObject.Proxy = 0
ViewProviderSimpleAssemblyShape(sas.ViewObject)
faces = []

shape_list = []
for obj in visibleImportObjects:
faces = faces + obj.Shape.Faces
shape_list.append(obj.Shape)
shell = Part.makeShell(faces)
sas.Shape = shell
try:
# solid = Part.Solid(shell)
# solid = Part.makeCompound (shape_list)
if a2plib.getUseSolidUnion():
if len(shape_list) > 1:
shape_base=shape_list[0]
shapes=shape_list[1:]
solid = shape_base.fuse(shapes)
else: #one shape only
solid = shape_list[0]
else:
solid = Part.Solid(shell)
except:
# keeping a shell if solid is failing
solid = shell
sas.Shape = solid #shell
sas.ViewObject.Visibility = False


Expand Down
3 changes: 2 additions & 1 deletion a2p_constraintDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,8 @@ def parseSelections(self):
self.planesParallelButton.setEnabled(True)
self.planeCoincidentButton.setEnabled(True)
self.angledPlanesButton.setEnabled(True)
self.centerOfMassButton.setEnabled(True)
if ((planeSelected(s1) or ClosedEdgeSelected(s1)) and (planeSelected(s2) or ClosedEdgeSelected(s2))):
self.centerOfMassButton.setEnabled(True)
#=============================
if sphericalSurfaceSelected(s1):
if vertexSelected(s2):
Expand Down
22 changes: 15 additions & 7 deletions a2p_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,16 @@ def __init__(self,selection):
self.create(selection)

def calcInitialValues(self):
plane1 = getObjectFaceFromName(self.ob1, self.sub1)
plane2 = getObjectFaceFromName(self.ob2, self.sub2)
if self.sub1.startswith('Face'):
plane1 = getObjectFaceFromName(self.ob1, self.sub1)
elif self.sub1.startswith('Edge'):
#print(self.sub1)
plane1 = Part.Face(Part.Wire(getObjectEdgeFromName(self.ob1, self.sub1)))
if self.sub2.startswith('Face'):
plane2 = getObjectFaceFromName(self.ob2, self.sub2)
elif self.sub2.startswith('Edge'):
plane2 = Part.Face(Part.Wire(getObjectEdgeFromName(self.ob2, self.sub2)))
#plane2 = getObjectFaceFromName(self.ob2, self.sub2)
CoM1 = plane1.CenterOfMass
CoM2 = plane2.CenterOfMass
axis1 = plane1.Surface.Axis
Expand All @@ -665,11 +673,11 @@ def getToolTip():
'''
Creates a Center of Mass constraint.
(Join centerOfMass of face1 to
centerOfMass of face2)
(Join centerOfMass of \'face1\' or \'closed edge1\' to
centerOfMass of \'face2\' or \'closed edge2\')
1) select first face object
2) select second face object on another part
1) select first \'face\' or \'closed edge\' object
2) select second \'face\' or \'closed edge\' object on another part
After creating this constraint you can change
entry "offset" in object editor to desired value.
Expand All @@ -684,7 +692,7 @@ def isValidSelection(selection):
if len(selection) == 2:
s1, s2 = selection
if s1.ObjectName != s2.ObjectName:
if ( planeSelected(s1) and planeSelected(s2)):
if ( planeSelected(s1) or ClosedEdgeSelected(s1)) and (planeSelected(s2) or ClosedEdgeSelected(s2)):
validSelection = True
return validSelection

Expand Down
59 changes: 38 additions & 21 deletions a2p_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,26 @@ def Create(doc, constraint, solver, rigid1, rigid2):
ob1 = doc.getObject(c.Object1)
ob2 = doc.getObject(c.Object2)

plane1 = getObjectFaceFromName(ob1, c.SubElement1)
plane2 = getObjectFaceFromName(ob2, c.SubElement2)
dep1.refPoint = plane1.Faces[0].CenterOfMass
dep2.refPoint = plane2.Faces[0].CenterOfMass

if c.SubElement1.startswith('Face'):
plane1 = getObjectFaceFromName(ob1, c.SubElement1)
dep1.refPoint = plane1.Faces[0].CenterOfMass
elif c.SubElement1.startswith('Edge'):
plane1 = Part.Face(Part.Wire(getObjectEdgeFromName(ob1, c.SubElement1)))
dep1.refPoint = plane1.CenterOfMass
if c.SubElement2.startswith('Face'):
plane2 = getObjectFaceFromName(ob2, c.SubElement2)
dep2.refPoint = plane2.Faces[0].CenterOfMass
elif c.SubElement2.startswith('Edge'):
plane2 = Part.Face(Part.Wire(getObjectEdgeFromName(ob2, c.SubElement2)))
dep2.refPoint = plane2.CenterOfMass
#plane1 = getObjectFaceFromName(ob1, c.SubElement1)
#plane2 = getObjectFaceFromName(ob2, c.SubElement2)
# dep1.refPoint = plane1.Faces[0].CenterOfMass
# dep2.refPoint = plane2.Faces[0].CenterOfMass
normal1 = plane1.Surface.Axis
normal2 = plane2.Surface.Axis
print(normal2)
if dep2.direction == "opposed":
normal2.multiply(-1.0)
print(normal2)
dep1.refAxisEnd = dep1.refPoint.add(normal1)
dep2.refAxisEnd = dep2.refPoint.add(normal2)
# to be improved: toggle direction even if offset == 0.0
Expand Down Expand Up @@ -822,25 +831,33 @@ def calcDOF(self, _dofPos, _dofRot, _pointconstraints=[]):

class DependencyCenterOfMass(Dependency):
def __init__(self, constraint, refType):
Dependency.__init__(self, constraint, refType, False)
self.isPointConstraint = True
Dependency.__init__(self, constraint, refType, True)
self.isPointConstraint = False
self.useRefPointSpin = True

def getMovement(self):
if not self.Enabled: return None, None

moveVector = self.foreignDependency.refPoint.sub(self.refPoint)
return self.refPoint, moveVector

def calcDOF(self, _dofPos, _dofRot, _pointconstraints=[]):
#PointIdentity, PointOnLine, PointOnPlane, Spherical Constraints:
# PointIdentityPos() needs to know the point constrained as vector, the dofpos array, the rigid center point as vector and
# the pointconstraints which stores all point constraints of the rigid
# PointIdentityRot() needs to know the point constrained as vector, the dofrot array, and
# the pointconstraints which stores all point constraints of the rigid
# These constraint have to be the last evaluated in the chain of constraints.

tmpaxis = cleanAxis(create_Axis(self.refPoint, self.currentRigid.getRigidCenter()))
#dofpos = PointIdentityPos(tmpaxis,_dofPos,_pointconstraints)
#dofrot = PointIdentityRot(tmpaxis,_dofRot,_pointconstraints)
return PointIdentity(tmpaxis, _dofPos, _dofRot, _pointconstraints)
#function used to determine the dof lost due to this constraint
#CircularEdgeConstraint:
# AxisAlignment() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofrot array
# AxisDistance() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array
# PlaneOffset() needs to know the axis normal to circle (stored in dep as refpoint and refAxisEnd) and the dofpos array
# LockRotation() need to know if LockRotation is True or False and the array dofrot
#
# honestly speaking this would be simplified like this:
# if LockRotation:
# dofpos = []
# dofrot = []
# else:
# dofpos = []
# dofrot = AxisAlignment(ConstraintAxis, dofrot)
if self.lockRotation:
return [], []
else:
tmpaxis = cleanAxis(create_Axis2Points(self.refPoint,self.refAxisEnd))
return [], AxisAlignment(tmpaxis,_dofRot)
4 changes: 3 additions & 1 deletion a2p_topomapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,13 @@ def createTopoNames(self,withColor=False):
shell = Part.makeShell(faces)
try:
if a2plib.getUseSolidUnion():
if len(shape_list) > 0:
if len(shape_list) > 1:
shape_base=shape_list[0]
shapes=shape_list[1:]
solid = shape_base.fuse(shapes)
#solid = ob.Shape
else: #one shape only
solid = shape_list[0]
else:
solid = Part.Solid(shell)
except:
Expand Down
11 changes: 11 additions & 0 deletions a2plib.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,17 @@ def CircularEdgeSelected( selection ):
return True
return False
#------------------------------------------------------------------------------
def ClosedEdgeSelected( selection ):
if len( selection.SubElementNames ) == 1:
subElement = selection.SubElementNames[0]
if subElement.startswith('Edge'):
edge = getObjectEdgeFromName( selection.Object, subElement)
if edge.isClosed():
return True
else:
return False
return False
#------------------------------------------------------------------------------
def AxisOfPlaneSelected( selection ): #adding Planes/Faces selection for Axial constraints
if len( selection.SubElementNames ) == 1:
subElement = selection.SubElementNames[0]
Expand Down

0 comments on commit 413663e

Please sign in to comment.