Rebar Addon for FreeCAD
RebarDistribution.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # ***************************************************************************
3 # * *
4 # * Copyright (c) 2017 - Amritpal Singh <amrit3701@gmail.com> *
5 # * *
6 # * This program is free software; you can redistribute it and/or modify *
7 # * it under the terms of the GNU Lesser General Public License (LGPL) *
8 # * as published by the Free Software Foundation; either version 2 of *
9 # * the License, or (at your option) any later version. *
10 # * for detail see the LICENCE text file. *
11 # * *
12 # * This program is distributed in the hope that it will be useful, *
13 # * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 # * GNU Library General Public License for more details. *
16 # * *
17 # * You should have received a copy of the GNU Library General Public *
18 # * License along with this program; if not, write to the Free Software *
19 # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
20 # * USA *
21 # * *
22 # ***************************************************************************
23 
24 __title__ = "DialogDistribution"
25 __author__ = "Amritpal Singh"
26 __url__ = "https://www.freecadweb.org"
27 
28 from PySide import QtCore, QtGui
29 from Rebarfunc import *
30 from PySide.QtCore import QT_TRANSLATE_NOOP
31 import FreeCAD
32 import FreeCADGui
33 import ArchCommands
34 import os
35 import sys
36 import math
37 
39  def __init__(self, frontCover, size):
40  self.FrontCover = frontCover
41  self.ExpandingLength = size
42  self.form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] + ".ui")
43  self.form.setWindowTitle(QtGui.QApplication.translate("Arch", "Rebar Distribution", None))
44  self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/RebarDistribution.svg"))
45 
46  def accept(self):
47  amount1 = self.form.amount1.value()
48  spacing1 = self.form.spacing1.text()
49  spacing1 = FreeCAD.Units.Quantity(spacing1).Value
50  amount2 = self.form.amount2.value()
51  spacing2 = self.form.spacing2.text()
52  spacing2 = FreeCAD.Units.Quantity(spacing2).Value
53  amount3 = self.form.amount3.value()
54  spacing3 = self.form.spacing3.text()
55  spacing3 = FreeCAD.Units.Quantity(spacing3).Value
56  self.CustomSpacing = getCustomSpacingString(amount1, spacing1, amount2, spacing2, amount3, spacing3, self.FrontCover, self.ExpandingLength)
57 
58  def setupUi(self):
59  # Connect Signals and Slots
60  self.form.buttonBox.accepted.connect(self.accept)
61  pass
62 
63 def getCustomSpacingString(amount1, spacing1, amount2, spacing2, amount3, spacing3, frontCover, size):
64  seg1_area = amount1 * spacing1 - spacing1 / 2
65  seg3_area = amount3 * spacing3 - spacing3 / 2
66  seg2_area = size - seg1_area - seg3_area - 2 * frontCover
67  if seg2_area < 0:
68  FreeCAD.Console.PrintError("Sum of length of segment 1 and segment 2 is greater than length of rebar expands.\n")
69  return
70  if spacing1 and spacing2 and spacing3 and amount1 and amount2 and amount3:
71  pass
72  else:
73  if spacing1 and spacing2 and spacing3:
74  amount2 = math.ceil(seg2_area / spacing2)
75  spacing2 = seg2_area / amount2
76  elif amount1 and amount2 and amount3:
77  spacing2 = math.floor(seg2_area / amount2)
78  CustomSpacing = str(amount1) + "@" + str(spacing1) + "+" + str(int(amount2)) + "@" + str(spacing2) + "+" + str(amount3) + "@" + str(spacing3)
79  return CustomSpacing
80 
81 def getupleOfCustomSpacing(span_string):
82  """ gettupleOfCustomSpacing(span_string): This function take input
83  in specific syntax and return output in the form of list. For eg.
84  Input: "3@100+2@200+3@100"
85  Output: [(3, 100), (2, 200), (3, 100)]"""
86  import string
87  span_st = string.strip(span_string)
88  span_sp = string.split(span_st, '+')
89  index = 0
90  spacinglist = []
91  while index < len(span_sp):
92  # Find "@" recursively in span_sp array.
93  in_sp = string.split(span_sp[index], '@')
94  spacinglist.append((int(in_sp[0]),float(in_sp[1])))
95  index += 1
96  return spacinglist
97 
99  frontCover = self.form.frontCover.text()
100  frontCover = FreeCAD.Units.Quantity(frontCover).Value
101  face = self.SelectedObj.Shape.Faces[getFaceNumber(self.FaceName) - 1]
102  size = (ArchCommands.projectToVector(self.SelectedObj.Shape.copy(), face.normalAt(0, 0))).Length
103  dialog = _RebarDistributionDialog(frontCover, size)
104  dialog.setupUi()
105  dialog.form.exec_()
106  self.CustomSpacing = dialog.CustomSpacing
107 
109  self.CustomSpacing = ""
110  self.Rebar.CustomSpacing = ""
111  FreeCAD.ActiveDocument.recompute()
112 
113 #runRebarDistribution(App.ActiveDocument.Rebar)
def getFaceNumber(s)
Definition: Rebarfunc.py:72
def runRebarDistribution(self)
def removeRebarDistribution(self)
def getCustomSpacingString(amount1, spacing1, amount2, spacing2, amount3, spacing3, frontCover, size)
def getupleOfCustomSpacing(span_string)