--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccodeeditor.h"
+
+#include "dccodehighlighter.h"
+
+#include <QtGui>
+
+DCCodeEditor::DCCodeEditor(QWidget *parent) :
+ QPlainTextEdit(parent)
+{
+ QFont font;
+ font.setFamily("Courier");
+ font.setFixedPitch(true);
+ font.setPointSize(10);
+
+ setFont(font);
+
+ mHighlighter = new DCCodeHighlighter(this->document());
+
+ lineNumberArea = new DCLineNumberArea(this);
+
+ connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
+ connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
+// connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
+
+ updateLineNumberAreaWidth(0);
+// highlightCurrentLine();
+
+ QFontMetrics fontMetrics(font);
+ setTabStopWidth(fontMetrics.width(" ") * 4);
+
+ setWordWrapMode(QTextOption::NoWrap);
+
+}
+
+
+int DCCodeEditor::lineNumberAreaWidth()
+{
+ int digits = 1;
+ int max = qMax(1, blockCount());
+ while (max >= 10) {
+ max /= 10;
+ ++digits;
+ }
+
+ int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
+
+ return space;
+}
+
+void DCCodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
+{
+ setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
+}
+
+
+void DCCodeEditor::updateLineNumberArea(const QRect &rect, int dy)
+{
+ if (dy)
+ lineNumberArea->scroll(0, dy);
+ else
+ lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
+
+ if (rect.contains(viewport()->rect()))
+ updateLineNumberAreaWidth(0);
+}
+
+
+void DCCodeEditor::resizeEvent(QResizeEvent *e)
+{
+ QPlainTextEdit::resizeEvent(e);
+
+ QRect cr = contentsRect();
+ lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
+}
+
+void DCCodeEditor::highlightCurrentLine()
+{
+ QList<QTextEdit::ExtraSelection> extraSelections;
+
+ if (!isReadOnly()) {
+ QTextEdit::ExtraSelection selection;
+
+ QColor lineColor = QColor(Qt::yellow).lighter(160);
+
+ selection.format.setBackground(lineColor);
+ selection.format.setProperty(QTextFormat::FullWidthSelection, true);
+ selection.cursor = textCursor();
+ selection.cursor.clearSelection();
+ extraSelections.append(selection);
+ }
+
+ setExtraSelections(extraSelections);
+}
+
+void DCCodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
+{
+ QPainter painter(lineNumberArea);
+ painter.fillRect(event->rect(), Qt::lightGray);
+
+ QTextBlock block = firstVisibleBlock();
+ int blockNumber = block.blockNumber();
+ int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
+ int bottom = top + (int) blockBoundingRect(block).height();
+
+ while (block.isValid() && top <= event->rect().bottom()) {
+ if (block.isVisible() && bottom >= event->rect().top()) {
+ QString number = QString::number(blockNumber + 1);
+ painter.setPen(Qt::black);
+ painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
+ Qt::AlignRight, number);
+ }
+
+ block = block.next();
+ top = bottom;
+ bottom = top + (int) blockBoundingRect(block).height();
+ ++blockNumber;
+ }
+}
+
+QSize DCCodeEditor::sizeHint() const
+{
+ return QSize(800,700);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+
+#ifndef DCCODEEDITOR_H
+#define DCCODEEDITOR_H
+
+#include <QPlainTextEdit>
+
+class DCCodeHighlighter;
+
+class DCCodeEditor : public QPlainTextEdit
+{
+ Q_OBJECT
+public:
+ explicit DCCodeEditor(QWidget *parent = 0);
+
+ void lineNumberAreaPaintEvent(QPaintEvent *event);
+ int lineNumberAreaWidth();
+
+ virtual QSize sizeHint() const;
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+signals:
+
+public slots:
+
+private slots:
+ void updateLineNumberAreaWidth(int newBlockCount);
+ void highlightCurrentLine();
+ void updateLineNumberArea(const QRect &, int);
+
+private:
+ DCCodeHighlighter *mHighlighter;
+ QWidget *lineNumberArea;
+
+};
+
+
+
+class DCLineNumberArea : public QWidget
+{
+public:
+ DCLineNumberArea(DCCodeEditor *editor) : QWidget(editor) {
+ codeEditor = editor;
+ }
+
+ QSize sizeHint() const {
+ return QSize(codeEditor->lineNumberAreaWidth(), 0);
+ }
+
+protected:
+ void paintEvent(QPaintEvent *event) {
+ codeEditor->lineNumberAreaPaintEvent(event);
+ }
+
+private:
+ DCCodeEditor *codeEditor;
+};
+
+#endif // DCCODEEDITOR_H
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+
+#include "dccodehighlighter.h"
+
+#include <QtGui>
+
+DCCodeHighlighter::DCCodeHighlighter(QTextDocument *parent) :
+ QSyntaxHighlighter(parent)
+{
+ HighlightingRule rule;
+
+ keywordFormat.setForeground(QColor(Qt::blue).lighter());
+ keywordFormat.setFontWeight(QFont::Bold);
+ QStringList keywordPatterns;
+ keywordPatterns << "\\bthis.cell.axonValue\\b" << "\\bthis.cell.receptors\\b"
+ << "\\bfunction\\b";
+
+ foreach (const QString &pattern, keywordPatterns) {
+ rule.pattern = QRegExp(pattern);
+ rule.format = keywordFormat;
+ highlightingRules.append(rule);
+ }
+
+ classFormat.setFontWeight(QFont::Bold);
+ classFormat.setForeground(Qt::magenta);
+ rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
+ rule.format = classFormat;
+ highlightingRules.append(rule);
+
+ singleLineCommentFormat.setForeground(Qt::red);
+ rule.pattern = QRegExp("//[^\n]*");
+ rule.format = singleLineCommentFormat;
+ highlightingRules.append(rule);
+
+ multiLineCommentFormat.setForeground(Qt::red);
+
+ quotationFormat.setForeground(QColor(Qt::green).lighter());
+ rule.pattern = QRegExp("\".*\"");
+ rule.format = quotationFormat;
+ highlightingRules.append(rule);
+
+ functionFormat.setFontItalic(true);
+ functionFormat.setForeground(QColor(Qt::blue).lighter(170));
+ rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
+ rule.format = functionFormat;
+ highlightingRules.append(rule);
+
+ commentStartExpression = QRegExp("/\\*");
+ commentEndExpression = QRegExp("\\*/");
+}
+
+
+void DCCodeHighlighter::highlightBlock(const QString &text)
+{
+ foreach (const HighlightingRule &rule, highlightingRules) {
+ QRegExp expression(rule.pattern);
+ int index = expression.indexIn(text);
+ while (index >= 0) {
+ int length = expression.matchedLength();
+ setFormat(index, length, rule.format);
+ index = expression.indexIn(text, index + length);
+ }
+ }
+ setCurrentBlockState(0);
+
+ int startIndex = 0;
+ if (previousBlockState() != 1)
+ startIndex = commentStartExpression.indexIn(text);
+
+ while (startIndex >= 0) {
+ int endIndex = commentEndExpression.indexIn(text, startIndex);
+ int commentLength;
+ if (endIndex == -1) {
+ setCurrentBlockState(1);
+ commentLength = text.length() - startIndex;
+ } else {
+ commentLength = endIndex - startIndex
+ + commentEndExpression.matchedLength();
+ }
+ setFormat(startIndex, commentLength, multiLineCommentFormat);
+ startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
+ }
+}
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+
+#ifndef DCCODEHIGHLIGHTER_H
+#define DCCODEHIGHLIGHTER_H
+
+#include <QSyntaxHighlighter>
+
+class DCCodeHighlighter : public QSyntaxHighlighter
+{
+ Q_OBJECT
+public:
+ explicit DCCodeHighlighter(QTextDocument *parent = 0);
+
+signals:
+
+public slots:
+
+
+protected:
+ void highlightBlock(const QString &text);
+
+private:
+ struct HighlightingRule
+ {
+ QRegExp pattern;
+ QTextCharFormat format;
+ };
+ QVector<HighlightingRule> highlightingRules;
+
+ QRegExp commentStartExpression;
+ QRegExp commentEndExpression;
+
+ QTextCharFormat keywordFormat;
+ QTextCharFormat classFormat;
+ QTextCharFormat singleLineCommentFormat;
+ QTextCharFormat multiLineCommentFormat;
+ QTextCharFormat quotationFormat;
+ QTextCharFormat functionFormat;
+};
+
+#endif // DCCODEHIGHLIGHTER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccommand.h"
+
+#include "dccreator.h"
+
+DCCommand::DCCommand(const void *requester, DCCreator *creator)
+ : d_requester(requester), d_controller(creator)
+{
+ if (creator)
+ {
+ d_scene = creator->getScene();
+ }
+ else
+ {
+ d_scene = NULL;
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCOMMAND_H
+#define DCCOMMAND_H
+
+#include <QUndoCommand>
+
+class DCCreator;
+class DCScene;
+
+class DCCommand : public QUndoCommand
+{
+ const void *d_requester;
+ DCCreator *d_controller;
+ DCScene *d_scene;
+
+public:
+ DCCommand(const void *requester, DCCreator *creator);
+ virtual ~DCCommand() {}
+
+ const void * getRequester() const { return d_requester; }
+ DCCreator * getController() const { return d_controller; }
+ DCScene * getScene() const { return d_scene; }
+};
+
+#endif // DCCOMMAND_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccommandevent.h"
+
+DCCommandEvent::DCCommandEvent(QUndoCommand *command)
+ : QEvent(EVENT_TYPEID), d_command(command)
+{
+}
+
+//static
+const QEvent::Type DCCommandEvent::EVENT_TYPEID = (QEvent::Type) QEvent::registerEventType();
+
+
+DCUndoEvent::DCUndoEvent()
+ : QEvent(EVENT_TYPEID)
+{
+}
+
+//static
+const QEvent::Type DCUndoEvent::EVENT_TYPEID = (QEvent::Type) QEvent::registerEventType();
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCOMMANDEVENT_H
+#define DCCOMMANDEVENT_H
+
+#include <QEvent>
+#include <QUndoCommand>
+
+class DCCommandEvent : public QEvent
+{
+ QUndoCommand *d_command;
+public:
+ DCCommandEvent(QUndoCommand *command);
+ virtual ~DCCommandEvent() {}
+
+ static const Type EVENT_TYPEID;
+ QUndoCommand* getCommand() const { return d_command; }
+};
+
+class DCUndoEvent : public QEvent
+{
+public:
+ DCUndoEvent();
+ virtual ~DCUndoEvent() {}
+
+ static const Type EVENT_TYPEID;
+
+};
+
+#endif // DCCOMMANDEVENT_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dceditcommands.h"
+
+#include "dccreator.h"
+#include "dcscene.h"
+
+#include "dccontainer.h"
+#include "dccell.h"
+#include "dccellcode.h"
+#include "dcaxon.h"
+#include "dcaxonterminal.h"
+#include "dcreceptor.h"
+#include "dcvpagecomponent.h"
+
+#include "dctreeviewwidget.h"
+
+// -----------------------------
+DCStartAddAxonTerminalCommandFromAxon::DCStartAddAxonTerminalCommandFromAxon(const void *requester, DCCreator *creator, DCCell *ownerCell)
+ : DCCommand(requester, creator), d_ownerCell(ownerCell)
+{
+
+}
+
+void DCStartAddAxonTerminalCommandFromAxon::redo()
+{
+ DCAxon *axon = d_ownerCell->getAxon();
+ getScene()->startTerminalEditForAxon(getRequester(), axon);
+}
+
+void DCStartAddAxonTerminalCommandFromAxon::undo()
+{
+ getScene()->finishTerminalEdit(getRequester());
+}
+
+
+// -----------------------------
+DCStartAddAxonTerminalCommandFromReceptor::DCStartAddAxonTerminalCommandFromReceptor(const void *requester, DCCreator *creator, DCCell *ownerCell, const QString &receptorName)
+ : DCCommand(requester, creator), d_ownerCell(ownerCell), d_receptorName(receptorName)
+{
+
+}
+
+void DCStartAddAxonTerminalCommandFromReceptor::redo()
+{
+ DCReceptor *receptor = d_ownerCell->createReceptor(d_receptorName);
+ getScene()->startTerminalEditForReceptor(getRequester(), receptor);
+}
+
+void DCStartAddAxonTerminalCommandFromReceptor::undo()
+{
+ getScene()->finishTerminalEdit(getRequester());
+ d_ownerCell->removeReceptor(d_receptorName);
+}
+
+
+// -----------------------------
+DCCommitAddAxonTerminalCommand::DCCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCAxon *axon, DCCell *receptorCell, const QString &receptorName)
+ : DCCommand(requester, creator), d_receptorCell(receptorCell),d_receptor(NULL), d_receptorName(receptorName), d_isAdded(false)
+{
+ d_axonCell = axon->getOwnerCell();
+}
+
+DCCommitAddAxonTerminalCommand::DCCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCReceptor *receptor)
+ : DCCommand(requester, creator), d_axonCell(axonCell), d_receptor(receptor), d_receptorName(""), d_isAdded(false)
+{
+ d_receptorCell = dynamic_cast<DCCell*>(d_receptor->getOwnerCell());
+}
+
+void DCCommitAddAxonTerminalCommand::redo()
+{
+ if (!d_receptor)
+ {
+ d_isAdded = d_axonCell->connectTo(d_receptorName.toStdString(), d_receptorCell);
+ getScene()->finishTerminalEdit(getRequester());
+ }
+ else
+ {
+ TKAxonTerminal *terminal = d_axonCell->getAxon()->addTerminal();
+ if (terminal)
+ {
+ d_receptor->setTarget(terminal);
+ d_isAdded = true;
+ }
+ getScene()->finishTerminalEdit(getRequester());
+ }
+}
+
+void DCCommitAddAxonTerminalCommand::undo()
+{
+ if (!d_isAdded)
+ return;
+
+ if (!d_receptor)
+ {
+ DCAxon *axon = dynamic_cast <DCAxon*>(d_axonCell->getAxon());
+ DCReceptor *receptor = d_receptorCell->getReceptor(d_receptorName);
+ if (axon && receptor)
+ {
+ DCAxonTerminal *terminal = dynamic_cast<DCAxonTerminal*>(receptor->getTarget());
+ d_receptorCell->removeReceptor(d_receptorName);
+ axon->removeAxonTerminal(terminal);
+ }
+ }
+ else
+ {
+ DCAxon *axon = dynamic_cast <DCAxon*>(d_axonCell->getAxon());
+ QString receptorName = QString::fromStdString(d_receptorCell->getReceptorName(d_receptor));
+ DCAxonTerminal *terminal = dynamic_cast<DCAxonTerminal*>(d_receptor->getTarget());
+
+ d_receptorCell->removeReceptor(receptorName);
+ axon->removeAxonTerminal(terminal);
+ }
+
+}
+
+
+DCDeleteAxonTerminalCommand::DCDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCAxonTerminal *terminal)
+ : DCCommand(requester, creator), d_cell(axonCell), d_axonTerminal(terminal), d_receptorName(""), d_isDeleted(false)
+{
+
+}
+
+DCDeleteAxonTerminalCommand::DCDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *receptorCell, const QString &receptorName)
+ : DCCommand(requester, creator), d_cell(receptorCell), d_axonTerminal(NULL), d_receptorName(receptorName), d_isDeleted(false)
+{
+
+}
+
+void DCDeleteAxonTerminalCommand::redo()
+{
+ if (d_axonTerminal)
+ {
+ //delete from axon terminal
+ DCReceptor *receptor = dynamic_cast<DCReceptor*>(d_axonTerminal->getTarget());
+ DCAxon *axon = dynamic_cast <DCAxon*>(d_axonTerminal->getOwner());
+ if (receptor && axon)
+ {
+ DCCell *targetCell = dynamic_cast<DCCell*>(receptor->getOwnerCell());
+ QString receptorName = QString::fromStdString(targetCell->getReceptorName(receptor));
+ d_isDeleted = targetCell->removeReceptor(receptorName);
+ if (d_isDeleted)
+ axon->removeAxonTerminal(d_axonTerminal);
+ }
+ }
+ else
+ {
+ //delete from receptor name
+ DCReceptor *receptor = d_cell->getReceptor(d_receptorName);
+ DCAxonTerminal *terminal = dynamic_cast<DCAxonTerminal*>(receptor->getTarget());
+ DCAxon *axon = dynamic_cast<DCAxon*>(terminal->getOwner());
+ d_isDeleted = d_cell->removeReceptor(d_receptorName);
+ if (d_isDeleted)
+ axon->removeAxonTerminal(terminal);
+ }
+}
+
+void DCDeleteAxonTerminalCommand::undo()
+{
+ qDebug() << "TODO undo DCDeleteAxonTermianlCommand";
+ //TODO
+}
+
+
+DCStartCellCodeEditCommand::DCStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell)
+ : DCCommand(requester, creator), d_cell(ownerCell)
+{
+
+}
+
+void DCStartCellCodeEditCommand::redo()
+{
+ getScene()->startCellCodeEdit(getRequester(), d_cell);
+
+}
+
+void DCStartCellCodeEditCommand::undo()
+{
+
+}
+
+
+DCStopCellCodeEditCommand::DCStopCellCodeEditCommand(const void *requester, DCCreator *creator)
+ : DCCommand(requester, creator)
+{
+
+}
+
+void DCStopCellCodeEditCommand::redo()
+{
+ getScene()->finishCellCodeEdit(getRequester());
+
+}
+
+void DCStopCellCodeEditCommand::undo()
+{
+
+}
+
+
+/*--------------------------------*/
+DCSetCellCodeClassCommand::DCSetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell, DCCellCode *cellCode)
+ : DCCommand(requester, creator), d_cell(cell), d_cellCode(cellCode), d_prevClass(NULL)
+{
+
+}
+
+void DCSetCellCodeClassCommand::redo()
+{
+ if (d_cell)
+ {
+ d_prevClass = d_cell->getCellCode();
+ d_cell->setCellCode(d_cellCode, NULL);
+ }
+}
+
+void DCSetCellCodeClassCommand::undo()
+{
+ if (d_cell && d_prevClass)
+ {
+ d_cell->setCellCode(d_prevClass, NULL);
+ }
+
+}
+
+
+/*--------------------------------*/
+DCUnsetCellCodeClassCommand::DCUnsetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell)
+ : DCCommand(requester, creator), d_cell(cell), d_prevClass(NULL)
+{
+
+}
+
+void DCUnsetCellCodeClassCommand::redo()
+{
+ if (d_cell)
+ {
+ d_prevClass = d_cell->getCellCode();
+ d_cell->setCellCode(getController()->getCurrentContainer()->getEmptyCellCodeClass(), NULL);
+ }
+}
+
+void DCUnsetCellCodeClassCommand::undo()
+{
+ if (d_cell && d_prevClass)
+ {
+ d_cell->setCellCode(d_prevClass, NULL);
+ }
+
+}
+
+
+/*--------------------------------*/
+
+DCAddCellCodeClassCommand::DCAddCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString &name, const QString &type)
+ : DCCommand(requester, creator), d_container(container), d_name(name), d_type(type)
+{
+
+}
+
+void DCAddCellCodeClassCommand::redo()
+{
+ d_container->addCellCode(d_name.toStdString(), d_type.toStdString(), "\n");
+}
+
+void DCAddCellCodeClassCommand::undo()
+{
+
+}
+
+/*--------------------------------*/
+
+DCAddCellCommand::DCAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString &path, const QString &name, const QString &type)
+ : DCCommand(requester, creator), d_container(container), d_path(path), d_name(name), d_type(type)
+{
+
+}
+
+void DCAddCellCommand::redo()
+{
+ DCCell *cell = dynamic_cast<DCCell*>(d_container->addCell(d_path.toStdString(), d_name.toStdString(), d_type.toStdString(), "\n"));
+ if (cell)
+ {
+ cell->getVComponent()->setSelected(true,true);
+ getController()->selectPage(this, cell->getPageBelonging(), false);
+ if (getController()->getPersMode() != DCCreator::DC_PERSMODE_PAGEEDIT)
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
+ }
+ }
+}
+
+void DCAddCellCommand::undo()
+{
+
+}
+
+/*--------------------------------*/
+static const char *SKELTON_PAGE =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
+ "</html>\n" ;
+
+DCAddPageCommand::DCAddPageCommand(const void *requester, DCCreator *creator, const QString &contentBasedPath)
+ : DCCommand(requester, creator), d_path(contentBasedPath)
+{
+
+}
+
+void DCAddPageCommand::redo()
+{
+ getScene()->addPage(d_path.toStdString());
+ QFile file(QString::fromStdString(getController()->getCurrentContainer()->getContentPath()) + d_path);
+ file.open(QIODevice::WriteOnly | QIODevice::Text);
+ file.write(SKELTON_PAGE);
+ file.close();
+}
+
+void DCAddPageCommand::undo()
+{
+
+}
+
+/*--------------------------------*/
+DCAddDirectoryCommand::DCAddDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysFilePath)
+ : DCCommand(requester, creator), d_path(sysFilePath)
+{
+
+}
+
+void DCAddDirectoryCommand::redo()
+{
+ DCTreeViewWidget::addDirectory(d_path);
+}
+
+void DCAddDirectoryCommand::undo()
+{
+
+}
+
+/*--------------------------------*/
+DCRemoveDirectoryCommand::DCRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysFilePath)
+ : DCCommand(requester, creator), d_path(sysFilePath)
+{
+
+}
+
+void DCRemoveDirectoryCommand::redo()
+{
+ DCTreeViewWidget::removeDirectory(d_path);
+}
+
+void DCRemoveDirectoryCommand::undo()
+{
+
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCEDITCOMMANDS_H
+#define DCEDITCOMMANDS_H
+
+#include "dccommand.h"
+
+class DCCell;
+class DCCellCode;
+class DCContainer;
+class DCAxon;
+class DCReceptor;
+class DCAxonTerminal;
+
+class DCStartAddAxonTerminalCommandFromAxon : public DCCommand
+{
+ DCCell *d_ownerCell;
+
+public:
+ DCStartAddAxonTerminalCommandFromAxon(const void *requester, DCCreator *creator, DCCell *ownerCell);
+ virtual ~DCStartAddAxonTerminalCommandFromAxon() {}
+ void undo();
+ void redo();
+};
+
+
+class DCStartAddAxonTerminalCommandFromReceptor : public DCCommand
+{
+ DCCell *d_ownerCell;
+ QString d_receptorName;
+
+public:
+ DCStartAddAxonTerminalCommandFromReceptor(const void *requester, DCCreator *creator, DCCell *ownerCell, const QString &receptorName);
+ virtual ~DCStartAddAxonTerminalCommandFromReceptor() {}
+ void undo();
+ void redo();
+};
+
+
+//------------------------------------------
+
+class DCCommitAddAxonTerminalCommand : public DCCommand
+{
+ DCCell *d_axonCell;
+ DCCell *d_receptorCell;
+ DCReceptor *d_receptor;
+ QString d_receptorName;
+ bool d_isAdded;
+
+public:
+ DCCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCAxon *axon, DCCell *receptorCell, const QString &receptorName);
+ DCCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCReceptor *receptor);
+ virtual ~DCCommitAddAxonTerminalCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCDeleteAxonTerminalCommand : public DCCommand
+{
+ DCCell *d_cell;
+ DCAxonTerminal *d_axonTerminal;
+ QString d_receptorName;
+ bool d_isDeleted;
+public:
+ DCDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCAxonTerminal *terminal);
+ DCDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *receptorCell, const QString& receptorName);
+ virtual ~DCDeleteAxonTerminalCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCStartCellCodeEditCommand : public DCCommand
+{
+ DCCell *d_cell;
+public:
+ DCStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell);
+ virtual ~DCStartCellCodeEditCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCStopCellCodeEditCommand : public DCCommand
+{
+public:
+ DCStopCellCodeEditCommand(const void *requester, DCCreator *creator);
+ virtual ~DCStopCellCodeEditCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCSetCellCodeClassCommand : public DCCommand
+{
+ DCCell *d_cell;
+ DCCellCode *d_cellCode;
+ DCCellCode *d_prevClass;
+public:
+ DCSetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell, DCCellCode *cellCode);
+ virtual ~DCSetCellCodeClassCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCUnsetCellCodeClassCommand : public DCCommand
+{
+ DCCell *d_cell;
+ DCCellCode *d_prevClass;
+public:
+ DCUnsetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell);
+ virtual ~DCUnsetCellCodeClassCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCAddCellCodeClassCommand : public DCCommand
+{
+ DCContainer *d_container;
+ QString d_name;
+ QString d_type;
+
+public:
+ DCAddCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& name, const QString &type);
+ virtual ~DCAddCellCodeClassCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCAddCellCommand : public DCCommand
+{
+ DCContainer *d_container;
+ QString d_path;
+ QString d_name;
+ QString d_type;
+
+public:
+ DCAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& path, const QString& name, const QString &type);
+ virtual ~DCAddCellCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCAddPageCommand : public DCCommand
+{
+ QString d_path;
+public:
+ DCAddPageCommand(const void *requester, DCCreator *creator, const QString& contentBasedPathName);
+ virtual ~DCAddPageCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCAddDirectoryCommand : public DCCommand
+{
+ QString d_path;
+public:
+ DCAddDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
+ virtual ~DCAddDirectoryCommand() {}
+ void undo();
+ void redo();
+};
+
+class DCRemoveDirectoryCommand : public DCCommand
+{
+ QString d_path;
+public:
+ DCRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
+ virtual ~DCRemoveDirectoryCommand() {}
+ void undo();
+ void redo();
+};
+
+#endif // DCEDITCOMMANDS_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcanimationtimer.h"
+
+//static
+DCAnimationTimer* DCAnimationTimer::instance()
+{
+ static DCAnimationTimer timer;
+
+ return &timer;
+}
+
+DCAnimationTimer::DCAnimationTimer(QObject *parent) :
+ QThread(parent), mTerminate(false)
+{
+ start();
+}
+
+DCAnimationTimer::~DCAnimationTimer()
+{
+ mTerminate = true;
+ wait(1000);
+}
+
+void DCAnimationTimer::run()
+{
+ while(!mTerminate)
+ {
+ emit goNextFrame();
+ msleep(50);
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCANIMATIONTIMER_H
+#define DCANIMATIONTIMER_H
+
+#include <QThread>
+
+class DCAnimationTimer : public QThread
+{
+ Q_OBJECT
+public:
+ static DCAnimationTimer* instance();
+
+private:
+ explicit DCAnimationTimer(QObject *parent = 0);
+ virtual ~DCAnimationTimer();
+
+ void run();
+
+signals:
+ void goNextFrame();
+
+public slots:
+
+private:
+ bool mTerminate;
+
+};
+
+#endif // DCANIMATIONTIMER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcaxon.h"
+
+#include "dcvcomponent.h"
+#include "dccell.h"
+#include "dcaxonterminal.h"
+#include "dcvceditmodecursor.h"
+#include "dcvceditmodeterminal.h"
+
+DCAxon::DCAxon(DCCell *theOwner) : TKAxon(theOwner), d_ownerCell(theOwner), d_vComponent(NULL),
+ d_viewLength(0), d_viewAngle(0), d_isTerminalVisible(true), d_editCursor(NULL)
+{
+}
+
+DCAxon::~DCAxon()
+{
+ if (d_vComponent)
+ {
+ delete d_vComponent;
+ d_vComponent = NULL;
+ }
+}
+
+void DCAxon::bindComponent(DCVComponent *component)
+{
+ d_vComponent = component;
+ d_vComponent->updateShape();
+}
+
+DCAxonTerminal* DCAxon::getTerminalAt(int i) const
+{
+ return dynamic_cast<DCAxonTerminal*>(mTerminals.at(i));
+}
+
+DCCell* DCAxon::getOwnerCell() const
+{
+ return d_ownerCell;
+}
+
+float DCAxon::getViewLength() const
+{
+ return d_viewLength;
+}
+
+float DCAxon::getViewAngle() const
+{
+ return d_viewAngle;
+}
+
+void DCAxon::setViewLength(float length)
+{
+ if (d_viewLength != length && length > 0)
+ {
+ d_viewLength = length;
+ if (d_vComponent)
+ d_vComponent->updateShape();
+ }
+}
+
+void DCAxon::setViewAngle(float angle)
+{
+ if (d_viewAngle != angle)
+ {
+ d_viewAngle = angle;
+ if (d_vComponent)
+ d_vComponent->updateShape();
+ }
+}
+
+bool DCAxon::hasEditingTerminal() const
+{
+ return d_editCursor != NULL;
+}
+
+DCVComponent* DCAxon::getEditingTerminal() const
+{
+ return d_editCursor->getTerminal();
+}
+
+void DCAxon::setEditingCursorViewMatrix(const float matrix[])
+{
+ Q_ASSERT(d_editCursor);
+ DCVCEditModeTerminal *terminal = d_editCursor->getTerminal();
+
+ Q_ASSERT(terminal);
+ terminal->setViewMatrixForAxonPoint(matrix);
+}
+
+bool DCAxon::removeAxonTerminal(DCAxonTerminal *terminal)
+{
+ bool found = false;
+ for ( std::vector<TKAxonTerminal*>::iterator it = mTerminals.begin(); it != mTerminals.end(); ++it ) {
+ if (*it == terminal)
+ {
+ mTerminals.erase(it);
+ delete terminal;
+ found = true;
+ break;
+ }
+ }
+ return found;
+}
+
+void DCAxon::registerEditCursor(DCVCEditModeCursor *cursor)
+{
+ d_editCursor = cursor;
+}
+
+void DCAxon::unregisterEditCursor()
+{
+ d_editCursor = NULL;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCAXON_H
+#define DCAXON_H
+
+#include "TKAxon.h"
+
+class DCCell;
+class DCAxonTerminal;
+class DCVComponent;
+class DCVCEditModeCursor;
+
+class DCAxon : public TKAxon
+{
+ friend class DCComponentUtil;
+
+ DCAxon(DCCell *theOwner);
+ void bindComponent(DCVComponent *component);
+
+ DCCell *d_ownerCell;
+ DCVComponent *d_vComponent;
+ float d_viewLength;
+ float d_viewAngle;
+ bool d_isTerminalVisible;
+ DCVCEditModeCursor *d_editCursor;
+
+public:
+ virtual ~DCAxon();
+
+ DCVComponent * getVComponent() const { return d_vComponent; }
+ inline int getNumberOfTerminals() const { return mTerminals.size(); }
+ DCAxonTerminal* getTerminalAt(int i) const;
+ DCCell* getOwnerCell() const;
+ float getViewLength() const;
+ float getViewAngle() const;
+ bool getIsTerminalVisible() const { return d_isTerminalVisible; }
+
+ bool hasEditingTerminal() const;
+ DCVComponent* getEditingTerminal() const;
+
+ void setViewLength(float length);
+ void setViewAngle(float angle);
+ void setTerminalVisible(bool visible) { d_isTerminalVisible = visible; }
+
+ void setEditingCursorViewMatrix(const float matrix[]);
+ void registerEditCursor(DCVCEditModeCursor *cursor);
+ void unregisterEditCursor();
+
+ //Called from command
+ //this will remove axon terminal from the list and the object itself
+ bool removeAxonTerminal(DCAxonTerminal *terminal);
+
+};
+
+#endif // DCAXON_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcaxonterminal.h"
+
+#include "dcvcomponent.h"
+#include "dcaxon.h"
+
+DCAxonTerminal::DCAxonTerminal(DCAxon *theOwner) : TKAxonTerminal(theOwner), mVComponent(NULL),
+ mIsViewReceptorPointUpdated(false), mIsViewAxonPointUpdated(false)
+
+{
+}
+
+DCAxonTerminal::~DCAxonTerminal()
+{
+ if (mVComponent)
+ {
+ delete mVComponent;
+ mVComponent = NULL;
+ }
+}
+
+void DCAxonTerminal::setViewMatrixForAxonPoint(const float matrix[])
+{
+ for (int i = 0; i < 16; i++)
+ {
+ mViewAxonPointMatrix[i] = matrix[i];
+ }
+
+ mIsViewAxonPointUpdated = true;
+}
+
+void DCAxonTerminal::setViewMatrixForReceptorPoint(const float matrix[])
+{
+ for (int i = 0; i < 16; i++)
+ {
+ mViewReceptorPointMatrix[i] = matrix[i];
+ }
+
+ mIsViewReceptorPointUpdated = true;
+}
+
+void DCAxonTerminal::resetViewPoinMatrices()
+{
+ mIsViewAxonPointUpdated = false;
+ mIsViewReceptorPointUpdated = false;
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCAXONTERMINAL_H
+#define DCAXONTERMINAL_H
+
+#include "TKAxonTerminal.h"
+
+#include <QList>
+
+class DCAxon;
+class DCVCAxonTerminal;
+class DCVComponent;
+
+class DCAxonTerminal : public TKAxonTerminal
+{
+ friend class DCComponentUtil;
+ DCAxonTerminal(DCAxon *theOwner);
+ void bindComponent(DCVComponent *component) { mVComponent = component; }
+
+ DCVComponent *mVComponent;
+ bool mIsViewReceptorPointUpdated;
+ bool mIsViewAxonPointUpdated;
+ float mViewAxonPointMatrix[16];
+ float mViewReceptorPointMatrix[16];
+
+public:
+ virtual ~DCAxonTerminal();
+
+ DCVComponent* getVComponent() const { return mVComponent; }
+ bool getIsViewAxonPointUpdated() const { return mIsViewAxonPointUpdated; }
+ bool getIsViewReceptorPointUpdated() const { return mIsViewReceptorPointUpdated; }
+ const float* getViewAxonPointMatrix() const { return mViewAxonPointMatrix; }
+ const float* getViewReceptorPointMatrix() const { return mViewReceptorPointMatrix; }
+
+ void setViewMatrixForAxonPoint(const float matrix[16]);
+ void setViewMatrixForReceptorPoint(const float matrix[16]);
+ void resetViewPoinMatrices();
+};
+
+#endif // DCAXONTERMINAL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccell.h"
+
+#include "dcvpagecomponent.h"
+#include "dccontainer.h"
+#include "dcaxon.h"
+#include "dcreceptor.h"
+#include "dccellcode.h"
+#include "DCAxonTerminal.h"
+
+#include "DNUtils.h"
+
+const float DCCell::S_MAXSIZE = 5;
+const float DCCell::S_MINSIZE = 0.5;
+
+DCCell::DCCell(DCContainer *container, std::string location, std::string name, std::string type, bool canInterface) :
+ TKCell(container, location, name, canInterface), d_vComponent(NULL), d_cellCode(NULL),
+ d_viewSize(0.5), d_viewHeight(0.5)
+{
+ d_type = QString::fromStdString(type);
+}
+
+DCCell::~DCCell()
+{
+ if (d_vComponent)
+ {
+ delete d_vComponent;
+ d_vComponent = NULL;
+ }
+}
+
+void DCCell::bindComponent(DCVPageComponent *component)
+{
+ d_vComponent = component;
+ d_vComponent->updateShape();
+}
+
+std::string DCCell::getReceptorName(DCReceptor *receptor) const
+{
+ for ( TKReceptorMap::const_iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
+ if (it->second == receptor)
+ {
+ return it->first;
+ }
+ }
+ return "";
+}
+
+DCReceptor* DCCell::getReceptor(const QString &receptorName)
+{
+ DCReceptor *receptor = NULL;
+ const TKReceptorMap *receptors = getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ QString aReceptorName = QString::fromStdString((*it).first);
+ if (receptorName == aReceptorName)
+ {
+ receptor = dynamic_cast<DCReceptor*>((*it).second);
+ break;
+ }
+ ++it;
+ }
+ return receptor;
+}
+
+bool DCCell::setCellCode(TKCellCode *code, const void *data)
+{
+ bool r = false;
+
+ if (d_cellCode != code)
+ {
+ d_cellCode = dynamic_cast<DCCellCode*>(code);
+ r = TKCell::setCellCode(code,data);
+
+ if (d_vComponent)
+ d_vComponent->updateShape();
+
+ emit cellCodeChanged();
+ }
+ return r;
+}
+
+DCVCPage* DCCell::getPageBelonging() const
+{
+ return d_vComponent->getPageBelonging();
+}
+
+DCAxon* DCCell::getAxon() const
+{
+ return dynamic_cast<DCAxon*>(mAxon);
+}
+
+QString DCCell::getCustomScript() const
+{
+ return ((DCContainer*)mContainer)->readCustomScriptFromWorkFile(this);
+}
+
+bool DCCell::saveCustomScript(const QString &script)
+{
+ return ((DCContainer*)mContainer)->saveCustomScriptToWorkFile(this, script.toStdString());
+}
+
+QString DCCell::getType() const
+{
+ return d_type;
+}
+
+float DCCell::getViewPageX() const
+{
+ return d_vComponent->getPageX();
+}
+
+float DCCell::getViewPageY() const
+{
+ return d_vComponent->getPageY();
+}
+
+float DCCell::getViewSize() const
+{
+ return d_viewSize;
+}
+
+float DCCell::getViewHeight() const
+{
+ return d_viewHeight;
+}
+
+void DCCell::getViewHCrossPoint(float dx, float dz, float *outX, float *outZ) const
+{
+ float offset = d_viewSize * 0.5;
+
+ *outX = 0;
+ *outZ = 0;
+
+ if (dx == 0)
+ {
+ *outZ = dz < 0 ? -offset : offset;
+ }
+ else
+ {
+ float a = fabs(dz / dx);
+ if (a < 1)
+ {
+ *outX = offset * (dx < 0 ? -1 : 1);
+ *outZ = offset * a * (dz < 0 ? -1 : 1);
+ }
+ else
+ {
+ *outX = offset / a * (dx < 0 ? -1 : 1);
+ *outZ = offset * (dz < 0 ? -1 : 1);
+ }
+ }
+}
+
+void DCCell::getViewVCrossPoint(float dx, float dy, float *outX, float *outY) const
+{
+ //TODO
+}
+
+void DCCell::setViewPageX(float x)
+{
+ d_vComponent->setPageX(x);
+}
+
+void DCCell::setViewPageY(float y)
+{
+ d_vComponent->setPageY(y);
+}
+
+void DCCell::setViewSize(float size)
+{
+ if (size > S_MAXSIZE)
+ size = S_MAXSIZE;
+ else if (size < S_MINSIZE)
+ size = S_MINSIZE;
+
+ if (d_viewSize != size)
+ {
+ d_viewSize = size;
+ if (d_vComponent)
+ d_vComponent->updateShape();
+ }
+}
+
+void DCCell::setViewHeight(float _height)
+{
+ if (d_viewHeight != _height)
+ {
+ d_viewHeight = _height;
+ if (d_vComponent)
+ d_vComponent->updateShape();
+ }
+}
+
+bool DCCell::removeReceptor(const QString &name)
+{
+ TKReceptorMap::iterator it = mReceptors.find(name.toStdString());
+ if (it != mReceptors.end())
+ {
+ TKReceptor *receptor = (*it).second;
+ mReceptors.erase(it);
+ delete receptor;
+ return true;
+ }
+ return false;
+}
+
+DCReceptor* DCCell::createReceptor(const QString &receptorName)
+{
+ return dynamic_cast<DCReceptor*>(TKCell::createReceptor(receptorName.toStdString()));
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCELL_H
+#define DCCELL_H
+
+#include "TKCell.h"
+
+class DCContainer;
+class DCAxon;
+class DCAxonTerminal;
+class DCReceptor;
+class DCCellCode;
+class DCVComponent;
+class DCVPageComponent;
+class DCVCPage;
+
+#include <QObject>
+#include <QString>
+
+class DCCell : public QObject, public TKCell
+{
+ Q_OBJECT
+
+ friend class DCComponentUtil;
+ DCCell(DCContainer *container, std::string location, std::string name, std::string type, bool canInterface);
+ void bindComponent(DCVPageComponent *component);
+
+ DCVPageComponent *d_vComponent;
+ DCCellCode *d_cellCode;
+ QString d_type;
+ float d_viewSize;
+ float d_viewHeight;
+
+ const static float S_MINSIZE;
+ const static float S_MAXSIZE;
+
+public:
+ virtual ~DCCell();
+
+ virtual bool doTick(float time) {return false;}
+ virtual bool doInit() {return false;}
+ virtual bool doDestroy() {return false;}
+ virtual bool setCellCode(TKCellCode *code, const void *data);
+
+ DCVPageComponent * getVComponent() const { return d_vComponent; }
+ DCVCPage* getPageBelonging() const;
+ DCCellCode* getCellCode() const { return d_cellCode; }
+ DCAxon* getAxon() const;
+ std::string getReceptorName(DCReceptor *receptor) const;
+ DCReceptor* getReceptor(const QString& receptorName);
+ QString getCustomScript() const;
+ QString getType() const;
+ float getViewPageX() const;
+ float getViewPageY() const;
+ float getViewSize() const;
+ float getViewHeight() const;
+ void getViewHCrossPoint(float dx, float dz, float *outX, float *outZ) const;
+ void getViewVCrossPoint(float dx, float dy, float *outX, float *outY) const;
+
+ void setViewPageX(float x);
+ void setViewPageY(float y);
+ void setViewSize(float size);
+ void setViewHeight(float height);
+ bool saveCustomScript(const QString& script);
+
+ /* This method is exepected to be called from command.
+ * This will remove receptor from the list
+ * This will remove receptor object but won't remove the axon terminal connected to the receptor
+ */
+ bool removeReceptor(const QString &name);
+
+ /* This method is exepected to be called from command.
+ */
+ virtual DCReceptor* createReceptor(const QString &receptorName);
+
+signals:
+ void cellCodeChanged();
+
+
+};
+
+#endif // DCCELL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccellcode.h"
+
+#include "dcvccellcode.h"
+#include "dccontainer.h"
+
+DCCellCode::DCCellCode(std::string theName, std::string theCellAPIName)
+ : TKCellCode(theName, theCellAPIName)
+{
+}
+
+DCCellCode::~DCCellCode()
+{
+}
+
+QString DCCellCode::getOwnScript(DCContainer *container) const
+{
+ return container->readCellCodeScriptFromFile(this);
+}
+
+void DCCellCode::saveScript(DCContainer *container, const QString &script)
+{
+ container->saveClassScriptToWorkFile(this, script.toStdString());
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCELLCODE_H
+#define DCCELLCODE_H
+
+#include "TKCellCode.h"
+
+#include <QString>
+
+class DCVCCellCode;
+class TKCellCodeInstance;
+class DCVComponent;
+class DCContainer;
+
+class DCCellCode : public TKCellCode
+{
+ friend class DCComponentUtil;
+ DCCellCode(std::string theName, std::string theCellAPIName);
+ void bindComponent(DCVComponent *component) { mVComponent = component; }
+
+ DCVComponent *mVComponent;
+
+public:
+ virtual ~DCCellCode();
+ virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data) { return 0; }
+
+ void saveScript(DCContainer *container, const QString& script);
+ DCVComponent *getVComponent() const { return mVComponent; }
+ QString getOwnScript(DCContainer *container) const;
+
+};
+
+#endif // DCCELLCODE_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccontainer.h"
+
+#include "dccell.h"
+#include "dccellcode.h"
+#include "dcaxon.h"
+#include "dcaxonterminal.h"
+#include "dcreceptor.h"
+#include "DNUtils.h"
+#include "dcscene.h"
+#include "dccontent.h"
+#include "dccreator.h"
+#include "dcvcomponent.h"
+#include "dcvpagecomponent.h"
+#include "utils/dccomponentutil.h"
+
+#include "DNFileList.h"
+#include "DNDirectory.h"
+
+#include <QMutexLocker>
+#include <QDir>
+#include <QDirIterator>
+
+//static
+TKContainer* TKContainer::createContainer()
+{
+ TKContainer *container = new DCContainer();
+ container->init();
+ return container;
+}
+
+DCContainer::DCContainer() : d_content(NULL), d_factoryCachedLocation(""), d_factoryCachedPageObject(NULL)
+{
+ d_scene = new DCScene(this);
+
+ d_workDirRoot = QDir::homePath() + "/.denncoCreator/work";
+ d_workDirCellRoot = d_workDirRoot + "/cells";
+ d_workDirCellCodeRoot = d_workDirRoot + "/cellcodes";
+
+}
+
+DCContainer::~DCContainer()
+{
+ if (d_scene)
+ {
+ delete d_scene;
+ d_scene = NULL;
+ }
+}
+
+bool DCContainer::isScriptableCell(DCCell *cell)
+{
+ bool noScript = false;
+
+ std::string type = cell->getType().toStdString();
+
+ if (type == CELLTYPE_JSBASIC || type.length() == 0)
+ {
+ noScript = false;
+ }
+ else if (type == CELLTYPE_IN)
+ {
+ noScript = true;
+ }
+ else if (type == CELLTYPE_OUT)
+ {
+ noScript = true;
+ }
+ else if (type == CELLTYPE_BASICSTORAGE)
+ {
+ noScript = false;
+ }
+ else
+ {
+ Q_ASSERT(0);
+ }
+ return !noScript;
+}
+
+void DCContainer::setContent(DCContent *content)
+{
+ d_content = content;
+}
+
+void DCContainer::unselectCellObjectAll()
+{
+ for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
+ DCCell *cell = dynamic_cast<DCCell*>(it->second);
+ if (cell)
+ cell->getVComponent()->setSelected(false,true);
+ }
+}
+
+QList<DCVComponent*> DCContainer::getSelectedCellObjects() const
+{
+ QList<DCVComponent*> list;
+
+ for ( TKCellMap::const_iterator it = mCells.begin(); it != mCells.end(); ++it ) {
+ DCCell *cell = dynamic_cast<DCCell*>(it->second);
+ if (cell)
+ {
+ DCVComponent *object = NULL;
+
+ object = cell->getVComponent();
+ if (object && object->getIsSelected())
+ {
+ list.push_back(object);
+ }
+
+ //axon
+ DCAxon *axon = cell->getAxon();
+ object = axon->getVComponent();
+ if (object && object->getIsSelected())
+ {
+ list.push_back(object);
+ }
+
+ //terminals
+ int n = axon->getNumberOfTerminals();
+ for (int i = 0; i < n; i++)
+ {
+ object = axon->getTerminalAt(i)->getVComponent();
+ if (object && object->getIsSelected())
+ {
+ list.push_back(object);
+ }
+ }
+
+ //receptors
+ const TKReceptorMap *receptors = cell->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ object = ((DCReceptor*)(*it).second)->getVComponent();
+ if (object && object->getIsSelected())
+ {
+ list.push_back(object);
+ }
+ ++it;
+ }
+ }
+ }
+
+ return list;
+}
+
+TKCell* DCContainer::addCell(std::string theLocation, std::string theName, std::string type, std::string customScript)
+{
+ QMutexLocker(d_scene->getSceneLock());
+
+ TKCell *cell = TKContainer::addCell(theLocation, theName, type, customScript);
+
+ saveCustomScriptToWorkFile(cell, customScript);
+
+ return cell;
+}
+
+TKCell* DCContainer::addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript)
+{
+ QMutexLocker(d_scene->getSceneLock());
+
+ TKCell *cell = TKContainer::addCell(theLocation, theName, cellCode, customScript);
+
+ saveCustomScriptToWorkFile(cell, customScript);
+
+ return cell;
+}
+
+TKCellCode* DCContainer::addCellCode(std::string theName, std::string theAPIType, std::string code)
+{
+ QMutexLocker(d_scene->getSceneLock());
+
+ TKCellCode *cellCode = TKContainer::addCellCode(theName, theAPIType, code);
+
+ saveClassScriptToWorkFile(cellCode, code);
+
+ return cellCode;
+}
+
+TKCell* DCContainer::cellFactory(std::string location, std::string name, std::string type, bool canInterface)
+{
+ if (location != d_factoryCachedLocation || d_factoryCachedPageObject == NULL)
+ {
+ d_factoryCachedPageObject = d_scene->findPage(location);
+ if (d_factoryCachedPageObject == NULL)
+ {
+ d_factoryCachedPageObject = d_scene->addPage(location);
+ }
+ }
+ d_factoryCachedLocation = location;
+
+ TKCell *cell = DCComponentUtil::createCell(this, d_factoryCachedPageObject, location, name, type, canInterface);
+ cell->init();
+
+ return cell;
+}
+
+TKAxon* DCContainer::axonFactory(TKCell *theOwner)
+{
+ return DCComponentUtil::createAxon((DCCell*)theOwner);
+}
+
+TKReceptor* DCContainer::receptorFactory(TKCell *theOwner)
+{
+ return DCComponentUtil::createReceptor((DCCell*)theOwner);
+}
+
+TKAxonTerminal* DCContainer::axonTerminalFactory(TKAxon *theOwner)
+{
+ return DCComponentUtil::createAxonTerminal((DCAxon*)theOwner);
+}
+
+TKCellCode* DCContainer::cellCodeFactory(std::string name, std::string cellapi, std::string code)
+{
+ return DCComponentUtil::createCellCode(name, cellapi);
+}
+
+void DCContainer::beganParsePage(const char *docRoot, const char *path)
+{
+ QDir workCellDir(d_workDirCellRoot + "/" + QString::fromLocal8Bit(path));
+ QDir workCellCodeDir(d_workDirCellCodeRoot + "/" + QString::fromLocal8Bit(path));
+ if (!workCellDir.exists())
+ {
+ workCellDir.mkpath(workCellDir.absolutePath());
+ }
+ if (!workCellCodeDir.exists())
+ {
+ workCellCodeDir.mkpath(workCellCodeDir.absolutePath());
+ }
+
+ std::string location = path;
+ d_factoryCachedPageObject = d_scene->findPage(location);
+ if (d_factoryCachedPageObject == NULL)
+ {
+ d_factoryCachedPageObject = d_scene->addPage(location);
+ }
+ d_factoryCachedLocation = location;
+}
+
+void DCContainer::endedParsePage(const char *docRoot, const char *path)
+{
+
+}
+
+
+void DCContainer::beganBuildContainer()
+{
+ removeDirRecursive(d_workDirRoot);
+}
+
+void DCContainer::endedBuildContainer()
+{
+
+
+}
+
+bool DCContainer::saveCustomScriptToWorkFile(TKCell *cell, std::string customScript)
+{
+ QDir workdir(d_workDirCellRoot + "/" + QString::fromStdString(cell->getLocation()));
+ if (!workdir.exists())
+ {
+ workdir.mkpath(workdir.absolutePath());
+ }
+ QFile workfile(workdir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
+ workfile.open(QIODevice::WriteOnly);
+ QTextStream out(&workfile);
+ out << QString::fromStdString(customScript);
+ workfile.close();
+ return true;
+}
+
+bool DCContainer::saveClassScriptToWorkFile(TKCellCode *cellCode, std::string code)
+{
+ QString qNamePath = QString::fromStdString(cellCode->getName());
+ int idx = qNamePath.lastIndexOf("#");
+ QString path;
+ QString name;
+ if (idx >= 0)
+ {
+ path = qNamePath.left(idx);
+ name = qNamePath.mid(idx + 1);
+ }
+ else
+ {
+ path = "";
+ name = qNamePath;
+ }
+
+ QDir workdir(d_workDirCellCodeRoot + "/" + path);
+ if (!workdir.exists())
+ {
+ workdir.mkpath(workdir.absolutePath());
+ }
+ QFile workfile(workdir.absoluteFilePath(name + ".js"));
+ workfile.open(QIODevice::WriteOnly);
+ QTextStream out(&workfile);
+ out << QString::fromStdString(code);
+ workfile.close();
+ return true;
+}
+
+QString DCContainer::readCustomScriptFromWorkFile(const DCCell *cell)
+{
+ QFile file(d_workDirCellRoot + "/" + QString::fromStdString(cell->getLocation()) + "/" + QString::fromStdString(cell->getName()) + ".js");
+
+ if (!file.exists())
+ {
+ return "";
+ }
+
+ file.open(QIODevice::ReadOnly);
+ QTextStream in(&file);
+ QString out = in.readAll();
+ file.close();
+
+ return out;
+}
+
+QString DCContainer::readCellCodeScriptFromFile(const DCCellCode *cellCode)
+{
+ QString qNamePath = QString::fromStdString(cellCode->getName());
+ int idx = qNamePath.lastIndexOf("#");
+ QString path;
+ QString name;
+ if (idx >= 0)
+ {
+ path = qNamePath.left(idx);
+ name = qNamePath.mid(idx + 1);
+ }
+ else
+ {
+ path = "";
+ name = qNamePath;
+ }
+
+ QFile file(d_workDirCellCodeRoot + "/" + path + "/" + name + ".js");
+ if (!file.exists())
+ {
+ return "";
+ }
+
+ file.open(QIODevice::ReadOnly);
+ QTextStream in(&file);
+ QString out = in.readAll();
+ file.close();
+
+ return out;
+}
+
+void DCContainer::removeDirRecursive(QString path)
+{
+ QDir dir(path);
+
+ QFileInfoList list = dir.entryInfoList(QDir::NoDot | QDir::NoDotDot | QDir::AllEntries);
+
+ for (int i = 0; i < list.length(); i++)
+ {
+ QFileInfo info = list.at(i);
+ if (info.isDir())
+ {
+ removeDirRecursive(info.absoluteFilePath());
+ info.dir().rmdir(info.absoluteFilePath());
+ }
+ else
+ {
+ QFile file(info.absoluteFilePath());
+ file.remove();
+ }
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCONTAINER_H
+#define DCCONTAINER_H
+
+#include "TKContainer.h"
+
+class TKCell;
+class TKCellCode;
+class DCCell;
+class DCCellCode;
+class DCScene;
+class DCVCPage;
+class DCContent;
+class DCVComponent;
+class DCUIGraphicsScene;
+
+#include <QList>
+#include <QString>
+
+class DCContainer : public TKContainer
+{
+ void removeDirRecursive(QString path);
+
+ DCContent *d_content;
+ DCScene *d_scene;
+
+ std::string d_factoryCachedLocation;
+ DCVCPage *d_factoryCachedPageObject;
+
+ QString d_workDirRoot;
+ QString d_workDirCellRoot;
+ QString d_workDirCellCodeRoot;
+
+public:
+ DCContainer();
+ virtual ~DCContainer();
+
+ virtual TKCell* addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
+ virtual TKCell* addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
+ virtual TKCellCode* addCellCode(std::string theName, std::string theAPIType, std::string code);
+
+ virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterface = true);
+ virtual TKAxon* axonFactory(TKCell *theOwner);
+ virtual TKReceptor* receptorFactory(TKCell *theOwner);
+ virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
+ virtual TKCellCode* cellCodeFactory(std::string name, std::string cellapi, std::string code);
+
+ //
+ DCContent* getContent() const { return d_content; }
+ DCScene* getScene() const { return d_scene; }
+ QList<DCVComponent*> getSelectedCellObjects() const;
+ virtual float getValue(std::string key) const { return 0; }
+
+ TKCellCode* getEmptyCellCodeClass() const { return mEmptyCellClass; }
+ bool isScriptableCell(DCCell *cell);
+
+ //
+ void setContent(DCContent *content);
+
+ void unselectCellObjectAll();
+
+ virtual void setValue(std::string key, float value) {}
+
+ virtual void beganParsePage(const char *docRoot, const char *path);
+ virtual void endedParsePage(const char *docRoot, const char *path);
+
+ void beganBuildContainer();
+ void endedBuildContainer();
+
+ bool saveCustomScriptToWorkFile(TKCell *cell, std::string customScript);
+ bool saveClassScriptToWorkFile(TKCellCode *cellCode, std::string code);
+
+ QString readCustomScriptFromWorkFile(const DCCell *cell);
+ QString readCellCodeScriptFromFile(const DCCellCode *cellcode);
+
+};
+
+#endif // DCCONTAINER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccontent.h"
+
+#include "dccontainer.h"
+#include "DNContainerBuilder.h"
+#include "DNGlobal.h"
+#include "DNXML.h"
+#include "DNXMLElement.h"
+#include "DNUtils.h"
+
+#include <stdlib.h>
+#include <sstream>
+#include <iostream>
+
+DCContent::DCContent(DCCreator *creator, const char *contentPath) :
+ mCreator(creator), mValid(false), mContainer(0)
+{
+ mContainer = (DCContainer*) TKContainer::createContainer();
+ mContainer->setContent(this);
+
+ dnGlobal()->updateRunningStatus(DNGlobal::STOPPED);
+ dnGlobal()->resetErrorStatus();
+
+ std::string basePath(contentPath);
+ std::string containerRoot = basePath;
+ containerRoot.append("/Container");
+
+ bool succeeded = false;
+ succeeded = parseSettingFile(contentPath);
+ if (!succeeded || !dnGlobal()->isErrorStatusNormal())
+ {
+ dnNotifyError("property.xml parse error", "failed to parse setting file /property.xml");
+ return;
+ }
+
+ std::string dataStorePath = containerRoot;
+ dataStorePath.append("/data.db");
+
+ succeeded = mContainer->setDataStore(dataStorePath.c_str());
+ if (!succeeded)
+ {
+ dnNotifyError("Initialization failed","Failed to the setup data store");
+ return;
+ }
+
+ succeeded = parseContainerFile(containerRoot.c_str());
+ if (!succeeded)
+ {
+ dnNotifyError("Initialization failed", "Failed to parse container file");
+ return;
+ }
+
+ mValid = true;
+}
+
+DCContent::~DCContent()
+{
+ mValid = false;
+ if (mContainer)
+ {
+ delete mContainer;
+ mContainer = 0;
+ }
+}
+
+bool DCContent::parseSettingFile(const char *contentRoot)
+{
+ bool valid = false;
+
+ DNXML *xml = DNXML::createXMLFromFile(contentRoot, "property.xml");
+ if (xml)
+ {
+ valid = true;
+ DNXMLElement *element = xml->getRoot();
+ if (!element)
+ {
+ valid = false;
+ std::string message = "Failed to load property.xml file";
+ dnNotifyError("Initialization failed",message);
+ }
+
+ if (valid && element->name != "dennco")
+ {
+ valid = false;
+ std::string message = "First element of property.xml should be <dennco>";
+ dnNotifyError("Initialization failed",message);
+ }
+
+ if (valid)
+ {
+ DNXMLElement *e = element->inner;
+ while(e)
+ {
+ std::string pname = upperString(e->name);
+
+ if (pname == "TICKINTERVALSEC")
+ {
+ std::istringstream is(e->text);
+ float t = 0.0;
+ is >> t;
+ if (t>0)
+ {
+ //TODO
+ }
+ else
+ {
+ valid = false;
+ std::string message = "Error in property.xml. TickIntervalSec is not configured properly.";
+ dnNotifyError("Initialization failed",message);
+ }
+ }
+ else if (pname == "UIPATH")
+ {
+ // TODO
+ }
+ else if (pname == "ENABLEHTTPSERVER")
+ {
+
+ }
+ else if (pname == "ENABLESERIALSERVER")
+ {
+ if ( upperString(e->text) == "YES")
+ {
+ //TODO
+ }
+ else
+ {
+ //TODO
+ }
+ }
+ else if (pname == "SERIALSPEED")
+ {
+ //TODO
+ }
+ e = e->next;
+ }
+ }
+
+ delete xml;
+ }
+ return valid;
+}
+
+bool DCContent::parseContainerFile(const char *containerRoot)
+{
+ DNContainerBuilder builder(mContainer);
+ mContainer->beganBuildContainer();
+ bool r = builder.buildContainerFromXHTML(containerRoot);
+ mContainer->endedBuildContainer();
+
+ return r;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCONTENT_H
+#define DCVCONTENT_H
+
+class DCContainer;
+class DCCreator;
+
+class DCContent
+{
+ bool parseSettingFile(const char *contentRoot);
+ bool parseContainerFile(const char *containerRoot);
+
+ DCCreator *mCreator;
+ bool mValid;
+ DCContainer *mContainer;
+
+public:
+ DCContent(DCCreator *creator, const char *contentPath);
+ virtual ~DCContent();
+
+ bool isValid() { return mValid; }
+
+ DCContainer* getContainer() const { return mContainer; }
+ DCCreator* getCreator() const { return mCreator; }
+
+};
+
+#endif // DCVCONTENT_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "TKLog.h"
+
+#include "dccreator.h"
+
+#include "dccontent.h"
+#include "dccontainer.h"
+#include "dcscene.h"
+
+#include "dccell.h"
+#include "dcaxon.h"
+#include "dcaxonterminal.h"
+#include "dcreceptor.h"
+
+#include "command/dccommandevent.h"
+#include "utils/dcdialogutil.h"
+#include "utils/dccommandutil.h"
+#include "dialog/dcinputreceptornamedialog.h"
+
+
+
+#include <QUndoCommand>
+
+#include <map>
+
+DCCreator::DCCreator(QMainWindow *mainwindow)
+ : d_mainWindow(mainwindow), d_vcontent(NULL), d_scene(NULL),
+ d_persMode(DC_PERSMODE_PAGEEDIT), d_contentRootPath("")
+{
+ d_undoStack = new QUndoStack(this);
+}
+
+DCCreator::~DCCreator()
+{
+ if (d_vcontent)
+ {
+ delete d_vcontent;
+ }
+}
+
+bool DCCreator::event(QEvent *event)
+{
+ if(event->type() == DCCommandEvent::EVENT_TYPEID)
+ {
+ DCCommandEvent *commandEvent = dynamic_cast<DCCommandEvent*>(event);
+ if (commandEvent)
+ {
+ QUndoCommand *command = commandEvent->getCommand();
+ if (command)
+ {
+ d_undoStack->push(command);
+ emit commandExecuted(command);
+ }
+ return true;
+ }
+ }
+ else if (event->type() == DCUndoEvent::EVENT_TYPEID)
+ {
+ d_undoStack->undo();
+ emit commandExecuted(NULL);
+ return true;
+ }
+ return false;
+}
+
+void DCCreator::resetVisualizer()
+{
+ emit sceneChanged(this,0);
+}
+
+void DCCreator::initMode()
+{
+ d_persMode = DC_PERSMODE_NAVIGATION;
+ d_scene->initMode(DCScene::DCV_PERSMODE_NAVIGATION, DCScene::DCV_EDITMODE_LAYOUT);
+}
+
+bool DCCreator::loadContent(const char *contentRoot)
+{
+ d_contentRootPath = QString::fromLocal8Bit(contentRoot);
+ if (d_vcontent)
+ {
+ if (d_scene)
+ d_scene->disconnect(this);
+ resetVisualizer();
+ delete d_vcontent;
+ }
+ d_vcontent = new DCContent(this, contentRoot);
+
+ if (d_vcontent->isValid())
+ {
+ d_scene = d_vcontent->getContainer()->getScene();
+
+ //setup signal - slot connection for scene
+ connect(d_scene, SIGNAL(selectedCellObjectChanged(const void*)), this, SLOT(slotSceneSelectedCellObjectChanged(const void*)));
+ connect(d_scene, SIGNAL(selectedPageChanged(const void*)), this, SLOT(slotSceneSelectedPageChanged(const void*)));
+ connect(d_scene, SIGNAL(viewAngleChanged(const void*)), this, SLOT(slotSceneViewAngleChanged(const void*)));
+ connect(d_scene, SIGNAL(viewCenterChanged(const void*)), this, SLOT(slotSceneViewCenterChanged(const void*)));
+ connect(d_scene, SIGNAL(viewScaleChanged(const void*)), this, SLOT(slotSceneViewScaleChanged(const void*)));
+ connect(d_scene, SIGNAL(viewSettingChanged(const void*)), this, SLOT(slotSceneViewSettingChanged(const void*)));
+ connect(d_scene, SIGNAL(viewEditModeChanged(const void*)), this, SLOT(slotSceneViewEditModeChanged(const void*)));
+
+ emit contentRootPathChanged(this, d_contentRootPath);
+ emit sceneChanged(this, d_scene);
+ initMode();
+ return true;
+ }
+ else
+ {
+ d_scene = NULL;
+ emit sceneChanged(this, NULL);
+ return false;
+ }
+}
+
+
+void DCCreator::selectPage(const void *requester, DCVCPage *page, bool multipleSelection)
+{
+ if (d_scene)
+ {
+ d_scene->selectPage(requester, page, multipleSelection);
+ }
+}
+
+void DCCreator::unselectPage(const void *requester, DCVCPage *page)
+{
+ if (d_scene)
+ {
+ d_scene->unselectPage(requester, page);
+ }
+}
+
+bool DCCreator::selectPage(const void *requester, const QString &locationPath, bool multipleSelection)
+{
+ bool r = false;
+ if (d_scene)
+ {
+ r = d_scene->selectPage(requester, locationPath, multipleSelection);
+ }
+ return r;
+}
+
+bool DCCreator::unselectPage(const void *requester, const QString &locationPath)
+{
+ bool r = false;
+ if (d_scene)
+ {
+ r = d_scene->unselectPage(requester, locationPath);
+ }
+ return r;
+}
+
+
+void DCCreator::unselectPageAll(const void *requester)
+{
+ if (d_scene)
+ {
+ d_scene->unselectPageAll(requester);
+ }
+}
+
+void DCCreator::selectCellObject(const void *requester, DCVComponent *object, bool multipleSelection)
+{
+ if (d_scene)
+ d_scene->selectCellObject(requester, object, multipleSelection);
+}
+
+void DCCreator::unselectCellObject(const void *requester, DCVComponent *object)
+{
+ if (d_scene)
+ d_scene->unselectCellObject(requester, object);
+}
+
+void DCCreator::unselectCellObjectAll(const void *requester)
+{
+ if (d_scene)
+ d_scene->unselectCellObjectAll(requester);
+}
+
+void DCCreator::changeSceneScale(const void *requester, float scale)
+{
+ if (d_scene)
+ {
+ if (scale <= 10) scale =10;
+ if (scale >= 1000) scale = 1000;
+ d_scene->setScale(requester, scale);
+ }
+}
+
+void DCCreator::rotateScene(const void *requester, float xangle_delta, float yangle_delta)
+{
+ if (d_scene)
+ {
+ float xangle = d_scene->getXAngle() + xangle_delta;
+ if (xangle < 0) xangle = 0;
+ if (xangle > 90) xangle = 90;
+
+ float yangle = d_scene->getYAngle() + yangle_delta;
+ while (yangle < 0) yangle += 360;
+ while (yangle > 360) yangle -= 360;
+
+ d_scene->setAngle(requester, xangle,yangle);
+ }
+}
+
+void DCCreator::translateBrowsModeScene(const void *requester, float dx, float dy)
+{
+ if (d_scene)
+ {
+ float scale = d_scene->getScale();
+ float x = d_scene->getCenterX() - dx/scale*2;
+ float y = d_scene->getCenterBrowsModeY() + dy/scale*2;
+ d_scene->setBrowsModeCenter(requester, x,y);
+ }
+}
+
+void DCCreator::translateEditModeScene(const void *requester, float dx, float dy)
+{
+ if (d_scene)
+ {
+ float scale = d_scene->getScale();
+ float x = d_scene->getCenterX() - dx/scale*2;
+ float y = d_scene->getCenterEditModeY() - dy/scale*2;
+ d_scene->setPageModeCenter(requester, x,y);
+ }
+}
+
+void DCCreator::resetSceneTranslation()
+{
+
+}
+
+bool DCCreator::changePersMode(const void *requester, DCPersMode mode)
+{
+ bool r = false;
+ if (d_scene)
+ {
+ d_persMode = mode;
+ switch(mode)
+ {
+ case DC_PERSMODE_NAVIGATION:
+ r = d_scene->changePersMode(requester, DCScene::DCV_PERSMODE_NAVIGATION);
+ break;
+ case DC_PERSMODE_PAGEEDIT:
+ r = d_scene->changePersMode(requester, DCScene::DCV_PERSMODE_PAGEEDIT);
+ break;
+ }
+ d_scene->updateVisiblity();
+ }
+ return r;
+}
+
+void DCCreator::doUndo(const void *requester)
+{
+ //TODO
+}
+
+void DCCreator::doUndoImmidiate()
+{
+ d_undoStack->undo();
+}
+
+void DCCreator::doCommandStartAddAxonTerminalFromAxon(const void *requester, DCCell *axonCell)
+{
+ DCCommandUtil::postStartAddAxonTerminalCommandFromAxon(requester, this, axonCell);
+}
+
+void DCCreator::doCommandStartAddAxonTerminalFromReceptor(const void *requester, DCCell *receptorCell)
+{
+ DCInputReceptorNameDialog dialog(receptorCell);
+ dialog.exec();
+ if (dialog.getIsOk() && dialog.getInputText().length() > 0)
+ {
+ DCCommandUtil::postStartAddAxonTerminalCommandFromReceptor(requester, this, receptorCell, dialog.getInputText());
+ }
+}
+
+void DCCreator::doCommandCommitAddAxonTerminal(const void *requester, DCAxon *axon, DCCell *receptorCell)
+{
+ DCInputReceptorNameDialog dialog(receptorCell);
+ dialog.exec();
+ if (dialog.getIsOk() && dialog.getInputText().length() > 0)
+ {
+ DCCommandUtil::postCommitAddAxonTerminalCommand(requester, this, axon, receptorCell, dialog.getInputText());
+ }
+ else
+ {
+ doCommandCancelAddAxonTerminal(requester);
+ }
+}
+
+void DCCreator::doCommandCommitAddAxonTerminal(const void *requester, DCCell *axonCell, DCReceptor *receptor)
+{
+ DCCommandUtil::postCommitAddAxonTerminalCommand(requester, this, axonCell, receptor);
+}
+
+void DCCreator::doCommandCancelAddAxonTerminal(const void *requester)
+{
+//TODO:
+ // may need to consider the case multiple commands are executed after
+ // startAddAxon command is executed.
+ DCCommandUtil::postUndoRequestCommand(requester, this);
+}
+
+void DCCreator::doCommandDeleteAxonTerminal(const void *requester, DCCell *axonCell, DCAxonTerminal *axonTerminal)
+{
+ DCReceptor *receptor = dynamic_cast<DCReceptor*>(axonTerminal->getTarget());
+ if (!receptor)
+ return;
+
+ DCCell *targetCell = dynamic_cast<DCCell*>(receptor->getOwnerCell());
+ if (!targetCell)
+ return;
+
+ QMessageBox msgBox;
+ msgBox.setText(tr("Delete axon terminal"));
+ QString msg;
+ msg.append("Cell ");
+ msg.append(QString::fromStdString(axonCell->getName()));
+ msg.append("\nDo you want to delete the connection to ");
+ msg.append(QString::fromStdString(targetCell->getLocation()));
+ msg.append("#");
+ msg.append(QString::fromStdString(targetCell->getName()));
+ msg.append("(");
+ msg.append(QString::fromStdString(targetCell->getReceptorName(receptor)));
+ msg.append(")?");
+ msgBox.setInformativeText(msg);
+ msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
+ msgBox.setDefaultButton(QMessageBox::Cancel);
+ int ret = msgBox.exec();
+
+ if (ret == QMessageBox::Yes)
+ {
+ DCCommandUtil::postDeleteAxonTerminalCommand(requester, this, axonCell, axonTerminal);
+ }
+}
+
+void DCCreator::doCommandDeleteAxonTerminal(const void *requester, DCCell *receptorCell, const QString& receptorName)
+{
+
+ QMessageBox msgBox;
+ msgBox.setText(tr("Delete receptor"));
+ QString msg;
+ msg.append("Cell ");
+ msg.append(QString::fromStdString(receptorCell->getName()));
+ msg.append("\nDo you want to delete receptor ");
+ msg.append(receptorName);
+ msg.append("?\n");
+ msgBox.setInformativeText(msg);
+ msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
+ msgBox.setDefaultButton(QMessageBox::Cancel);
+ int ret = msgBox.exec();
+
+ if (ret == QMessageBox::Yes)
+ {
+ DCCommandUtil::postDeleteAxonTerminalCommand(requester, this, receptorCell, receptorName);
+ }
+}
+
+void DCCreator::doCommandStartEditCellCode(const void *requester, DCCell *cell)
+{
+ DCCommandUtil::postStartCellCodeEditCommand(requester, this, cell);
+}
+
+void DCCreator::doCommandStopEditCellCode(const void *requester)
+{
+ DCCommandUtil::postStopCellCodeEditCommand(requester, this);
+}
+
+void DCCreator::doCommandSetCellCodeClass(const void *requester, DCCell *cell, DCCellCode *cellCode)
+{
+ DCCommandUtil::postSetCellCodeClassCommand(requester, this, cell, cellCode);
+}
+
+void DCCreator::doCommandUnsetCellCodeClass(const void *requester, DCCell *cell)
+{
+ DCCommandUtil::postUnsetCellCodeClassCommand(requester, this, cell);
+}
+
+void DCCreator::doCommandAddCellCodeClass(const void *requester, DCContainer *container, const QString& name, const QString& type)
+{
+ DCCommandUtil::postAddCellCodeClassCommand(requester, this, container, name, type);
+}
+
+void DCCreator::doCommandAddCell(const void *requester, DCContainer *container, const QString& contentBasedPath, const QString& name, const QString& type)
+{
+ DCCommandUtil::postAddCellCommand(requester, this, container, contentBasedPath, name, type);
+}
+
+void DCCreator::doCommandAddPage(const void *requester, const QString &contentBasedPath)
+{
+ DCCommandUtil::postAddPageCommand(requester, this, contentBasedPath);
+}
+
+void DCCreator::doCommandAddDirectory(const void *requester, const QString &sysFilePath)
+{
+ DCCommandUtil::postAddDirectoryCommand(requester, this, sysFilePath);
+}
+
+void DCCreator::doCommandRemoveDirectory(const void *requester, const QString &sysFilePath)
+{
+ DCCommandUtil::postRemoveDirectoryCommand(requester, this, sysFilePath);
+}
+
+bool DCCreator::doCommandRenameDirectoryImmidiate(const void *requester, const QString &contentBasedPath, const QString &oldName, const QString &newName)
+{
+ //TODO
+ QMessageBox msgBox;
+ msgBox.setText("This command isn't implemented yet");
+ msgBox.exec();
+ return false;
+}
+
+DCContainer* DCCreator::getCurrentContainer() const
+{
+ return d_vcontent->getContainer();
+}
+
+void DCCreator::slotSceneSelectedPageChanged(const void *requester)
+{
+ emit sceneSelectedPageChanged(requester, d_scene);
+}
+
+void DCCreator::slotSceneSelectedCellObjectChanged(const void *requester)
+{
+ emit sceneSelectedCellChanged(requester, d_scene);
+}
+
+void DCCreator::slotSceneViewScaleChanged(const void *requester)
+{
+ emit sceneViewScaleChanged(requester, d_scene);
+}
+
+void DCCreator::slotSceneViewAngleChanged(const void *requester)
+{
+ emit sceneViewAngleChanged(requester, d_scene);
+}
+
+void DCCreator::slotSceneViewCenterChanged(const void *requester)
+{
+ emit sceneViewCenterChanged(requester, d_scene);
+}
+
+void DCCreator::slotSceneViewSettingChanged(const void *requester)
+{
+ emit sceneViewSettingChanged(requester, d_scene);
+}
+
+void DCCreator::slotSceneViewEditModeChanged(const void *requester)
+{
+ emit sceneViewEditModeChanged(requester, d_scene);
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCREATOR_H
+#define DCCREATOR_H
+
+class DCContent;
+class DCVCPage;
+class DCCell;
+class DCCellCode;
+class DCAxon;
+class DCReceptor;
+class DCAxonTerminal;
+class DCScene;
+class DCVComponent;
+class DCContainer;
+class DCCommand;
+
+#include <QtGUI>
+
+class DCCreator : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum DCPersMode { DC_PERSMODE_NAVIGATION, DC_PERSMODE_PAGEEDIT };
+
+private:
+ QMainWindow *d_mainWindow;
+ DCContent *d_vcontent;
+ DCScene *d_scene;
+ DCPersMode d_persMode;
+ QString d_contentRootPath;
+
+ QUndoStack *d_undoStack;
+
+public:
+ DCCreator(QMainWindow *mainwindow);
+ virtual ~DCCreator();
+
+ DCContainer* getCurrentContainer() const;
+ QMainWindow* getMainWindow() const { return d_mainWindow; }
+ DCScene* getScene() const { return d_scene; }
+ DCPersMode getPersMode() const { return d_persMode; }
+
+ virtual bool event(QEvent *event);
+
+ void resetVisualizer();
+ void initMode();
+
+ bool loadContent(const char *contentRoot);
+
+ void selectPage(const void *requester, DCVCPage *page, bool multipleSelection);
+ void unselectPage(const void *requester, DCVCPage *page);
+ bool selectPage(const void *requester, const QString &locationPath, bool multipleSelection);
+ bool unselectPage(const void *requester, const QString &locationPath);
+ void unselectPageAll(const void *requester);
+
+ void selectCellObject(const void *requester, DCVComponent *object, bool multipleSelection = false);
+ void unselectCellObject(const void *requester, DCVComponent *object);
+ void unselectCellObjectAll(const void *requester);
+
+ void changeSceneScale(const void *requester, float scale);
+ void rotateScene(const void *requester, float xangle_delta, float yangle_delta);
+ void translateBrowsModeScene(const void *requester, float dx, float dy);
+ void translateEditModeScene(const void *requester, float dx, float dy);
+ void resetSceneTranslation();
+
+ bool changePersMode(const void *requester, DCPersMode mode);
+
+
+ void doUndo(const void *requester);
+ void doUndoImmidiate();
+
+ //Editing actions
+ void doCommandStartAddAxonTerminalFromAxon(const void *requester, DCCell *axnoCell);
+ void doCommandStartAddAxonTerminalFromReceptor(const void *requester, DCCell *receptorCell);
+ void doCommandCommitAddAxonTerminal(const void *requester, DCAxon *axon, DCCell *receptorCell);
+ void doCommandCommitAddAxonTerminal(const void *requester, DCCell *axonCell, DCReceptor *receptor);
+ void doCommandCancelAddAxonTerminal(const void *requester);
+ void doCommandDeleteAxonTerminal(const void *requester, DCCell *axonCell, DCAxonTerminal *axonTerminal);
+ void doCommandDeleteAxonTerminal(const void *requester, DCCell *receptorCell, const QString& receptorName);
+ void doCommandStartEditCellCode(const void *requester, DCCell *cell);
+ void doCommandStopEditCellCode(const void *requester);
+ void doCommandSetCellCodeClass(const void *requester, DCCell *cell, DCCellCode *cellCode);
+ void doCommandUnsetCellCodeClass(const void *requester, DCCell *cell);
+
+ void doCommandAddCellCodeClass(const void *requester, DCContainer *container, const QString& name, const QString& type);
+ void doCommandAddCell(const void *requester, DCContainer *container, const QString& contentBasedPath, const QString& name, const QString& type);
+ void doCommandAddPage(const void *requester, const QString& contentBasedPath);
+
+ void doCommandAddDirectory(const void *requester, const QString& sysFilePath);
+ void doCommandRemoveDirectory(const void *requester, const QString& sysFilePath);
+
+ bool doCommandRenameDirectoryImmidiate(const void *requester, const QString& contentBasedPath, const QString& oldName, const QString &newName);
+
+private slots:
+ void slotSceneSelectedPageChanged(const void *requester);
+ void slotSceneSelectedCellObjectChanged(const void *requester);
+ void slotSceneViewScaleChanged(const void *requester);
+ void slotSceneViewAngleChanged(const void *requester);
+ void slotSceneViewCenterChanged(const void *requester);
+ void slotSceneViewSettingChanged(const void *requester);
+ void slotSceneViewEditModeChanged(const void *requester);
+
+signals:
+ void contentRootPathChanged(const void *requester, QString rootPath);
+ void sceneChanged(const void *requester, DCScene *scene);
+ void sceneSelectedPageChanged(const void *requester, const DCScene *scene);
+ void sceneSelectedCellChanged(const void *requester, const DCScene *scene);
+ void sceneViewScaleChanged(const void *requester, const DCScene *scene);
+ void sceneViewAngleChanged(const void *requester, const DCScene *scene);
+ void sceneViewCenterChanged(const void *requester, const DCScene *scene);
+ void sceneViewTranslationChanged(const void *requester, const DCScene *scene);
+ void sceneViewSettingChanged(const void *requester, const DCScene *scene);
+ void sceneViewEditModeChanged(const void *requester, const DCScene *scene);
+
+ void commandExecuted(const QUndoCommand *executedCommand);
+};
+
+#endif // DCCREATOR_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcreceptor.h"
+
+#include "dcvcomponent.h"
+#include "dccell.h"
+#include "dcvceditmodecursor.h"
+#include "dcvceditmodeterminal.h"
+
+DCReceptor::DCReceptor(DCCell *owner) : TKReceptor(owner), d_vComponent(NULL), d_isTerminalVisible(true), d_editCursor(NULL)
+{
+}
+
+DCReceptor::~DCReceptor()
+{
+ if (d_vComponent)
+ {
+ delete d_vComponent;
+ d_vComponent = NULL;
+ }
+}
+
+DCVComponent* DCReceptor::getVComponent() const
+{
+ return d_vComponent;
+}
+
+void DCReceptor::getViewReceptorOffsetPoint(float dx, float dy, float dz,float *x, float *y, float *z) const
+{
+ *x = 0;
+ *y = 0;
+ *z = 0;
+
+ DCCell *cell = dynamic_cast<DCCell*>(getOwnerCell());
+ if (cell)
+ {
+ float cx,cz;
+ cell->getViewHCrossPoint(dx,dz,&cx,&cz);
+ *x = cx;
+ *z = cz;
+ }
+}
+
+void DCReceptor::registerEditCursor(DCVCEditModeCursor *cursor)
+{
+ d_editCursor = cursor;
+}
+
+void DCReceptor::unregisterEditCursor()
+{
+ d_editCursor = NULL;
+}
+
+void DCReceptor::setEditingCursorViewMatrix(const float matrix[])
+{
+ if (d_editCursor)
+ {
+ d_editCursor->getTerminal()->setViewMatrixForReceptorPoint(this, matrix);
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCRECEPTOR_H
+#define DCRECEPTOR_H
+
+#include "TKReceptor.h"
+
+class DCCell;
+class DCVCReceptor;
+class DCVComponent;
+class DCVCEditModeCursor;
+
+class DCReceptor : public TKReceptor
+{
+ friend class DCComponentUtil;
+ DCReceptor(DCCell *theOwner);
+ void bindComponent(DCVComponent *component) { d_vComponent = component; }
+
+ DCVComponent *d_vComponent;
+ bool d_isTerminalVisible;
+ DCVCEditModeCursor *d_editCursor;
+
+public:
+ virtual ~DCReceptor();
+
+ DCVComponent* getVComponent() const;
+ void getViewReceptorOffsetPoint(float dx, float dy, float dz,float *x, float *y, float *z) const;
+ bool getIsTerminalVisible() const { return d_isTerminalVisible; }
+ bool hasEditCursor() const { return d_editCursor != 0; }
+ DCVCEditModeCursor* getEditCursor() const { return d_editCursor; }
+
+ void setTerminalVisible(bool visible) { d_isTerminalVisible = visible; }
+ void setEditingCursorViewMatrix(const float matrix[]);
+
+ void registerEditCursor(DCVCEditModeCursor *cursor);
+ void unregisterEditCursor();
+
+};
+
+#endif // DCRECEPTOR_H
--- /dev/null
+
+QT += core gui xml opengl sql
+
+INCLUDEPATH += engine/layer1 engine/layer2 visualizer visualizer/component visualizer/toolwindow visualizer/component/shape treeview codeeditor receptoreditor axoneditor axonterminaleditor
+
+HEADERS = mainwindow.h \
+ visualizer/dcscene.h \
+ visualizer/dcglvisualizerwidget.h \
+ engine/layer1/TKReceptor.h \
+ engine/layer1/TKContainer.h \
+ engine/layer1/TKCellCodeInstance.h \
+ engine/layer1/TKCellCode.h \
+ engine/layer1/TKCell.h \
+ engine/layer1/TKAxonTerminal.h \
+ engine/layer1/TKAxon.h \
+ engine/layer1/TKLockImpl.h \
+ engine/layer1/TKLock.h \
+ engine/layer1/platform/qt/qttklockimpl.h \
+ engine/layer1/TKLog.h \
+ engine/layer1/TKConsole.h \
+ engine/layer1/TKDebug.h \
+ engine/layer1/DNUtils.h \
+ engine/layer1/DNGlobal.h \
+ engine/layer2/DNXMLImpl.h \
+ engine/layer2/DNXMLElement.h \
+ engine/layer2/DNXML.h \
+ engine/layer2/DNFileList.h \
+ engine/layer2/DNDirectoryImpl.h \
+ engine/layer2/DNDirectory.h \
+ engine/layer2/DNContainerBuilder.h \
+ engine/layer2/platform/qt/qtdnxmlimpl.h \
+ engine/layer2/platform/qt/qtdndirectoryimpl.h \
+ engine/layer1/DNStorageImpl.h \
+ engine/layer1/DNStorage.h \
+ engine/layer1/platform/qt/qtdnstorageimpl.h \
+ dccreator.h \
+ visualizer/component/dcvcaxon.h \
+ visualizer/component/dcvccell.h \
+ visualizer/component/dcvccellcode.h \
+ visualizer/component/dcvcpage.h \
+ visualizer/component/dcvcreceptor.h \
+ visualizer/component/dcvcomponent.h \
+ dccontent.h \
+ dccell.h \
+ dccellcode.h \
+ dcaxon.h \
+ dcaxonterminal.h \
+ dccontainer.h \
+ dcreceptor.h \
+ dcanimationtimer.h \
+ treeview/dctreeviewwidget.h \
+ visualizer/component/shape/dccuberenderer.h \
+ codeeditor/dccodeeditor.h \
+ codeeditor/dccodehighlighter.h \
+ visualizer/component/shape/dcselectionrenderer.h \
+ visualizer/dcglwidget.h \
+ visualizer/toolwindow/dctoolwindowbase.h \
+ visualizer/toolwindow/dctoolwindowviewcontrol.h \
+ visualizer/dceditmenudialog.h \
+ visualizer/component/dcvpagecomponent.h \
+ visualizer/component/dcvcaxonterminal.h \
+ visualizer/component/dcvceditmodecursor.h \
+ visualizer/component/dcvceditmodeterminal.h \
+ visualizer/eventhandler/dcveventhandler.h \
+ visualizer/toolwindow/dctoolwindowcelleditor.h \
+ visualizer/toolwindow/dceditablelabel.h \
+ utils/dcqtitemmodel.h \
+ visualizer/toolwindow/dceditabletreeview.h \
+ utils/dcresources.h \
+ utils/dcveventhandlerutil.h \
+ utils/dcdialogutil.h \
+ utils/dccomponentutil.h \
+ command/dccommand.h \
+ command/dccommandevent.h \
+ command/dceditcommands.h \
+ utils/dccommandutil.h \
+ dialog/dcinputreceptornamedialog.h \
+ visualizer/eventhandler/dcvterminalfromreceptormodehandler.h \
+ visualizer/eventhandler/dcvterminalfromaxonmodehandler.h \
+ visualizer/eventhandler/dcvlayoutmodehandler.h \
+ visualizer/toolwindow/dctoolwindowterminalfromaxoneditor.h \
+ visualizer/toolwindow/dctoolwindowterminalfromreceptoreditor.h \
+ visualizer/toolwindow/dctoolwindowcellcodeeditor.h \
+ dialog/dcassigncellcodeclassdialog.h \
+ dialog/dcaddcellcodeclassdialog.h \
+ dialog/dcsinglecolumntableview.h \
+ dialog/dcinputnewpagenamedialog.h \
+ dialog/dcaddcelldialog.h
+
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ visualizer/dcscene.cpp \
+ visualizer/dcglvisualizerwidget.cpp \
+ engine/layer1/TKReceptor.cpp \
+ engine/layer1/TKCellCodeInstance.cpp \
+ engine/layer1/TKCellCode.cpp \
+ engine/layer1/TKCell.cpp \
+ engine/layer1/TKAxonTerminal.cpp \
+ engine/layer1/TKAxon.cpp \
+ engine/layer1/platform/qt/qttklockimpl.cpp \
+ engine/layer1/TKLog.cpp \
+ engine/layer1/platform/qt/QtTKConsole.cpp \
+ engine/layer1/TKDebug.cpp \
+ engine/layer1/DNUtils.cpp \
+ engine/layer1/TKLock.cpp \
+ engine/layer1/DNGlobal.cpp \
+ engine/layer2/DNXMLElement.cpp \
+ engine/layer2/DNXML.cpp \
+ engine/layer2/DNFileList.cpp \
+ engine/layer2/DNDirectory.cpp \
+ engine/layer2/DNContainerBuilder.cpp \
+ engine/layer2/platform/qt/qtdnxmlimpl.cpp \
+ engine/layer2/platform/qt/qtdndirectoryimpl.cpp \
+ engine/layer1/TKContainer.cpp \
+ engine/layer1/platform/qt/qtdnstorageimpl.cpp \
+ engine/layer1/DNStorage.cpp \
+ dccreator.cpp \
+ visualizer/component/dcvcaxon.cpp \
+ visualizer/component/dcvccell.cpp \
+ visualizer/component/dcvccellcode.cpp \
+ visualizer/component/dcvcpage.cpp \
+ visualizer/component/dcvcreceptor.cpp \
+ visualizer/component/dcvcomponent.cpp \
+ dccontent.cpp \
+ dccell.cpp \
+ dccellcode.cpp \
+ dcaxon.cpp \
+ dcaxonterminal.cpp \
+ dccontainer.cpp \
+ dcreceptor.cpp \
+ dcanimationtimer.cpp \
+ treeview/dctreeviewwidget.cpp \
+ visualizer/component/shape/dccuberenderer.cpp \
+ codeeditor/dccodeeditor.cpp \
+ codeeditor/dccodehighlighter.cpp \
+ visualizer/component/shape/dcselectionrenderer.cpp \
+ visualizer/dcglwidget.cpp \
+ visualizer/toolwindow/dctoolwindowbase.cpp \
+ visualizer/toolwindow/dctoolwindowviewcontrol.cpp \
+ visualizer/dceditmenudialog.cpp \
+ visualizer/component/dcvcaxonterminal.cpp \
+ visualizer/component/dcvceditmodecursor.cpp \
+ visualizer/component/dcvceditmodeterminal.cpp \
+ visualizer/eventhandler/dcveventhandler.cpp \
+ visualizer/toolwindow/dctoolwindowcelleditor.cpp \
+ visualizer/toolwindow/dceditablelabel.cpp \
+ utils/dcqtitemmodel.cpp \
+ visualizer/toolwindow/dceditabletreeview.cpp \
+ utils/dcresources.cpp \
+ utils/dcveventhandlerutil.cpp \
+ utils/dcdialogutil.cpp \
+ utils/dccomponentutil.cpp \
+ command/dccommand.cpp \
+ command/dccommandevent.cpp \
+ command/dceditcommands.cpp \
+ utils/dccommandutil.cpp \
+ dialog/dcinputreceptornamedialog.cpp \
+ visualizer/eventhandler/dcvterminalfromreceptormodehandler.cpp \
+ visualizer/eventhandler/dcvterminalfromaxonmodehandler.cpp \
+ visualizer/eventhandler/dcvlayoutmodehandler.cpp \
+ visualizer/toolwindow/dctoolwindowterminalfromaxoneditor.cpp \
+ visualizer/toolwindow/dctoolwindowterminalfromreceptoreditor.cpp \
+ visualizer/toolwindow/dctoolwindowcellcodeeditor.cpp \
+ dialog/dcassigncellcodeclassdialog.cpp \
+ dialog/dcaddcellcodeclassdialog.cpp \
+ dialog/dcsinglecolumntableview.cpp \
+ dialog/dcinputnewpagenamedialog.cpp \
+ dialog/dcaddcelldialog.cpp
+
+RESOURCES = denncoCreator.qrc
+
+FORMS += \
+ mainwindow.ui
--- /dev/null
+<RCC>
+ <qresource prefix="/">
+ <file>images/copy.png</file>
+ <file>images/cut.png</file>
+ <file>images/new.png</file>
+ <file>images/open.png</file>
+ <file>images/paste.png</file>
+ <file>images/save.png</file>
+ <file alias="addItemIcon.png">images/plusIcon.png</file>
+ <file alias="deleteItemIcon.png">images/minusIcon.png</file>
+ </qresource>
+</RCC>
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcaddcellcodeclassdialog.h"
+
+#include "dccontainer.h"
+#include "dccreator.h"
+#include "dcscene.h"
+#include "dcvcpage.h"
+#include "command/dccommand.h"
+#include "utils/dcqtitemmodel.h"
+#include "dcsinglecolumntableview.h"
+
+#include <QLineEdit>
+#include <QTableView>
+#include <QHeaderView>
+
+DCAddCellCodeClassDialog::DCAddCellCodeClassDialog(DCContainer *container, DCCreator *creator, const QString& path, QWidget *parent) :
+ QDialog(parent), d_container(container), d_creator(creator)
+{
+ setWindowTitle(tr("Add class"));
+
+ d_textField = new QLineEdit;
+
+ d_table = new DCSingleColumnTableView();
+ QStringList headers;
+ headers << "page";
+ d_tableModel = new DCQtItemModel(headers);
+ d_tableModel->setReadOnly(0,true);
+
+ d_comboBox = new QComboBox;
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_JSBASIC), QString::fromStdString(TKContainer::CELLTYPE_JSBASIC));
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_BASICSTORAGE), QString::fromStdString(TKContainer::CELLTYPE_BASICSTORAGE));
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_IN), QString::fromStdString(TKContainer::CELLTYPE_IN));
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_OUT), QString::fromStdString(TKContainer::CELLTYPE_OUT));
+
+ DCScene *scene = container->getScene();
+ const QMap<QString,DCVCPage*> pages = scene->getPages();
+ QMapIterator<QString, DCVCPage*> i(pages);
+ int row = 0;
+ int selection = -1;
+ while (i.hasNext())
+ {
+ i.next();
+ QString item = i.key();
+ d_tableModel->insertString(item);
+ if (item == path) selection = row;
+ row++;
+ }
+ d_table->setModel(d_tableModel);
+
+ setLayout(new QVBoxLayout);
+ d_table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+
+ d_okButton = new QPushButton(tr("OK"));
+ d_cancelButton = new QPushButton(tr("Cancel"));
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Expanding));
+ buttonLayout->addWidget(d_cancelButton);
+ buttonLayout->addWidget(d_okButton);
+ d_okButton->setEnabled(false);
+ d_cancelButton->setAutoDefault(true);
+ d_cancelButton->setDefault(true);
+
+ QGridLayout *glayout = new QGridLayout;
+ glayout->addWidget(new QLabel(tr("name")),0,0);
+ glayout->addWidget(d_textField,0,1);
+ glayout->addWidget(new QLabel(tr("type")),1,0);
+ glayout->addWidget(d_comboBox);
+ ((QVBoxLayout*)layout())->addLayout(glayout);
+ layout()->addWidget(d_table);
+ d_statusText = new QLabel;
+ d_message = new QLabel;
+ d_message->setStyleSheet("color : red;");
+ layout()->addWidget(d_statusText);
+ layout()->addWidget(d_message);
+ ((QVBoxLayout*)layout())->addLayout(buttonLayout);
+
+ connect(d_textField, SIGNAL(textChanged(QString)), this, SLOT(textInputChanged(QString)));
+ connect(d_okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
+ connect(d_cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
+ connect(d_table,SIGNAL(selectionChangedSignal(QItemSelection,QItemSelection)), this, SLOT(listSelectionChanged(QItemSelection,QItemSelection)));
+ connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*)));
+
+ if (selection >= 0)
+ {
+ d_table->selectRow(selection);
+ }
+}
+
+DCAddCellCodeClassDialog::~DCAddCellCodeClassDialog()
+{
+}
+
+
+bool DCAddCellCodeClassDialog::checkInput()
+{
+ d_message->setText("");
+ d_statusText->setText("");
+ if (d_selectedPagePath.length() == 0)
+ {
+ d_message->setText(tr("Select a page to place the class"));
+ }
+ else if (d_textField->text().length() > 0)
+ {
+ QString path = d_selectedPagePath;
+ path.append("#");
+ path.append(d_textField->text());
+ TKCellCode *cellCode = d_container->getCellCode(path.toStdString());
+ if (cellCode)
+ {
+ d_message->setText(tr("The class name exists"));
+ }
+ else
+ {
+ d_okButton->setEnabled(true);
+ d_statusText->setText(path);
+ return true;
+ }
+ }
+ else
+ {
+ d_message->setText(tr("Input class name"));
+ }
+ d_okButton->setEnabled(false);
+ return false;
+}
+
+void DCAddCellCodeClassDialog::textInputChanged(const QString &text)
+{
+ checkInput();
+}
+
+void DCAddCellCodeClassDialog::okButtonClicked()
+{
+ if (checkInput())
+ {
+ QString path = d_selectedPagePath;
+ path.append("#");
+ path.append(d_textField->text());
+ d_creator->doCommandAddCellCodeClass(this, d_container, path, d_comboBox->currentText());
+ }
+
+}
+
+void DCAddCellCodeClassDialog::cancelButtonClicked()
+{
+ done(false);
+}
+
+
+void DCAddCellCodeClassDialog::listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ if (selected.count()>0)
+ {
+ d_selectedPagePath = d_tableModel->data(selected.at(0).indexes().at(0), Qt::DisplayRole).toString();
+ }
+ else
+ {
+ d_selectedPagePath = "";
+ }
+ checkInput();
+}
+
+QString DCAddCellCodeClassDialog::getAddedCellCodeClassName() const
+{
+ if (d_selectedPagePath.length() == 0)
+ {
+ return "";
+ }
+ else if (d_textField->text().length() > 0)
+ {
+ QString path = d_selectedPagePath;
+ path.append("#");
+ path.append(d_textField->text());
+ return path;
+ }
+ return "";
+}
+
+void DCAddCellCodeClassDialog::commandExecuted(const QUndoCommand *executedCommand)
+{
+ const DCCommand *command = dynamic_cast<const DCCommand*>(executedCommand);
+ if (command && command->getRequester() == this)
+ {
+ done(true);
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCADDCELLCODECLASSDIALOG_H
+#define DCADDCELLCODECLASSDIALOG_H
+
+#include <QDialog>
+#include <QTableView>
+#include <QComboBox>
+#include <QLabel>
+#include <QUndoCommand>
+
+class DCContainer;
+class DCCreator;
+class DCQtItemModel;
+class DCSingleColumnTableView;
+
+class DCAddCellCodeClassDialog : public QDialog
+{
+ Q_OBJECT
+
+private:
+ DCContainer *d_container;
+ DCCreator *d_creator;
+ DCSingleColumnTableView *d_table;
+ DCQtItemModel *d_tableModel;
+ QComboBox *d_comboBox;
+ QPushButton *d_okButton;
+ QPushButton *d_cancelButton;
+ QString d_selectedPagePath;
+ QLineEdit *d_textField;
+ QLabel *d_statusText;
+ QLabel *d_message;
+
+ bool checkInput();
+
+public:
+ DCAddCellCodeClassDialog(DCContainer *container, DCCreator *creator, const QString& path, QWidget *parent = 0);
+ virtual ~DCAddCellCodeClassDialog();
+
+ QString getAddedCellCodeClassName() const;
+
+signals:
+
+private slots:
+ void textInputChanged(const QString &text);
+ void okButtonClicked();
+ void cancelButtonClicked();
+ void listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+ void commandExecuted(const QUndoCommand* executedCommand);
+};
+
+#endif // DCADDCELLCODECLASSDIALOG_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcaddcelldialog.h"
+
+#include "dccontainer.h"
+#include "dccreator.h"
+#include "dcscene.h"
+#include "dcvcpage.h"
+#include "command/dccommand.h"
+#include "utils/dcqtitemmodel.h"
+#include "dcsinglecolumntableview.h"
+
+#include <QLineEdit>
+#include <QTableView>
+#include <QHeaderView>
+
+ DCAddCellDialog::DCAddCellDialog(DCContainer *container, DCCreator *creator, const QString& path, QWidget *parent) :
+ QDialog(parent), d_container(container), d_creator(creator)
+{
+ setWindowTitle(tr("Add cell"));
+
+ d_textField = new QLineEdit;
+
+ d_table = new DCSingleColumnTableView();
+ QStringList headers;
+ headers << "page";
+ d_tableModel = new DCQtItemModel(headers);
+ d_tableModel->setReadOnly(0,true);
+
+ d_comboBox = new QComboBox;
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_JSBASIC), QString::fromStdString(TKContainer::CELLTYPE_JSBASIC));
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_BASICSTORAGE), QString::fromStdString(TKContainer::CELLTYPE_BASICSTORAGE));
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_IN), QString::fromStdString(TKContainer::CELLTYPE_IN));
+ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_OUT), QString::fromStdString(TKContainer::CELLTYPE_OUT));
+
+ DCScene *scene = container->getScene();
+ const QMap<QString,DCVCPage*> pages = scene->getPages();
+ QMapIterator<QString, DCVCPage*> i(pages);
+ int row = 0;
+ int selection = -1;
+ while (i.hasNext())
+ {
+ i.next();
+ QString item = i.key();
+ d_tableModel->insertString(item);
+ if (item == path) selection = row;
+ row++;
+ }
+ d_table->setModel(d_tableModel);
+
+ setLayout(new QVBoxLayout);
+ d_table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+
+ d_okButton = new QPushButton(tr("OK"));
+ d_cancelButton = new QPushButton(tr("Cancel"));
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Expanding));
+ buttonLayout->addWidget(d_cancelButton);
+ buttonLayout->addWidget(d_okButton);
+ d_okButton->setEnabled(false);
+ d_cancelButton->setAutoDefault(true);
+ d_cancelButton->setDefault(true);
+
+ QGridLayout *glayout = new QGridLayout;
+ glayout->addWidget(new QLabel(tr("name")),0,0);
+ glayout->addWidget(d_textField,0,1);
+ glayout->addWidget(new QLabel(tr("type")),1,0);
+ glayout->addWidget(d_comboBox);
+ ((QVBoxLayout*)layout())->addLayout(glayout);
+ layout()->addWidget(d_table);
+ d_statusText = new QLabel;
+ d_message = new QLabel;
+ d_message->setStyleSheet("color : red;");
+ layout()->addWidget(d_statusText);
+ layout()->addWidget(d_message);
+ ((QVBoxLayout*)layout())->addLayout(buttonLayout);
+
+ connect(d_textField, SIGNAL(textChanged(QString)), this, SLOT(textInputChanged(QString)));
+ connect(d_okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
+ connect(d_cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
+ connect(d_table,SIGNAL(selectionChangedSignal(QItemSelection,QItemSelection)), this, SLOT(listSelectionChanged(QItemSelection,QItemSelection)));
+ connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*)));
+
+ if (selection >= 0)
+ {
+ QModelIndex index = d_tableModel->index(selection, 0);
+ if (index.isValid())
+ d_table->setCurrentIndex(index);
+ }
+}
+
+DCAddCellDialog::~DCAddCellDialog()
+{
+
+}
+
+bool DCAddCellDialog::checkInput()
+{
+ d_message->setText("");
+ d_statusText->setText("");
+ if (d_selectedPagePath.length() == 0)
+ {
+ d_message->setText(tr("Select a page to place the cell"));
+ }
+ else if (d_textField->text().length() > 0)
+ {
+ QString path = d_selectedPagePath;
+ path.append("#");
+ path.append(d_textField->text());
+ TKCell *cell = d_container->getCell(path.toStdString());
+ if (cell)
+ {
+ d_message->setText(tr("The cell name exists"));
+ }
+ else
+ {
+ d_okButton->setEnabled(true);
+ d_statusText->setText(path);
+ return true;
+ }
+ }
+ else
+ {
+ d_message->setText(tr("Input cell name"));
+ }
+ d_okButton->setEnabled(false);
+ return false;
+}
+
+void DCAddCellDialog::textInputChanged(const QString &text)
+{
+ checkInput();
+}
+
+void DCAddCellDialog::okButtonClicked()
+{
+ if (checkInput())
+ {
+ d_creator->doCommandAddCell(this, d_container, d_selectedPagePath, d_textField->text(), d_comboBox->currentText());
+ }
+
+}
+
+void DCAddCellDialog::cancelButtonClicked()
+{
+ done(false);
+}
+
+
+void DCAddCellDialog::listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ if (selected.count()>0)
+ {
+ d_selectedPagePath = d_tableModel->data(selected.at(0).indexes().at(0), Qt::DisplayRole).toString();
+ }
+ else
+ {
+ d_selectedPagePath = "";
+ }
+ checkInput();
+}
+
+void DCAddCellDialog::commandExecuted(const QUndoCommand *executedCommand)
+{
+ const DCCommand *command = dynamic_cast<const DCCommand*>(executedCommand);
+ if (command && command->getRequester() == this)
+ {
+ done(true);
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCADDCELLDIALOG_H
+#define DCADDCELLDIALOG_H
+
+#include <QDialog>
+#include <QTableView>
+#include <QComboBox>
+#include <QLabel>
+#include <QUndoCommand>
+
+class DCContainer;
+class DCCreator;
+class DCQtItemModel;
+class DCSingleColumnTableView;
+
+class DCAddCellDialog : public QDialog
+{
+ Q_OBJECT
+
+private:
+ DCContainer *d_container;
+ DCCreator *d_creator;
+ DCSingleColumnTableView *d_table;
+ DCQtItemModel *d_tableModel;
+ QComboBox *d_comboBox;
+ QPushButton *d_okButton;
+ QPushButton *d_cancelButton;
+ QString d_selectedPagePath;
+ QLineEdit *d_textField;
+ QLabel *d_statusText;
+ QLabel *d_message;
+
+ bool checkInput();
+
+public:
+ DCAddCellDialog(DCContainer *container, DCCreator *creator, const QString& path, QWidget *parent = 0);
+ virtual ~DCAddCellDialog();
+
+
+signals:
+
+private slots:
+ void textInputChanged(const QString &text);
+ void okButtonClicked();
+ void cancelButtonClicked();
+ void listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+ void commandExecuted(const QUndoCommand* executedCommand);
+
+};
+
+#endif // DCADDCELLDIALOG_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcassigncellcodeclassdialog.h"
+
+#include "dccontainer.h"
+#include "DCCellCode.h"
+#include "utils/dcqtitemmodel.h"
+#include "dcaddcellcodeclassdialog.h"
+#include "dcsinglecolumntableview.h"
+
+#include <QTableView>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QHeaderView>
+
+DCAssignCellCodeClassDialog::DCAssignCellCodeClassDialog(DCContainer *container, DCCreator *creator, QWidget *parent) :
+ QDialog(parent), d_container(container), d_creator(creator), d_selectedCellCodeClassName("")
+{
+ setWindowTitle(tr("Assign cell code class"));
+
+ d_table = new DCSingleColumnTableView();
+ QStringList headers;
+ headers << "page # name";
+ d_tableModel = new DCQtItemModel(headers);
+ d_tableModel->setReadOnly(0,true);
+
+ updateClassList();
+
+ d_table->setModel(d_tableModel);
+
+ d_addNewButton = new QPushButton(tr("Add new"));
+ setLayout(new QVBoxLayout);
+ d_table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+
+ d_okButton = new QPushButton(tr("OK"));
+ d_cancelButton = new QPushButton(tr("Cancel"));
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Expanding));
+ buttonLayout->addWidget(d_cancelButton);
+ buttonLayout->addWidget(d_okButton);
+ d_okButton->setEnabled(false);
+ d_cancelButton->setAutoDefault(true);
+ d_cancelButton->setDefault(true);
+
+ layout()->addWidget(d_table);
+ layout()->addWidget(d_addNewButton);
+ ((QVBoxLayout*)layout())->addLayout(buttonLayout);
+
+ connect(d_okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
+ connect(d_cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
+ connect(d_addNewButton, SIGNAL(clicked()), this, SLOT(addNewClicked()));
+ connect(d_table,SIGNAL(selectionChangedSignal(QItemSelection,QItemSelection)), this, SLOT(listSelectionChanged(QItemSelection,QItemSelection)));
+
+}
+
+
+DCAssignCellCodeClassDialog::~DCAssignCellCodeClassDialog()
+{
+ if (d_tableModel)
+ d_tableModel->deleteLater();
+}
+
+void DCAssignCellCodeClassDialog::updateClassList()
+{
+ d_tableModel->removeAllItems();
+ const TKCellCodeMap *cellcodes = d_container->getCellCodes();
+ TKCellCode *emtpyCellCodeClass = d_container->getEmptyCellCodeClass();
+ for ( TKCellCodeMap::const_iterator it = cellcodes->begin(); it != cellcodes->end(); ++it ) {
+ if (it->second != emtpyCellCodeClass)
+ {
+ QStringList items;
+ items << QString::fromStdString(it->first);
+ d_tableModel->insertStringList(items);
+ }
+ }
+}
+
+DCCellCode* DCAssignCellCodeClassDialog::getSelectedCellCodeClass() const
+{
+ if (d_selectedCellCodeClassName.length()>0)
+ return dynamic_cast<DCCellCode*>(d_container->getCellCode(d_selectedCellCodeClassName.toStdString()));
+ else
+ return NULL;
+
+}
+
+void DCAssignCellCodeClassDialog::okButtonClicked()
+{
+ done(true);
+}
+
+void DCAssignCellCodeClassDialog::cancelButtonClicked()
+{
+ d_selectedCellCodeClassName = "";
+ done(false);
+}
+
+void DCAssignCellCodeClassDialog::addNewClicked()
+{
+ DCAddCellCodeClassDialog dialog(d_container, d_creator, "");
+ dialog.exec();
+ updateClassList();
+ QString classname = dialog.getAddedCellCodeClassName();
+ if (classname.length()>0)
+ {
+ int cnt = d_tableModel->rowCount();
+ for (int i = 0; i < cnt; i++)
+ {
+ QString s = d_tableModel->data(d_tableModel->index(i,0), Qt::DisplayRole).toString();
+ if (s == classname)
+ {
+ d_table->selectRow(i);
+ break;
+ }
+ }
+ }
+}
+
+void DCAssignCellCodeClassDialog::listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ if (selected.count()>0)
+ {
+ d_selectedCellCodeClassName = d_tableModel->data(selected.at(0).indexes().at(0), Qt::DisplayRole).toString();
+ d_okButton->setEnabled(true);
+ }
+ else
+ {
+ d_okButton->setEnabled(false);
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCASSIGNCELLCODECLASSDIALOG_H
+#define DCASSIGNCELLCODECLASSDIALOG_H
+
+#include <QDialog>
+#include <QTableView>
+
+class DCContainer;
+class DCCellCode;
+class DCCreator;
+class DCQtItemModel;
+class DCSingleColumnTableView;
+
+class DCAssignCellCodeClassDialog : public QDialog
+{
+ Q_OBJECT
+private:
+ DCContainer *d_container;
+ DCCreator *d_creator;
+ DCSingleColumnTableView *d_table;
+ DCQtItemModel *d_tableModel;
+ QPushButton *d_addNewButton;
+ QPushButton *d_okButton;
+ QPushButton *d_cancelButton;
+ QString d_selectedCellCodeClassName;
+
+ void updateClassList();
+public:
+ DCAssignCellCodeClassDialog(DCContainer *container, DCCreator *creator, QWidget *parent = 0);
+ virtual ~DCAssignCellCodeClassDialog();
+
+ DCCellCode *getSelectedCellCodeClass() const;
+signals:
+
+private slots:
+ void okButtonClicked();
+ void cancelButtonClicked();
+ void addNewClicked();
+ void listSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+
+};
+
+#endif // DCASSIGNCELLCODECLASSDIALOG_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcinputnewpagenamedialog.h"
+
+#include <QVBoxLayout>
+#include <QLabel>
+
+DCInputNewPageNameDialog::DCInputNewPageNameDialog(QWidget *parent) :
+ QDialog(parent), d_result("")
+{
+ d_inputField = new QLineEdit();
+ QVBoxLayout *contentLayout = new QVBoxLayout;
+ contentLayout->addWidget(new QLabel(tr("name")));
+ QHBoxLayout *hlayout = new QHBoxLayout;
+ hlayout->addWidget(d_inputField);
+ hlayout->addWidget(new QLabel(tr(".xhtml")));
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ d_cancelButton = new QPushButton(tr("Cancel"));
+ d_okButton = new QPushButton(tr("OK"));
+ d_okButton->setEnabled(false);
+ buttonLayout->addWidget(d_cancelButton);
+ buttonLayout->addWidget(d_okButton);
+
+ contentLayout->addLayout(hlayout);
+ contentLayout->addLayout(buttonLayout);
+
+ setLayout(contentLayout);
+
+ connect(d_okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
+ connect(d_cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
+ connect(d_inputField, SIGNAL(textChanged(QString)), this, SLOT(inputChanged()));
+}
+
+void DCInputNewPageNameDialog::inputChanged()
+{
+ // TODO:
+ // Need to consider the case when the name has already existed.
+ //
+ if (d_inputField->text().length() > 0)
+ {
+ d_okButton->setEnabled(true);
+ }
+ else
+ {
+ d_okButton->setEnabled(false);
+ }
+}
+
+void DCInputNewPageNameDialog::okButtonClicked()
+{
+ d_result = d_inputField->text();
+ done(true);
+}
+
+void DCInputNewPageNameDialog::cancelButtonClicked()
+{
+ d_result = "";
+ done(false);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCINPUTNEWPAGENAMEDIALOG_H
+#define DCINPUTNEWPAGENAMEDIALOG_H
+
+#include <QDialog>
+#include <QLineEdit>
+#include <QPushButton>
+
+class DCInputNewPageNameDialog : public QDialog
+{
+ Q_OBJECT
+
+ QString d_result;
+ QLineEdit *d_inputField;
+ QPushButton *d_okButton;
+ QPushButton *d_cancelButton;
+
+public:
+ explicit DCInputNewPageNameDialog(QWidget *parent = 0);
+ virtual ~DCInputNewPageNameDialog() {}
+
+ QString getName() const { return d_result + ".xhtml"; }
+
+signals:
+
+private slots:
+ void okButtonClicked();
+ void cancelButtonClicked();
+ void inputChanged();
+};
+
+#endif // DCINPUTNEWPAGENAMEDIALOG_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcinputreceptornamedialog.h"
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QLabel>
+
+#include "dccell.h"
+
+DCInputReceptorNameDialog::DCInputReceptorNameDialog(DCCell *cell, QWidget *parent) :
+ QDialog(parent), d_isOK(false), d_cell(cell)
+{
+ QVBoxLayout *layout = new QVBoxLayout;
+ d_textInput = new QLineEdit;
+ layout->addWidget(new QLabel(tr("Input receptor name")));
+ layout->addWidget(d_textInput);
+ d_messageText = new QLabel(" ");
+ d_messageText->setStyleSheet("color : red;");
+ layout->addWidget(d_messageText);
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ d_okButton = new QPushButton(tr("OK"));
+ QPushButton *cancelButton = new QPushButton(tr("Cancel"));
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(d_okButton);
+ buttonLayout->addWidget(cancelButton);
+
+
+ connect(d_textInput, SIGNAL(textChanged(QString)), this, SLOT(slotInputTextChanged(QString)));
+ connect(d_okButton, SIGNAL(clicked()), this, SLOT(slotOKButtonClicked()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(slotCancelButtonClicked()));
+
+ layout->addLayout(buttonLayout);
+
+
+ setLayout(layout);
+}
+
+void DCInputReceptorNameDialog::slotInputTextChanged(const QString &inputText)
+{
+ QString receptorName = inputText.trimmed();
+
+ if (d_cell->getReceptors()->find(receptorName.toStdString()) != d_cell->getReceptors()->end())
+ {
+ d_messageText->setText(tr("The receptor name already exists in the target."));
+ d_okButton->setEnabled(false);
+ }
+ else
+ {
+ d_messageText->setText(tr(" "));
+ d_okButton->setEnabled(true);
+ }
+}
+
+void DCInputReceptorNameDialog::slotOKButtonClicked()
+{
+ d_isOK = true;
+ done(true);
+}
+
+void DCInputReceptorNameDialog::slotCancelButtonClicked()
+{
+ d_isOK = false;
+ done(false);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCINPUTRECEPTORNAMEDIALOG_H
+#define DCINPUTRECEPTORNAMEDIALOG_H
+
+#include <QtGui>
+#include <QLineEdit>
+#include <QLabel>
+#include <QPushButton>
+
+class DCCell;
+
+class DCInputReceptorNameDialog : public QDialog
+{
+ Q_OBJECT
+
+private:
+ QLineEdit *d_textInput;
+ QLabel *d_messageText;
+ QPushButton *d_okButton;
+ bool d_isOK;
+ DCCell *d_cell;
+
+public:
+ explicit DCInputReceptorNameDialog(DCCell *cell, QWidget *parent = 0);
+
+ bool getIsOk() const { return d_isOK; }
+ QString getInputText() const { return d_textInput->text().trimmed(); }
+
+signals:
+
+public slots:
+ void slotInputTextChanged(const QString &inputText);
+ void slotOKButtonClicked();
+ void slotCancelButtonClicked();
+
+};
+
+#endif // DCINPUTRECEPTORNAMEDIALOG_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcsinglecolumntableview.h"
+
+DCSingleColumnTableView::DCSingleColumnTableView(QWidget *parent) :
+ QTableView(parent)
+{
+}
+
+DCSingleColumnTableView::~DCSingleColumnTableView()
+{
+
+}
+
+void DCSingleColumnTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ QTableView::selectionChanged(selected, deselected);
+ emit selectionChangedSignal(selected, deselected);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCSINGLECOLUMNTABLEVIEW_H
+#define DCSINGLECOLUMNTABLEVIEW_H
+
+#include <QTableView>
+
+class DCSingleColumnTableView : public QTableView
+{
+ Q_OBJECT
+public:
+ explicit DCSingleColumnTableView(QWidget *parent = 0);
+ virtual ~DCSingleColumnTableView();
+
+protected:
+ virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+
+signals:
+ void selectionChangedSignal(const QItemSelection &selected, const QItemSelection &deselected);
+
+public slots:
+
+};
+
+#endif // DCSINGLECOLUMNTABLEVIEW_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#include "DNGlobal.h"
+
+DNGlobal* dnGlobal()
+{
+ return DNGlobal::instance();
+}
+
+//static
+DNGlobal *DNGlobal::instance()
+{
+ static DNGlobal *_instance = 0;
+ if (!_instance)
+ {
+ _instance = new DNGlobal();
+ }
+
+ return _instance;
+}
+
+DNGlobal::DNGlobal() : mEStatus(NORMAL), mRStatus(STOPPED)
+{
+}
+
+DNGlobal::~DNGlobal()
+{
+}
+
+bool DNGlobal::updateErrorStatus(E_Status status)
+{
+ bool isStatusUpdated = false;
+ mLock.lock();
+ if (mEStatus < status)
+ {
+ mEStatus = status;
+ isStatusUpdated = true;
+ }
+ mLock.unlock();
+ return isStatusUpdated;
+}
+
+void DNGlobal::setMessage1(std::string message1)
+{
+ mLock.lock();
+ mMessage1 = message1;
+ mLock.unlock();
+}
+
+void DNGlobal::setMessage2(std::string message2)
+{
+ mLock.lock();
+ mMessage2 = message2;
+ mLock.unlock();
+}
+
+DNGlobal::E_Status DNGlobal::getErrorStatus()
+{
+ return mEStatus;
+}
+
+bool DNGlobal::isErrorStatusNormal()
+{
+ return mEStatus == NORMAL;
+}
+
+std::string DNGlobal::getMessage1()
+{
+ if (mEStatus > NORMAL)
+ {
+ return mMessage1;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+std::string DNGlobal::getMessage2()
+{
+ if (mEStatus > NORMAL)
+ {
+ return mMessage2;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+void DNGlobal::resetErrorStatus()
+{
+ mEStatus = NORMAL;
+ mMessage1 = "";
+ mMessage2 = "";
+}
+
+DNGlobal::R_Status DNGlobal::getRunningStatus()
+{
+ return mRStatus;
+}
+
+bool DNGlobal::updateRunningStatus(R_Status status)
+{
+ bool updated = false;
+ mLock.lock();
+ if (mRStatus != status)
+ {
+ updated = true;
+ mRStatus = status;
+ }
+ mLock.unlock();
+
+ return updated;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#ifndef DNGLOBAL_H
+#define DNGLOBAL_H
+
+#include <string>
+#include "TKLock.h"
+
+class DNGlobal
+{
+public:
+ static DNGlobal* instance();
+ ~DNGlobal();
+
+ enum E_Status {NORMAL,WARNING,ERROR,FATAL_ERROR};
+ enum R_Status {STOPPED,RUNNIING,STOPPING};
+
+ bool updateErrorStatus(E_Status status);
+ E_Status getErrorStatus();
+
+ bool isErrorStatusNormal();
+ void setMessage1(std::string message);
+ void setMessage2(std::string message);
+ std::string getMessage1();
+ std::string getMessage2();
+ void resetErrorStatus();
+
+ bool updateRunningStatus(R_Status running);
+ R_Status getRunningStatus();
+
+
+private:
+ DNGlobal();
+ TKLock mLock;
+ std::string mMessage1;
+ std::string mMessage2;
+ E_Status mEStatus;
+ R_Status mRStatus;
+};
+
+DNGlobal* dnGlobal();
+
+#endif // DNGLOBAL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 3/24/2012.
+//
+#include "DNStorage.h"
+
+#include "DNStorageImpl.h"
+
+DNStorageXYZVRecords::DNStorageXYZVRecords(int _length) : length(_length), data(0)
+{
+ data = new DNStorageXYZVData[length];
+}
+
+DNStorageXYZVRecords::~DNStorageXYZVRecords()
+{
+ if (data)
+ {
+ delete[] data;
+ data = 0;
+ }
+}
+
+DNStorage::DNStorage(const char *storagePath)
+{
+ impl = DNStorageImpl::create(storagePath);
+}
+
+DNStorage::~DNStorage()
+{
+ if (impl)
+ {
+ impl->flush();
+ delete impl;
+ impl = 0;
+ }
+}
+
+bool DNStorage::setValue(const char *path, const char *key, float value)
+{
+ bool r = 0;
+ if (impl)
+ {
+ r = impl->setValue(path,key,value);
+ }
+ return r;
+}
+
+int DNStorage::getCount(const char *path, const char *key)
+{
+ int r = 0;
+ if (impl)
+ {
+ r = impl->getCount(path,key);
+ }
+ return r;
+}
+
+float DNStorage::getValue(const char *path, const char *key)
+{
+ float r = 0;
+ if (impl)
+ {
+ r = impl->getValue(path,key);
+ }
+ return r;
+}
+
+int DNStorage::countXYZVData(const char *path, const char *key)
+{
+ int r = 0;
+ if (impl)
+ {
+ r = impl->countXYZVData(path,key);
+ }
+ return r;
+}
+
+bool DNStorage::insertXYZVData(const char *path, const char *key, int index, float x, float y, float z, float v)
+{
+ bool r = false;
+ if (impl)
+ {
+ r = impl->insertXYZVData(path,key,index,x,y,z,v);
+ }
+ return r;
+}
+
+DNStorageXYZVRecords* DNStorage::queryXYZVData(const char *path, const char *key)
+{
+ DNStorageXYZVRecords *r = 0;
+ if (impl)
+ {
+ r = impl->queryXYZVData(path,key);
+ }
+ return r;
+}
+
+bool DNStorage::deleteXYZVData(const char *path, const char *key)
+{
+ bool r = false;
+ if (impl)
+ {
+ r = impl->deleteXYZVData(path,key);
+ }
+ return r;
+}
+
+bool DNStorage::flush()
+{
+ bool r = false;
+ if (impl)
+ r = impl->flush();
+
+ return r;
+}
+
+bool DNStorage::isValid()
+{
+ bool r = false;
+ if (impl)
+ r = impl->isValid();
+
+ return r;
+}
+
+bool DNStorage::startTransaction()
+{
+ bool r = false;
+ if (impl)
+ r = impl->startTransaction();
+
+ return r;
+}
+
+bool DNStorage::commitTransaction()
+{
+ bool r = false;
+ if (impl)
+ r = impl->commitTransaction();
+
+ return r;
+}
+
+bool DNStorage::rollbackTransaction()
+{
+ bool r = false;
+ if (impl)
+ r = impl->rollbackTransaction();
+
+ return r;
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 3/24/2012.
+//
+#ifndef DNSTORAGE_H
+#define DNSTORAGE_H
+
+class DNStorageImpl;
+
+
+class DNStorageXYZVData
+{
+public:
+ DNStorageXYZVData():index(0),x(0.0),y(0.0),z(0.0),v(0.0) {}
+
+ int index;
+ float x;
+ float y;
+ float z;
+ float v;
+};
+
+class DNStorageXYZVRecords
+{
+public:
+ DNStorageXYZVRecords(int length);
+ ~DNStorageXYZVRecords();
+
+ int length;
+ DNStorageXYZVData *data;
+};
+
+class DNStorage
+{
+public:
+ DNStorage(const char *storagePath);
+ ~DNStorage();
+
+ //methods for simple key-value storage
+ bool setValue(const char *path, const char *key, float value);
+ float getValue(const char *path, const char *key);
+ int getCount(const char *path, const char *key);
+
+ //methods for xyz dataset storage
+ int countXYZVData(const char *path, const char *key);
+ bool insertXYZVData(const char *path, const char *key, int index, float x, float y, float z, float v);
+ DNStorageXYZVRecords* queryXYZVData(const char *path, const char *key);
+ bool deleteXYZVData(const char *path, const char *key);
+
+ bool flush();
+
+ bool isValid();
+
+ bool startTransaction();
+ bool commitTransaction();
+ bool rollbackTransaction();
+
+private:
+ DNStorageImpl *impl;
+};
+
+#endif // DNSTORAGE_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 3/24/2012.
+//
+#ifndef DNSTORAGEIMPL_H
+#define DNSTORAGEIMPL_H
+
+class DNStorageDataSet;
+class DNStorageDataSetQuery;
+class DNStorageXYZVRecords;
+
+class DNStorageImpl
+{
+public:
+ static DNStorageImpl* create(const char *storagePath);
+
+ virtual ~DNStorageImpl() {}
+ virtual bool setValue(const char *path, const char *key, float value) = 0;
+ virtual float getValue(const char *path, const char *key) = 0;
+ virtual int getCount(const char *path, const char *key) = 0;
+
+ virtual int countXYZVData(const char *path, const char *key) = 0;
+ virtual bool insertXYZVData(const char *path, const char *key, int index, float x, float y, float z,float v) = 0;
+ virtual DNStorageXYZVRecords* queryXYZVData(const char *path, const char *key) = 0;
+ virtual bool deleteXYZVData(const char *path, const char *key) = 0;
+
+ virtual bool isValid() = 0;
+
+ virtual bool flush() = 0;
+
+ virtual bool startTransaction() = 0;
+ virtual bool commitTransaction() = 0;
+ virtual bool rollbackTransaction() = 0;
+};
+
+#endif // DNSOTRAGEIMPL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#include "DNUtils.h"
+#include "TKLog.h"
+#include "TKDebug.h"
+#include "DNGlobal.h"
+
+#ifndef _MSC_VER
+ #include <string.h>
+ #include <stdlib.h>
+#endif
+
+#include <algorithm>
+
+void trimString(std::string& str)
+{
+ std::string::size_type pos1 = str.find_first_not_of(' ');
+ std::string::size_type pos2 = str.find_last_not_of(' ');
+ std::string::size_type pos1_2 = str.find_first_not_of('\t');
+ std::string::size_type pos2_2 = str.find_last_not_of('\t');
+
+ pos1 = pos1 < pos1_2 ? pos1_2 : pos1;
+ pos2 = pos2 < pos2_2 ? pos2_2 : pos2;
+
+ str = str.substr(pos1 == std::string::npos ? 0 : pos1,
+ pos2 == std::string::npos ? str.length() - 1 : pos2 - pos1 + 1);
+}
+
+std::string upperString( const std::string &src )
+{
+ std::string data = src;
+ std::transform(data.begin(), data.end(), data.begin(), ::toupper);
+
+ return data;
+}
+
+std::string parseCellCodeForScriptEngine(std::string jname, std::string cellCode)
+{
+#ifdef DEBUG
+ DEBUG_TRACE("TKJSCellCode::TKJSCellCode() parse for %s\n=== Original code =====\n%s\n", jname.c_str(), cellCode.c_str());
+#endif
+
+ const char *c = cellCode.c_str();
+
+ int inComment1 = 0; // //
+ int inComment2 = 0; // /* ... */
+ int inComment2_end = 0;
+ int inFunction = 0;
+ int inVar = 0;
+ int inQuote = 0;
+ int inDoubleQuote = 0;
+ int nest = 0;
+ const char *sp = 0;
+ int l = 0;
+ int lp = 0;
+ std::string funcs = "";
+ std::string vars = "";
+ std::string fff = "";
+
+ const char* str_comment1 = "//";
+ const char* str_comment2 = "/*";
+ const char* str_comment2_end = "*/";
+ const char* str_function = "function";
+ const char* str_var = "var";
+
+ while (*c)
+ {
+ if (*c == '\r' || *c == '\n')
+ {
+ lp = 0;
+ }
+ else if (*c != ' ' && *c != '\t')
+ {
+ lp++;
+ }
+
+ if (inComment1 == -1)
+ {
+ if (*c == '\r' || *c == '\n' )
+ inComment1 = 0;
+ c++;
+ continue;
+ }
+ else if (inComment2 == -1)
+ {
+ if (*c == str_comment2_end[inComment2_end])
+ {
+ inComment2_end ++;
+ if (str_comment2_end[inComment2_end] == 0)
+ {
+ inComment2 = 0;
+ inComment2_end = 0;
+ }
+ }
+ else
+ {
+ inComment2_end = 0;
+ }
+ c++;
+ continue;
+ }
+
+ if (inQuote == -1)
+ {
+ if (*c == '\\')
+ {
+ c++;
+ if (*c != 0)c++;
+ continue;
+ }
+ if (*c == '\'')
+ {
+ inQuote = 0;
+ }
+ c++;
+ continue;
+ }
+ else if (inDoubleQuote == -1)
+ {
+ if (*c == '\\')
+ {
+ c++;
+ if (*c != 0)c++;
+ continue;
+ }
+ if (*c == '\"')
+ {
+ inDoubleQuote = 0;
+ }
+ c++;
+ continue;
+ }
+
+ if (*c == '\'')
+ {
+ inQuote = -1;
+ c++;
+ continue;
+ }
+
+ if (*c == '\"')
+ {
+ inDoubleQuote = -1;
+ c++;
+ continue;
+ }
+
+ //IN COMMENT?
+ if (*c == str_comment1[inComment1])
+ {
+ inComment1++;
+ if (str_comment1[inComment1] == 0)
+ {
+ inComment1 = -1;
+ c++;
+ continue;
+ }
+ }
+ else
+ {
+ inComment1 = 0;
+ }
+
+ if (*c == str_comment2[inComment2])
+ {
+ inComment2++;
+ if (str_comment2[inComment2] == 0)
+ {
+ inComment2 = -1;
+ c++;
+ continue;
+ }
+ }
+ else
+ {
+ inComment2 = 0;
+ }
+
+ if (!inComment1 && !inComment2 && !inQuote && !inDoubleQuote && *c == '{')
+ {
+ nest++;
+ if (inFunction == -1 && nest == 1)
+ {
+ fff = "";
+ fff.append(sp,c-sp+1);
+ unsigned long fp = fff.find( "(", 0 );
+ if( fp != std::string::npos )
+ {
+ fff = fff.substr(0, fp);
+ trimString(fff);
+ sp += fp;
+ }
+ else
+ {
+ inFunction = 0;
+ }
+ }
+ }
+ else if (!inComment1 && !inComment2 && !inQuote && !inDoubleQuote && *c == '}')
+ {
+ nest--;
+ if (nest == 0)
+ {
+ if (inFunction == -1)
+ {
+ //FUNCTION DEF
+ funcs.append(jname);
+ funcs.append(".prototype.");
+ funcs.append(fff);
+ funcs.append(" = function");
+ funcs.append(sp ,c-sp+1);
+ funcs.append("\r\n");
+ inFunction = 0;
+ }
+ }
+ c++;
+ continue;
+ }
+
+ if (*c == ';')
+ {
+ if (inVar == -1)
+ {
+ //VAR DEF
+ std::string t = "";
+ t.append(sp,c-sp+1);
+ trimString(t);
+ vars.append("this.");
+ vars.append(t);
+ vars.append("\r\n");
+ inVar = 0;
+ }
+ c++;
+ continue;
+ }
+
+ if (inFunction == -1)
+ {
+ if (l == 0) {
+ if (*c != ' ' && *c != '\t' && *c != '\r' && *c != '\n')
+ {
+ inFunction =0;
+ c++;
+ l = 0;
+ continue;
+ }
+ }
+ c++;
+ l++;
+ continue;
+ }
+
+ if (inVar == -1)
+ {
+ if (l == 0) {
+ if (*c != ' ' && *c != '\t' && *c != '\r' && *c != '\n' && *c != '=')
+ {
+ inVar =0;
+ c++;
+ l = 0;
+ continue;
+ }
+ }
+ c++;
+ l++;
+ continue;
+ }
+
+
+ if (nest == 0 && *c == str_function[inFunction] && (inFunction+1) == lp)
+ {
+ inFunction++;
+ if (str_function[inFunction] == 0)
+ {
+ inFunction = -1;
+ sp = c+1;
+ l = 0;
+ }
+ c++;
+ continue;
+ }
+
+ if (nest == 0 && *c == str_var[inVar] && (inVar+1) == lp)
+ {
+ inVar++;
+ if (str_var[inVar] == 0)
+ {
+ inVar = -1;
+ sp = c+1;
+ l = 0;
+ }
+ c++;
+ continue;
+ }
+
+ c++;
+
+ }
+
+ std::string stmt = "";
+ stmt.append("function ");
+ stmt.append(jname);
+ stmt.append("(ownerCell)\n{\nthis.cell = ownerCell;\n");
+ stmt.append(vars);
+ stmt.append("\n}\n");
+ stmt.append(funcs);
+#ifdef DEBUG
+ DEBUG_TRACE("\n\n==== Translated JS statement:=====\n%s\n=====\n", stmt.c_str());
+#endif
+ return stmt;
+}
+
+std::string getFQNString(const char *location, const char *name)
+{
+ std::string path;
+ std::string node;
+ int l = (int)strlen(location) - 1;
+ bool f = false;
+ while (l >= 0)
+ {
+ if (location[l] == '/')
+ {
+ f = true;
+ break;
+ }
+ l--;
+ }
+ if( f )
+ {
+ if (l == 0)
+ {
+ path = "/";
+ node = location;
+ }
+ else
+ {
+ node = location;
+ path = node.substr(0,l);
+ node = node.substr(l);
+ }
+ }
+ else
+ {
+ path = "";
+ node = location;
+ }
+
+ const char *c = name;
+ int i = 0;
+ const char *p = c;
+ while(*c)
+ {
+ if (*c == '/')
+ {
+ if (i >= 2 && *(c - 2) == '.' && *(c - 1) == '.')
+ {
+ unsigned long l = path.find_last_of("/");
+ if( l != std::string::npos )
+ {
+ if (l == 0)
+ {
+ path = "/";
+ }
+ else if (l > 0)
+ {
+ path = path.substr(0, l);
+ }
+ }
+ else
+ {
+ path = "";
+ }
+ p = c;
+ }
+ else if (i >= 1 && *(c - 1) == '.')
+ {
+ p = c;
+ }
+ else if (i >= 1 && *(c - 1) == '/')
+ {
+ p = c;
+ }
+ else if (i == 0)
+ {
+ if (path.length() > 0 && path.at(0) == '/')
+ {
+ path = "/";
+ }
+ else
+ {
+ path = "";
+ }
+ }
+ else
+ {
+ size_t pl = path.length();
+ if (pl == 0)
+ {
+ if (*p == '/')
+ {
+ p++;
+ }
+ }
+ else if (pl == 1)
+ {
+ char p1 = path.at(0);
+ if (p1 == '/' || p1 == '.')
+ {
+ if (*p == '/')
+ {
+ p++;
+ }
+ }
+ }
+ else
+ {
+ if (*p != '/')
+ {
+ path.append("/");
+ }
+ }
+ std::string s(p, c-p);
+ path.append(s);
+ p = c;
+ }
+ }
+ c++;
+ i++;
+ if (i > 1024) break;
+ }
+
+ if (*p == '/')
+ {
+ node = p;
+ }
+ else if(*p == '#')
+ {
+ node.append(p);
+ }
+ else
+ {
+ const char *p2 = p;
+ bool hasAnchor = false;
+ while(*p2)
+ {
+ if (*p2 == '#')
+ {
+ hasAnchor = true;
+ break;
+ }
+ p2++;
+ }
+ if (hasAnchor)
+ {
+ node = "/";
+ node.append(p);
+ }
+ else
+ {
+ node.append("#");
+ node.append(p);
+ }
+ }
+
+ int pl = (int)path.length();
+ std::string fqn;
+ if (pl == 0)
+ {
+ if (node.at(0) == '/' && node.length() > 1)
+ {
+ fqn = node.substr(1);
+ }
+ else
+ {
+ fqn = node;
+ }
+
+ }
+ else if (pl == 1)
+ {
+ if (path.at(0) == '/' && node.length() > 0 && node.at(0) == '/')
+ {
+ fqn = node;
+ }
+ else
+ {
+ fqn = path.append(node);
+ }
+ }
+ else
+ {
+ fqn = path.append(node);
+ }
+
+ return fqn;
+}
+
+std::string getJSEscapeString(const char *cstring)
+{
+ const char *c = cstring;
+ std::string result = "";
+ while(*c)
+ {
+ if (*c == '/')
+ {
+ result.append("_s");
+ }
+ else if (*c == '_')
+ {
+ result.append("__");
+ }
+ else if (*c == '.')
+ {
+ result.append("_d");
+ }
+ else if (*c == '#')
+ {
+ result.append("_S");
+ }
+ else
+ {
+ result.append(1,*c);
+ }
+
+ c++;
+ }
+
+ return result;
+}
+
+static TKLock NotifyLock;
+
+void dnNotifyError(std::string title, std::string message)
+{
+ NotifyLock.lock();
+
+ std::string::size_type pos = 0;
+ while(pos = message.find("\n", pos), pos != std::string::npos) {
+ message.replace(pos, 1, "\n ");
+ pos += 1;
+ }
+
+ std::string outMessage = "[ERROR!!!]:";
+ outMessage.append(title).append("\n ");
+ outMessage.append(message);
+
+ TKLog::printf(TKLog::ERROR, "%s", outMessage.c_str());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1(title);
+ dnGlobal()->setMessage2(message);
+ }
+ else
+ {
+ dnGlobal()->setMessage1(title);
+ }
+ NotifyLock.unlock();
+}
+
+void dnNotifyWarning(std::string title, std::string message)
+{
+ NotifyLock.lock();
+
+ std::string::size_type pos = 0;
+ while(pos = message.find("\n", pos), pos != std::string::npos) {
+ message.replace(pos, 1, "\n ");
+ pos += 1;
+ }
+
+ std::string outMessage = "[WARNING] :";
+ outMessage.append(title).append("\n ");
+ outMessage.append(message);
+
+ TKLog::printf(TKLog::WARNING, "%s", outMessage.c_str());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::WARNING))
+ {
+ dnGlobal()->setMessage1(title);
+ dnGlobal()->setMessage2(message);
+ }
+ else
+ {
+ dnGlobal()->setMessage1(title);
+ }
+ NotifyLock.unlock();
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#ifndef dennco_DNUtils_h
+#define dennco_DNUtils_h
+
+#include <string>
+#include "TKLock.h"
+
+void trimString(std::string& str);
+std::string upperString( const std::string &src );
+
+std::string getFQNString(const char *location, const char *name);
+std::string getJSEscapeString(const char *cstring);
+std::string parseCellCodeForScriptEngine(std::string jname, std::string cellCode);
+
+void dnNotifyError(std::string title, std::string message);
+void dnNotifyWarning(std::string title, std::string message);
+
+class DNLocker
+{
+public:
+ DNLocker(TKLock *lock) : mLock(lock) {mLock->lock();}
+ ~DNLocker() { mLock->unlock();}
+private:
+ TKLock *mLock;
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+#include "TKAxon.h"
+#include "TKCell.h"
+#include "TKContainer.h"
+#include "TKAxonTerminal.h"
+#include "TKLock.h"
+#include "DNUtils.h"
+
+TKAxon::TKAxon(TKCell *theOwner) : mValue(0.0), mOwner(theOwner)
+{
+}
+
+TKAxon::~TKAxon()
+{
+ for ( std::vector<TKAxonTerminal*>::iterator it = mTerminals.begin(); it != mTerminals.end(); ++it ) {
+ delete *it;
+ }
+ mTerminals.clear();
+}
+
+float TKAxon::getValue() const
+{
+ DNLocker locker(&mLock);
+
+ return mValue;
+}
+
+void TKAxon::setValue(float value)
+{
+ DNLocker locker(&mLock);
+
+ mValue = value;
+}
+
+TKAxonTerminal* TKAxon::addTerminal()
+{
+ TKAxonTerminal *terminal = mOwner->getContainer()->axonTerminalFactory(this);
+
+ if (terminal)
+ {
+ mTerminals.push_back(terminal);
+ }
+ return terminal;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#ifndef __INCLUDE_TKAXON__
+#define __INCLUDE_TKAXON__
+
+#include <string>
+#include <vector>
+
+#include "TKLock.h"
+
+class TKCell;
+class TKAxonTerminal;
+
+class TKAxon
+{
+public:
+ TKAxon(TKCell *theOwner);
+ virtual ~TKAxon();
+ TKAxonTerminal* addTerminal();
+ TKCell* getOwner() const { return mOwner; }
+ float getValue() const;
+ void setValue(float value);
+
+protected:
+ std::vector<TKAxonTerminal*> mTerminals;
+
+private:
+ float mValue;
+ TKCell *mOwner;
+ mutable TKLock mLock;
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#include "TKAxonTerminal.h"
+#include "TKAxon.h"
+#include "TKDebug.h"
+
+void TKAxonTerminal::release(TKReceptor *receptor)
+{
+ if (receptor == mTarget)
+ mTarget = NULL;
+}
+
+float TKAxonTerminal::getValue()
+{
+ TKASSERT(mOwner);
+ return mOwner->getValue();
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#ifndef __INCLUDE_TKAXONTERMINAL__
+#define __INCLUDE_TKAXONTERMINAL__
+
+class TKAxon;
+class TKReceptor;
+
+class TKAxonTerminal
+{
+public:
+ TKAxonTerminal(TKAxon *theOwner) : mOwner(theOwner), mTarget(0) {}
+ virtual ~TKAxonTerminal() {}
+
+ void setTarget(TKReceptor *theReceptor) {mTarget = theReceptor;}
+ void release(TKReceptor *receptor);
+
+ bool isConnected() { return mTarget != 0; }
+ TKAxon* getOwner() { return mOwner; }
+ TKReceptor* getTarget() { return mTarget; }
+ float getValue();
+
+private:
+ TKAxon *mOwner;
+ TKReceptor *mTarget;
+
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#include "TKCell.h"
+#include "TKReceptor.h"
+#include "TKContainer.h"
+#include "TKCellCode.h"
+#include "TKAxon.h"
+#include "TKCellCodeInstance.h"
+#include "TKLog.h"
+#include <string>
+
+TKCell::TKCell(TKContainer *container, std::string location, std::string name, bool canIntarface)
+: mName(name), mLocation(location), mContainer(container), mAxon(NULL), mCellCodeInstance(NULL), mCanInterface(canIntarface)
+{
+}
+
+TKCell::~TKCell()
+{
+ if (mCellCodeInstance)
+ {
+ delete mCellCodeInstance;
+ mCellCodeInstance = NULL;
+ }
+
+ for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
+ delete it->second;
+ }
+ mReceptors.clear();
+
+ if (mAxon)
+ {
+ delete mAxon;
+ mAxon = NULL;
+ }
+}
+
+void TKCell::init()
+{
+ if (!mAxon)
+ mAxon = mContainer->axonFactory(this);
+}
+
+float TKCell::getAxonValue() const
+{
+ if (!mAxon)
+ return 0.0;
+ return mAxon->getValue();
+}
+
+void TKCell::setAxonValue(float value)
+{
+ if (!mAxon)
+ return;
+ mAxon->setValue(value);
+}
+
+bool TKCell::setCellCode(TKCellCode *code, const void *data)
+{
+ if (mCellCodeInstance)
+ delete mCellCodeInstance;
+
+ mCellCodeInstance = code->createCellCodeInstance(this, data);
+ return mCellCodeInstance != NULL;
+}
+
+bool TKCell::connectTo(std::string connectionName, TKCell *targetCell)
+{
+ TKReceptor *receptor = targetCell->createReceptor(connectionName);
+ if (receptor)
+ {
+ TKAxonTerminal *terminal = mAxon->addTerminal();
+ receptor->setTarget(terminal);
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+TKReceptor* TKCell::createReceptor(std::string name)
+{
+ TKReceptor *receptor;
+ TKReceptorMap::iterator it = mReceptors.find(name);
+ if (it != mReceptors.end())
+ {
+ receptor = NULL;
+ }
+ else
+ {
+ receptor = mContainer->receptorFactory(this);
+ if (receptor)
+ {
+ mReceptors.insert( TKReceptorMap::value_type( name, receptor ) );
+ }
+ }
+
+ return receptor;
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#ifndef __INCLUDE_TKCELL__
+#define __INCLUDE_TKCELL__
+
+#include <string>
+#include <map>
+
+class TKCellCode;
+class TKReceptor;
+class TKAxon;
+class TKContainer;
+class TKCellCodeInstance;
+
+typedef std::map<std::string, TKReceptor*> TKReceptorMap;
+
+class TKCell
+{
+public:
+ TKCell(TKContainer *container, std::string location, std::string name, bool canInterface);
+ virtual ~TKCell();
+
+ void init();
+
+ std::string getName() const { return mName; }
+ std::string getLocation() const { return mLocation; }
+
+ float getAxonValue() const;
+ void setAxonValue(float value);
+
+ const TKReceptorMap* getReceptors() const { return &mReceptors; }
+
+ virtual bool setCellCode(TKCellCode *code, const void *data);
+
+ bool connectTo(std::string connectionName, TKCell *targetReceptor);
+ inline TKContainer* getContainer() const { return mContainer; }
+ bool isInterface() { return mCanInterface; }
+
+ virtual bool doTick(float time) = 0;
+ virtual bool doInit() = 0;
+ virtual bool doDestroy() = 0;
+
+protected:
+ virtual TKReceptor* createReceptor(std::string name);
+
+ std::string mName;
+ std::string mLocation;
+ TKContainer *mContainer;
+ TKAxon *mAxon;
+ TKReceptorMap mReceptors;
+ TKCellCodeInstance *mCellCodeInstance;
+ bool mCanInterface;
+
+};
+
+#endif
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#include "TKCellCode.h"
+#include "TKCell.h"
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/12/2011.
+//
+
+#ifndef __INCLUDE_TKCELLCODE__
+#define __INCLUDE_TKCELLCODE__
+
+#include <string>
+#include <vector>
+
+class TKReceptor;
+class TKContainer;
+class TKCell;
+class TKCellCodeInstance;
+
+class TKCellCode
+{
+public:
+ TKCellCode(std::string theName, std::string theCellAPIName) : mName(theName), mCellAPIName(theCellAPIName) {}
+ virtual ~TKCellCode() {}
+
+ std::string getName() const { return mName; }
+ std::string getCellAPIName() const { return mCellAPIName; }
+
+ virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data) = 0;
+
+private:
+ std::string mName;
+ std::string mCellAPIName;
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/21/2011.
+//
+
+#include "TKCellCodeInstance.h"
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/21/2011.
+//
+
+#ifndef __INCLUDE_TKCELLCODEINSTANCE__
+#define __INCLUDE_TKCELLCODEINSTANCE__
+
+class TKCell;
+
+class TKCellCodeInstance
+{
+public:
+ inline TKCell* getOwner() { return mOwner; }
+
+ TKCellCodeInstance(TKCell *owner) : mOwner(owner) {}
+ virtual ~TKCellCodeInstance() {}
+
+ virtual bool doTick(float time) = 0;
+ virtual bool doInit() = 0;
+ virtual bool doDestroy() = 0;
+
+
+
+private:
+ TKCell *mOwner;
+
+};
+
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/2/2012.
+//
+
+#ifndef dennco_TKConsole_h
+#define dennco_TKConsole_h
+
+#include <stdarg.h>
+#include "TKLog.h"
+
+class TKConsole
+{
+public:
+ virtual void vprintf(TKLog::MessageType type, const char *fmt, va_list arg);
+ virtual void vDebugPrintf(const char *fmt, va_list arg);
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#include "TKContainer.h"
+#include "TKCell.h"
+#include "TKCellCode.h"
+#include "DNStorage.h"
+#include "DNUtils.h"
+
+#include <string>
+
+const std::string TKContainer::CELLTYPE_JSBASIC = "B";
+const std::string TKContainer::CELLTYPE_OUT = "O";
+const std::string TKContainer::CELLTYPE_IN = "I";
+const std::string TKContainer::CELLTYPE_BASICSTORAGE = "BS";
+
+TKContainer::TKContainer() : mStorage(NULL), mEmptyCellClass(NULL)
+{
+}
+
+void TKContainer::init()
+{
+ mEmptyCellClass = addCellCode("_DNEMPTY",CELLTYPE_JSBASIC,"");
+}
+
+TKContainer::~TKContainer()
+{
+ doDestroy();
+ releaseDataStore();
+}
+
+bool TKContainer::doInit()
+{
+ mLock.lock();
+ for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
+ it->second->doInit();
+ }
+ mLock.unlock();
+ return true;
+}
+
+bool TKContainer::doTick(float time)
+{
+ mLock.lock();
+ for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
+ it->second->doTick(time);
+ }
+ mLock.unlock();
+ return true;
+}
+
+bool TKContainer::doDestroy()
+{
+ mLock.lock();
+
+ for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
+ (it->second)->doDestroy();
+ }
+ for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
+ delete it->second;
+ }
+ mCells.clear();
+ mInterfaceCells.clear();
+
+ mLock.unlock();
+ return true;
+}
+
+TKCell* TKContainer::addCell(std::string theLocation, std::string theName, std::string type, std::string customScript)
+{
+ TKCell *cell = NULL;
+ bool noScript = false;
+
+ if (type == CELLTYPE_JSBASIC || type.length() == 0)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else if (type == CELLTYPE_IN)
+ {
+ cell = cellFactory(theLocation, theName, type, true);
+ noScript = true;
+ }
+ else if (type == CELLTYPE_OUT)
+ {
+ cell = cellFactory(theLocation, theName, type, true);
+ noScript = true;
+ }
+ else if (type == CELLTYPE_BASICSTORAGE)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode requires type '").append(type).append("' but it's not a supported type.");
+ dnNotifyError("Initialization failed", message);
+ }
+
+ if (cell)
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
+ mCells.insert(TKCellMap::value_type(fqnName, cell));
+ if (cell->isInterface())
+ {
+ mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ }
+ if (!noScript)
+ {
+ cell->setCellCode(mEmptyCellClass,(const void*)customScript.c_str());
+ }
+ else
+ {
+ if (customScript.length()>0)
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode is type '").append(type).append("'. This type doesn't support custom script.");
+ dnNotifyError("Initialization failed",message);
+ }
+ }
+ }
+ else
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(),theName.c_str());
+ std::string message = "Failed to create a cell. ";
+ message += fqnName;
+ message += "\n";
+ message += "Out of memory?";
+ dnNotifyError("Initialization failed", message);
+ }
+
+ return cell;
+}
+
+TKCell* TKContainer::addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript)
+{
+ TKCell *cell = NULL;
+
+ std::string type = cellCode->getCellAPIName();
+
+ if (type == CELLTYPE_JSBASIC)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else if (type == CELLTYPE_BASICSTORAGE)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else if (type == CELLTYPE_OUT)
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode type '").append(type).append("' doesn't support to have a CellCode class.");
+ dnNotifyError("Initialization failed", message);
+ }
+ else if (type == CELLTYPE_IN)
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode requires type '").append(type).append("' doesn't support to have a CellCode class.");
+ dnNotifyError("Initialization failed", message);
+ }
+ else
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode requires type '").append(type).append("' but it's not a supported type.");
+ dnNotifyError("Initialization failed",message);
+ }
+
+
+ if (cell)
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
+ mCells.insert(TKCellMap::value_type(fqnName, cell));
+ cell->setCellCode(cellCode,(const void*)customScript.c_str());
+
+ if (cell->isInterface())
+ {
+ mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ }
+ }
+ else
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(),theName.c_str());
+ std::string message = "Failed to create a cell. ";
+ message += fqnName;
+ message += "\n";
+ message += "Out of memory?";
+ dnNotifyError("Initialization failed", message);
+ }
+
+ return cell;
+}
+
+TKCellCode* TKContainer::addCellCode(std::string theName, std::string theAPIType, std::string code)
+{
+ TKCellCode *cellCode = cellCodeFactory(theName, theAPIType, code);
+
+ if (cellCode)
+ {
+ mCellCodes.insert( std::map<std::string, TKCellCode*>::value_type(theName, cellCode));
+ }
+ return cellCode;
+}
+
+bool TKContainer::setDataStore(std::string storagePath)
+{
+ mStorage = new DNStorage(storagePath.c_str());
+ return mStorage->isValid();
+}
+
+bool TKContainer::releaseDataStore()
+{
+ mLock.lock();
+ if (mStorage)
+ {
+ delete mStorage;
+ mStorage = NULL;
+ }
+ mLock.unlock();
+ return true;
+}
+
+TKCell* TKContainer::getCell(std::string theFQNName)
+{
+ TKCellMap::iterator it = mCells.find(theFQNName);
+ if (it == mCells.end())
+ {
+ return NULL;
+ }
+ else
+ {
+ return it->second;
+ }
+}
+
+TKCell* TKContainer::getInterfaceCell(std::string theFQNName)
+{
+ DNLocker locker(&mLock);
+
+ if (mInterfaceCells.empty())
+ {
+ return NULL;
+ }
+ TKCellMap::iterator it = mInterfaceCells.find(theFQNName);
+ if (it == mInterfaceCells.end())
+ {
+ return NULL;
+ }
+ else
+ {
+ return it->second;
+ }
+}
+
+TKCellCode* TKContainer::getCellCode(std::string theCellCodeName)
+{
+ TKCellCodeMap::iterator it = mCellCodes.find(theCellCodeName);
+ if (it == mCellCodes.end())
+ {
+ return NULL;
+ }
+ else
+ {
+ return it->second;
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#ifndef __INCLUDE_TKCONTAINER__
+#define __INCLUDE_TKCONTAINER__
+
+#include "TKLock.h"
+
+#include <string>
+#include <map>
+
+class TKCell;
+class TKReceptor;
+class TKAxon;
+class TKAxonTerminal;
+class TKCellCode;
+class DNStorage;
+
+typedef std::map<std::string, TKCell*> TKCellMap;
+typedef std::map<std::string, TKCellCode*> TKCellCodeMap;
+
+class TKContainer
+{
+public:
+ static const std::string CELLTYPE_JSBASIC;
+ static const std::string CELLTYPE_OUT;
+ static const std::string CELLTYPE_IN;
+ static const std::string CELLTYPE_BASICSTORAGE;
+
+ static TKContainer* createContainer();
+ virtual void init();
+
+ virtual ~TKContainer();
+
+ const TKCellMap* getCells() { return &mCells; }
+ const TKCellCodeMap* getCellCodes() { return &mCellCodes; }
+
+ void setContentPath(std::string contentPath) { mContentPath = contentPath; }
+ std::string getContentPath() { return mContentPath; }
+ bool setDataStore(std::string storagePath);
+ DNStorage* getDataStore() { return mStorage; }
+ bool releaseDataStore();
+ TKCell* getCell(std::string theFQNName);
+ TKCell* getInterfaceCell(std::string theFQNName);
+ TKCellCode* getCellCode(std::string theCellCodeName);
+
+ bool doInit();
+ bool doTick(float time);
+ bool doDestroy();
+
+ virtual TKCell* addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
+ virtual TKCell* addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
+ virtual TKCellCode* addCellCode(std::string theName, std::string theAPIType, std::string code);
+
+ virtual void setValue(std::string key, float value) = 0;
+ inline virtual float getValue(std::string key) const = 0;
+
+ virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterface = true) = 0;
+ virtual TKAxon* axonFactory(TKCell *theOwner) = 0;
+ virtual TKReceptor* receptorFactory(TKCell *theOwner) = 0;
+ virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner) = 0;
+ virtual TKCellCode* cellCodeFactory(std::string name, std::string cellapi, std::string code) = 0;
+
+ virtual void beganParsePage(const char *docRoot, const char *path) {}
+ virtual void endedParsePage(const char *docRoot, const char *path) {}
+
+protected:
+ TKContainer();
+ TKCellMap mCells;
+ TKCellMap mInterfaceCells;
+ TKCellCodeMap mCellCodes;
+ std::string mContentPath;
+ DNStorage *mStorage;
+ TKCellCode *mEmptyCellClass;
+
+private:
+ TKLock mLock;
+};
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/23/2011.
+//
+
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/23/2011.
+//
+
+#ifndef __INCLUDE_TKDEBUG__
+#define __INCLUDE_TKDEBUG__
+
+#include "TKLog.h"
+
+#ifdef DEBUG
+//# define DEBUG_TRACE(fmt, ...) TKLog::printf("%s(%d)" fmt, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
+#define DEBUG_TRACE(fmt, ...) TKLog::debugPrintf(fmt,__VA_ARGS__)
+#else
+#define DEBUG_TRACE(...)
+#endif
+
+#ifdef DEBUG
+ #if defined(_MSC_VER)
+ #define TKASSERT(b) { if (!b) {TKLog::debugPrintf("ASSERT ERROR! %s(%d)",__FUNCTION__, __LINE__);/*TODO*/}}
+ #else
+ #define TKASSERT(b) { if (!b) {TKLog::debugPrintf("ASSERT ERROR! %s(%d)",__PRETTY_FUNCTION__, __LINE__);/*TODO*/}}
+ #endif
+#else
+ #define TKASSERT(b)
+#endif
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/19/2011.
+//
+
+#include "TKLock.h"
+#include "TKLockImpl.h"
+
+TKLock::TKLock()
+{
+ impl = TKLockImpl::create();
+}
+
+TKLock::~TKLock()
+{
+ if (impl)
+ delete impl;
+}
+
+void TKLock::lock()
+{
+ impl->lock();
+}
+
+void TKLock::unlock()
+{
+ impl->unlock();
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/19/2011.
+//
+
+#ifndef __INCLUDE_TKLOCK__
+#define __INCLUDE_TKLOCK__
+
+class TKLockImpl;
+
+class TKLock
+{
+public:
+ TKLock();
+ ~TKLock() ;
+ void lock();
+ void unlock();
+private:
+ TKLockImpl *impl;
+};
+
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/20/2011.
+//
+
+#ifndef __INCLUDE_TKLOCKIMPL__
+#define __INCLUDE_TKLOCKIMPL__
+
+class TKLockImpl
+{
+public:
+ static TKLockImpl* create();
+
+ TKLockImpl() {}
+ virtual ~TKLockImpl() {}
+ virtual void lock() = 0;
+ virtual void unlock() = 0;
+};
+
+
+
+
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/2/2012.
+//
+
+#include "TKConsole.h"
+#include "TKLog.h"
+
+#include <stdarg.h>
+
+TKConsole *TKLog::msConsole = 0;
+
+void TKLog::printf(MessageType type, const char* fmt,...)
+{
+ if (TKLog::msConsole)
+ {
+ va_list ap;
+ va_start(ap, fmt);
+ msConsole->vprintf(type, fmt, ap);
+ va_end(ap);
+ }
+}
+
+void TKLog::debugPrintf(const char* fmt,...)
+{
+ if (TKLog::msConsole)
+ {
+ va_list ap;
+ va_start(ap, fmt);
+ msConsole->vDebugPrintf(fmt, ap);
+ va_end(ap);
+ }
+}
+
+void TKLog::setDestination(TKConsole *console)
+{
+ TKLog::msConsole = console;
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/16/2011.
+//
+
+#ifndef __INCLUDE_TKLOG__
+#define __INCLUDE_TKLOG__
+
+class TKConsole;
+
+class TKLog
+{
+public:
+ enum MessageType {NORMAL, WARNING, ERROR};
+
+ static void printf(MessageType type, const char* fmt,...);
+ static void debugPrintf(const char* fmt,...);
+ static void setDestination(TKConsole *console);
+private:
+ static TKConsole *msConsole;
+};
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#include "TKAxonTerminal.h"
+#include "TKReceptor.h"
+#include "TKCell.h"
+#include "TKAxon.h"
+#include "TKLog.h"
+
+float TKReceptor::getValue()
+{
+#ifdef DEBUG_CONNECTION
+ TKLog::debugPrintf("TKReceptor::getValue called: owner:%s tarminal owner:%s value:%f\n",
+ mOwner->getName().c_str(),
+ mTerminal->getOwner()->getOwner()->getName().c_str(),
+ mTerminal->getValue());
+#endif
+ if (mTerminal)
+ {
+ return mTerminal->getValue();
+ }
+ return 0.0;
+}
+
+void TKReceptor::setTarget(TKAxonTerminal *theTerminal)
+{
+ if (mTerminal)
+ {
+ mTerminal->release(this);
+ }
+ mTerminal = theTerminal;
+ mTerminal->setTarget(this);
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 12/11/2011.
+//
+
+#ifndef __INCLUDE_TKRECEPTOR__
+#define __INCLUDE_TKRECEPTOR__
+
+class TKCell;
+class TKAxonTerminal;
+
+class TKReceptor
+{
+public:
+ TKReceptor(TKCell *theOwner) : mOwner(theOwner), mTerminal(0) {}
+ virtual ~TKReceptor() {}
+
+ void setTarget(TKAxonTerminal *theTerminal);
+ TKAxonTerminal* getTarget() const { return mTerminal; }
+ TKCell* getOwnerCell() const { return mOwner; }
+
+ float getValue();
+
+private:
+ TKCell *mOwner;
+ TKAxonTerminal *mTerminal;
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 2/27/2012.
+//
+
+#include "TKConsole.h"
+
+#include <QDebug>
+
+void TKConsole::vprintf(TKLog::MessageType type, const char *fmt, va_list ap)
+{
+ (type);
+ QString msg = QString().vsprintf(fmt,ap);
+ qDebug() << msg << endl;
+}
+
+void TKConsole::vDebugPrintf(const char *fmt, va_list ap)
+{
+#ifdef DEBUG
+ QString msg = QString().vsprintf(fmt,ap);
+ qDebug() << "DEBUG:" << msg << endl;
+#endif
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 3/24/2012.
+//
+#include "qtdnstorageimpl.h"
+
+#include "DNStorage.h"
+#include "DNStorageImpl.h"
+#include "TKLog.h"
+#include "DNUtils.h"
+
+#include <QtSql>
+#include <DNGlobal.h>
+
+//static
+DNStorageImpl* DNStorageImpl::create(const char *storagePath)
+{
+ return new QtDNStorageImpl(storagePath);
+}
+
+QtDNStorageImpl::~QtDNStorageImpl()
+{
+ if (mQueries)
+ {
+ delete mQueries;
+ mQueries = NULL;
+ }
+
+ if (mDatabase)
+ {
+ mDatabase->database.rollback();
+ QString connectionName = mDatabase->database.connectionName();
+ if (mDatabase->database.isValid() && mDatabase->database.isOpen())
+ {
+ mDatabase->database.close();
+ }
+
+ delete mDatabase;
+ QSqlDatabase::removeDatabase(connectionName);
+ mDatabase = NULL;
+ }
+}
+
+QtDNStorageImpl::QtDNStorageImpl(const char *storagePath) : mDatabase(NULL),mQueries(NULL)
+{
+ mStoragePath = QString::fromLocal8Bit(storagePath);
+ mIsValid = initDB();
+}
+
+bool QtDNStorageImpl::setValue(const char *path, const char *key, float value)
+{
+ if (!mIsValid)
+ return false;
+
+ QString qPath(path);
+ QString qKey(key);
+ mQueries->propertiesCountQuery.addBindValue(qPath);
+ mQueries->propertiesCountQuery.addBindValue(qKey);
+ if (!mQueries->propertiesCountQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->propertiesCountQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return false;
+ }
+ mQueries->propertiesCountQuery.next();
+ int cnt = mQueries->propertiesCountQuery.value(0).toInt();
+ if (cnt == 0)
+ {
+ mQueries->propertiesInsertQuery.addBindValue(qPath);
+ mQueries->propertiesInsertQuery.addBindValue(qKey);
+ mQueries->propertiesInsertQuery.addBindValue(value);
+ if (!mQueries->propertiesInsertQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->propertiesCountQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return false;
+ }
+ }
+ else
+ {
+ mQueries->propertiesUpdateQuery.addBindValue(value);
+ mQueries->propertiesUpdateQuery.addBindValue(qPath);
+ mQueries->propertiesUpdateQuery.addBindValue(qKey);
+ if (!mQueries->propertiesUpdateQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->propertiesCountQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+float QtDNStorageImpl::getValue(const char *path, const char *key)
+{
+ if (mQueries == NULL || !mIsValid)
+ return 0;
+
+ QString qPath(path);
+ QString qKey(key);
+ mQueries->propertiesGetQuery.addBindValue(qPath);
+ mQueries->propertiesGetQuery.addBindValue(qKey);
+ if (!mQueries->propertiesGetQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->propertiesCountQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return false;
+ }
+ mQueries->propertiesGetQuery.next();
+ return mQueries->propertiesGetQuery.value(0).toFloat();
+}
+
+int QtDNStorageImpl::getCount(const char *path, const char *key)
+{
+ if (!mIsValid)
+ return 0;
+
+ QString qPath(path);
+ QString qKey(key);
+ mQueries->propertiesCountQuery.addBindValue(qPath);
+ mQueries->propertiesCountQuery.addBindValue(qKey);
+ if (!mQueries->propertiesCountQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->propertiesCountQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return 0;
+ }
+
+ mQueries->propertiesCountQuery.next();
+ return mQueries->propertiesCountQuery.value(0).toInt();
+}
+
+
+int QtDNStorageImpl::countXYZVData(const char *path, const char *key)
+{
+ if (mQueries == NULL || !mIsValid)
+ return 0;
+ QString qPath(path);
+ QString qKey(key);
+ mQueries->xyzvDataCountQuery.addBindValue(qPath);
+ mQueries->xyzvDataCountQuery.addBindValue(qKey);
+ if (!mQueries->xyzvDataCountQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->xyzvDataCountQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return 0;
+ }
+
+ mQueries->xyzvDataCountQuery.next();
+ return mQueries->xyzvDataCountQuery.value(0).toInt();
+}
+
+bool QtDNStorageImpl::insertXYZVData(const char *path, const char *key, int index, float x, float y, float z, float v)
+{
+ if (mQueries == NULL || !mIsValid)
+ return 0;
+
+ QString qPath(path);
+ QString qKey(key);
+ mQueries->xyzvDataInsetQuery.addBindValue(qPath);
+ mQueries->xyzvDataInsetQuery.addBindValue(qKey);
+ mQueries->xyzvDataInsetQuery.addBindValue(index);
+
+ mQueries->xyzvDataInsetQuery.addBindValue(x);
+ mQueries->xyzvDataInsetQuery.addBindValue(y);
+ mQueries->xyzvDataInsetQuery.addBindValue(z);
+ mQueries->xyzvDataInsetQuery.addBindValue(v);
+ if (!mQueries->xyzvDataInsetQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->xyzvDataInsetQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return false;
+ }
+
+ return true;
+}
+
+DNStorageXYZVRecords* QtDNStorageImpl::queryXYZVData(const char *path, const char *key)
+{
+ if (mQueries == NULL || !mIsValid)
+ return 0;
+
+ QString qPath(path);
+ QString qKey(key);
+ mQueries->xyzvDataCountQuery.addBindValue(qPath);
+ mQueries->xyzvDataCountQuery.addBindValue(qKey);
+ if (!mQueries->xyzvDataCountQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->xyzvDataCountQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return 0;
+ }
+ mQueries->xyzvDataCountQuery.next();
+ int length = mQueries->xyzvDataCountQuery.value(0).toInt();
+ DNStorageXYZVRecords *records = new DNStorageXYZVRecords(length);
+ mQueries->xyzvDataGetQuery.addBindValue(qPath);
+ mQueries->xyzvDataGetQuery.addBindValue(qKey);
+ if (!mQueries->xyzvDataGetQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->xyzvDataGetQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ if (records)
+ delete records;
+ return 0;
+ }
+
+ int i = 0;
+ while(mQueries->xyzvDataGetQuery.next() && i < length)
+ {
+ records->data[i].index = mQueries->xyzvDataGetQuery.value(0).toInt();
+ records->data[i].x = mQueries->xyzvDataGetQuery.value(1).toFloat();
+ records->data[i].y = mQueries->xyzvDataGetQuery.value(2).toFloat();
+ records->data[i].z = mQueries->xyzvDataGetQuery.value(3).toFloat();
+ records->data[i].v = mQueries->xyzvDataGetQuery.value(4).toFloat();
+ i++;
+ }
+ records->length = i;
+
+ return records;
+}
+
+bool QtDNStorageImpl::deleteXYZVData(const char *path, const char *key)
+{
+ if (mQueries == NULL || !mIsValid)
+ return false;
+
+ QString qPath(path);
+ QString qKey(key);
+ mQueries->xyzvDataRemoveQuery.addBindValue(qPath);
+ mQueries->xyzvDataRemoveQuery.addBindValue(qKey);
+ if (!mQueries->xyzvDataRemoveQuery.exec())
+ {
+ std::string message = "SQL error while processing cell ";
+ message.append(path);
+ message.append(":");
+ message.append(key);
+ message.append("\n");
+ message.append(mQueries->xyzvDataRemoveQuery.lastError().text().toStdString());
+ dnNotifyWarning("SQL ERROR", message);
+ return false;
+ }
+ return true;
+}
+
+
+bool QtDNStorageImpl::flush()
+{
+ if (mDatabase == NULL || !mIsValid)
+ return false;
+
+ return mDatabase->database.commit();
+}
+
+bool QtDNStorageImpl::startTransaction()
+{
+ if (mDatabase == NULL || !mIsValid)
+ return false;
+
+ return mDatabase->database.transaction();
+}
+
+bool QtDNStorageImpl::commitTransaction()
+{
+ if (mDatabase == NULL || !mIsValid)
+ return false;
+
+ return mDatabase->database.commit();
+}
+
+bool QtDNStorageImpl::rollbackTransaction()
+{
+ if (mDatabase == NULL || !mIsValid)
+ return false;
+
+ return mDatabase->database.rollback();
+}
+
+bool QtDNStorageImpl::initDB()
+{
+ mDatabase = new QtDNDatabase;
+
+ mDatabase->database = QSqlDatabase::addDatabase("QSQLITE");
+ mDatabase->database.setDatabaseName(mStoragePath);
+
+ if (!mDatabase->database.open())
+ {
+ std::string message = "Failied to open storage file ";
+ message.append(mStoragePath.toStdString());
+ message.append("\n");
+ message.append(mDatabase->database.lastError().text().toStdString());
+ dnNotifyError("Persistent storage initialization error.", message);
+ return false;
+ }
+
+ QStringList tables = mDatabase->database.tables();
+ if (!tables.contains("properties"))
+ {
+ QSqlQuery q;
+
+ if (!q.exec("CREATE TABLE properties(cell TEXT, prokey TEXT, value REAL, PRIMARY KEY (cell, prokey))"))
+ {
+ std::string message = "Failied to create data table (properties) in ";
+ message.append(mStoragePath.toStdString());
+ message.append("\n");
+ message.append(mDatabase->database.lastError().text().toStdString());
+ dnNotifyError("Persistent storage initialization error.", message);
+ return false;
+ }
+ }
+
+ if (!tables.contains("xyzvdata"))
+ {
+ QSqlQuery q;
+
+ if (!q.exec("CREATE TABLE xyzvdata(cell TEXT, dskey TEXT, dsindex INTEGER, x REAL, y REAL, z REAL, v REAL, PRIMARY KEY (cell, dskey, dsindex))"))
+ {
+ std::string message = "Failied to create data table (dataset) in ";
+ message.append(mStoragePath.toStdString());
+ message.append("\n");
+ message.append(mDatabase->database.lastError().text().toStdString());
+ dnNotifyError("Persistent storage initialization error.", message);
+ return false;
+ }
+ }
+
+ mQueries = new QtDNDBQueries;
+
+ mQueries->propertiesCountQuery.prepare("SELECT count(*) FROM properties WHERE cell=? and prokey=?");
+ mQueries->propertiesInsertQuery.prepare("INSERT INTO properties VALUES(?,?,?)");
+ mQueries->propertiesUpdateQuery.prepare("UPDATE properties SET value=? WHERE cell=? and prokey=?");
+ mQueries->propertiesGetQuery.prepare("SELECT value FROM properties WHERE cell=? and prokey=?");
+
+ mQueries->xyzvDataInsetQuery.prepare("INSERT INTO xyzvdata VALUES (?,?,?, ?,?,?,?)");
+ mQueries->xyzvDataCountQuery.prepare("SELECT count(*) FROM xyzvdata WHERE cell=? and dskey=?");
+ mQueries->xyzvDataGetQuery.prepare("SELECT dsindex, x, y, z, v FROM xyzvdata WHERE cell=? and dskey=?");
+ mQueries->xyzvDataRemoveQuery.prepare("DELETE FROM xyzvdata WHERE cell=? and dskey=?");
+
+ if (mDatabase->database.lastError().type() != QSqlError::NoError)
+ {
+ std::string message = "Failied to prepare database ";
+ message.append(mStoragePath.toStdString());
+ message.append("\n");
+ message.append(mDatabase->database.lastError().text().toStdString());
+ dnNotifyError("Persistent storage initialization error.", message);
+ return false;
+ }
+
+ return true;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 3/24/2012.
+//
+#ifndef QTDNSTORAGEIMPL_H
+#define QTDNSTORAGEIMPL_H
+
+#include "DNStorageImpl.h"
+
+#include <QString>
+#include <QtSql>
+
+class QtDNDatabase
+{
+public:
+ QSqlDatabase database;
+};
+
+class QtDNDBQueries
+{
+public:
+ QSqlQuery propertiesCountQuery;
+ QSqlQuery propertiesInsertQuery;
+ QSqlQuery propertiesUpdateQuery;
+ QSqlQuery propertiesGetQuery;
+
+ QSqlQuery xyzvDataInsetQuery;
+ QSqlQuery xyzvDataRemoveQuery;
+ QSqlQuery xyzvDataCountQuery;
+ QSqlQuery xyzvDataGetQuery;
+};
+
+class QtDNStorageImpl : public DNStorageImpl
+{
+public:
+ QtDNStorageImpl(const char *storagePath);
+ virtual ~QtDNStorageImpl();
+
+ virtual bool setValue(const char *path, const char *key, float value);
+ virtual float getValue(const char *path, const char *key);
+ virtual int getCount(const char *path, const char *key);
+
+ virtual int countXYZVData(const char *path, const char *key);
+ virtual bool insertXYZVData(const char *path, const char *key, int index, float x, float y, float z, float v);
+ virtual DNStorageXYZVRecords* queryXYZVData(const char *path, const char *key);
+ virtual bool deleteXYZVData(const char *path, const char *key);
+
+ virtual bool flush();
+
+ virtual bool isValid() { return mIsValid; }
+
+ virtual bool startTransaction();
+ virtual bool commitTransaction();
+ virtual bool rollbackTransaction();
+
+private:
+ bool initDB();
+ bool mIsValid;
+ QString mStoragePath;
+
+ QtDNDatabase *mDatabase;
+ QtDNDBQueries *mQueries;
+};
+
+#endif // QTDNSTORAGEIMPL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
+#include "qttklockimpl.h"
+
+TKLockImpl *TKLockImpl::create()
+{
+ return new QtTKLockImpl;
+}
+
+QtTKLockImpl::QtTKLockImpl()
+{
+}
+
+ QtTKLockImpl::~QtTKLockImpl()
+ {
+ }
+
+ void QtTKLockImpl::lock()
+ {
+ mLock.lock();
+ }
+
+ void QtTKLockImpl::unlock()
+ {
+ mLock.unlock();
+ }
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
+#ifndef QTTKLOCKIMPL_H
+#define QTTKLOCKIMPL_H
+
+#include "TKLockImpl.h"
+
+#include <QMutex>
+
+class QtTKLockImpl : public TKLockImpl
+{
+public:
+ QtTKLockImpl();
+ virtual ~QtTKLockImpl() ;
+ virtual void lock();
+ virtual void unlock();
+
+ QMutex mLock;
+};
+
+#endif // QTTKLOCKIMPL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/6/2012.
+//
+#include "DNContainerBuilder.h"
+
+#include "TKLock.h"
+#include "TKContainer.h"
+#include "DNUtils.h"
+#include "DNDirectory.h"
+#include "DNFileList.h"
+#include "DNXML.h"
+#include "DNXMLElement.h"
+#include "TKLog.h"
+#include "DNUtils.h"
+#include "TKCell.h"
+#include "TKDebug.h"
+#include "DNGlobal.h"
+
+DNContainerBuilder::DNContainerBuilder(TKContainer *container) : mContainer(container)
+{
+
+}
+
+DNContainerBuilder::~DNContainerBuilder()
+{
+
+}
+
+bool DNContainerBuilder::buildContainerFromXHTML(const char* docRoot)
+{
+ mLock.lock();
+
+ mContainer->setContentPath(std::string(docRoot));
+
+ DNDirectory directory(docRoot);
+ const DNFileList *flist = directory.getFileList("html|htm|xml|xhtml");
+
+ //parse XHTML files
+ while(flist)
+ {
+ std::string p = flist->getFilePath();
+ parseXHTML(docRoot, p.c_str());
+
+ flist = flist->next;
+ }
+
+ //build cells
+ while(!mPendingCellDefinitions.empty())
+ {
+ PendingCellDefinition *cellInfo = mPendingCellDefinitions.front();
+ TKCell *newCell = NULL;
+ if (cellInfo->useCellCodeClass)
+ {
+ TKCellCode *cellCode = mContainer->getCellCode(cellInfo->cellCodeClassOrType);
+ if (cellCode)
+ {
+ newCell = mContainer->addCell(cellInfo->location, cellInfo->cellName, cellCode, cellInfo->customScript);
+ }
+ else
+ {
+ std::string message = std::string("Failed to construct cell: ").append(cellInfo->location).append("#").append(cellInfo->cellName);
+ message.append("\nCellCode '").append(cellInfo->cellCodeClassOrType).append("' couldn't be found.");
+ dnNotifyError("Initialization failed", message);
+ }
+ }
+ else
+ {
+ newCell = mContainer->addCell(cellInfo->location, cellInfo->cellName, cellInfo->cellCodeClassOrType, cellInfo->customScript);
+ }
+
+ if (newCell == NULL)
+ {
+ std::string message = std::string("Failed to construct cell: ").append(cellInfo->location).append("#").append(cellInfo->cellName);
+ dnNotifyError("Initialization failed", message);
+ }
+ mPendingCellDefinitions.pop();
+ }
+
+ //build connections
+ while(!mPendingConnections.empty())
+ {
+ PendingCellConnection *connInfo = mPendingConnections.front();
+ TKCell *orgCell = mContainer->getCell(connInfo->originCellName);
+ TKCell *tgtCell = mContainer->getCell(connInfo->targetCellName);
+
+ if (orgCell && tgtCell)
+ {
+ if (!orgCell->connectTo(connInfo->connectionName, tgtCell))
+ {
+ std::string message = std::string("Failed to make connection. Receptor name for the target cell may be duplicated. (").append(connInfo->connectionName).append(") cell:").append(connInfo->originCellName).append(" - > ").append(connInfo->targetCellName);
+ dnNotifyError("Initialization failed", message);
+ }
+ }
+ else
+ {
+ std::string message = std::string("Failed to make connection (").append(connInfo->connectionName).append(") cell:").append(connInfo->originCellName).append(" - > ").append(connInfo->targetCellName);
+ dnNotifyError("Initialization failed", message);
+ }
+ mPendingConnections.pop();
+ }
+ mLock.unlock();
+
+ return dnGlobal()->isErrorStatusNormal();
+}
+
+void DNContainerBuilder::defineCellWithoutCellCodeClass(const char *path, std::string name, std::string type, std::string customScript)
+{
+ DEBUG_TRACE("\n===== Define cell (no CellCode class) ================ \nName:%s/%s\nType:%s\nCustom script:\n%s\n", path,name.c_str(), type.c_str(),customScript.c_str());
+
+ PendingCellDefinition *newCellDefine = new PendingCellDefinition();
+ newCellDefine->useCellCodeClass = false;
+ newCellDefine->location = path;
+ newCellDefine->cellName = name;
+ newCellDefine->cellCodeClassOrType = type;
+ newCellDefine->customScript = customScript;
+
+ mPendingCellDefinitions.push(newCellDefine);
+}
+
+void DNContainerBuilder::defineCellWithCellCodeClass(const char *path, std::string name, std::string cellcode, std::string customScript)
+{
+ DEBUG_TRACE("\n===== Define cell (CellCode class attached)=========== \nName:%s/%s\nClass:%s\nCustom script:\n%s\n", path,name.c_str(), cellcode.c_str(),customScript.c_str());
+
+ PendingCellDefinition *newCellDefine = new PendingCellDefinition();
+ newCellDefine->useCellCodeClass = true;
+ newCellDefine->location = path;
+ newCellDefine->cellName = name;
+ newCellDefine->cellCodeClassOrType = getFQNString(path, cellcode.c_str());
+ newCellDefine->customScript = customScript;
+
+ mPendingCellDefinitions.push(newCellDefine);
+}
+
+void DNContainerBuilder::defineCellCodeClass(const char *path, std::string name, std::string type, std::string cellScript)
+{
+ std::string fqnName = getFQNString(path, name.c_str());
+
+ DEBUG_TRACE("\n===== Define cell code class ===== \nClass:%s\nAPI:%s\n%s\n", fqnName.c_str(), type.c_str(), cellScript.c_str());
+
+ mContainer->addCellCode(fqnName, type, cellScript);
+}
+
+void DNContainerBuilder::defineConnection(const char *path, std::string origine, std::string destination, std::string name)
+{
+ PendingCellConnection *newConnection = new PendingCellConnection();
+ newConnection->connectionName = name;
+ newConnection->originCellName = getFQNString(path, origine.c_str());
+ newConnection->targetCellName = getFQNString(path, destination.c_str());
+ mPendingConnections.push(newConnection);
+}
+
+void DNContainerBuilder::parseXHTML(const char *docRoot, const char *path)
+{
+ mContainer->beganParsePage(docRoot, path);
+ DNXML *xml = DNXML::createXMLFromFile(docRoot, path);
+ DNXMLElement *element = xml->getRoot();
+
+ std::string cellName;
+ std::string cellCodeClassName;
+ std::string cellAPIType;
+ std::string script;
+
+ int defineDepth = -1;
+
+ while(element)
+ {
+ std::string define = element->getAttributeValue("define");
+ if (define.length() > 0)
+ {
+ if (defineDepth > 0)
+ {
+ std::string message = std::string("Syntax error while parsing ").append(path).append(". A defnie element seems to be nested.");
+ dnNotifyError("Initialization failed", message);
+ }
+ else
+ {
+ if (define == "cell")
+ {
+ cellName = element->getAttributeValue("name");
+ defineDepth = element->depth;
+ }
+ else if (define == "cellcode")
+ {
+ cellCodeClassName = element->getAttributeValue("name");
+ cellAPIType = element->getAttributeValue("type");
+ defineDepth = element->depth;
+ }
+ else
+ {
+ std::string message = std::string("Syntax error while parsing ").append(path).append(". defnie='").append("' isn't correct.");
+ dnNotifyError("Initialization failed", message);
+ }
+ }
+ }
+
+ std::string parameter = element->getAttributeValue("parameter");
+ if (parameter.length() > 0)
+ {
+ if (parameter == "script")
+ {
+ script = element->text;
+ }
+ else if (parameter == "cellcode")
+ {
+ cellCodeClassName = element->getAttributeValue("href");
+ cellAPIType = element->getAttributeValue("type");
+ if (cellCodeClassName.length() > 0 && cellAPIType.length() > 0)
+ {
+ std::string message = std::string("Syntax error while parsing ").append(path).append(". CellCode:").append(cellName);
+ message.append("\n'type' can't be defined here if you use CellCode class.");
+ dnNotifyError("Initialization failed", message);
+ }
+ }
+ else if (parameter== "connection")
+ {
+ std::string target = element->getAttributeValue("href");
+ std::string rname = element->getAttributeValue("receptor");
+ if (rname.length()==0)
+ {
+ rname = cellName;
+ }
+ defineConnection(path, cellName, target, rname);
+ }
+ else
+ {
+ std::string message = std::string("Syntax error while parsing ").append(path).append(". parameter='").append(parameter).append("' isn't correct.");
+ dnNotifyError("Initialization failed", message);
+ }
+ }
+
+ //go to next element
+ //
+ if (element->inner)
+ {
+ // go inside
+ element = element->inner;
+ }
+ else
+ {
+ // go next
+ do {
+ if (!element->next)
+ {
+ element = element->outer;
+ }
+ } while(element && element->next == NULL && element != xml->getRoot());
+
+ if (!element)
+ break;
+ element = element->next;
+
+ if (defineDepth >= 0 && (element == NULL || element->depth <= defineDepth))
+ {
+ defineDepth = -1;
+ if (cellName.length()>0)
+ {
+ if (cellCodeClassName.length()>0)
+ {
+ defineCellWithCellCodeClass(path, cellName, cellCodeClassName, script);
+ }
+ else
+ {
+ if (cellAPIType.length() > 0)
+ {
+ defineCellWithoutCellCodeClass(path, cellName, cellAPIType, script);
+ }
+ else
+ {
+ std::string message = std::string("Syntax error while parsing ").append(path).append(". cellName:'").append(cellName).append("'\nFaield to determin the cellcode.\nThe cellcode isn't defined for the cell?");
+ dnNotifyError("Initialization failed", message);
+ }
+ }
+
+ cellName = "";
+ cellCodeClassName = "";
+ cellAPIType = "";
+ script = "";
+ }
+ else
+ {
+ defineCellCodeClass(path, cellCodeClassName, cellAPIType, script);
+ cellCodeClassName = "";
+ cellAPIType = "";
+ script = "";
+ }
+ }
+ }
+ }
+ if (xml)
+ delete xml;
+
+ mContainer->endedParsePage(docRoot, path);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/6/2012.
+//
+
+#ifndef dennco_TKContainerBuilder_h
+#define dennco_TKContainerBuilder_h
+
+#include <queue>
+#include <string>
+#include "TKLock.h"
+
+class TKContainer;
+
+class DNContainerBuilder
+{
+public:
+ DNContainerBuilder(TKContainer *container);
+ ~DNContainerBuilder();
+
+ bool buildContainerFromXHTML(const char* docRoot);
+
+private:
+ void parseXHTML(const char* docRoot, const char *fpath);
+ TKLock mLock;
+ TKContainer *mContainer;
+
+ void defineCellWithoutCellCodeClass(const char *path, std::string name, std::string type, std::string customScript);
+ void defineCellWithCellCodeClass(const char *path, std::string name, std::string cellcode, std::string customScript);
+ void defineCellCodeClass(const char *path, std::string name, std::string type, std::string cellScript);
+ void defineConnection(const char *path, std::string origine, std::string destination, std::string name);
+
+ class PendingCellDefinition
+ {
+ public:
+ bool useCellCodeClass;
+ std::string location;
+ std::string cellName;
+ std::string cellCodeClassOrType;
+ std::string customScript;
+ };
+
+ class PendingCellConnection
+ {
+ public:
+ std::string connectionName;
+ std::string originCellName;
+ std::string targetCellName;
+ };
+
+ std::queue<PendingCellConnection*> mPendingConnections;
+ std::queue<PendingCellDefinition*> mPendingCellDefinitions;
+
+
+};
+
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#include "DNDirectoryImpl.h"
+#include "DNDirectory.h"
+
+DNDirectory::DNDirectory(const char *dir)
+{
+ impl = DNDirectoryImpl::create(dir);
+}
+
+DNDirectory::~DNDirectory()
+{
+ if (impl)
+ delete impl;
+}
+
+const DNFileList* DNDirectory::getFileList(const char *filter)
+{
+ return impl->getFileList(filter);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#ifndef dennco_DNDirectory_h
+#define dennco_DNDirectory_h
+
+class DNDirectoryImpl;
+class DNFileList;
+
+class DNDirectory
+{
+public:
+ DNDirectory(const char *dir);
+ ~DNDirectory();
+
+ const DNFileList* getFileList(const char *filter);
+
+private:
+ DNDirectoryImpl *impl;
+};
+
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#ifndef dennco_DNDirectoryImpl_h
+#define dennco_DNDirectoryImpl_h
+
+class DNFileList;
+
+class DNDirectoryImpl
+{
+public:
+ static DNDirectoryImpl* create(const char *dir);
+
+ virtual const DNFileList* getFileList(const char *filter) = 0;
+
+ virtual ~DNDirectoryImpl() {}
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#include "DNFileList.h"
+
+DNFileList::DNFileList(std::string f) : next(NULL),prev(NULL)
+{
+ filePath = f;
+}
+
+DNFileList::~DNFileList()
+{
+ if (prev)
+ {
+ prev->next = next;
+ }
+ if (next)
+ next->prev = prev;
+
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#ifndef dennco_DNFileList_h
+#define dennco_DNFileList_h
+
+#include <string>
+
+class DNFileList
+{
+public:
+ DNFileList(std::string f);
+
+ ~DNFileList();
+
+ DNFileList *next;
+ DNFileList *prev;
+ std::string getFilePath() const { return filePath; }
+
+private:
+ std::string filePath;
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#include "DNXMLImpl.h"
+#include "DNXML.h"
+
+//static
+DNXML* DNXML::createXMLFromFile(const char *docRoot, const char *path)
+{
+ DNXMLImpl *impl = DNXMLImpl::createXMLFromFileImpl(docRoot, path);
+ if (impl)
+ {
+ return new DNXML(impl);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+DNXML::~DNXML()
+{
+ if (impl)
+ {
+ delete impl;
+ }
+}
+
+DNXMLElement* DNXML::getRoot()
+{
+ return impl->getRoot();
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#ifndef dennco_DNXML_h
+#define dennco_DNXML_h
+
+class DNXMLImpl;
+class DNXMLElement;
+
+class DNXML
+{
+public:
+ static DNXML* createXMLFromFile(const char *docRoot, const char *path);
+
+ virtual ~DNXML();
+
+ DNXMLElement* getRoot();
+
+private:
+ DNXMLImpl *impl;
+ DNXML(DNXMLImpl *i) : impl(i) {}
+
+
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#include "DNXMLElement.h"
+
+DNXMLElement::DNXMLElement(std::string _name):
+outer(NULL),inner(NULL),next(NULL),depth(0),name(_name),text("")
+{
+}
+
+DNXMLElement::~DNXMLElement()
+{
+ DNXMLElement *e = inner;
+ while (e && e != this && depth <= e->depth)
+ {
+ while(e->inner) e = e->inner;
+ if (e->outer)
+ e->outer->inner = e->next;
+ DNXMLElement *ne = e->next ? e->next : e->outer;
+ delete e;
+ e = ne;
+ }
+ mAttributes.clear();
+}
+
+void DNXMLElement::setAttribute(const char *name, const char *value)
+{
+ std::string _key = name;
+ std::string _value = value;
+ mAttributes.insert(std::map<std::string, std::string>::value_type( _key, _value));
+}
+
+void DNXMLElement::setAttribute(std::string name, std::string value)
+{
+ mAttributes.insert(std::map<std::string, std::string>::value_type( name, value));
+}
+
+std::string DNXMLElement::getAttributeValue(const char *name)
+{
+ std::string key = name;
+ std::map<std::string, std::string>::iterator it = mAttributes.find(key);
+ if (it != mAttributes.end())
+ {
+ return it->second;
+ }
+ else
+ {
+ return "";
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#ifndef dennco_DNXMLElement_h
+#define dennco_DNXMLElement_h
+
+#include <string>
+#include <map>
+
+class DNXMLElement
+{
+public:
+ DNXMLElement(std::string _name);
+ ~DNXMLElement();
+ void setAttribute(const char *name, const char *value);
+ void setAttribute(std::string name, std::string value);
+
+ std::string getAttributeValue(const char *name);
+ DNXMLElement *outer;
+ DNXMLElement *inner;
+ DNXMLElement *next;
+
+ int depth;
+ std::string name;
+ std::string text;
+private:
+ std::map<std::string, std::string> mAttributes;
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 1/7/2012.
+//
+
+#ifndef dennco_DNXMLImpl_h
+#define dennco_DNXMLImpl_h
+
+class DNXML;
+class DNXMLElement;
+
+class DNXMLImpl
+{
+public:
+ static DNXMLImpl* createXMLFromFileImpl(const char *docRoot, const char *path);
+
+ virtual DNXMLElement* getRoot() = 0;
+ virtual ~DNXMLImpl() {}
+};
+
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
+#include "qtdndirectoryimpl.h"
+
+#include <QDirIterator>
+
+DNDirectoryImpl *DNDirectoryImpl::create(const char *dir)
+{
+ return new QtDNDirectoryImpl(dir);
+}
+
+QtDNDirectoryImpl::QtDNDirectoryImpl(const char *dir) : mFileList(0)
+{
+ mRootDir = QString::fromLocal8Bit(dir);
+}
+
+QtDNDirectoryImpl::~QtDNDirectoryImpl()
+{
+ cleanFileList();
+}
+const DNFileList* QtDNDirectoryImpl::getFileList(const char *filter)
+{
+ cleanFileList();
+
+ QStringList filters;
+ QString filterString = QString::fromLocal8Bit(filter);
+ if (filterString.length()>0)
+ {
+ int idx = 0;
+ while( (idx = filterString.indexOf("|")) != -1 )
+ {
+ QString pre("*.");
+ filters << pre.append(filterString.left(idx));
+ filterString = filterString.right(filterString.length()-idx-1);
+ }
+ QString pre("*.");
+ filters << pre.append(filterString);
+ }
+
+ QDir rootDir(mRootDir);
+ QDirIterator dirIterator(mRootDir, filters, QDir::Files, QDirIterator::Subdirectories);
+
+ mFileList = 0;
+ DNFileList *prev = 0;
+ while(dirIterator.hasNext())
+ {
+ dirIterator.next();
+ std::string filePath = "/";
+ filePath.append(rootDir.relativeFilePath(dirIterator.filePath()).toStdString());
+ DNFileList *dnfile = new DNFileList(filePath);
+ if (prev)
+ {
+ prev->next = dnfile;
+ dnfile->prev = prev;
+ prev = dnfile;
+ }
+ else
+ {
+ mFileList = dnfile;
+ prev = dnfile;
+ }
+ }
+
+ return mFileList;
+}
+void QtDNDirectoryImpl::cleanFileList()
+{
+ DNFileList *file = mFileList;
+ mFileList = 0;
+ while(file)
+ {
+ DNFileList *next = file->next;
+ if (next) next->prev = 0;
+ delete file;
+ file = next;
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
+#ifndef QTDNDIRECTORYIMPL_H
+#define QTDNDIRECTORYIMPL_H
+
+#include "DNDirectoryImpl.h"
+#include "DNFileList.h"
+
+#include <QString>
+
+class QtDNDirectoryImpl : public DNDirectoryImpl
+{
+public:
+ virtual const DNFileList* getFileList(const char *filter);
+
+ QtDNDirectoryImpl(const char *dir);
+ virtual ~QtDNDirectoryImpl();
+
+private:
+ QString mRootDir;
+ DNFileList *mFileList;
+
+ void cleanFileList();
+};
+
+#endif // QTDNDIRECTORYIMPL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
+#include "qtdnxmlimpl.h"
+
+#include "DNXMLElement.h"
+#include "TKLog.h"
+#include "DNGlobal.h"
+#include "DNUtils.h"
+
+DNXMLImpl *DNXMLImpl::createXMLFromFileImpl(const char *docRoot, const char *docPath)
+{
+ QString qDocRoot = QString::fromLocal8Bit(docRoot);
+ QString qDocPath = QString::fromLocal8Bit(docPath);
+
+ if (qDocRoot.lastIndexOf("/") != qDocRoot.length()-1 && qDocPath.at(0) != QChar('/'))
+ {
+ qDocRoot.append("/");
+ }
+ QString filePath = qDocRoot;
+ filePath.append(qDocPath);
+
+ return new QtDNXMLImpl(filePath);
+}
+
+QtDNXMLImpl::QtDNXMLImpl(QString filePath) : mHandler(NULL), mValid(false), mFilePath(filePath)
+{
+ QFile file(filePath);
+ if (file.open(QFile::ReadOnly | QFile::Text)) {
+ QXmlInputSource xmlInputSource(&file);
+ mHandler = new QtXMLHandler(filePath);
+ QXmlSimpleReader reader;
+ reader.setContentHandler(mHandler);
+ reader.setErrorHandler(mHandler);
+
+ mValid = reader.parse(xmlInputSource);
+ }
+
+ if (!mValid)
+ {
+ std::string message = "failed to load file:";
+ message.append(filePath.toStdString());
+ dnNotifyError("Error at loading XML file", message);
+ }
+}
+
+QtDNXMLImpl::~QtDNXMLImpl()
+{
+ if (mHandler)
+ delete mHandler;
+}
+
+DNXMLElement* QtDNXMLImpl::getRoot()
+{
+ if (mHandler && mValid)
+ {
+ return mHandler->getRoot();
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+QtXMLHandler::QtXMLHandler(QString filePath) : mRootElement(NULL), mCurrentElement(NULL), mFilePath(filePath)
+{
+}
+
+QtXMLHandler::~QtXMLHandler()
+{
+ if (mRootElement)
+ {
+ delete mRootElement;
+ }
+}
+
+//QXML handler implementation
+bool QtXMLHandler::startDocument()
+{
+ return true;
+}
+
+bool QtXMLHandler::endDocument()
+{
+ return true;
+}
+
+bool QtXMLHandler::startElement(const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts )
+{
+ if (mRootElement == NULL)
+ {
+ mRootElement = new DNXMLElement(qName.toStdString());
+ mCurrentElement = mRootElement;
+ }
+ else
+ {
+ if (!mCurrentElement->inner)
+ {
+ DNXMLElement *outer = mCurrentElement;
+ mCurrentElement->inner = new DNXMLElement(qName.toStdString());
+ mCurrentElement = mCurrentElement->inner;
+ mCurrentElement->outer = outer;
+ mCurrentElement->depth = outer->depth + 1;
+ }
+ else
+ {
+ DNXMLElement *prev = mCurrentElement->inner;
+ while(prev->next) prev = prev->next;
+ prev->next = new DNXMLElement(qName.toStdString());
+ mCurrentElement = prev->next;
+ mCurrentElement->outer = prev->outer;
+ mCurrentElement->depth = prev->depth;
+ }
+ }
+
+ if (mCurrentElement)
+ {
+ for(int i = 0; i < atts.count(); i++)
+ {
+ QString qname = atts.qName(i);
+ QString value = atts.value(i);
+ mCurrentElement->setAttribute(qname.toStdString(), value.toStdString());
+ }
+
+ }
+ return true;
+}
+
+bool QtXMLHandler::endElement (const QString & namespaceURI, const QString & localName, const QString & qName )
+{
+ mCurrentElement = mCurrentElement->outer;
+ return true;
+}
+
+bool QtXMLHandler::characters (const QString & ch )
+{
+ mCurrentElement->text.append(ch.toStdString());
+ return true;
+}
+
+bool QtXMLHandler::error (const QXmlParseException & exception )
+{
+ std::string message = exception.message().toStdString();
+ TKLog::printf(TKLog::WARNING, "Error while reading XML file!! \n%s", message.c_str());
+ return true;
+}
+
+bool QtXMLHandler::fatalError(const QXmlParseException & exception )
+{
+ QString message = QString().sprintf("ERROR while reading XML file!! file.%s (line:%d) \nReason:%s",
+ mFilePath.toLocal8Bit().data(), exception.lineNumber(), exception.message().toLocal8Bit().data());
+ dnNotifyError("Error at loading XML file", message.toStdString());
+ return true;
+}
+
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on 2/25/2012.
+//
+#ifndef QTDNXMLIMPL_H
+#define QTDNXMLIMPL_H
+
+#include "DNXMLImpl.h"
+#include <QXmlDefaultHandler>
+
+class QtXMLHandler : public QXmlDefaultHandler
+{
+public:
+ QtXMLHandler(QString filePath);
+ virtual ~QtXMLHandler();
+
+ DNXMLElement *getRoot() { return mRootElement; }
+
+ //QXML handler implementation
+ virtual bool startDocument();
+ virtual bool endDocument();
+ virtual bool startElement(const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts );
+ virtual bool endElement (const QString & namespaceURI, const QString & localName, const QString & qName );
+ virtual bool characters (const QString & ch );
+ virtual bool error (const QXmlParseException & exception );
+ virtual bool fatalError(const QXmlParseException & exception );
+
+private:
+ DNXMLElement *mRootElement;
+ DNXMLElement *mCurrentElement;
+ QString mFilePath;
+
+};
+
+class QtDNXMLImpl : public DNXMLImpl
+{
+public:
+ QtDNXMLImpl(QString filePath);
+ virtual ~QtDNXMLImpl();
+ virtual DNXMLElement *getRoot();
+
+private:
+ QtXMLHandler *mHandler;
+ bool mValid;
+ QString mFilePath;
+};
+
+
+#endif // QTDNXMLIMPL_H
--- /dev/null
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "TKLog.h"
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include "dccreator.h"
+#include "dcglvisualizerwidget.h"
+#include "dctreeviewwidget.h"
+#include "TKConsole.h"
+#include "utils/dcresources.h"
+
+#include <QCloseEvent>
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QSettings>
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+
+ DCResources::initResources();
+
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+
+ readSettings();
+
+ TKLog::setDestination(new TKConsole);
+
+ mCreator = new DCCreator(this);
+ mVisualizerWidget = new DCGLVisualizerWidget(mCreator, this) ;
+ setCentralWidget(mVisualizerWidget);
+
+ mTreeViewWidget = new DCTreeViewWidget(this, mCreator);
+ ui->treeViewDock->layout()->addWidget(mTreeViewWidget);
+
+ setCurrentContent("");
+ setUnifiedTitleAndToolBarOnMac(true);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+ if (mCreator)
+ delete mCreator;
+}
+
+
+//! [3]
+void MainWindow::closeEvent(QCloseEvent *event)
+//! [3] //! [4]
+{
+ if (maybeSave()) {
+ writeSettings();
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+//! [4]
+
+//! [5]
+void MainWindow::newFile()
+//! [5] //! [6]
+{
+ if (maybeSave()) {
+// textEdit->clear();
+ setCurrentContent("");
+ }
+}
+//! [6]
+
+//! [7]
+void MainWindow::open()
+//! [7] //! [8]
+{
+ if (maybeSave()) {
+ QString dirName = QFileDialog::getExistingDirectory(this);
+ if (!dirName.isEmpty())
+ loadContent(dirName);
+ }
+}
+//! [8]
+
+//! [9]
+bool MainWindow::save()
+//! [9] //! [10]
+{
+ if (curContent.isEmpty()) {
+ return saveAs();
+ } else {
+ return saveContent(curContent);
+ }
+}
+//! [10]
+
+//! [11]
+bool MainWindow::saveAs()
+//! [11] //! [12]
+{
+ QString dirName = QFileDialog::getSaveFileName(this);
+ if (dirName.isEmpty())
+ return false;
+
+ return saveContent(dirName);
+}
+//! [12]
+
+//! [13]
+void MainWindow::about()
+//! [13] //! [14]
+{
+ QMessageBox::about(this, tr("About Application"),
+ tr("TODO: exampalin\81@about <b>dennco creator</b> "
+ "TODO: exampalin\81@about <b>dennco creator</b> "
+ "TODO: exampalin\81@about <b>dennco creator</b>"));
+}
+//! [14]
+
+//! [15]
+void MainWindow::documentWasModified()
+//! [15] //! [16]
+{
+// setWindowModified(textEdit->document()->isModified());
+}
+//! [16]
+
+//! [17]
+void MainWindow::createActions()
+//! [17] //! [18]
+{
+ newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
+ newAct->setShortcuts(QKeySequence::New);
+ newAct->setStatusTip(tr("Create a new file"));
+ connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
+
+//! [19]
+ openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ openAct->setStatusTip(tr("Open an existing file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+//! [18] //! [19]
+
+ saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("Save the document to disk"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ saveAsAct = new QAction(tr("Save &As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ saveAsAct->setStatusTip(tr("Save the document under a new name"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+//! [20]
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+//! [20]
+ exitAct->setStatusTip(tr("Exit the application"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+//! [21]
+ cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);
+//! [21]
+ cutAct->setShortcuts(QKeySequence::Cut);
+ cutAct->setStatusTip(tr("Cut the current selection's contents to the "
+ "clipboard"));
+// connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut()));
+
+ copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this);
+ copyAct->setShortcuts(QKeySequence::Copy);
+ copyAct->setStatusTip(tr("Copy the current selection's contents to the "
+ "clipboard"));
+// connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy()));
+
+ pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
+ pasteAct->setShortcuts(QKeySequence::Paste);
+ pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
+ "selection"));
+// connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ cutAct->setEnabled(false);
+//! [23] //! [24]
+ copyAct->setEnabled(false);
+// connect(textEdit, SIGNAL(copyAvailable(bool)),
+// cutAct, SLOT(setEnabled(bool)));
+// connect(textEdit, SIGNAL(copyAvailable(bool)),
+// copyAct, SLOT(setEnabled(bool)));
+}
+//! [24]
+
+//! [25] //! [26]
+void MainWindow::createMenus()
+//! [25] //! [27]
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(newAct);
+//! [28]
+ fileMenu->addAction(openAct);
+//! [28]
+ fileMenu->addAction(saveAct);
+//! [26]
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(cutAct);
+ editMenu->addAction(copyAct);
+ editMenu->addAction(pasteAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+}
+//! [27]
+
+//! [29] //! [30]
+void MainWindow::createToolBars()
+{
+ fileToolBar = addToolBar(tr("File"));
+ fileToolBar->addAction(newAct);
+//! [29] //! [31]
+ fileToolBar->addAction(openAct);
+//! [31]
+ fileToolBar->addAction(saveAct);
+
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(cutAct);
+ editToolBar->addAction(copyAct);
+ editToolBar->addAction(pasteAct);
+}
+//! [30]
+
+//! [32]
+void MainWindow::createStatusBar()
+//! [32] //! [33]
+{
+ statusBar()->showMessage(tr("Ready"));
+}
+//! [33]
+
+//! [34] //! [35]
+void MainWindow::readSettings()
+//! [34] //! [36]
+{
+ QSettings settings("dennco project", "dennco creator");
+ QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
+ QSize size = settings.value("size", QSize(400, 400)).toSize();
+ resize(size);
+ move(pos);
+}
+//! [35] //! [36]
+
+//! [37] //! [38]
+void MainWindow::writeSettings()
+//! [37] //! [39]
+{
+ QSettings settings("dennco project", "dennco creator");
+ settings.setValue("pos", pos());
+ settings.setValue("size", size());
+}
+//! [38] //! [39]
+
+//! [40]
+bool MainWindow::maybeSave()
+//! [40] //! [41]
+{
+// if (textEdit->document()->isModified()) {
+ // QMessageBox::StandardButton ret;
+ // ret = QMessageBox::warning(this, tr("Application"),
+ // tr("The document has been modified.\n"
+// "Do you want to save your changes?"),
+// QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+// if (ret == QMessageBox::Save)
+// return save();
+// else if (ret == QMessageBox::Cancel)
+// return false;
+// }
+ return true;
+}
+//! [41]
+
+//! [42]
+void MainWindow::loadContent(const QString &contentDirectory)
+//! [42] //! [43]
+{
+
+ if (!mCreator)
+ return;
+
+ //TODO
+ QByteArray aContentDirectory = contentDirectory.toLocal8Bit();
+ mCreator->loadContent(aContentDirectory.data());
+
+ setCurrentContent(contentDirectory);
+ statusBar()->showMessage(tr("Content loaded"), 2000);
+}
+//! [43]
+
+//! [44]
+bool MainWindow::saveContent(const QString &contentDirectory)
+{
+
+ //TODO
+
+ setCurrentContent(contentDirectory);
+ statusBar()->showMessage(tr("Content saved"), 2000);
+ return true;
+}
+//! [45]
+
+//! [46]
+void MainWindow::setCurrentContent(const QString &contentDirectory)
+{
+ curContent = contentDirectory;
+// textEdit->document()->setModified(false);
+ setWindowModified(false);
+
+ QString shownName = curContent;
+ if (curContent.isEmpty())
+ shownName = "untitled.txt";
+ setWindowFilePath(shownName);
+}
+//! [47]
+
+//! [48]
+QString MainWindow::strippedName(const QString &fullFileName)
+//! [48] //! [49]
+{
+ return QFileInfo(fullFileName).fileName();
+}
+//! [49]
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+namespace Ui {
+class MainWindow;
+}
+
+class DCCreator;
+class DCGLVisualizerWidget;
+class DCTreeViewWidget;
+class DCCellInfoViewWidget;
+class DCCellCodeInfoViewWidget;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void newFile();
+ void open();
+ bool save();
+ bool saveAs();
+ void about();
+ void documentWasModified();
+
+private:
+ void createActions();
+ void createMenus();
+ void createToolBars();
+ void createStatusBar();
+ void readSettings();
+ void writeSettings();
+ bool maybeSave();
+ void loadContent(const QString &contentDirectory);
+ bool saveContent(const QString &contentDirectory);
+ void setCurrentContent(const QString &contentDirectory);
+ QString strippedName(const QString &fullFileName);
+
+ QString curContent;
+
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *helpMenu;
+ QToolBar *fileToolBar;
+ QToolBar *editToolBar;
+ QAction *newAct;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *cutAct;
+ QAction *copyAct;
+ QAction *pasteAct;
+ QAction *aboutAct;
+
+//! [0]
+private:
+ Ui::MainWindow *ui;
+
+ DCCreator *mCreator;
+ DCGLVisualizerWidget *mVisualizerWidget;
+ DCTreeViewWidget *mTreeViewWidget;
+ DCCellInfoViewWidget *mCellInfoViewWidget;
+ DCCellCodeInfoViewWidget *mCellCodeInfoViewWidget;
+};
+
+#endif // MAINWINDOW_H
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget"/>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>24</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <widget class="QDockWidget" name="dock1">
+ <property name="features">
+ <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
+ </property>
+ <property name="windowTitle">
+ <string>File</string>
+ </property>
+ <attribute name="dockWidgetArea">
+ <number>1</number>
+ </attribute>
+ <widget class="QWidget" name="treeViewDock">
+ <layout class="QHBoxLayout" name="horizontalLayout"/>
+ </widget>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dctreeviewwidget.h"
+
+#include "dccreator.h"
+#include "dcscene.h"
+#include "dcvcpage.h"
+#include "dcvccell.h"
+#include "dccontainer.h"
+#include "command/dccommand.h"
+
+#include "dialog/dcinputnewpagenamedialog.h"
+#include "dialog/dcaddcellcodeclassdialog.h"
+#include "dialog/dcaddcelldialog.h"
+
+#include <QList>
+#include <QItemSelectionModel>
+#include <QModelIndexList>
+
+static DCTreeViewWidget *s_treeViewWidget = NULL;
+
+static bool IsIndexUnderContainer(const QFileSystemModel *model, QModelIndex index)
+{
+ bool r = false;
+ while (index.isValid())
+ {
+ if (index.parent().isValid()
+ && model->fileName(index.parent()) == "Container"
+ && index.parent().parent().isValid()
+ && index.parent().parent() == model->index(model->rootPath()))
+ {
+ r = true;
+ }
+ index = index.parent();
+ }
+ return r;
+}
+
+
+DCTreeViewModel::DCTreeViewModel(DCCreator *creator)
+ : d_creator(creator)
+{
+
+}
+
+DCTreeViewModel::~DCTreeViewModel()
+{
+
+}
+
+bool DCTreeViewModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ bool r = false;
+ if (role == Qt::EditRole)
+ {
+ QString oldFilePath = filePath(index);
+ QString oldFileName = fileName(index);
+ QString baseDirPath = oldFilePath.left(oldFilePath.length()-oldFileName.length());
+
+ if (QFileInfo(oldFilePath).isDir() && IsIndexUnderContainer(this, index))
+ {
+ QString contentPath = QString::fromStdString(d_creator->getCurrentContainer()->getContentPath());
+ QString contentBasedPath = "/" + QDir(contentPath).relativeFilePath(baseDirPath);
+ if (d_creator->doCommandRenameDirectoryImmidiate(this, contentBasedPath, oldFileName, value.toString()))
+ {
+ r = QFileSystemModel::setData(index, value, role);
+ if (!r)
+ {
+ d_creator->doUndoImmidiate();
+ }
+ }
+ }
+ }
+ else
+ {
+ r = QFileSystemModel::setData(index, value, role);
+ }
+ return r;
+}
+
+DCTreeViewWidget::DCTreeViewWidget(QWidget *parent, DCCreator *creator) :
+ QTreeView(parent), d_creator(creator), d_fileSystemModel(creator), d_scene(NULL), d_inSelectionChange(false)
+{
+ setModel(&d_fileSystemModel);
+ d_fileSystemModel.setReadOnly(false);
+ connect(d_creator, SIGNAL(contentRootPathChanged(const void*, QString)), this, SLOT(contentRootPathChanged(const void*, QString)));
+ connect(d_creator, SIGNAL(sceneChanged(const void*, DCScene*)), this, SLOT(sceneChanged(const void*, DCScene*)));
+ connect(d_creator, SIGNAL(sceneSelectedPageChanged(const void*, const DCScene*)), this, SLOT(selectedPageChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(destroyed(QObject*)), this, SLOT(creatorDestroyed()));
+
+ connect(&d_fileSystemModel, SIGNAL(directoryLoaded(QString)), this, SLOT(expandAll()));
+
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(doContextMenu(const QPoint&)));
+ connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*)));
+ s_treeViewWidget = this;
+}
+
+DCTreeViewWidget::~DCTreeViewWidget()
+{
+ if (d_creator)
+ {
+ d_creator->disconnect(this);
+ }
+}
+
+//static
+bool DCTreeViewWidget::addDirectory(const QString &path)
+{
+ bool r = false;
+
+ if (s_treeViewWidget)
+ {
+ QModelIndex index = s_treeViewWidget->d_fileSystemModel.index(path);
+ if (index.isValid())
+ {
+ QString newDirName = "NewFolder";
+ int i = 0;
+ while(QDir(path + "/" + newDirName).exists())
+ {
+ i++;
+ newDirName = "";
+ QTextStream(&newDirName) << "NewFolder(" << i << ")";
+ }
+ QModelIndex newDirIndex = s_treeViewWidget->d_fileSystemModel.mkdir(index, newDirName);
+ if (newDirIndex.isValid())
+ {
+ r = true;
+ s_treeViewWidget->setCurrentIndex(newDirIndex);
+ }
+ }
+ }
+ else
+ {
+ Q_ASSERT(0);
+ }
+ return r;
+}
+
+//static
+bool DCTreeViewWidget::removeDirectory(const QString &path)
+{
+ bool r = false;
+
+ if (s_treeViewWidget)
+ {
+ QModelIndex index = s_treeViewWidget->d_fileSystemModel.index(path);
+ if (index.isValid())
+ {
+ r = s_treeViewWidget->d_fileSystemModel.rmdir(index);
+ }
+ }
+ else
+ {
+ Q_ASSERT(0);
+ }
+ return r;
+}
+
+
+void DCTreeViewWidget::doContextMenu(const QPoint &pos)
+{
+ QPoint globalPos = mapToGlobal(pos);
+
+ QFileSystemModel *fileModel = dynamic_cast<QFileSystemModel*>(model());
+
+ QMenu menu;
+ bool showMenu = false;
+
+ QAction *addDictionaryAction = NULL;
+ QAction *addPageAction = NULL;
+ QAction *addCellAction = NULL;
+ QAction *addCellCodeClassAction = NULL;
+ QAction *renamePageAction = NULL;
+ QAction *removeDirectoryAction = NULL;
+ QAction *removePageAction = NULL;
+
+ bool isDir = true;
+ bool isPage = false;
+
+ QModelIndex index;
+
+ QModelIndexList indexes = selectedIndexes();
+ if (indexes.length() == 0)
+ {
+ addDictionaryAction = menu.addAction(tr("Add folder"));
+ index = fileModel->index(fileModel->rootPath() + "/Container");
+ showMenu = true;
+ }
+ else if (indexes.length() > 0)
+ {
+ index = indexes.at(0);
+ isDir = d_fileSystemModel.isDir(index);
+ isPage = !isDir && d_fileSystemModel.fileInfo(index).completeSuffix() == "xhtml";
+
+ if (isDir)
+ {
+ addDictionaryAction = menu.addAction(tr("Add folder"));
+ if (IsIndexUnderContainer(&d_fileSystemModel, index))
+ {
+ addPageAction = menu.addAction(tr("Add page..."));
+ }
+ if (fileModel->flags(index) & Qt::ItemIsEditable && !index.child(0,0).isValid())
+ {
+ removeDirectoryAction = menu.addAction(tr("Remove"));
+ }
+ showMenu = true;
+ }
+ else
+ {
+ if (isPage)
+ {
+ addCellAction = menu.addAction(tr("Add cell ..."));
+ addCellCodeClassAction = menu.addAction(tr("Add cell code class ..."));
+ menu.addSeparator();
+ renamePageAction = menu.addAction(tr("Rename"));
+ removePageAction = menu.addAction(tr("Remove..."));
+ menu.addSeparator();
+ }
+ addDictionaryAction = menu.addAction(tr("Add folder"));
+ showMenu = true;
+ }
+ }
+
+ if (showMenu)
+ {
+ QString contentPath;
+ QString contentBasedPath;
+
+ if (index.isValid())
+ {
+ contentPath = QString::fromStdString(d_creator->getCurrentContainer()->getContentPath());
+ contentBasedPath = "/" + QDir(contentPath).relativeFilePath(fileModel->filePath(index));
+ }
+
+ QAction* selectedItem = menu.exec(globalPos);
+ if (selectedItem)
+ {
+ if (selectedItem == addDictionaryAction)
+ {
+ if (index.isValid())
+ d_creator->doCommandAddDirectory(this, fileModel->filePath(index));
+ }
+ else if (selectedItem == removeDirectoryAction)
+ {
+ if (index.isValid())
+ d_creator->doCommandRemoveDirectory(this, fileModel->filePath(index));
+ }
+ else if (selectedItem == addPageAction)
+ {
+ if (index.isValid())
+ {
+ if (contentBasedPath.length() > 1)
+ {
+ DCInputNewPageNameDialog dialog;
+ if (dialog.exec())
+ {
+ QString pageName = dialog.getName();
+ if (pageName.length() > 0)
+ {
+ QString pathName = contentBasedPath + "/" + pageName;
+ d_creator->doCommandAddPage(this, pathName);
+ }
+ }
+ }
+ }
+ }
+ else if (selectedItem == renamePageAction)
+ {
+ //TODO
+ QMessageBox msgBox;
+ msgBox.setText("This command hasn't implemented yet");
+ msgBox.exec();
+ }
+ else if (selectedItem == removePageAction)
+ {
+ //TODO
+ QMessageBox msgBox;
+ msgBox.setText("This command hasn't implemented yet");
+ msgBox.exec();
+ }
+ else if (selectedItem == addCellAction )
+ {
+ if (index.isValid())
+ {
+ DCAddCellDialog dialog(d_creator->getCurrentContainer(), d_creator, contentBasedPath);
+ dialog.exec();
+ }
+ }
+ else if (selectedItem == addCellCodeClassAction)
+ {
+ if (index.isValid())
+ {
+ DCAddCellCodeClassDialog dialog(d_creator->getCurrentContainer(), d_creator, contentBasedPath);
+ dialog.exec();
+ }
+ }
+
+ }
+ }
+}
+
+
+void DCTreeViewWidget::showEvent(QShowEvent *event)
+{
+ setColumnHidden(1,true);
+ setColumnHidden(2,true);
+ setColumnHidden(3,true);
+
+ QTreeView::showEvent(event);
+}
+
+void DCTreeViewWidget::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ QModelIndex index = currentIndex();
+ if (index.isValid())
+ {
+ bool isDir = d_fileSystemModel.isDir(index);
+ bool isPage = false;
+ if (!isDir && d_fileSystemModel.fileInfo(index).completeSuffix() == "xhtml")
+ {
+ isPage = true;
+ }
+
+ if (!IsIndexUnderContainer(&d_fileSystemModel, index))
+ {
+ event->accept();
+ return;
+ }
+
+ if (isDir)
+ {
+ QTreeView::mouseDoubleClickEvent(event);
+ }
+ else if (isPage)
+ {
+ d_creator->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
+ event->accept();
+ }
+ }
+ else
+ {
+ QTreeView::mouseDoubleClickEvent(event);
+ }
+}
+
+void DCTreeViewWidget::creatorDestroyed()
+{
+ d_creator = NULL;
+}
+
+void DCTreeViewWidget::contentRootPathChanged(const void *requester, QString rootPath)
+{
+ QModelIndex idx = d_fileSystemModel.setRootPath(rootPath);
+ setRootIndex(idx);
+ sortByColumn(0, Qt::DescendingOrder);
+}
+
+void DCTreeViewWidget::sceneChanged(const void *requester, DCScene*scene)
+{
+ d_scene = scene;
+}
+
+void DCTreeViewWidget::selectedPageChanged(const void *requester, const DCScene*scene)
+{
+ if (d_scene != scene)
+ return;
+
+ if (requester == this)
+ {
+ return;
+ }
+
+ if (d_scene)
+ {
+ d_inSelectionChange = true;
+ clearSelection();
+ QList<DCVCPage*> list = d_scene->getSelectedPages();
+ QItemSelectionModel *selection = selectionModel();
+ QString rootPath = d_fileSystemModel.rootPath();
+ for (int i = 0; i < list.length(); i++)
+ {
+ DCVCPage *page = list.at(i);
+ QString path = rootPath + QString("/Container") + page->getLocationPath();
+ QModelIndex idx = d_fileSystemModel.index(path);
+ selection->select(idx, QItemSelectionModel::Select);
+ }
+ d_inSelectionChange = false;
+ }
+}
+
+void DCTreeViewWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ QTreeView::selectionChanged(selected, deselected);
+
+ if (d_inSelectionChange)
+ {
+ return;
+ }
+
+ if (d_creator)
+ {
+ QModelIndexList selectedList = selected.indexes();
+ QModelIndexList deselectedList = deselected.indexes();
+ int stripLen = d_fileSystemModel.rootPath().length();
+
+ for (int i = 0; i < selectedList.length(); i++)
+ {
+ QString fpath = d_fileSystemModel.filePath(selectedList.at(i));
+ if (fpath.length() > stripLen)
+ {
+ fpath = fpath.mid(stripLen);
+ if (fpath.indexOf("/Container") == 0)
+ {
+ fpath = fpath.mid(10);
+ d_creator->selectPage(this, fpath, true);
+ }
+ }
+ }
+
+ for (int i = 0; i < deselectedList.length(); i++)
+ {
+ QString fpath = d_fileSystemModel.filePath(deselectedList.at(i));
+ if (fpath.length() > stripLen)
+ {
+ fpath = fpath.mid(stripLen);
+ if (fpath.indexOf("/Container") == 0)
+ {
+ fpath = fpath.mid(10);
+ d_creator->unselectPage(this, fpath);
+ }
+ }
+ }
+
+ if (d_creator->getPersMode() == DCCreator::DC_PERSMODE_PAGEEDIT)
+ {
+ d_creator->changePersMode(this, DCCreator::DC_PERSMODE_NAVIGATION);
+ }
+ }
+}
+
+void DCTreeViewWidget::commandExecuted(const QUndoCommand *command)
+{
+ const DCCommand *dccommand = dynamic_cast<const DCCommand*>(command);
+ if (dccommand && dccommand->getRequester() == this)
+ {
+ sortByColumn(0, Qt::DescendingOrder);
+ }
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCTREEVIEWWIDGET_H
+#define DCTREEVIEWWIDGET_H
+
+#include <QTreeView>
+#include <QShowEvent>
+#include <QFileSystemModel>
+#include <QUndoCommand>
+
+class DCCreator;
+class DCScene;
+
+class DCTreeViewModel : public QFileSystemModel
+{
+ Q_OBJECT
+private:
+ DCCreator *d_creator;
+
+public:
+ DCTreeViewModel(DCCreator *creator);
+ virtual ~DCTreeViewModel();
+
+ virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
+
+};
+
+class DCTreeViewWidget : public QTreeView
+{
+ Q_OBJECT
+private:
+ DCCreator *d_creator;
+ DCTreeViewModel d_fileSystemModel;
+ DCScene *d_scene;
+ bool d_inSelectionChange;
+
+public:
+ DCTreeViewWidget(QWidget *parent, DCCreator *creator);
+ virtual ~DCTreeViewWidget();
+
+ static bool addDirectory(const QString &path);
+ static bool removeDirectory(const QString &path);
+
+protected:
+ virtual void showEvent(QShowEvent *);
+ virtual void mouseDoubleClickEvent(QMouseEvent *event);
+
+private slots:
+ void contentRootPathChanged(const void *requester, QString rootPath);
+ void sceneChanged(const void *requester, DCScene*scene);
+ void selectedPageChanged(const void *requester, const DCScene*scene);
+ void creatorDestroyed();
+
+ virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+
+ void doContextMenu(const QPoint &pos);
+
+ void commandExecuted(const QUndoCommand *command);
+
+};
+
+#endif // DCTREEVIEWWIDGET_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccommandutil.h"
+
+#include <QtGui>
+
+#include "command/dceditcommands.h"
+#include "command/dccommandevent.h"
+#include "dccreator.h"
+
+static void postEvent(QObject *target, DCCommand *command)
+{
+ QEvent *event = new DCCommandEvent(command);
+ QApplication::instance()->postEvent(target, event);
+}
+
+
+//static
+void DCCommandUtil::postStartAddAxonTerminalCommandFromAxon(const void *requester, DCCreator *creator, DCCell *ownerCell)
+{
+ postEvent(creator, new DCStartAddAxonTerminalCommandFromAxon(requester, creator, ownerCell));
+}
+
+//static
+void DCCommandUtil::postStartAddAxonTerminalCommandFromReceptor(const void *requester, DCCreator *creator, DCCell *ownerCell, const QString &receptorName)
+{
+ postEvent(creator, new DCStartAddAxonTerminalCommandFromReceptor(requester, creator, ownerCell, receptorName));
+}
+
+//static
+void DCCommandUtil::postCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCAxon *axon, DCCell *receptorCell, const QString &receptorName)
+{
+ postEvent(creator, new DCCommitAddAxonTerminalCommand(requester, creator, axon, receptorCell, receptorName));
+}
+
+//static
+void DCCommandUtil::postCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCReceptor *receptor)
+{
+ postEvent(creator, new DCCommitAddAxonTerminalCommand(requester, creator, axonCell, receptor));
+}
+
+//static
+void DCCommandUtil::postDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCAxonTerminal *axonTerminal)
+{
+ postEvent(creator, new DCDeleteAxonTerminalCommand(requester, creator, axonCell, axonTerminal));
+}
+
+//static
+void DCCommandUtil::postDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *receptorCell, const QString &receptorName)
+{
+ postEvent(creator, new DCDeleteAxonTerminalCommand(requester, creator, receptorCell, receptorName));
+}
+
+//static
+void DCCommandUtil::postStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell)
+{
+ postEvent(creator, new DCStartCellCodeEditCommand(requester, creator, ownerCell));
+}
+
+//static
+void DCCommandUtil::postStopCellCodeEditCommand(const void *requester, DCCreator *creator)
+{
+ postEvent(creator, new DCStopCellCodeEditCommand(requester, creator));
+}
+
+//static
+void DCCommandUtil::postUndoRequestCommand(const void *requester, DCCreator *creator)
+{
+ QEvent *event = new DCUndoEvent();
+ QApplication::instance()->postEvent(creator, event);
+}
+
+//static
+void DCCommandUtil::postSetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell, DCCellCode *cellCode)
+{
+ postEvent(creator, new DCSetCellCodeClassCommand(requester, creator, cell, cellCode));
+}
+
+//static
+void DCCommandUtil::postUnsetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell)
+{
+ postEvent(creator, new DCUnsetCellCodeClassCommand(requester, creator, cell));
+}
+
+//static
+void DCCommandUtil::postAddCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString &name, const QString &type)
+{
+ postEvent(creator, new DCAddCellCodeClassCommand(requester, creator, container, name, type));
+}
+
+//static
+void DCCommandUtil::postAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString &contentBasedPath, const QString &name, const QString &type)
+{
+ postEvent(creator, new DCAddCellCommand(requester, creator, container, contentBasedPath, name, type));
+}
+
+//static
+void DCCommandUtil::postAddPageCommand(const void *requester, DCCreator *creator, const QString& contentBasedPath)
+{
+ postEvent(creator, new DCAddPageCommand(requester, creator, contentBasedPath));
+}
+
+//static
+void DCCommandUtil::postAddDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysFilePath)
+{
+ postEvent(creator, new DCAddDirectoryCommand(requester, creator, sysFilePath));
+}
+
+//static
+void DCCommandUtil::postRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysFilePath)
+{
+ postEvent(creator, new DCRemoveDirectoryCommand(requester, creator, sysFilePath));
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCOMMANDUTIL_H
+#define DCCOMMANDUTIL_H
+
+class DCCommand;
+class DCCreator;
+class DCContainer;
+class DCCell;
+class DCCellCode;
+class DCAxon;
+class DCReceptor;
+class DCAxonTerminal;
+
+#include <QString>
+
+struct DCCommandUtil
+{
+ static void postStartAddAxonTerminalCommandFromAxon(const void *requester, DCCreator *creator, DCCell *ownerCell);
+ static void postStartAddAxonTerminalCommandFromReceptor(const void *requester, DCCreator *creator, DCCell *ownerCell, const QString &receptorName);
+ static void postCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCAxon *axon, DCCell *receptorCell, const QString &receptorName);
+ static void postCommitAddAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCReceptor *receptor);
+ static void postDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *axonCell, DCAxonTerminal *axonTerminal);
+ static void postDeleteAxonTerminalCommand(const void *requester, DCCreator *creator, DCCell *receptorCell, const QString& receptorName);
+
+ static void postStartCellCodeEditCommand(const void *requester, DCCreator *creator, DCCell *ownerCell);
+ static void postStopCellCodeEditCommand(const void *requester, DCCreator *creator);
+
+ static void postUndoRequestCommand(const void *requester, DCCreator *creator);
+
+ static void postSetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell, DCCellCode *cellCode);
+ static void postUnsetCellCodeClassCommand(const void *requester, DCCreator *creator, DCCell *cell);
+
+ static void postAddCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& name, const QString& type);
+ static void postAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& contentBasedPath, const QString& name, const QString& type);
+ static void postAddPageCommand(const void *requester, DCCreator *creator, const QString& contentBasedPath);
+
+ static void postAddDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
+ static void postRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
+};
+
+#endif // DCCOMMANDUTIL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dccomponentutil.h"
+
+#include "dccell.h"
+#include "dcvccell.h"
+#include "dccellcode.h"
+#include "dcvccellcode.h"
+#include "dcaxon.h"
+#include "dcvcaxon.h"
+#include "dcaxonterminal.h"
+#include "dcvcaxonterminal.h"
+#include "dcreceptor.h"
+#include "dcvcreceptor.h"
+#include "dcvcpage.h"
+#include "TKReceptor.h"
+#include "dcvceditmodeterminal.h"
+
+#include <map>
+
+//static
+DCCell* DCComponentUtil::createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterface)
+{
+ DCCell *cell = new DCCell(container, location, name, type, canInterface);
+ cell->bindComponent(new DCVCCell(cell, page, 0.5, 0.5));
+ page->registerCell(dynamic_cast<DCVPageComponent*>(cell->getVComponent()));
+
+ return cell;
+}
+
+//static
+DCCellCode* DCComponentUtil::createCellCode(std::string theName, std::string theCellAPIName)
+{
+ DCCellCode *cellcode = new DCCellCode(theName, theCellAPIName);
+ cellcode->bindComponent(new DCVCCellCode(cellcode));
+
+ return cellcode;
+}
+
+//static
+DCAxon* DCComponentUtil::createAxon(DCCell *theOwner)
+{
+ DCAxon *axon = new DCAxon(theOwner);
+ axon->bindComponent(new DCVCAxon(axon));
+
+ return axon;
+}
+
+//static
+DCAxonTerminal* DCComponentUtil::createAxonTerminal(DCAxon *theOwner)
+{
+ DCAxonTerminal *axonTerminal = new DCAxonTerminal(theOwner);
+ axonTerminal->bindComponent(new DCVCAxonTerminal(axonTerminal));
+
+ return axonTerminal;
+}
+
+//static
+DCReceptor* DCComponentUtil::createReceptor(DCCell *theOwner)
+{
+ DCReceptor *receptor = new DCReceptor(theOwner);
+ receptor->bindComponent(new DCVCReceptor(receptor));
+
+ return receptor;
+}
+
+//static
+bool DCComponentUtil::isConnectedToSelectedCell(DCVComponent *vcell)
+{
+ DCCell *cell = dynamic_cast<DCVCCell*>(vcell)->getOwnerCell();
+ bool r = false;
+ const TKReceptorMap *receptors = cell->getReceptors();
+ for ( TKReceptorMap::const_iterator it = receptors->begin(); it != receptors->end(); ++it )
+ {
+ TKReceptor *receptor = it->second;
+ if ( receptor && receptor->getTarget() && ((DCCell*)receptor->getTarget()->getOwner()->getOwner())->getVComponent()->getIsSelected())
+ {
+ r = true;
+ break;
+ }
+ }
+
+ if (!r)
+ {
+ DCAxon *axon = cell->getAxon();
+ if (axon)
+ {
+ for (int i = axon->getNumberOfTerminals()-1; i >= 0; i--)
+ {
+ DCAxonTerminal *terminal = axon->getTerminalAt(i);
+ if (terminal && terminal->getTarget() && ((DCCell*)terminal->getTarget()->getOwnerCell())->getVComponent()->getIsSelected())
+ {
+ r = true;
+ break;
+ }
+ }
+ }
+ }
+ return r;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCCOMPONENTUTIL_H
+#define DCCOMPONENTUTIL_H
+
+class DCVComponent;
+class DCVCPage;
+class DCCell;
+class DCCellCode;
+class DCAxon;
+class DCAxonTerminal;
+class DCReceptor;
+class DCContainer;
+
+#include <string>
+
+struct DCComponentUtil
+{
+ static DCCell* createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterface);
+ static DCCellCode* createCellCode(std::string theName, std::string theCellAPIName);
+ static DCAxon* createAxon(DCCell *theOwner);
+ static DCAxonTerminal* createAxonTerminal(DCAxon *theOwner);
+ static DCReceptor* createReceptor(DCCell *theOwner);
+ static bool isConnectedToSelectedCell(DCVComponent *cell);
+
+};
+
+#endif // DCCOMPONENTUTIL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcdialogutil.h"
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCDIALOGUTIL_H
+#define DCDIALOGUTIL_H
+
+class DCCreator;
+
+struct DCDialogUtil
+{
+
+};
+
+#endif // DCDIALOGUTIL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcqtitemmodel.h"
+
+#include <QtGui>
+
+static const QSize s_iconSize(16,16);
+
+DCQtItemModelItem::DCQtItemModelItem(const QVector<QVariant> &data, DCQtItemModelItem *parent)
+ : mItemData(data), mParentItem(parent)
+{
+}
+
+DCQtItemModelItem::~DCQtItemModelItem()
+{
+ qDeleteAll(mChildItems);
+}
+
+DCQtItemModelItem *DCQtItemModelItem::child(int number)
+{
+ return mChildItems.value(number);
+}
+
+int DCQtItemModelItem::childCount() const
+{
+ return mChildItems.count();
+}
+
+int DCQtItemModelItem::childNumber() const
+{
+ if (mParentItem)
+ return mParentItem->mChildItems.indexOf(const_cast<DCQtItemModelItem*>(this));
+
+ return 0;
+}
+
+int DCQtItemModelItem::columnCount() const
+{
+ return mItemData.count();
+}
+
+QVariant DCQtItemModelItem::data(int column) const
+{
+ return mItemData.value(column);
+}
+
+bool DCQtItemModelItem::insertChildren(int position, int count, int columns)
+{
+ if (position < 0 || position > mChildItems.size())
+ return false;
+
+ for (int row = 0; row < count; ++row) {
+ QVector<QVariant> data(columns);
+ DCQtItemModelItem *item = new DCQtItemModelItem(data, this);
+ mChildItems.insert(position, item);
+ }
+
+ return true;
+}
+
+bool DCQtItemModelItem::insertColumns(int position, int columns)
+{
+ if (position < 0 || position > mItemData.size())
+ return false;
+
+ for (int column = 0; column < columns; ++column)
+ mItemData.insert(position, QVariant());
+
+ foreach (DCQtItemModelItem *child, mChildItems)
+ child->insertColumns(position, columns);
+
+ return true;
+}
+
+DCQtItemModelItem *DCQtItemModelItem::parent()
+{
+ return mParentItem;
+}
+
+
+bool DCQtItemModelItem::removeChildren(int position, int count)
+{
+ if (position < 0 || position + count > mChildItems.size())
+ return false;
+
+ for (int row = 0; row < count; ++row)
+ delete mChildItems.takeAt(position);
+
+ return true;
+}
+
+
+bool DCQtItemModelItem::removeColumns(int position, int columns)
+{
+ if (position < 0 || position + columns > mItemData.size())
+ return false;
+
+ for (int column = 0; column < columns; ++column)
+ mItemData.remove(position);
+
+ foreach (DCQtItemModelItem *child, mChildItems)
+ child->removeColumns(position, columns);
+
+ return true;
+}
+
+bool DCQtItemModelItem::setData(int column, const QVariant &value)
+{
+ if (column < 0 || column >= mItemData.size())
+ return false;
+
+ mItemData[column] = value;
+ return true;
+}
+
+
+
+DCQtItemModel::DCQtItemModel(const QStringList &headers, QObject *parent)
+ : QAbstractItemModel(parent)
+{
+ QVector<QVariant> rootData;
+ foreach (QString header, headers)
+ {
+ rootData << header;
+ mReadOnlyAttrib.push_back(true);
+ }
+
+ mRootItem = new DCQtItemModelItem(rootData);
+}
+
+DCQtItemModel::~DCQtItemModel()
+{
+ delete mRootItem;
+}
+
+int DCQtItemModel::columnCount(const QModelIndex & /* parent */) const
+{
+ return mRootItem->columnCount();
+}
+
+QVariant DCQtItemModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ DCQtItemModelItem *item = getItem(index);
+
+ if (role == Qt::DecorationRole)
+ {
+ if (item->data(index.column()).type() == QVariant::Pixmap)
+ return item->data(index.column());
+ }
+ else if (role == Qt::SizeHintRole)
+ {
+ if (item->data(index.column()).type() == QVariant::Pixmap)
+ {
+// return s_iconSize;
+ }
+ }
+ else if (role == Qt::DisplayRole || role == Qt::EditRole)
+ {
+ if (item->data(index.column()).type() == QVariant::Pixmap)
+ {
+ return " ";
+ }
+ else
+ {
+ return item->data(index.column());
+ }
+ }
+
+ return QVariant();
+}
+
+Qt::ItemFlags DCQtItemModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return 0;
+
+ Qt::ItemFlags flags = Qt::NoItemFlags;
+
+ if (index.column() < mReadOnlyAttrib.size())
+ {
+ flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+
+ if (mReadOnlyAttrib[index.column()] == false)
+ {
+ flags |= Qt::ItemIsEditable;
+ }
+ }
+
+ return flags;
+}
+
+DCQtItemModelItem *DCQtItemModel::getItem(const QModelIndex &index) const
+{
+ if (index.isValid()) {
+ DCQtItemModelItem *item = static_cast<DCQtItemModelItem*>(index.internalPointer());
+ if (item) return item;
+ }
+ return mRootItem;
+}
+
+QVariant DCQtItemModel::headerData(int section, Qt::Orientation orientation,
+ int role) const
+{
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
+ return mRootItem->data(section);
+
+ return QVariant();
+}
+
+QModelIndex DCQtItemModel::index(int row, int column, const QModelIndex &parent) const
+{
+ if (parent.isValid() && parent.column() != 0)
+ return QModelIndex();
+
+ DCQtItemModelItem *parentItem = getItem(parent);
+
+ DCQtItemModelItem *childItem = parentItem->child(row);
+ if (childItem)
+ return createIndex(row, column, childItem);
+ else
+ return QModelIndex();
+}
+
+bool DCQtItemModel::insertColumns(int position, int columns, const QModelIndex &parent)
+{
+ bool success;
+
+ beginInsertColumns(parent, position, position + columns - 1);
+ success = mRootItem->insertColumns(position, columns);
+ endInsertColumns();
+
+ return success;
+}
+
+bool DCQtItemModel::insertRows(int position, int rows, const QModelIndex &parent)
+{
+ DCQtItemModelItem *parentItem = getItem(parent);
+ bool success;
+
+ beginInsertRows(parent, position, position + rows - 1);
+ success = parentItem->insertChildren(position, rows, mRootItem->columnCount());
+ endInsertRows();
+
+ return success;
+}
+
+QModelIndex DCQtItemModel::parent(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return QModelIndex();
+
+ DCQtItemModelItem *childItem = getItem(index);
+ DCQtItemModelItem *parentItem = childItem->parent();
+
+ if (parentItem == mRootItem)
+ return QModelIndex();
+
+ return createIndex(parentItem ? parentItem->childNumber() : 0, 0, parentItem);
+}
+
+bool DCQtItemModel::removeColumns(int position, int columns, const QModelIndex &parent)
+{
+ bool success;
+
+ beginRemoveColumns(parent, position, position + columns - 1);
+ success = mRootItem->removeColumns(position, columns);
+ endRemoveColumns();
+
+ if (mRootItem->columnCount() == 0)
+ removeRows(0, rowCount());
+
+ return success;
+}
+
+bool DCQtItemModel::removeRows(int position, int rows, const QModelIndex &parent)
+{
+ if (rows == 0)
+ return true;
+
+ DCQtItemModelItem *parentItem = getItem(parent);
+ bool success = true;
+
+ beginRemoveRows(parent, position, position + rows - 1);
+ success = parentItem->removeChildren(position, rows);
+ endRemoveRows();
+
+ return success;
+}
+
+bool DCQtItemModel::removeAllItems()
+{
+ return removeRows(0, rowCount());
+}
+
+int DCQtItemModel::rowCount(const QModelIndex &parent) const
+{
+ DCQtItemModelItem *parentItem = getItem(parent);
+
+ return parentItem->childCount();
+}
+
+bool DCQtItemModel::setData(const QModelIndex &index, const QVariant &value,
+ int role)
+{
+ if (role != Qt::EditRole)
+ return false;
+
+ DCQtItemModelItem *item = getItem(index);
+ bool result = item->setData(index.column(), value);
+
+ if (result)
+ emit dataChanged(index, index);
+
+ return result;
+}
+
+bool DCQtItemModel::setHeaderData(int section, Qt::Orientation orientation,
+ const QVariant &value, int role)
+{
+ if (role != Qt::EditRole || orientation != Qt::Horizontal)
+ return false;
+
+ bool result = mRootItem->setData(section, value);
+
+ if (result)
+ emit headerDataChanged(orientation, section, section);
+
+ return result;
+}
+
+bool DCQtItemModel::insertStringList(const QStringList &stringList, const QModelIndex &parent)
+{
+ DCQtItemModelItem *parentItem = getItem(parent);
+ int position = parentItem->childCount();
+
+ insertRows(position,1,parent);
+ for (int i = 0; i < stringList.length(); i++)
+ {
+ setData(index(position,i,parent),QVariant(stringList.at(i)));
+ }
+ return true;
+}
+
+bool DCQtItemModel::insertString(const QString &string, const QModelIndex &parent)
+{
+ DCQtItemModelItem *parentItem = getItem(parent);
+ int position = parentItem->childCount();
+ insertRows(position,1,parent);
+ setData(index(position,0,parent),QVariant(string));
+ return true;
+}
+
+
+void DCQtItemModel::setReadOnly(int column, bool isReadOnly)
+{
+ if (column < mReadOnlyAttrib.size())
+ {
+ mReadOnlyAttrib[column] = isReadOnly;
+ }
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCQTITEMMODEL_H
+#define DCQTITEMMODEL_H
+
+#include <QAbstractItemModel>
+#include <QVector>
+#include <QStringList>
+
+class DCQtItemModelItem
+{
+public:
+ DCQtItemModelItem(const QVector<QVariant> &data, DCQtItemModelItem *parent = 0);
+ virtual ~DCQtItemModelItem();
+
+ DCQtItemModelItem *child(int number);
+ int childCount() const;
+ int columnCount() const;
+ QVariant data(int column) const;
+ bool insertChildren(int position, int count, int columns);
+ bool insertColumns(int position, int columns);
+ DCQtItemModelItem *parent();
+ bool removeChildren(int position, int count);
+ bool removeColumns(int position, int columns);
+ int childNumber() const;
+ bool setData(int column, const QVariant &value);
+
+private:
+ QList<DCQtItemModelItem*> mChildItems;
+ QVector<QVariant> mItemData;
+ DCQtItemModelItem *mParentItem;
+};
+
+class DCQtItemModel : public QAbstractItemModel
+{
+ Q_OBJECT
+public:
+ DCQtItemModel(const QStringList &headers, QObject *parent = 0);
+ virtual ~DCQtItemModel();
+
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex &index) const;
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
+
+ bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex());
+ bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex());
+ bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex());
+ bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
+ bool removeAllItems();
+
+ //
+ bool insertStringList(const QStringList &stringList, const QModelIndex &parent = QModelIndex());
+ bool insertString(const QString &string, const QModelIndex &parent = QModelIndex());
+ void setReadOnly(int column, bool isReadOnly);
+
+private:
+ DCQtItemModelItem *getItem(const QModelIndex &index) const;
+
+ DCQtItemModelItem *mRootItem;
+ QVector<bool> mReadOnlyAttrib;
+signals:
+
+public slots:
+
+};
+
+#endif // DCQTITEMMODEL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcresources.h"
+
+#include <QtGui>
+
+static QPixmap *s_addItemIcon = NULL;
+static QPixmap *s_deleteItemIcon = NULL;
+
+//static
+void DCResources::initResources()
+{
+ //should only called once
+ Q_ASSERT(s_addItemIcon == NULL);
+ Q_ASSERT(s_deleteItemIcon == NULL);
+
+ s_addItemIcon = new QPixmap(":/addItemIcon.png");
+ s_deleteItemIcon = new QPixmap(":/deleteItemIcon.png");
+}
+
+//static
+QPixmap DCResources::addItemIcon()
+{
+ Q_ASSERT(s_addItemIcon != NULL);
+ return *s_addItemIcon;
+}
+
+//static
+QPixmap DCResources::deleteItemIcon()
+{
+ Q_ASSERT(s_deleteItemIcon != NULL);
+ return *s_deleteItemIcon;
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCRESOURCES_H
+#define DCRESOURCES_H
+
+class QPixmap;
+
+struct DCResources
+{
+ static void initResources();
+ static QPixmap addItemIcon();
+ static QPixmap deleteItemIcon();
+};
+
+#endif // DCRESOURCES_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcveventhandlerutil.h"
+
+#include "visualizer/eventhandler/dcveventhandler.h"
+#include "visualizer/eventhandler/dcvlayoutmodehandler.h"
+#include "visualizer/eventhandler/dcvterminalfromaxonmodehandler.h"
+#include "visualizer/eventhandler/dcvterminalfromreceptormodehandler.h"
+
+#include <typeinfo>
+
+//static
+DCVEventHandler* DCVEventHandlerUtil::createLayoutModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene)
+{
+ return new DCVLayoutModeHandler(widget, creator, scene);
+}
+
+//static
+DCVEventHandler* DCVEventHandlerUtil::createTerminalFromAxonModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCAxon *editAxon, DCVCEditModeCursor *cursor)
+{
+ return new DCVTerminalFromAxonModeHandler(widget, creator, scene, editAxon, cursor);
+}
+
+//static
+DCVEventHandler* DCVEventHandlerUtil::createTerminalFromReceptorModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCReceptor *editReceptor, DCVCEditModeCursor *cursor)
+{
+ return new DCVTerminalFromReceptorModeHandler(widget, creator, scene, editReceptor, cursor);
+}
+
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVEVENTHANDLERUTIL_H
+#define DCVEVENTHANDLERUTIL_H
+
+class DCScene;
+class DCCreator;
+class DCUIGraphicsScene;
+class DCVEventHandler;
+class DCAxon;
+class DCReceptor;
+class DCVCEditModeCursor;
+class DCVComponent;
+
+#include <QString>
+
+struct DCVEventHandlerUtil
+{
+ static DCVEventHandler * createLayoutModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene);
+ static DCVEventHandler * createTerminalFromAxonModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCAxon *editAxon, DCVCEditModeCursor *cursor);
+ static DCVEventHandler * createTerminalFromReceptorModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCReceptor *editReceptor, DCVCEditModeCursor *cursor);
+};
+
+#endif // DCVEVENTHANDLERUTIL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvcaxon.h"
+
+#include "dcaxon.h"
+#include "dcaxonterminal.h"
+#include "dccell.h"
+#include "dcvpagecomponent.h"
+#include "dccuberenderer.h"
+
+#include <math.h>
+
+static const double PI = 3.14159265358979323846264338327950288419717;
+static DCCubeRenderer *s_shapeTerminalSocket = NULL;
+
+DCVCAxon::DCVCAxon(DCAxon *owner) : d_owner(owner), d_shouldUpdateShape(true)
+{
+ // default size
+ owner->setViewLength(owner->getOwnerCell()->getViewSize()/2 + 0.1);
+}
+
+DCVCAxon::~DCVCAxon()
+{
+}
+
+void DCVCAxon::prepareChildrenForDraw(bool isAnimationInterval)
+{
+ int len = d_owner->getNumberOfTerminals();
+ float matrix[16];
+ glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
+ for (int i = 0; i < len; ++i)
+ {
+ d_owner->getTerminalAt(i)->setViewMatrixForAxonPoint(matrix);
+ d_owner->getTerminalAt(i)->getVComponent()->prepareForDraw(isAnimationInterval);
+ }
+ if (d_owner->hasEditingTerminal())
+ {
+ d_owner->setEditingCursorViewMatrix(matrix);
+ }
+}
+
+void DCVCAxon::drawChildren(bool isAnimationInterval)
+{
+ int len = d_owner->getNumberOfTerminals();
+ for (int i = 0; i < len; ++i)
+ {
+ d_owner->getTerminalAt(i)->getVComponent()->draw(isAnimationInterval);
+ }
+ if (d_owner->hasEditingTerminal())
+ {
+ d_owner->getEditingTerminal()->draw(isAnimationInterval);
+ }
+}
+
+void DCVCAxon::drawChildrenForSelection(QList<DCVComponent *> *itemList)
+{
+ int len = d_owner->getNumberOfTerminals();
+ for (int i = 0; i < len; ++i)
+ {
+ d_owner->getTerminalAt(i)->getVComponent()->drawForSelection(itemList);
+ }
+ if (d_owner->hasEditingTerminal())
+ {
+ d_owner->getEditingTerminal()->drawForSelection(itemList);
+ }
+}
+
+void DCVCAxon::translate()
+{
+ float rad = d_owner->getViewAngle() / 180 * PI;
+ float length = d_owner->getViewLength();
+ glTranslatef(cos(rad)* length, -0.245, sin(rad)* length);
+}
+
+void DCVCAxon::setSelected(bool selected, bool updateChildren)
+{
+ DCVComponent::setSelected(selected, updateChildren);
+
+ DCCell *cell = getOwnerCell();
+ if (cell)
+ cell->getVComponent()->setSelected(selected, false);
+
+ if (updateChildren)
+ {
+ int len = d_owner->getNumberOfTerminals();
+ for (int i = 0; i < len; ++i)
+ {
+ d_owner->getTerminalAt(i)->getVComponent()->setSelected(selected, true);
+ }
+ }
+}
+
+void DCVCAxon::setVisible(DCVVisibility visibleSelf, DCVVisibility visibleChildren)
+{
+ DCVComponent::setVisible(visibleSelf, visibleChildren);
+ d_owner->setTerminalVisible(visibleChildren != DCV_VISIBLE_NONE);
+}
+
+DCVCPage* DCVCAxon::getPageBelonging() const
+{
+ return getOwnerCell()->getPageBelonging();
+}
+
+void DCVCAxon::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
+{
+ float rad = d_owner->getViewAngle() / 180 * PI;
+ float length = d_owner->getViewLength();
+ if (renderAsWireframe)
+ glColor4f(1.0, 1.0, 1.0, 0.5);
+ else
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable( GL_LINE_SMOOTH );
+ glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
+
+ glBegin(GL_LINES);
+ glVertex3f(0, 0, 0);
+ glVertex3f(-cos(rad)* length, 0, -sin(rad)* length);
+ glEnd();
+
+ glTranslatef(0,0.05,0);
+
+ if (renderAsWireframe)
+ {
+ //render bounding box
+ float hwidth = 0.05;
+ float hheight = 0.05;
+ glLineWidth(1);
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, hheight, -hwidth);
+ glVertex3f(hwidth, hheight, -hwidth);
+ glEnd();
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(hwidth, -hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, -hwidth);
+ glVertex3f(hwidth, -hheight, -hwidth);
+ glEnd();
+ glBegin(GL_LINES);
+ glVertex3f(hwidth, -hheight, hwidth);
+ glVertex3f(hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, hwidth);
+ glVertex3f(-hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, -hwidth);
+ glVertex3f(-hwidth, hheight, -hwidth);
+ glVertex3f(hwidth, -hheight, -hwidth);
+ glVertex3f(hwidth, hheight, -hwidth);
+ glEnd();
+ }
+ else
+ {
+ if (s_shapeTerminalSocket == NULL)
+ {
+ s_shapeTerminalSocket = new DCCubeRenderer(0.1, 0.1, 0,0, true);
+ s_shapeTerminalSocket->setFaceColor(0,0,0);
+ }
+ s_shapeTerminalSocket->draw();
+ }
+ glDisable(GL_BLEND);
+}
+
+DCCell* DCVCAxon::getOwnerCell() const
+{
+ return d_owner->getOwnerCell();
+}
+
+bool DCVCAxon::startDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return true;
+}
+
+bool DCVCAxon::dragging(float x, float y, float z, bool isResizingDrag)
+{
+ if (isResizingDrag)
+ return false;
+
+ DCCell *cell = getOwnerCell();
+ float cellx = cell->getViewPageX();
+ float celly = cell->getViewPageY();
+
+ float dx = x - cellx;
+ float dy = z - celly;
+
+ float len, minX, minY, minLenP, lenP;
+ cell->getViewHCrossPoint(dx,dy,&minX, &minY);
+ minLenP = minX * minX + minY * minY;
+ lenP = dx * dx + dy * dy;
+ len = minLenP < lenP ? sqrt(lenP) : sqrt(minLenP);
+ float angle = atan2(dy,dx) / PI * 180;
+
+ d_owner->setViewLength(len);
+ d_owner->setViewAngle(angle);
+
+ return true;
+}
+
+bool DCVCAxon::endDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return true;
+
+}
+
+void DCVCAxon::updateShape()
+{
+ d_shouldUpdateShape = true;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCAXON_H
+#define DCVCAXON_H
+
+#include "dcvcomponent.h"
+
+#include <QtOpenGL>
+
+class DCAxon;
+class DCCell;
+class DCCubeRenderer;
+
+class DCVCAxon : public DCVComponent
+{
+ DCAxon *d_owner;
+ bool d_shouldUpdateShape;
+
+public:
+ DCVCAxon(DCAxon *owner);
+ virtual ~DCVCAxon();
+
+ virtual DCVCPage * getPageBelonging() const;
+ virtual bool isResizingArea(float x, float y, float z) const { return false; }
+
+ virtual DCCell * getOwnerCell() const;
+
+ virtual void prepareChildrenForDraw(bool isAnimationInterval);
+ virtual void drawChildren(bool isAnimationInterval);
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
+ virtual void translate();
+ virtual void setSelected(bool selected, bool updateChildren = false);
+ virtual void setVisible(DCVVisibility visibleSelf, DCVVisibility visibleChildren);
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe);
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag);
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag);
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag);
+ virtual void updateShape();
+
+ void setLength(float length);
+ void setAngle(float angle);
+};
+
+#endif // DCVCAXON_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvcaxonterminal.h"
+
+#include "dcvcomponent.h"
+#include "dcaxon.h"
+#include "dcreceptor.h"
+#include "dcaxonterminal.h"
+
+#include <QtOpenGL>
+
+static const double PI = 3.14159265358979323846264338327950288419717;
+
+DCVCAxonTerminal::DCVCAxonTerminal(DCAxonTerminal *owner)
+ : d_owner(owner), d_isRendered(false)
+{
+}
+
+void DCVCAxonTerminal::prepareChildrenForDraw(bool isAnimationInterval)
+{
+ d_isRendered = false;
+}
+
+void DCVCAxonTerminal::drawChildren(bool isAnimationInterval)
+{
+}
+
+void DCVCAxonTerminal::drawChildrenForSelection(QList<DCVComponent *> *itemList)
+{
+
+}
+
+void DCVCAxonTerminal::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
+{
+
+ if (d_owner->getIsViewAxonPointUpdated() && d_owner->getIsViewReceptorPointUpdated() && !d_isRendered)
+ {
+ //
+ const float *axonPointMatrix = d_owner->getViewAxonPointMatrix();
+ const float *receptorPointMatrix = d_owner->getViewReceptorPointMatrix();
+
+ float dx = axonPointMatrix[12] - receptorPointMatrix[12];
+ float dy = axonPointMatrix[13] - receptorPointMatrix[13];
+ float dz = axonPointMatrix[14] - receptorPointMatrix[14];
+
+ float receptorX = receptorPointMatrix[12];
+ float receptorY = receptorPointMatrix[13];
+ float receptorZ = receptorPointMatrix[14];
+
+ DCReceptor *receptor = dynamic_cast<DCReceptor*>(d_owner->getTarget());
+ if (receptor)
+ {
+ float ox,oy,oz;
+ receptor->getViewReceptorOffsetPoint(dx,dy,dz, &ox, &oy, &oz);
+ receptorX = receptorPointMatrix[0] * ox + receptorPointMatrix[4] * oy + receptorPointMatrix[8] * oz + receptorPointMatrix[12];
+ receptorY = receptorPointMatrix[1] * ox + receptorPointMatrix[5] * oy + receptorPointMatrix[9] * oz + receptorPointMatrix[13];
+ receptorZ = receptorPointMatrix[2] * ox + receptorPointMatrix[6] * oy + receptorPointMatrix[10] * oz + receptorPointMatrix[14];
+ }
+
+ //render terminal
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glLineWidth(2);
+ glColor4f(0.2, 1.0, 0.4,1.0);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable( GL_LINE_SMOOTH );
+ glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
+
+ glBegin(GL_LINES);
+ glVertex3f(axonPointMatrix[12], axonPointMatrix[13], axonPointMatrix[14]);
+ glVertex3f(receptorX, receptorY, receptorZ);
+ glEnd();
+
+ //arrow
+ float ang1 = atan2(dz,dx)/ PI * 180;
+// float ang2 = atan2(dy,dx)/ PI * 180;
+
+ glTranslatef(receptorX,receptorY,receptorZ);
+ glRotatef(-ang1,0,1,0);
+// glRotatef(ang2,1,0,0);
+ glBegin(GL_LINE_STRIP);
+ glVertex3f(0.08,0,0.04);
+ glVertex3f(0,0,0);
+ glVertex3f(0.08,0,-0.04);
+ glEnd();
+
+ glPopMatrix();
+ glDisable(GL_BLEND);
+ d_isRendered = true;
+ d_owner->resetViewPoinMatrices();
+ }
+}
+
+void DCVCAxonTerminal::translate()
+{
+
+}
+
+DCVComponent::DCVVisibility DCVCAxonTerminal::getIsVisible() const
+{
+ DCAxon *axon = (DCAxon*)d_owner->getOwner();
+ DCReceptor *receptor = (DCReceptor*)d_owner->getTarget();
+ return ((axon && axon->getIsTerminalVisible()) || (receptor && receptor->getIsTerminalVisible())) ?
+ DCV_VISIBLE_FULL : DCV_VISIBLE_NONE;
+}
+
+DCAxonTerminal* DCVCAxonTerminal::getOwnerTerminal() const
+{
+ return d_owner;
+}
+
+DCVComponent* DCVCAxonTerminal::getAxonComponent() const
+{
+ DCAxon *axon = (DCAxon*)d_owner->getOwner();
+ if (axon)
+ {
+ return axon->getVComponent();
+ }
+ return NULL;
+}
+
+DCVComponent* DCVCAxonTerminal::getReceptorComponent() const
+{
+ DCReceptor *receptor = (DCReceptor*)d_owner->getTarget();
+ if (receptor)
+ {
+ return receptor->getVComponent();
+ }
+ return NULL;
+}
+
+DCVCPage* DCVCAxonTerminal::getPageBelonging() const
+{
+ return NULL;
+}
+
+DCCell* DCVCAxonTerminal::getOwnerCell() const
+{
+ DCAxon *axon = (DCAxon*)d_owner->getOwner();
+ if (axon)
+ {
+ return axon->getOwnerCell();
+ }
+ return NULL;
+}
+
+bool DCVCAxonTerminal::startDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCAxonTerminal::dragging(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCAxonTerminal::endDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCAXONTERMINAL_H
+#define DCVCAXONTERMINAL_H
+
+#include "dcvcomponent.h"
+
+class DCAxonTerminal;
+
+class DCVCAxonTerminal : public DCVComponent
+{
+ DCVComponent* getAxonComponent() const;
+ DCVComponent* getReceptorComponent() const;
+
+ DCAxonTerminal *d_owner;
+ bool d_isRendered;
+
+public:
+ DCVCAxonTerminal(DCAxonTerminal *owner);
+
+ virtual DCVVisibility getIsVisible() const;
+ virtual DCVCPage * getPageBelonging() const;
+ virtual DCCell* getOwnerCell() const;
+ virtual bool isResizingArea(float x, float y, float z) const { return false; }
+
+ bool isMatrixUpdated() const;
+ const float* getPointMatrix() const;
+ DCAxonTerminal* getOwnerTerminal() const;
+
+ virtual void prepareChildrenForDraw(bool isAnimationInterval);
+ virtual void drawChildren(bool isAnimationInterval);
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
+ virtual void translate();
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe);
+ virtual void updateShape() {}
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag);
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag);
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag);
+
+};
+
+#endif // DCVCAXONTERMINAL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvccell.h"
+
+#include "dccell.h"
+#include "dccellcode.h"
+#include "dcaxon.h"
+#include "dcreceptor.h"
+#include "dccontainer.h"
+#include "dcscene.h"
+
+#include "dccuberenderer.h"
+#include "dcselectionrenderer.h"
+
+#include <QtOpenGL>
+
+
+static const double CUBE_ROUNDRADIUS = 0.05;
+static const double PI = 3.14159265358979323846264338327950288419717;
+
+DCVCCell::DCVCCell(DCCell *owner, DCVCPage *page, float size, float height)
+ : d_owner(owner), d_page(page), d_shouldUpdateShape(true),
+ d_dragOffsetX(0), d_dragOffsetY(0), d_dragOffsetZ(0), d_draggingOriginalSize(0), d_isDragging(false), d_isResizingDrag(false), d_draggingOriginalAxonLength(0)
+{
+ DCContainer *container = dynamic_cast<DCContainer*> (d_owner->getContainer());
+ if (container)
+ {
+ d_shape = new DCCubeRenderer(size,height, CUBE_ROUNDRADIUS,3, true);
+ d_shouldUpdateShape = true;
+ }
+
+ d_selectionRectRenderer = new DCSelectionRenderer(CUBE_ROUNDRADIUS,CUBE_ROUNDRADIUS);
+}
+
+DCVCCell::~DCVCCell()
+{
+ if (d_shape)
+ delete d_shape;
+
+ if (d_selectionRectRenderer)
+ delete d_selectionRectRenderer;
+
+
+}
+
+void DCVCCell::unregisterFromPage()
+{
+ d_page = NULL;
+}
+
+void DCVCCell::prepareChildrenForDraw(bool isAnimationInterval)
+{
+ const TKReceptorMap *receptors = d_owner->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ ((DCReceptor*)(*it).second)->getVComponent()->prepareForDraw(isAnimationInterval);
+ ++it;
+ }
+ d_owner->getAxon()->getVComponent()->prepareForDraw(isAnimationInterval);
+}
+
+void DCVCCell::drawChildren(bool isAnimationInterval)
+{
+ const TKReceptorMap *receptors = d_owner->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ ((DCReceptor*)(*it).second)->getVComponent()->draw(isAnimationInterval);
+ ++it;
+ }
+ d_owner->getAxon()->getVComponent()->draw(isAnimationInterval);
+}
+
+void DCVCCell::drawChildrenForSelection(QList<DCVComponent *> *itemList)
+{
+ const TKReceptorMap *receptors = d_owner->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ ((DCReceptor*)(*it).second)->getVComponent()->draw(false);
+ ++it;
+ }
+ d_owner->getAxon()->getVComponent()->drawForSelection(itemList);
+}
+
+void DCVCCell::translate()
+{
+ glTranslatef(getPageX() , d_owner->getViewHeight()/2.0, getPageY());
+}
+
+void DCVCCell::setSelected(bool selected, bool updateChildren)
+{
+ DCVComponent::setSelected(selected, updateChildren);
+
+ const TKReceptorMap *receptors = d_owner->getReceptors();
+ if (updateChildren)
+ {
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ ((DCReceptor*)(*it).second)->getVComponent()->setSelected(selected, true);
+ ++it;
+ }
+ d_owner->getAxon()->getVComponent()->setSelected(selected, updateChildren);
+ }
+ d_shouldUpdateShape = true;
+}
+
+void DCVCCell::setVisible(DCVVisibility visibleSelf, DCVVisibility visibleChildren)
+{
+ DCVComponent::setVisible(visibleSelf, visibleChildren);
+
+ const TKReceptorMap *receptors = d_owner->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ ((DCReceptor*)(*it).second)->getVComponent()->setVisible(visibleChildren,visibleChildren);
+ ++it;
+ }
+ d_owner->getAxon()->getVComponent()->setVisible(visibleSelf,visibleChildren);
+}
+
+void DCVCCell::setSelectable(bool selectable)
+{
+ DCVComponent::setSelectable(selectable);
+
+ const TKReceptorMap *receptors = d_owner->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ while( it != receptors->end())
+ {
+ ((DCReceptor*)(*it).second)->getVComponent()->setSelectable(selectable);
+ ++it;
+ }
+ d_owner->getAxon()->getVComponent()->setSelectable(selectable);
+}
+
+void DCVCCell::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
+{
+ if (renderAsWireframe)
+ {
+ //render bounding box
+ float hwidth = d_owner->getViewSize()/2.0;
+ float hheight = d_owner->getViewHeight()/2.0;
+ glLineWidth(1);
+ glColor4f(1.0, 1.0, 1.0,0.5);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable( GL_LINE_SMOOTH );
+ glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, hheight, -hwidth);
+ glVertex3f(hwidth, hheight, -hwidth);
+ glEnd();
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(hwidth, -hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, -hwidth);
+ glVertex3f(hwidth, -hheight, -hwidth);
+ glEnd();
+ glBegin(GL_LINES);
+ glVertex3f(hwidth, -hheight, hwidth);
+ glVertex3f(hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, hwidth);
+ glVertex3f(-hwidth, hheight, hwidth);
+ glVertex3f(-hwidth, -hheight, -hwidth);
+ glVertex3f(-hwidth, hheight, -hwidth);
+ glVertex3f(hwidth, -hheight, -hwidth);
+ glVertex3f(hwidth, hheight, -hwidth);
+ glEnd();
+ glDisable(GL_BLEND);
+ }
+ else
+ {
+ if (d_shouldUpdateShape)
+ {
+ d_shape->setSize(d_owner->getViewSize());
+ d_shape->setHeight(d_owner->getViewHeight());
+
+ QString label1;
+ if (d_owner->getCellCode() && d_owner->getCellCode()->getName() != "_DNEMPTY")
+ {
+ label1 = QString::fromStdString(d_owner->getCellCode()->getName());
+ label1 = label1.mid(label1.lastIndexOf("#") + 1);
+ }
+ else
+ {
+ label1 = "type : " + d_owner->getType();
+ }
+
+ QString label2 = QString::fromStdString(d_owner->getName());
+ d_shape->setTextLabel(label1, label2);
+
+ d_shouldUpdateShape = false;
+ }
+ d_shape->draw();
+
+ if (getIsSelected())
+ {
+ d_selectionRectRenderer->setRectSize(d_owner->getViewSize());
+ glPushMatrix();
+ glTranslatef(0,d_owner->getViewHeight()/2,0);
+ d_selectionRectRenderer->draw(isAnimationInterval && (d_isDragging && !d_isResizingDrag));
+ glPopMatrix();
+ DCScene::setShouldContinueAnimation(true);
+ }
+ }
+}
+
+void DCVCCell::updateShape()
+{
+ d_shouldUpdateShape = true;
+}
+
+bool DCVCCell::startDrag(float x, float y, float z, bool isResizingDrag)
+{
+ d_dragOffsetX = getPageX() - x;
+ d_dragOffsetY = getPageY() - z;
+
+ d_isResizingDrag = isResizingDrag;
+ d_isDragging = true;
+
+ if (isResizingDrag)
+ {
+ d_draggingOriginalSize = d_owner->getViewSize();
+ d_draggingOriginalAxonLength = d_owner->getAxon()->getViewLength();
+ }
+
+ return true;
+}
+
+bool DCVCCell::dragging(float x, float y, float z, bool isResizingDrag)
+{
+ if (isResizingDrag && d_isResizingDrag)
+ {
+ float dx = d_dragOffsetX - getPageX() + x;
+ float dy = d_dragOffsetY - getPageY() + z;
+ float length = sqrt(dx * dx + dy * dy);
+ float dlength = dx < 0 && dy < 0 ? - length : length;
+ float newSize = d_draggingOriginalSize + dlength;
+ d_owner->setViewSize(newSize);
+ float newAxonLength = d_draggingOriginalAxonLength + dlength/2;
+ if (newAxonLength < d_owner->getViewSize()/2)
+ newAxonLength = d_owner->getViewSize()/2;
+ d_owner->getAxon()->setViewLength(newAxonLength);
+ }
+ else
+ {
+ setPageX(d_dragOffsetX + x);
+ setPageY(d_dragOffsetY + z);
+ }
+
+ d_isDragging = true;
+
+ return true;
+}
+
+bool DCVCCell::endDrag(float x, float y, float z, bool isResizingDrag)
+{
+ d_isDragging = false;
+ return true;
+}
+
+bool DCVCCell::isResizingArea(float x, float y, float z) const
+{
+ d_selectionRectRenderer->setRectSize(d_owner->getViewSize());
+ return d_selectionRectRenderer->isResizingArea(x, z);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCCELL_H
+#define DCVCCELL_H
+
+#include "dcvpagecomponent.h"
+
+class DCCell;
+class DCCubeRenderer;
+class DCSelectionRenderer;
+class DCVCPage;
+
+class DCVCCell : public DCVPageComponent
+{
+ DCCell *d_owner;
+ DCVCPage *d_page;
+ DCCubeRenderer *d_shape;
+ bool d_shouldUpdateShape;
+ DCSelectionRenderer *d_selectionRectRenderer;
+ float d_dragOffsetX;
+ float d_dragOffsetY;
+ float d_dragOffsetZ;
+ float d_draggingOriginalSize;
+ bool d_isDragging;
+ bool d_isResizingDrag;
+ float d_draggingOriginalAxonLength;
+
+public:
+ DCVCCell(DCCell *owner, DCVCPage *page, float size, float height);
+ virtual ~DCVCCell();
+
+
+ virtual DCCell* getOwnerCell() const { return d_owner; }
+ virtual DCVCPage * getPageBelonging() const{ return d_page; }
+ virtual bool isResizingArea(float x, float y, float z) const;
+
+ virtual void unregisterFromPage();
+ virtual void prepareChildrenForDraw(bool isAnimationInterval);
+ virtual void drawChildren(bool isAnimationInterval);
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
+ virtual void translate();
+ virtual void setSelected(bool selected, bool updateChildren);
+ virtual void setVisible(DCVVisibility visible, DCVVisibility visibleChildren);
+ virtual void setSelectable(bool selectable);
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe);
+ virtual void updateShape();
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag);
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag);
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag);
+
+ void addReceptor();
+};
+
+#endif // DCVCCELL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvccellcode.h"
+
+#include "dcvcomponent.h"
+
+DCVCCellCode::DCVCCellCode(DCCellCode *owner)
+{
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCCELLCODE_H
+#define DCVCCELLCODE_H
+
+#include "dcvcomponent.h"
+
+class DCCellCode;
+
+class DCVCCellCode : public DCVComponent
+{
+public:
+ DCVCCellCode(DCCellCode *owner);
+
+ virtual DCVCPage * getPageBelonging() const { return NULL; }
+ virtual DCCell * getOwnerCell() const { return NULL; }
+ virtual bool isResizingArea(float x, float y, float z) const { return false; }
+
+ virtual void prepareChildrenForDraw(bool isAnimationInterval) {}
+ virtual void drawChildren(bool isAnimationInterval) {}
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList) {}
+ virtual void translate() {}
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe) {}
+ virtual void updateShape() {}
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag){return false;}
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag){return false;}
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag){return false; }
+
+};
+
+#endif // DCVCCELLCODE_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvceditmodecursor.h"
+
+#include "utils/dccomponentutil.h"
+#include "dcvceditmodeterminal.h"
+#include "dccell.h"
+#include "dcaxon.h"
+#include "dcreceptor.h"
+#include "dcvcpage.h"
+
+#include <QtOpenGL>
+
+//TEMP
+#include "dccuberenderer.h"
+static DCCubeRenderer *s_cursorShape = NULL;
+
+DCVCEditModeCursor::DCVCEditModeCursor()
+ : d_ownerCell(NULL), d_ownerAxon(NULL), d_ownerReceptor(NULL), d_page(NULL),
+ d_cursorType(DCV_CURSOR_NONE), d_dropTarget(NULL), d_dragOffsetX(0), d_dragOffsetY(0), d_isDragging(false)
+{
+ d_terminal = new DCVCEditModeTerminal;
+}
+
+DCVCEditModeCursor::~DCVCEditModeCursor()
+{
+ if (d_terminal)
+ {
+ delete d_terminal;
+ d_terminal = NULL;
+ }
+}
+
+
+void DCVCEditModeCursor::setOwnerFromAxon(DCAxon *owner)
+{
+ if (d_ownerAxon)
+ {
+ d_ownerAxon->unregisterEditCursor();
+ }
+
+ d_ownerAxon = owner;
+ d_ownerCell = d_ownerAxon->getOwnerCell();
+ d_cursorType = DCV_CURSOR_FROM_AXON;
+ if (d_ownerCell)
+ {
+ setPageBelonging(d_ownerCell->getPageBelonging());
+ setVisible(DCVComponent::DCV_VISIBLE_FULL, DCVComponent::DCV_VISIBLE_FULL);
+ owner->registerEditCursor(this);
+ }
+ else
+ {
+ setPageBelonging(NULL);
+ setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE);
+ }
+}
+
+void DCVCEditModeCursor::setOwnerFromReceptor(DCReceptor *owner)
+{
+ if (d_ownerReceptor)
+ {
+ d_ownerReceptor->unregisterEditCursor();
+ }
+
+ d_ownerReceptor = owner;
+ d_ownerCell = dynamic_cast<DCCell*>(owner->getOwnerCell());
+ if (d_ownerReceptor && d_ownerCell)
+ {
+ d_cursorType = DCV_CURSOR_FROM_RECEPTAOR;
+ setPageBelonging(d_ownerCell->getPageBelonging());
+ setVisible(DCVComponent::DCV_VISIBLE_FULL, DCVComponent::DCV_VISIBLE_FULL);
+ owner->registerEditCursor(this);
+ }
+ else
+ {
+ setPageBelonging(NULL);
+ setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE);
+ }
+}
+
+void DCVCEditModeCursor::unsetCursor()
+{
+ if (d_ownerAxon)
+ {
+ d_ownerAxon->unregisterEditCursor();
+ d_ownerAxon = NULL;
+ }
+ if (d_ownerReceptor)
+ {
+ d_ownerReceptor->unregisterEditCursor();
+ d_ownerReceptor = NULL;
+ }
+ d_ownerCell = NULL;
+ setPageBelonging(NULL);
+ setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE);
+}
+
+void DCVCEditModeCursor::setPageBelonging(DCVCPage *page)
+{
+ bool changed = false;
+ if (d_page != page)
+ {
+ if (d_page)
+ {
+ d_page->unregisterEditCursor();
+ }
+ changed = true;
+ }
+ d_page = page;
+ if (d_page)
+ d_page->registerEditCursor(this);
+
+ if (changed)
+ emit pageBelongingChanged(page);
+}
+
+void DCVCEditModeCursor::setDropTarget(DCVComponent *dropTarget)
+{
+ bool changed = false;
+ if (d_dropTarget != dropTarget)
+ {
+ d_dropTarget = dropTarget;
+ changed = true;
+ }
+
+ if (changed)
+ emit dropTargetChanged(dropTarget);
+}
+
+bool DCVCEditModeCursor::isResizingArea(float x, float y, float z) const
+{
+ return false;
+}
+
+void DCVCEditModeCursor::unregisterFromPage()
+{
+ d_page = NULL;
+}
+
+void DCVCEditModeCursor::prepareChildrenForDraw(bool isAnimationInterval)
+{
+ float matrix[16];
+
+ switch(d_cursorType)
+ {
+ case DCV_CURSOR_FROM_AXON:
+ glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
+ d_terminal->setViewMatrixForReceptorPoint(NULL, matrix);
+ break;
+
+ case DCV_CURSOR_FROM_RECEPTAOR:
+ glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
+ d_terminal->setViewMatrixForAxonPoint(matrix);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void DCVCEditModeCursor::drawChildren(bool isAnimationInterval)
+{
+ d_terminal->draw(isAnimationInterval);
+}
+
+void DCVCEditModeCursor::drawChildrenForSelection(QList<DCVComponent*> *itemList)
+{
+ d_terminal->drawForSelection(itemList);
+}
+
+void DCVCEditModeCursor::translate()
+{
+ glTranslatef(getPageX() , 0.15, getPageY());
+}
+
+void DCVCEditModeCursor::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
+{
+ if (!s_cursorShape)
+ {
+ s_cursorShape = new DCCubeRenderer(0.3,0.3, 0.01, 1);
+ }
+ s_cursorShape->draw();
+}
+
+bool DCVCEditModeCursor::startDrag(float x, float y, float z, bool isResizingDrag)
+{
+ d_dragOffsetX = getPageX() - x;
+ d_dragOffsetY = getPageY() - z;
+
+ d_isDragging = true;
+
+ return true;
+}
+
+bool DCVCEditModeCursor::dragging(float x, float y, float z, bool isResizingDrag)
+{
+ setPageX(d_dragOffsetX + x);
+ setPageY(d_dragOffsetY + z);
+ d_isDragging = true;
+ return true;
+}
+
+bool DCVCEditModeCursor::endDrag(float x, float y, float z, bool isResizingDrag)
+{
+ d_isDragging = false;
+ return true;
+}
+
+void DCVCEditModeCursor::updateShape()
+{
+ delete s_cursorShape;
+ s_cursorShape = NULL;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCEDIRMODECURSOR_H
+#define DCVCEDIRMODECURSOR_H
+
+#include "dcvpagecomponent.h"
+
+class DCCell;
+class DCAxon;
+class DCReceptor;
+class DCVCPage;
+class DCVCEditModeTerminal;
+
+#include <QObject>
+
+class DCVCEditModeCursor : public QObject, public DCVPageComponent
+{
+ Q_OBJECT
+
+public:
+ enum DCVEditCursorType { DCV_CURSOR_NONE, DCV_CURSOR_FROM_AXON, DCV_CURSOR_FROM_RECEPTAOR};
+
+private:
+ DCCell *d_ownerCell;
+ DCAxon *d_ownerAxon;
+ DCReceptor *d_ownerReceptor;
+ DCVCPage *d_page;
+ DCVEditCursorType d_cursorType;
+ DCVCEditModeTerminal *d_terminal;
+ DCVComponent *d_dropTarget;
+ float d_dragOffsetX;
+ float d_dragOffsetY;
+ bool d_isDragging;
+
+public:
+ DCVCEditModeCursor();
+ virtual ~DCVCEditModeCursor();
+
+ virtual DCVCPage* getPageBelonging() const { return d_page; }
+ virtual DCCell* getOwnerCell() const { return d_ownerCell; }
+ virtual bool isResizingArea(float x, float y, float z) const;
+ DCVCEditModeTerminal* getTerminal() const { return d_terminal; }
+ bool getIsDragging() const { return d_isDragging; }
+ DCVComponent* getDropTarget() const { return d_dropTarget; }
+
+ void setOwnerFromAxon(DCAxon *owner);
+ void setOwnerFromReceptor(DCReceptor *owner);
+ void setPageBelonging(DCVCPage *page);
+ void setDropTarget(DCVComponent *dropTarget);
+ void unsetCursor();
+
+ virtual void unregisterFromPage();
+ virtual void prepareChildrenForDraw(bool isAnimationInterval);
+ virtual void drawChildren(bool isAnimationInterval);
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
+ virtual void translate();
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe);
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag);
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag);
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag);
+
+ virtual void updateShape();
+
+signals:
+ void pageBelongingChanged(DCVCPage *currentPage);
+ void dropTargetChanged(DCVComponent *currentTarget);
+};
+
+#endif // DCVCEDIRMODECURSOR_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvceditmodeterminal.h"
+
+#include "dcreceptor.h"
+
+#include <QtOpenGL>
+
+static const double PI = 3.14159265358979323846264338327950288419717;
+
+DCVCEditModeTerminal::DCVCEditModeTerminal() :
+ d_isViewReceptorPointUpdated(false),d_isViewAxonPointUpdated(false),d_isRendered(false)
+{
+}
+
+DCVCEditModeTerminal::~DCVCEditModeTerminal()
+{
+
+}
+
+DCCell* DCVCEditModeTerminal::getOwnerCell() const
+{
+ return NULL;
+}
+
+bool DCVCEditModeTerminal::isResizingArea(float x, float y, float z) const
+{
+ return false;
+}
+
+void DCVCEditModeTerminal::prepareChildrenForDraw(bool isAnimationInterval)
+{
+ d_isRendered = false;
+}
+
+void DCVCEditModeTerminal::drawChildren(bool isAnimationInterval)
+{
+
+}
+
+void DCVCEditModeTerminal::drawChildrenForSelection(QList<DCVComponent*> *itemList)
+{
+
+}
+
+void DCVCEditModeTerminal::translate()
+{
+
+}
+
+void DCVCEditModeTerminal::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
+{
+ if (d_isViewAxonPointUpdated && d_isViewReceptorPointUpdated && !d_isRendered)
+ {
+ //
+ float dx = d_viewAxonPointMatrix[12] - d_viewReceptorPointMatrix[12];
+ float dy = d_viewAxonPointMatrix[13] - d_viewReceptorPointMatrix[13];
+ float dz = d_viewAxonPointMatrix[14] - d_viewReceptorPointMatrix[14];
+
+ float receptorX = d_viewReceptorPointMatrix[12];
+ float receptorY = d_viewReceptorPointMatrix[13];
+ float receptorZ = d_viewReceptorPointMatrix[14];
+
+ if (d_receptor)
+ {
+ float ox,oy,oz;
+ d_receptor->getViewReceptorOffsetPoint(dx,dy,dz, &ox, &oy, &oz);
+ receptorX = d_viewReceptorPointMatrix[0] * ox + d_viewReceptorPointMatrix[4] * oy + d_viewReceptorPointMatrix[8] * oz + d_viewReceptorPointMatrix[12];
+ receptorY = d_viewReceptorPointMatrix[1] * ox + d_viewReceptorPointMatrix[5] * oy + d_viewReceptorPointMatrix[9] * oz + d_viewReceptorPointMatrix[13];
+ receptorZ = d_viewReceptorPointMatrix[2] * ox + d_viewReceptorPointMatrix[6] * oy + d_viewReceptorPointMatrix[10] * oz + d_viewReceptorPointMatrix[14];
+ }
+
+ //render terminal
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glLineWidth(1);
+ glColor4f(1.0, 1.0, 1.0,1.0);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable( GL_LINE_SMOOTH );
+ glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
+
+ glBegin(GL_LINES);
+ glVertex3f(d_viewAxonPointMatrix[12], d_viewAxonPointMatrix[13], d_viewAxonPointMatrix[14]);
+ glVertex3f(receptorX, receptorY, receptorZ);
+ glEnd();
+
+ //arrow
+ float ang1 = atan2(dz,dx)/ PI * 180;
+// float ang2 = atan2(dy,dx)/ PI * 180;
+
+ glTranslatef(receptorX,receptorY,receptorZ);
+ glRotatef(-ang1,0,1,0);
+// glRotatef(ang2,1,0,0);
+ glBegin(GL_LINE_STRIP);
+ glVertex3f(0.08,0,0.04);
+ glVertex3f(0,0,0);
+ glVertex3f(0.08,0,-0.04);
+ glEnd();
+
+ glPopMatrix();
+ glDisable(GL_BLEND);
+ d_isRendered = true;
+
+ resetViewPoinMatrices();
+ }
+}
+
+bool DCVCEditModeTerminal::startDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCEditModeTerminal::dragging(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCEditModeTerminal::endDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+void DCVCEditModeTerminal::updateShape()
+{
+
+}
+
+void DCVCEditModeTerminal::setViewMatrixForAxonPoint(const float matrix[])
+{
+ for (int i = 0; i < 16; i++)
+ {
+ d_viewAxonPointMatrix[i] = matrix[i];
+ }
+
+ d_isViewAxonPointUpdated = true;
+}
+
+void DCVCEditModeTerminal::setViewMatrixForReceptorPoint(DCReceptor *receptor, const float matrix[])
+{
+ for (int i = 0; i < 16; i++)
+ {
+ d_viewReceptorPointMatrix[i] = matrix[i];
+ }
+
+ d_receptor = receptor;
+ d_isViewReceptorPointUpdated = true;
+}
+
+void DCVCEditModeTerminal::resetViewPoinMatrices()
+{
+ d_isViewAxonPointUpdated = false;
+ d_isViewReceptorPointUpdated = false;
+ d_isRendered = false;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCEDITMODETERMINAL_H
+#define DCVCEDITMODETERMINAL_H
+
+#include "dcvcomponent.h"
+
+class DCReceptor;
+
+class DCVCEditModeTerminal : public DCVComponent
+{
+ bool d_isViewReceptorPointUpdated;
+ bool d_isViewAxonPointUpdated;
+ bool d_isRendered;
+ float d_viewAxonPointMatrix[16];
+ float d_viewReceptorPointMatrix[16];
+ DCReceptor *d_receptor;
+
+public:
+ DCVCEditModeTerminal();
+ virtual ~DCVCEditModeTerminal();
+
+ bool getIsViewAxonPointUpdated() const { return d_isViewAxonPointUpdated; }
+ bool getIsViewReceptorPointUpdated() const { return d_isViewReceptorPointUpdated; }
+ const float* getViewAxonPointMatrix() const { return d_viewAxonPointMatrix; }
+ const float* getViewReceptorPointMatrix() const { return d_viewReceptorPointMatrix; }
+
+ void setViewMatrixForAxonPoint(const float matrix[16]);
+ void setViewMatrixForReceptorPoint(DCReceptor *receptor, const float matrix[16]);
+ void resetViewPoinMatrices();
+
+ virtual DCVCPage* getPageBelonging() const { return NULL; }
+ virtual DCCell* getOwnerCell() const;
+ virtual bool isResizingArea(float x, float y, float z) const;
+
+ virtual void prepareChildrenForDraw(bool isAnimationInterval);
+ virtual void drawChildren(bool isAnimationInterval);
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
+ virtual void translate();
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe);
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag);
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag);
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag);
+
+ virtual void updateShape();
+};
+
+#endif // DCVCEDITMODETERMINAL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvcomponent.h"
+
+#include <QtOpenGL>
+
+DCVComponent::DCVComponent() :
+ d_isVisible(DCV_VISIBLE_FULL), d_isSelectable(true), d_isSelected(false)
+{
+}
+
+void DCVComponent::prepareForDraw(bool isAnimationInterval)
+{
+ glPushMatrix();
+ translate();
+ prepareChildrenForDraw(isAnimationInterval);
+ glPopMatrix();
+}
+
+void DCVComponent::draw(bool isAnimationInterval)
+{
+
+ glPushMatrix();
+ translate();
+ glGetDoublev(GL_MODELVIEW_MATRIX, d_modelview);
+ DCVVisibility visibility = getIsVisible();
+ if (visibility != DCV_VISIBLE_NONE)
+ renderOwnShape(isAnimationInterval, visibility == DCV_VISIBLE_WIREFRAME);
+ drawChildren(isAnimationInterval);
+ glPopMatrix();
+}
+
+void DCVComponent::drawForSelection(QList<DCVComponent*> *itemList)
+{
+ glLoadName(itemList->size());
+ itemList->append(this);
+ glPushMatrix();
+ translate();
+ if (getIsVisible() != DCV_VISIBLE_NONE && getIsSelectable())
+ renderOwnShapeForSelection();
+ drawChildrenForSelection(itemList);
+ glPopMatrix();
+}
+
+void DCVComponent::renderOwnShapeForSelection()
+{
+ if (getIsVisible() == DCV_VISIBLE_NONE)
+ return;
+
+ renderOwnShape(false, DCV_VISIBLE_FULL);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCOMPONENT_H
+#define DCVCOMPONENT_H
+
+#include <QtGui>
+
+class DCVCPage;
+class DCCell;
+
+class DCVComponent
+{
+public:
+ enum DCVVisibility {DCV_VISIBLE_FULL, DCV_VISIBLE_WIREFRAME, DCV_VISIBLE_NONE };
+
+private:
+ double d_modelview[16];
+ DCVVisibility d_isVisible;
+ bool d_isSelectable;
+ bool d_isSelected;
+
+public:
+ DCVComponent();
+ virtual ~DCVComponent() {}
+
+ virtual DCVCPage * getPageBelonging() const = 0;
+ virtual DCCell* getOwnerCell() const = 0;
+ virtual bool isResizingArea(float x, float y, float z) const = 0;
+ virtual DCVVisibility getIsVisible() const { return d_isVisible; }
+ virtual bool getIsSelectable() const { return d_isSelectable; }
+ virtual bool getIsSelected() const { return d_isSelected; }
+ virtual const double * getModelViewMatrix() const { return d_modelview; }
+
+ virtual void prepareChildrenForDraw(bool isAnimationInterval) = 0;
+ virtual void drawChildren(bool isAnimationInterval) = 0;
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList) = 0;
+ virtual void translate() = 0;
+ virtual void setVisible(DCVVisibility visibleSelf, DCVVisibility childrenAreVisible) { d_isVisible = visibleSelf; }
+ virtual void setSelectable(bool selectable) { d_isSelectable = selectable; }
+ virtual void setSelected(bool selectedSelf, bool updateChildren) { d_isSelected = selectedSelf; }
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe) = 0;
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag) = 0;
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag) = 0;
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag) = 0;
+
+ virtual void prepareForDraw(bool isAnimationInterval);
+ virtual void draw(bool isAnimationInterval);
+ virtual void drawForSelection(QList<DCVComponent*> *itemList);
+ virtual void renderOwnShapeForSelection();
+ virtual void updateShape() = 0;
+
+};
+
+#endif // DCVCOMPONENT_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvcpage.h"
+
+#include "dcvcomponent.h"
+#include "dcvpagecomponent.h"
+#include "dcvccell.h"
+#include "dcvccellcode.h"
+#include "dccell.h"
+#include "utils/dccomponentutil.h"
+
+#include <QtOpenGL>
+
+DCVCPage::DCVCPage(const QString &locationPath) :
+ d_locationPath(locationPath), d_height(0), d_width(10), d_depth(6), d_shouldUpdateShape(true),
+ d_colorR(0), d_colorG(0), d_colorB(0), d_colorA(0), d_editCursor(NULL)
+{
+}
+
+DCVCPage::~DCVCPage()
+{
+ while (!d_cells.isEmpty())
+ {
+ DCVPageComponent *cell = d_cells.takeFirst();
+ if (cell)
+ {
+ cell->unregisterFromPage();
+ }
+ }
+}
+
+void DCVCPage::registerCell(DCVPageComponent *cell)
+{
+ if (cell)
+ {
+ d_cells.append(cell);
+ }
+}
+
+void DCVCPage::unregisterCell(DCVPageComponent *cell)
+{
+ if (cell)
+ {
+ d_cells.removeOne(cell);
+ }
+}
+
+void DCVCPage::registerEditCursor(DCVPageComponent *ecursor)
+{
+ d_editCursor = ecursor;
+}
+
+void DCVCPage::unregisterEditCursor()
+{
+ d_editCursor = NULL;
+}
+
+void DCVCPage::updateVisiblity(bool linkedCellVisible, bool linkedCellRenderFull, bool linkedCellSelectable, bool otherCellVisible, bool otherCellRenderFull, bool otherCellSelectable)
+{
+ setVisible(linkedCellVisible || otherCellVisible ? DCV_VISIBLE_FULL : DCV_VISIBLE_NONE, linkedCellVisible || otherCellVisible ? DCV_VISIBLE_FULL : DCV_VISIBLE_NONE);
+
+ for (int i = 0; i < d_cells.size(); ++i)
+ {
+ DCVComponent *vcell = d_cells.at(i);
+ if (vcell->getIsSelected())
+ {
+ vcell->setVisible(DCV_VISIBLE_FULL,DCV_VISIBLE_FULL);
+ vcell->setSelectable(true);
+ }
+ else
+ {
+ if (linkedCellVisible && otherCellVisible && linkedCellRenderFull == otherCellRenderFull && linkedCellSelectable == otherCellSelectable)
+ {
+ vcell->setVisible(linkedCellRenderFull ? DCV_VISIBLE_FULL : DCV_VISIBLE_WIREFRAME, linkedCellRenderFull ? DCV_VISIBLE_FULL : DCV_VISIBLE_NONE);
+ vcell->setSelectable(linkedCellSelectable);
+ }
+ else
+ {
+ if(DCComponentUtil::isConnectedToSelectedCell(vcell))
+ {
+ if (linkedCellVisible)
+ vcell->setVisible(linkedCellRenderFull ? DCV_VISIBLE_FULL : DCV_VISIBLE_WIREFRAME, linkedCellRenderFull ? DCV_VISIBLE_FULL : DCV_VISIBLE_NONE);
+ else
+ vcell->setVisible(DCV_VISIBLE_NONE, DCV_VISIBLE_NONE);
+ vcell->setSelectable(linkedCellSelectable);
+ }
+ else
+ {
+ if (otherCellVisible)
+ vcell->setVisible(otherCellRenderFull ? DCV_VISIBLE_FULL : DCV_VISIBLE_WIREFRAME, otherCellRenderFull ? DCV_VISIBLE_FULL : DCV_VISIBLE_NONE);
+ else
+ vcell->setVisible(DCV_VISIBLE_NONE, DCV_VISIBLE_NONE);
+ vcell->setSelectable(otherCellSelectable);
+ }
+ }
+ }
+ }
+}
+
+
+void DCVCPage::prepareChildrenForDraw(bool isAnimationInterval)
+{
+ for (int i = 0; i < d_cells.size(); ++i)
+ {
+ d_cells.at(i)->prepareForDraw(isAnimationInterval);
+ }
+ if (d_editCursor)
+ {
+ d_editCursor->prepareForDraw(isAnimationInterval);
+ }
+}
+
+void DCVCPage::drawChildren(bool isAnimationInterval)
+{
+ for (int i = 0; i < d_cells.size(); ++i)
+ {
+ d_cells.at(i)->draw(isAnimationInterval);
+ }
+ if (d_editCursor)
+ {
+ d_editCursor->draw(isAnimationInterval);
+ }
+}
+
+void DCVCPage::drawChildrenForSelection(QList<DCVComponent *> *itemList)
+{
+ for (int i = 0; i < d_cells.size(); ++i)
+ {
+ d_cells.at(i)->drawForSelection(itemList);
+ }
+ if (d_editCursor)
+ {
+ d_editCursor->drawForSelection(itemList);
+ }
+}
+
+void DCVCPage::translate()
+{
+ glTranslatef(0,d_height,0);
+}
+
+void DCVCPage::setSelected(bool isSelected, bool updateChildren)
+{
+ DCVComponent::setSelected(isSelected, updateChildren);
+
+ d_shouldUpdateShape = true;
+
+ if (updateChildren)
+ {
+ for (int i = 0; i < d_cells.size(); ++i)
+ {
+ d_cells.at(i)->setSelected(isSelected, true);
+ }
+ }
+}
+
+void DCVCPage::setVisible(DCVVisibility visibleSelf, DCVVisibility visibleChildren)
+{
+ DCVComponent::setVisible(visibleSelf, visibleChildren);
+}
+
+void DCVCPage::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
+{
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+ glColor4f(d_colorR, d_colorG, d_colorB, d_colorA);
+ glBegin(GL_QUADS);
+ glVertex3f(-d_width/2.0, -0.01, -d_depth/2.0);
+ glVertex3d(-d_width/2.0, -0.01, d_depth/2.0);
+ glVertex3d( d_width/2.0, -0.01, d_depth/2.0);
+ glVertex3d( d_width/2.0, -0.01, -d_depth/2.0);
+ glEnd();
+ glDisable(GL_BLEND);
+ glEnable(GL_DEPTH_TEST);
+
+ glEndList();
+}
+
+
+void DCVCPage::setHeight(float height)
+{
+ d_height = height;
+}
+
+void DCVCPage::setWidth(float width)
+{
+ if (d_width != width)
+ {
+ d_width = width;
+ d_shouldUpdateShape = true;
+ }
+}
+
+void DCVCPage::setDepth(float depth)
+{
+ if (d_depth != depth)
+ {
+ d_depth = depth;
+ d_shouldUpdateShape = true;
+ }
+}
+
+void DCVCPage::setColor(float r, float g, float b, float a)
+{
+ d_colorR = r;
+ d_colorG = g;
+ d_colorB = b;
+ d_colorA = a;
+}
+
+bool DCVCPage::startDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCPage::dragging(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCPage::endDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCPAGE_H
+#define DCVCPAGE_H
+
+#include "dcvcomponent.h"
+
+class DCVCCell;
+class DCVCCellCode;
+class DCVPageComponent;
+
+class DCVCPage : public DCVComponent
+{
+ QString d_locationPath;
+ float d_height;
+ float d_width;
+ float d_depth;
+ bool d_shouldUpdateShape;
+ float d_colorR;
+ float d_colorG;
+ float d_colorB;
+ float d_colorA;
+
+ QList<DCVPageComponent*> d_cells;
+ DCVPageComponent *d_editCursor;
+
+public:
+ DCVCPage(const QString &locationPath);
+ virtual ~DCVCPage();
+
+ virtual DCVCPage * getPageBelonging() const { return const_cast<DCVCPage*>(this);}
+ virtual DCCell* getOwnerCell() const { return NULL; }
+ virtual DCVVisibility getIsVisible() const { return d_colorA == 0 ? DCV_VISIBLE_NONE : DCVComponent::getIsVisible(); }
+ virtual bool isResizingArea(float x, float y, float z) const { return false; }
+ QString getLocationPath() const { return d_locationPath; }
+
+ void registerCell(DCVPageComponent *cell);
+ void unregisterCell(DCVPageComponent *cell);
+
+ void registerEditCursor(DCVPageComponent *ecursor);
+ void unregisterEditCursor();
+
+ void updateVisiblity(bool linkedCellVisible, bool linkedCellRenderFull, bool linkedCellSelectable, bool otherCellVisible, bool otherCellRenderFull, bool otherCellSelectable);
+
+ virtual void prepareChildrenForDraw(bool isAnimationInterval);
+ virtual void drawChildren(bool isAnimationInterval);
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
+ virtual void translate();
+ virtual void setSelected(bool selected, bool updateChildren);
+ virtual void setVisible(DCVVisibility visibleSelf, DCVVisibility visibleChildren);
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe);
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag);
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag);
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag);
+ virtual void updateShape() {}
+
+ void setHeight(float height);
+ void setWidth(float width);
+ void setDepth(float depth);
+ void setColor(float r, float g, float b, float a);
+};
+
+#endif // DCVCPAGE_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvcreceptor.h"
+
+#include "dcvcomponent.h"
+#include "dcaxonterminal.h"
+#include "dccell.h"
+
+#include "dcreceptor.h"
+#include "dccontainer.h"
+
+#include "dcvceditmodecursor.h"
+
+#include <QtOpenGL>
+
+DCVCReceptor::DCVCReceptor(DCReceptor *owner) : d_owner(owner), d_matrixUpdated(false), d_size(0.1)
+{
+}
+
+void DCVCReceptor::prepareChildrenForDraw(bool isAnimationInterval)
+{
+ float matrix[16];
+ glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
+
+ DCVComponent *vterminal = getTerminalComponent();
+ if (vterminal)
+ {
+ ((DCAxonTerminal*)d_owner->getTarget())->setViewMatrixForReceptorPoint(matrix);
+ vterminal->prepareForDraw(isAnimationInterval);
+ }
+ if (d_owner->hasEditCursor())
+ {
+ d_owner->setEditingCursorViewMatrix(matrix);
+ }
+}
+
+void DCVCReceptor::drawChildren(bool isAnimationInterval)
+{
+ DCVComponent *vterminal = getTerminalComponent();
+ if (vterminal)
+ {
+ vterminal->draw(isAnimationInterval);
+ }
+}
+
+void DCVCReceptor::drawChildrenForSelection(QList<DCVComponent *> *itemList)
+{
+ DCVComponent *vterminal = getTerminalComponent();
+ if (vterminal)
+ {
+ vterminal->drawForSelection(itemList);
+ }
+}
+
+void DCVCReceptor::translate()
+{
+ glTranslatef(0, -0.245, 0);
+}
+
+void DCVCReceptor::setSelected(bool selected, bool updateChildren)
+{
+ DCVComponent::setSelected(selected,updateChildren);
+
+ DCVComponent *vterminal = getTerminalComponent();
+ if (updateChildren)
+ {
+ if (vterminal)
+ {
+ vterminal->setSelected(selected, true);
+ }
+ }
+}
+
+void DCVCReceptor::setVisible(DCVVisibility visibleSelf, DCVVisibility visibleChildren)
+{
+ DCVComponent::setVisible(visibleSelf, visibleChildren);
+ d_owner->setTerminalVisible(visibleChildren != DCV_VISIBLE_NONE);
+}
+
+void DCVCReceptor::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
+{
+ //TODO
+}
+
+DCVComponent* DCVCReceptor::getTerminalComponent() const
+{
+ DCAxonTerminal *terminal = (DCAxonTerminal*)d_owner->getTarget();
+ if (terminal)
+ {
+ return terminal->getVComponent();
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+bool DCVCReceptor::isMatrixUpdated() const
+{
+ return d_matrixUpdated;
+}
+
+const float* DCVCReceptor::getPointMatrix() const
+{
+ return &d_matrix[0];
+}
+
+DCCell* DCVCReceptor::getOwnerCell() const
+{
+ return dynamic_cast<DCCell*>(d_owner->getOwnerCell());
+}
+
+DCVCPage* DCVCReceptor::getPageBelonging() const
+{
+ return getOwnerCell()->getPageBelonging();
+}
+
+bool DCVCReceptor::startDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCReceptor::dragging(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
+bool DCVCReceptor::endDrag(float x, float y, float z, bool isResizingDrag)
+{
+ return false;
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVCRECEPTOR_H
+#define DCVCRECEPTOR_H
+
+#include "dcvcomponent.h"
+
+class DCReceptor;
+class DCCell;
+
+class DCVCReceptor : public DCVComponent
+{
+ DCVComponent *getTerminalComponent() const;
+
+ DCReceptor *d_owner;
+ float d_matrix[16];
+ bool d_matrixUpdated;
+ float d_size;
+
+public:
+ DCVCReceptor(DCReceptor *owner);
+
+ virtual DCVCPage * getPageBelonging() const;
+ virtual bool isResizingArea(float x, float y, float z) const { return false; }
+
+ bool isMatrixUpdated() const;
+ const float* getPointMatrix() const;
+ virtual DCCell* getOwnerCell() const;
+
+ virtual void prepareChildrenForDraw(bool isAnimationInterval);
+ virtual void drawChildren(bool isAnimationInterval);
+ virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
+ virtual void translate();
+ virtual void setSelected(bool selected, bool updateChildren);
+ virtual void setVisible(DCVVisibility visibleSelf, DCVVisibility visibleChildren);
+ virtual void renderOwnShape(bool isAnimationInterval, bool renderAsWireframe);
+ virtual void updateShape() {}
+
+ virtual bool startDrag(float x, float y, float z, bool isResizingDrag);
+ virtual bool dragging(float x, float y, float z, bool isResizingDrag);
+ virtual bool endDrag(float x, float y, float z, bool isResizingDrag);
+};
+
+#endif // DCVCRECEPTOR_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVPAGECOMPONENT_H
+#define DCVPAGECOMPONENT_H
+
+#include "dcvcomponent.h"
+
+class DCVCPage;
+
+class DCVPageComponent : public DCVComponent
+{
+ float d_pageX;
+ float d_pageY;
+
+public:
+ DCVPageComponent() : d_pageX(0), d_pageY(0) {}
+ virtual ~DCVPageComponent() {}
+
+ virtual void unregisterFromPage() = 0;
+
+ virtual float getPageX() const { return d_pageX; }
+ virtual float getPageY() const { return d_pageY; }
+
+ virtual void setPageX(float x) { d_pageX = x; }
+ virtual void setPageY(float y) { d_pageY = y; }
+
+};
+
+#endif // DCVPAGECOMPONENT_H
--- /dev/null
+/*
+ * cuberenderer.cpp
+ *
+ * CubeRenderer class - rendering rounded cube
+ *
+ * Copyright (C) 2010 Takuji Kawata
+ */
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+
+#include "TKLog.h"
+#include "dccuberenderer.h"
+#include "dcglwidget.h"
+
+#include <math.h>
+#include <stdio.h>
+#include <GL/gl.h>
+
+static const double PI = 3.14159265358979323846264338327950288419717;
+
+typedef float Mat3x3_t[3][3];
+
+// no transform
+Mat3x3_t MATRIX_BASE = {
+ { 1, 0, 0 },
+ { 0, 1, 0 },
+ { 0, 0, 1 }};
+// y rotate 90
+Mat3x3_t MATRIX_Y90 = {
+ { 0, 0, 1},
+ { 0, 1, 0},
+ {-1, 0, 0}};
+// y rotate 180
+Mat3x3_t MATRIX_Y180 = {
+ {-1, 0, 0},
+ { 0, 1, 0},
+ { 0, 0,-1}};
+// y rotate 270
+Mat3x3_t MATRIX_Y270 = {
+ { 0, 0,-1},
+ { 0, 1, 0},
+ { 1, 0, 0}};
+// z rotate 90
+Mat3x3_t MATRIX_Z90 = {
+ { 0,-1, 0},
+ { 1, 0, 0},
+ { 0, 0, 1}};
+// z rotate 180
+Mat3x3_t MATRIX_Z180 = {
+ {-1, 0, 0},
+ { 0,-1, 0},
+ { 0, 0, 1}};
+// y roate 90 + x rotate 90
+Mat3x3_t MATRIX_Y90X90 = {
+ { 0,-1, 0},
+ { 0, 0, 1},
+ {-1, 0, 0}};
+// y roate 90 + x rotate 180
+Mat3x3_t MATRIX_Y90X180 = {
+ { 0, 0,-1},
+ { 0,-1, 0},
+ {-1, 0, 0}};
+// x rotate 90
+Mat3x3_t MATRIX_X90 = {
+ { 1, 0, 0},
+ { 0, 0, 1},
+ { 0,-1, 0}};
+// x rotate 270
+Mat3x3_t MATRIX_X270 = {
+ { 1, 0, 0},
+ { 0, 0,-1},
+ { 0, 1, 0}};
+// x rotate 90 + y roate 90
+Mat3x3_t MATRIX_X90Y90 = {
+ { 0, 0, 1},
+ {-1, 0, 0},
+ { 0,-1, 0}};
+
+// x rotate 90 + y roate 180
+Mat3x3_t MATRIX_X90Y180 = {
+ {-1, 0, 0},
+ { 0, 0,-1},
+ { 0,-1, 0}};
+// x rotate 90 + y roate 270
+Mat3x3_t MATRIX_X90Y270 = {
+ { 0, 0,-1},
+ { 1, 0, 0},
+ { 0,-1, 0}};
+
+
+
+void translate(const float verticesIn[3], float verticesOut[3], const Mat3x3_t matrix)
+{
+ verticesOut[0] = verticesIn[0] * matrix[0][0] + verticesIn[1] * matrix[1][0] + verticesIn[2] * matrix[2][0];
+ verticesOut[1] = verticesIn[0] * matrix[0][1] + verticesIn[1] * matrix[1][1] + verticesIn[2] * matrix[2][1];
+ verticesOut[2] = verticesIn[0] * matrix[0][2] + verticesIn[1] * matrix[1][2] + verticesIn[2] * matrix[2][2];
+}
+
+
+DCCubeRenderer::DCCubeRenderer(float size, float height, float radius, int r_step, bool cache)
+ : m_size(size), m_height(height), m_radius(radius), m_step(r_step), m_cache(cache), m_shapeId(0), m_shapeUpdated(true)
+{
+ for (int i = 0; i < 6; i++)
+ {
+ m_textures[i] = 0;
+ }
+
+ m_edgeColor[0] = 0;
+ m_edgeColor[1] = 0;
+ m_edgeColor[2] = 0;
+ m_edgeColor[3] = 1;
+
+ m_faceColor[0] = 1;
+ m_faceColor[1] = 1;
+ m_faceColor[2] = 1;
+ m_faceColor[3] = 1;
+
+ m_text1 = "";
+ m_text2 = "";
+ m_widget = DCGLWidget::singleton();
+}
+
+DCCubeRenderer::~DCCubeRenderer()
+{
+ deleteTextures();
+ if (m_shapeId)
+ {
+ glDeleteLists(m_shapeId,1);
+ }
+}
+
+void DCCubeRenderer::draw()
+{
+ if (m_shapeUpdated)
+ {
+ if (m_shapeId != 0)
+ {
+ glDeleteLists(m_shapeId, 1);
+ m_shapeId = 0;
+ }
+ deleteTextures();
+ buildTextures();
+ }
+
+ if (m_shapeId)
+ {
+ glCallList(m_shapeId);
+ }
+ else
+ {
+ if (m_cache)
+ {
+ m_shapeId = glGenLists(1);
+ if (m_shapeId <= 0)
+ {
+ // ERROR for creating glGenList
+ m_shapeId = 0;
+ buildShape();
+ TKLog::printf(TKLog::WARNING, "FAILED for create displaylist in DCCubeRender::draw(). Out-of-memory?");
+ }
+
+ glNewList(m_shapeId, GL_COMPILE);
+ buildShape();
+ glEndList();
+
+ glCallList(m_shapeId);
+ }
+ else
+ {
+ buildShape();
+ }
+ }
+
+ m_shapeUpdated = false;
+}
+
+void DCCubeRenderer::setEdgeColor(GLfloat r, GLfloat g, GLfloat b)
+{
+ m_edgeColor[0] = r;
+ m_edgeColor[1] = g;
+ m_edgeColor[2] = b;
+ m_shapeUpdated = true;
+}
+
+void DCCubeRenderer::setFaceColor(GLfloat r, GLfloat g, GLfloat b)
+{
+ m_faceColor[0] = r;
+ m_faceColor[1] = g;
+ m_faceColor[2] = b;
+ m_shapeUpdated = true;
+}
+
+void DCCubeRenderer::setTextLabel(const QString &text1, const QString &text2)
+{
+ QString newText1 = " " + text1 + " ";
+ QString newText2 = " " + text2 + " ";
+
+ if (newText1 != m_text1 || newText2 != m_text2)
+ {
+ m_text1 = newText1;
+ m_text2 = newText2;
+ m_shapeUpdated = true;
+ }
+}
+
+void DCCubeRenderer::setSize(float size_)
+{
+ if (m_size != size_)
+ {
+ m_size = size_;
+ m_shapeUpdated = true;
+ }
+}
+
+void DCCubeRenderer::setHeight(float height)
+{
+ if (m_height != height)
+ {
+ m_height = height;
+ m_shapeUpdated = true;
+ }
+}
+
+bool DCCubeRenderer::buildShape()
+{
+ renderTopAndBottomFaces();
+ renderSideFaces();
+
+ if (m_radius == 0)
+ {
+ return true;
+ }
+
+ renderEdges();
+ renderJoints();
+
+ return true;
+}
+
+void DCCubeRenderer::buildTextures()
+{
+ if (m_widget)
+ {
+ //texture for top and bottom
+ {
+ int texSize = 128 * (m_size < 1 ? 1 : m_size);
+ QPixmap image(texSize,texSize);
+ image.fill(QColor(m_edgeColor[0]*255, m_edgeColor[1]*255, m_edgeColor[2]*255));
+ QPainter painter;
+ painter.begin(&image);
+
+ float r = texSize * m_radius / m_size;
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(QBrush(QColor(m_faceColor[0]*255, m_faceColor[1]*255, m_faceColor[2]*255)));
+ painter.drawRoundedRect(0,0, texSize, texSize, r,r);
+
+ QFont font;
+ font.setPointSize(22);
+ font.setItalic(true);
+ painter.setPen(Qt::black);
+ painter.setFont(font);
+ QRectF rect = painter.boundingRect(0,0,image.width(), image.height()*0.4, Qt::AlignCenter | Qt::TextDontClip, m_text1);
+ if (rect.width() > image.rect().width())
+ {
+ font.setPointSizeF(22*(image.rect().width()/rect.width()));
+ painter.setFont(font);
+ }
+ painter.drawText(0,0,image.width(),image.height()*0.4, Qt::AlignCenter | Qt::TextDontClip, m_text1);
+
+ font.setPointSize(48);
+ font.setItalic(false);
+ painter.setPen(Qt::black);
+ painter.setFont(font);
+ rect = painter.boundingRect(0,0,image.width(), image.height()*0.6, Qt::AlignCenter | Qt::TextDontClip, m_text2);
+ if (rect.width() > image.rect().width())
+ {
+ font.setPointSizeF(48*(image.rect().width()/rect.width()));
+ painter.setFont(font);
+ }
+ painter.drawText(0, image.height()*0.4, image.width(), image.height()*0.6, Qt::AlignCenter | Qt::TextDontClip, m_text2);
+
+ GLuint texture = m_widget->bindTexture(image, GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption|QGLContext::InvertedYBindOption);
+
+ for (int i = 0; i < 2; i++)
+ {
+ m_textures[i] = texture;
+ }
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+
+ //texture for side faces
+ {
+ int texSize_w = 128;
+ int texSize_h = 128;
+ if (m_size < m_height)
+ {
+ texSize_w = 128 * (m_size < 1 ? 1 : m_size);
+ texSize_h = 128 * m_height / m_size;
+ }
+ else
+ {
+ texSize_h = 128 * (m_height < 1 ? 1 : m_height);
+ texSize_w = 128 * m_size / m_height;
+ }
+
+ QPixmap image(texSize_w,texSize_h);
+ image.fill(QColor(m_edgeColor[0]*255, m_edgeColor[1]*255, m_edgeColor[2]*255));
+ QPainter painter;
+ painter.begin(&image);
+
+ float r_w = texSize_w * m_radius / m_size;
+ float r_h = texSize_h * m_radius / m_height;
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(QBrush(QColor(m_faceColor[0]*255, m_faceColor[1]*255, m_faceColor[2]*255)));
+ painter.drawRoundedRect(0,0, texSize_w, texSize_h, r_w, r_h);
+
+ QFont font;
+ font.setPointSize(22);
+ font.setItalic(true);
+ painter.setPen(Qt::black);
+ painter.setFont(font);
+ QRectF rect = painter.boundingRect(0,0,image.width(), image.height()*0.4, Qt::AlignCenter | Qt::TextDontClip, m_text1);
+ if (rect.width() > image.rect().width())
+ {
+ font.setPointSizeF(22*(image.rect().width()/rect.width()));
+ painter.setFont(font);
+ }
+ painter.drawText(0,0,image.width(), image.height()*0.4, Qt::AlignCenter | Qt::TextDontClip, m_text1);
+
+ font.setPointSize(48);
+ font.setItalic(false);
+ painter.setPen(Qt::black);
+ painter.setFont(font);
+ rect = painter.boundingRect(0,0,image.width(), image.height()*0.6, Qt::AlignCenter | Qt::TextDontClip, m_text2);
+ if (rect.width() > image.rect().width())
+ {
+ font.setPointSizeF(48*(image.rect().width()/rect.width()));
+ painter.setFont(font);
+ }
+ painter.drawText(0,image.height()*0.4,image.width(), image.height()*0.6, Qt::AlignCenter | Qt::TextDontClip, m_text2);
+
+ painter.end();
+
+ GLuint texture = m_widget->bindTexture(image, GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption|QGLContext::InvertedYBindOption);
+
+ for (int i = 2; i < 6; i++)
+ {
+ m_textures[i] = texture;
+ }
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+ }
+}
+
+void DCCubeRenderer::deleteTextures()
+{
+ GLuint deletedTextureIds[6];
+
+ for (int i = 0; i < 6; i++)
+ {
+ if (m_textures[i] != 0)
+ {
+ bool alreadyDeleted = false;
+ for (int j = 0; j < i; j++)
+ {
+ if (deletedTextureIds[j] == m_textures[i])
+ {
+ alreadyDeleted = true;
+ break;
+ }
+ }
+ if (!alreadyDeleted)
+ glDeleteTextures(1, &m_textures[i]);
+ deletedTextureIds[i] = m_textures[i];
+ m_textures[i] = 0;
+ }
+ }
+}
+
+void DCCubeRenderer::renderTopAndBottomFaces()
+{
+ float vertices[4][3];
+ float normals[4][3];
+
+ float vertexOut[3];
+ float normalOut[3];
+
+ float sh = m_size / 2.0 - m_radius;
+ float hh = m_height / 2.0;
+
+ Mat3x3_t *trans[4] = {&MATRIX_BASE, &MATRIX_Z180};
+
+ normals[0][0] = 0; normals[0][1] = 1; normals[0][2] = 0;
+ vertices[0][0] = -sh; vertices[0][1] = hh; vertices[0][2] = -sh;
+
+ normals[1][0] = 0; normals[1][1] = 1; normals[1][2] = 0;
+ vertices[1][0] = -sh; vertices[1][1] = hh; vertices[1][2] = sh;
+
+ normals[2][0] = 0; normals[2][1] = 1; normals[2][2] = 0;
+ vertices[2][0] = sh; vertices[2][1] = hh; vertices[2][2] = sh;
+
+ normals[3][0] = 0; normals[3][1] = 1; normals[3][2] = 0;
+ vertices[3][0] = sh; vertices[3][1] = hh; vertices[3][2] = -sh;
+
+ for (int i = 0; i < 2; i++)
+ {
+ const float texcords[4][2] = {{0,1}, {0,0}, {1,0}, {1,1}};
+
+ if (m_textures[i] != 0)
+ {
+ glColor4fv(m_faceColor);
+ glBindTexture(GL_TEXTURE_2D ,m_textures[i]);
+ }
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
+ glBegin(GL_QUADS);
+
+ for (int j = 0; j < 4; j++)
+ {
+ translate(vertices[j], vertexOut, *trans[i]);
+ translate(normals[j], normalOut, *trans[i]);
+
+ glTexCoord2fv(texcords[j]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+ }
+ glEnd();
+
+ if (m_textures[i] != 0)
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+}
+
+void DCCubeRenderer::renderSideFaces()
+{
+ float vertices[4][3];
+ float normals[4][3];
+
+ float vertexOut[3];
+ float normalOut[3];
+
+ float sh0 = m_size / 2.0;
+ float sh = m_size / 2.0 - m_radius;
+ float hh = m_height / 2.0 - m_radius;
+
+ Mat3x3_t *trans[4] = {&MATRIX_BASE, &MATRIX_Y90, &MATRIX_Y180,&MATRIX_Y270};
+
+ normals[0][0] = 0; normals[0][1] = 0; normals[0][2] = 1.0;
+ vertices[0][0] = sh; vertices[0][1] = hh; vertices[0][2] = sh0;
+
+ normals[1][0] = 0; normals[1][1] = 0; normals[1][2] = 1.0;
+ vertices[1][0] = -sh; vertices[1][1] = hh; vertices[1][2] = sh0;
+
+ normals[2][0] = 0; normals[2][1] = 0; normals[2][2] = 1.0;
+ vertices[2][0] = - sh; vertices[2][1] = -hh; vertices[2][2] = sh0;
+
+ normals[3][0] = 0; normals[3][1] = 0; normals[3][2] = 1.0;
+ vertices[3][0] = sh; vertices[3][1] = -hh; vertices[3][2] = sh0;
+
+ for (int i = 0; i < 4; i++)
+ {
+ const float texcords[4][2] = {{1,1}, {0,1}, {0,0}, {1,0}};
+
+
+ if (m_textures[i+2] != 0)
+ {
+ glColor4fv(m_faceColor);
+ glBindTexture(GL_TEXTURE_2D ,m_textures[i+2]);
+ }
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
+ glBegin(GL_QUADS);
+
+ for (int j = 0; j < 4; j++)
+ {
+ translate(vertices[j], vertexOut, *trans[i]);
+ translate(normals[j], normalOut, *trans[i]);
+
+ glTexCoord2fv(texcords[j]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+ }
+ glEnd();
+
+ if (m_textures[i+2] != 0)
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+}
+
+void DCCubeRenderer::renderEdges()
+{
+ float vertex[3];
+ float normal[3];
+
+ float vertexOut[3];
+ float normalOut[3];
+
+ float sh = m_size / 2.0 - m_radius;
+ float hh = m_height / 2.0 - m_radius;
+
+ float rad_step = PI / 2.0 / m_step;
+
+ //horizontal part
+ int n = 0;
+ float side = 1;
+ for (int i = 0; i < 8; i ++)
+ {
+ Mat3x3_t *trans[4] = {&MATRIX_BASE, &MATRIX_Y90, &MATRIX_Y180,&MATRIX_Y270};
+ glBegin(GL_TRIANGLE_STRIP);
+ glColor4fv(m_edgeColor);
+ for (int j = 0 ; j <= m_step ; j++)
+ {
+ float xn = cos(rad_step * j);
+ float yn = sin(rad_step * j);
+ float xp = m_radius * cos(rad_step * j);
+ float yp = m_radius * sin(rad_step * j);
+
+ normal[0] = xn; normal[1] = yn; normal[2] = 0;
+ vertex[0] = (sh + xp) * side;
+ vertex[1] = (hh + yp) * side;
+ vertex[2] = sh;
+ translate(vertex, vertexOut, *trans[n]);
+ translate(normal, normalOut, *trans[n]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+
+ normal[0] = xn; normal[1] = yn; normal[2] = 0;
+ vertex[2] = - sh;
+ translate(vertex, vertexOut, *trans[n]);
+ translate(normal, normalOut, *trans[n]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+ }
+ glEnd();
+ n++;
+ if (n==4)
+ {
+ n = 0;
+ side = -1;
+ }
+ }
+
+ //vertical part
+ for (int i = 0; i < 4; i ++)
+ {
+ glBegin(GL_TRIANGLE_STRIP);
+ Mat3x3_t *trans[4] = {&MATRIX_BASE, &MATRIX_Y90, &MATRIX_Y180,&MATRIX_Y270};
+ glBegin(GL_TRIANGLE_STRIP);
+ glColor4fv(m_edgeColor);
+ for (int j = 0 ; j <= m_step ; j++)
+ {
+ float xn = cos(rad_step * j);
+ float zn = sin(rad_step * j);
+ float xp = m_radius * cos(rad_step * j);
+ float zp = m_radius * sin(rad_step * j);
+
+ normal[0] = xn; normal[1] = 0; normal[2] = zn;
+ vertex[0] = sh + xp;
+ vertex[1] = - hh;
+ vertex[2] = sh + zp;
+ translate(vertex, vertexOut, *trans[i]);
+ translate(normal, normalOut, *trans[i]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+
+ normal[0] = xn; normal[1] = 0; normal[2] = zn;
+ vertex[1] = hh;
+ translate(vertex, vertexOut, *trans[i]);
+ translate(normal, normalOut, *trans[i]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+ }
+ glEnd();
+ }
+}
+
+void DCCubeRenderer::renderJoints()
+{
+ float vertex[3];
+ float normal[3];
+
+ float vertexOut[3];
+ float normalOut[3];
+
+ float sh = m_size / 2.0 - m_radius;
+ float hh = m_height / 2.0 - m_radius;
+
+ float rad_step = PI / 2.0 / m_step;
+
+ int n = 0;
+ float side = 1;
+ for (int i = 0; i < 8; i ++)
+ {
+ glBegin(GL_TRIANGLE_STRIP);
+ Mat3x3_t *trans[4] = {&MATRIX_BASE, &MATRIX_Y90, &MATRIX_Y180,&MATRIX_Y270};
+ glColor4fv(m_edgeColor);
+ glBegin(GL_TRIANGLE_STRIP);
+ for (int j = 0 ; j < m_step ; j++)
+ {
+ float x0n = cos(rad_step * j);
+ float y0n = sin(rad_step * j);
+
+ float x1n = cos(rad_step * (j+1));
+ float y1n = sin(rad_step * (j+1));
+
+ for (int k = 0; k <= m_step ; k++)
+ {
+ normal[0] = x0n * cos(rad_step * k) * side;
+ normal[1] = y0n * side;
+ normal[2] = x0n * sin(rad_step * k);
+ vertex[0] = sh * side + m_radius * normal[0];
+ vertex[1] = hh * side + m_radius * normal[1];
+ vertex[2] = sh + m_radius * normal[2];
+
+ translate(vertex, vertexOut, *trans[n]);
+ translate(normal, normalOut, *trans[n]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+
+ normal[0] = x1n * cos(rad_step * k) * side;
+ normal[1] = y1n * side;
+ normal[2] = x1n * sin(rad_step * k);
+ vertex[0] = sh * side + m_radius * normal[0];
+ vertex[1] = hh * side + m_radius * normal[1];
+ vertex[2] = sh + m_radius * normal[2];
+
+ translate(vertex, vertexOut, *trans[n]);
+ translate(normal, normalOut, *trans[n]);
+ glNormal3fv(normalOut);
+ glVertex3fv(vertexOut);
+ }
+
+ }
+ glEnd();
+ n++;
+ if (n==4)
+ {
+ n = 0;
+ side = -1;
+ }
+ }
+}
+
+
--- /dev/null
+/*
+ * cuberenderer.h
+ *
+ * CubeRenderer class - rendering rounded cube
+ *
+ * Copyright (C) 2010 Takuji Kawata
+ */
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+
+#ifndef DCCUBERENDERER_H
+#define DCCUBERENDERER_H
+
+#include <QGLWidget>
+#include <GL/gl.h>
+#include <string>
+
+class DCCubeRenderer
+{
+public:
+ DCCubeRenderer(float size, float height, float radius, int r_step, bool cache = true);
+ virtual ~DCCubeRenderer();
+
+ void draw();
+ void setEdgeColor(GLfloat r, GLfloat g, GLfloat b);
+ void setFaceColor(GLfloat r, GLfloat g, GLfloat b);
+ void setTextLabel(const QString &text1, const QString &text2);
+ void setSize(float size);
+ void setHeight(float height);
+
+private:
+ bool buildShape();
+ void buildTextures();
+ void deleteTextures();
+
+ void renderSideFaces();
+ void renderTopAndBottomFaces();
+ void renderEdges();
+ void renderJoints();
+
+ float m_size;
+ float m_height;
+ float m_radius;
+ float m_step;
+ bool m_cache;
+
+ bool m_shapeValid;
+ GLuint m_shapeId;
+ bool m_shapeUpdated;
+ QGLWidget *m_widget;
+
+ GLuint m_textures[6];
+ GLfloat m_edgeColor[4];
+ GLfloat m_faceColor[4];
+
+ QString m_text1;
+ QString m_text2;
+
+};
+
+#endif // DCCUBERENDERER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcselectionrenderer.h"
+
+#include <QtOpenGL>
+
+static const double PI = 3.14159265358979323846264338327950288419717;
+
+DCSelectionRenderer::DCSelectionRenderer(float lineWidth, float gap)
+ : d_rectSize(0), d_lineWidth(lineWidth), d_gap(gap), d_offset(0),
+ d_strokeLen(0), d_strokePosition(0)
+
+{
+ d_roundEdgeDistanceRadius = d_lineWidth * 0.5;
+ d_roundEdgeStep = PI / 10 * d_roundEdgeDistanceRadius;
+ d_lineWidth2 = d_lineWidth * 0.5;
+}
+
+DCSelectionRenderer::~DCSelectionRenderer()
+{
+
+}
+
+void DCSelectionRenderer::setRectSize(float rectSize)
+{
+ d_rectSize = rectSize;
+ d_strokeLen = d_rectSize - d_lineWidth * 2;
+ d_strokePosition = d_rectSize/2;
+}
+
+void DCSelectionRenderer::draw(bool isAnimationInterval)
+{
+ if (d_rectSize <= 0)
+ {
+ return;
+ }
+
+ float strokeLenHalf = d_strokeLen / 2;
+ float roundEdgelen = d_roundEdgeDistanceRadius * PI / 2;
+
+ float totalLen = d_strokeLen * 4 + roundEdgelen * 4;
+ int gaps = totalLen / (d_gap * 2);
+ float adj = (totalLen - (gaps * d_gap * 2)) / gaps;
+
+ float d = d_offset;
+ float gap = d_gap - adj * 2;
+
+ glBegin(GL_TRIANGLE_STRIP);
+
+ bool c = true;
+ while (d <= d_strokeLen)
+ {
+ glVertex3f(strokeLenHalf - d, 0, -d_strokePosition + d_lineWidth);
+ glVertex3f(strokeLenHalf - d, 0, -d_strokePosition);
+
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+
+ glVertex3f(strokeLenHalf - d, 0, -d_strokePosition + d_lineWidth);
+ glVertex3f(strokeLenHalf - d, 0, -d_strokePosition);
+
+ d += gap;
+ c = !c;
+ }
+
+ //round edge1
+ c = !c;
+ bool nc = c;
+ float nextGap = d - d_strokeLen;
+ d = 0;
+ while(d <= roundEdgelen)
+ {
+ float rad = d / d_roundEdgeDistanceRadius;
+ float rx = d_lineWidth * cos(rad);
+ float ry = d_lineWidth * sin(rad);
+ glVertex3f(-strokeLenHalf, 0, -d_strokePosition + d_lineWidth);
+ glVertex3f(-strokeLenHalf - ry, 0, -d_strokePosition + d_lineWidth - rx);
+ if (nc != c)
+ {
+ c = nc;
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(-strokeLenHalf, 0, -d_strokePosition + d_lineWidth);
+ glVertex3f(-strokeLenHalf - ry, 0, -d_strokePosition + d_lineWidth - rx);
+ }
+ d += d_roundEdgeStep;
+ if (nextGap < d && nextGap < roundEdgelen)
+ {
+ d = nextGap;
+ nc = !c;
+ nextGap += gap;
+ }
+ }
+ d = nextGap - roundEdgelen;
+ c = !c;
+ glVertex3f(-d_strokePosition + d_lineWidth, 0, -strokeLenHalf );
+ glVertex3f(-d_strokePosition , 0, - strokeLenHalf );
+ //
+
+ while (d < d_strokeLen)
+ {
+ glVertex3f(-d_strokePosition + d_lineWidth, 0, -strokeLenHalf + d);
+ glVertex3f(-d_strokePosition , 0, - strokeLenHalf + d);
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(-d_strokePosition + d_lineWidth, 0, -strokeLenHalf + d);
+ glVertex3f(-d_strokePosition , 0, - strokeLenHalf + d);
+
+ d += gap;
+ c = !c;
+ }
+
+ //round edge2
+ c = !c;
+ nc = c;
+ nextGap = d - d_strokeLen;
+ d = 0;
+ while(d <= roundEdgelen)
+ {
+ float rad = d / d_roundEdgeDistanceRadius;
+ float rx = d_lineWidth * cos(rad);
+ float ry = d_lineWidth * sin(rad);
+ glVertex3f(-d_strokePosition + d_lineWidth, 0, strokeLenHalf );
+ glVertex3f(-d_strokePosition + d_lineWidth - rx, 0, strokeLenHalf + ry);
+ if (nc != c)
+ {
+ c = nc;
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(-d_strokePosition + d_lineWidth, 0, strokeLenHalf );
+ glVertex3f(-d_strokePosition + d_lineWidth - rx, 0, strokeLenHalf + ry);
+ }
+ d += d_roundEdgeStep;
+ if (nextGap < d && nextGap < roundEdgelen)
+ {
+ d = nextGap;
+ nc = !c;
+ nextGap += gap;
+ }
+ }
+ d = nextGap - roundEdgelen;
+ c = !c;
+ glVertex3f(-strokeLenHalf, 0, d_strokePosition - d_lineWidth);
+ glVertex3f(-strokeLenHalf, 0, d_strokePosition);
+
+ //
+
+ while (d < d_strokeLen)
+ {
+ glVertex3f(-strokeLenHalf + d, 0, d_strokePosition - d_lineWidth);
+ glVertex3f(-strokeLenHalf + d, 0, d_strokePosition);
+
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(-strokeLenHalf + d, 0, d_strokePosition - d_lineWidth);
+ glVertex3f(-strokeLenHalf + d, 0, d_strokePosition);
+
+ d += gap;
+ c = !c;
+ }
+
+ //round edge3
+ c = !c;
+ nc = c;
+ nextGap = d - d_strokeLen;
+ d = 0;
+ while(d <= roundEdgelen)
+ {
+ float rad = d / d_roundEdgeDistanceRadius;
+ float rx = d_lineWidth * cos(rad);
+ float ry = d_lineWidth * sin(rad);
+ glVertex3f(strokeLenHalf , 0, d_strokePosition - d_lineWidth );
+ glVertex3f(strokeLenHalf + ry, 0, d_strokePosition - d_lineWidth + rx);
+ if (nc != c)
+ {
+ c = nc;
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(strokeLenHalf , 0, d_strokePosition - d_lineWidth );
+ glVertex3f(strokeLenHalf + ry, 0, d_strokePosition - d_lineWidth + rx);
+ }
+ d += d_roundEdgeStep;
+ if (nextGap < d && nextGap < roundEdgelen)
+ {
+ d = nextGap;
+ nc = !c;
+ nextGap += gap;
+ }
+ }
+ d = nextGap - roundEdgelen;
+ c = !c;
+
+ glVertex3f(d_strokePosition - d_lineWidth, 0, strokeLenHalf);
+ glVertex3f(d_strokePosition, 0, strokeLenHalf);
+
+ while (d < d_strokeLen)
+ {
+ glVertex3f(d_strokePosition - d_lineWidth, 0, strokeLenHalf - d);
+ glVertex3f(d_strokePosition, 0, strokeLenHalf - d);
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(d_strokePosition - d_lineWidth, 0, strokeLenHalf - d);
+ glVertex3f(d_strokePosition, 0, strokeLenHalf - d);
+
+ d += gap;
+ c = !c;
+ }
+
+ //round edge4
+ c = !c;
+ nc = c;
+ nextGap = d - d_strokeLen;
+ d = 0;
+ while(d <= roundEdgelen)
+ {
+ float rad = d / d_roundEdgeDistanceRadius;
+ float rx = d_lineWidth * cos(rad);
+ float ry = d_lineWidth * sin(rad);
+ glVertex3f(d_strokePosition - d_lineWidth , 0, -strokeLenHalf );
+ glVertex3f(d_strokePosition - d_lineWidth + rx, 0, -strokeLenHalf - ry);
+ if (nc != c)
+ {
+ c = nc;
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(d_strokePosition - d_lineWidth , 0, -strokeLenHalf );
+ glVertex3f(d_strokePosition - d_lineWidth + rx, 0, -strokeLenHalf - ry);
+ }
+ d += d_roundEdgeStep;
+ if (nextGap < d && nextGap < roundEdgelen)
+ {
+ d = nextGap;
+ nc = !c;
+ nextGap += gap;
+ }
+ }
+ d = nextGap - roundEdgelen;
+
+
+ glVertex3f(d_strokePosition - d_lineWidth , 0, -strokeLenHalf );
+ glVertex3f(d_strokePosition - d_lineWidth, 0, -d_strokePosition);
+
+ glVertex3f(strokeLenHalf - d, 0, -d_strokePosition + d_lineWidth);
+ glVertex3f(strokeLenHalf - d, 0, -d_strokePosition);
+
+ glEnd();
+
+ glBegin(GL_QUADS);
+ d = 0;
+ c = false;
+ for (int i = 0; i < 6; i ++)
+ {
+ if (c)
+ glColor3f(1,1,1);
+ else
+ glColor3f(0,0,0);
+ glVertex3f(strokeLenHalf - d_lineWidth2 - d , 0.001, strokeLenHalf);
+ glVertex3f(strokeLenHalf - d, 0.001, strokeLenHalf);
+ glVertex3f(strokeLenHalf, 0.001, strokeLenHalf - d);
+ glVertex3f(strokeLenHalf, 0.001, strokeLenHalf - d_lineWidth2 - d);
+
+ d += d_lineWidth2;
+ c = !c;
+ }
+ glEnd();
+
+ if (isAnimationInterval)
+ {
+ d_offset += (gap / 3);
+ if (d_offset >= gap * 2)
+ {
+ d_offset -= (gap * 2);
+ }
+ }
+}
+
+bool DCSelectionRenderer::isResizingArea(float x, float y)
+{
+ float strokeLenHalf = d_strokeLen / 2;
+ float x0 = strokeLenHalf - d_lineWidth2 * 6;
+ float y0 = strokeLenHalf;
+ float x1 = strokeLenHalf;
+ float y1 = strokeLenHalf - d_lineWidth2 * 6;
+
+ return (x0 <= x && x <= x1 && y1 <= y && y <= y0 && -(x - x0) + y0 < y);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCSELECTIONRENDERER_H
+#define DCSELECTIONRENDERER_H
+
+class DCSelectionRenderer
+{
+ float d_rectSize;
+ float d_lineWidth;
+ float d_gap;
+ float d_roundEdgeStep;
+ float d_offset;
+ float d_roundEdgeDistanceRadius;
+ float d_strokeLen;
+ float d_strokePosition;
+ float d_lineWidth2;
+
+public:
+ DCSelectionRenderer(float lineWidth, float gap);
+ ~DCSelectionRenderer();
+
+ void setRectSize(float rectSize);
+ void draw(bool isAnimationInterval);
+
+ bool isResizingArea(float x, float y);
+
+
+};
+
+#endif // DCSELECTIONRENDERER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dceditmenudialog.h"
+
+#include <QPushButton>
+
+DCEditMenuDialog::DCEditMenuDialog(QWidget *parent) :
+ QDialog(parent), isEditCellCode(false), isEditAxonTerminal(false), isEditReceptor(false), isEditCellAttribute(false)
+{
+ setLayout(new QVBoxLayout);
+
+ setWindowFlags(Qt::Dialog);
+
+ setWindowTitle("Edit a cell...");
+
+ QPushButton *b1 = new QPushButton("Edit cell code");
+ QPushButton *b2 = new QPushButton("Add axon terminal");
+ QPushButton *b3 = new QPushButton("Add receptor");
+ QPushButton *b4 = new QPushButton("Edit cell attributes");
+
+ layout()->addWidget(b1);
+ layout()->addWidget(b2);
+ layout()->addWidget(b3);
+ layout()->addWidget(b4);
+
+ connect(b1, SIGNAL(clicked()), this, SLOT(editCellCodeSelected()));
+ connect(b2, SIGNAL(clicked()), this, SLOT(editAxonTerminalSelected()));
+ connect(b3, SIGNAL(clicked()), this, SLOT(editReceptorSelected()));
+ connect(b4, SIGNAL(clicked()), this, SLOT(editCellAttributeSelected()));
+}
+
+void DCEditMenuDialog::editCellCodeSelected()
+{
+ isEditCellCode = true;
+ close();
+}
+
+void DCEditMenuDialog::editAxonTerminalSelected()
+{
+ isEditAxonTerminal = true;
+ close();
+}
+
+void DCEditMenuDialog::editReceptorSelected()
+{
+ isEditReceptor = true;
+ close();
+}
+
+void DCEditMenuDialog::editCellAttributeSelected()
+{
+ isEditCellAttribute = true;
+ close();
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCEDITMENUDIALOG_H
+#define DCEDITMENUDIALOG_H
+
+#include <QtGui>
+#include <QDialog>
+
+class DCEditMenuDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit DCEditMenuDialog(QWidget *parent = 0);
+
+ bool isEditCellCode;
+ bool isEditAxonTerminal;
+ bool isEditReceptor;
+ bool isEditCellAttribute;
+
+signals:
+
+private slots:
+ void editCellCodeSelected();
+ void editAxonTerminalSelected();
+ void editReceptorSelected();
+ void editCellAttributeSelected();
+};
+
+#endif // DCEDITMENUDIALOG_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "TKLog.h"
+
+#include "dcglvisualizerwidget.h"
+#include "dcvcomponent.h"
+#include "dcvpagecomponent.h"
+#include "dcvcpage.h"
+
+#include "dccreator.h"
+#include "dcscene.h"
+#include "dcanimationtimer.h"
+#include "dccell.h"
+#include "dcaxon.h"
+#include "dcreceptor.h"
+#include "utils/dccomponentutil.h"
+#include "dcglwidget.h"
+
+#include "dctoolwindowviewcontrol.h"
+#include "dctoolwindowcelleditor.h"
+#include "dctoolwindowterminalfromaxoneditor.h"
+#include "dctoolwindowterminalfromreceptoreditor.h"
+#include "dctoolwindowcellcodeeditor.h"
+#include "dceditmenudialog.h"
+
+#include "eventhandler/dcveventhandler.h"
+#include "utils/dcveventhandlerutil.h"
+
+#include <QtGui>
+#include <QObject>
+#include <QGLFormat>
+#include <QtOpenGL>
+#include <QDebug>
+#include <GL/glu.h>
+#include <typeinfo>
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+static QGraphicsView *s_uiView = NULL;
+
+
+DCGLVisualizerWidget::DCGLVisualizerWidget(DCCreator *creator, QWidget *parent) : QGraphicsView(parent)
+{
+ QGraphicsScene *scene = new DCUIGraphicsScene(creator, parent);
+ setScene(scene);
+
+ setViewport(DCGLWidget::singleton());
+ setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),scene, SLOT(showContextMenu(const QPoint&)));
+
+ s_uiView = this;
+}
+
+DCGLVisualizerWidget::~DCGLVisualizerWidget()
+{
+}
+
+QPointF DCGLVisualizerWidget::globalPointToLocal(const QPoint &point)
+{
+ if (s_uiView && s_uiView->scene())
+ {
+ return s_uiView->mapToScene(s_uiView->mapFromGlobal(point));
+ }
+ return QPoint();
+}
+
+bool toolWindowPositionLessThan(const DCGraphicsProxyWidget *t1, const DCGraphicsProxyWidget *t2)
+{
+ if (t1->geometry().right() < t2->geometry().left())
+ {
+ return true;
+ }
+ else if (t2->geometry().right() < t1->geometry().left())
+ {
+ return false;
+ }
+
+ if (t1->pos().y() < t2->pos().y())
+ {
+ return true;
+ }
+ else if (t1->pos().y() == t2->pos().y())
+ {
+ if (t1->getPosPriority() < t2->getPosPriority())
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+void DCGLVisualizerWidget::resizeEvent(QResizeEvent *event) {
+ if (scene())
+ {
+ scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
+ }
+ QGraphicsView::resizeEvent(event);
+}
+
+void DCGLVisualizerWidget::setupViewport(QWidget *viewport)
+{
+ QGLWidget *glWidget = dynamic_cast<QGLWidget*>(viewport);
+ glWidget->setAutoFillBackground(false);
+ glWidget->setMouseTracking(true);
+
+ if (glWidget)
+ glWidget->updateGL();
+}
+
+void DCGLVisualizerWidget::setVisible(bool visible)
+{
+ QGraphicsView::setVisible(visible);
+}
+
+int DCGraphicsProxyWidget::getPosPriority() const
+{
+ DCToolWindowBase *window = dynamic_cast<DCToolWindowBase*>(widget());
+ if (window)
+ {
+ return window->getPosPriority();
+ }
+ return 999;
+}
+
+DCGraphicsProxyWidget::DCGraphicsProxyWidget(DCSticky sticky, QGraphicsItem *parent, Qt::WindowFlags wFlags)
+ : QGraphicsProxyWidget(parent, wFlags), d_sticky(sticky), d_hasTargetPos(false), d_targetX(0), d_targetY(0),d_embeddedToolWindow(NULL)
+{
+}
+
+DCGraphicsProxyWidget::~DCGraphicsProxyWidget()
+{
+ this->disconnect();
+}
+
+void DCGraphicsProxyWidget::setTargetPos(float targetX, float targetY)
+{
+ d_targetX = targetX;
+ d_targetY = targetY;
+ d_hasTargetPos = true;
+}
+
+void DCGraphicsProxyWidget::doAnimation()
+{
+ const static int MINSPEED = 60;
+
+ if (!d_embeddedToolWindow)
+ {
+ d_embeddedToolWindow = dynamic_cast<DCToolWindowBase*>(widget());
+ if (!d_embeddedToolWindow)
+ return;
+ }
+
+ if (d_hasTargetPos)
+ {
+ QPointF p = pos();
+ float dx = d_targetX - p.x();
+ float dy = d_targetY - p.y();
+ float d = sqrt(dx * dx + dy * dy);
+ if (d < MINSPEED)
+ {
+ d_hasTargetPos = false;
+ setPos(d_targetX, d_targetY);
+ }
+ else
+ {
+ float speed = MINSPEED + d/3;
+ float sr = speed / d;
+ moveBy(dx * sr, dy * sr);
+ }
+ }
+
+ d_embeddedToolWindow->doAnimation();
+}
+
+QVariant DCGraphicsProxyWidget::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ DCUIGraphicsScene *dcGraphicScene = dynamic_cast<DCUIGraphicsScene*>(scene());
+
+ if (change == ItemPositionChange && dcGraphicScene) {
+ QRectF rect = boundingRect();
+ QPointF pos = value.toPointF();
+
+ bool adjusted = false;
+
+ QRectF sceneRect = dcGraphicScene->sceneRect();
+
+ if (d_sticky == DC_STICKYWIDGET_LEFT && pos.x() + rect.left() > dcGraphicScene->getStickyAreaLeftWidth())
+ {
+ d_sticky = DC_STICKYWIDGET_NONE;
+ }
+ else if (d_sticky == DC_STICKYWIDGET_RIGHT && pos.x() + rect.width() < sceneRect.right() - dcGraphicScene->getStickyAreaRightWidth())
+ {
+ d_sticky = DC_STICKYWIDGET_NONE;
+ }
+
+ if (pos.x() + rect.left() < sceneRect.left() + 2)
+ {
+ d_sticky = DC_STICKYWIDGET_LEFT;
+ adjusted = true;
+ pos.setX(sceneRect.left() - rect.left() + 2);
+ }
+ else if (pos.x() + rect.right() >= sceneRect.right() - 2)
+ {
+ d_sticky = DC_STICKYWIDGET_RIGHT;
+ adjusted = true;
+ pos.setX(sceneRect.right() - rect.right() - 2);
+ }
+
+ if (pos.y() + rect.top() < sceneRect.top() + 2)
+ {
+ adjusted = true;
+ pos.setY(sceneRect.top() - rect.top() + 2);
+ }
+ else if (pos.y() + rect.bottom() >= sceneRect.bottom() - 2)
+ {
+ adjusted = true;
+ pos.setY(sceneRect.bottom() - rect.bottom() - 2);
+ }
+
+ if (adjusted)
+ {
+ widget()->move(pos.x(), pos.y());
+ }
+ return pos;
+ }
+ return QGraphicsProxyWidget::itemChange(change, value);
+}
+
+void DCGraphicsProxyWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
+{
+ QGraphicsProxyWidget::resizeEvent(event);
+}
+
+
+DCUIGraphicsScene::DCUIGraphicsScene(DCCreator *creator, QWidget *parent)
+ : QGraphicsScene(parent), d_creator(creator), d_scene(NULL), d_eventHandler(NULL), d_isPaintForAnimation(false), d_requestRedraw(false),
+ d_inResigingDrag(false), d_dragStartX(0), d_dragStartY(0),
+ d_requestLayoutToolWindows(false), d_stickyAreaLeftWidth(10), d_stickyAreaRightWidth(10),
+ d_terminalFromAxonToolWindow(NULL),d_terminalFromReceptorToolWindow(NULL), d_cellCodeEditor(NULL)
+{
+ connect(d_creator, SIGNAL(sceneChanged(const void*, DCScene*)), this, SLOT(sceneChanged(const void*, DCScene*)));
+ connect(d_creator, SIGNAL(sceneSelectedPageChanged(const void*, const DCScene*)), this, SLOT(sceneSelectedPageChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(sceneSelectedCellChanged(const void*, const DCScene*)), this, SLOT(sceneSelectedCellChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(sceneViewAngleChanged(const void*,const DCScene*)), this, SLOT(sceneAngleChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(sceneViewCenterChanged(const void*,const DCScene*)), this, SLOT(sceneCenterChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(sceneViewScaleChanged(const void*, const DCScene*)), this, SLOT(sceneScaleChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(sceneViewSettingChanged(const void*, const DCScene*)), this, SLOT(sceneSettingChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(sceneViewEditModeChanged(const void*,const DCScene*)), this, SLOT(sceneEditModeChanged(const void*, const DCScene*)));
+ connect(d_creator, SIGNAL(destroyed(QObject*)), this, SLOT(creatorDestroyed()));
+ connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand *)), this, SLOT(creatorCommandExecuted()));
+ connect(DCAnimationTimer::instance(), SIGNAL(goNextFrame()), this, SLOT(doAnimation()));
+ connect(this, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(resizeEvent(QRectF)));
+ d_viewControlTool = new DCToolWindowViewControl(d_creator);
+
+}
+
+DCUIGraphicsScene::~DCUIGraphicsScene()
+{
+ if (d_creator)
+ {
+ d_creator->disconnect(this);
+ }
+ DCAnimationTimer::instance()->disconnect(this);
+
+ foreach (QGraphicsItem *item, items())
+ {
+ removeItem(item);
+ }
+
+ while (d_cellEditToolWindowPool.length() > 0)
+ {
+ DCToolWindowBase *window = d_cellEditToolWindowPool.takeFirst();
+ delete window;
+ }
+
+ while (d_cellEditToolWindowList.length() > 0)
+ {
+ DCToolWindowBase *window = d_cellEditToolWindowList.takeFirst();
+ removeToolWindow(window);
+ delete window;
+ }
+
+ if (d_terminalFromAxonToolWindow)
+ {
+ removeToolWindow(d_terminalFromAxonToolWindow);
+ delete d_terminalFromAxonToolWindow;
+ }
+}
+
+
+void DCUIGraphicsScene::addToolWindow(DCToolWindowBase *window, int x, int y, DCGraphicsProxyWidget::DCSticky sticky )
+{
+ DCGraphicsProxyWidget *proxy = new DCGraphicsProxyWidget(sticky);
+ proxy->setWidget(window);
+ proxy->setZValue(1e30);
+ proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); // QGraphicsItem::ItemCoordinateCache
+ proxy->setFlag(QGraphicsItem::ItemIsMovable);
+ proxy->setFlag(QGraphicsItem::ItemIsSelectable, true);
+ proxy->setFlag(QGraphicsItem::ItemIsFocusable, true);
+
+ proxy->setPos(x,y);
+ addItem(proxy);
+ connect(window, SIGNAL(dragMoveFinished()), this, SLOT(requestLayoutToolWindows()));
+ connect(proxy, SIGNAL(heightChanged()), this, SLOT(requestLayoutToolWindows()));
+ connect(proxy, SIGNAL(widthChanged()), this, SLOT(requestLayoutToolWindows()));
+
+ requestLayoutToolWindows();
+}
+
+void DCUIGraphicsScene::removeToolWindow(DCToolWindowBase *window)
+{
+ for (int i = items().length() - 1; i >= 0; i-- )
+ {
+ DCGraphicsProxyWidget *proxy = dynamic_cast<DCGraphicsProxyWidget*>(items().at(i));
+ if (proxy && proxy->widget() == window)
+ {
+ proxy->setWidget(NULL);
+ removeItem(proxy);
+ delete proxy;
+ break;
+ }
+ }
+ requestLayoutToolWindows();
+}
+
+void DCUIGraphicsScene::layoutToolWindows()
+{
+ QList<DCGraphicsProxyWidget*> stickyListLeft;
+ QList<DCGraphicsProxyWidget*> stickyListRight;
+
+ foreach (QGraphicsItem *item, items())
+ {
+ DCGraphicsProxyWidget *proxy = dynamic_cast<DCGraphicsProxyWidget*>(item);
+ if (proxy)
+ {
+ switch(proxy->getSticky())
+ {
+ case DCGraphicsProxyWidget::DC_STICKYWIDGET_LEFT:
+ stickyListLeft.append(proxy);
+ break;
+ case DCGraphicsProxyWidget::DC_STICKYWIDGET_RIGHT:
+ stickyListRight.append(proxy);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ qSort(stickyListLeft.begin(), stickyListLeft.end(), toolWindowPositionLessThan);
+ qSort(stickyListRight.begin(), stickyListRight.end(), toolWindowPositionLessThan);
+
+ QRectF srect = sceneRect();
+ QPointF pos(10, 10);
+ float xmax = 10;
+ for (int i = 0; i < stickyListLeft.length(); i++)
+ {
+ DCGraphicsProxyWidget *item = stickyListLeft.at(i);
+ const QRectF rect = item->boundingRect();
+ float tx = pos.x() - rect.x();
+ float ty = pos.y() - rect.y();
+ if (ty + rect.height() > srect.height())
+ {
+ pos.setX(xmax + 10);
+ pos.setY(10);
+ tx = pos.x() - rect.x();
+ ty = pos.y() - rect.y();
+ }
+ item->setTargetPos(tx, ty);
+ if (tx + rect.width() > xmax)
+ xmax = tx + rect.width();
+ pos += QPointF(0, 10 + rect.height());
+ }
+ d_stickyAreaLeftWidth = xmax;
+
+ pos.setX(srect.width() - 10);
+ pos.setY(srect.height() - 10);
+ float xmin = srect.width() - 10;
+ for (int i = stickyListRight.length() - 1; i >= 0 ; i--)
+ {
+ DCGraphicsProxyWidget *item = stickyListRight.at(i);
+ const QRectF rect = item->boundingRect();
+ float tx = pos.x() - rect.width() - rect.x();
+ float ty = pos.y() - rect.height() - rect.y();
+ if (ty < 0)
+ {
+ pos.setX(xmin - 10);
+ pos.setY(srect.height() - 10);
+ tx = pos.x() - rect.width() - rect.x();
+ ty = pos.y() - rect.height() - rect.y();
+ }
+ item->setTargetPos(tx, ty);
+ if (tx < xmin)
+ xmin = tx;
+ pos -= QPointF(0, 10 + rect.height());
+ }
+ d_stickyAreaRightWidth = srect.width() - xmin;
+
+ d_requestLayoutToolWindows = false;
+}
+
+void DCUIGraphicsScene::creatorDestroyed()
+{
+ d_creator = NULL;
+}
+
+void DCUIGraphicsScene::sceneChanged(const void *requester, DCScene *scene)
+{
+ DCScene::lockScene();
+ if (d_eventHandler)
+ {
+ delete d_eventHandler;
+ d_eventHandler = NULL;
+ }
+ if (d_scene)
+ {
+ d_scene->disconnect(d_viewControlTool);
+ d_scene->disconnect(this);
+ }
+ d_scene = scene;
+ if (d_scene)
+ {
+ d_viewControlTool->setDCScene(d_scene);
+ connect(d_scene, SIGNAL(viewPersModeChanged(const void*)), d_viewControlTool, SLOT(changeMode(const void*)));
+ connect(d_scene, SIGNAL(modeInitialized()), this, SLOT(initMode()));
+ connect(d_scene, SIGNAL(terminalEditCursorBelongingPageChagend(DCVCPage*)), this, SLOT(sceneTerminalEditPageBelongingChanged(DCVCPage*)));
+ connect(d_scene, SIGNAL(terminalEditCursorDropTargetChanged(DCVComponent*)), this, SLOT(sceneTerminalEditDropTargetChanged(DCVComponent*)));
+ }
+
+ while (!d_cellEditToolWindowList.isEmpty())
+ {
+ DCToolWindowBase *toolWindow = d_cellEditToolWindowList.takeFirst();
+ removeToolWindow(toolWindow);
+ }
+
+ if (d_cellCodeEditor)
+ {
+ removeToolWindow(d_cellCodeEditor);
+ delete d_cellCodeEditor;
+ d_cellCodeEditor = NULL;
+ }
+
+ DCScene::unlockScene();
+ updateView(false);
+}
+
+void DCUIGraphicsScene::sceneAngleChanged(const void* requester, const DCScene *scene)
+{
+ if (d_scene != scene)
+ return;
+
+ d_requestRedraw = true;
+}
+
+void DCUIGraphicsScene::sceneCenterChanged(const void *requester, const DCScene *scene)
+{
+ if (d_scene != scene)
+ return;
+
+ d_requestRedraw = true;
+}
+
+void DCUIGraphicsScene::sceneScaleChanged(const void* requester, const DCScene *scene)
+{
+ if (d_scene != scene)
+ return;
+
+ d_requestRedraw = true;
+}
+
+void DCUIGraphicsScene::sceneSettingChanged(const void* requester, const DCScene *scene)
+{
+ if (d_scene != scene)
+ return;
+
+ d_requestRedraw = true;
+}
+
+void DCUIGraphicsScene::sceneSelectedPageChanged(const void* requester, const DCScene *scene)
+{
+ if (d_scene != scene)
+ return;
+
+ d_requestRedraw = true;
+}
+
+
+void DCUIGraphicsScene::sceneSelectedCellChanged(const void* requester, const DCScene *scene)
+{
+ if (d_scene != scene)
+ return;
+
+ switch (scene->getEditMode())
+ {
+ case DCScene::DCV_EDITMODE_LAYOUT:
+ updateCellEditorToolWindows();
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON:
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR:
+ break;
+
+ case DCScene::DCV_EDITMODE_CELLCODE:
+ break;
+ }
+
+ d_requestRedraw = true;
+}
+
+void DCUIGraphicsScene::sceneEditModeChanged(const void *requester, const DCScene *scene)
+{
+
+ if (d_scene != scene)
+ return;
+
+ if (d_eventHandler && scene->getEditMode() == d_eventHandler->getHandlerType() && d_scene == d_eventHandler->getScene())
+ return;
+
+ if (d_eventHandler)
+ {
+ delete d_eventHandler;
+ d_eventHandler = NULL;
+ }
+
+ switch (scene->getEditMode())
+ {
+ case DCScene::DCV_EDITMODE_LAYOUT:
+ closeTerminalFromAxonToolWindow();
+ closeTerminalFromReceptorToolWindow();
+ closeCellCodeEditorToolWindow();
+ showCellEditorToolWindows();
+ d_eventHandler = DCVEventHandlerUtil::createLayoutModeHandler(this, d_creator, d_scene);
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON:
+ closeAllCellEditorToolWindows();
+ closeTerminalFromReceptorToolWindow();
+ closeCellCodeEditorToolWindow();
+ showTerminalFromAxonToolWindow();
+ d_eventHandler = DCVEventHandlerUtil::createTerminalFromAxonModeHandler(this, d_creator, d_scene, scene->getEditAxon(), scene->getTerminalEditCursor());
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR:
+ closeAllCellEditorToolWindows();
+ closeTerminalFromAxonToolWindow();
+ closeCellCodeEditorToolWindow();
+ showTerminalFromReceptorToolWindow();
+ d_eventHandler = DCVEventHandlerUtil::createTerminalFromReceptorModeHandler(this, d_creator, d_scene, scene->getEditReceptor(), scene->getTerminalEditCursor());
+ break;
+
+ case DCScene::DCV_EDITMODE_CELLCODE:
+ closeAllCellEditorToolWindows();
+ closeTerminalFromAxonToolWindow();
+ closeTerminalFromReceptorToolWindow();
+ showCellCodeEditorToolWindow();
+ break;
+ }
+ requestRedraw(false);
+}
+
+void DCUIGraphicsScene::sceneTerminalEditPageBelongingChanged(DCVCPage *page)
+{
+ switch (d_scene->getEditMode())
+ {
+ case DCScene::DCV_EDITMODE_LAYOUT:
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON:
+ updateTerminalFromAxonToolWindow();
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR:
+ updateTerminalFromReceptorToolWindow();
+ break;
+
+ case DCScene::DCV_EDITMODE_CELLCODE:
+ updateCellCodeEditorToolWindow();
+ break;
+ }
+
+ d_requestRedraw = true;
+}
+
+void DCUIGraphicsScene::sceneTerminalEditDropTargetChanged(DCVComponent *dropTarget)
+{
+ switch (d_scene->getEditMode())
+ {
+ case DCScene::DCV_EDITMODE_LAYOUT:
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON:
+ updateTerminalFromAxonToolWindow();
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR:
+ updateTerminalFromReceptorToolWindow();
+ break;
+
+ case DCScene::DCV_EDITMODE_CELLCODE:
+ updateCellCodeEditorToolWindow();
+ }
+
+ d_requestRedraw = true;
+}
+
+void DCUIGraphicsScene::setupProjection()
+{
+ if (!d_creator || !d_scene)
+ return;
+
+ float _width = width();
+ float _height = height();
+ float _scale = d_scene->getScale();
+ glViewport(0, 0, _width, _height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-_width / _scale, _width / _scale, -_height / _scale, _height / _scale, -100.0, 100.0);
+
+ setupCamera();
+
+ glGetDoublev(GL_PROJECTION_MATRIX, d_projectionMatrix);
+ glGetIntegerv(GL_VIEWPORT, d_viewportMatrix);
+
+}
+
+void DCUIGraphicsScene::setupCamera()
+{
+ glTranslatef(- d_scene->getCenterX(), d_scene->getCenterEditModeY(), 0);
+ glRotatef(d_scene->getXAngle(),1,0,0);
+ glRotatef(d_scene->getYAngle(),0,1,0);
+ glTranslatef(0, - d_scene->getCenterBrowsModeY(), 0);
+}
+
+void DCUIGraphicsScene::showEditMenu(DCCell *editCell)
+{
+ if (editCell == NULL)
+ return;
+
+ DCEditMenuDialog dialog;
+ dialog.exec();
+ if (dialog.isEditCellCode)
+ {
+ d_creator->doCommandStartEditCellCode(this, editCell);
+ }
+ else if (dialog.isEditAxonTerminal)
+ {
+ d_creator->doCommandStartAddAxonTerminalFromAxon(this, editCell);
+ }
+ else if (dialog.isEditReceptor)
+ {
+ d_creator->doCommandStartAddAxonTerminalFromReceptor(this, editCell);
+ }
+ else if (dialog.isEditCellAttribute)
+ {
+ //TODO
+ }
+}
+
+void DCUIGraphicsScene::updateView(bool isAnimationInterval)
+{
+ DCScene::lockScene();
+
+ DCGLWidget::singleton()->makeCurrent();
+
+ d_isPaintForAnimation = isAnimationInterval;
+ d_requestRedraw = false;
+
+ update();
+}
+
+void DCUIGraphicsScene::requestRedraw(bool immediate)
+{
+ if (immediate)
+ updateView(false);
+ else
+ d_requestRedraw = true;
+}
+
+DCVComponent* DCUIGraphicsScene::getObjectAt(int viewX, int viewY, DCVComponent *priorityObject)
+{
+ if (!d_creator || !d_scene)
+ return NULL;
+
+ DCScene::lockScene();
+
+ DCGLWidget::singleton()->makeCurrent();
+
+ float _width = width();
+ float _height = height();
+ float _scale = d_scene->getScale();
+
+ GLuint selectionBuffer[512];
+ glSelectBuffer(512, selectionBuffer);
+ glRenderMode(GL_SELECT);
+ glInitNames();
+ glPushName(0);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ int viewportMat[4];
+ memcpy(viewportMat, d_viewportMatrix, sizeof(viewportMat));
+ gluPickMatrix(viewX,viewportMat[3] - viewY, 4,4,viewportMat);
+ glOrtho(-_width / _scale, _width / _scale, -_height / _scale, _height / _scale, -100.0, 100.0);
+
+ setupCamera();
+
+ QList<DCVComponent *> itemList;
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ d_scene->drawForSelection(&itemList);
+ glPopMatrix();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+
+ glFlush();
+ glMatrixMode(GL_MODELVIEW);
+
+ int items = glRenderMode(GL_RENDER);
+ DCVComponent *selectedObject = NULL;
+ DCVComponent *selectedPage = NULL;
+ int idx = 0;
+ unsigned int minDepthPage = UINT_MAX;
+ unsigned int minDepthObject = UINT_MAX;
+ if (priorityObject)
+ {
+ for (int i = 0; i < items; i++)
+ {
+ unsigned int nameLen = selectionBuffer[idx];
+ unsigned int min = selectionBuffer[idx + 1];
+ unsigned int nameId = selectionBuffer[idx + 3];
+
+ if (nameLen == 1 && nameId < (unsigned int) itemList.length())
+ {
+ DCVComponent *obj = itemList[nameId];
+ if (priorityObject == obj)
+ {
+ selectedObject = obj;
+ break;
+ }
+ if (obj->getPageBelonging() == obj)
+ {
+ if (min < minDepthPage)
+ {
+ minDepthPage = min;
+ selectedPage = obj;
+ }
+ }
+ else
+ {
+ if (obj->getIsSelectable() && min < minDepthObject)
+ {
+ minDepthObject = min;
+ selectedObject = obj;
+ }
+ }
+ }
+ idx += nameLen + 3;
+ }
+ }
+ else
+ {
+ for (int i = 0; i < items; i++)
+ {
+ unsigned int nameLen = selectionBuffer[idx];
+ unsigned int min = selectionBuffer[idx + 1];
+ unsigned int nameId = selectionBuffer[idx + 3];
+
+ if (nameLen == 1 && nameId < (unsigned int) itemList.length())
+ {
+ DCVComponent *obj = itemList[nameId];
+ if (obj->getPageBelonging() == obj)
+ {
+ if (min < minDepthPage)
+ {
+ minDepthPage = min;
+ selectedPage = obj;
+ }
+ }
+ else
+ {
+ if (obj->getIsSelectable() && min < minDepthObject)
+ {
+ minDepthObject = min;
+ selectedObject = obj;
+ }
+ }
+ }
+ idx += nameLen + 3;
+ }
+ }
+
+ DCScene::unlockScene();
+
+ return selectedObject ? selectedObject : selectedPage;
+}
+
+//slot
+void DCUIGraphicsScene::initMode()
+{
+ sceneEditModeChanged(NULL, d_scene);
+}
+
+//slot
+void DCUIGraphicsScene::doAnimation()
+{
+ if (d_requestLayoutToolWindows)
+ {
+ layoutToolWindows();
+ }
+
+ foreach (QGraphicsItem *item, items())
+ {
+ DCGraphicsProxyWidget *proxy = dynamic_cast<DCGraphicsProxyWidget*>(item);
+ if (proxy)
+ {
+ proxy->doAnimation();
+ }
+ }
+
+ if (!d_creator || !d_scene)
+ return;
+
+ if (DCScene::getShouldContinueAnimation())
+ {
+ bool r = d_scene->doAnimation();
+ DCScene::setShouldContinueAnimation(r);
+ updateView(true);
+ }
+ else if (d_requestRedraw)
+ {
+ updateView(false);
+ }
+}
+
+
+void DCUIGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
+{
+ painter->beginNativePainting();
+ setStates();
+
+ paintGL();
+
+ defaultStates();
+ painter->endNativePainting();
+}
+
+void DCUIGraphicsScene::setStates()
+{
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ initializeGL();
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+}
+
+void DCUIGraphicsScene::defaultStates()
+{
+ glPopAttrib();
+
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+
+}
+
+void DCUIGraphicsScene::initializeGL()
+{
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_MULTISAMPLE);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+ glDisable(GL_LIGHTING);
+ glDisable(GL_COLOR_MATERIAL);
+ glDisable(GL_LIGHT0);
+ glDisable(GL_NORMALIZE);
+}
+
+void DCUIGraphicsScene::paintGL()
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ setupProjection();
+
+ DCScene::lockScene();
+ glMatrixMode(GL_MODELVIEW);
+ if (d_scene)
+ {
+ glPushMatrix();
+ d_scene->draw(d_isPaintForAnimation);
+ glPopMatrix();
+ }
+ d_isPaintForAnimation = false;
+ glFlush();
+ DCScene::unlockScene();
+}
+
+void DCUIGraphicsScene::resizeEvent(const QRectF & rect)
+{
+ updateView(false);
+ requestLayoutToolWindows();
+}
+
+void DCUIGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsScene::mousePressEvent(event);
+ if (event->isAccepted()) return;
+
+ if (!d_creator || !d_scene || d_scene->getIsInModeTransition())
+ return;
+
+ QPointF mousePos = event->scenePos();
+ d_dragStartX = mousePos.x();
+ d_dragStartY = mousePos.y();
+
+ d_clickTime.start();
+
+ if (d_eventHandler)
+ d_eventHandler->mousePressEvent(event);
+}
+
+void DCUIGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsScene::mousePressEvent(event);
+ if (event->isAccepted()) return;
+
+ if (!d_creator || !d_scene || d_scene->getIsInModeTransition())
+ return;
+
+ if (d_eventHandler)
+ d_eventHandler->mouseDoubleClickEvent(event);
+}
+
+void DCUIGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsScene::mouseMoveEvent(event);
+ if (event->isAccepted()) return;
+
+ if (!d_creator || !d_scene || d_scene->getIsInModeTransition())
+ return;
+
+ if (d_eventHandler)
+ d_eventHandler->mouseMoveEvent(event, d_clickTime.elapsed());
+}
+
+void DCUIGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsScene::mouseReleaseEvent(event);
+ if (event->isAccepted()) return;
+ if (!d_creator || !d_scene || d_scene->getIsInModeTransition())
+ return;
+
+ QPointF mousePos = event->scenePos();
+
+ int dx = mousePos.x() - d_dragStartX;
+ int dy = mousePos.y() - d_dragStartY;
+
+ bool wasDrag = !(d_clickTime.elapsed() < 500 && dx * dx + dy * dy < 400);
+
+ DCGLWidget::singleton()->setCursor(Qt::ArrowCursor);
+
+ if (d_eventHandler)
+ d_eventHandler->mouseReleaseEvent(event, wasDrag);
+}
+
+void DCUIGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *event)
+{
+ QGraphicsScene::wheelEvent(event);
+
+ if (!d_creator || !d_scene)
+ return;
+
+ if (d_eventHandler)
+ d_eventHandler->wheelEvent(event);
+}
+
+void DCUIGraphicsScene::keyPressEvent(QKeyEvent *event)
+{
+ QGraphicsScene::keyPressEvent(event);
+ if (event->isAccepted()) return;
+
+ if (!d_creator || !d_scene)
+ return;
+
+ if (d_eventHandler)
+ d_eventHandler->keyPressEvent(event);
+}
+
+void DCUIGraphicsScene::keyReleaseEvent(QKeyEvent *event)
+{
+ QGraphicsScene::keyReleaseEvent(event);
+ if (event->isAccepted()) return;
+
+ if (d_eventHandler)
+ d_eventHandler->keyReleaseEvent(event);
+}
+
+void DCUIGraphicsScene::showContextMenu(const QPoint &pos)
+{
+ if (!d_creator || !d_scene)
+ return;
+
+ QPoint globalPos = DCGLWidget::singleton()->mapToGlobal(pos);
+
+ QMenu menu;
+ switch(d_scene->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ menu.addAction(tr("Edit this page"), this, SLOT(menuActionEditThisPage()));
+ menu.addAction(tr("Save change"));
+ menu.addSeparator();
+ menu.addAction(tr("Remove this page"));
+ menu.addSeparator();
+ menu.addAction(tr("Insert new page"));
+
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+
+ if (d_scene->getSelectedCellObjects().size() > 0)
+ {
+ menu.addAction(tr("Edit attributes..."));
+ menu.addAction(tr("Edit cell code..."), this, SLOT(menuActionEditCellCode()));
+ menu.addSeparator();
+ menu.addAction(tr("Edit axon terminals..."), this, SLOT(menuActionEditAxonTerminal()));
+ menu.addSeparator();
+ menu.addAction(tr("Edit receptors..."), this, SLOT(menuActionEditReceptor()));
+ }
+ else
+ {
+ menu.addAction(tr("Save change"));
+ menu.addAction(tr("Finish edit mode"), this, SLOT(menuActionFinishEditMode()));
+ }
+
+ break;
+ }
+
+ QAction* selectedItem = menu.exec(globalPos);
+ if (selectedItem)
+ {
+ // something was chosen, do stuff
+ }
+ else
+ {
+ // nothing was chosen
+ }
+}
+
+void DCUIGraphicsScene::menuActionEditThisPage()
+{
+ if (!d_creator || !d_scene)
+ return;
+
+ d_creator->changePersMode(this, DCCreator::DC_PERSMODE_NAVIGATION);
+}
+
+void DCUIGraphicsScene::menuActionEditCellCode()
+{
+ if (!d_creator || !d_scene)
+ return;
+
+ DCCell *cell = NULL;
+ bool isSingleCellSelection = false;
+ QList<DCVComponent*> list = d_scene->getSelectedCellObjects();
+ for (int i = 0; i < list.size(); i++)
+ {
+ if (cell && cell != list.at(i)->getOwnerCell())
+ {
+ isSingleCellSelection = false;
+ break;
+ }
+ else if (cell == NULL)
+ {
+ cell = list.at(i)->getOwnerCell();
+ }
+ }
+ d_creator->doCommandStartEditCellCode(this, cell);
+}
+
+void DCUIGraphicsScene::menuActionFinishEditMode()
+{
+ if (!d_creator || !d_scene)
+ return;
+
+ d_creator->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
+}
+
+void DCUIGraphicsScene::menuActionEditReceptor()
+{
+ if (!d_creator || !d_scene)
+ return;
+
+ //TODO
+}
+
+void DCUIGraphicsScene::menuActionEditAxonTerminal()
+{
+ if (!d_creator || !d_scene)
+ return;
+
+ //TODO
+}
+
+void DCUIGraphicsScene::creatorCommandExecuted()
+{
+ switch (d_scene->getEditMode())
+ {
+ case DCScene::DCV_EDITMODE_LAYOUT:
+ updateCellEditorToolWindows();
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON:
+ break;
+
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR:
+ break;
+
+ case DCScene::DCV_EDITMODE_CELLCODE:
+ break;
+ }
+
+ d_requestRedraw = true;
+}
+
+bool DCUIGraphicsScene::toObjectCoordinateXZ(float viewX, float viewY, DCVComponent *object, float *pLocalX, float *pLocalZ)
+{
+ double localX0, localY0, localZ0;
+ double localX1, localY1, localZ1;
+
+ gluUnProject(viewX, d_viewportMatrix[3] - viewY, 0, object->getModelViewMatrix(), d_projectionMatrix, d_viewportMatrix, &localX0, &localY0, &localZ0);
+ gluUnProject(viewX, d_viewportMatrix[3] - viewY, 1, object->getModelViewMatrix(), d_projectionMatrix, d_viewportMatrix, &localX1, &localY1, &localZ1);
+ double dx = localX1 - localX0;
+ double dy = localY1 - localY0;
+ double dz = localZ1 - localZ0;
+ if (dy == 0)
+ {
+ *pLocalX = 0;
+ *pLocalZ = 0;
+ return false;
+ }
+ else
+ {
+ *pLocalX = -(dx * localY0 - dy * localX0)/dy;
+ *pLocalZ = -(dz * localY0 - dy * localZ0)/dy;
+ }
+ return true;
+}
+
+void DCUIGraphicsScene::showCellEditorToolWindows()
+{
+ updateCellEditorToolWindows();
+}
+
+void DCUIGraphicsScene::updateCellEditorToolWindows()
+{
+ QList<DCVComponent*> selectedList = d_scene->getSelectedCellObjects();
+
+ for (int i = d_cellEditToolWindowList.length() - 1; i >= 0 ; i--)
+ {
+ DCToolWindowCellEditor *window = d_cellEditToolWindowList.at(i);
+ if (!window->getCell()->getVComponent()->getIsSelected())
+ {
+ removeToolWindow(window);
+ d_cellEditToolWindowList.takeAt(i);
+ d_cellEditToolWindowPool.push_back(window);
+ }
+ else
+ {
+ window->updateView();
+ requestLayoutToolWindows();
+ }
+ }
+
+ for (int i = 0; i < selectedList.length(); i++)
+ {
+ bool found = false;
+ for (int j = 0 ; j < d_cellEditToolWindowList.length(); j++)
+ {
+ if (d_cellEditToolWindowList.at(j)->getCell() == selectedList.at(i)->getOwnerCell())
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ DCToolWindowCellEditor *window = NULL;
+ if (d_cellEditToolWindowPool.length() > 0)
+ {
+ window = d_cellEditToolWindowPool.takeFirst();
+ }
+ else
+ {
+ window = new DCToolWindowCellEditor(d_creator);
+ }
+ addToolWindow(window);
+ window->setCell(selectedList.at(i)->getOwnerCell());
+ d_cellEditToolWindowList.append(window);
+ }
+ }
+}
+
+void DCUIGraphicsScene::closeAllCellEditorToolWindows()
+{
+ while (d_cellEditToolWindowList.length() > 0)
+ {
+ DCToolWindowCellEditor *window = d_cellEditToolWindowList.takeFirst();
+ removeToolWindow(window);
+ d_cellEditToolWindowPool.push_back(window);
+ }
+ requestLayoutToolWindows();
+}
+
+void DCUIGraphicsScene::showTerminalFromAxonToolWindow()
+{
+ if (d_terminalFromAxonToolWindow == NULL)
+ {
+ d_terminalFromAxonToolWindow = new DCToolWindowTerminalFromAxon(d_creator);
+ }
+ updateTerminalFromAxonToolWindow();
+ addToolWindow(d_terminalFromAxonToolWindow);
+}
+
+void DCUIGraphicsScene::updateTerminalFromAxonToolWindow()
+{
+ if (d_terminalFromAxonToolWindow)
+ {
+ d_terminalFromAxonToolWindow->updateData(d_scene->getEditAxon()->getOwnerCell(),
+ d_scene->getTerminalEditCursorLocationString(),
+ d_scene->getTerminalEditCursorDropTarget() ? d_scene->getTerminalEditCursorDropTarget()->getOwnerCell() : NULL);
+ }
+}
+
+void DCUIGraphicsScene::closeTerminalFromAxonToolWindow()
+{
+ if (d_terminalFromAxonToolWindow)
+ {
+ removeToolWindow(d_terminalFromAxonToolWindow);
+ }
+}
+
+void DCUIGraphicsScene::showTerminalFromReceptorToolWindow()
+{
+ if (d_terminalFromReceptorToolWindow == NULL)
+ {
+ d_terminalFromReceptorToolWindow = new DCToolWindowTerminalFromReceptor(d_creator);
+ }
+ updateTerminalFromReceptorToolWindow();
+ addToolWindow(d_terminalFromReceptorToolWindow);
+}
+
+void DCUIGraphicsScene::updateTerminalFromReceptorToolWindow()
+{
+ if (d_terminalFromReceptorToolWindow)
+ {
+ DCReceptor *receptor = d_scene->getEditReceptor();
+ if (receptor)
+ d_terminalFromReceptorToolWindow->updateData(dynamic_cast<DCCell*>(receptor->getOwnerCell()),
+ receptor,
+ d_scene->getTerminalEditCursorLocationString(),
+ d_scene->getTerminalEditCursorDropTarget() ? d_scene->getTerminalEditCursorDropTarget()->getOwnerCell() : NULL);
+ }
+}
+
+void DCUIGraphicsScene::closeTerminalFromReceptorToolWindow()
+{
+ if (d_terminalFromReceptorToolWindow)
+ {
+ d_terminalFromReceptorToolWindow->resetData();
+ removeToolWindow(d_terminalFromReceptorToolWindow);
+ }
+}
+
+void DCUIGraphicsScene::showCellCodeEditorToolWindow()
+{
+ if (!d_cellCodeEditor)
+ {
+ d_cellCodeEditor = new DCToolWindowCellCodeEditor(d_creator);
+ }
+ updateCellCodeEditorToolWindow();
+ removeToolWindow(d_viewControlTool);
+ addToolWindow(d_cellCodeEditor);
+}
+
+void DCUIGraphicsScene::updateCellCodeEditorToolWindow()
+{
+ if (d_cellCodeEditor)
+ {
+ DCCell *cell = d_scene->getEditCellCodeCell();
+ d_cellCodeEditor->setData(d_scene->getContainer(), cell->getCellCode(),cell );
+ }
+}
+
+void DCUIGraphicsScene::closeCellCodeEditorToolWindow()
+{
+ if (d_cellCodeEditor)
+ {
+ removeToolWindow(d_cellCodeEditor);
+ }
+ addToolWindow(d_viewControlTool);
+}
+
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCGLVISUALIZERWIDGET_H
+#define DCGLVISUALIZERWIDGET_H
+
+#include <QtGui>
+#include <QGLWidget>
+#include <QGraphicsView>
+
+class DCCreator;
+class DCVComponent;
+class DCCell;
+class DCVCPage;
+class DCVCAxon;
+class DCScene;
+class DCVEventHandler;
+class DCToolWindowBase;
+class DCToolWindowViewControl;
+class DCToolWindowCellEditor;
+class DCToolWindowTerminalFromAxon;
+class DCToolWindowTerminalFromReceptor;
+class DCToolWindowCellCodeEditor;
+
+class DCGLVisualizerWidget : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ DCGLVisualizerWidget(DCCreator *creator, QWidget *parent = 0);
+ virtual ~DCGLVisualizerWidget();
+
+ static QPointF globalPointToLocal(const QPoint &point);
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+protected slots:
+ virtual void setupViewport(QWidget *viewport);
+ virtual void setVisible ( bool visible );
+};
+
+
+class DCGraphicsProxyWidget : public QGraphicsProxyWidget
+{
+ Q_OBJECT
+
+public:
+ enum DCSticky {DC_STICKYWIDGET_NONE, DC_STICKYWIDGET_LEFT, DC_STICKYWIDGET_RIGHT};
+
+private:
+ DCSticky d_sticky;
+ float d_hasTargetPos;
+ float d_targetX;
+ float d_targetY;
+ DCToolWindowBase *d_embeddedToolWindow;
+public:
+ DCGraphicsProxyWidget(DCSticky sticky = DC_STICKYWIDGET_LEFT, QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
+ virtual ~DCGraphicsProxyWidget();
+
+ DCSticky getSticky() const { return d_sticky; }
+ int getPosPriority() const;
+
+ void setSticky(DCSticky b) { d_sticky = b; }
+ void setTargetPos(float targetX, float targetY);
+
+ void doAnimation();
+
+protected:
+ virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+ virtual void resizeEvent( QGraphicsSceneResizeEvent * event );
+
+signals:
+ void dragMoveFinished();
+ void doAnimationExecuted();
+};
+
+class DCUIGraphicsScene : public QGraphicsScene
+{
+ Q_OBJECT
+
+private:
+ void setupProjection();
+ void setupCamera();
+ void updateView(bool isAnimationInterval = false);
+
+ void layoutToolWindows();
+
+ void showCellEditorToolWindows();
+ void updateCellEditorToolWindows();
+ void closeAllCellEditorToolWindows();
+
+ void showTerminalFromAxonToolWindow();
+ void updateTerminalFromAxonToolWindow();
+ void closeTerminalFromAxonToolWindow();
+
+ void showTerminalFromReceptorToolWindow();
+ void updateTerminalFromReceptorToolWindow();
+ void closeTerminalFromReceptorToolWindow();
+
+ void showCellCodeEditorToolWindow();
+ void updateCellCodeEditorToolWindow();
+ void closeCellCodeEditorToolWindow();
+
+ DCCreator *d_creator;
+ DCScene *d_scene;
+ DCVEventHandler *d_eventHandler;
+ DCToolWindowViewControl *d_viewControlTool;
+
+ bool d_isPaintForAnimation;
+ bool d_requestRedraw;
+
+ bool d_inResigingDrag;
+ QTime d_clickTime;
+ int d_dragStartX;
+ int d_dragStartY;
+ double d_projectionMatrix[16];
+ int d_viewportMatrix[4];
+
+ bool d_requestLayoutToolWindows;
+
+ float d_stickyAreaLeftWidth;
+ float d_stickyAreaRightWidth;
+
+ QList<DCToolWindowCellEditor*> d_cellEditToolWindowList;
+ QList<DCToolWindowCellEditor*> d_cellEditToolWindowPool;
+
+ DCToolWindowTerminalFromAxon *d_terminalFromAxonToolWindow;
+ DCToolWindowTerminalFromReceptor *d_terminalFromReceptorToolWindow;
+
+ DCToolWindowCellCodeEditor *d_cellCodeEditor;
+
+public:
+ DCUIGraphicsScene(DCCreator *creator, QWidget *parent = 0);
+ virtual ~DCUIGraphicsScene();
+
+ float getStickyAreaLeftWidth() const { return d_stickyAreaLeftWidth; }
+ float getStickyAreaRightWidth() const { return d_stickyAreaRightWidth; }
+
+ void requestRedraw(bool immediate = false);
+ DCVComponent* getObjectAt(int viewX, int viewY, DCVComponent *priorityObject = NULL);
+ bool toObjectCoordinateXZ(float viewX, float viewY, DCVComponent *object, float *pLocalX, float *pLocalZ);
+ void showEditMenu(DCCell *editCell);
+
+ void addToolWindow(DCToolWindowBase *window, int x = 10, int y = 10, DCGraphicsProxyWidget::DCSticky sticky = DCGraphicsProxyWidget::DC_STICKYWIDGET_LEFT);
+ void removeToolWindow(DCToolWindowBase *window);
+
+protected:
+ virtual void drawBackground ( QPainter * painter, const QRectF & rect );
+ void setStates();
+ void defaultStates();
+
+ virtual void initializeGL();
+ virtual void paintGL();
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
+ virtual void keyPressEvent(QKeyEvent *event);
+ virtual void keyReleaseEvent(QKeyEvent *event);
+
+signals:
+
+public slots:
+ void doAnimation();
+ void initMode();
+ void creatorDestroyed();
+ void sceneChanged(const void* requester, DCScene *scene);
+ void sceneSelectedPageChanged(const void* requester, const DCScene *scene);
+ void sceneSelectedCellChanged(const void* requester, const DCScene *scene);
+ void sceneAngleChanged(const void* requester, const DCScene *scene);
+ void sceneCenterChanged(const void* requester, const DCScene *scene);
+ void sceneScaleChanged(const void* requester, const DCScene *scene);
+ void sceneSettingChanged(const void *requester, const DCScene *scene);
+ void sceneEditModeChanged(const void *requester, const DCScene *scene);
+ void showContextMenu(const QPoint&);
+ void menuActionEditThisPage();
+ void menuActionEditCellCode();
+ void menuActionFinishEditMode();
+ void menuActionEditReceptor();
+ void menuActionEditAxonTerminal();
+
+ void resizeEvent(const QRectF & rect);
+
+ void creatorCommandExecuted();
+
+ void requestLayoutToolWindows() { d_requestLayoutToolWindows = true; }
+
+ void sceneTerminalEditPageBelongingChanged(DCVCPage *page);
+ void sceneTerminalEditDropTargetChanged(DCVComponent *dropTarget);
+
+};
+
+#endif // DCGLVISUALIZERWIDGET_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcglwidget.h"
+
+DCGLWidget::DCGLWidget() : QGLWidget(QGLFormat(QGL::SampleBuffers))
+{
+}
+
+//static
+DCGLWidget* DCGLWidget::singleton()
+{
+ static DCGLWidget* instance = NULL;
+ if (instance == NULL)
+ {
+ instance = new DCGLWidget;
+ }
+ return instance;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCGLWIDGET_H
+#define DCGLWIDGET_H
+
+#include <QGLWidget>
+
+class DCGLWidget : public QGLWidget
+{
+public:
+ DCGLWidget();
+
+ static DCGLWidget* singleton();
+};
+
+#endif // DCGLWIDGET_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcscene.h"
+
+#include "dcvcpage.h"
+#include "DNUtils.h"
+#include "dccontainer.h"
+#include "dccellcode.h"
+#include "dcvceditmodecursor.h"
+
+#include <QMapIterator>
+#include <QMutex>
+#include <QtOpenGL>
+
+bool DCScene::sShouldContinueAnimation = false;
+
+DCScene::DCScene(DCContainer *owner)
+ : d_owner(owner),
+ d_vpMode(DCV_PERSMODE_NAVIGATION), d_veMode(DCV_EDITMODE_LAYOUT), d_transition(DC_TRANS_NONE),
+ d_scale(200), d_xAngle(45), d_yAngle(20),
+ d_centerX(0), d_centerBrowsModeY(0), d_centerEditModeY(0),
+ d_navigationModeSelectedPageAlpha(0.9), d_navigationModeAboveAlpha(0.15), d_navigationModeBelowAlpha(0.4),
+ d_pageEditModeSelectedPageAlpha(0.8),
+ d_navigationModeSelectedCellMovable(true), d_navigationModeOtherCellSelectable(true), d_navigationModeOtherCellVisible(true),
+ d_navigationModeOtherCellRenderFull(true),
+ d_pageEditModeOtherSamePageRenderFull(true),
+ d_pageEditModeLinkedOtherPageVisible(true), d_pageEditModeLinkedOtherPageRenderFull(false),
+ d_pageEditModeOtherOtherPageVisible(true), d_pageEditModeOtherOtherPageRenderFull(false),
+ d_editAxon(NULL), d_editReceptor(NULL), d_editCellCodeCell(NULL)
+{
+ d_terminalEditCursor = new DCVCEditModeCursor;
+ connect(d_terminalEditCursor, SIGNAL(pageBelongingChanged(DCVCPage*)), this, SLOT(slotTerminalEditCursorBelongingPageChagend(DCVCPage*)));
+ connect(d_terminalEditCursor, SIGNAL(dropTargetChanged(DCVComponent*)), this, SLOT(slotTerminalEditCursorDropTargetChanged(DCVComponent*)));
+
+}
+
+DCScene::~DCScene()
+{
+ while (!d_pages.isEmpty())
+ {
+ QMap<QString, DCVCPage*>::iterator i = d_pages.begin();
+ delete i.value();
+ d_pages.take(i.key());
+ }
+
+ d_terminalEditCursor->disconnect(this);
+ if (d_terminalEditCursor)
+ delete d_terminalEditCursor;
+}
+
+void DCScene::initMode(DCVPersMode persMode, DCVEditMode editMode)
+{
+ d_vpMode = persMode;
+ d_veMode = editMode;
+ emit modeInitialized();
+}
+
+DCVCPage* DCScene::findPage(const std::string &location)
+{
+ DNLocker(getSceneLock());
+
+ QMap<QString, DCVCPage*>::const_iterator i = d_pages.find(QString::fromStdString(location));
+ if (i != d_pages.end())
+ {
+ return i.value();
+ }
+ return NULL;
+}
+
+bool DCScene::getIsPageExist(const std::string &location) const
+{
+ DNLocker(getSceneLock());
+
+ QMap<QString, DCVCPage*>::const_iterator i = d_pages.find(QString::fromStdString(location));
+ return i != d_pages.end();
+}
+
+DCVCPage* DCScene::addPage(const std::string &location)
+{
+ DNLocker(getSceneLock());
+ QString qlocation = QString::fromStdString(location);
+ QMap<QString, DCVCPage*>::const_iterator i = d_pages.find(qlocation);
+ if (i != d_pages.end())
+ {
+ return i.value();
+ }
+ DCVCPage *newPage = new DCVCPage(qlocation);
+ d_pages.insert(qlocation, newPage);
+
+ return newPage;
+}
+
+void DCScene::setScale(const void *requester, float scale)
+{
+ d_scale = scale;
+ emit viewScaleChanged(requester);
+}
+
+void DCScene::setAngle(const void *requester, float xangle, float yangle)
+{
+ d_xAngle = xangle;
+ d_yAngle = yangle;
+ emit viewAngleChanged(requester);
+}
+
+void DCScene::setBrowsModeCenter(const void *requester, float cx, float cy)
+{
+ d_centerX = cx;
+ d_centerBrowsModeY = cy;
+ emit viewCenterChanged(requester);
+}
+
+void DCScene::setPageModeCenter(const void *requester, float cx, float cy)
+{
+ d_centerX = cx;
+ d_centerEditModeY = cy;
+ emit viewCenterChanged(requester);
+}
+
+bool DCScene::selectPage(const void *requester, const DCVCPage *page, bool multipleSelection)
+{
+ DNLocker(getSceneLock());
+ bool pageFound = false;
+
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value() == page)
+ {
+ pageFound = true;
+ i.value()->setSelected(true,false);
+ }
+ else if (!multipleSelection && i.value()->getIsSelected())
+ {
+ i.value()->setSelected(false,false);
+ }
+ }
+
+ if (pageFound)
+ {
+ emit selectedPageChanged(requester);
+ }
+ return pageFound;
+}
+
+bool DCScene::unselectPage(const void *requester, const DCVCPage *page)
+{
+ DNLocker(getSceneLock());
+ bool pageFound = false;
+
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value() == page)
+ {
+ pageFound = true;
+ i.value()->setSelected(false,false);
+ }
+ }
+
+ if (pageFound)
+ {
+ emit selectedPageChanged(requester);
+ }
+ return pageFound;
+}
+
+bool DCScene::selectPage(const void *requester, const QString &locationPath, bool multipleSelection)
+{
+ DNLocker(getSceneLock());
+ bool pageFound = false;
+
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value()->getLocationPath() == locationPath)
+ {
+ pageFound = true;
+ i.value()->setSelected(true,false);
+ }
+ else if (!multipleSelection && i.value()->getIsSelected())
+ {
+ i.value()->setSelected(false,false);
+ }
+ }
+
+ if (pageFound)
+ {
+ emit selectedPageChanged(requester);
+ }
+ return pageFound;
+}
+
+bool DCScene::unselectPage(const void *requester, const QString &locationPath)
+{
+ DNLocker(getSceneLock());
+ bool pageFound = false;
+
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value()->getLocationPath() == locationPath)
+ {
+ pageFound = true;
+ i.value()->setSelected(false,false);
+ }
+ }
+
+ if (pageFound)
+ {
+ emit selectedPageChanged(requester);
+ }
+ return pageFound;
+}
+
+bool DCScene::unselectPageAll(const void *requester)
+{
+ DNLocker(getSceneLock());
+
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ i.value()->setSelected(false,false);
+ }
+
+ emit selectedPageChanged(requester);
+ return true;
+}
+
+void DCScene::selectCellObject(const void *requester, DCVComponent *object, bool multipleSelection)
+{
+ DNLocker(getSceneLock());
+
+ bool objectSelected = false;
+ bool otherObjectSelected = false;
+
+ QList<DCVComponent*> list = d_owner->getSelectedCellObjects();
+ for (int i = 0; i < list.length(); i++)
+ {
+ if (list.at(i) == object)
+ {
+ objectSelected = true;
+ }
+ else
+ {
+ otherObjectSelected = true;
+ }
+ }
+
+ if ((multipleSelection && objectSelected) || (!multipleSelection && objectSelected && !otherObjectSelected))
+ {
+ //object selected already
+ return;
+ }
+
+ if (!multipleSelection)
+ {
+ d_owner->unselectCellObjectAll();
+ }
+ object->setSelected(true,false);
+
+ updateVisiblity();
+ emit selectedCellObjectChanged(requester);
+}
+
+void DCScene::unselectCellObject(const void *requester, DCVComponent *object)
+{
+ DNLocker(getSceneLock());
+
+ if (!object->getIsSelected())
+ {
+ return;
+ }
+
+ object->setSelected(false,false);
+
+ updateVisiblity();
+ emit selectedCellObjectChanged(requester);
+}
+
+void DCScene::unselectCellObjectAll(const void *requester)
+{
+ DNLocker(getSceneLock());
+
+ QList<DCVComponent*> list = d_owner->getSelectedCellObjects();
+ if (list.size() == 0)
+ {
+ return;
+ }
+
+ d_owner->unselectCellObjectAll();
+
+ updateVisiblity();
+ emit selectedCellObjectChanged(requester);
+}
+
+int DCScene::getNumberOfSelectedPages() const
+{
+ DNLocker(getSceneLock());
+ int cnt = 0;
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value()->getIsSelected())
+ cnt++;
+ }
+ return cnt;
+}
+
+QList<DCVCPage*> DCScene::getSelectedPages() const
+{
+ QList<DCVCPage*> list;
+
+ DNLocker(getSceneLock());
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value()->getIsSelected())
+ list.append(i.value());
+ }
+ return list;
+}
+
+QList<DCVComponent*> DCScene::getSelectedCellObjects() const
+{
+ DNLocker(getSceneLock());
+ return d_owner->getSelectedCellObjects();
+}
+
+void DCScene::updateVisiblity()
+{
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+
+
+ bool sp1,sp2,sp3,sp4,sp5,sp6;
+ bool np1,np2,np3,np4,np5,np6;
+
+ //xp1:linkedCellVisible
+ //xp2:linkedCellRenderFull
+ //xp3:linkedCellSelectable
+ //xp4:otherCellVisible
+ //xp5:otherCellRenderFull
+ //xp6:otherCellSelectable
+ //selected pages : x <= s
+ //non-selected pages: x <= n
+
+ if (d_veMode == DCV_EDITMODE_LAYOUT || d_veMode == DCV_EDITMODE_CELLCODE)
+ {
+ switch(d_vpMode)
+ {
+ case DCV_PERSMODE_NAVIGATION:
+ sp1 = true;
+ sp2 = true;
+ sp3 = true;
+ sp4 = d_navigationModeOtherCellVisible;
+ sp5 = d_navigationModeOtherCellRenderFull;
+ sp6 = d_navigationModeOtherCellSelectable;
+
+ np1 = true;
+ np2 = true;
+ np3 = true;
+ np4 = d_navigationModeOtherCellVisible;
+ np5 = d_navigationModeOtherCellRenderFull;
+ np6 = d_navigationModeOtherCellSelectable;
+ break;
+ case DCV_PERSMODE_PAGEEDIT:
+ sp1 = true;
+ sp2 = true;
+ sp3 = true;
+ sp4 = true;
+ sp5 = d_pageEditModeOtherSamePageRenderFull;
+ sp6 = true;
+
+ np1 = d_pageEditModeLinkedOtherPageVisible;
+ np2 = d_pageEditModeLinkedOtherPageRenderFull;
+ np3 = false;
+ np4 = d_pageEditModeOtherOtherPageVisible;
+ np5 = d_pageEditModeOtherOtherPageRenderFull;
+ np6 = false;
+ break;
+ }
+ }
+ else if (d_veMode == DCV_EDITMODE_TERMINAL_FROM_AXON || d_veMode == DCV_EDITMODE_TERMINAL_FROM_RECEPTOR)
+ {
+ if (d_terminalEditCursor->getIsDragging())
+ {
+ switch(d_vpMode)
+ {
+ case DCV_PERSMODE_NAVIGATION:
+ sp1 = true;
+ sp2 = true;
+ sp3 = true;
+ sp4 = d_navigationModeOtherCellVisible;
+ sp5 = d_navigationModeOtherCellRenderFull;
+ sp6 = d_navigationModeOtherCellSelectable;
+
+ np1 = true;
+ np2 = false;
+ np3 = false;
+ np4 = d_navigationModeOtherCellVisible;
+ np5 = false;
+ np6 = false;
+ break;
+ case DCV_PERSMODE_PAGEEDIT:
+ sp1 = true;
+ sp2 = true;
+ sp3 = true;
+ sp4 = true;
+ sp5 = d_pageEditModeOtherSamePageRenderFull;
+ sp6 = true;
+
+ np1 = d_pageEditModeLinkedOtherPageVisible;
+ np2 = d_pageEditModeLinkedOtherPageRenderFull;
+ np3 = false;
+ np4 = d_pageEditModeOtherOtherPageVisible;
+ np5 = d_pageEditModeOtherOtherPageRenderFull;
+ np6 = false;
+ break;
+ }
+ }
+ else
+ {
+ switch(d_vpMode)
+ {
+ case DCV_PERSMODE_NAVIGATION:
+ sp1 = true;
+ sp2 = false;
+ sp3 = true;
+ sp4 = d_navigationModeOtherCellVisible;
+ sp5 = false;
+ sp6 = false;
+
+ np1 = true;
+ np2 = false;
+ np3 = false;
+ np4 = d_navigationModeOtherCellVisible;
+ np5 = false;
+ np6 = false;
+ break;
+
+ case DCV_PERSMODE_PAGEEDIT:
+ sp1 = true;
+ sp2 = false;
+ sp3 = true;
+ sp4 = true;
+ sp5 = false;
+ sp6 = true;
+
+ np1 = d_pageEditModeLinkedOtherPageVisible;
+ np2 = false;
+ np3 = false;
+ np4 = false;
+ np5 = false;
+ np6 = false;
+ break;
+ }
+ }
+ }
+ else
+ {
+ Q_ASSERT(0);
+ }
+
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value())
+ {
+ DCVCPage *page = i.value();
+
+ if (page->getIsSelected())
+ {
+ page->updateVisiblity(sp1, sp2, sp3, sp4, sp5, sp6);
+ }
+ else
+ {
+ page->updateVisiblity(np1, np2, np3, np4, np5, np6);
+ }
+ }
+ }
+
+}
+
+void DCScene::draw(bool isAnimationInterval)
+{
+
+ getSceneLock()->lock();
+
+ {
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ //todo
+ float y = 0;
+
+ while (i.hasNext())
+ {
+ i.next();
+ glPushMatrix();
+
+ //TODO
+ glTranslatef(0,y,0);
+ i.value()->prepareForDraw(isAnimationInterval);
+ glPopMatrix();
+ y += 1;
+ }
+ }
+
+ {
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+
+ //todo
+ float y = 0;
+ float selectedPageAlpha;
+ float nonSelectedPageAlpha;
+
+ switch (d_vpMode)
+ {
+ case DCV_PERSMODE_NAVIGATION:
+ selectedPageAlpha = d_navigationModeSelectedPageAlpha;
+ nonSelectedPageAlpha = d_navigationModeBelowAlpha;
+ break;
+
+ case DCV_PERSMODE_PAGEEDIT:
+ selectedPageAlpha = d_pageEditModeSelectedPageAlpha;
+ nonSelectedPageAlpha = 0;
+ break;
+
+ }
+
+ while (i.hasNext())
+ {
+ i.next();
+ glPushMatrix();
+
+ //TODO
+ DCVCPage *page = i.value();
+ if (page->getIsSelected())
+ {
+ page->setColor(0.4, 0.4, 1, selectedPageAlpha);
+ if (d_vpMode == DCV_PERSMODE_NAVIGATION)
+ {
+ nonSelectedPageAlpha = d_navigationModeAboveAlpha;
+ }
+ else
+ {
+ selectedPageAlpha = 0;
+ }
+ }
+ else
+ {
+ page->setColor(0.2, 0.2, 0.6, nonSelectedPageAlpha);
+ }
+ glTranslatef(0,y,0);
+ page->draw(isAnimationInterval);
+ glPopMatrix();
+ y += 1;
+ }
+ }
+}
+
+void DCScene::drawForSelection(QList<DCVComponent*> *itemList)
+{
+ //todo
+ float y = 0;
+
+ getSceneLock()->lock();
+
+ QMapIterator<QString, DCVCPage*> i(d_pages);
+ while (i.hasNext())
+ {
+ i.next();
+ glPushMatrix();
+
+ //TODO
+ glTranslatef(0,y,0);
+ y += 1;
+ i.value()->drawForSelection(itemList);
+ glPopMatrix();
+ }
+ getSceneLock()->unlock();
+}
+
+bool DCScene::doAnimation()
+{
+ const int step = 10;
+
+ bool shouldContinue = false;
+
+ if (sShouldContinueAnimation)
+ {
+ switch(d_transition)
+ {
+ case DC_TRANS_TO_PAGEEDIT:
+ //xangle -> 90, yangle -> 0, step 10
+ if (abs(d_xAngle - 90) < step)
+ {
+ d_xAngle = 90;
+ }
+ else
+ {
+ d_xAngle += d_xAngle < 90 ? step : -step;
+ shouldContinue = true;
+ }
+ if (abs(d_yAngle) < step || abs(d_yAngle - 360) < step)
+ {
+ d_yAngle = 0;
+ }
+ else
+ {
+ d_yAngle += d_yAngle < 0 || d_yAngle > 180 ? step : -step;
+ shouldContinue = true;
+ }
+ if (!shouldContinue)
+ updateVisiblity();
+
+ emit viewAngleChanged(this);
+ break;
+
+ case DC_TRANS_TO_NAVIGATION:
+ {
+ //xangle -> 45, yangle -> 20
+ float dxAngle = abs(d_xAngle - 45);
+ if (dxAngle < step)
+ {
+ d_xAngle = 45;
+ }
+ else
+ {
+ d_xAngle += d_xAngle < 45 ? step : -step;
+ shouldContinue = true;
+ }
+ if (abs(d_yAngle - 20) < step)
+ {
+ d_yAngle = 20;
+ }
+ else
+ {
+ d_yAngle += d_yAngle < 20 ? step : -step;
+ shouldContinue = true;
+ }
+
+ if (shouldContinue)
+ {
+ int ls = dxAngle / step;
+ if (ls > 0)
+ d_centerEditModeY -= d_centerEditModeY / ls;
+ else
+ d_centerEditModeY = 0;
+ }
+ else
+ {
+ d_centerEditModeY = 0;
+ }
+
+ emit viewAngleChanged(this);
+ }
+ break;
+
+ case DC_TRANS_NONE:
+ break;
+
+ }
+
+ if (!shouldContinue)
+ d_transition = DC_TRANS_NONE;
+ }
+
+ return shouldContinue;
+}
+
+bool DCScene::changePersMode(const void *requester, DCVPersMode mode)
+{
+ if (mode == d_vpMode)
+ return false;
+
+ d_vpMode = mode;
+ switch(mode)
+ {
+ case DCV_PERSMODE_PAGEEDIT:
+ {
+ d_centerEditModeY = 0;
+ QList<DCVCPage*> pages = getSelectedPages();
+ QList<DCVComponent*> objs = getSelectedCellObjects();
+ for (int i = 0; i < objs.length() ; i++)
+ {
+ bool isInSelectedPage = false;
+ DCVCPage *page = objs.at(i)->getPageBelonging();
+ for (int j = 0; j < pages.length() ; j++)
+ {
+ if (page == pages.at(j))
+ {
+ isInSelectedPage = true;
+ break;
+ }
+ }
+ if (!isInSelectedPage)
+ {
+ unselectCellObject(this, objs.at(i));
+ }
+ }
+ d_transition = DC_TRANS_TO_PAGEEDIT;
+ }
+ break;
+
+ case DCV_PERSMODE_NAVIGATION:
+ d_transition = DC_TRANS_TO_NAVIGATION;
+ updateVisiblity();
+ break;
+
+ }
+ setShouldContinueAnimation(true);
+ emit viewPersModeChanged(requester);
+
+ return true;
+}
+
+bool DCScene::startTerminalEditForAxon(const void *requester, DCAxon *ownerAxon)
+{
+ d_veMode = DCV_EDITMODE_TERMINAL_FROM_AXON;
+ d_editAxon = ownerAxon;
+ d_terminalEditCursor->setOwnerFromAxon(ownerAxon);
+
+ updateVisiblity();
+ emit viewEditModeChanged(requester);
+
+ return true;
+}
+
+bool DCScene::startTerminalEditForReceptor(const void *requester, DCReceptor *ownerReceptor)
+{
+ d_veMode = DCV_EDITMODE_TERMINAL_FROM_RECEPTOR;
+ d_editReceptor = ownerReceptor;
+ d_terminalEditCursor->setOwnerFromReceptor(ownerReceptor);
+
+ updateVisiblity();
+ emit viewEditModeChanged(requester);
+
+ return true;
+}
+
+bool DCScene::startCellCodeEdit(const void *requester, DCCell *cell)
+{
+ d_veMode = DCV_EDITMODE_CELLCODE;
+
+ d_editCellCodeCell = cell;
+ updateVisiblity();
+ emit viewEditModeChanged(requester);
+
+ return true;
+}
+
+bool DCScene::finishTerminalEdit(const void *requester)
+{
+ d_veMode = DCV_EDITMODE_LAYOUT;
+ d_terminalEditCursor->unsetCursor();
+ updateVisiblity();
+ emit viewEditModeChanged(requester);
+
+ return true;
+}
+
+bool DCScene::finishCellCodeEdit(const void *requester)
+{
+ d_veMode = DCV_EDITMODE_LAYOUT;
+
+ updateVisiblity();
+ emit viewEditModeChanged(requester);
+
+ return true;
+}
+
+
+void DCScene::setNavModeSelectedPageAlpha(const void *requester, float alpha)
+{
+ d_navigationModeSelectedPageAlpha = alpha;
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setNavModeAboveAlpha(const void *requester, float alpha)
+{
+ d_navigationModeAboveAlpha = alpha;
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setNavModeBelowAlpha(const void *requester, float alpha)
+{
+ d_navigationModeBelowAlpha = alpha;
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setPageModeSelectedAlpha(const void *requester, float alpha)
+{
+ d_pageEditModeSelectedPageAlpha = alpha;
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setNavModeSelectedCellMovable(const void *requester, bool b)
+{
+ d_navigationModeSelectedCellMovable = b;
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setNavModeOtherCellSelectable(const void *requester, bool b)
+{
+ d_navigationModeOtherCellSelectable = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setNavModeOtherCellVisible(const void *requester, bool b)
+{
+ d_navigationModeOtherCellVisible = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setNavModeOtherCellRenderFull(const void *requester, bool b)
+{
+ d_navigationModeOtherCellRenderFull = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setPageModeOtherSamePageRenderFull(const void *requester, bool b)
+{
+ d_pageEditModeOtherSamePageRenderFull = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setPageModeLinkedOtherPageVisible(const void *requester, bool b)
+{
+ d_pageEditModeLinkedOtherPageVisible = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setPageModeLinkedOtherPageRenderFull(const void *requester, bool b)
+{
+ d_pageEditModeLinkedOtherPageRenderFull = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setPageModeOtherOtherPageVisible(const void *requester, bool b)
+{
+ d_pageEditModeOtherOtherPageVisible = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+void DCScene::setPageModeOtherOtherPageRenderFull(const void *requester, bool b)
+{
+ d_pageEditModeOtherOtherPageRenderFull = b;
+ updateVisiblity();
+ emit viewSettingChanged(requester);
+}
+
+QString DCScene::getTerminalEditCursorLocationString() const
+{
+ return d_terminalEditCursor->getPageBelonging()->getLocationPath();
+}
+
+DCVComponent* DCScene::getTerminalEditCursorDropTarget() const
+{
+ return d_terminalEditCursor->getDropTarget();
+}
+
+void DCScene::slotTerminalEditCursorBelongingPageChagend(DCVCPage *newPage)
+{
+ emit terminalEditCursorBelongingPageChagend(newPage);
+}
+
+void DCScene::slotTerminalEditCursorDropTargetChanged(DCVComponent *newTarget)
+{
+ emit terminalEditCursorDropTargetChanged(newTarget);
+}
+
+//static
+QMutex* DCScene::getSceneLock()
+{
+ static QMutex sLock(QMutex::Recursive);
+ return &sLock;
+}
+
+//static
+void DCScene::lockScene()
+{
+ getSceneLock()->lock();
+}
+
+//static
+void DCScene::unlockScene()
+{
+ getSceneLock()->unlock();
+}
+
+//static
+void DCScene::setShouldContinueAnimation(bool shouldContinue)
+{
+ sShouldContinueAnimation = shouldContinue;
+}
+
+//static
+bool DCScene::getShouldContinueAnimation()
+{
+ return sShouldContinueAnimation;
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCSCENE_H
+#define DCSCENE_H
+
+#include <QObject>
+#include <QString>
+#include <QMap>
+#include <QList>
+#include <QMutex>
+
+class DCContent;
+class DCVComponent;
+class DCVCPage;
+class DCVCEditModeCursor;
+class DCContainer;
+class DCCellCode;
+class DCCell;
+class DCAxon;
+class DCReceptor;
+
+class DCScene : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum DCVPersMode { DCV_PERSMODE_NAVIGATION, DCV_PERSMODE_PAGEEDIT };
+ enum DCVEditMode { DCV_EDITMODE_LAYOUT, DCV_EDITMODE_TERMINAL_FROM_AXON, DCV_EDITMODE_TERMINAL_FROM_RECEPTOR, DCV_EDITMODE_CELLCODE };
+
+private:
+ DCContainer *d_owner;
+ QMap<QString,DCVCPage*> d_pages;
+ static bool sShouldContinueAnimation;
+
+ DCVPersMode d_vpMode;
+ DCVEditMode d_veMode;
+
+ enum DCSceneTransition { DC_TRANS_NONE,
+ DC_TRANS_TO_PAGEEDIT,
+ DC_TRANS_TO_NAVIGATION
+ };
+ DCSceneTransition d_transition;
+
+ float d_scale;
+ float d_xAngle;
+ float d_yAngle;
+ float d_centerX;
+ float d_centerBrowsModeY;
+ float d_centerEditModeY;
+
+ float d_navigationModeSelectedPageAlpha;
+ float d_navigationModeAboveAlpha;
+ float d_navigationModeBelowAlpha;
+ float d_pageEditModeSelectedPageAlpha;
+
+ bool d_navigationModeSelectedCellMovable;
+ bool d_navigationModeOtherCellSelectable;
+ bool d_navigationModeOtherCellVisible;
+ bool d_navigationModeOtherCellRenderFull;
+
+ bool d_pageEditModeOtherSamePageRenderFull;
+ bool d_pageEditModeLinkedOtherPageVisible;
+ bool d_pageEditModeLinkedOtherPageRenderFull;
+ bool d_pageEditModeOtherOtherPageVisible;
+ bool d_pageEditModeOtherOtherPageRenderFull;
+
+ DCVCEditModeCursor *d_terminalEditCursor;
+ DCAxon *d_editAxon;
+ DCReceptor *d_editReceptor;
+
+ DCCell *d_editCellCodeCell;
+
+public:
+ DCScene(DCContainer *owner);
+ virtual ~DCScene();
+
+ void initMode(DCVPersMode persMode, DCVEditMode editMode);
+ //
+ static QMutex* getSceneLock();
+ static bool getShouldContinueAnimation();
+
+ DCContainer* getContainer() const { return d_owner; }
+ float getScale() const { return d_scale; }
+ float getXAngle() const { return d_xAngle; }
+ float getYAngle() const { return d_yAngle; }
+ float getCenterX() const { return d_centerX; }
+ float getCenterBrowsModeY() const { return d_centerBrowsModeY; }
+ float getCenterEditModeY() const { return d_centerEditModeY; }
+ int getNumberOfSelectedPages() const;
+ QList<DCVCPage*> getSelectedPages() const;
+ QList<DCVComponent*> getSelectedCellObjects() const;
+ DCVPersMode getPersMode() const { return d_vpMode; }
+ DCVEditMode getEditMode() const { return d_veMode; }
+ bool getIsInModeTransition() const { return d_transition != DC_TRANS_NONE; }
+
+ float getNavModeSelectedPageAlpha() const { return d_navigationModeSelectedPageAlpha; }
+ float getNavModeAboveAlpha() const { return d_navigationModeAboveAlpha; }
+ float getNavModeBelowAlpha() const { return d_navigationModeBelowAlpha; }
+ float getPageModeSelectedAlpha() const { return d_pageEditModeSelectedPageAlpha; }
+
+ bool getNavModeSelectedCellMovable() const { return d_navigationModeSelectedCellMovable; }
+ bool getNavModeOtherCellSelectable() const { return d_navigationModeOtherCellSelectable; }
+ bool getNavModeOtherCellVisible() const { return d_navigationModeOtherCellVisible; }
+ bool getNavModeOtherCellRenderFull() const { return d_navigationModeOtherCellRenderFull; }
+
+ bool getPageModeOtherSamePageRenderFull() const { return d_pageEditModeOtherSamePageRenderFull; }
+ bool getPageModeLinkedOtherPageVisible() const { return d_pageEditModeLinkedOtherPageVisible; }
+ bool getPageModeLinkedOtherPageRenderFull() const { return d_pageEditModeLinkedOtherPageRenderFull; }
+ bool getPageModeOtherOtherPageVisible() const { return d_pageEditModeOtherOtherPageVisible; }
+ bool getPageModeOtherOtherPageRenderFull() const { return d_pageEditModeOtherOtherPageRenderFull; }
+
+ DCVCEditModeCursor * getTerminalEditCursor() const { return d_terminalEditCursor; }
+ DCAxon* getEditAxon() const { return d_editAxon; }
+ DCReceptor* getEditReceptor() const { return d_editReceptor; }
+ QString getTerminalEditCursorLocationString() const;
+ DCVComponent* getTerminalEditCursorDropTarget() const;
+
+ DCCell* getEditCellCodeCell() const { return d_editCellCodeCell; }
+
+ const QMap<QString,DCVCPage*> getPages() const { return d_pages; }
+ bool getIsPageExist(const std::string& location) const;
+
+ //
+ void setNavModeSelectedPageAlpha(const void *requester, float alpha);
+ void setNavModeAboveAlpha(const void *requester, float alpha);
+ void setNavModeBelowAlpha(const void *requester, float alpha);
+ void setPageModeSelectedAlpha(const void *requester, float alpha);
+
+ void setNavModeSelectedCellMovable(const void *requester, bool b);
+ void setNavModeOtherCellSelectable(const void *requester, bool b);
+ void setNavModeOtherCellVisible(const void *requester, bool b);
+ void setNavModeOtherCellRenderFull(const void *requester, bool b);
+
+ void setPageModeOtherSamePageRenderFull(const void *requester, bool b);
+ void setPageModeLinkedOtherPageVisible(const void *requester, bool b);
+ void setPageModeLinkedOtherPageRenderFull(const void *requester, bool b);
+ void setPageModeOtherOtherPageVisible(const void *requester, bool b);
+ void setPageModeOtherOtherPageRenderFull(const void *requester, bool b);
+
+ void draw(bool isAnimationInterval);
+ void drawForSelection(QList<DCVComponent*> *itemList);
+ bool doAnimation();
+ void updateVisiblity();
+
+ DCVCPage* findPage(const std::string& location);
+
+ DCVCPage* addPage(const std::string& location);
+ void setScale(const void *requester, float scale);
+ void setAngle(const void *requester, float xangle, float yangle);
+ void setBrowsModeCenter(const void *requester, float cx, float cy);
+ void setPageModeCenter(const void *requester, float cx, float cy);
+
+ bool selectPage(const void *requester, const DCVCPage *page, bool multipleSelection);
+ bool unselectPage(const void *requester, const DCVCPage *page);
+ bool selectPage(const void *requester, const QString &locationPath, bool multipleSelection);
+ bool unselectPage(const void *requester, const QString &locationPath);
+ bool unselectPageAll(const void *requester);
+
+ void selectCellObject(const void *requester, DCVComponent *object, bool multipleSelection = false);
+ void unselectCellObject(const void *requester, DCVComponent *object);
+ void unselectCellObjectAll(const void *requester);
+
+ bool changePersMode(const void *requester, DCVPersMode mode);
+ bool startTerminalEditForAxon(const void *requester, DCAxon *ownerAxon);
+ bool startTerminalEditForReceptor(const void *requester, DCReceptor *ownerReceptor);
+ bool startCellCodeEdit(const void *requester, DCCell *cell);
+ bool finishTerminalEdit(const void *requester);
+ bool finishCellCodeEdit(const void *requester);
+
+ static void lockScene();
+ static void unlockScene();
+ static void setShouldContinueAnimation(bool shouldContinue);
+
+signals:
+ void selectedPageChanged(const void *requester);
+ void selectedCellObjectChanged(const void *requester);
+ void viewScaleChanged(const void *requester);
+ void viewAngleChanged(const void *requester);
+ void viewCenterChanged(const void *requester);
+ void viewSettingChanged(const void *requester);
+ void viewPersModeChanged(const void* requester);
+ void viewEditModeChanged(const void *requester);
+
+ void modeInitialized();
+
+ void terminalEditCursorBelongingPageChagend(DCVCPage *newPage);
+ void terminalEditCursorDropTargetChanged(DCVComponent *newTarget);
+
+private slots:
+ void slotTerminalEditCursorBelongingPageChagend(DCVCPage *newPage);
+ void slotTerminalEditCursorDropTargetChanged(DCVComponent *newTarget);
+
+};
+
+#endif // DCSCENE_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcveventhandler.h"
+
+
+DCVEventHandler::DCVEventHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene) :
+ d_widget(widget), d_creator(creator), d_scene(scene)
+{
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVEVENTHANDLER_H
+#define DCVEVENTHANDLER_H
+
+class DCScene;
+class DCCreator;
+class DCUIGraphicsScene;
+
+#include <QtGui>
+
+class DCVEventHandler
+{
+ DCUIGraphicsScene *d_widget;
+ DCCreator *d_creator;
+ DCScene *d_scene;
+
+public:
+ DCVEventHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene);
+ virtual ~DCVEventHandler() {}
+
+ inline DCUIGraphicsScene *getView() const { return d_widget; }
+ inline DCScene *getScene() const { return d_scene; }
+ inline DCCreator *getController() const { return d_creator; }
+
+ virtual int getHandlerType() const = 0;
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) = 0;
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) = 0;
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event, int clickTimeElapsed) = 0;
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event, bool wasDrag) = 0;
+ virtual void wheelEvent(QGraphicsSceneWheelEvent *event) = 0;
+ virtual void keyPressEvent(QKeyEvent *event) = 0;
+ virtual void keyReleaseEvent(QKeyEvent *event) = 0;
+};
+
+#endif // DCVEVENTHANDLER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvlayoutmodehandler.h"
+
+#include "dcglvisualizerwidget.h"
+#include "dcvcomponent.h"
+#include "dcvcpage.h"
+#include "dcvcaxon.h"
+#include "dcscene.h"
+#include "dccreator.h"
+#include "dcglwidget.h"
+
+#include "dccell.h"
+#include "dcvpagecomponent.h"
+
+#include <typeinfo>
+
+DCVLayoutModeHandler::DCVLayoutModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene) :
+ DCVEventHandler(widget, creator, scene), d_draggedObject(NULL), d_inResigingDrag(false)
+{
+
+}
+
+DCVLayoutModeHandler::~DCVLayoutModeHandler()
+{
+
+}
+
+int DCVLayoutModeHandler::getHandlerType() const
+{
+ return DCScene::DCV_EDITMODE_LAYOUT;
+}
+
+void DCVLayoutModeHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+
+ QPointF mousePos = event->scenePos();
+
+ DCVComponent *obj = getView()->getObjectAt(mousePos.x(), mousePos.y());
+ if (!obj)
+ return;
+
+ if (!obj->getIsSelectable())
+ return;
+
+ DCVCPage *page = dynamic_cast<DCVCPage*>(obj->getPageBelonging());
+ if (!page)
+ return;
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ if (obj != page)
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), page, &pageX, &pageZ);
+ getController()->selectPage(this, page, shift);
+ getController()->selectCellObject(this, obj);
+ if (obj->startDrag(pageX, 0, pageZ, false))
+ {
+ getView()->requestRedraw(true);
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ }
+ else
+ {
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ {
+ float pageX, pageZ;
+ float objX, objZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), obj, &objX, &objZ);
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), page, &pageX, &pageZ);
+ d_inResigingDrag = obj->isResizingArea(objX,0,objZ);
+ getController()->selectCellObject(this, obj);
+ if (obj->startDrag(pageX, 0, pageZ, d_inResigingDrag))
+ {
+ getView()->requestRedraw(true);
+ }
+ d_draggedObject = obj;
+ }
+ break;
+ }
+
+ event->accept();
+}
+
+void DCVLayoutModeHandler::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+ DCVComponent *obj = d_draggedObject;
+
+ if (!obj)
+ return;
+
+ if (obj->getOwnerCell() && !obj->getOwnerCell()->getVComponent()->getIsSelectable())
+ return;
+
+ DCVComponent *page = obj->getPageBelonging();
+ if (!page)
+ return;
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
+ d_draggedObject = NULL;
+ }
+
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ {
+ if (obj == page)
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_NAVIGATION);
+ d_draggedObject = NULL;
+ }
+ else
+ {
+ if (typeid(*obj) == typeid(DCVCAxon))
+ {
+ getController()->doCommandStartAddAxonTerminalFromAxon(this, obj->getOwnerCell());
+ }
+ else
+ {
+ getView()->showEditMenu(d_draggedObject->getOwnerCell());
+ }
+ }
+ }
+ break;
+ }
+
+ event->accept();
+}
+
+void DCVLayoutModeHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event, int clickTimeElapsed)
+{
+ QPointF mousePos = event->scenePos();
+ QPointF mousePrevPos = event->lastScenePos();
+
+ // This method will be called continuously while the mouse is moving.
+ // Some process we want to execute here may become heavyer and it will affect the performance.
+ // To privent this to affect the performance, we only execute the potentially heavyer
+ // process 12.5 times in a second in maximum.
+ static int lastCheckTime = 0;
+ bool canProcessHeavyTask = clickTimeElapsed - lastCheckTime < 0 || clickTimeElapsed - lastCheckTime >= 80;
+ if (canProcessHeavyTask)
+ lastCheckTime = clickTimeElapsed;
+
+
+ if (event->buttons() == Qt::LeftButton)
+ {
+ //dragging
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+ float dx = mousePos.x() - mousePrevPos.x();
+ float dy = mousePos.y() - mousePrevPos.y();
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ if (getScene()->getNavModeSelectedCellMovable() && d_draggedObject && d_draggedObject->getPageBelonging() && d_draggedObject != d_draggedObject->getPageBelonging())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+
+ if (d_draggedObject->dragging(pageX, 0, pageZ, false))
+ {
+ DCGLWidget::singleton()->setCursor(Qt::OpenHandCursor);
+ getView()->requestRedraw(false);
+ }
+ }
+ else if (!shift)
+ {
+ getController()->rotateScene(this, dy / 5.0, dx / 5.0);
+ }
+ else
+ {
+ getController()->translateBrowsModeScene(this, dx, dy);
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ if (d_draggedObject && d_draggedObject->getPageBelonging())
+ {
+ if (d_draggedObject == d_draggedObject->getPageBelonging())
+ {
+ getController()->translateEditModeScene(this, dx, dy);
+ }
+ else
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+ if (d_draggedObject->dragging(pageX, 0, pageZ, d_inResigingDrag))
+ {
+ if (d_inResigingDrag)
+ {
+ DCGLWidget::singleton()->setCursor(Qt::SizeFDiagCursor);
+ }
+ else
+ {
+ DCGLWidget::singleton()->setCursor(Qt::OpenHandCursor);
+ }
+ getView()->requestRedraw(false);
+ }
+ }
+ }
+ break;
+ }
+ }
+ else
+ {
+ //mouse moving
+ if (canProcessHeavyTask)
+ {
+ DCVComponent *obj = getView()->getObjectAt(mousePos.x(), mousePos.y());
+ float objX, objZ;
+ if (obj)
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), obj, &objX, &objZ);
+ if (obj && obj->isResizingArea(objX,0,objZ))
+ {
+ DCGLWidget::singleton()->setCursor(Qt::SizeFDiagCursor);
+ }
+ else
+ {
+ DCGLWidget::singleton()->setCursor(Qt::ArrowCursor);
+ }
+ }
+ }
+
+ event->accept();
+}
+
+void DCVLayoutModeHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, bool wasDrag)
+{
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+ QPointF mousePos = event->scenePos();
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ DCVCPage *page = NULL;
+ if (d_draggedObject)
+ {
+ page = d_draggedObject->getPageBelonging();
+ }
+
+ if (!wasDrag)
+ {
+ if (page)
+ {
+ getController()->selectPage(this, page, shift);
+ }
+ else
+ {
+ getController()->unselectPageAll(this);
+ }
+ }
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ if (d_draggedObject && d_draggedObject->getPageBelonging())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+ if (d_draggedObject->endDrag(pageX, 0, pageZ, d_inResigingDrag))
+ {
+ getView()->requestRedraw(true);
+ }
+ }
+ break;
+ }
+ event->accept();
+}
+
+void DCVLayoutModeHandler::wheelEvent(QGraphicsSceneWheelEvent *event)
+{
+ if (event->isAccepted()) return;
+
+ getController()->changeSceneScale(this, getScene()->getScale() + event->delta()/5);
+
+ event->accept();
+}
+
+void DCVLayoutModeHandler::keyPressEvent(QKeyEvent *event)
+{
+ switch(event->key())
+ {
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ {
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ if (getScene()->getSelectedPages().length() > 0)
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ if (getScene()->getSelectedCellObjects().length() == 1)
+ {
+ getView()->showEditMenu(getScene()->getSelectedCellObjects().at(0)->getOwnerCell());
+ }
+ break;
+
+ }
+ }
+ break;
+
+ case Qt::Key_Escape:
+ {
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ getController()->unselectPageAll(this);
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_NAVIGATION);
+ break;
+ }
+ }
+ break;
+ }
+}
+
+void DCVLayoutModeHandler::keyReleaseEvent(QKeyEvent *event)
+{
+
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVLAYOUTMODEHANDLER_H
+#define DCVLAYOUTMODEHANDLER_H
+
+#include "dcveventhandler.h"
+
+class DCVComponent;
+
+class DCVLayoutModeHandler : public DCVEventHandler
+{
+ DCVComponent *d_draggedObject;
+ bool d_inResigingDrag;
+
+public:
+ DCVLayoutModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene);
+ virtual ~DCVLayoutModeHandler();
+
+ virtual int getHandlerType() const;
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) ;
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) ;
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event, int clickTimeElapsed) ;
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event, bool wasDrag) ;
+ virtual void wheelEvent(QGraphicsSceneWheelEvent *event) ;
+ virtual void keyPressEvent(QKeyEvent *event) ;
+ virtual void keyReleaseEvent(QKeyEvent *event) ;
+
+};
+
+#endif // DCVLAYOUTMODEHANDLER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvterminalfromaxonmodehandler.h"
+
+#include "dcglvisualizerwidget.h"
+#include "dcvcomponent.h"
+#include "dcvcpage.h"
+#include "dcscene.h"
+#include "dccreator.h"
+#include "dcglwidget.h"
+
+#include "dccell.h"
+#include "dcaxon.h"
+#include "dcvceditmodecursor.h"
+
+
+DCVTerminalFromAxonModeHandler::DCVTerminalFromAxonModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCAxon *editAxon, DCVCEditModeCursor *cursor) :
+ DCVEventHandler(widget, creator, scene), d_draggedObject(NULL), d_inResigingDrag(false), d_editAxon(editAxon), d_cursor(cursor)
+{
+ switch(getScene()->getEditMode())
+ {
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON:
+ d_mode = TERMINAL_FROM_AXON;
+ break;
+ case DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR:
+ d_mode = TERMINAL_FROM_RECEPTOR;
+ break;
+ default:
+ Q_ASSERT(0);
+ }
+}
+
+DCVTerminalFromAxonModeHandler::~DCVTerminalFromAxonModeHandler()
+{
+ d_cursor->setDropTarget(NULL);
+}
+
+int DCVTerminalFromAxonModeHandler::getHandlerType() const
+{
+ if (d_mode == TERMINAL_FROM_AXON)
+ {
+ return DCScene::DCV_EDITMODE_TERMINAL_FROM_AXON;
+ }
+ else
+ {
+ return DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR;
+ }
+}
+
+void DCVTerminalFromAxonModeHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+
+ QPointF mousePos = event->scenePos();
+
+ DCVComponent *obj = getView()->getObjectAt(mousePos.x(), mousePos.y(), d_cursor);
+ if (!obj)
+ return;
+
+ DCVCPage *page = dynamic_cast<DCVCPage*>(obj->getPageBelonging());
+ if (!page)
+ return;
+
+ if (obj != getScene()->getTerminalEditCursor() && obj != page)
+ return;
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ if (obj != page)
+ {
+ getController()->selectPage(this, page, shift);
+ if (obj->getIsSelectable())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), page, &pageX, &pageZ);
+ if (obj->startDrag(pageX, 0, pageZ, false))
+ {
+ getScene()->updateVisiblity();
+ getView()->requestRedraw(true);
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ }
+ }
+ else
+ {
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), page, &pageX, &pageZ);
+ if (obj->startDrag(pageX, 0, pageZ, false))
+ {
+ getScene()->updateVisiblity();
+ getView()->requestRedraw(true);
+ }
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ break;
+ }
+
+ event->accept();
+}
+
+void DCVTerminalFromAxonModeHandler::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+ DCVComponent *obj = d_draggedObject;
+
+ if (!obj)
+ return;
+
+ DCVComponent *page = obj->getPageBelonging();
+ if (!page)
+ return;
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
+ d_draggedObject = NULL;
+ }
+
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ {
+ if (obj == page)
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_NAVIGATION);
+ d_draggedObject = NULL;
+ }
+ else if (obj == d_cursor)
+ {
+
+ getController()->doCommandCancelAddAxonTerminal(this);
+ }
+
+ }
+ break;
+ }
+
+ event->accept();
+}
+
+void DCVTerminalFromAxonModeHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event, int clickTimeElapsed)
+{
+ QPointF mousePos = event->scenePos();
+ QPointF mousePrevPos = event->lastScenePos();
+
+ // This method will be called continuously while the mouse is moving.
+ // Some process we want to execute here may become heavyer and it will affect the performance.
+ // To privent this to affect the performance, we only execute the potentially heavyer
+ // process 12.5 times in a second in maximum.
+ static int lastCheckTime = 0;
+ bool canProcessHeavyTask = clickTimeElapsed - lastCheckTime < 0 || clickTimeElapsed - lastCheckTime >= 80;
+ if (canProcessHeavyTask)
+ lastCheckTime = clickTimeElapsed;
+
+ if (event->buttons() == Qt::LeftButton)
+ {
+ //dragging
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+ float dx = mousePos.x() - mousePrevPos.x();
+ float dy = mousePos.y() - mousePrevPos.y();
+
+
+ if (canProcessHeavyTask && d_draggedObject && d_draggedObject != d_draggedObject->getPageBelonging())
+ {
+ d_draggedObject->setSelectable(false);
+ DCVComponent *obj = getView()->getObjectAt(mousePos.x(), mousePos.y());
+ d_draggedObject->setSelectable(true);
+
+ if (d_cursor->getDropTarget() && d_cursor->getDropTarget() != obj)
+ {
+ getController()->unselectCellObject(this, d_cursor->getDropTarget());
+ getController()->selectCellObject(this, d_editAxon->getOwnerCell()->getVComponent());
+ }
+ if (obj && obj != obj->getPageBelonging() && obj->getPageBelonging() == d_draggedObject->getPageBelonging())
+ {
+ getController()->selectCellObject(this, obj, true);
+ d_cursor->setDropTarget(obj);
+ }
+ else
+ {
+ d_cursor->setDropTarget(NULL);
+ }
+ }
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ if (d_draggedObject && d_draggedObject->getPageBelonging() && d_draggedObject != d_draggedObject->getPageBelonging())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+
+ if (d_draggedObject->dragging(pageX, 0, pageZ, false))
+ {
+ DCGLWidget::singleton()->setCursor(Qt::OpenHandCursor);
+ getView()->requestRedraw(false);
+ }
+ }
+ else if (!shift)
+ {
+ getController()->rotateScene(this, dy / 5.0, dx / 5.0);
+ }
+ else
+ {
+ getController()->translateBrowsModeScene(this, dx, dy);
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ if (d_draggedObject && d_draggedObject->getPageBelonging())
+ {
+ if (d_draggedObject == d_draggedObject->getPageBelonging())
+ {
+ getController()->translateEditModeScene(this, dx, dy);
+ }
+ else
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+ if (d_draggedObject->dragging(pageX, 0, pageZ, false))
+ {
+ DCGLWidget::singleton()->setCursor(Qt::OpenHandCursor);
+ getView()->requestRedraw(false);
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ event->accept();
+}
+
+void DCVTerminalFromAxonModeHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, bool wasDrag)
+{
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+ QPointF mousePos = event->scenePos();
+
+ if (d_draggedObject && d_draggedObject->getPageBelonging())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+ d_draggedObject->endDrag(pageX, 0, pageZ, d_inResigingDrag);
+ }
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ DCVCPage *page = NULL;
+ if (d_draggedObject)
+ {
+ page = d_draggedObject->getPageBelonging();
+ }
+
+ if (wasDrag)
+ {
+ if (d_cursor->getDropTarget())
+ {
+ getController()->doCommandCommitAddAxonTerminal(this, d_editAxon, d_cursor->getDropTarget()->getOwnerCell());
+ }
+ }
+ else
+ {
+ if (page)
+ {
+ getController()->selectPage(this, page, shift);
+ d_cursor->setPageBelonging(page);
+ }
+ else
+ {
+ getController()->unselectPageAll(this);
+ }
+ }
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ if (wasDrag)
+ {
+ if (d_cursor->getDropTarget())
+ {
+ getController()->doCommandCommitAddAxonTerminal(this, d_editAxon, d_cursor->getDropTarget()->getOwnerCell());
+ }
+ }
+
+ break;
+ }
+
+ getScene()->updateVisiblity();
+ getView()->requestRedraw(true);
+ event->accept();
+}
+
+void DCVTerminalFromAxonModeHandler::wheelEvent(QGraphicsSceneWheelEvent *event)
+{
+ if (event->isAccepted()) return;
+
+ getController()->changeSceneScale(this, getScene()->getScale() + event->delta()/5);
+
+ event->accept();
+}
+
+void DCVTerminalFromAxonModeHandler::keyPressEvent(QKeyEvent *event)
+{
+
+}
+
+void DCVTerminalFromAxonModeHandler::keyReleaseEvent(QKeyEvent *event)
+{
+
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVTERMINALFROMAXONMODEHANDLER_H
+#define DCVTERMINALFROMAXONMODEHANDLER_H
+
+#include "dcveventhandler.h"
+
+class DCAxon;
+class DCVComponent;
+class DCVCEditModeCursor;
+
+class DCVTerminalFromAxonModeHandler : public DCVEventHandler
+{
+ enum HANDLER_MODE {TERMINAL_FROM_AXON, TERMINAL_FROM_RECEPTOR};
+
+ DCVComponent *d_draggedObject;
+ bool d_inResigingDrag;
+ DCAxon *d_editAxon;
+ DCVCEditModeCursor *d_cursor;
+
+ HANDLER_MODE d_mode;
+
+public:
+ DCVTerminalFromAxonModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCAxon *editAxon, DCVCEditModeCursor *cursor);
+ virtual ~DCVTerminalFromAxonModeHandler();
+
+ virtual int getHandlerType() const;
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) ;
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) ;
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event, int clickTimeElapsed) ;
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event, bool wasDrag) ;
+ virtual void wheelEvent(QGraphicsSceneWheelEvent *event) ;
+ virtual void keyPressEvent(QKeyEvent *event) ;
+ virtual void keyReleaseEvent(QKeyEvent *event) ;
+};
+
+#endif // DCVTERMINALFROMAXONMODEHANDLER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dcvterminalfromreceptormodehandler.h"
+
+#include "dcvcomponent.h"
+#include "dcvcpage.h"
+#include "dcscene.h"
+#include "dccreator.h"
+#include "dcglwidget.h"
+
+#include "dccell.h"
+#include "dcreceptor.h"
+#include "dcvceditmodecursor.h"
+#include "dcglvisualizerwidget.h"
+
+DCVTerminalFromReceptorModeHandler::DCVTerminalFromReceptorModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCReceptor *editReceptor, DCVCEditModeCursor *cursor) :
+ DCVEventHandler(widget, creator, scene), d_draggedObject(NULL), d_inResigingDrag(false), d_editReceptor(editReceptor), d_cursor(cursor)
+{
+
+}
+
+DCVTerminalFromReceptorModeHandler::~DCVTerminalFromReceptorModeHandler()
+{
+
+}
+
+int DCVTerminalFromReceptorModeHandler::getHandlerType() const
+{
+ return DCScene::DCV_EDITMODE_TERMINAL_FROM_RECEPTOR;
+}
+
+void DCVTerminalFromReceptorModeHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+
+ QPointF mousePos = event->scenePos();
+
+ DCVComponent *obj = getView()->getObjectAt(mousePos.x(), mousePos.y(), d_cursor);
+ if (!obj)
+ return;
+
+ DCVCPage *page = dynamic_cast<DCVCPage*>(obj->getPageBelonging());
+ if (!page)
+ return;
+
+ if (obj != getScene()->getTerminalEditCursor() && obj != page)
+ return;
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ if (obj != page)
+ {
+ getController()->selectPage(this, page, shift);
+ if (obj->getIsSelectable())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), page, &pageX, &pageZ);
+ if (obj->startDrag(pageX, 0, pageZ, false))
+ {
+ getScene()->updateVisiblity();
+ getView()->requestRedraw(true);
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ }
+ }
+ else
+ {
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), page, &pageX, &pageZ);
+ if (obj->startDrag(pageX, 0, pageZ, false))
+ {
+ getScene()->updateVisiblity();
+ getView()->requestRedraw(true);
+ }
+ d_draggedObject = obj;
+ d_inResigingDrag = false;
+ }
+ break;
+ }
+
+ event->accept();
+}
+
+void DCVTerminalFromReceptorModeHandler::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+ DCVComponent *obj = d_draggedObject;
+
+ if (!obj)
+ return;
+
+ DCVComponent *page = obj->getPageBelonging();
+ if (!page)
+ return;
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
+ d_draggedObject = NULL;
+ }
+
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ {
+ if (obj == page)
+ {
+ getController()->changePersMode(this, DCCreator::DC_PERSMODE_NAVIGATION);
+ d_draggedObject = NULL;
+ }
+ else if (obj == d_cursor)
+ {
+
+ getController()->doCommandCancelAddAxonTerminal(this);
+ }
+
+ }
+ break;
+ }
+
+ event->accept();
+}
+
+void DCVTerminalFromReceptorModeHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event, int clickTimeElapsed)
+{
+ QPointF mousePos = event->scenePos();
+ QPointF mousePrevPos = event->lastScenePos();
+
+ // This method will be called continuously while the mouse is moving.
+ // Some process we want to execute here may become heavyer and it will affect the performance.
+ // To privent this to affect the performance, we only execute the potentially heavyer
+ // process 12.5 times in a second in maximum.
+ static int lastCheckTime = 0;
+ bool canProcessHeavyTask = clickTimeElapsed - lastCheckTime < 0 || clickTimeElapsed - lastCheckTime >= 80;
+ if (canProcessHeavyTask)
+ lastCheckTime = clickTimeElapsed;
+
+ if (event->buttons() == Qt::LeftButton)
+ {
+ //dragging
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+ float dx = mousePos.x() - mousePrevPos.x();
+ float dy = mousePos.y() - mousePrevPos.y();
+
+
+ if (canProcessHeavyTask && d_draggedObject && d_draggedObject != d_draggedObject->getPageBelonging())
+ {
+ d_draggedObject->setSelectable(false);
+ DCVComponent *obj = getView()->getObjectAt(mousePos.x(), mousePos.y());
+ d_draggedObject->setSelectable(true);
+ DCCell *cell = dynamic_cast<DCCell*>(d_editReceptor->getOwnerCell());
+
+ if (d_cursor->getDropTarget() && d_cursor->getDropTarget() != obj)
+ {
+ getController()->unselectCellObject(this, d_cursor->getDropTarget());
+ getController()->selectCellObject(this, cell->getVComponent());
+ }
+ if (obj && obj != obj->getPageBelonging() && obj->getPageBelonging() == d_draggedObject->getPageBelonging())
+ {
+ getController()->selectCellObject(this, obj, true);
+ d_cursor->setDropTarget(obj);
+ }
+ else
+ {
+ d_cursor->setDropTarget(NULL);
+ }
+ }
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ if (d_draggedObject && d_draggedObject->getPageBelonging() && d_draggedObject != d_draggedObject->getPageBelonging())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+
+ if (d_draggedObject->dragging(pageX, 0, pageZ, false))
+ {
+ DCGLWidget::singleton()->setCursor(Qt::OpenHandCursor);
+ getView()->requestRedraw(false);
+ }
+ }
+ else if (!shift)
+ {
+ getController()->rotateScene(this, dy / 5.0, dx / 5.0);
+ }
+ else
+ {
+ getController()->translateBrowsModeScene(this, dx, dy);
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ if (d_draggedObject && d_draggedObject->getPageBelonging())
+ {
+ if (d_draggedObject == d_draggedObject->getPageBelonging())
+ {
+ getController()->translateEditModeScene(this, dx, dy);
+ }
+ else
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+ if (d_draggedObject->dragging(pageX, 0, pageZ, false))
+ {
+ DCGLWidget::singleton()->setCursor(Qt::OpenHandCursor);
+ getView()->requestRedraw(false);
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ event->accept();
+}
+
+void DCVTerminalFromReceptorModeHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, bool wasDrag)
+{
+ bool shift = event->modifiers() & Qt::ShiftModifier;
+ QPointF mousePos = event->scenePos();
+
+ if (d_draggedObject && d_draggedObject->getPageBelonging())
+ {
+ float pageX, pageZ;
+ getView()->toObjectCoordinateXZ(mousePos.x(), mousePos.y(), d_draggedObject->getPageBelonging(), &pageX, &pageZ);
+ d_draggedObject->endDrag(pageX, 0, pageZ, d_inResigingDrag);
+ }
+
+ switch(getScene()->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ {
+ DCVCPage *page = NULL;
+ if (d_draggedObject)
+ {
+ page = d_draggedObject->getPageBelonging();
+ }
+
+ if (wasDrag)
+ {
+ if (d_cursor->getDropTarget())
+ {
+ getController()->doCommandCommitAddAxonTerminal(this, d_cursor->getDropTarget()->getOwnerCell(), d_editReceptor);
+ }
+ }
+ else
+ {
+ if (page)
+ {
+ getController()->selectPage(this, page, shift);
+ d_cursor->setPageBelonging(page);
+ }
+ else
+ {
+ getController()->unselectPageAll(this);
+ }
+ }
+ }
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ if (wasDrag)
+ {
+ if (d_cursor->getDropTarget())
+ {
+ getController()->doCommandCommitAddAxonTerminal(this, d_cursor->getDropTarget()->getOwnerCell(), d_editReceptor);
+ }
+ }
+
+ break;
+ }
+
+ getScene()->updateVisiblity();
+ getView()->requestRedraw(true);
+ event->accept();
+}
+
+void DCVTerminalFromReceptorModeHandler::wheelEvent(QGraphicsSceneWheelEvent *event)
+{
+ if (event->isAccepted()) return;
+
+ getController()->changeSceneScale(this, getScene()->getScale() + event->delta()/5);
+
+ event->accept();
+}
+
+void DCVTerminalFromReceptorModeHandler::keyPressEvent(QKeyEvent *event)
+{
+
+}
+
+void DCVTerminalFromReceptorModeHandler::keyReleaseEvent(QKeyEvent *event)
+{
+
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCVTERMINALFROMRECEPTORHANDLER_H
+#define DCVTERMINALFROMRECEPTORHANDLER_H
+
+#include "dcveventhandler.h"
+
+class DCReceptor;
+class DCVComponent;
+class DCVCEditModeCursor;
+
+class DCVTerminalFromReceptorModeHandler : public DCVEventHandler
+{
+ DCVComponent *d_draggedObject;
+ bool d_inResigingDrag;
+ DCReceptor *d_editReceptor;
+ DCVCEditModeCursor *d_cursor;
+
+public:
+ DCVTerminalFromReceptorModeHandler(DCUIGraphicsScene *widget, DCCreator *creator, DCScene *scene, DCReceptor *editReceptor, DCVCEditModeCursor *cursor);
+ virtual ~DCVTerminalFromReceptorModeHandler();
+
+ virtual int getHandlerType() const;
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) ;
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) ;
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event, int clickTimeElapsed) ;
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event, bool wasDrag) ;
+ virtual void wheelEvent(QGraphicsSceneWheelEvent *event) ;
+ virtual void keyPressEvent(QKeyEvent *event) ;
+ virtual void keyReleaseEvent(QKeyEvent *event) ;
+};
+#endif // DCVTERMINALFROMRECEPTORHANDLER_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dceditablelabel.h"
+
+#include "dctoolwindowbase.h"
+#include "dcglvisualizerwidget.h"
+
+#include <QMouseEvent>
+
+static const QString HOVERSTYLE =
+ "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgba(0,0,0,60), stop: 0.3 rgba(70,80,70,60), stop: 0.9 rgba(70,80,70,60), stop: 1.0 rgba(0,0,0,60));"
+ "border: 1px solid rgba(40,50,40,60); text-align:left; padding: 0 4px;";
+
+static const QString NORMALSTYLE =
+ "background: rgba(0,0,0,50); border: 1px solid rgba(0,0,0,60); text-align:left; padding: 0 4px;";
+
+static const QString EDITSTYLE =
+ "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(0,0,0), stop: 0.3 rgb(40,40,40), stop: 1.0 rgb(40,40,40));"
+ "border: 1px solid rgb(40,50,40); text-align:left; padding: 0 4px;";
+
+DCEditableLabel::DCEditableLabel(DCToolWindowBase *parent, const QString &text) :
+ QLineEdit(text), d_parent(parent), d_mouseOver(false)
+{
+ setReadOnly(true);
+ setStyleSheet(NORMALSTYLE);
+ setMouseTracking(true);
+ connect(parent, SIGNAL(doAnimationInToolWindow()), this, SLOT(doAnimation()));
+ connect(this, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
+}
+
+DCEditableLabel::~DCEditableLabel()
+{
+ d_parent->disconnect(this);
+}
+
+void DCEditableLabel::doAnimation()
+{
+ if (d_mouseOver)
+ {
+ QPoint p = mapFromGlobal(DCGLVisualizerWidget::globalPointToLocal(QCursor::pos()).toPoint());
+ if ( p.x() < 0 || p.x() > width() || p.y() < 0 || p.y() > height())
+ {
+ d_mouseOver = false;
+ setStyleSheet(NORMALSTYLE);
+ }
+ }
+}
+
+void DCEditableLabel::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ QLineEdit::mouseDoubleClickEvent(event);
+ setStyleSheet(EDITSTYLE);
+ setReadOnly(false);
+ selectAll();
+ d_mouseOver = false;
+}
+
+void DCEditableLabel::mouseMoveEvent(QMouseEvent *event)
+{
+ QLineEdit::mouseMoveEvent(event);
+ QPoint p = event->pos();
+
+ if ( isReadOnly() && p.x() > 0 && p.x() < width() && p.y() > 0 && p.y() < height())
+ {
+ if (!d_mouseOver)
+ {
+ d_mouseOver = true;
+ setStyleSheet(HOVERSTYLE);
+ }
+ }
+}
+
+void DCEditableLabel::labelButtonClicked()
+{
+}
+
+void DCEditableLabel::slotEditingFinished()
+{
+ setReadOnly(true);
+ setStyleSheet(NORMALSTYLE);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCEDITABLELABEL_H
+#define DCEDITABLELABEL_H
+
+#include <QtGui>
+#include <QWidget>
+#include <QStackedLayout>
+#include <QPushButton>
+#include <QLineEdit>
+
+class DCToolWindowBase;
+
+class DCEditableLabel : public QLineEdit
+{
+ Q_OBJECT
+private:
+ DCToolWindowBase *d_parent;
+ QStackedLayout *d_layout;
+ QPushButton *d_labelButton;
+ QLineEdit *d_editField;
+ bool d_mouseOver;
+
+public:
+ DCEditableLabel(DCToolWindowBase *parent, const QString &text);
+ virtual ~DCEditableLabel();
+
+protected:
+ virtual void mouseDoubleClickEvent(QMouseEvent *);
+ virtual void mouseMoveEvent(QMouseEvent *);
+
+signals:
+
+public slots:
+ void labelButtonClicked();
+ void slotEditingFinished();
+ void doAnimation();
+};
+
+#endif // DCEDITABLELABEL_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dceditabletreeview.h"
+
+const static QString NORMALSTYLE =
+ " QTreeView {"
+ " background-color: rgba(0,0,0,50);"
+ " show-decoration-selected: 1;"
+ " }"
+
+ " QTreeView::item {"
+ " border: none;"
+ " }"
+
+ " QTreeView::item:hover {"
+ " background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1 stop: 0 #6ea1f1, stop: 1 #567dbc);"
+ " border: none;"
+ " }"
+
+ " QTreeView::item:selected {"
+ " border: 1px solid #567dbc;"
+ " }"
+
+ " QTreeView::item:selected:active{"
+ " background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);"
+ " }"
+
+ " QTreeView::item:selected:!active {"
+ " background: rgba(0,0,0,0);"
+ " color: white;"
+ " }"
+
+ " QLineEdit {"
+ " background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(0,0,0), stop: 0.3 rgb(40,40,40), stop: 1.0 rgb(40,40,40));"
+ " border: none; text-align:left; padding: 0 4px;}";
+
+
+DCEditableTreeView::DCEditableTreeView(QWidget *parent) :
+ QTreeView(parent), d_maximumVisibleRow(8)
+{
+ setMinimumSize(10,10);
+ setStyleSheet(NORMALSTYLE);
+ ScrollBar *vscrollbar = new ScrollBar;
+ setVerticalScrollBar(vscrollbar);
+ connect(vscrollbar, SIGNAL(shown()), this, SLOT(slotVScrollbarShown()));
+ connect(vscrollbar, SIGNAL(hidden()), this, SLOT(slotVScrollbarHidden()));
+}
+
+DCEditableTreeView::~DCEditableTreeView()
+{
+
+}
+
+int DCEditableTreeView::calculateHeight(const QModelIndex &parent) const
+{
+ QAbstractItemModel *pModel = model();
+
+ int totalHeight = 0;
+ if (pModel)
+ {
+ int len = pModel->rowCount(parent);
+ len = len < d_maximumVisibleRow ? len : d_maximumVisibleRow;
+
+ for (int i = 0; i < len ; i++)
+ {
+ QModelIndex itemIndex = pModel->index(i,0,parent);
+ if (!isRowHidden(i,parent))
+ totalHeight += rowHeight(itemIndex);
+
+ totalHeight += calculateHeight(itemIndex);
+ }
+ }
+ return totalHeight;
+}
+
+QSize DCEditableTreeView::sizeHint() const
+{
+ QSize size = QTreeView::sizeHint();
+ if (!isHeaderHidden())
+ size.setHeight(header()->frameSize().height() + calculateHeight() + 4);
+ else
+ size.setHeight(calculateHeight() + 4);
+
+ return size;
+}
+
+void DCEditableTreeView::slotVScrollbarShown()
+{
+ emit vscrollbarShown();
+}
+
+void DCEditableTreeView::slotVScrollbarHidden()
+{
+ emit vscrollbarHidden();
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCEDITABLETREEVIEW_H
+#define DCEDITABLETREEVIEW_H
+
+#include <QtGUi>
+#include <QTreeView>
+
+class DCEditableTreeView : public QTreeView
+{
+ Q_OBJECT
+private:
+ int d_maximumVisibleRow;
+ int calculateHeight(const QModelIndex &parent = QModelIndex()) const;
+
+public:
+ explicit DCEditableTreeView(QWidget *parent = 0);
+ virtual ~DCEditableTreeView();
+
+
+protected:
+ virtual QSize sizeHint () const;
+
+signals:
+ void vscrollbarShown();
+ void vscrollbarHidden();
+
+public slots:
+ void slotVScrollbarShown();
+ void slotVScrollbarHidden();
+};
+
+class ScrollBar : public QScrollBar
+{
+ Q_OBJECT
+
+public:
+ ScrollBar() : QScrollBar() {}
+ virtual ~ScrollBar() {}
+
+protected:
+ virtual void showEvent(QShowEvent *event)
+ {
+ emit shown();
+ }
+
+ virtual void hideEvent(QHideEvent *event)
+ {
+ emit hidden();
+ }
+
+signals:
+ void shown();
+ void hidden();
+};
+
+#endif // DCEDITABLETREEVIEW_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dctoolwindowbase.h"
+
+const static QString DialogContentStyle =
+ "* {color: white} "
+ "QDialog {background-color: rgba(255,255,255,60);} "
+ "QRadioButton {background-color: transparent;} "
+ "QPlainTextEdit {background: black;} "
+ "QGroupBox { border: 1px solid gray; border-radius: 3px;} "
+ "QTableView { background: black;} "
+ "QPushButton { background-color: rgb(128,128,128);} ";
+
+DCToolWindowBase::DCToolWindowBase(const QString &windowTitle,DCCreator *creator)
+ : QDialog(0,Qt::CustomizeWindowHint | Qt::FramelessWindowHint), d_collapsed(false), d_creator(creator)
+{
+ setWindowOpacity(0.8);
+ setLayout(new QVBoxLayout);
+ layout()->setContentsMargins(0,0,0,0);
+
+ d_titleButton = new DCToolWindowTitleBar(windowTitle, this);
+ d_titleButton->setStyleSheet("* {background-color: rgb(85, 85, 255);} ");
+ connect(d_titleButton, SIGNAL(moved(int,int)), this, SLOT(slotMoveWindow(int,int)));
+ connect(d_titleButton, SIGNAL(expandOrCollapse()), this, SLOT(slotExpandOrCollapse()));
+ connect(d_titleButton, SIGNAL(dragMoveFinished()), this, SLOT(slotDragModeFinished()));
+ d_titleButtonHeight = d_titleButton->geometry().height();
+ setMinimumHeight(d_titleButtonHeight);
+ d_titleButton->setMinimumHeight(d_titleButtonHeight);
+
+ layout()->addWidget(d_titleButton);
+
+ d_layout = new QVBoxLayout;
+ d_layout->setContentsMargins(6,6,6,9);
+ ((QVBoxLayout*)layout())->addLayout(d_layout);
+
+ setStyleSheet(DialogContentStyle);
+
+}
+
+DCToolWindowBase::~DCToolWindowBase()
+{
+ this->disconnect();
+}
+
+void DCToolWindowBase::setButtonedWindowTitle(const QString &title)
+{
+ d_titleButton->setText(title);
+}
+
+void DCToolWindowBase::resizeEvent(QResizeEvent *event)
+{
+}
+
+void DCToolWindowBase::slotMoveWindow(int dx, int dy)
+{
+ QRect rect = geometry();
+ move(rect.x() + dx, rect.y() + dy);
+}
+
+void DCToolWindowBase::slotExpandOrCollapse()
+{
+ d_collapsed = !d_collapsed;
+
+ if (d_collapsed)
+ {
+ d_rect = QRect(geometry());
+ resize(d_rect.width(), d_titleButtonHeight);
+ }
+ else
+ {
+ resize(d_rect.width(), d_rect.height());
+ }
+}
+
+void DCToolWindowBase::slotDragModeFinished()
+{
+ emit dragMoveFinished();
+}
+
+DCToolWindowTitleBar::DCToolWindowTitleBar(const QString &windowTitle, QWidget *parent) : QPushButton(windowTitle, parent)
+{
+ setStyleSheet("background-color: rgb(54,72,237); color: white;");
+}
+
+DCToolWindowTitleBar::~DCToolWindowTitleBar()
+{
+ this->disconnect();
+}
+
+void DCToolWindowTitleBar::mousePressEvent(QMouseEvent *event)
+{
+ QPushButton::mousePressEvent(event);
+ QPoint p = QCursor::pos();
+ d_mousePrevX = p.x();
+ d_mousePrevY = p.y();
+ d_dragStartX = p.x();
+ d_dragStartY = p.y();
+ d_clickTime.start();
+}
+
+void DCToolWindowTitleBar::mouseMoveEvent(QMouseEvent *event)
+{
+ QPushButton::mouseMoveEvent(event);
+ QPoint p = QCursor::pos();
+ int dx = p.x() - d_mousePrevX;
+ int dy = p.y() - d_mousePrevY;
+ d_mousePrevX = p.x();
+ d_mousePrevY = p.y();
+ emit moved(dx,dy);
+}
+
+void DCToolWindowTitleBar::mouseReleaseEvent(QMouseEvent *event)
+{
+ QPushButton::mouseReleaseEvent(event);
+ QPoint p = QCursor::pos();
+ int dx = p.x() - d_dragStartX;
+ int dy = p.y() - d_dragStartY;
+
+ bool wasDrag = !(d_clickTime.elapsed() < 500 && dx * dx + dy * dy < 400);
+
+ if (!wasDrag)
+ {
+ emit expandOrCollapse();
+ }
+ else
+ {
+ emit dragMoveFinished();
+ }
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCTOOLWINDOWBASE_H
+#define DCTOOLWINDOWBASE_H
+
+#include <QtGui>
+#include <QPushButton>
+#include <QDialog>
+
+class DCCreator;
+
+class DCToolWindowTitleBar : public QPushButton
+{
+ Q_OBJECT
+
+private:
+ int d_mousePrevX;
+ int d_mousePrevY;
+ int d_dragStartX;
+ int d_dragStartY;
+ QTime d_clickTime;
+
+public:
+ DCToolWindowTitleBar(const QString &windowTitle, QWidget *parent = 0);
+ virtual ~DCToolWindowTitleBar();
+
+protected:
+ virtual void mousePressEvent(QMouseEvent * event);
+ virtual void mouseReleaseEvent(QMouseEvent * event);
+ virtual void mouseMoveEvent(QMouseEvent * event);
+
+signals:
+ void moved(int dx, int dy);
+ void expandOrCollapse();
+ void dragMoveFinished();
+
+private slots:
+
+};
+
+
+class DCToolWindowBase : public QDialog
+{
+ Q_OBJECT
+
+private:
+ QVBoxLayout *d_layout;
+ DCToolWindowTitleBar *d_titleButton;
+ bool d_collapsed;
+ QRect d_rect;
+ int d_titleButtonHeight;
+ DCCreator *d_creator;
+
+public:
+ DCToolWindowBase(const QString &windowTitle, DCCreator *creator);
+ virtual ~DCToolWindowBase();
+
+ DCCreator* getController() const { return d_creator; }
+ int getTitleButtonHeight() const { return d_titleButtonHeight; }
+ virtual int getPosPriority() const = 0;
+ QVBoxLayout* contentLayout() { return d_layout; }
+
+ void setButtonedWindowTitle(const QString &title);
+ void doAnimation() { emit doAnimationInToolWindow(); }
+
+protected:
+ virtual void resizeEvent(QResizeEvent *event);
+
+private slots:
+ void slotMoveWindow(int dx,int dy);
+ void slotExpandOrCollapse();
+ void slotDragModeFinished();
+
+signals:
+ void dragMoveFinished();
+ void doAnimationInToolWindow();
+};
+
+
+#endif // DCTOOLWINDOWBASE_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dctoolwindowcellcodeeditor.h"
+
+#include "dccodeeditor.h"
+#include "dccontainer.h"
+#include "dccell.h"
+#include "dcaxon.h"
+#include "dcaxonterminal.h"
+#include "dcreceptor.h"
+#include "dccellcode.h"
+#include "dccreator.h"
+#include "dceditablelabel.h"
+#include "dceditabletreeview.h"
+#include "utils/dcqtitemmodel.h"
+#include "dialog/dcassigncellcodeclassdialog.h"
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QStackedLayout>
+#include <QSpacerItem>
+
+
+DCToolWindowCellCodeEditor::DCToolWindowCellCodeEditor(DCCreator *creator) :
+ DCToolWindowBase("CELL CODE:", creator), d_mode(CELLCLASS_EDIT_MODE), d_container(NULL), d_cellCodeClass(NULL), d_ownerCell(NULL)
+{
+ d_editor = new DCCodeEditor;
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(d_editor);
+
+ QVBoxLayout *toolLayout = new QVBoxLayout;
+ d_uiClassGroupBox = new QGroupBox(tr("Class"));
+
+ QGridLayout *cellclassGroupBoxLayoutInnder1 = new QGridLayout;
+
+ cellclassGroupBoxLayoutInnder1->addWidget(new QLabel(tr("name")), 0,0);
+ cellclassGroupBoxLayoutInnder1->addWidget(new QLabel(tr("type")), 1,0);
+
+ d_uiClassName = new DCEditableLabel(this, "");
+ d_uiClassType = new DCEditableLabel(this, "");
+ d_uiClassUnsetButton = new QPushButton(tr("Unset class"));
+ d_uiClassUserList = new QTableView;
+ cellclassGroupBoxLayoutInnder1->addWidget(d_uiClassName, 0,1);
+ cellclassGroupBoxLayoutInnder1->addWidget(d_uiClassType, 1,1);
+ cellclassGroupBoxLayoutInnder1->addWidget(d_uiClassUnsetButton, 2,0,1,2);
+ cellclassGroupBoxLayoutInnder1->addWidget(new QLabel(tr("Cells uses the cell code")), 3,0,1,2);
+ cellclassGroupBoxLayoutInnder1->addWidget(d_uiClassUserList, 4,0,1,2);
+
+ QVBoxLayout *cellclassGroupBoxLayoutInnder2 = new QVBoxLayout;
+ d_uiClassAssignButton = new QPushButton(tr("Assign a class"));
+ cellclassGroupBoxLayoutInnder2->addWidget(new QLabel(tr("No Cell Code class is assinged.")));
+ cellclassGroupBoxLayoutInnder2->addWidget(d_uiClassAssignButton);
+
+ QWidget *uiCellCode1 = new QWidget(d_uiClassGroupBox);
+ QWidget *uiCellCode2 = new QWidget(d_uiClassGroupBox);
+ uiCellCode1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
+ uiCellCode2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
+ uiCellCode1->setLayout(cellclassGroupBoxLayoutInnder1);
+ uiCellCode2->setLayout(cellclassGroupBoxLayoutInnder2);
+ QVBoxLayout *cellclassGroupBoxLayoutOuter = new QVBoxLayout;
+ cellclassGroupBoxLayoutOuter->addWidget(uiCellCode1);
+ cellclassGroupBoxLayoutOuter->addWidget(uiCellCode2);
+
+ d_uiClassGroupBox->setLayout(cellclassGroupBoxLayoutOuter);
+ d_uiClassGroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
+ toolLayout->addWidget(d_uiClassGroupBox);
+
+ d_uiCellGroupBox = new QGroupBox(tr("Cell"));
+ QGridLayout *cellGroupBoxLayout = new QGridLayout;
+ cellGroupBoxLayout->addWidget(new QLabel(tr("name")), 0,0);
+ cellGroupBoxLayout->addWidget(new QLabel(tr("path")), 1,0);
+ cellGroupBoxLayout->addWidget(new QLabel(tr("type")), 2,0);
+
+ d_uiCellName = new DCEditableLabel(this, "");
+ d_uiCellPath = new DCEditableLabel(this, "");
+ d_uiCellType = new DCEditableLabel(this, "");
+ d_uiSwitchEditorButton = new QPushButton(tr("Open custom script"));
+ cellGroupBoxLayout->addWidget(d_uiCellName, 0,1);
+ cellGroupBoxLayout->addWidget(d_uiCellPath, 1,1);
+ cellGroupBoxLayout->addWidget(d_uiCellType, 2,1);
+
+ d_receptors = new DCEditableTreeView(this);
+ d_receptors->setHeaderHidden(true);
+ d_receptors->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ d_axonTerminals = new DCEditableTreeView(this);
+ d_axonTerminals->setHeaderHidden(true);
+ d_axonTerminals->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+
+ d_receptorItemModel = new DCQtItemModel(QStringList("name"));
+ d_axonTerminalItemModel = new DCQtItemModel(QStringList("name"));
+
+ d_receptors->setModel(d_receptorItemModel);
+ d_axonTerminals->setModel(d_axonTerminalItemModel);
+
+ cellGroupBoxLayout->addWidget(d_receptors, 3,0,1,2);
+ cellGroupBoxLayout->addWidget(d_axonTerminals, 4, 0, 1, 2);
+ cellGroupBoxLayout->addWidget(d_uiSwitchEditorButton, 5, 0,1,2);
+
+ d_uiCellGroupBox->setLayout(cellGroupBoxLayout);
+
+ toolLayout->addWidget(d_uiCellGroupBox);
+
+ toolLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Minimum, QSizePolicy::Expanding));
+
+ layout->addLayout(toolLayout);
+
+ d_uiCloseButton = new QPushButton("Close");
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Expanding));
+ buttonLayout->addWidget(d_uiCloseButton);
+
+ contentLayout()->addLayout(layout);
+ contentLayout()->addLayout(buttonLayout);
+
+ connect(d_uiCloseButton, SIGNAL(clicked()), this, SLOT(finishEditing()));
+ connect(d_uiSwitchEditorButton, SIGNAL(clicked()), this, SLOT(switchEditor()));
+ connect(d_uiClassUnsetButton, SIGNAL(clicked()), this, SLOT(unsetCellCodeButtonClicked()));
+ connect(d_uiClassAssignButton, SIGNAL(clicked()), this, SLOT(assignCellCodeButtonClicked()));
+}
+
+DCToolWindowCellCodeEditor::~DCToolWindowCellCodeEditor()
+{
+ d_receptors->disconnect(this);
+ d_axonTerminals->disconnect(this);
+
+ if (d_receptorItemModel)
+ d_receptorItemModel->deleteLater();
+
+ if (d_axonTerminalItemModel)
+ d_axonTerminalItemModel->deleteLater();
+}
+
+void DCToolWindowCellCodeEditor::setData(DCContainer *container, DCCellCode *cellCodeClass, DCCell *ownerCell)
+{
+ if (d_ownerCell && d_ownerCell != ownerCell)
+ {
+ d_ownerCell->disconnect(this);
+ }
+ if (ownerCell)
+ connect(ownerCell, SIGNAL(cellCodeChanged()), this, SLOT(classForCellChanged()));
+
+ d_container = container;
+ d_cellCodeClass = cellCodeClass;
+ d_ownerCell = ownerCell;
+
+ QString titleString = "";
+
+ bool cellCodeAvaiable = true;
+
+ if (ownerCell)
+ {
+ titleString.append("CELL : ");
+ titleString.append(QString::fromStdString(d_ownerCell->getName()));
+ titleString.append(" ");
+
+ updateCellInformation();
+ d_uiCellGroupBox->setVisible(true);
+
+ cellCodeAvaiable = d_container->isScriptableCell(ownerCell);
+ }
+ else
+ {
+ d_uiCellGroupBox->setVisible(false);
+ }
+
+
+ if (cellCodeClass && cellCodeAvaiable)
+ {
+ if (d_container->getEmptyCellCodeClass() != cellCodeClass)
+ {
+ updateClassInformation();
+ d_uiClassGroupBox->setVisible(true);
+ titleString.append("CELL CODE : ");
+ titleString.append(QString::fromStdString(cellCodeClass->getName()));
+ titleString.append(" (");
+ titleString.append(QString::fromStdString(cellCodeClass->getCellAPIName()));
+ titleString.append(")");
+ d_uiClassGroupBox->layout()->itemAt(0)->widget()->setVisible(true);
+ d_uiClassGroupBox->layout()->itemAt(1)->widget()->setVisible(false);
+ d_uiClassGroupBox->adjustSize();
+ }
+ else
+ {
+ d_uiClassGroupBox->setVisible(true);
+ d_uiClassGroupBox->layout()->itemAt(0)->widget()->setVisible(false);
+ d_uiClassGroupBox->layout()->itemAt(1)->widget()->setVisible(true);
+ d_uiClassGroupBox->adjustSize();
+ }
+ }
+ else
+ {
+ d_uiClassGroupBox->setVisible(false);
+ d_uiClassGroupBox->layout()->itemAt(0)->widget()->setVisible(false);
+ d_uiClassGroupBox->layout()->itemAt(1)->widget()->setVisible(false);
+ d_editor->setPlainText("");
+ d_editor->setReadOnly(true);
+ }
+
+ setButtonedWindowTitle(titleString);
+ showClassScript();
+}
+
+void DCToolWindowCellCodeEditor::setData(DCContainer *container, DCCell *ownerCell)
+{
+ if (d_ownerCell && d_ownerCell != ownerCell)
+ {
+ d_ownerCell->disconnect(this);
+ }
+ if (ownerCell)
+ connect(ownerCell, SIGNAL(cellCodeChanged()), this, SLOT(classForCellChanged()));
+
+ d_container = container;
+ d_ownerCell = ownerCell;
+
+ if (ownerCell)
+ {
+ d_cellCodeClass = ownerCell->getCellCode();
+ }
+
+
+ QString titleString = "";
+
+ if (ownerCell)
+ {
+ titleString.append("CELL : ");
+ titleString.append(QString::fromStdString(d_ownerCell->getName()));
+ titleString.append(" ");
+
+ updateCellInformation();
+ d_uiCellGroupBox->setVisible(true);
+ }
+ else
+ {
+ d_uiCellGroupBox->setVisible(false);
+ }
+
+ if (d_cellCodeClass && d_cellCodeClass != d_container->getEmptyCellCodeClass())
+ {
+ updateClassInformation();
+ d_uiClassGroupBox->setVisible(true);
+ titleString.append("CELL CODE : ");
+ titleString.append(QString::fromStdString(d_cellCodeClass->getName()));
+ titleString.append(" (");
+ titleString.append(QString::fromStdString(d_cellCodeClass->getCellAPIName()));
+ titleString.append(")");
+
+ }
+ else
+ {
+ d_uiClassGroupBox->setVisible(false);
+ d_editor->setPlainText("");
+ d_editor->setReadOnly(true);
+ }
+
+ setButtonedWindowTitle(titleString);
+ showCustomScript();
+}
+
+void DCToolWindowCellCodeEditor::showClassScript()
+{
+ d_mode = CELLCLASS_EDIT_MODE;
+ d_uiClassGroupBox->setVisible(true);
+ d_uiSwitchEditorButton->setText(tr("Switch to Custom Script"));
+ if (d_cellCodeClass && d_cellCodeClass != d_container->getEmptyCellCodeClass() && d_container)
+ {
+ d_editor->setPlainText(d_cellCodeClass->getOwnScript(d_container));
+ d_editor->setReadOnly(false);
+ }
+ else
+ {
+ d_editor->setPlainText("");
+ d_editor->setReadOnly(true);
+ }
+}
+
+void DCToolWindowCellCodeEditor::showCustomScript()
+{
+ d_mode = CUSTOMSCRIPT_EDIT_MODE;
+ d_uiClassGroupBox->setVisible(false);
+ d_uiSwitchEditorButton->setText(tr("Switch to Cell Code"));
+ if (d_ownerCell)
+ {
+ d_editor->setPlainText(d_ownerCell->getCustomScript());
+ d_editor->setReadOnly(false);
+ }
+ else
+ {
+ d_editor->setPlainText("");
+ d_editor->setReadOnly(true);
+ }
+}
+
+void DCToolWindowCellCodeEditor::updateClassInformation()
+{
+ if (d_cellCodeClass)
+ {
+ d_uiClassName->setText(QString::fromStdString(d_cellCodeClass->getName()));
+ d_uiClassType->setText(QString::fromStdString(d_cellCodeClass->getCellAPIName()));
+ }
+ else
+ {
+ d_uiClassName->setText("");
+ d_uiClassType->setText("");
+ }
+}
+
+void DCToolWindowCellCodeEditor::updateCellInformation()
+{
+ d_receptorItemModel->removeAllItems();
+ d_axonTerminalItemModel->removeAllItems();
+
+ if (d_ownerCell)
+ {
+ d_uiCellName->setText(QString::fromStdString(d_ownerCell->getName()));
+ d_uiCellPath->setText(QString::fromStdString(d_ownerCell->getLocation()));
+ d_uiCellType->setText(d_ownerCell->getType());
+
+ d_receptorItemModel->insertString("receptors");
+ d_receptorItemModel->setReadOnly(0,true);
+
+ d_axonTerminalItemModel->insertString("axonTerminals");
+ d_axonTerminalItemModel->setReadOnly(0,true);
+
+ const TKReceptorMap *receptors = d_ownerCell->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ QModelIndex rroot = d_receptorItemModel->index(0,0);
+ int i = 0;
+ while( it != receptors->end())
+ {
+ QString receptorName = QString::fromStdString((*it).first);
+ d_receptorItemModel->insertString(receptorName,rroot);
+ ++it;
+ ++i;
+ }
+
+ QModelIndex aroot = d_axonTerminalItemModel->index(0,0);
+ DCAxon *axon = d_ownerCell->getAxon();
+ int acnt = axon->getNumberOfTerminals();
+ for (int i = 0; i < acnt; i++)
+ {
+ DCReceptor *targetReceptor = NULL;
+ DCCell *targetCell = NULL;
+ DCAxonTerminal *tarminal = axon->getTerminalAt(i);
+ if (tarminal)
+ {
+ targetReceptor = dynamic_cast<DCReceptor*>(tarminal->getTarget());
+ if (targetReceptor)
+ {
+ targetCell = dynamic_cast<DCCell*>(targetReceptor->getOwnerCell());
+ }
+ }
+ QString axonTerminalName;
+
+ if (targetCell)
+ {
+ QTextStream(&axonTerminalName)
+ << QString::fromStdString(targetCell->getLocation())
+ << "/"
+ << QString::fromStdString(targetCell->getName())
+ << "#"
+ << QString::fromStdString(targetCell->getReceptorName(targetReceptor));
+ }
+ else
+ {
+ axonTerminalName = "-";
+ }
+
+ d_axonTerminalItemModel->insertString(axonTerminalName,aroot);
+ }
+ d_receptors->expandAll();
+ d_axonTerminals->expandAll();
+ }
+ else
+ {
+ d_uiCellName->setText("");
+ d_uiCellPath->setText("");
+ d_uiCellType->setText("");
+ }
+}
+
+void DCToolWindowCellCodeEditor::switchEditor()
+{
+ saveScriptToFile();
+ if (d_mode == CELLCLASS_EDIT_MODE)
+ {
+ showCustomScript();
+ }
+ else
+ {
+ showClassScript();
+ }
+}
+
+void DCToolWindowCellCodeEditor::saveScriptToFile()
+{
+ switch(d_mode)
+ {
+ case CELLCLASS_EDIT_MODE:
+ if (d_cellCodeClass)
+ d_cellCodeClass->saveScript(d_container, d_editor->toPlainText());
+ break;
+
+ case CUSTOMSCRIPT_EDIT_MODE:
+ d_ownerCell->saveCustomScript(d_editor->toPlainText());
+ break;
+
+ }
+
+}
+
+void DCToolWindowCellCodeEditor::finishEditing()
+{
+ saveScriptToFile();
+ getController()->doCommandStopEditCellCode(this);
+}
+
+void DCToolWindowCellCodeEditor::unsetCellCodeButtonClicked()
+{
+ getController()->doCommandUnsetCellCodeClass(this, d_ownerCell);
+}
+
+void DCToolWindowCellCodeEditor::assignCellCodeButtonClicked()
+{
+ DCAssignCellCodeClassDialog dialog(d_container, getController());
+ dialog.exec();
+ DCCellCode *cellCode = dialog.getSelectedCellCodeClass();
+ if (cellCode)
+ {
+ getController()->doCommandSetCellCodeClass(this, d_ownerCell, cellCode);
+ }
+}
+
+void DCToolWindowCellCodeEditor::classForCellChanged()
+{
+ setData(d_container, d_ownerCell->getCellCode(), d_ownerCell);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCTOOLWINDOWCELLCODEEDITOR_H
+#define DCTOOLWINDOWCELLCODEEDITOR_H
+
+#include "dctoolwindowbase.h"
+
+class DCCodeEditor;
+class DCCell;
+class DCCellCode;
+class DCContainer;
+
+class DCEditableLabel;
+class DCEditableTreeView;
+class DCQtItemModel;
+
+class DCToolWindowCellCodeEditor : public DCToolWindowBase
+{
+ Q_OBJECT
+private:
+ enum DCScriptEditMode { CELLCLASS_EDIT_MODE, CUSTOMSCRIPT_EDIT_MODE };
+
+ DCScriptEditMode d_mode;
+ DCContainer *d_container;
+ DCCodeEditor *d_editor;
+ DCCellCode *d_cellCodeClass;
+ DCCell *d_ownerCell;
+
+ QGroupBox *d_uiClassGroupBox;
+ DCEditableLabel *d_uiClassName;
+ DCEditableLabel *d_uiClassType;
+ QTableView *d_uiClassUserList;
+ QPushButton *d_uiClassUnsetButton;
+ QPushButton *d_uiClassAssignButton;
+
+ QGroupBox *d_uiCellGroupBox;
+ DCEditableLabel *d_uiCellName;
+ DCEditableLabel *d_uiCellPath;
+ DCEditableLabel *d_uiCellType;
+ DCEditableTreeView *d_receptors;
+ DCQtItemModel *d_receptorItemModel;
+ DCEditableTreeView *d_axonTerminals;
+ DCQtItemModel *d_axonTerminalItemModel;
+ QPushButton *d_uiSwitchEditorButton;
+
+ QPushButton *d_uiCloseButton;
+
+ void updateCellInformation();
+ void updateClassInformation();
+ void showClassScript();
+ void showCustomScript();
+
+public:
+ DCToolWindowCellCodeEditor(DCCreator *creator);
+ virtual ~DCToolWindowCellCodeEditor();
+
+ virtual int getPosPriority() const { return 1; }
+
+ void setData(DCContainer *container, DCCellCode *cellCodeClass, DCCell *ownerCell = NULL);
+ void setData(DCContainer *container, DCCell *ownerCell);
+
+signals:
+
+public slots:
+ void finishEditing();
+ void saveScriptToFile();
+ void switchEditor();
+
+private slots:
+ void unsetCellCodeButtonClicked();
+ void assignCellCodeButtonClicked();
+ void classForCellChanged();
+
+};
+
+#endif // DCTOOLWINDOWCELLCODEEDITOR_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dctoolwindowcelleditor.h"
+
+#include "dceditablelabel.h"
+#include "dceditabletreeview.h"
+#include "dccell.h"
+#include "dccreator.h"
+#include "dcreceptor.h"
+#include "dcaxon.h"
+#include "dccellcode.h"
+#include "dcaxonterminal.h"
+#include "dccontainer.h"
+#include "utils/dcresources.h"
+#include "utils/dcqtitemmodel.h"
+
+#include <QGridLayout>
+#include <QLineEdit>
+#include <QTreeView>
+#include <QSizePolicy>
+#include <QIcon>
+
+DCToolWindowCellEditor::DCToolWindowCellEditor(DCCreator *creator) :
+ DCToolWindowBase("CELL:", creator), d_cell(NULL)
+{
+ d_layout = new QGridLayout;
+ d_layout->setSpacing(6);
+ d_layout->setContentsMargins(0,0,0,0);
+ d_layout->addWidget(new QLabel(tr("page")),0,0);
+ d_layout->addWidget(new QLabel(tr("type")),1,0);
+ d_layout->addWidget(new QLabel(tr("cell code")),2,0);
+ d_layout->addWidget(new QLabel(tr("custom script")),3,0);
+
+ d_detailButton = new QPushButton(tr("detail..."));
+ d_detailButton->setStyleSheet("background-color: rgba(255,255,255,60);");
+
+ d_layout->addWidget(d_detailButton,6,0,1,2);
+
+ d_textPage = new DCEditableLabel(this, "");
+ d_textType = new DCEditableLabel(this, "");
+ d_layout->addWidget(d_textPage, 0,1);
+ d_layout->addWidget(d_textType, 1,1);
+
+ d_classButton = new QPushButton("...");
+ QPushButton *customScriptEditButton = new QPushButton(tr("edit..."));
+
+ d_layout->addWidget(d_classButton, 2,1);
+ d_layout->addWidget(customScriptEditButton, 3,1);
+
+ d_receptors = new DCEditableTreeView(this);
+ d_receptors->setHeaderHidden(true);
+ d_receptors->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ d_axonTerminals = new DCEditableTreeView(this);
+ d_axonTerminals->setHeaderHidden(true);
+ d_axonTerminals->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+
+ d_receptorItemModel = new DCQtItemModel(QStringList("name"));
+ d_axonTerminalItemModel = new DCQtItemModel(QStringList("name"));
+
+ d_receptors->setModel(d_receptorItemModel);
+ d_axonTerminals->setModel(d_axonTerminalItemModel);
+
+ d_layout->addWidget(d_receptors, 4,0,1,2);
+ d_layout->addWidget(d_axonTerminals, 5, 0, 1, 2);
+
+ contentLayout()->addLayout(d_layout);
+
+ connect(d_receptors, SIGNAL(collapsed(QModelIndex)), this, SLOT(slotReceptorTreeCollapsed(QModelIndex)));
+ connect(d_receptors, SIGNAL(expanded(QModelIndex)), this, SLOT(slotReceptorTreeExpanded(QModelIndex)));
+ connect(d_receptors, SIGNAL(clicked(QModelIndex)), this, SLOT(slotReceptorItemClicked(QModelIndex)));
+ connect(d_receptors, SIGNAL(vscrollbarShown()), this, SLOT(adjustTreeColumnWidth()));
+ connect(d_receptors, SIGNAL(vscrollbarHidden()), this, SLOT(adjustTreeColumnWidth()));
+ connect(d_axonTerminals, SIGNAL(collapsed(QModelIndex)), this, SLOT(slotAxonTerminalTreeCollapsed(QModelIndex)));
+ connect(d_axonTerminals, SIGNAL(expanded(QModelIndex)), this, SLOT(slotAxonTerminalTreeExpanded(QModelIndex)));
+ connect(d_axonTerminals, SIGNAL(clicked(QModelIndex)), this, SLOT(slotAxonTerminalItemClicked(QModelIndex)));
+ connect(d_axonTerminals, SIGNAL(vscrollbarShown()), this, SLOT(adjustTreeColumnWidth()));
+ connect(d_axonTerminals, SIGNAL(vscrollbarHidden()), this, SLOT(adjustTreeColumnWidth()));
+
+ connect(d_classButton, SIGNAL(clicked()), this, SLOT(slotCellCodeEditButtonPressed()));
+ connect(customScriptEditButton, SIGNAL(clicked()), this, SLOT(slotCustomScriptEditButtonPressed()));
+
+}
+
+DCToolWindowCellEditor::~DCToolWindowCellEditor()
+{
+ d_receptors->disconnect(this);
+ d_axonTerminals->disconnect(this);
+
+ if (d_receptorItemModel)
+ d_receptorItemModel->deleteLater();
+
+ if (d_axonTerminalItemModel)
+ d_axonTerminalItemModel->deleteLater();
+}
+
+void DCToolWindowCellEditor::setCell(DCCell *cell)
+{
+ d_cell = cell;
+ QString title = "CELL:";
+ if (cell)
+ {
+ title.append(QString::fromStdString(cell->getName()));
+ if (cell->getCellCode() && cell->getCellCode() != getController()->getCurrentContainer()->getEmptyCellCodeClass())
+ {
+ d_classButton->setText(QString::fromStdString(cell->getCellCode()->getName()));
+ }
+ else
+ {
+ d_classButton->setText("...");
+ }
+ }
+
+ setButtonedWindowTitle(title);
+ updateView();
+}
+
+void DCToolWindowCellEditor::updateView()
+{
+ d_receptorItemModel->removeAllItems();
+ d_axonTerminalItemModel->removeAllItems();
+
+ if (d_cell)
+ {
+ d_textPage->setText(QString::fromStdString(d_cell->getLocation()));
+ d_textType->setText(d_cell->getType());
+
+ d_receptorItemModel->insertString("receptors");
+ d_receptorItemModel->insertColumns(1,2);
+ d_receptorItemModel->setReadOnly(0,false);
+ d_receptorItemModel->setData(d_receptorItemModel->index(0,1), QVariant::fromValue(DCResources::addItemIcon()));
+
+ d_axonTerminalItemModel->insertString("axonTerminals");
+ d_axonTerminalItemModel->insertColumns(1,2);
+ d_axonTerminalItemModel->setReadOnly(0,false);
+ d_axonTerminalItemModel->setData(d_axonTerminalItemModel->index(0,1), QVariant::fromValue(DCResources::addItemIcon()));
+
+ const TKReceptorMap *receptors = d_cell->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ QModelIndex rroot = d_receptorItemModel->index(0,0);
+ int i = 0;
+ while( it != receptors->end())
+ {
+
+ QString receptorName = QString::fromStdString((*it).first);
+ d_receptorItemModel->insertString(receptorName,rroot);
+ d_receptorItemModel->setData(rroot.child(i,2), QVariant::fromValue(DCResources::deleteItemIcon()));
+ ++it;
+ ++i;
+ }
+
+ QModelIndex aroot = d_axonTerminalItemModel->index(0,0);
+ DCAxon *axon = d_cell->getAxon();
+ int acnt = axon->getNumberOfTerminals();
+ for (int i = 0; i < acnt; i++)
+ {
+ DCReceptor *targetReceptor = NULL;
+ DCCell *targetCell = NULL;
+ DCAxonTerminal *tarminal = axon->getTerminalAt(i);
+ if (tarminal)
+ {
+ targetReceptor = dynamic_cast<DCReceptor*>(tarminal->getTarget());
+ if (targetReceptor)
+ {
+ targetCell = dynamic_cast<DCCell*>(targetReceptor->getOwnerCell());
+ }
+ }
+ QString axonTerminalName;
+
+ if (targetCell)
+ {
+ QTextStream(&axonTerminalName)
+ << QString::fromStdString(targetCell->getLocation())
+ << "/"
+ << QString::fromStdString(targetCell->getName())
+ << "#"
+ << QString::fromStdString(targetCell->getReceptorName(targetReceptor));
+ }
+ else
+ {
+ axonTerminalName = "-";
+ }
+
+ d_axonTerminalItemModel->insertString(axonTerminalName,aroot);
+ d_receptorItemModel->setData(aroot.child(i,2), QVariant::fromValue(DCResources::deleteItemIcon()));
+ }
+ d_receptors->expandAll();
+ d_axonTerminals->expandAll();
+
+ resizeView();
+ }
+}
+
+void DCToolWindowCellEditor::slotReceptorTreeCollapsed(const QModelIndex &index)
+{
+ resizeView();
+}
+
+void DCToolWindowCellEditor::slotReceptorTreeExpanded(const QModelIndex &index)
+{
+ resizeView();
+}
+
+void DCToolWindowCellEditor::slotReceptorItemClicked(const QModelIndex &index)
+{
+ switch (index.column())
+ {
+ case 1:
+ qDebug() << "add item clicked..";
+ if (!index.parent().isValid())
+ {
+ getController()->doCommandStartAddAxonTerminalFromReceptor(this, d_cell);
+ }
+ break;
+
+ case 2:
+ qDebug() << "delete item clicked..";
+ if (index.parent().row() == 0)
+ {
+ int itemRowIndex = index.row();
+ if (itemRowIndex >= 0)
+ {
+ QModelIndex itemIndex = d_receptorItemModel->index(itemRowIndex,0,index.parent());
+ QString receptorName = d_receptorItemModel->data(itemIndex,Qt::DisplayRole).toString();
+ if (receptorName.length()>0)
+ {
+ d_receptors->setCurrentIndex(itemIndex);
+ getController()->doCommandDeleteAxonTerminal(this, d_cell, receptorName);
+ }
+ }
+ }
+ break;
+
+ default:
+ qDebug() << "other clicked..";
+ break;
+
+ }
+
+}
+
+void DCToolWindowCellEditor::slotAxonTerminalTreeCollapsed(const QModelIndex &index)
+{
+ resizeView();
+}
+
+void DCToolWindowCellEditor::slotAxonTerminalTreeExpanded(const QModelIndex &index)
+{
+ resizeView();
+}
+
+void DCToolWindowCellEditor::slotAxonTerminalItemClicked(const QModelIndex &index)
+{
+ switch (index.column())
+ {
+ case 1:
+ qDebug() << "add item clicked..";
+ if (!index.parent().isValid())
+ {
+ getController()->doCommandStartAddAxonTerminalFromAxon(this, d_cell);
+ }
+ break;
+
+ case 2:
+ qDebug() << "delete item clicked..";
+ if (index.parent().row() == 0)
+ {
+ int itemIndex = index.row();
+ if (itemIndex >= 0)
+ {
+ d_axonTerminals->setCurrentIndex(d_axonTerminalItemModel->index(itemIndex,0,index.parent()));
+ getController()->doCommandDeleteAxonTerminal(this, d_cell, d_cell->getAxon()->getTerminalAt(itemIndex));
+ }
+ }
+ break;
+
+ default:
+ qDebug() << "other clicked..";
+ break;
+
+ }
+}
+
+void DCToolWindowCellEditor::slotCellCodeEditButtonPressed()
+{
+ if (d_cell)
+ {
+ getController()->doCommandStartEditCellCode(this, d_cell);
+ }
+}
+
+void DCToolWindowCellEditor::slotCustomScriptEditButtonPressed()
+{
+ if (d_cell)
+ {
+ getController()->doCommandStartEditCellCode(this, d_cell);
+ }
+}
+
+// TODO
+// There may be better / proper way to do this.
+// The goal is to adjust the window height to fit all inside components
+// with its desigered size.
+void DCToolWindowCellEditor::resizeView()
+{
+ int totalHeight = 0;
+ int spacing = d_layout->verticalSpacing();
+ for (int i = 0 ; i < d_layout->rowCount(); i++ )
+ {
+ int maxHeightInRow = 0;
+ for (int j = 0; j < d_layout->columnCount(); j++)
+ {
+ QLayoutItem *item = d_layout->itemAtPosition(i,j);
+ if (item)
+ {
+ QWidget *pWidget = item->widget();
+ if (pWidget)
+ {
+ QSize sh = pWidget->sizeHint();
+ pWidget->setFixedHeight(sh.height());
+ if (sh.height() > maxHeightInRow)
+ {
+ maxHeightInRow = sh.height();
+ }
+ }
+ }
+ }
+ totalHeight += maxHeightInRow + spacing;
+ }
+
+ QSize s = size();
+ int left,top,right,bottom;
+ contentLayout()->getContentsMargins(&left,&top,&right,&bottom);
+ s.setHeight(totalHeight + getTitleButtonHeight() + top + bottom);
+ resize(s);
+
+ adjustTreeColumnWidth();
+}
+
+void DCToolWindowCellEditor::adjustTreeColumnWidth()
+{
+ d_receptors->setColumnWidth(1, 18);
+ d_receptors->setColumnWidth(2, 18);
+ QScrollBar *sb = d_receptors->verticalScrollBar();
+ if (sb && sb->isVisible())
+ d_receptors->setColumnWidth(0, d_receptors->width()-44 - sb->width());
+ else
+ d_receptors->setColumnWidth(0, d_receptors->width()-42);
+
+ d_axonTerminals->setColumnWidth(1, 18);
+ d_axonTerminals->setColumnWidth(2, 18);
+ d_axonTerminals->setColumnWidth(0, d_axonTerminals->width()-42);
+ sb = d_axonTerminals->verticalScrollBar();
+ if (sb && sb->isVisible())
+ d_axonTerminals->setColumnWidth(0, d_axonTerminals->width()-44 - sb->width());
+ else
+ d_axonTerminals->setColumnWidth(0, d_axonTerminals->width()-42);
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCTOOLWINDOWCELLEDITOR_H
+#define DCTOOLWINDOWCELLEDITOR_H
+
+#include "dctoolwindowbase.h"
+
+#include <QtGui>
+
+class DCCell;
+class DCEditableTreeView;
+class DCQtItemModel;
+class DCEditableLabel;
+
+class DCToolWindowCellEditor : public DCToolWindowBase
+{
+ Q_OBJECT
+private:
+ DCCell *d_cell;
+ DCEditableLabel *d_textPage;
+ DCEditableLabel *d_textType;
+ QPushButton *d_classButton;
+ QPushButton *d_detailButton;
+ DCEditableTreeView *d_receptors;
+ DCQtItemModel *d_receptorItemModel;
+ DCEditableTreeView *d_axonTerminals;
+ DCQtItemModel *d_axonTerminalItemModel;
+ QGridLayout *d_layout;
+
+ void resizeView();
+
+public:
+ explicit DCToolWindowCellEditor(DCCreator *creator);
+ virtual ~DCToolWindowCellEditor();
+
+ virtual int getPosPriority() const { return 2; }
+ DCCell* getCell() const { return d_cell; }
+
+ void setCell(DCCell *cell);
+
+ void updateView();
+
+private slots:
+ void slotAxonTerminalTreeExpanded(const QModelIndex &index);
+ void slotAxonTerminalTreeCollapsed(const QModelIndex &index);
+ void slotAxonTerminalItemClicked(const QModelIndex &index);
+ void slotReceptorTreeExpanded(const QModelIndex &index);
+ void slotReceptorTreeCollapsed(const QModelIndex &index);
+ void slotReceptorItemClicked(const QModelIndex &index);
+ void adjustTreeColumnWidth();
+
+ void slotCellCodeEditButtonPressed();
+ void slotCustomScriptEditButtonPressed();
+
+};
+
+#endif // DCTOOLWINDOWCELLEDITOR_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dctoolwindowterminalfromaxoneditor.h"
+
+#include "dceditablelabel.h"
+#include "dceditabletreeview.h"
+#include "utils/dcqtitemmodel.h"
+
+#include "dccell.h"
+
+#include <QGroupBox>
+#include <QGridLayout>
+
+
+
+DCToolWindowTerminalFromAxon::DCToolWindowTerminalFromAxon(DCCreator *creator) :
+ DCToolWindowBase(tr("Add axon terminal"), creator), d_axonCell(NULL), d_receptorCell(NULL), d_receptorPagePath("")
+{
+ QGroupBox *axonBox = new QGroupBox("Axon side");
+ QGridLayout *axonLayout = new QGridLayout;
+ axonLayout->setSpacing(6);
+ d_textAxonCellName = new DCEditableLabel(this, "");
+ d_textAxonCellPath = new DCEditableLabel(this, "");
+ axonLayout->addWidget(new QLabel(tr("cell")),0,0);
+ axonLayout->addWidget(new QLabel(tr("location")),1,0);
+ axonLayout->addWidget(d_textAxonCellName, 0,1);
+ axonLayout->addWidget(d_textAxonCellPath, 1,1);
+ axonBox->setLayout(axonLayout);
+
+ QGroupBox *receptorBox = new QGroupBox("Receptor side");
+ QGridLayout *receptorLayout = new QGridLayout;
+ receptorLayout->setSpacing(6);
+ d_textReceptorCellName = new DCEditableLabel(this, "");
+ d_textReceptorCellPath = new DCEditableLabel(this, "");
+ receptorLayout->addWidget(new QLabel(tr("cell")),0,0);
+ receptorLayout->addWidget(new QLabel(tr("location")),1,0);
+ receptorLayout->addWidget(d_textReceptorCellName, 0,1);
+ receptorLayout->addWidget(d_textReceptorCellPath, 1,1);
+
+ d_receptorCellReceptors = new DCEditableTreeView(this);
+ d_receptorCellReceptors->setHeaderHidden(true);
+ d_receptorCellReceptors->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ d_receptorCellReceptorItemModel = new DCQtItemModel(QStringList("name"));
+
+ d_receptorCellReceptors->setModel(d_receptorCellReceptorItemModel);
+
+ receptorLayout->addWidget(d_receptorCellReceptors, 2,0,1,2);
+
+ receptorBox->setLayout(receptorLayout);
+
+ contentLayout()->addWidget(axonBox);
+ contentLayout()->addWidget(receptorBox);
+}
+
+DCToolWindowTerminalFromAxon::~DCToolWindowTerminalFromAxon()
+{
+ if (d_receptorCellReceptorItemModel)
+ d_receptorCellReceptorItemModel->deleteLater();
+}
+
+void DCToolWindowTerminalFromAxon::updateData(DCCell *axonCell, const QString &receptorPagePath, DCCell *receptorCell)
+{
+ d_axonCell = axonCell;
+ d_receptorCell = receptorCell;
+
+ d_receptorCellReceptorItemModel->removeAllItems();
+
+ if (d_axonCell)
+ {
+ d_textAxonCellName->setText(QString::fromStdString(d_axonCell->getName()));
+ d_textAxonCellPath->setText(QString::fromStdString(d_axonCell->getLocation()));
+ }
+
+ d_textReceptorCellPath->setText(receptorPagePath);
+
+ if (d_receptorCell)
+ {
+ d_textReceptorCellName->setText(QString::fromStdString(d_receptorCell->getName()));
+ d_receptorCellReceptorItemModel->insertString("receptors");
+ d_receptorCellReceptorItemModel->setReadOnly(0,true);
+
+ const TKReceptorMap *receptors = d_receptorCell->getReceptors();
+ TKReceptorMap::const_iterator it = receptors->begin();
+ QModelIndex rroot = d_receptorCellReceptorItemModel->index(0,0);
+ while( it != receptors->end())
+ {
+
+ QString receptorName = QString::fromStdString((*it).first);
+ d_receptorCellReceptorItemModel->insertString(receptorName,rroot);
+ ++it;
+ }
+ d_receptorCellReceptors->expandAll();
+ }
+ else
+ {
+ d_textReceptorCellName->setText("");
+ }
+}
+
+
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCTOOLWINDOWTERMINALFROMAXONEDITOR_H
+#define DCTOOLWINDOWTERMINALFROMAXONEDITOR_H
+
+#include "dctoolwindowbase.h"
+
+#include <QtGui>
+
+class DCCreator;
+class DCCell;
+class DCEditableLabel;
+class DCEditableTreeView;
+class DCQtItemModel;
+
+class DCToolWindowTerminalFromAxon : public DCToolWindowBase
+{
+ Q_OBJECT
+private:
+ DCCell *d_axonCell;
+ DCCell *d_receptorCell;
+ QString d_receptorPagePath;
+ DCEditableLabel *d_textAxonCellName;
+ DCEditableLabel *d_textAxonCellPath;
+ DCEditableLabel *d_textReceptorCellName;
+ DCEditableLabel *d_textReceptorCellPath;
+
+ DCEditableTreeView *d_receptorCellReceptors;
+ DCQtItemModel *d_receptorCellReceptorItemModel;
+ QGridLayout *d_layout;
+
+
+public:
+ explicit DCToolWindowTerminalFromAxon(DCCreator *creator);
+ virtual ~DCToolWindowTerminalFromAxon();
+
+ virtual int getPosPriority() const { return 2; }
+ DCCell* getAxonCell() const { return d_axonCell; }
+ DCCell* getReceptorCell() const { return d_receptorCell; }
+
+ void updateData(DCCell *axonCell, const QString &receptorPagePath, DCCell *receptorCell);
+
+signals:
+
+public slots:
+
+};
+
+#endif // DCTOOLWINDOWTERMINALFROMAXONEDITOR_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dctoolwindowterminalfromreceptoreditor.h"
+
+#include "dceditablelabel.h"
+#include "dccell.h"
+
+#include <QGroupBox>
+#include <QGridLayout>
+
+
+DCToolWindowTerminalFromReceptor::DCToolWindowTerminalFromReceptor(DCCreator *creator) :
+ DCToolWindowBase(tr("Add axon terminal"), creator), d_receptorCell(NULL), d_receptor(NULL), d_axonCell(NULL), d_axonPagePathString("")
+{
+ QGroupBox *receptorBox = new QGroupBox("Receptor side");
+ QGridLayout *receptorLayout = new QGridLayout;
+ receptorLayout->setSpacing(6);
+ d_textReceptorCellName = new DCEditableLabel(this, "");
+ d_textReceptorCellPath = new DCEditableLabel(this, "");
+ d_textReceptorName = new DCEditableLabel(this, "");
+
+ receptorLayout->addWidget(new QLabel(tr("cell")),0,0);
+ receptorLayout->addWidget(new QLabel(tr("location")),1,0);
+ receptorLayout->addWidget(new QLabel(tr("receptor")),2,0);
+ receptorLayout->addWidget(d_textReceptorCellName, 0,1);
+ receptorLayout->addWidget(d_textReceptorCellPath, 1,1);
+ receptorLayout->addWidget(d_textReceptorName, 2,1);
+ receptorBox->setLayout(receptorLayout);
+
+ QGroupBox *axonBox = new QGroupBox("Axon side");
+ QGridLayout *axonLayout = new QGridLayout;
+ axonLayout->setSpacing(6);
+ d_textAxonCellName = new DCEditableLabel(this, "");
+ d_textAxonCellPath = new DCEditableLabel(this, "");
+ axonLayout->addWidget(new QLabel(tr("cell")),0,0);
+ axonLayout->addWidget(new QLabel(tr("location")),1,0);
+ axonLayout->addWidget(d_textAxonCellName, 0,1);
+ axonLayout->addWidget(d_textAxonCellPath, 1,1);
+ axonBox->setLayout(axonLayout);
+
+ contentLayout()->addWidget(receptorBox);
+ contentLayout()->addWidget(axonBox);
+}
+
+DCToolWindowTerminalFromReceptor::~DCToolWindowTerminalFromReceptor()
+{
+
+}
+
+
+
+void DCToolWindowTerminalFromReceptor::updateData(DCCell *receptorCell, DCReceptor *receptor, const QString &axonPagePath, DCCell *axonCell)
+{
+ if (d_receptorCell != receptorCell || d_receptor != receptor)
+ {
+ d_receptorCell = receptorCell;
+ d_receptor = receptor;
+ d_receptorName = QString::fromStdString(receptorCell->getReceptorName(receptor));
+ }
+
+ d_axonCell = axonCell;
+ d_axonPagePathString = axonPagePath;
+
+ if (receptorCell)
+ {
+ d_textReceptorCellName->setText(QString::fromStdString(receptorCell->getName()));
+ d_textReceptorCellPath->setText(QString::fromStdString(receptorCell->getLocation()));
+ d_textReceptorName->setText(d_receptorName);
+ }
+ else
+ {
+ d_textReceptorCellName->setText("");
+ d_textReceptorCellPath->setText("");
+ }
+
+ d_textAxonCellPath->setText(axonPagePath);
+
+ if (axonCell)
+ {
+ d_textAxonCellName->setText(QString::fromStdString(axonCell->getName()));
+ }
+ else
+ {
+ d_textAxonCellName->setText("");
+ }
+}
+
+void DCToolWindowTerminalFromReceptor::resetData()
+{
+ d_receptorCell = NULL;
+ d_receptor = NULL;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCTOOLWINDOWTERMINALFROMRECEPTOREDITOR_H
+#define DCTOOLWINDOWTERMINALFROMRECEPTOREDITOR_H
+
+#include "dctoolwindowbase.h"
+
+#include <QtGui>
+
+class DCCreator;
+class DCCell;
+class DCReceptor;
+class DCEditableLabel;
+
+class DCToolWindowTerminalFromReceptor : public DCToolWindowBase
+{
+ DCEditableLabel *d_textReceptorCellName;
+ DCEditableLabel *d_textReceptorCellPath;
+ DCEditableLabel *d_textReceptorName;
+ DCEditableLabel *d_textAxonCellName;
+ DCEditableLabel *d_textAxonCellPath;
+
+ DCCell *d_receptorCell;
+ DCReceptor *d_receptor;
+ QString d_receptorName;
+ DCCell *d_axonCell;
+ QString d_axonPagePathString;
+
+ Q_OBJECT
+public:
+ explicit DCToolWindowTerminalFromReceptor(DCCreator *creator);
+ virtual ~DCToolWindowTerminalFromReceptor();
+
+ virtual int getPosPriority() const { return 2; }
+ DCCell* getAxonCell() const { return d_axonCell; }
+ DCCell* getReceptorCell() const { return d_receptorCell; }
+
+ void updateData(DCCell *receptorCell, DCReceptor *receptor, const QString &axonPagePath, DCCell *axonCell);
+ void resetData();
+signals:
+
+public slots:
+
+};
+
+#endif // DCTOOLWINDOWTERMINALFROMRECEPTOREDITOR_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#include "dctoolwindowviewcontrol.h"
+
+DCToolWindowViewControl::DCToolWindowViewControl(DCCreator *creator) :
+ DCToolWindowBase(tr("Navigation mode"), creator), d_dcScene(NULL)
+{
+
+ //navigation mode
+ QGridLayout *gridLayout1 = new QGridLayout;
+ gridLayout1->setContentsMargins(0,0,0,0);
+ gridLayout1->addWidget(new QLabel(tr("Selected cell")),0,0);
+ gridLayout1->addWidget(new QLabel(tr("Other cell")),1,0);
+ gridLayout1->addWidget(new QLabel(tr("Selected page")),4,0);
+ gridLayout1->addWidget(new QLabel(tr("Above")),5,0);
+ gridLayout1->addWidget(new QLabel(tr("Below")),6,0);
+
+ d_NSelectedCellMovableChkBtn = new QCheckBox("movable");
+ gridLayout1->addWidget(d_NSelectedCellMovableChkBtn, 0,1);
+ connect(d_NSelectedCellMovableChkBtn, SIGNAL(stateChanged(int)), this, SLOT(uiNSelectedCellMovableStateChanged(int)));
+
+ d_NOtherCellSelectableChkBtn = new QCheckBox("selectable");
+ gridLayout1->addWidget(d_NOtherCellSelectableChkBtn, 1,1);
+ connect(d_NOtherCellSelectableChkBtn, SIGNAL(stateChanged(int)), this, SLOT(uiNOtherCellSelectableStateChanged(int)));
+
+ d_NOtherCellVisibleChkBtn = new QCheckBox("visible");
+ gridLayout1->addWidget(d_NOtherCellVisibleChkBtn, 2,1);
+ connect(d_NOtherCellVisibleChkBtn, SIGNAL(stateChanged(int)), this, SLOT(uiNOtherCellVisibleStateChanged(int)));
+
+ d_NOtherCellRenderFullRadioBtn = new QRadioButton("render full");
+ d_NOtherCellRenderFullRadioBtn->setAutoExclusive(false);
+ gridLayout1->addWidget(d_NOtherCellRenderFullRadioBtn, 3,1);
+ connect(d_NOtherCellRenderFullRadioBtn, SIGNAL(clicked()), this, SLOT(uiNOtherCellRenderFullSelected()));
+
+ d_NOtherCellRenderWireRadioBtn = new QRadioButton("render wire");
+ d_NOtherCellRenderWireRadioBtn->setAutoExclusive(false);
+ gridLayout1->addWidget(d_NOtherCellRenderWireRadioBtn, 3,2);
+ connect(d_NOtherCellRenderWireRadioBtn, SIGNAL(clicked()), this, SLOT(uiNOtherCellRenderWireSelected()));
+
+ d_NSelectedPageSlider = new QSlider(Qt::Horizontal);
+ gridLayout1->addWidget(d_NSelectedPageSlider, 4,1,1,2);
+ d_NSelectedPageSlider->setMaximum(100);
+ d_NSelectedPageSlider->setMinimum(0);
+ connect(d_NSelectedPageSlider, SIGNAL(valueChanged(int)), this, SLOT(uiNSelectedPageAlphaChanged(int)));
+
+ d_NAbovePageSlider = new QSlider(Qt::Horizontal);
+ gridLayout1->addWidget(d_NAbovePageSlider, 5,1,1,2);
+ d_NAbovePageSlider->setMaximum(100);
+ d_NAbovePageSlider->setMinimum(0);
+ connect(d_NAbovePageSlider, SIGNAL(valueChanged(int)), this, SLOT(uiNAbovePageAlphaChanged(int)));
+
+ d_NBelowPageSlider = new QSlider(Qt::Horizontal);
+ gridLayout1->addWidget(d_NBelowPageSlider, 6,1,1,2);
+ d_NBelowPageSlider->setMaximum(100);
+ d_NBelowPageSlider->setMinimum(0);
+ connect(d_NBelowPageSlider, SIGNAL(valueChanged(int)), this, SLOT(uiNBelowPageAlphaChanged(int)));
+
+ // page edit mode
+ QGridLayout *gridLayout2 = new QGridLayout;
+ gridLayout2->setContentsMargins(0,0,0,0);
+ gridLayout2->addWidget(new QLabel(tr("Other -same page")),0,0);
+ gridLayout2->addWidget(new QLabel(tr("Linked -other page")),1,0);
+ gridLayout2->addWidget(new QLabel(tr("Other -other page")),3,0);
+ gridLayout2->addWidget(new QLabel(tr("Selecated page")),5,0);
+ gridLayout2->addWidget(new QLabel(""),6,0);
+
+ d_POtherSamePageRenderFullRadioBtn = new QRadioButton("render full");
+ d_POtherSamePageRenderFullRadioBtn->setAutoExclusive(false);
+ gridLayout2->addWidget(d_POtherSamePageRenderFullRadioBtn, 0,1);
+ connect(d_POtherSamePageRenderFullRadioBtn, SIGNAL(clicked()), this, SLOT(uiPOtherSamePageFullSelected()));
+
+ d_POtherSamePageRenderWireRadioBtn = new QRadioButton("render wire");
+ d_POtherSamePageRenderWireRadioBtn->setAutoExclusive(false);
+ gridLayout2->addWidget(d_POtherSamePageRenderWireRadioBtn, 0,2);
+ connect(d_POtherSamePageRenderWireRadioBtn, SIGNAL(clicked()), this, SLOT(uiPOtherSamePageWireSelected()));
+
+ d_PLinkedOtherPageVisibleChkBtn = new QCheckBox("visible");
+ gridLayout2->addWidget(d_PLinkedOtherPageVisibleChkBtn, 1,1);
+ connect(d_PLinkedOtherPageVisibleChkBtn, SIGNAL(stateChanged(int)), this, SLOT(uiPLinkedOtherPageVisibleStateChanged(int)));
+
+ d_PLinkedOtherPageRenderFullRadioBtn = new QRadioButton("render full");
+ d_PLinkedOtherPageRenderFullRadioBtn->setAutoExclusive(false);
+ gridLayout2->addWidget(d_PLinkedOtherPageRenderFullRadioBtn, 2,1);
+ connect(d_PLinkedOtherPageRenderFullRadioBtn, SIGNAL(clicked()), this, SLOT(uiPLinkedOtherPageFullSelected()));
+
+ d_PLinkedOtherPageRenderWireRadioBtn = new QRadioButton("render wire");
+ d_PLinkedOtherPageRenderWireRadioBtn->setAutoExclusive(false);
+ gridLayout2->addWidget(d_PLinkedOtherPageRenderWireRadioBtn, 2,2);
+ connect(d_PLinkedOtherPageRenderWireRadioBtn, SIGNAL(clicked()), this, SLOT(uiPLinkedOtherPageWireSelected()));
+
+ d_POtherOtherPageVisibleChkBtn = new QCheckBox("visible");
+ gridLayout2->addWidget(d_POtherOtherPageVisibleChkBtn, 3,1);
+ connect(d_POtherOtherPageVisibleChkBtn, SIGNAL(stateChanged(int)), this, SLOT(uiPOtherOtherPageVisibleStateChanged(int)));
+
+ d_POtherOtherPageRenderFullRadioBtn = new QRadioButton("render full");
+ d_POtherOtherPageRenderFullRadioBtn->setAutoExclusive(false);
+ gridLayout2->addWidget(d_POtherOtherPageRenderFullRadioBtn, 4,1);
+ connect(d_POtherOtherPageRenderFullRadioBtn, SIGNAL(clicked()), this, SLOT(uiPOtherOtherPageFullSelected()));
+
+ d_POtherOtherPageRenderWireRadioBtn = new QRadioButton("render wire");
+ d_POtherOtherPageRenderWireRadioBtn->setAutoExclusive(false);
+ gridLayout2->addWidget(d_POtherOtherPageRenderWireRadioBtn, 4,2);
+ connect(d_POtherOtherPageRenderWireRadioBtn, SIGNAL(clicked()), this, SLOT(uiPOtherOtherPageWireSelected()));
+
+ d_PSelectedPageSlider = new QSlider(Qt::Horizontal);
+ gridLayout2->addWidget(d_PSelectedPageSlider, 5,1,1,2);
+ d_PSelectedPageSlider->setMaximum(100);
+ d_PSelectedPageSlider->setMinimum(0);
+ connect(d_PSelectedPageSlider, SIGNAL(valueChanged(int)), this, SLOT(uiPSelectedPageAlphaChanged(int)));
+
+ //
+ QWidget *w1 = new QWidget;
+ QWidget *w2 = new QWidget;
+ w1->setLayout(gridLayout1);
+ w2->setLayout(gridLayout2);
+ d_stackedLayout = new QStackedLayout;
+ d_stackedLayout->setContentsMargins(0,0,0,0);
+ contentLayout()->addLayout(d_stackedLayout);
+ d_stackedLayout->addWidget(w1);
+ d_stackedLayout->addWidget(w2);
+ d_stackedLayout->setCurrentIndex(0);
+
+}
+
+
+void DCToolWindowViewControl::setDCScene(DCScene *dcScene)
+{
+ d_dcScene = dcScene;
+ if (dcScene)
+ {
+ d_NSelectedCellMovableChkBtn->setChecked(dcScene->getNavModeSelectedCellMovable());
+ d_NOtherCellSelectableChkBtn->setChecked(dcScene->getNavModeOtherCellSelectable());
+ d_NOtherCellVisibleChkBtn->setChecked(dcScene->getNavModeOtherCellVisible());
+ d_NOtherCellRenderFullRadioBtn->setChecked(dcScene->getNavModeOtherCellRenderFull());
+ d_NOtherCellRenderWireRadioBtn->setChecked(!dcScene->getNavModeOtherCellRenderFull());
+ d_NSelectedPageSlider->setValue(dcScene->getNavModeSelectedPageAlpha() * 100);
+ d_NAbovePageSlider->setValue(dcScene->getNavModeAboveAlpha() * 100);
+ d_NBelowPageSlider->setValue(dcScene->getNavModeBelowAlpha() * 100);
+
+ d_POtherSamePageRenderFullRadioBtn->setChecked(dcScene->getPageModeOtherSamePageRenderFull());
+ d_POtherSamePageRenderWireRadioBtn->setChecked(!dcScene->getPageModeOtherSamePageRenderFull());
+ d_PLinkedOtherPageVisibleChkBtn->setChecked(dcScene->getPageModeLinkedOtherPageVisible());
+ d_PLinkedOtherPageRenderFullRadioBtn->setChecked(dcScene->getPageModeLinkedOtherPageRenderFull());
+ d_PLinkedOtherPageRenderFullRadioBtn->setEnabled(dcScene->getPageModeLinkedOtherPageVisible());
+ d_PLinkedOtherPageRenderWireRadioBtn->setChecked(!dcScene->getPageModeLinkedOtherPageRenderFull());
+ d_PLinkedOtherPageRenderWireRadioBtn->setEnabled(dcScene->getPageModeLinkedOtherPageVisible());
+ d_POtherOtherPageVisibleChkBtn->setChecked(dcScene->getPageModeOtherOtherPageVisible());
+ d_POtherOtherPageRenderFullRadioBtn->setChecked(dcScene->getPageModeOtherOtherPageRenderFull());
+ d_POtherOtherPageRenderFullRadioBtn->setEnabled(dcScene->getPageModeOtherOtherPageVisible());
+ d_POtherOtherPageRenderWireRadioBtn->setChecked(!dcScene->getPageModeOtherOtherPageRenderFull());
+ d_POtherOtherPageRenderWireRadioBtn->setEnabled(dcScene->getPageModeOtherOtherPageVisible());
+ d_PSelectedPageSlider->setValue(dcScene->getPageModeSelectedAlpha() * 100);
+
+ changeMode(this);
+ }
+}
+
+
+void DCToolWindowViewControl::changeMode(const void* requester)
+{
+ switch (d_dcScene->getPersMode())
+ {
+ case DCScene::DCV_PERSMODE_NAVIGATION:
+ d_stackedLayout->setCurrentIndex(0);
+ setButtonedWindowTitle("Navigation perspective");
+ break;
+
+ case DCScene::DCV_PERSMODE_PAGEEDIT:
+ d_stackedLayout->setCurrentIndex(1);
+ setButtonedWindowTitle("Page perspective");
+ break;
+ }
+}
+
+void DCToolWindowViewControl::uiNSelectedCellMovableStateChanged(int state)
+{
+ if (d_dcScene)
+ d_dcScene->setNavModeSelectedCellMovable(this, state == Qt::Checked);
+}
+
+void DCToolWindowViewControl::uiNOtherCellSelectableStateChanged(int state)
+{
+ if (d_dcScene)
+ d_dcScene->setNavModeOtherCellSelectable(this, state == Qt::Checked);
+}
+
+void DCToolWindowViewControl::uiNOtherCellVisibleStateChanged(int state)
+{
+ d_NOtherCellRenderFullRadioBtn->setEnabled(state == Qt::Checked);
+ d_NOtherCellRenderWireRadioBtn->setEnabled(state == Qt::Checked);
+ if (d_dcScene)
+ d_dcScene->setNavModeOtherCellVisible(this, state == Qt::Checked);
+}
+
+void DCToolWindowViewControl::uiNOtherCellRenderFullSelected()
+{
+ d_NOtherCellRenderFullRadioBtn->setChecked(true);
+ d_NOtherCellRenderWireRadioBtn->setChecked(false);
+ if (d_dcScene)
+ d_dcScene->setNavModeOtherCellRenderFull(this, true);
+}
+
+void DCToolWindowViewControl::uiNOtherCellRenderWireSelected()
+{
+ d_NOtherCellRenderFullRadioBtn->setChecked(false);
+ d_NOtherCellRenderWireRadioBtn->setChecked(true);
+ if (d_dcScene)
+ d_dcScene->setNavModeOtherCellRenderFull(this, false);
+}
+
+void DCToolWindowViewControl::uiNSelectedPageAlphaChanged(int alpha)
+{
+ if (d_dcScene)
+ d_dcScene->setNavModeSelectedPageAlpha(this, alpha / 100.0);
+}
+
+void DCToolWindowViewControl::uiNAbovePageAlphaChanged(int alpha)
+{
+ if (d_dcScene)
+ d_dcScene->setNavModeAboveAlpha(this, alpha / 100.0);
+}
+
+void DCToolWindowViewControl::uiNBelowPageAlphaChanged(int alpha)
+{
+ if (d_dcScene)
+ d_dcScene->setNavModeBelowAlpha(this, alpha / 100.0);
+}
+
+
+//page edit mode
+void DCToolWindowViewControl::uiPOtherSamePageFullSelected()
+{
+ d_POtherSamePageRenderFullRadioBtn->setChecked(true);
+ d_POtherSamePageRenderWireRadioBtn->setChecked(false);
+ if (d_dcScene)
+ d_dcScene->setPageModeOtherSamePageRenderFull(this, true);
+}
+
+void DCToolWindowViewControl::uiPOtherSamePageWireSelected()
+{
+ d_POtherSamePageRenderFullRadioBtn->setChecked(false);
+ d_POtherSamePageRenderWireRadioBtn->setChecked(true);
+ if (d_dcScene)
+ d_dcScene->setPageModeOtherSamePageRenderFull(this, false);
+}
+
+void DCToolWindowViewControl::uiPLinkedOtherPageVisibleStateChanged(int state)
+{
+ d_PLinkedOtherPageRenderFullRadioBtn->setEnabled( state == Qt::Checked);
+ d_PLinkedOtherPageRenderWireRadioBtn->setEnabled( state == Qt::Checked);
+ if (d_dcScene)
+ d_dcScene->setPageModeLinkedOtherPageVisible(this, state == Qt::Checked);
+}
+
+void DCToolWindowViewControl::uiPLinkedOtherPageFullSelected()
+{
+ d_PLinkedOtherPageRenderFullRadioBtn->setChecked(true);
+ d_PLinkedOtherPageRenderWireRadioBtn->setChecked(false);
+ if (d_dcScene)
+ d_dcScene->setPageModeLinkedOtherPageRenderFull(this, true);
+}
+
+void DCToolWindowViewControl::uiPLinkedOtherPageWireSelected()
+{
+ d_PLinkedOtherPageRenderFullRadioBtn->setChecked(false);
+ d_PLinkedOtherPageRenderWireRadioBtn->setChecked(true);
+ if (d_dcScene)
+ d_dcScene->setPageModeLinkedOtherPageRenderFull(this, false);
+}
+
+void DCToolWindowViewControl::uiPOtherOtherPageVisibleStateChanged(int state)
+{
+ d_POtherOtherPageRenderFullRadioBtn->setEnabled( state == Qt::Checked);
+ d_POtherOtherPageRenderWireRadioBtn->setEnabled( state == Qt::Checked);
+ if (d_dcScene)
+ d_dcScene->setPageModeOtherOtherPageVisible(this, state == Qt::Checked);
+}
+
+void DCToolWindowViewControl::uiPOtherOtherPageFullSelected()
+{
+ d_POtherOtherPageRenderFullRadioBtn->setChecked(true);
+ d_POtherOtherPageRenderWireRadioBtn->setChecked(false);
+ if (d_dcScene)
+ d_dcScene->setPageModeOtherOtherPageRenderFull(this, true);
+}
+
+void DCToolWindowViewControl::uiPOtherOtherPageWireSelected()
+{
+ d_POtherOtherPageRenderFullRadioBtn->setChecked(false);
+ d_POtherOtherPageRenderWireRadioBtn->setChecked(true);
+ if (d_dcScene)
+ d_dcScene->setPageModeOtherOtherPageRenderFull(this, false);
+}
+
+void DCToolWindowViewControl::uiPSelectedPageAlphaChanged(int alpha)
+{
+ if (d_dcScene)
+ d_dcScene->setPageModeSelectedAlpha(this, alpha / 100.0);
+}
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// 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 3 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/>.
+
+//
+// Created by tkawata on Sep-30, 2012.
+//
+#ifndef DCTOOLWINDOWVIEWCONTROL_H
+#define DCTOOLWINDOWVIEWCONTROL_H
+
+#include "dctoolwindowbase.h"
+
+#include "dcscene.h"
+
+class DCToolWindowViewControl : public DCToolWindowBase
+{
+ Q_OBJECT
+private:
+ DCScene *d_dcScene;
+
+ QStackedLayout *d_stackedLayout;
+ QCheckBox *d_NSelectedCellMovableChkBtn;
+ QCheckBox *d_NOtherCellSelectableChkBtn;
+ QCheckBox *d_NOtherCellVisibleChkBtn;
+ QRadioButton *d_NOtherCellRenderFullRadioBtn;
+ QRadioButton *d_NOtherCellRenderWireRadioBtn;
+ QSlider *d_NSelectedPageSlider;
+ QSlider *d_NAbovePageSlider;
+ QSlider *d_NBelowPageSlider;
+
+ QRadioButton *d_POtherSamePageRenderFullRadioBtn;
+ QRadioButton *d_POtherSamePageRenderWireRadioBtn;
+ QCheckBox *d_PLinkedOtherPageVisibleChkBtn;
+ QRadioButton *d_PLinkedOtherPageRenderFullRadioBtn;
+ QRadioButton *d_PLinkedOtherPageRenderWireRadioBtn;
+ QCheckBox *d_POtherOtherPageVisibleChkBtn;
+ QRadioButton *d_POtherOtherPageRenderFullRadioBtn;
+ QRadioButton *d_POtherOtherPageRenderWireRadioBtn;
+ QSlider *d_PSelectedPageSlider;
+
+public:
+ DCToolWindowViewControl(DCCreator *creator);
+
+ virtual int getPosPriority() const { return 1; }
+
+ void setDCScene(DCScene *dcScene);
+
+signals:
+
+
+public slots:
+ void changeMode(const void* requester);
+
+ //navigation mode
+ void uiNSelectedCellMovableStateChanged(int state);
+ void uiNOtherCellSelectableStateChanged(int state);
+ void uiNOtherCellVisibleStateChanged(int state);
+ void uiNOtherCellRenderFullSelected();
+ void uiNOtherCellRenderWireSelected();
+ void uiNSelectedPageAlphaChanged(int alpha);
+ void uiNAbovePageAlphaChanged(int alpha);
+ void uiNBelowPageAlphaChanged(int alpha);
+
+ //page edit mode
+ void uiPOtherSamePageFullSelected();
+ void uiPOtherSamePageWireSelected();
+ void uiPLinkedOtherPageVisibleStateChanged(int state);
+ void uiPLinkedOtherPageFullSelected();
+ void uiPLinkedOtherPageWireSelected();
+ void uiPOtherOtherPageVisibleStateChanged(int state);
+ void uiPOtherOtherPageFullSelected();
+ void uiPOtherOtherPageWireSelected();
+ void uiPSelectedPageAlphaChanged(int alpha);
+};
+
+#endif // DCTOOLWINDOWVIEWCONTROL_H