forked from teodoran/BMUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.py
95 lines (80 loc) · 2.56 KB
/
Model.py
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
from IdState import IdState
from Calculation import Calculation
from BeamElement import BeamElement
from Point import Point
from MatrixUtil import *
from TestFrame import *
class Model:
def __init__(self):
self.elementList = []
self.idState = IdState()
self.setPointState = False
def setPoint(self, x, y):
pointB = Point(x, y, self.idState.getPointId())
if self.setPointState and (0 != len(self.elementList)):
pointA = self.elementList.pop()
beamElement = BeamElement(pointA, pointB, self.idState.getBeamId())
self.elementList.append(beamElement)
self.elementList.append(pointA)
self.elementList.append(pointB)
self.setPointState = True
def endPoint(self):
self.setPointState = False
def setForce(self, x, y):
index = self.getSelectedElementIndex(x, y)
if index != -1 and self.elementList[index].Type == 'p':
self.elementList[index].addForce();
self.setPointState = False
def setFixture(self, x, y):
self.setPointState = False
def drawElementList(self, canv):
for element in self.elementList:
element.draw(canv)
return canv
def getSelectedElementIndex(self, x, y):
for i in range(len(self.elementList)):
if self.elementList[i].isSelected(x, y):
return i
return -1
def newCalculation(self):
newCalculation = Calculation(self.calculateIEG(), self.getBeamList(), self.calculateNumVert())
#TODO: Get force vector from user and number of iterations from user..
newCalculation.setForceVector(self.getForceVector())
newCalculation.calculateDisplacementVector(200)
print "Stivhetsmatrise:"
printC(newCalculation.K)
print "Forskyvningsvektor:"
print newCalculation.displacementVector
print "Belastningsvektor:"
print newCalculation.forceVector
def calculateIEG(self):
IEG = []
for element in self.elementList:
if element.Type == 'b':
IEG.append([element.start.ID, element.end.ID])
return IEG
def calculateNumVert(self):
numVert = 0
for element in self.elementList:
if element.Type == 'p':
numVert += 1
return numVert
def getBeamList(self):
beamList = []
for element in self.elementList:
if element.Type == 'b':
#TODO: User set properties.
element.setPhysicalProperties(1, 1, 1)
beamList.append(element)
return beamList
def getForceVector(self):
localForceVectors = []
for element in self.elementList:
if element.Type == 'p':
localForceVectors.append(element.forceVector)
return appendLists(localForceVectors)
def printElementListId(self):
liste = []
for element in self.elementList:
liste.append(element.getIdType())
print liste