From e5c36c9b3c7678f312cd55f114a78c4e247accb7 Mon Sep 17 00:00:00 2001
From: Daniel Brown <ddb@star.sr.bham.ac.uk>
Date: Sun, 1 Dec 2013 21:13:21 +0000
Subject: [PATCH] updates for blocks

---
 pykat/commands.py   |  3 +++
 pykat/components.py |  1 +
 pykat/detectors.py  |  1 +
 pykat/finesse.py    | 14 ++++++++++++--
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/pykat/commands.py b/pykat/commands.py
index a86647b..9a2ac77 100644
--- a/pykat/commands.py
+++ b/pykat/commands.py
@@ -11,6 +11,9 @@ from components import *
 from structs import *
 
 class Command(object):
+    def __init__(self):
+        self.tag = None
+        
     def getFinesseText(self):
         """ Base class for individual finesse optical components """    
         raise NotImplementedError("This function is not implemented")
diff --git a/pykat/components.py b/pykat/components.py
index 783aa55..b5398de 100644
--- a/pykat/components.py
+++ b/pykat/components.py
@@ -34,6 +34,7 @@ class Component(object) :
         self._nodes = None
         self._requested_node_names = []
         self._kat = None
+        self.tag = None
         
         # store a unique ID for this component
         global next_component_id
diff --git a/pykat/detectors.py b/pykat/detectors.py
index afdc83b..ebbaed8 100644
--- a/pykat/detectors.py
+++ b/pykat/detectors.py
@@ -18,6 +18,7 @@ class Detector(object) :
         self._kat = None
         self.noplot = False
         self.enabled = True
+        self.tag = None
         
         if node.find('*'):
             self._alternate_beam = True
diff --git a/pykat/finesse.py b/pykat/finesse.py
index 1889998..c859112 100644
--- a/pykat/finesse.py
+++ b/pykat/finesse.py
@@ -141,11 +141,19 @@ class kat(object):
                 if values[0] == "%%%":
                     if values[1] == "FTblock":
                         newTag = values[2]
-                        if newTag != self.__currentTag and self.__currentTag: 
+                        
+                        if self.__currentTag != None and newTag != self.__currentTag: 
                             warnings.warn("found block {0} before block {1} ended".format(newTag, self.__currentTag))    
+                            
+                        if newTag in self.__blocks:
+                            raise pkex.BasePyKatException("Block `{0}` has already been read")
+                            
+                        self.__blocks{newTag} = [] # create new list to store all references to components in block
                         self.__currentTag = newTag                            
+                        
                     if values[1] == "FTend":
-                        self.__currentTag = ""
+                        self.__currentTag = None
+                        
                     continue
                 #warnings.warn("current tag {0}".format(self.__currentTag))    
 
@@ -174,6 +182,7 @@ class kat(object):
                 else:
                     print "Parsing `{0}` into pykat object not implemented yet, added as extra line.".format(line)
                     self.__extra_lines.append(line + "\n")
+                    
         self.__currentTag= ""
             
     def run(self, printout=1, printerr=1, save_output=False, save_kat=False,kat_name=None) :
@@ -308,6 +317,7 @@ class kat(object):
     def add(self, obj) :
         try:
             obj.tag = self.__currentTag
+            
             if isinstance(obj, Component):
                 
                 if obj.name in self.__components :
-- 
GitLab