OSDN Git Service

[denncoCreator] Initial implementation for saveAll functionality completed.
authortkawata <tkawata@users.sourceforge.jp>
Wed, 3 Oct 2012 05:07:47 +0000 (14:07 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Wed, 3 Oct 2012 05:07:47 +0000 (14:07 +0900)
SaveAll works now. Failure cases are not considered well.
Error handling logics need to be implemented.

15 files changed:
Source/dccontainer.cpp
Source/dccontainersaver.cpp
Source/dccontent.cpp
Source/dccontent.h
Source/dccreator.cpp
Source/engine/layer1/TKContainer.cpp
Source/engine/layer1/TKContainer.h
Source/utils/dccomponentutil.cpp
Source/utils/dccomponentutil.h
Source/visualizer/component/dcvccell.cpp
Source/visualizer/component/dcvccell.h
Source/visualizer/component/dcvccellcode.cpp
Source/visualizer/component/dcvccellcode.h
Source/visualizer/dcscene.cpp
Source/visualizer/dcscene.h

index 007ff9b..05910a3 100644 (file)
@@ -230,7 +230,26 @@ TKAxonTerminal* DCContainer::axonTerminalFactory(TKAxon *theOwner)
 
 TKCellCode* DCContainer::cellCodeFactory(std::string name, std::string cellapi, std::string code)
 {
-    return DCComponentUtil::createCellCode(name, cellapi);
+    DCVCPage *page = NULL;
+    if (name != TKContainer::CELLCODENAME_EMPTY)
+    {
+        std::string location = name;
+        if (location.find("#") != std::string::npos)
+        {
+            location = location.substr(0, location.find("#"));
+        }
+        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;
+        page = d_factoryCachedPageObject;
+    }
+    return DCComponentUtil::createCellCode(page, name, cellapi);
 }
 
 void DCContainer::beganParsePage(const char *docRoot, const char *path)
index 9c726c7..3ad3522 100644 (file)
 #include "dccontainer.h"
 #include "dcscene.h"
 #include "dcvcpage.h"
+#include "dcvccellcode.h"
 #include "dccell.h"
 #include "dccellcode.h"
 #include "dcreceptor.h"
 #include "dcaxon.h"
 #include "dcaxonterminal.h"
 #include "dcvpagecomponent.h"
+#include "dcscene.h"
 
 #include <QDomDocument>
 #include <QMap>
+#include <QFile>
+#include <QDir>
 
 DCContainerSaver::DCContainerSaver(DCContainer *container) : d_container(container)
 {
@@ -45,11 +49,15 @@ bool DCContainerSaver::saveAll(const QString& containerRootPath)
 {
     const QMap<QString,DCVCPage*> *pages = d_container->getScene()->getPages();
     QMapIterator<QString, DCVCPage*> i(*pages);
+    bool r = true;
     while (i.hasNext())
     {
         i.next();
         DCVCPage *page = i.value();
-        saveForPage(containerRootPath, page);
+        if (!saveForPage(containerRootPath, page))
+        {
+            r = false;
+        }
     }
     return true;
 }
@@ -68,9 +76,9 @@ bool DCContainerSaver::saveForPage(const QString& containerRootPath, DCVCPage *p
     root.appendChild(body);
 
     const QList<DCVPageComponent*>* vcells = page->getCells();
-    for (int j = 0; j < vcells->length(); j++)
+    for (int i = 0; i < vcells->length(); i++)
     {
-        DCCell *cell = vcells->at(j)->getOwnerCell();
+        DCCell *cell = vcells->at(i)->getOwnerCell();
         QString cellName = QString::fromStdString(cell->getName());
 
         QDomElement aCellTag = doc.createElement("a");
@@ -89,9 +97,9 @@ bool DCContainerSaver::saveForPage(const QString& containerRootPath, DCVCPage *p
         }
         aCellTag.appendChild(aCellCodeTag);
         DCAxon *axon = cell->getAxon();
-        for (int k = 0; k < axon->getNumberOfTerminals(); k++)
+        for (int j = 0; j < axon->getNumberOfTerminals(); j++)
         {
-            DCAxonTerminal *terminal = axon->getTerminalAt(k);
+            DCAxonTerminal *terminal = axon->getTerminalAt(j);
             DCReceptor *receptor = dynamic_cast<DCReceptor*>(terminal->getTarget());
             if (receptor)
             {
@@ -111,12 +119,42 @@ bool DCContainerSaver::saveForPage(const QString& containerRootPath, DCVCPage *p
                 }
             }
         }
+        QDomElement preScriptTag = doc.createElement("pre");
+        preScriptTag.setAttribute("parameter", "script");
+        QDomCDATASection scriptCData = doc.createCDATASection(d_container->readCustomScriptFromWorkFile(cell));
+        preScriptTag.appendChild(scriptCData);
+        aCellTag.appendChild(preScriptTag);
         body.appendChild(aCellTag);
     }
 
+    const QList<DCVPageComponent*>* vcellcodeclasses = page->getCellCodeClasses();
+    for (int i = 0; i < vcellcodeclasses->length(); i++)
+    {
+        DCCellCode *cellcodeclass = dynamic_cast<DCVCCellCode*>(vcellcodeclasses->at(i))->getOwnerCellCodeClass();
+        QString cellCodeClassName = QString::fromStdString(cellcodeclass->getName());
+        if (cellCodeClassName.indexOf("#") >= 0)
+            cellCodeClassName = cellCodeClassName.mid(cellCodeClassName.indexOf("#")+1);
+
+        QDomElement aCellCodeTag = doc.createElement("a");
+        aCellCodeTag.setAttribute("define", "cellcode");
+        aCellCodeTag.setAttribute("name", cellCodeClassName);
+        aCellCodeTag.setAttribute("type", QString::fromStdString(cellcodeclass->getCellAPIName()));
+        QDomElement preScriptTag = doc.createElement("pre");
+        preScriptTag.setAttribute("parameter", "script");
+        QDomCDATASection scriptCData = doc.createCDATASection(d_container->readCellCodeScriptFromFile(cellcodeclass));
+        preScriptTag.appendChild(scriptCData);
+        aCellCodeTag.appendChild(preScriptTag);
+        body.appendChild(aCellCodeTag);
+    }
+
     doc.appendChild(root);
 
     QFile file(pageFilePath);
+    QFileInfo pathInfo = QFileInfo(pageFilePath);
+    QDir dir = pathInfo.dir();
+    if (!dir.exists())
+        dir.mkpath(dir.absolutePath());
+
     bool r = false;
     if (file.open(QFile::WriteOnly | QFile::Truncate))
     {
@@ -124,5 +162,10 @@ bool DCContainerSaver::saveForPage(const QString& containerRootPath, DCVCPage *p
         doc.save(out, 4);
         r = true;
     }
+
+    if (r)
+    {
+        r = d_container->getScene()->saveSceneForPage(containerRootPath, page);
+    }
     return r;
 }
index b5624d2..4f54e87 100644 (file)
@@ -33,6 +33,7 @@
 DCContent::DCContent(DCCreator *creator, std::string contentPath) :
     d_creator(creator), d_valid(false), d_container(0)
 {
+    d_contentRootPath = QString::fromStdString(contentPath);
     d_container = (DCContainer*) TKContainer::createContainer();
     d_container->setContent(this);
 
@@ -168,8 +169,10 @@ bool DCContent::parseContainerFile(const char *containerRoot)
     return r;
 }
 
-bool DCContent::saveAll(const QString& containerRoot)
+bool DCContent::saveAll(const QString& contentRoot)
 {
-    DCContainerSaver saver(d_container);
-    return saver.saveAll(containerRoot);
+    DCContainerSaver containerSaver(d_container);
+
+    QString containerRoot = contentRoot + "/Container";
+    return containerSaver.saveAll(containerRoot);
 }
index 46a0a5b..f1e3c13 100644 (file)
@@ -32,6 +32,7 @@ class DCContent
     DCCreator   *d_creator;
     bool        d_valid;
     DCContainer *d_container;
+    QString     d_contentRootPath;
 
 public:
     DCContent(DCCreator *creator, std::string contentPath);
@@ -41,8 +42,9 @@ public:
 
     DCContainer*    getContainer() const { return d_container; }
     DCCreator*      getCreator() const { return d_creator; }
+    QString         getContentRootPath() const { return d_contentRootPath; }
 
-    bool            saveAll(const QString& containerRoot);
+    bool            saveAll(const QString& contentRoot);
 
 };
 
index 07b8218..b3f3414 100644 (file)
@@ -130,11 +130,21 @@ bool DCCreator::loadContent(const QString &contentRoot)
 
 bool DCCreator::saveAll()
 {
-    if (d_scene)
+    bool r = false;
+    if (d_scene && d_vcontent)
+    {
+        r = d_vcontent->saveAll(d_vcontent->getContentRootPath());
+    }
+    QMessageBox msgBox;
+    if (r)
     {
-        d_vcontent->saveAll(QString::fromStdString(getCurrentContainer()->getContainerRootPath()));
-        return d_scene->saveSceneAll();
+        msgBox.setText(tr("Content is saved successfully"));
     }
+    else
+    {
+        msgBox.setText(tr("Error!! Failed to save content files"));
+    }
+    msgBox.exec();
     return false;
 }
 
@@ -438,7 +448,10 @@ bool DCCreator::doCommandRenameDirectoryImmidiate(const void *requester, const Q
 
 DCContainer* DCCreator::getCurrentContainer() const
 {
-    return d_vcontent->getContainer();
+    if (d_vcontent)
+        return d_vcontent->getContainer();
+    else
+        return NULL;
 }
 
 void DCCreator::slotSceneSelectedPageChanged(const void *requester)
index ae91abd..d4bbe89 100644 (file)
@@ -29,6 +29,7 @@ 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";
+const std::string TKContainer::CELLCODENAME_EMPTY    = "_DNEMPTY";
 
 TKContainer::TKContainer() : mStorage(NULL), mEmptyCellClass(NULL)
 {
@@ -36,7 +37,7 @@ TKContainer::TKContainer() : mStorage(NULL), mEmptyCellClass(NULL)
 
 void TKContainer::init()
 {
-    mEmptyCellClass = addCellCode("_DNEMPTY",CELLTYPE_JSBASIC,"");
+    mEmptyCellClass = addCellCode(CELLCODENAME_EMPTY,CELLTYPE_JSBASIC,"");
 }
 
 TKContainer::~TKContainer()
index c8eb76f..5d31d9e 100644 (file)
@@ -43,6 +43,8 @@ public:
     static const std::string CELLTYPE_IN;
     static const std::string CELLTYPE_BASICSTORAGE;
 
+    static const std::string CELLCODENAME_EMPTY;
+
     static TKContainer* createContainer();
     virtual void init();
 
index 9d9d886..39b1383 100644 (file)
 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()));
+    DCVPageComponent *vcompo = new DCVCCell(cell, page, 0.5, 0.5);
+    cell->bindComponent(vcompo);
+    page->registerCell(vcompo);
 
     return cell;
 }
 
 //static
-DCCellCode* DCComponentUtil::createCellCode(std::string theName, std::string theCellAPIName)
+DCCellCode* DCComponentUtil::createCellCode(DCVCPage *page, std::string theName, std::string theCellAPIName)
 {
     DCCellCode *cellcode = new DCCellCode(theName, theCellAPIName);
-    cellcode->bindComponent(new DCVCCellCode(cellcode));
+    DCVPageComponent *vcompo = new DCVCCellCode(cellcode, page);
+    cellcode->bindComponent(vcompo);
+    if (page)
+        page->registerCellCodeClass(vcompo);
 
     return cellcode;
 }
index e5f30a4..3d15f71 100644 (file)
@@ -33,7 +33,7 @@ class DCContainer;
 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 DCCellCode*      createCellCode(DCVCPage *page, std::string theName, std::string theCellAPIName);
     static DCAxon*          createAxon(DCCell *theOwner);
     static DCAxonTerminal*  createAxonTerminal(DCAxon *theOwner);
     static DCReceptor*      createReceptor(DCCell *theOwner);
index 342f188..d153f12 100644 (file)
@@ -36,13 +36,14 @@ static const double PI = 3.14159265358979323846264338327950288419717;
 
 DCVCCell::DCVCCell(DCCell *owner, DCVCPage *page, float size, float height)
     : 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)
+      d_dragOffsetX(0), d_dragOffsetY(0), d_dragOffsetZ(0), d_draggingOriginalSize(0), d_isDragging(false), d_isResizingDrag(false), d_draggingOriginalAxonLength(0), d_emptyCellCode(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_emptyCellCode = container->getEmptyCellCodeClass();
     }
 
     d_selectionRectRenderer = new DCSelectionRenderer(CUBE_ROUNDRADIUS,CUBE_ROUNDRADIUS);
@@ -196,7 +197,7 @@ void DCVCCell::renderOwnShape(bool isAnimationInterval, bool renderAsWireframe)
             d_shape->setHeight(d_owner->getViewHeight());
 
             QString label1;
-            if (d_owner->getCellCode() && d_owner->getCellCode()->getName() != "_DNEMPTY")
+            if (d_owner->getCellCode() && d_owner->getCellCode()!= d_emptyCellCode)
             {
                 label1 = QString::fromStdString(d_owner->getCellCode()->getName());
                 label1 = label1.mid(label1.lastIndexOf("#") + 1);
index 4acfc1e..78a1b01 100644 (file)
@@ -22,6 +22,7 @@
 #include "dcvpagecomponent.h"
 
 class DCCell;
+class TKCellCode;
 class DCCubeRenderer;
 class DCSelectionRenderer;
 class DCVCPage;
@@ -39,6 +40,7 @@ class DCVCCell : public DCVPageComponent
     bool                d_isDragging;
     bool                d_isResizingDrag;
     float               d_draggingOriginalAxonLength;
+    TKCellCode          *d_emptyCellCode;
 
 public:
     DCVCCell(DCCell *owner, DCVCPage *page, float size, float height);
index fe08b87..a9e330c 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "dcvcomponent.h"
 
-DCVCCellCode::DCVCCellCode(DCCellCode *owner)
+DCVCCellCode::DCVCCellCode(DCCellCode *owner, DCVCPage *page) : DCVPageComponent(page), d_owner(owner)
 {
 }
 
index 8fe37c4..3bd2c08 100644 (file)
@@ -25,13 +25,15 @@ class DCCellCode;
 
 class DCVCCellCode : public DCVPageComponent
 {
+    DCCellCode *d_owner;
+
 public:
-    DCVCCellCode(DCCellCode *owner);
+    DCVCCellCode(DCCellCode *owner, DCVCPage *page);
 
-    virtual DCVCPage *  getPageBelonging() const { return NULL; }
     virtual DCCell *    getOwnerCell() const { return NULL; }
     virtual bool        isResizingArea(float x, float y, float z) const { return false; }
 
+    DCCellCode*     getOwnerCellCodeClass() const { return d_owner; }
     virtual void    changePageBelonging(DCVCPage *page);
     virtual void    prepareChildrenForDraw(bool isAnimationInterval) {}
     virtual void    drawChildren(bool isAnimationInterval) {}
index 01b1124..6248a5d 100644 (file)
@@ -935,24 +935,9 @@ bool DCScene::loadSceneForPage(DCVCPage *page)
     return r;
 }
 
-bool DCScene::saveSceneAll()
+bool DCScene::saveSceneForPage(const QString &containerRootPath, DCVCPage *page)
 {
-    bool r = true;
-    QMapIterator<QString, DCVCPage*> i(d_pages);
-    while (i.hasNext())
-    {
-        i.next();
-        if (!saveSceneForPage(i.value()))
-        {
-            r = false;
-        }
-    }
-    return r;
-}
-
-bool DCScene::saveSceneForPage(DCVCPage *page)
-{
-    QString pageFilePath = QString::fromStdString(d_owner->getContainerRootPath()) + page->getLocationPath();
+    QString pageFilePath = containerRootPath + page->getLocationPath();
     QString settingFilePath = pageFilePath + ".dcvxml";
 
     QDomDocument doc;
@@ -968,7 +953,6 @@ bool DCScene::saveSceneForPage(DCVCPage *page)
         doc.save(out, 4);
         r = true;
     }
-
     return r;
 }
 
index 97304d5..e9aa8a6 100644 (file)
@@ -186,8 +186,7 @@ public:
     bool loadSceneAll();
     bool loadSceneForPage(DCVCPage *page);
 
-    bool saveSceneAll();
-    bool saveSceneForPage(DCVCPage *page);
+    bool saveSceneForPage(const QString& containerRootPath, DCVCPage *page);
 
     static void     lockScene();
     static void     unlockScene();