--- /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 Oct-2, 2012.
+//
+#include "dccontainersaver.h"
+
+#include "dccontainer.h"
+#include "dcscene.h"
+#include "dcvcpage.h"
+#include "dccell.h"
+#include "dccellcode.h"
+#include "dcreceptor.h"
+#include "dcaxon.h"
+#include "dcaxonterminal.h"
+#include "dcvpagecomponent.h"
+
+#include <QDomDocument>
+#include <QMap>
+
+DCContainerSaver::DCContainerSaver(DCContainer *container) : d_container(container)
+{
+
+}
+
+DCContainerSaver::~DCContainerSaver()
+{
+
+}
+
+bool DCContainerSaver::saveAll(const QString& containerRootPath)
+{
+ const QMap<QString,DCVCPage*> *pages = d_container->getScene()->getPages();
+ QMapIterator<QString, DCVCPage*> i(*pages);
+ while (i.hasNext())
+ {
+ i.next();
+ DCVCPage *page = i.value();
+ saveForPage(containerRootPath, page);
+ }
+ return true;
+}
+
+bool DCContainerSaver::saveForPage(const QString& containerRootPath, DCVCPage *page)
+{
+ QString pageFilePath = containerRootPath;
+ pageFilePath.append(page->getLocationPath());
+
+ QDomDocument doc("html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"");
+ doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
+
+ QDomElement root = doc.createElementNS("http://www.w3.org/1999/xhtml","html");
+ root.setAttribute("lang", "en");
+ QDomElement body = doc.createElement("body");
+ root.appendChild(body);
+
+ const QList<DCVPageComponent*>* vcells = page->getCells();
+ for (int j = 0; j < vcells->length(); j++)
+ {
+ DCCell *cell = vcells->at(j)->getOwnerCell();
+ QString cellName = QString::fromStdString(cell->getName());
+
+ QDomElement aCellTag = doc.createElement("a");
+ aCellTag.setAttribute("define", "cell");
+ aCellTag.setAttribute("name", cellName);
+
+ QDomElement aCellCodeTag = doc.createElement("a");
+ aCellCodeTag.setAttribute("parameter", "cellcode");
+ if (cell->getCellCode() && cell->getCellCode() != d_container->getEmptyCellCodeClass())
+ {
+ aCellCodeTag.setAttribute("href", QString::fromStdString(cell->getCellCode()->getName()));
+ }
+ else
+ {
+ aCellCodeTag.setAttribute("type", cell->getType());
+ }
+ aCellTag.appendChild(aCellCodeTag);
+ DCAxon *axon = cell->getAxon();
+ for (int k = 0; k < axon->getNumberOfTerminals(); k++)
+ {
+ DCAxonTerminal *terminal = axon->getTerminalAt(k);
+ DCReceptor *receptor = dynamic_cast<DCReceptor*>(terminal->getTarget());
+ if (receptor)
+ {
+ DCCell *targetCell = dynamic_cast<DCCell*>(receptor->getOwnerCell());
+ if (targetCell)
+ {
+ QString connectionPath = QString::fromStdString(targetCell->getLocation());
+ connectionPath.append("#");
+ connectionPath.append(QString::fromStdString(targetCell->getName()));
+ QString receptorName = QString::fromStdString(targetCell->getReceptorName(receptor));
+
+ QDomElement aConnectionTag = doc.createElement("a");
+ aConnectionTag.setAttribute("parameter", "connection");
+ aConnectionTag.setAttribute("href", connectionPath);
+ aConnectionTag.setAttribute("receptor", receptorName);
+ aCellTag.appendChild(aConnectionTag);
+ }
+ }
+ }
+ body.appendChild(aCellTag);
+ }
+
+ doc.appendChild(root);
+
+ QFile file(pageFilePath);
+ bool r = false;
+ if (file.open(QFile::WriteOnly | QFile::Truncate))
+ {
+ QTextStream out(&file);
+ doc.save(out, 4);
+ r = true;
+ }
+ 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 Oct-2, 2012.
+//
+#ifndef DCCONTAINERSAVER_H
+#define DCCONTAINERSAVER_H
+
+#include <QString>
+
+class DCContainer;
+class DCVCPage;
+
+class DCContainerSaver
+{
+ DCContainer *d_container;
+public:
+ DCContainerSaver(DCContainer *container);
+ virtual ~DCContainerSaver();
+
+ bool saveAll(const QString& containerRootPath);
+ bool saveForPage(const QString& containerRootPath, DCVCPage *page);
+};
+
+#endif // DCCONTAINERSAVER_H
#include "DNXML.h"
#include "DNXMLElement.h"
#include "DNUtils.h"
+#include "dccontainersaver.h"
#include <stdlib.h>
#include <sstream>
#include <iostream>
DCContent::DCContent(DCCreator *creator, std::string contentPath) :
- mCreator(creator), mValid(false), mContainer(0)
+ d_creator(creator), d_valid(false), d_container(0)
{
- mContainer = (DCContainer*) TKContainer::createContainer();
- mContainer->setContent(this);
+ d_container = (DCContainer*) TKContainer::createContainer();
+ d_container->setContent(this);
dnGlobal()->updateRunningStatus(DNGlobal::STOPPED);
dnGlobal()->resetErrorStatus();
std::string dataStorePath = containerRoot;
dataStorePath.append("/data.db");
- succeeded = mContainer->setDataStore(dataStorePath.c_str());
+ succeeded = d_container->setDataStore(dataStorePath.c_str());
if (!succeeded)
{
dnNotifyError("Initialization failed","Failed to the setup data store");
return;
}
- mValid = true;
+ d_valid = true;
}
DCContent::~DCContent()
{
- mValid = false;
- if (mContainer)
+ d_valid = false;
+ if (d_container)
{
- delete mContainer;
- mContainer = 0;
+ delete d_container;
+ d_container = 0;
}
}
bool DCContent::parseContainerFile(const char *containerRoot)
{
- DNContainerBuilder builder(mContainer);
- mContainer->beganBuildContainer();
+ DNContainerBuilder builder(d_container);
+ d_container->beganBuildContainer();
bool r = builder.buildContainerFromXHTML(containerRoot);
- mContainer->endedBuildContainer();
+ d_container->endedBuildContainer();
return r;
}
+
+bool DCContent::saveAll(const QString& containerRoot)
+{
+ DCContainerSaver saver(d_container);
+ return saver.saveAll(containerRoot);
+}
class DCContainer;
class DCCreator;
-#include <string>
+#include <QString>
class DCContent
{
bool parseSettingFile(const char *contentRoot);
bool parseContainerFile(const char *containerRoot);
- DCCreator *mCreator;
- bool mValid;
- DCContainer *mContainer;
+ DCCreator *d_creator;
+ bool d_valid;
+ DCContainer *d_container;
public:
DCContent(DCCreator *creator, std::string contentPath);
virtual ~DCContent();
- bool isValid() { return mValid; }
+ bool isValid() const { return d_valid; }
- DCContainer* getContainer() const { return mContainer; }
- DCCreator* getCreator() const { return mCreator; }
+ DCContainer* getContainer() const { return d_container; }
+ DCCreator* getCreator() const { return d_creator; }
+
+ bool saveAll(const QString& containerRoot);
};
{
if (d_scene)
{
+ d_vcontent->saveAll(QString::fromStdString(getCurrentContainer()->getContainerRootPath()));
return d_scene->saveSceneAll();
}
return false;
dialog/dcinputnewpagenamedialog.h \
dialog/dcaddcelldialog.h \
utils/dcskeltoncreatorutil.h \
- utils/dcutil.h
+ utils/dcutil.h \
+ dccontainersaver.h
SOURCES = main.cpp \
mainwindow.cpp \
dialog/dcinputnewpagenamedialog.cpp \
dialog/dcaddcelldialog.cpp \
utils/dcskeltoncreatorutil.cpp \
- utils/dcutil.cpp
+ utils/dcutil.cpp \
+ dccontainersaver.cpp
RESOURCES = denncoCreator.qrc
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);
+ const QMap<QString,DCVCPage*> *pages = scene->getPages();
+ QMapIterator<QString, DCVCPage*> i(*pages);
int row = 0;
int selection = -1;
while (i.hasNext())
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);
+ const QMap<QString,DCVCPage*> *pages = scene->getPages();
+ QMapIterator<QString, DCVCPage*> i(*pages);
int row = 0;
int selection = -1;
while (i.hasNext())
if (QFileInfo(oldFilePath).isDir() && IsIndexUnderContainer(this, index))
{
- QString containerPath = QString::fromStdString(d_creator->getCurrentContainer()getContainerRootPathth());
+ QString containerPath = QString::fromStdString(d_creator->getCurrentContainer()->getContainerRootPath());
QString containerBasedPath = "/" + QDir(containerPath).relativeFilePath(baseDirPath);
if (d_creator->doCommandRenameDirectoryImmidiate(this, containerBasedPath, oldFileName, value.toString()))
{
if (showMenu)
{
- QString contentPath;
+ QString containerPath;
QString containerBasedPath;
if (index.isValid())
{
- containerPath = QString::fromStdString(d_creator->getCurrentContainer()getContainerRootPathth());
+ containerPath = QString::fromStdString(d_creator->getCurrentContainer()->getContainerRootPath());
containerBasedPath = "/" + QDir(containerPath).relativeFilePath(fileModel->filePath(index));
}
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),
+ : DCVPageComponent(page), d_owner(owner), 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());
}
-void DCVCCell::unregisterFromPage()
+void DCVCCell::changePageBelonging(DCVCPage *page)
{
- d_page = NULL;
+ //TODO
}
void DCVCCell::prepareChildrenForDraw(bool isAnimationInterval)
class DCVCCell : public DCVPageComponent
{
DCCell *d_owner;
- DCVCPage *d_page;
DCCubeRenderer *d_shape;
bool d_shouldUpdateShape;
DCSelectionRenderer *d_selectionRectRenderer;
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 changePageBelonging(DCVCPage *page);
virtual void prepareChildrenForDraw(bool isAnimationInterval);
virtual void drawChildren(bool isAnimationInterval);
virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
DCVCCellCode::DCVCCellCode(DCCellCode *owner)
{
}
+
+void DCVCCellCode::changePageBelonging(DCVCPage *page)
+{
+ //TODO
+}
#ifndef DCVCCELLCODE_H
#define DCVCCELLCODE_H
-#include "dcvcomponent.h"
+#include "dcvpagecomponent.h"
class DCCellCode;
-class DCVCCellCode : public DCVComponent
+class DCVCCellCode : public DCVPageComponent
{
public:
DCVCCellCode(DCCellCode *owner);
virtual DCCell * getOwnerCell() const { return NULL; }
virtual bool isResizingArea(float x, float y, float z) const { return false; }
+ virtual void changePageBelonging(DCVCPage *page);
virtual void prepareChildrenForDraw(bool isAnimationInterval) {}
virtual void drawChildren(bool isAnimationInterval) {}
virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList) {}
static DCCubeRenderer *s_cursorShape = NULL;
DCVCEditModeCursor::DCVCEditModeCursor()
- : d_ownerCell(NULL), d_ownerAxon(NULL), d_ownerReceptor(NULL), d_page(NULL),
+ : d_ownerCell(NULL), d_ownerAxon(NULL), d_ownerReceptor(NULL),
d_cursorType(DCV_CURSOR_NONE), d_dropTarget(NULL), d_dragOffsetX(0), d_dragOffsetY(0), d_isDragging(false)
{
d_terminal = new DCVCEditModeTerminal;
d_cursorType = DCV_CURSOR_FROM_AXON;
if (d_ownerCell)
{
- setPageBelonging(d_ownerCell->getPageBelonging());
+ changePageBelonging(d_ownerCell->getPageBelonging());
setVisible(DCVComponent::DCV_VISIBLE_FULL, DCVComponent::DCV_VISIBLE_FULL);
owner->registerEditCursor(this);
}
else
{
- setPageBelonging(NULL);
+ changePageBelonging(NULL);
setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE);
}
}
if (d_ownerReceptor && d_ownerCell)
{
d_cursorType = DCV_CURSOR_FROM_RECEPTAOR;
- setPageBelonging(d_ownerCell->getPageBelonging());
+ changePageBelonging(d_ownerCell->getPageBelonging());
setVisible(DCVComponent::DCV_VISIBLE_FULL, DCVComponent::DCV_VISIBLE_FULL);
owner->registerEditCursor(this);
}
else
{
- setPageBelonging(NULL);
+ changePageBelonging(NULL);
setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE);
}
}
d_ownerReceptor = NULL;
}
d_ownerCell = NULL;
- setPageBelonging(NULL);
+ changePageBelonging(NULL);
setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE);
}
-void DCVCEditModeCursor::setPageBelonging(DCVCPage *page)
+void DCVCEditModeCursor::changePageBelonging(DCVCPage *page)
{
- bool changed = false;
- if (d_page != page)
+ if (getPageBelonging() != page)
{
- if (d_page)
+ if (page)
{
- d_page->unregisterEditCursor();
+ page->registerEditCursor(this);
+ }
+ else
+ {
+ getPageBelonging()->unregisterEditCursor();
}
- changed = true;
- }
- d_page = page;
- if (d_page)
- d_page->registerEditCursor(this);
-
- if (changed)
emit pageBelongingChanged(page);
+ }
}
void DCVCEditModeCursor::setDropTarget(DCVComponent *dropTarget)
return false;
}
-void DCVCEditModeCursor::unregisterFromPage()
-{
- d_page = NULL;
-}
-
void DCVCEditModeCursor::prepareChildrenForDraw(bool isAnimationInterval)
{
float matrix[16];
DCCell *d_ownerCell;
DCAxon *d_ownerAxon;
DCReceptor *d_ownerReceptor;
- DCVCPage *d_page;
DCVEditCursorType d_cursorType;
DCVCEditModeTerminal *d_terminal;
DCVComponent *d_dropTarget;
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; }
void setOwnerFromAxon(DCAxon *owner);
void setOwnerFromReceptor(DCReceptor *owner);
- void setPageBelonging(DCVCPage *page);
void setDropTarget(DCVComponent *dropTarget);
void unsetCursor();
- virtual void unregisterFromPage();
+ virtual void changePageBelonging(DCVCPage *page);
virtual void prepareChildrenForDraw(bool isAnimationInterval);
virtual void drawChildren(bool isAnimationInterval);
virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
DCVPageComponent *cell = d_cells.takeFirst();
if (cell)
{
- cell->unregisterFromPage();
+ cell->unregisteredFromPage();
+ }
+ }
+ while (!d_cellCodeClasses.isEmpty())
+ {
+ DCVPageComponent *cellCodeClass = d_cellCodeClasses.takeFirst();
+ if (cellCodeClass)
+ {
+ cellCodeClass->unregisteredFromPage();
}
}
}
{
if (cell)
{
+ if (cell->getPageBelonging())
+ {
+ cell->getPageBelonging()->unregisterCell(cell);
+ }
d_cells.append(cell);
+ cell->regiesteredToPage(this);
}
}
if (cell)
{
d_cells.removeOne(cell);
+ cell->unregisteredFromPage();
+ }
+}
+
+void DCVCPage::registerCellCodeClass(DCVPageComponent *cellCodeClass)
+{
+ if (cellCodeClass)
+ {
+ if (cellCodeClass->getPageBelonging())
+ {
+ cellCodeClass->getPageBelonging()->unregisterCellCodeClass(cellCodeClass);
+ }
+ d_cellCodeClasses.append(cellCodeClass);
+ cellCodeClass->regiesteredToPage(this);
+ }
+}
+
+void DCVCPage::unregisterCellCodeClass(DCVPageComponent *cellCodeClass)
+{
+ if (cellCodeClass)
+ {
+ d_cellCodeClasses.removeOne(cellCodeClass);
+ cellCodeClass->unregisteredFromPage();
}
}
void DCVCPage::registerEditCursor(DCVPageComponent *ecursor)
{
+ if (ecursor)
+ {
+ if (ecursor->getPageBelonging())
+ {
+ ecursor->getPageBelonging()->unregisterEditCursor();
+ }
+ }
d_editCursor = ecursor;
+ d_editCursor->regiesteredToPage(this);
}
void DCVCPage::unregisterEditCursor()
{
+ d_editCursor->unregisteredFromPage();
d_editCursor = NULL;
}
if (path == d_locationPath)
{
QDomNodeList cellNodes = e.childNodes();
- for (int j = 0; j < cellNodes.length(); j++)
+ for (unsigned int j = 0; j < cellNodes.length(); j++)
{
if (!cellNodes.at(j).isElement())
continue;
#include "dcvcomponent.h"
-class DCVCCell;
-class DCVCCellCode;
class DCVPageComponent;
class DCVCPage : public DCVComponent
float d_colorA;
QList<DCVPageComponent*> d_cells;
+ QList<DCVPageComponent*> d_cellCodeClasses;
+
DCVPageComponent *d_editCursor;
public:
virtual bool isResizingArea(float x, float y, float z) const { return false; }
QString getLocationPath() const { return d_locationPath; }
+ const QList<DCVPageComponent*>* getCells() const { return &d_cells; }
+ const QList<DCVPageComponent*>* getCellCodeClasses() const { return &d_cellCodeClasses; }
+
+ // register / unregister cell to this page.
+ // They are called from DCVCCell.
+ // Other classes shouldn't call this directly.
+ // To change the page a cell belonging,
+ // DCVCCell::changePageBelonging() should be called instead.
void registerCell(DCVPageComponent *cell);
void unregisterCell(DCVPageComponent *cell);
+ // register / unregister cellcode to this page.
+ // They are called from DCVCCellCode.
+ // Other classes shouldn't call this directly.
+ // To change the page a cell code class belonging,
+ // DCVCCellCode::changePageBelonging() should be called instead.
+ void registerCellCodeClass(DCVPageComponent *cellCodeClass);
+ void unregisterCellCodeClass(DCVPageComponent *cellCodeClass);
+
+ // register / unregister cellcode to this page.
+ // They are called from DCVCEditModeCursor.
+ // Other classes shouldn't call this directly.
+ // To change the page a cell code class belonging,
+ // DCVCEditModeCursor::changePageBelonging() should be called instead.
void registerEditCursor(DCVPageComponent *ecursor);
void unregisterEditCursor();
#include "dcvcomponent.h"
-class DCVCPage;
+#include "dcvcpage.h"
class DCVPageComponent : public DCVComponent
{
- float d_pageX;
- float d_pageY;
+ friend class DCVCPage;
+
+ DCVCPage *d_page;
+ float d_pageX;
+ float d_pageY;
+
+ void regiesteredToPage(DCVCPage *page) { d_page = page; }
+ void unregisteredFromPage() { d_page = NULL; }
public:
- DCVPageComponent() : d_pageX(0), d_pageY(0) {}
+ DCVPageComponent() : d_page(NULL), d_pageX(0), d_pageY(0) {}
+ explicit DCVPageComponent(DCVCPage *page) : d_page(page), d_pageX(0), d_pageY(0) {}
virtual ~DCVPageComponent() {}
- virtual void unregisterFromPage() = 0;
+ inline DCVCPage* getPageBelonging() const{ return d_page; }
+
+ virtual void changePageBelonging(DCVCPage *page) = 0;
virtual float getPageX() const { return d_pageX; }
virtual float getPageY() const { return d_pageY; }
DCCell* getEditCellCodeCell() const { return d_editCellCodeCell; }
- const QMap<QString,DCVCPage*> getPages() const { return d_pages; }
+ const QMap<QString,DCVCPage*>* getPages() const { return &d_pages; }
bool getIsPageExist(const std::string& location) const;
//
if (page)
{
getController()->selectPage(this, page, shift);
- d_cursor->setPageBelonging(page);
+ d_cursor->changePageBelonging(page);
}
else
{
if (page)
{
getController()->selectPage(this, page, shift);
- d_cursor->setPageBelonging(page);
+ d_cursor->changePageBelonging(page);
}
else
{