24 __title__ =
"GenericRebarFuctions" 25 __author__ =
"Amritpal Singh" 26 __url__ =
"https://www.freecadweb.org" 28 from PySide
import QtCore, QtGui
29 from DraftGeomUtils
import vec, isCubic
39 """ getEdgesAngle(edge1, edge2): returns a angle between two edges.""" 42 angle = vec1.getAngle(vec2)
43 angle = math.degrees(angle)
47 """ checkRectangle(edges=[]): This function checks whether the given form rectangle 48 or not. It will return True when edges form rectangular shape or return False 49 when edges not form a rectangular.""" 52 if angles.count(90) == 2
and (angles.count(180) == 1
or angles.count(0) == 1):
58 """ getBaseStructuralObject(obj): This function will return last base 66 """ getBaseObject(obj): This function will return last base object.""" 67 if hasattr(obj,
"Base"):
73 """ getFaceNumber(facename): This will return a face number from face name. 77 head = s.rstrip(
'0123456789')
82 if not structure
and not facename:
83 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
84 structure = selected_obj.Object
85 facename = selected_obj.SubElementNames[0]
87 normal = face.normalAt(0,0)
88 normal = face.Placement.Rotation.inverted().multVec(normal)
96 """ getTrueParametersOfStructure(obj): This function return actual length, 97 width and height of the structural element in the form of array like 98 [Length, Width, Height]""" 103 if baseObject.isDerivedFrom(
"Sketcher::SketchObject"):
104 edges = baseObject.Shape.Edges
108 rep_vector = edge.Vertexes[1].Point.sub(edge.Vertexes[0].Point)
109 rep_vector_angle = round(math.degrees(rep_vector.getAngle(FreeCAD.Vector(1,0,0))))
110 if rep_vector_angle
in {0, 180}:
118 height = obj.Height.Value
121 length = structuralBaseObject.Length.Value
122 width = structuralBaseObject.Width.Value
123 height = structuralBaseObject.Height.Value
124 return [length, width, height]
127 """ getParametersOfFace(structure, facename, sketch = True): This function will return 128 length, width and points of center of mass of a given face according to the sketch 129 value in the form of list. 132 Case 1: When sketch is True: We use True when we want to create rebars from sketch 133 (planar rebars) and the sketch is strictly based on 2D so we neglected the normal 135 Output: [(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY)] 137 Case 2: When sketch is False: When we want to create non-planar rebars(like stirrup) 138 or we want to create rebar from a wire. Also for creating rebar from wire 139 we will require three coordinates (x, y, z). 140 Output: [(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY, CenterOfMassZ)]""" 142 center_of_mass = face.CenterOfMass
144 center_of_mass = center_of_mass.sub(structure.Placement.Base)
149 if isCubic(structure.Shape):
151 for edge
in face.Edges:
157 if round((vec(edge)).Length)
not in [round((vec(x)).Length)
for x
in Edges]:
162 facePRM = [(vec(edge)).Length
for edge
in Edges]
166 if round(Edges[0].tangentAt(0)[0])
in {1,-1}:
167 x = center_of_mass[0]
168 if round(Edges[1].tangentAt(0)[1])
in {1, -1}:
169 y = center_of_mass[1]
171 y = center_of_mass[2]
173 elif round(Edges[0].tangentAt(0)[1])
in {1,-1}:
174 x = center_of_mass[1]
175 if round(Edges[1].tangentAt(0)[0])
in {1, -1}:
178 y = center_of_mass[1]
180 y = center_of_mass[2]
181 elif round(Edges[0].tangentAt(0)[2])
in {1,-1}:
182 y = center_of_mass[2]
183 if round(Edges[1].tangentAt(0)[0])
in {1, -1}:
184 x = center_of_mass[0]
186 x = center_of_mass[1]
188 facelength = facePRM[0]
189 facewidth = facePRM[1]
193 boundbox = face.BoundBox
196 if 0
in {round(boundbox.XLength), round(boundbox.YLength), round(boundbox.ZLength)}:
197 normal = face.normalAt(0,0)
198 normal = face.Placement.Rotation.inverted().multVec(normal)
205 for i
in range(len(normal)):
206 if round(normal[i]) == 0:
208 x = center_of_mass[i]
209 facelength = boundbox.XLength
211 elif flag
and i == 1:
212 x = center_of_mass[i]
213 facelength = boundbox.YLength
216 y = center_of_mass[i]
217 facewidth = boundbox.YLength
219 y = center_of_mass[i]
220 facewidth = boundbox.ZLength
225 center_of_mass = face.CenterOfMass
226 return [(facelength, facewidth), center_of_mass]
229 return [(facelength, facewidth), (x, y)]
236 """ extendedTangentPartLength(rounding, diameter, angle): Get a extended 237 length of rounding on corners.""" 238 radius = rounding * diameter
239 x1 = radius / math.tan(math.radians(angle))
240 x2 = radius / math.cos(math.radians(90 - angle)) - radius
244 """ extendedTangentLength(rounding, diameter, angle): Get a extended 245 length of rounding at the end of Stirrup for bent.""" 246 radius = rounding * diameter
247 x1 = radius / math.sin(math.radians(angle))
248 x2 = radius * math.tan(math.radians(90 - angle))
256 """ check_selected_face(): This function checks whether user have selected 258 selected_objs = FreeCADGui.Selection.getSelectionEx()
259 if not selected_objs:
260 showWarning(
"Select any face of the structural element.")
263 selected_face_names = selected_objs[0].SubElementNames
264 if not selected_face_names:
266 showWarning(
"Select any face of the structural element.")
267 elif "Face" in selected_face_names[0]:
268 if len(selected_face_names) > 1:
269 showWarning(
"You have selected more than one face of the structural element.")
271 elif len(selected_face_names) == 1:
272 selected_obj = selected_objs[0]
274 showWarning(
"Select any face of the selected the face.")
279 selected_objs = FreeCADGui.Selection.getSelectionEx()
281 if len(selected_objs[0].SubObjects) == 1:
282 if "Face" in selected_objs[0].SubElementNames[0]:
283 self.SelectedObj = selected_objs[0].Object
284 self.FaceName = selected_objs[0].SubElementNames[0]
285 self.form.PickSelectedFaceLabel.setText(
"Selected face is " + self.FaceName)
287 showWarning(
"Select any face of the structural element.")
289 showWarning(
"Select only one face of the structural element.")
291 showWarning(
"Select any face of the structural element.")
294 """ showWarning(message): This function is used to produce warning 295 message for the user.""" 296 msg = QtGui.QMessageBox()
297 msg.setIcon(QtGui.QMessageBox.Warning)
298 msg.setText(
translate(
"RebarAddon", message))
299 msg.setStandardButtons(QtGui.QMessageBox.Ok)
304 return QtCore.QCoreApplication.translate(context, text, disambig)
def getTrueParametersOfStructure(obj)
def check_selected_face()
def extendedTangentLength(rounding, diameter, angle)
def getBaseStructuralObject(obj)
def getEdgesAngle(edge1, edge2)
def getSelectedFace(self)
def translate(context, text, disambig=None)
def checkRectangle(edges)
def getParametersOfFace(structure, facename, sketch=True)
def facenormalDirection(structure=None, facename=None)
def extendedTangentPartLength(rounding, diameter, angle)