#!/usr/bin/env python3




##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
    import builtins as builtin
except ImportError:
    import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from Cheetah.compat import unicode
from xpdeint.Segments._BreakpointSegment import _BreakpointSegment
from xpdeint.CallOnceGuards import callOnceGuard

##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '3.2.6.post2'
__CHEETAH_versionTuple__ = (3, 2, 6, 'post', 2)
__CHEETAH_genTime__ = 1634954793.2205033
__CHEETAH_genTimestamp__ = 'Sat Oct 23 13:06:33 2021'
__CHEETAH_src__ = '/home/mattias/xmds-3.0.0/admin/staging/xmds-3.1.0/xpdeint/Segments/BreakpointSegment.tmpl'
__CHEETAH_srcLastModified__ = 'Thu Apr  4 16:29:24 2019'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class BreakpointSegment(_BreakpointSegment):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        super(BreakpointSegment, self).__init__(*args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def description(self, **KWS):



        ## Generated from @def description: segment $segmentNumber (Breakpoint) at line 30, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''segment ''')
        _v = VFFSL(SL,"segmentNumber",True) # '$segmentNumber' on line 30, col 27
        if _v is not None: write(_filter(_v, rawExpr='$segmentNumber')) # from line 30, col 27.
        write(''' (Breakpoint)''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    @callOnceGuard
    def static_globals(self, **KWS):



        ## CHEETAH: generated from @def static_globals at line 36, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        _v = super(BreakpointSegment, self).static_globals()
        if _v is not None: write(_filter(_v))
        # 
        write('''long _breakpointAutoNameCounter = 0;
''')
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def segmentFunctionBody(self, function, **KWS):



        ## CHEETAH: generated from @def segmentFunctionBody($function) at line 47, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        _v = VFFSL(SL,"evaluateComputedVectors",False)(VFFSL(SL,"dependencies",True)) # '${evaluateComputedVectors($dependencies)}' on line 48, col 1
        if _v is not None: write(_filter(_v, rawExpr='${evaluateComputedVectors($dependencies)}')) # from line 48, col 1.
        write('''
''')
        _v = VFFSL(SL,"transformVectorsToBasis",False)(VFFSL(SL,"dependencies",True), VFFSL(SL,"breakpointBasis",True)) # '${transformVectorsToBasis($dependencies, $breakpointBasis)}' on line 50, col 1
        if _v is not None: write(_filter(_v, rawExpr='${transformVectorsToBasis($dependencies, $breakpointBasis)}')) # from line 50, col 1.
        write('''
''')
        featureOrdering = ['Driver']
        dict = {'extraIndent': 0}
        _v = VFFSL(SL,"insertCodeForFeatures",False)('breakpointBegin', featureOrdering, dict) # "${insertCodeForFeatures('breakpointBegin', featureOrdering, dict)}" on line 54, col 1
        if _v is not None: write(_filter(_v, rawExpr="${insertCodeForFeatures('breakpointBegin', featureOrdering, dict)}")) # from line 54, col 1.
        extraIndent = dict['extraIndent']
        write('''
''')
        _v = VFFSL(SL,"breakpointFunctionContents",True) # '${breakpointFunctionContents, extraIndent=extraIndent}' on line 57, col 1
        if _v is not None: write(_filter(_v, extraIndent=extraIndent, rawExpr='${breakpointFunctionContents, extraIndent=extraIndent}')) # from line 57, col 1.
        write('''
''')
        _v = VFFSL(SL,"insertCodeForFeaturesInReverseOrder",False)('breakpointEnd', VFFSL(SL,"featureOrdering",True), dict) # "${insertCodeForFeaturesInReverseOrder('breakpointEnd', $featureOrdering, dict)}" on line 59, col 1
        if _v is not None: write(_filter(_v, rawExpr="${insertCodeForFeaturesInReverseOrder('breakpointEnd', $featureOrdering, dict)}")) # from line 59, col 1.
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def breakpointFunctionContents(self, **KWS):



        ## CHEETAH: generated from @def breakpointFunctionContents at line 63, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        write('''char *_baseFilename = (char*)malloc(255);
''')
        if not VFFSL(SL,"filename",True): # generated from line 66, col 3
            #  If we don't have a filename, then we are auto-naming
            write('''_breakpointAutoNameCounter++;
snprintf(_baseFilename, 255, "%li%s", _breakpointAutoNameCounter, gsArgsAndValues.c_str());
''')
        else: # generated from line 70, col 3
            #  We have a name, rip off the extension if its 'xsil'
            baseFilename = VFFSL(SL,"filename",True)
            if baseFilename.endswith('.xsil'): # generated from line 73, col 5
                baseFilename = baseFilename[0:-5]
            write('''snprintf(_baseFilename, 255, "%s%s", "''')
            _v = VFFSL(SL,"baseFilename",True) # '$baseFilename' on line 76, col 39
            if _v is not None: write(_filter(_v, rawExpr='$baseFilename')) # from line 76, col 39.
            write('''", gsArgsAndValues.c_str());
''')
        write('''
''')
        featureOrdering = ['Output']
        _v = VFN(VFFSL(SL,"outputFormat",True),"writeOutSetup",False)('_baseFilename', self) # "${outputFormat.writeOutSetup('_baseFilename', self)}" on line 80, col 1
        if _v is not None: write(_filter(_v, rawExpr="${outputFormat.writeOutSetup('_baseFilename', self)}")) # from line 80, col 1.
        write('''
''')
        dependentVariables = [{'vector': vector, 'arrayName': ''.join(['_active_',str(VFFSL(SL,"vector.id",True))]), 'components': vector.components} for vector in VFFSL(SL,"dependencies",True)]
        writeOutDict = {'field': VFFSL(SL,"field",True),                        'basis': VFFSL(SL,"breakpointBasis",True),                        'fp': '_outfile',                        'baseFilename': "_baseFilename",                        'outputGroupFilenameSuffix': '',                        'dependentVariables': dependentVariables,                        'xsilElementName': "breakpoint",                        'groupID': 1                       }
        _v = VFN(VFFSL(SL,"outputFormat",True),"writeOutFunctionImplementationBody",False)(writeOutDict) # '${outputFormat.writeOutFunctionImplementationBody(writeOutDict)}' on line 92, col 1
        if _v is not None: write(_filter(_v, rawExpr='${outputFormat.writeOutFunctionImplementationBody(writeOutDict)}')) # from line 92, col 1.
        write('''
''')
        _v = VFFSL(SL,"outputFormat.writeOutTearDown",True) # '${outputFormat.writeOutTearDown}' on line 94, col 1
        if _v is not None: write(_filter(_v, rawExpr='${outputFormat.writeOutTearDown}')) # from line 94, col 1.
        write('''
''')
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''
''')
        # 
        # BreakpointSegment.tmpl
        # 
        # Created by Graham Dennis on 2008-03-15.
        # 
        # Copyright (c) 2008-2012, Graham Dennis
        # 
        # This program is free software: you can redistribute it and/or modify
        # it under the terms of the GNU General Public License as published by
        # the Free Software Foundation, either version 2 of the License, or
        # (at your option) any later version.
        # 
        # This program is distributed in the hope that it will be useful,
        # but WITHOUT ANY WARRANTY; without even the implied warranty of
        # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        # GNU General Public License for more details.
        # 
        # You should have received a copy of the GNU General Public License
        # along with this program.  If not, see <http://www.gnu.org/licenses/>.
        # 
        write('''
''')
        # 
        #   Description of template
        write('''
''')
        # 
        #   Static globals
        write('''
''')
        # 
        #   Function implementations
        write('''

''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    _mainCheetahMethod_for_BreakpointSegment = 'writeBody'

## END CLASS DEFINITION

if not hasattr(BreakpointSegment, '_initCheetahAttributes'):
    templateAPIClass = getattr(BreakpointSegment,
                               '_CHEETAH_templateClass',
                               Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(BreakpointSegment)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit https://cheetahtemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=BreakpointSegment()).run()


