Skip to content
Permalink
Browse files

added support when structure element derived from any object

  • Loading branch information...
amrit3701 committed Jul 14, 2017
1 parent 8f2ae70 commit 497e29985815d3a1426ab83a6a8076e8584b980d
Showing with 95 additions and 18 deletions.
  1. +81 −4 Rebarfunc.py
  2. +4 −4 Stirrup.py
  3. +6 −6 StraightRebar.py
  4. +4 −4 UShapeRebar.py
@@ -130,10 +130,10 @@ def getTrueParametersOfStructure(obj):
height = structuralBaseObject.Height.Value
return [length, width, height]

def getParametersOfFace(obj, selected_face, sketch=True):
""" getParametersOfFace(obj, selected_face): This function will return
length, width and points of center of mass of a given face in the form of list like
[(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY)]"""
"""def getParametersOfFace11(obj, selected_face, sketch=True):
#getParametersOfFace(obj, selected_face): This function will return
#length, width and points of center of mass of a given face in the form of list like
#[(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY)]
StructurePRM = getTrueParametersOfStructure(obj)
if not StructurePRM:
return None
@@ -165,8 +165,85 @@ def getParametersOfFace(obj, selected_face, sketch=True):
if not sketch:
center_of_mass = selected_face.CenterOfMass
return [(facelength, facewidth), center_of_mass]
print "faceoriginal: ", [(facelength, facewidth), (x, y)]
return [(facelength, facewidth), (x, y)]"""

def getParametersOfFace(structure, facename, sketch = True):
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
center_of_mass = face.CenterOfMass
#center_of_mass = center_of_mass.sub(getBaseStructuralObject(structure).Placement.Base)
center_of_mass = center_of_mass.sub(structure.Placement.Base)
from DraftGeomUtils import isCubic
Edges = []
facePRM = []
if isCubic(structure.Shape):
for edge in face.Edges:
if not Edges:
Edges.append(edge)
else:
if (vec(edge)).Length not in [(vec(x)).Length for x in Edges]:
Edges.append(edge)
facePRM = [(vec(edge)).Length for edge in Edges]
if Edges[0].tangentAt(0)[0] in {1,-1}:
x = center_of_mass[0]
if Edges[1].tangentAt(0)[1] in {1, -1}:
y = center_of_mass[1]
else:
y = center_of_mass[2]
elif Edges[0].tangentAt(0)[1] in {1,-1}:
x = center_of_mass[1]
if Edges[1].tangentAt(0)[0] in {1, -1}:
facePRM.reverse()
y = center_of_mass[1]
else:
y = center_of_mass[2]
elif Edges[0].tangentAt(0)[2] in {1,-1}:
y = center_of_mass[2]
if Edges[1].tangentAt(0)[0] in {1, -1}:
x = center_of_mass[0]
else:
x = center_of_mass[1]
facePRM.reverse()
facelength = facePRM[0]
facewidth = facePRM[1]
else:
boundbox = face.BoundBox
if 0 in {boundbox.XLength, boundbox.YLength, boundbox.ZLength}:
normal = face.normalAt(0,0)
normal = face.Placement.Rotation.inverted().multVec(normal)
#print "x: ", boundbox.XLength
#print "y: ", boundbox.YLength
#print "z: ", boundbox.ZLength
# Set length and width of user selected face of structural element
flag = True
for i in range(len(normal)):
if round(normal[i]) == 0:
if flag and i == 0:
x = center_of_mass[i]
facelength = boundbox.XLength
flag = False
elif flag and i == 1:
x = center_of_mass[i]
facelength = boundbox.YLength
flag = False
if i == 1:
y = center_of_mass[i]
facewidth = boundbox.YLength
elif i == 2:
y = center_of_mass[i]
facewidth = boundbox.ZLength
print [(facelength, facewidth), (x, y)]
if not sketch:
center_of_mass = face.CenterOfMass
return [(facelength, facewidth), center_of_mass]
return [(facelength, facewidth), (x, y)]


def getFaceNumber(s):
head = s.rstrip('0123456789')
tail = s[len(head):]
return int(tail)

def extendedTangentPartLength(rounding, diameter, angle):
""" extendedTangentPartLength(rounding, diameter, angle): Get a extended
length of rounding on corners."""
@@ -183,9 +183,9 @@ def makeStirrup(s_cover, f_cover, bentAngle, bentFactor, diameter, rounding,\
selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
structure = selected_obj.Object
facename = selected_obj.SubElementNames[0]
face = structure.Shape.Faces[int(facename[-1]) - 1]
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
StructurePRM = getTrueParametersOfStructure(structure)
FacePRM = getParametersOfFace(structure, face, False)
FacePRM = getParametersOfFace(structure, facename, False)
FaceNormal = face.normalAt(0,0)
FaceNormal = face.Placement.Rotation.inverted().multVec(FaceNormal)
if not FacePRM:
@@ -246,11 +246,11 @@ def editStirrup(Rebar, s_cover, f_cover, bentAngle, bentFactor, diameter, roundi
# Assigned values
facename = sketch.Support[0][1][0]
structure = sketch.Support[0][0]
face = structure.Shape.Faces[int(facename[-1]) - 1]
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
StructurePRM = getTrueParametersOfStructure(structure)
#FreeCAD.Console.PrintMessage(str(StructurePRM)+"\n")
# Get parameters of the face where sketch of rebar is drawn
FacePRM = getParametersOfFace(structure, face, False)
FacePRM = getParametersOfFace(structure, facename, False)
FaceNormal = face.normalAt(0, 0)
FaceNormal = face.Placement.Rotation.inverted().multVec(FaceNormal)
# Calculate the coordinates value of U-Shape rebar
@@ -109,9 +109,9 @@ def makeStraightRebar(f_cover, b_cover, s_cover, diameter, amount_spacing_check,
selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
structure = selected_obj.Object
facename = selected_obj.SubElementNames[0]
face = structure.Shape.Faces[int(facename[-1]) - 1]
StructurePRM = getTrueParametersOfStructure(structure)
FacePRM = getParametersOfFace(structure, face)
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
#StructurePRM = getTrueParametersOfStructure(structure)
FacePRM = getParametersOfFace(structure, facename)
if not FacePRM:
FreeCAD.Console.PrintError("Cannot identified shape or from which base object sturctural element is derived\n")
return
@@ -162,10 +162,10 @@ def editStraightRebar(Rebar, f_cover, b_cover, s_cover, diameter, amount_spacing
# Assigned values
facename = sketch.Support[0][1][0]
structure = sketch.Support[0][0]
face = structure.Shape.Faces[int(facename[-1]) - 1]
StructurePRM = getTrueParametersOfStructure(structure)
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
#StructurePRM = getTrueParametersOfStructure(structure)
# Get parameters of the face where sketch of rebar is drawn
FacePRM = getParametersOfFace(structure, face)
FacePRM = getParametersOfFace(structure, facename)
# Get points of Striaght rebar
points = getpointsOfStraightRebar(FacePRM, s_cover, b_cover)
sketch.movePoint(0, 1, points[0], 0)
@@ -115,9 +115,9 @@ def makeUShapeRebar(f_cover, b_cover, s_cover, diameter, t_cover, rounding, amou
selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
structure = selected_obj.Object
facename = selected_obj.SubElementNames[0]
face = structure.Shape.Faces[int(facename[-1]) - 1]
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
StructurePRM = getTrueParametersOfStructure(structure)
FacePRM = getParametersOfFace(structure, face)
FacePRM = getParametersOfFace(structure, facename)
if not FacePRM:
FreeCAD.Console.PrintError("Cannot identified shape or from which base object sturctural element is derived\n")
return
@@ -175,10 +175,10 @@ def editUShapeRebar(Rebar, f_cover, b_cover, s_cover, diameter, t_cover, roundin
# Assigned values
facename = sketch.Support[0][1][0]
structure = sketch.Support[0][0]
face = structure.Shape.Faces[int(facename[-1]) - 1]
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
StructurePRM = getTrueParametersOfStructure(structure)
# Get parameters of the face where sketch of rebar is drawn
FacePRM = getParametersOfFace(structure, face)
FacePRM = getParametersOfFace(structure, facename)
# Get points of U-Shape rebar
points = getpointsOfUShapeRebar(FacePRM, s_cover, b_cover, t_cover)
FreeCAD.Console.PrintMessage(str(points)+"\n")

0 comments on commit 497e299

Please sign in to comment.
You can’t perform that action at this time.