From 716aadc00c1a03e43c246a72be4758fcdf809fe0 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 15 Jan 2017 18:45:15 +0100 Subject: working on parser --- tikzit/edge.cpp | 19 ++++ tikzit/edge.h | 26 +++++ tikzit/graph.cpp | 30 ++++++ tikzit/graph.h | 32 ++++++ tikzit/graphelementdata.cpp | 37 +++++++ tikzit/graphelementdata.h | 24 +++++ tikzit/graphelementproperty.cpp | 34 ++++++ tikzit/graphelementproperty.h | 35 ++++++ tikzit/main.cpp | 9 +- tikzit/mainwindow.cpp | 14 ++- tikzit/mainwindow.h | 6 +- tikzit/mainwindow.ui | 36 ++++++- tikzit/node.cpp | 43 ++++++++ tikzit/node.h | 34 ++++++ tikzit/tikzgraphassembler.cpp | 9 ++ tikzit/tikzgraphassembler.h | 25 +++++ tikzit/tikzit.pro | 16 ++- tikzit/tikzit.pro.user | 4 +- tikzit/tikzlexer.lpp | 171 ++++++++++++++++++++++++++++++ tikzit/tikzparser.ypp | 228 ++++++++++++++++++++++++++++++++++++++++ tikzit/tikzparserdefs.h | 2 + tikzit/toolpalette.cpp | 7 +- tikzit/toolpalette.h | 2 +- 23 files changed, 827 insertions(+), 16 deletions(-) create mode 100644 tikzit/edge.cpp create mode 100644 tikzit/edge.h create mode 100644 tikzit/graph.cpp create mode 100644 tikzit/graph.h create mode 100644 tikzit/graphelementdata.cpp create mode 100644 tikzit/graphelementdata.h create mode 100644 tikzit/graphelementproperty.cpp create mode 100644 tikzit/graphelementproperty.h create mode 100644 tikzit/node.cpp create mode 100644 tikzit/node.h create mode 100644 tikzit/tikzgraphassembler.cpp create mode 100644 tikzit/tikzgraphassembler.h create mode 100644 tikzit/tikzlexer.lpp create mode 100644 tikzit/tikzparser.ypp create mode 100644 tikzit/tikzparserdefs.h diff --git a/tikzit/edge.cpp b/tikzit/edge.cpp new file mode 100644 index 0000000..bea96b8 --- /dev/null +++ b/tikzit/edge.cpp @@ -0,0 +1,19 @@ +#include "edge.h" + +Edge::Edge(Node *s, Node *t, QObject *parent) : + QObject(parent), _source(s), _target(t) +{ + +} + +Node *Edge::source() const +{ + return _source; +} + +Node *Edge::target() const +{ + return _target; +} + + diff --git a/tikzit/edge.h b/tikzit/edge.h new file mode 100644 index 0000000..2153f30 --- /dev/null +++ b/tikzit/edge.h @@ -0,0 +1,26 @@ +#ifndef EDGE_H +#define EDGE_H + +#include + +class Node; + +class Edge : public QObject +{ + Q_OBJECT +public: + explicit Edge(Node *s, Node *t, QObject *parent = 0); + + Node *source() const; + Node *target() const; + +signals: + +public slots: + +private: + Node *_source; + Node *_target; +}; + +#endif // EDGE_H diff --git a/tikzit/graph.cpp b/tikzit/graph.cpp new file mode 100644 index 0000000..0db20e1 --- /dev/null +++ b/tikzit/graph.cpp @@ -0,0 +1,30 @@ +#include "graph.h" + +Graph::Graph(QObject *parent) : QObject(parent) +{ + +} + +void Graph::removeNode(Node *n) { + nodes.removeAll(n); + inEdges.remove(n); + outEdges.remove(n); +} + +Edge *Graph::addEdge(Node *s, Node *t) +{ + +} + +void Graph::removeEdge(Edge *e) +{ + +} + +Node *Graph::addNode() { + Node *n = new Node(this); + nodes << n; + return n; +} + + diff --git a/tikzit/graph.h b/tikzit/graph.h new file mode 100644 index 0000000..f55b3c9 --- /dev/null +++ b/tikzit/graph.h @@ -0,0 +1,32 @@ +#ifndef GRAPH_H +#define GRAPH_H + +#include "node.h" +#include "edge.h" + +#include +#include +#include + +class Graph : public QObject +{ + Q_OBJECT +public: + explicit Graph(QObject *parent = 0); + Node *addNode(); + void removeNode(Node *n); + Edge *addEdge(Node *s, Node*t); + void removeEdge(Edge *e); + +signals: + +public slots: + +private: + QVector nodes; + QVector edges; + QMultiHash inEdges; + QMultiHash outEdges; +}; + +#endif // GRAPH_H diff --git a/tikzit/graphelementdata.cpp b/tikzit/graphelementdata.cpp new file mode 100644 index 0000000..7240ea8 --- /dev/null +++ b/tikzit/graphelementdata.cpp @@ -0,0 +1,37 @@ +#include "graphelementdata.h" + +GraphElementData::GraphElementData(QObject *parent) : QObject(parent) +{ + +} + +void GraphElementData::setProperty(QString key, QString value) +{ + +} + +void GraphElementData::unsetProperty(QString key) +{ + +} + +void GraphElementData::setAtom(QString atom) +{ + +} + +void GraphElementData::unsetAtom(QString atom) +{ + +} + +QString GraphElementData::property(QString key) +{ + +} + +QString GraphElementData::atom(QString atom) +{ + +} + diff --git a/tikzit/graphelementdata.h b/tikzit/graphelementdata.h new file mode 100644 index 0000000..e67d740 --- /dev/null +++ b/tikzit/graphelementdata.h @@ -0,0 +1,24 @@ +#ifndef GRAPHELEMENTDATA_H +#define GRAPHELEMENTDATA_H + +#include +#include + +class GraphElementData : public QObject +{ + Q_OBJECT +public: + explicit GraphElementData(QObject *parent = 0); + void setProperty(QString key, QString value); + void unsetProperty(QString key); + void setAtom(QString atom); + void unsetAtom(QString atom); + QString property(QString key); + QString atom(QString atom); + +signals: + +public slots: +}; + +#endif // GRAPHELEMENTDATA_H diff --git a/tikzit/graphelementproperty.cpp b/tikzit/graphelementproperty.cpp new file mode 100644 index 0000000..7602b1c --- /dev/null +++ b/tikzit/graphelementproperty.cpp @@ -0,0 +1,34 @@ +#include "graphelementproperty.h" + +GraphElementProperty::GraphElementProperty(QString key, QString value, + bool atom, bool keyMatch, QObject *parent) : + QObject(parent), _key(key), _value(value), _atom(atom), _keyMatch(keyMatch) +{} + +GraphElementProperty::GraphElementProperty(QString key, QString value, QObject *parent) : + QObject(parent), _key(key), _value(value), _atom(false), _keyMatch(false) +{} + +GraphElementProperty::GraphElementProperty(QString key, QObject *parent) : + QObject(parent), _key(key), _value(""), _atom(true), _keyMatch(false) +{} + +QString GraphElementProperty::key() const +{ return _key; } + +QString GraphElementProperty::value() const +{ return _value; } + +bool GraphElementProperty::atom() const +{ return _atom; } + +bool GraphElementProperty::keyMatch() const +{ return _keyMatch; } + +bool GraphElementProperty::matches(GraphElementProperty *p) +{ + if (p->atom()) return _atom && _key == p->key(); + if (p->keyMatch()) return !_atom && _key == p->key(); + if (_keyMatch) return !p->atom() && _key == p->key(); + return !_atom && _key == p->key() && _value == p->value(); +} diff --git a/tikzit/graphelementproperty.h b/tikzit/graphelementproperty.h new file mode 100644 index 0000000..56d20e9 --- /dev/null +++ b/tikzit/graphelementproperty.h @@ -0,0 +1,35 @@ +#ifndef GRAPHELEMENTPROPERTY_H +#define GRAPHELEMENTPROPERTY_H + +#include + +class GraphElementProperty : public QObject +{ + Q_OBJECT +public: + GraphElementProperty(QString key, QString value, bool atom, bool keyMatch, QObject *parent = 0); + + // construct a property + GraphElementProperty(QString key, QString value, QObject *parent = 0); + + // construct an atom + GraphElementProperty(QString key, QObject *parent = 0); + + QString key() const; + QString value() const; + bool atom() const; + bool keyMatch() const; + + bool matches(GraphElementProperty *p); +signals: + +public slots: + +private: + QString _key; + QString _value; + bool _atom; + bool _keyMatch; +}; + +#endif // GRAPHELEMENTPROPERTY_H diff --git a/tikzit/main.cpp b/tikzit/main.cpp index 7ece416..50c6978 100644 --- a/tikzit/main.cpp +++ b/tikzit/main.cpp @@ -1,5 +1,7 @@ #include "mainwindow.h" #include "toolpalette.h" +#include "graph.h" + #include int main(int argc, char *argv[]) @@ -8,8 +10,13 @@ int main(int argc, char *argv[]) MainWindow *w = new MainWindow(); w->show(); - ToolPalette *tp = new ToolPalette(); + ToolPalette *tp = new ToolPalette(new QMainWindow()); tp->show(); + //w->addToolBar(Qt::LeftToolBarArea, tp); + + Graph *g = new Graph; + Node *n = g->addNode(); + delete g; return a.exec(); } diff --git a/tikzit/mainwindow.cpp b/tikzit/mainwindow.cpp index cbb0f60..ef73a20 100644 --- a/tikzit/mainwindow.cpp +++ b/tikzit/mainwindow.cpp @@ -1,14 +1,20 @@ #include "mainwindow.h" +#include "ui_mainwindow.h" #include -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) { + ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); tikzScene = new TikzScene(this); - tikzView = new QGraphicsView(tikzScene); - setCentralWidget(tikzView); - resize(700, 500); + ui->tikzView->setScene(tikzScene); + //tikzView = new QGraphicsView(tikzScene); + //setCentralWidget(tikzView); + //resize(700, 500); + // badger? } MainWindow::~MainWindow() diff --git a/tikzit/mainwindow.h b/tikzit/mainwindow.h index 167707a..d33a89d 100644 --- a/tikzit/mainwindow.h +++ b/tikzit/mainwindow.h @@ -6,6 +6,10 @@ #include #include +namespace Ui { +class MainWindow; +} + class MainWindow : public QMainWindow { Q_OBJECT @@ -15,7 +19,7 @@ public: ~MainWindow(); private: TikzScene *tikzScene; - QGraphicsView *tikzView; + Ui::MainWindow *ui; }; #endif // MAINWINDOW_H diff --git a/tikzit/mainwindow.ui b/tikzit/mainwindow.ui index d04e8e9..6439ee8 100644 --- a/tikzit/mainwindow.ui +++ b/tikzit/mainwindow.ui @@ -11,9 +11,41 @@ - MainWindow + TikZiT - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Stuff written here</p></body></html> + + + + + + diff --git a/tikzit/node.cpp b/tikzit/node.cpp new file mode 100644 index 0000000..2c1c7ee --- /dev/null +++ b/tikzit/node.cpp @@ -0,0 +1,43 @@ +#include "node.h" + +#include + +Node::Node(QObject *parent) : QObject(parent) +{ + qDebug() << "Node()"; +} + +Node::~Node() +{ + qDebug() << "~Node()"; +} + +QPointF Node::pos() const +{ + return _pos; +} + +void Node::setPos(const QPointF &pos) +{ + _pos = pos; +} + +QString Node::name() const +{ + return _name; +} + +void Node::setName(const QString &name) +{ + _name = name; +} + +QString Node::label() const +{ + return _label; +} + +void Node::setLabel(const QString &label) +{ + _label = label; +} diff --git a/tikzit/node.h b/tikzit/node.h new file mode 100644 index 0000000..8eae520 --- /dev/null +++ b/tikzit/node.h @@ -0,0 +1,34 @@ +#ifndef NODE_H +#define NODE_H + +#include +#include +#include + +class Node : public QObject +{ + Q_OBJECT +public: + explicit Node(QObject *parent = 0); + ~Node(); + + QPointF pos() const; + void setPos(const QPointF &pos); + + QString name() const; + void setName(const QString &name); + + QString label() const; + void setLabel(const QString &label); + +signals: + +public slots: + +private: + QPointF _pos; + QString _name; + QString _label; +}; + +#endif // NODE_H diff --git a/tikzit/tikzgraphassembler.cpp b/tikzit/tikzgraphassembler.cpp new file mode 100644 index 0000000..a785d85 --- /dev/null +++ b/tikzit/tikzgraphassembler.cpp @@ -0,0 +1,9 @@ +#include "tikzgraphassembler.h" + +TikzGraphAssembler::TikzGraphAssembler(QObject *parent) : QObject(parent) +{ + +} + +void TikzGraphAssembler::addNodeToMap(Node *n) { _nodeMap.insert(n->name(), n); } +Node *TikzGraphAssembler::nodeWithName(QString name) { return _nodeMap[name]; } diff --git a/tikzit/tikzgraphassembler.h b/tikzit/tikzgraphassembler.h new file mode 100644 index 0000000..5869d95 --- /dev/null +++ b/tikzit/tikzgraphassembler.h @@ -0,0 +1,25 @@ +#ifndef TIKZGRAPHASSEMBLER_H +#define TIKZGRAPHASSEMBLER_H + +#include "node.h" + +#include +#include + +class TikzGraphAssembler : public QObject +{ + Q_OBJECT +public: + explicit TikzGraphAssembler(QObject *parent = 0); + void addNodeToMap(Node *n); + Node *nodeWithName(QString name); + +signals: + +public slots: + +private: + QHash _nodeMap; +}; + +#endif // TIKZGRAPHASSEMBLER_H diff --git a/tikzit/tikzit.pro b/tikzit/tikzit.pro index 3301c1a..2762908 100644 --- a/tikzit/tikzit.pro +++ b/tikzit/tikzit.pro @@ -26,11 +26,23 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += main.cpp\ mainwindow.cpp \ toolpalette.cpp \ - tikzscene.cpp + tikzscene.cpp \ + graph.cpp \ + node.cpp \ + edge.cpp \ + tikzgraphassembler.cpp \ + graphelementdata.cpp \ + graphelementproperty.cpp HEADERS += mainwindow.h \ toolpalette.h \ - tikzscene.h + tikzscene.h \ + graph.h \ + node.h \ + edge.h \ + tikzgraphassembler.h \ + graphelementdata.h \ + graphelementproperty.h FORMS += mainwindow.ui diff --git a/tikzit/tikzit.pro.user b/tikzit/tikzit.pro.user index 5f8dab8..f8495a5 100644 --- a/tikzit/tikzit.pro.user +++ b/tikzit/tikzit.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -19,7 +19,7 @@ Cpp - CppGlobal + qt diff --git a/tikzit/tikzlexer.lpp b/tikzit/tikzlexer.lpp new file mode 100644 index 0000000..19c4d85 --- /dev/null +++ b/tikzit/tikzlexer.lpp @@ -0,0 +1,171 @@ +%{ +/* + * Copyright 2010 Chris Heunen + * Copyright 2010-2013 Aleks Kissinger + * Copyright 2013 K. Johan Paulsson + * Copyright 2013 Alex Merry + * + * 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 . + */ + +#include "tikzparserdefs.h" +#include "tikzparser.h" + +#include + +#define YY_USER_ACTION \ + yylloc->first_line = yylloc->last_line; \ + yylloc->first_column = yylloc->last_column + 1; \ + yylloc->last_column = yylloc->first_column + yyleng - 1; + +%} + +%option reentrant bison-bridge bison-locations 8bit +%option nounput +%option yylineno +%option noyywrap +%option header-file="common/tikzlexer.h" +%option extra-type="TikzGraphAssembler *" + + +%s props +%s xcoord +%s ycoord +%s noderef + +FLOAT \-?[0-9]*(\.[0-9]+)? + +%% + + /* whitespace is ignored, except for position counting; we don't + count formfeed and vtab as whitespace, because it's not obvious + how they should be dealt with and no-one actually uses them */ + + /* lex will take the longest-matching string */ +\r\n|\r|\n { + yylloc->first_line += 1; + yylloc->last_line = yylloc->first_line; + yylloc->first_column = yylloc->last_column = 0; +} +[\t ]+ { } + +\\begin\{tikzpicture\} { return BEGIN_TIKZPICTURE_CMD; } +\\end\{tikzpicture\} { return END_TIKZPICTURE_CMD; } +\\begin\{pgfonlayer\} { return BEGIN_PGFONLAYER_CMD; } +\\end\{pgfonlayer\} { return END_PGFONLAYER_CMD; } +\\draw { return DRAW_CMD; } +\\node { return NODE_CMD; } +\\path { return PATH_CMD; } +rectangle { return RECTANGLE; } +node { return NODE; } +at { return AT; } +to { return TO; } +; { return SEMICOLON; } + +\([ ]*{FLOAT}[ ]*,[ ]*{FLOAT}[ ]*\) { + yylloc->last_column = yylloc->first_column + 1; + yyless(1); + BEGIN(xcoord); +} +{FLOAT} { + yylval->pt.x=(float)strtod(yytext,NULL); + BEGIN(ycoord); +} +, { } +{FLOAT} { + yylval->pt.y=(float)strtod(yytext,NULL); +} +\) { + BEGIN(INITIAL); + return COORD; +} + + /* when we see "[", change parsing mode */ +\[ /*syntaxhlfix]*/ { + BEGIN(props); + return LEFTBRACKET; +} += { return EQUALS; } +, { return COMMA; } + /* technically, it is possible to have newlines in the middle of + property names or values, but in practice this is unlikely and + screws up our line counting */ +[^=,\{\] \t\n]([^=,\{\]\n]*[^=,\{\] \t\n])? { + yylval->nsstr=[NSString stringWithUTF8String:yytext]; + return PROPSTRING; +} +\] { + BEGIN(INITIAL); + return RIGHTBRACKET; +} + +\( { + BEGIN(noderef); + return LEFTPARENTHESIS; +} +\. { + return FULLSTOP; +} + /* we assume node names (and anchor names) never contain + newlines */ +[^\.\{\)\n]+ { + yylval->nsstr=[NSString stringWithUTF8String:yytext]; + return REFSTRING; +} +\) { + BEGIN(INITIAL); + return RIGHTPARENTHESIS; +} + +\{ { + NSMutableString *buf = [NSMutableString string]; + unsigned int brace_depth = 1; + unsigned int escape = 0; + while (1) { + char c = input(yyscanner); + // eof reached before closing brace + if (c == '\0' || c == EOF) { + return UNCLOSED_DELIM_STR; + } + + yylloc->last_column += 1; + yyleng += 1; + if (escape) { + escape = 0; + } else if (c == '\\') { + escape = 1; + } else if (c == '{') { + brace_depth++; + } else if (c == '}') { + brace_depth--; + if (brace_depth == 0) break; + } else if (c == '\n') { + yylloc->last_line += 1; + yylloc->last_column = 0; + } + [buf appendFormat:@"%c", c]; + } + + yylval->nsstr = buf; + return DELIMITEDSTRING; +} + +\\begin { return UNKNOWN_BEGIN_CMD; } +\\end { return UNKNOWN_END_CMD; } +\\[a-zA-Z0-9]+ { return UNKNOWN_CMD; } +[a-zA-Z0-9]+ { return UNKNOWN_STR; } +. { return UNKNOWN_STR; } + + /* vi:ft=lex:noet:ts=4:sts=4:sw=4: + */ diff --git a/tikzit/tikzparser.ypp b/tikzit/tikzparser.ypp new file mode 100644 index 0000000..e97b1c7 --- /dev/null +++ b/tikzit/tikzparser.ypp @@ -0,0 +1,228 @@ +%{ +/* + * Copyright 2010 Chris Heunen + * Copyright 2010-2013 Aleks Kissinger + * Copyright 2013 K. Johan Paulsson + * Copyright 2013 Alex Merry + * + * 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 . + */ + +#include "tikzparserdefs.h" +%} + +/* we use features added to bison 2.4 */ +%require "2.3" + +%error-verbose +/* enable maintaining locations for better error messages */ +%locations +/* the name of the header file */ +/*%defines "common/tikzparser.h"*/ +/* make it re-entrant (no global variables) */ +%pure-parser +/* We use a pure (re-entrant) lexer. This means yylex + will take a void* (opaque) type to maintain its state */ +%lex-param {void *scanner} +/* Since this parser is also pure, yyparse needs to take + that lexer state as an argument */ +%parse-param {void *scanner} + +/* possible data types for semantic values */ +%union { + QString qstr; + GraphElementProperty *prop; + GraphElementData *data; + Node *node; + QPointF pt; + struct noderef noderef; +} + +%{ +#include "node.h" +#include "edge.h" + #include "graphelementdata.h" +#include "graphelementproperty.h" + +#include "tikzlexer.h" +#import "tikzgraphassembler.h" +/* the assembler (used by this parser) is stored in the lexer + state as "extra" data */ +#define assembler yyget_extra(scanner) + +/* pass errors off to the assembler */ +void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) { + // TODO: implement reportError() + //assembler->reportError(str, yylloc); +} +%} + +/* yyloc is set up with first_column = last_column = 1 by default; + however, it makes more sense to think of us being "before the + start of the line" before we parse anything */ +%initial-action { + yylloc.first_column = yylloc.last_column = 0; +} + + +%token BEGIN_TIKZPICTURE_CMD "\\begin{tikzpicture}" +%token END_TIKZPICTURE_CMD "\\end{tikzpicture}" +%token BEGIN_PGFONLAYER_CMD "\\begin{pgfonlayer}" +%token END_PGFONLAYER_CMD "\\end{pgfonlayer}" +%token DRAW_CMD "\\draw" +%token NODE_CMD "\\node" +%token PATH_CMD "\\path" +%token RECTANGLE "rectangle" +%token NODE "node" +%token AT "at" +%token TO "to" +%token SEMICOLON ";" +%token COMMA "," + +%token LEFTPARENTHESIS "(" +%token RIGHTPARENTHESIS ")" +%token LEFTBRACKET "[" +%token RIGHTBRACKET "]" +%token FULLSTOP "." +%token EQUALS "=" +%token COORD "co-ordinate" +%token PROPSTRING "key/value string" +%token REFSTRING "string" +%token DELIMITEDSTRING "{-delimited string" + +%token UNKNOWN_BEGIN_CMD "unknown \\begin command" +%token UNKNOWN_END_CMD "unknown \\end command" +%token UNKNOWN_CMD "unknown latex command" +%token UNKNOWN_STR "unknown string" +%token UNCLOSED_DELIM_STR "unclosed {-delimited string" + +%type nodename +%type optanchor +%type val +%type property +%type extraproperties +%type properties +%type optproperties +%type optedgenode +%type noderef +%type optnoderef + +%% + +tikzpicture: "\\begin{tikzpicture}" optproperties tikzcmds "\\end{tikzpicture}" + { + if ($2) { + assembler->graph()->setData($2); + } + }; +tikzcmds: tikzcmds tikzcmd | ; +tikzcmd: node | edge | boundingbox | ignore; + +ignore: "\\begin{pgfonlayer}" DELIMITEDSTRING | "\\end{pgfonlayer}"; + +optproperties: + "[" "]" + { $$ = 0; } + | "[" properties "]" + { $$ = $2; } + | { $$ = 0; }; +properties: extraproperties property + { + [$1 addObject:$2]; + $$ = $1; + }; +extraproperties: + extraproperties property "," + { + [$1 addObject:$2]; + $$ = $1; + } + | { $$ = [GraphElementData data]; }; +property: + val "=" val + { $$ = [GraphElementProperty property:$1 withValue:$3]; } + | val + { $$ = [GraphElementProperty atom:$1]; }; +val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; + +nodename: "(" REFSTRING ")" { $$ = $2; }; +node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";" + { + Node *node = assembler->graph()->addNode(); + if ($2) + node->setData($2); + node->setName($3); + node->setPoint($5); + node->setLabel($6); + assembler->addNodeToMap(node); + }; + +optanchor: { $$ = 0; } | "." REFSTRING { $$ = $2; }; +noderef: "(" REFSTRING optanchor ")" + { + $$.node = assembler->nodeWithName($2); + $$.anchor = $3; + }; +optnoderef: + noderef { $$ = $1; } + | "(" ")" { $$.node = 0; $$.anchor = 0; } +optedgenode: + { $$ = 0; } + | "node" optproperties DELIMITEDSTRING + { + // TODO: implement edge-nodes + // $$ = [Node node]; + // if ($2) + // [$$ setData:$2]; + // [$$ setLabel:$3]; + } +edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";" + { + Node *s; + Node *t; + Node *en; + + // TODO: anchors and edge nodes + + s = $3.node; + if ($6.node) { + t = $6.node; + //[edge setTargetAnchor:$6.anchor]; + } else { + t = $3.node; + //[edge setTargetAnchor:$3.anchor]; + } + + Edge *edge = assembler->graph()->addEdge(s, t); + if ($2) + edge->setData($2); + + // [edge setSourceAnchor:$3.anchor]; + // [edge setEdgeNode:$5]; + + // [edge setAttributesFromData]; + }; + +ignoreprop: val | val "=" val; +ignoreprops: ignoreprop ignoreprops | ; +optignoreprops: "[" ignoreprops "]"; +boundingbox: + "\\path" optignoreprops COORD "rectangle" COORD ";" + { + // TODO: bounding box + //[[assembler graph] setBoundingBox:NSRectAroundPoints($3, $5)]; + }; + +/* vi:ft=yacc:noet:ts=4:sts=4:sw=4 +*/ diff --git a/tikzit/tikzparserdefs.h b/tikzit/tikzparserdefs.h new file mode 100644 index 0000000..f721ba5 --- /dev/null +++ b/tikzit/tikzparserdefs.h @@ -0,0 +1,2 @@ +// nothing here + diff --git a/tikzit/toolpalette.cpp b/tikzit/toolpalette.cpp index cd939c2..fd06730 100644 --- a/tikzit/toolpalette.cpp +++ b/tikzit/toolpalette.cpp @@ -4,12 +4,13 @@ #include #include -ToolPalette::ToolPalette() +ToolPalette::ToolPalette(QWidget *parent) : + QToolBar(parent) { setWindowFlags(Qt::Window - | Qt::WindowTitleHint | Qt::WindowStaysOnTopHint - | Qt::CustomizeWindowHint); + | Qt::CustomizeWindowHint + | Qt::WindowDoesNotAcceptFocus); setOrientation(Qt::Vertical); setFocusPolicy(Qt::NoFocus); diff --git a/tikzit/toolpalette.h b/tikzit/toolpalette.h index 158f76c..05b2e12 100644 --- a/tikzit/toolpalette.h +++ b/tikzit/toolpalette.h @@ -10,7 +10,7 @@ class ToolPalette : public QToolBar { Q_OBJECT public: - ToolPalette(); + ToolPalette(QWidget *parent = 0); private: QActionGroup *tools; QAction *select; -- cgit v1.2.3