# Path: turbine.py
# class Turbine:
#     """Specifications for a Wind Turbine (Power Curve, ...)."""
# 
#     def get_config(self):
#         config = configparser.RawConfigParser()
#         if len(sys.argv) > 1:
#             config_file = sys.argv[1]
#         else:
#             config_file = getModelFile('SIREN.ini')
#         config.read(config_file)
#         try:
#           self.base_year = config.get('Base', 'year')
#         except:
#           self.base_year = '2012'
#         parents = []
#         try:
#             parents = getParents(config.items('Parents'))
#         except:
#             pass
#         try:
#             self.sam_file = config.get('Files', 'sam_turbines')
#             for key, value in parents:
#                 self.sam_file = self.sam_file.replace(key, value)
#             self.sam_file = self.sam_file.replace('$USER$', getUser())
#             self.sam_file = self.sam_file.replace('$YEAR$', self.base_year)
#         except:
#             self.sam_file = ''
# 
#     def __init__(self, name, poly=13):
#         """Initializes the data."""
#         self.get_config()
#         self.name = name
#         self.maxp = 0
#         if os.path.exists(self.sam_file):
#              turb_fil = open(self.sam_file)
#              turbines = csv.DictReader(turb_fil)
#              for turbine in turbines:
#                  if turbine['Name'].strip()  == name:
#                      self.capacity = float(turbine['KW Rating'])
#                      self.cutin = 0
#                      self.powers = turbine['Power Curve Array'].split('|')
#                      self.rotor = float(turbine['Rotor Diameter'])
#                      self.speeds = turbine['Wind Speed Array'].split('|')
#                      for i in range(len(self.powers)):
#                          self.speeds[i] = float(self.speeds[i])
#                          self.powers[i] = float(self.powers[i])
#                          if self.powers[i] > 0 and self.cutin == 0:
#                              self.cutin = self.speeds[i]
#                      self.wind_class = turbine['IEC Wind Speed Class']
#                      turb_fil.close()
#                      break
#              else:
#                  turb_fil.close()
#                  pow_turbine = Power_Curve(name, poly)
#                  if not hasattr(pow_turbine, 'capacity'):
#                      return None
#                  self.capacity = pow_turbine.capacity
#                  self.cutin = pow_turbine.cutin
#                  self.rotor = pow_turbine.rotor
#                  self.wind_class = '?'
#                  self.powers = []
#                  self.speeds = []
#                  last_pow = 0
#                  for ws in range(161):   # 0 to 40 by 0.25
#                      self.speeds.append(ws / 4.)
#                      powr = round(pow_turbine.Power(ws / 4.), 2)
#                      if powr > 0:
#                          if powr > last_pow:
#                              last_pow = powr
#                          self.powers.append(last_pow)
#                      else:
#                          self.powers.append(powr)
# 
# 
#     def Power(self):
#         """return power curve values for wind speed."""
#         return self.speeds, self.powers
# 
#     def PowerCurve(self):
#         """plot power curve."""
#         if not hasattr(self, 'speeds'):
#             return None
#         plt.plot(self.speeds, self.powers, linewidth=2.0)
#         plt.title('Power Curve for ' + self.name)
#         plt.grid(True)
#         plt.xlabel('wind speed (m/s)')
#         plt.ylabel('generation (kW)')
#         plt.show(block=True)


import os
import sys
import credits
from PyQt5 import QtCore, QtGui, QtWidgets
from turbine import Turbine
            else:
                html = self.anobject
                if self.anobject[:5] == '<html':
                    self.anobject = self.anobject.replace('[VERSION]', credits.fileVersion())
                    self.web.setHtml(self.anobject)
                else:
                    self.web.setPlainText(self.anobject)
            metrics.append(self.web.fontMetrics())
            try:
                widths[0] = metrics[0].boundingRect(self.web.text()).width()
                heights = metrics[0].boundingRect(self.web.text()).height()
            except:
                bits = html.split('\n')
                for lin in bits:
                    if len(lin) > widths[0]:
                        widths[0] = len(lin)
                heights = len(bits)
                fnt = self.web.fontMetrics()
                widths[0] = (widths[0]) * fnt.maxWidth()
                heights = (heights) * fnt.height()
                screen = QtWidgets.QDesktopWidget().availableGeometry()
                if widths[0] > screen.width() * .67:
                    heights = int(heights / .67)
                    widths[0] = int(screen.width() * .67)
            if self.readonly:
                self.web.setReadOnly(True)
            i = 1
            grid.addWidget(self.web, 0, 0)
            self.set_stuff(grid, widths, heights, i)
        elif isinstance(self.anobject, dict):

# Path: turbine.py
# class Turbine:
#     """Specifications for a Wind Turbine (Power Curve, ...)."""
# 
#     def get_config(self):
#         config = configparser.RawConfigParser()
#         if len(sys.argv) > 1:
#             config_file = sys.argv[1]
#         else:
#             config_file = getModelFile('SIREN.ini')
#         config.read(config_file)
#         try:
#           self.base_year = config.get('Base', 'year')
#         except:
#           self.base_year = '2012'
#         parents = []
#         try:
#             parents = getParents(config.items('Parents'))
#         except:
#             pass
#         try:
#             self.sam_file = config.get('Files', 'sam_turbines')
#             for key, value in parents:
#                 self.sam_file = self.sam_file.replace(key, value)
#             self.sam_file = self.sam_file.replace('$USER$', getUser())
#             self.sam_file = self.sam_file.replace('$YEAR$', self.base_year)
#         except:
#             self.sam_file = ''
# 
#     def __init__(self, name, poly=13):
#         """Initializes the data."""
#         self.get_config()
#         self.name = name
#         self.maxp = 0
#         if os.path.exists(self.sam_file):
#              turb_fil = open(self.sam_file)
#              turbines = csv.DictReader(turb_fil)
#              for turbine in turbines:
#                  if turbine['Name'].strip()  == name:
#                      self.capacity = float(turbine['KW Rating'])
#                      self.cutin = 0
#                      self.powers = turbine['Power Curve Array'].split('|')
#                      self.rotor = float(turbine['Rotor Diameter'])
#                      self.speeds = turbine['Wind Speed Array'].split('|')
#                      for i in range(len(self.powers)):
#                          self.speeds[i] = float(self.speeds[i])
#                          self.powers[i] = float(self.powers[i])
#                          if self.powers[i] > 0 and self.cutin == 0:
#                              self.cutin = self.speeds[i]
#                      self.wind_class = turbine['IEC Wind Speed Class']
#                      turb_fil.close()
#                      break
#              else:
#                  turb_fil.close()
#                  pow_turbine = Power_Curve(name, poly)
#                  if not hasattr(pow_turbine, 'capacity'):
#                      return None
#                  self.capacity = pow_turbine.capacity
#                  self.cutin = pow_turbine.cutin
#                  self.rotor = pow_turbine.rotor
#                  self.wind_class = '?'
#                  self.powers = []
#                  self.speeds = []
#                  last_pow = 0
#                  for ws in range(161):   # 0 to 40 by 0.25
#                      self.speeds.append(ws / 4.)
#                      powr = round(pow_turbine.Power(ws / 4.), 2)
#                      if powr > 0:
#                          if powr > last_pow:
#                              last_pow = powr
#                          self.powers.append(last_pow)
#                      else:
#                          self.powers.append(powr)
# 
# 
#     def Power(self):
#         """return power curve values for wind speed."""
#         return self.speeds, self.powers
# 
#     def PowerCurve(self):
#         """plot power curve."""
#         if not hasattr(self, 'speeds'):
#             return None
#         plt.plot(self.speeds, self.powers, linewidth=2.0)
#         plt.title('Power Curve for ' + self.name)
#         plt.grid(True)
#         plt.xlabel('wind speed (m/s)')
#         plt.ylabel('generation (kW)')
#         plt.show(block=True)


# Path: displayobject.py
import os
import sys
import credits
from PyQt5 import QtCore, QtGui, QtWidgets
from turbine import Turbine

            else:
                html = self.anobject
                if self.anobject[:5] == '<html':
                    self.anobject = self.anobject.replace('[VERSION]', credits.fileVersion())
                    self.web.setHtml(self.anobject)
                else:
                    self.web.setPlainText(self.anobject)
            metrics.append(self.web.fontMetrics())
            try:
                widths[0] = metrics[0].boundingRect(self.web.text()).width()
                heights = metrics[0].boundingRect(self.web.text()).height()
            except:
                bits = html.split('\n')
                for lin in bits:
                    if len(lin) > widths[0]:
                        widths[0] = len(lin)
                heights = len(bits)
                fnt = self.web.fontMetrics()
                widths[0] = (widths[0]) * fnt.maxWidth()
                heights = (heights) * fnt.height()
                screen = QtWidgets.QDesktopWidget().availableGeometry()
                if widths[0] > screen.width() * .67:
                    heights = int(heights / .67)
                    widths[0] = int(screen.width() * .67)
            if self.readonly:
                self.web.setReadOnly(True)
            i = 1
            grid.addWidget(self.web, 0, 0)
            self.set_stuff(grid, widths, heights, i)
        elif isinstance(self.anobject, dict):

            if self.textedit: