Ejemplo n.º 1
0
def toto(entity_common_attrs, class_suffix=''):
    if len(entity_common_attrs) == 0:
        return
    for name, entity_types in entity_common_attrs.items():
        name = cppName.make_cppname(name + class_suffix)
        header = cppHeader.Header(name, prefix='svg')
        # print name
        output = '''
namespace svg {
	struct %s ''' % (name)

        inherits = ''
        includes = ''
        fields = ''
        #print entity_types
        for entity_type in entity_types:

            if str(entity_type.__class__) == 'parse_attr.attr_entity_ref':
                entity_name = cppName.make_cppname(entity_type.entity_name)
                inherits = inherits + '\t\t\t%s,\n' % (entity_name)
                includes = includes + '#include <w3c/svg/%s.hpp>\n' % (
                    entity_name)

            elif isinstance(entity_type, parse_attr.attr_named_entity_ref):
                entity_name = cppName.make_cppname(entity_type.entity_name)
                includes = includes + '#include <w3c/svg/%s.hpp>\n' % (
                    entity_name)
                fields = fields + '\t\t\t%s %s;\n' % (
                    entity_name, cppName.make_cppname(entity_type.name))

            elif isinstance(entity_type, parse_attr.attr_named_enum):
                entity_name = cppName.make_cppname(entity_type.name)
                enumstr = '''
			enum %sEnum {
''' % (entity_name)
                for i in entity_type.enums:
                    enumstr = enumstr + '\t\t\t\t%s,\n' % (
                        entity_name + '_' + cppName.make_cppname(i))
                enumstr = enumstr + '\t\t\t};\n\n'
                enumstr = enumstr + '\t\t\t%sEnum %s;\n' % (entity_name,
                                                            entity_name)
                fields = fields + enumstr + '\n'

        if len(inherits):
            inherits = ':\n' + inherits[:-2]

        output = '// generated by genSvgElement.py\n\n' + includes + output + inherits + ' {\n\n' + fields
        output = output + '''
	};
}
'''
        header.add_content(output)
        header.dump('svg')
        all_headers.append(name)
Ejemplo n.º 2
0
def generate(name):
    if name == "PathSeg" or name == "ElementInstance":
        return
    typename = genAnimated.getBaseType(name)
    include = ""
    if name == "String":
        include = '#include "String_wxsvg.h"\n'
    elif typename not in cpp.builtin_types:
        include = '#include "SVG%s.h"\n' % name

    addGetParam = ""
    addSetParam = ""
    if name == "String":
        addGetParam = "wxChar delimiter = wxT(',')"
        addSetParam = ", wxChar delimiter = wxT(',')"

    output = '''%s#include "String_wxsvg.h"
#include <wx/dynarray.h>
WX_DECLARE_OBJARRAY(%s, wxSVG%sListBase);

class wxSVG%sList: public wxSVG%sListBase
{
  public:
    wxSVG%sList() {}
    
    wxString GetValueAsString(%s) const;
    void SetValueAsString(const wxString& value%s);
};''' % (include, typename, name, name, name, name, addGetParam, addSetParam)

    header = cppHeader.Header("SVG%sList" % name, "genList.py")
    header.add_content(output)
    header.dump(path=conf.include_dir)

    output = '''#include "SVG%sList.h"
#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY(wxSVG%sListBase);

wxString wxSVG%sList::GetValueAsString()
{
  wxString value;
  return value;
}

void wxSVG%sList::SetValueAsString(const wxString& value)
{

}''' % (name, name, name, name)
Ejemplo n.º 3
0
def genValues():
    cssValues = []
    for prop in cssProperties:
        for val in prop.values:
            if val not in cssValues:
                cssValues.append(val)
    cssValues.sort()

    values = ''
    for value in cssValues:
        if len(values):
            values = values + ',\n'
        values = values + '  %s' % valueId(value)

    output = '''\
enum wxCSS_VALUE
{
  wxCSS_VALUE_UNKNOWN,
%s
};''' % values

    header = cppHeader.Header("CSSValues", "genCSS.py")
    header.add_content(output)
    header.dump(path=config.include_dir)

    values = ''
    for value in cssValues:
        if len(values):
            values = values + ',\n'
        values = values + '  wxT("%s")' % value

    output = '''\
wxString s_cssValueStrings[] =
{
%s
};''' % values
    impl = cppImpl.Impl("css_values", "genCSS.py")
    impl.add_content(output)
    impl.dump(path=config.src_dir)
Ejemplo n.º 4
0
                return 1
        except KeyError:
            pass
    return 0

if len(parse_idl.class_decls):
    for (classname, classdecl) in parse_idl.class_decls.items():
        if classname.find("Animated") >=0 and classname not in ["SVGAnimatedPathData","SVGAnimatedPoints"]:
            used_animated.append(classname)
            continue
        if classname.find("List") >=0:
            used_lists.append(classname)
            continue

        # print classdecl
        header = cppHeader.Header(classname, "generate.py")

        includes=[]
        fwd_decls=[]
        doGetAttrByName=0

        output = ''
        cpp_output = ''
		
		# enums
        for enum in classdecl.enums:
            output = output + '\nenum %s\n{\n'%(cpp.fix_typename(enum.name))
            if len(enum.const_decls):
                output = output + '  %s'%(cpp.fix_typename('%s'%enum.const_decls[0]))
                if len(enum.const_decls[1:]):
                    for const_decl in enum.const_decls[1:]:
Ejemplo n.º 5
0
            pass
    return 0


if len(parse_idl.class_decls):
    for (classname, classdecl) in parse_idl.class_decls.items():

        if string.find(classname, "Animated") >=0 and classname not in ["SVGAnimatedPathData","SVGAnimatedPoints",""]:
            used_animated.append(classname)
            continue
        if string.find(classname, "List") >=0:
            used_lists.append(classname)
            continue

        # print classdecl
        header = cppHeader.Header(classname, prefix="svg")
        all_headers.append(classname)

        includes=[]
        fwd_decls=[]
        doGetAttrByName=0

        output = ''

        # inheritance
        output = output + "namespace svg {\n"        
        output = output + "\tclass %s"%(classname)
        if len(classdecl.inherits):
            output=output+' :\n'
            output = output + '\t\tpublic %s'%(classdecl.inherits[0])
            includes.append(classdecl.inherits[0])
Ejemplo n.º 6
0
def generate(name):
    typename = getBaseType(name)
    include = ''
    if name == "String":
        include = '#include "String_wxsvg.h"\n'
    elif typename not in cpp.builtin_types:
        include = '#include "SVG%s.h"\n' % name

    output = ''
    if typename in cpp.number_types:
        output = '''%s
class wxSVGAnimated%s
{
  public:
    wxSVGAnimated%s(): m_baseVal(0), m_animVal(0) {}
	wxSVGAnimated%s(%s value): m_baseVal(value), m_animVal(value) {}
	
    inline %s GetBaseVal() const { return m_baseVal; };
	inline void SetBaseVal(%s value) { m_baseVal = m_animVal = value; }
	
    inline %s GetAnimVal() const { return m_animVal; }
	inline void SetAnimVal(%s value) { m_animVal = value; }
    
  public:
    inline operator %s() const { return GetAnimVal(); }
    
  protected:
    %s m_baseVal;
    %s m_animVal;
};
''' % (include, name, name, name, typename, typename, typename, typename,
        typename, typename, typename, typename)
    else:
        output = '''%s
class wxSVGAnimated%s
{
  public:
    wxSVGAnimated%s(): m_animVal(NULL) {}
    wxSVGAnimated%s(const %s& value): m_baseVal(value), m_animVal(NULL) {}
    wxSVGAnimated%s(const wxSVGAnimated%s& value): m_baseVal(value.m_baseVal), m_animVal(NULL)
    { if (value.m_animVal != NULL) m_animVal = new %s(*value.m_animVal); }
    ~wxSVGAnimated%s() { ResetAnimVal(); }
    
    inline wxSVGAnimated%s& operator=(const wxSVGAnimated%s& value)
    { m_baseVal = value.m_baseVal; m_animVal = value.m_animVal != NULL ? new %s(*value.m_animVal) : NULL; return *this; }
    
    inline %s& GetBaseVal() { return m_baseVal; }
    inline const %s& GetBaseVal() const { return m_baseVal; }
    inline void SetBaseVal(const %s& value) { m_baseVal = value; ResetAnimVal(); }
    
    inline %s& GetAnimVal()
    {
      if (!m_animVal)
        m_animVal = new %s(m_baseVal);
      return *m_animVal;
    }
    inline const %s& GetAnimVal() const
    {
        return m_animVal ? *m_animVal : m_baseVal;
    }
    inline void SetAnimVal(const %s& value)
    {
      if (!m_animVal)
        m_animVal = new %s(value);
      else
        *m_animVal = value;
    }
    inline void ResetAnimVal()
    {
      if (m_animVal)
      {
        delete m_animVal;
        m_animVal = NULL;
      }
    }
    
  public:
    inline operator const %s&() const { return GetAnimVal(); }
    
  protected:
    %s m_baseVal;
    %s* m_animVal;
};
'''%(include,name,name,name,typename,name,name,typename,name,name,name,typename,\
     typename,typename,typename,typename,\
     typename,typename,typename,typename,typename,typename,typename)

    header = cppHeader.Header("SVGAnimated%s" % name, "genAnimated.py")
    header.add_content(output)
    header.dump(path=config.include_dir)
Ejemplo n.º 7
0
    dtdname = dtdname.replace(':', '_')
    includes = includes + '#include "SVG%sElement.h"\n'%(classname)
    dtdenum = dtdenum + '  wxSVG_%s_ELEMENT,\n'%(dtdname.upper())
    create = create + '''if (qualifiedName == wxT("%s"))
    res = new wxSVG%sElement();
  else '''%(element_dtd_name, classname)

create = '''wxSvgXmlElement* wxSVGDocument::CreateElementNS(const wxString& namespaceURI,
  const wxString& qualifiedName)
{
  wxSVGElement* res = NULL;
  ''' + create + '''
	res = new wxSVGGElement();
  return res;
}'''
dtdenum = 'enum wxSVGDTD\n{\n' + dtdenum + '  wxSVG_UNKNOWN_ELEMENT\n};'

impl = cppImpl.Impl("SVGDocument_CreateElement", "genSvgElement.py")
impl.add_content(create)
impl.dump(path=conf.src_dir)

includes = includes + '#include "SVGDocument.h"\n'
header = cppHeader.Header("svg", "genSvgElement.py")
header.add_content(includes)
header.dump(path=conf.include_dir)

header = cppHeader.Header("SVGDTD", "genSvgElement.py")
header.add_content(dtdenum)
header.dump(path=conf.include_dir)

Ejemplo n.º 8
0
def genCSSStyleDeclaration():
    enum = ''
    for prop in cssProperties:
        if (len(enum)):
            enum = enum + ',\n'
        enum = enum + '  ' + propId(prop.dtdName)

    methods = ''
    for prop in cssProperties:
        methodName = makeMethodName(prop.dtdName)
        valueType = prop.valueType
        get = '((%s&)*it->second)' % prop.cssType
        functionName = getFunctionName(prop.valueType)
        if len(functionName):
            get = get + '.Get' + functionName + '()'
        else:
            valueType = "const " + valueType + "&"
        get = '''\
    inline %s Get%s() const
    {
      const_iterator it = find(%s);
      return it != end() ? %s : %s;
    }
    ''' % (valueType, methodName, propId(prop.dtdName), get, prop.defValue)

        has = 'inline bool Has%s() const { return HasProperty(%s); }\n' % (
            methodName, propId(prop.dtdName))

        if len(functionName):
            valueType = prop.valueType
            if valueType not in cpp.builtin_types and valueType != "wxCSS_VALUE":
                valueType = "const " + valueType + "&"
            ptype = ""
            if prop.valueType == "wxString":
                ptype = "wxCSS_STRING, "
            elif prop.valueType == "double":
                ptype = "wxCSS_NUMBER, "
            set = '''\
    inline void Set%s(%s value)
    {
      iterator it = find(%s);
      if (it != end())
        ((%s*)it->second)->Set%s(%svalue);
      else
        (*this)[%s] = new %s(value);
    }
    ''' % (methodName, valueType, propId(prop.dtdName), prop.cssType,
            functionName, ptype, propId(prop.dtdName), prop.cssType)
        else:
            set = '''\
    inline void Set%s(const %s& value)
    {
      iterator it = find(%s);
      if (it != end())
      {
        delete it->second;
        it->second = new %s(value);
      }
      else
        (*this)[%s] = new %s(value);
    }
    ''' % (methodName, prop.valueType, propId(prop.dtdName), prop.valueType,
            propId(prop.dtdName), prop.valueType)

        if len(methods):
            methods = methods + '\n\n'
        methods = methods + get + has + set

    output = '''
#include "CSSValue.h"
#include "SVGPaint.h"
#include "SVGAnimatedType.h"
#include <wx/hashmap.h>

enum wxCSS_PROPERTY
{
  wxCSS_PROPERTY_UNKNOWN,
%s
};

WX_DECLARE_HASH_MAP(wxCSS_PROPERTY, wxCSSValue*, wxIntegerHash, wxIntegerEqual, wxHashMapCSSValue);

typedef wxString wxCSSStyler;

class wxCSSStyleDeclaration: public wxHashMapCSSValue
{
  public:
    wxCSSStyleDeclaration() {}
    wxCSSStyleDeclaration(const wxCSSStyleDeclaration& src) { Add(src); }
    ~wxCSSStyleDeclaration();
    wxCSSStyleDeclaration& operator=(const wxCSSStyleDeclaration& src);
    void Add(const wxCSSStyleDeclaration& style);

  public:
    wxString GetCSSText() const;
    void SetCSSText(const wxString& text);
    
    inline wxString GetPropertyValue(const wxString& propertyName) const
    { return GetPropertyValue(GetPropertyId(propertyName)); }
    
    inline const wxCSSValue& GetPropertyCSSValue(const wxString& propertyName) const
    { return GetPropertyCSSValue(GetPropertyId(propertyName)); }
    
    void SetProperty(const wxString& propertyName, const wxString& value)
    { SetProperty(GetPropertyId(propertyName), value); }
    
    void SetProperty(const wxString& propertyName, const wxSVGAnimatedType& value)
    { SetProperty(GetPropertyId(propertyName), value); }
    
    inline bool HasProperty(const wxString& propertyName) const
    { return HasProperty(GetPropertyId(propertyName)); }
    
    inline wxString RemoveProperty(const wxString& propertyName)
    { return RemoveProperty(GetPropertyId(propertyName)); }
  
  public:
    inline wxString GetPropertyValue(wxCSS_PROPERTY propertyId) const
    { const_iterator it = find(propertyId); if (it != end()) return it->second->GetCSSText(); return wxT(""); }
    
    inline const wxCSSValue& GetPropertyCSSValue(wxCSS_PROPERTY propertyId) const
    { const_iterator it = find(propertyId); if (it != end()) return *it->second; return *s_emptyCSSValue; }
    
    void SetProperty(wxCSS_PROPERTY propertyId, const wxString& value);
    void SetProperty(wxCSS_PROPERTY propertyId, const wxSVGAnimatedType& value);
    inline bool HasProperty(wxCSS_PROPERTY propertyId) const { return find(propertyId) != end(); }
    inline wxString RemoveProperty(wxCSS_PROPERTY propertyId) { erase(propertyId); return wxT(""); }
    
    static wxCSS_PROPERTY GetPropertyId(const wxString& propertyName);
    static wxString GetPropertyName(wxCSS_PROPERTY propertyId);
  
  public:
%s
  
  protected:
    static wxCSSPrimitiveValue* s_emptyCSSValue;
    static wxSVGColor* s_emptySVGColor;
    static wxSVGPaint* s_emptySVGPaint;
    static wxSVGPaint* s_blackSVGPaint;
    static wxCSSValueList* s_emptyValueList;

  public:
    static double ParseNumber(const wxString& value);
    static wxRGBColor ParseColor(const wxString& value);
    static void ParseSVGPaint(wxSVGPaint& paint, const wxString& value);
};

/* this class copy only references of css values */
class wxCSSStyleRef: public wxCSSStyleDeclaration
{
  public:
    wxCSSStyleRef() {}
    wxCSSStyleRef(const wxCSSStyleDeclaration& src) { Add(src); }
    ~wxCSSStyleRef();
    void Add(const wxCSSStyleDeclaration& style);
};
''' % (enum, methods)

    header = cppHeader.Header("CSSStyleDeclaration", "genCSS.py")
    header.add_content(output)
    header.dump(path=config.include_dir)
Ejemplo n.º 9
0
    includes = includes + '#include <w3c/svg/SVG%sElement.hpp>\n' % (classname)

    output = output + '''
   if (nodeName==svg::%s_element_string) {
      svg::SVG%sElement *elem = new svg::SVG%sElement;
      elem->parse(node, owner, viewport);
      return elem;
   } else
''' % (element_cpp_name, classname, classname)

    strdef_output = strdef_output + 'STRDEF(%s,"%s")\n' % (classname,
                                                           element_dtd_name)

output = output + '''
   {
      std::cerr << "element " << nodeName.c_str() << " (type " << node.getNodeType() << ") unknown" << std::endl;
      return 0;
   }
}
'''

#f = open(config.genDir+"/getNextSVGElement.cpp", 'w')
#f.write('// generated by genSvgElement.py\n\n' + includes +'\n'+output)

f = GenFile.gfopen(config.genDir + "/strings_def.hpp", 'w')
f.write('// generated by genSvgElement.py\n\n' + strdef_output)

header = cppHeader.Header("svg", prefix='svg')
header.add_content('// generated by genSvgElement.py\n\n' + includes)
header.dump(path=config.genDir)