SaveAll works now. Failure cases are not considered well.
Error handling logics need to be implemented.
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)
#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)
{
{
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;
}
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");
}
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)
{
}
}
}
+ 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))
{
doc.save(out, 4);
r = true;
}
+
+ if (r)
+ {
+ r = d_container->getScene()->saveSceneForPage(containerRootPath, page);
+ }
return r;
}
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);
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);
}
DCCreator *d_creator;
bool d_valid;
DCContainer *d_container;
+ QString d_contentRootPath;
public:
DCContent(DCCreator *creator, std::string contentPath);
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);
};
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;
}
DCContainer* DCCreator::getCurrentContainer() const
{
- return d_vcontent->getContainer();
+ if (d_vcontent)
+ return d_vcontent->getContainer();
+ else
+ return NULL;
}
void DCCreator::slotSceneSelectedPageChanged(const void *requester)
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)
{
void TKContainer::init()
{
- mEmptyCellClass = addCellCode("_DNEMPTY",CELLTYPE_JSBASIC,"");
+ mEmptyCellClass = addCellCode(CELLCODENAME_EMPTY,CELLTYPE_JSBASIC,"");
}
TKContainer::~TKContainer()
static const std::string CELLTYPE_IN;
static const std::string CELLTYPE_BASICSTORAGE;
+ static const std::string CELLCODENAME_EMPTY;
+
static TKContainer* createContainer();
virtual void init();
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;
}
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);
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);
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);
#include "dcvpagecomponent.h"
class DCCell;
+class TKCellCode;
class DCCubeRenderer;
class DCSelectionRenderer;
class DCVCPage;
bool d_isDragging;
bool d_isResizingDrag;
float d_draggingOriginalAxonLength;
+ TKCellCode *d_emptyCellCode;
public:
DCVCCell(DCCell *owner, DCVCPage *page, float size, float height);
#include "dcvcomponent.h"
-DCVCCellCode::DCVCCellCode(DCCellCode *owner)
+DCVCCellCode::DCVCCellCode(DCCellCode *owner, DCVCPage *page) : DCVPageComponent(page), d_owner(owner)
{
}
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) {}
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;
doc.save(out, 4);
r = true;
}
-
return r;
}
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();