/[ascend]/branches/mike/pygtk/canvas/blockcanvas.py
ViewVC logotype

Diff of /branches/mike/pygtk/canvas/blockcanvas.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2394 by jpye, Thu Feb 24 01:43:46 2011 UTC revision 2628 by grivan, Wed May 16 20:40:56 2012 UTC
# Line 3  from gaphas.item import Line Line 3  from gaphas.item import Line
3  import re  import re
4  from blockitem import DefaultBlockItem  from blockitem import DefaultBlockItem
5  from blockline import BlockLine  from blockline import BlockLine
6    from blockstream import BlockStream
7    
8  UNITS_RE = re.compile("([-+]?(\d+(\.\d*)?|\d*\.d+)([eE][-+]?\d+)?)\s*(.*)");  UNITS_RE = re.compile("([-+]?(\d+(\.\d*)?|\d*\.d+)([eE][-+]?\d+)?)\s*(.*)");
9    
# Line 52  class BlockCanvas(Canvas): Line 53  class BlockCanvas(Canvas):
53                            
54              #if bi.blocktype.type is None:              #if bi.blocktype.type is None:
55              #   bi.blocktype.reattach_ascend(ascwrap, notesdb)              #   bi.blocktype.reattach_ascend(ascwrap, notesdb)
56        '''    
57        def set_stream(self,stream):
58            items = self.get_all_items()
59            for item in items:
60                if type(item)==DefaultBlockItem:
61                    bi = item.blockinstance
62                    bi.stream=stream
63        '''
64        
65      def __str__(self):      def __str__(self):
66          """          """
67          Create ASCEND code corresponding to canvas model, return the          Create ASCEND code corresponding to canvas model, return the
# Line 64  class BlockCanvas(Canvas): Line 73  class BlockCanvas(Canvas):
73          # application layer, without using routines from Gaphas...          # application layer, without using routines from Gaphas...
74                            
75          string = '''          string = '''
76  (* automatically generated model from blocklist.py *)  (* automatically generated model*)
77  REQUIRE "{lib_name}";  REQUIRE "{lib_name}";
78    
79  MODEL canvasmodel;  MODEL canvasmodel;
80      {is_a}      {is_a}
81        {streams}
82      {are_the_same}      {are_the_same}
83        {canvas_user_code}
84  METHODS  METHODS
85  METHOD canvas_user_code;  METHOD canvas_user_code;
     {canvas_user_code}  
86  END canvas_user_code;  END canvas_user_code;
87  METHOD parameter_code;  METHOD parameter_code;
88      {parameter_code}      {parameter_code}
# Line 83  METHOD on_load; Line 93  METHOD on_load;
93  END on_load;  END on_load;
94  END canvasmodel;  END canvasmodel;
95  '''  '''
96          replacement_fields = {'lib_name':str(self.model_library),'is_a':'','are_the_same':'','canvas_user_code':'','parameter_code':'','block_user_code':''}          replacement_fields = {'lib_name':str(self.model_library),'is_a':'','are_the_same':'',
97                                  'canvas_user_code':'','parameter_code':'','block_user_code':''
98                                  ,'streams':''}
99            
100          items = self.get_all_items()          items = self.get_all_items()
101            
# Line 94  END canvasmodel; Line 106  END canvasmodel;
106                  specify = filter(lambda param:bi.params[param].value != None,bi.params)                  specify = filter(lambda param:bi.params[param].value != None,bi.params)
107                  fix = filter(lambda param:bi.params[param].fix == True,bi.params)                  fix = filter(lambda param:bi.params[param].fix == True,bi.params)
108                  specify = filter(lambda x:not (x in fix),specify)                  specify = filter(lambda x:not (x in fix),specify)
109                  specify = map(lambda param:'\t{0}.{1}:={2};\n'.format(bi.name,param,bi.params[param].value),specify)                  specify = map(lambda param:'\t{0}.{1}:={2};\n'.
110                  fix = map(lambda param:'\tFIX {0}.{1};\n\t{0}.{1}:={2}{4}{3}{5};\n'.format(bi.name,param,bi.params[param].value,bi.params[param].units,'{','}'),fix)                                format(bi.name,param,bi.params[param].value),specify)
111                    fix = map(lambda param:'\tFIX {0}.{1};\n\t{0}.{1}:={2}{4}{3}{5};\n'.
112                              format(bi.name,param,bi.params[param].value,
113                                     bi.params[param].units,'{','}'),fix)
114                  try:                  try:
115                      replacement_fields['parameter_code']+=reduce(lambda x,y:x+y,specify)                      replacement_fields['parameter_code']+=\
116                  except Exception as e:                                        reduce(lambda x,y:x+y,specify)
117                    except TypeError:
118                      pass                      pass
                     ##print 'No values to specify: ',e  
                     ##print 'Continuing...'  
119                  try:                  try:
120                      replacement_fields['parameter_code']+=reduce(lambda x,y:x+y,fix)                      replacement_fields['parameter_code']+=\
121                  except Exception as e:                                        reduce(lambda x,y:x+y,fix)
122                    except TypeError:
123                      pass                      pass
124                      ##print 'No values to fix: ',e                              
                     ##print 'Continuing...'  
               
125              if type(item)==BlockLine:              if type(item)==BlockLine:
126                  replacement_fields['are_the_same']+=str(item.lineinstance)                  replacement_fields['are_the_same']+=str(item.lineinstance)
127                    
# Line 116  END canvasmodel; Line 129  END canvasmodel;
129          map(parse,items)          map(parse,items)
130                    
131          replacement_fields['canvas_user_code'] = self.user_code          replacement_fields['canvas_user_code'] = self.user_code
           
         ##s +="\nQdot_loss ALIASES condenser_simple1.Qdot;\n T_H ALIASES boiler_simple1.outlet.T;\n T_C ALIASES condenser_simple1.outlet.T; \neta IS_A fraction; \neta * (boiler_simple1.Qdot_fuel - pump_simple1.Wdot) = turbine_simple1.Wdot;\neta_carnot IS_A fraction;\neta_carnot = 1 - T_C / T_H;\nx_turb_out ALIASES turbine_simple1.outlet.x;\n\n"  
           
132          return string.format(**replacement_fields)          return string.format(**replacement_fields)
133    
134      def __getstate__(self):      def __getstate__(self):
# Line 126  END canvasmodel; Line 136  END canvasmodel;
136          Placeholder for any special pickling stuff that we want to do with          Placeholder for any special pickling stuff that we want to do with
137          our canvas.          our canvas.
138          """          """
           
139          return super(BlockCanvas,self).__getstate__()          return super(BlockCanvas,self).__getstate__()
140            
141      def __setstate__(self, state):      def __setstate__(self, state):

Legend:
Removed from v.2394  
changed lines
  Added in v.2628

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22