summaryrefslogtreecommitdiff
path: root/Connections/Shear/Finplate/nutBoltPlacement.py
blob: 12ea89892bf271a08723e6101ce99f5eb9e75498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'''
Created on 07-Jun-2015

@author: deepa
'''
from bolt import Bolt
from nut import Nut
from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere
from ModelUtils import getGpPt

class NutBoltArray():
    
    '''
                                            gDir
          +---------------------------->
          |
          |
          |   P origin
          |      +-------+---------------+
          |      |       |               |
pDir      |      |       | End distance  |
          |      |       v               |
          |      |       X       X       |
          |      |                       |
          |      |                       |
          |      |                       |
          v      |                       |
                 |        Gauge distance |
                 |       X-------X       |
                 |       +               |
                 |       |               |
                 |       | Pitch         |
                 |       |               |
                 |       v               |
                 |       X       X+----> +
                 |               Edge distance
                 |                       |
                 |                       |
                 |                       |
                 +-----------------------+

                Nut Bolt Placement

    '''
    
    def __init__(self,boltPlaceObj,nut,bolt,gap):
        
        self.origin = None
        self.gaugeDir = None
        self.pitchDir = None
        self.boltDir =  None
        
        self.initBoltPlaceParams(boltPlaceObj)
        
        self.bolt = bolt
        self.nut = nut
        self.gap = gap
        
        self.bolts = []
        self.nuts = []
        self.initialiseNutBolts()
        
        self.positions = []
        #self.calculatePositions()
        
        self.models = []
        
    def initialiseNutBolts(self):
        '''
        Initializing the Nut and Bolt 
        '''
        b = self.bolt
        n = self.nut
        for i in range(self.row * self.col):
            self.bolts.append(Bolt(b.R,b.T, b.H, b.r))
            self.nuts.append(Nut(n.R, n.T,n.H, n.r1))
        
    def initBoltPlaceParams(self,boltPlaceObj):
        
        self.pitch = boltPlaceObj['Bolt']['pitch']
        self.gauge = boltPlaceObj['Bolt']['gauge']
        #self.gauge = 30
        self.edge = boltPlaceObj['Bolt']['edge']
        self.end = boltPlaceObj['Bolt']['enddist']
        self.row = boltPlaceObj['Bolt']['numofrow']
        self.col = boltPlaceObj['Bolt']['numofcol']
         
    def calculatePositions(self):
        '''
        Calculates the exact position for nuts and bolts.
        '''
        self.positions = []
        for rw in  range(self.row):
            for col in range(self.col):
                pos = self.origin 
                #pos = pos + self.end * self.gaugeDir
                pos = pos + self.edge * self.gaugeDir
                pos = pos + col * self.gauge * self.gaugeDir 
                #pos = pos + self.edge * self.pitchDir 
                pos = pos + self.end * self.pitchDir 
                pos = pos + rw * self.pitch * self.pitchDir
                
                self.positions.append(pos)
    
    def place(self, origin, gaugeDir, pitchDir, boltDir):
        
        self.origin = origin
        self.gaugeDir = gaugeDir
        self.pitchDir = pitchDir
        self.boltDir = boltDir
        
        self.calculatePositions()
        
        for index, pos in enumerate (self.positions):
            self.bolts[index].place(pos, gaugeDir, boltDir)
            self.nuts[index].place((pos + self.gap * boltDir), gaugeDir, -boltDir)
    
        
    def createModel(self):
        for bolt in self.bolts:
            self.models.append(bolt.createModel())        
        
        for nut in self.nuts:
            self.models.append(nut.createModel())
            
        dbg = self.dbgSphere(self.origin)
        self.models.append(dbg)
            
    def dbgSphere(self, pt):
        return BRepPrimAPI_MakeSphere(getGpPt(pt), 0.1).Shape()
        
    def getModels(self): 
        return self.models