Commit 48ae2ac7 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Add node factory base on core plugin one.

parent a8f83914
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Wed Mar 20 12:26:15 2013 (+0100)
## Version:
## Last-Updated: Fri Apr 5 09:31:15 2013 (+0200)
## Last-Updated: Wed Apr 10 12:10:27 2013 (+0200)
## By: Thibaud Kloczko
## Update #: 157
## Update #: 163
######################################################################
##
### Change Log:
......@@ -19,7 +19,7 @@ project(dtkComposer)
## #################################################################
set(${PROJECT_NAME}_HEADERS
# dtkComposer.h
dtkComposer.h
# dtkComposerCompass.h
# dtkComposerControls.h
# dtkComposerControlsDelegate.h
......@@ -42,6 +42,7 @@ set(${PROJECT_NAME}_HEADERS
# dtkComposerMachine.h
# dtkComposerMachineState.h
dtkComposerNode.h
dtkComposerNodeFactory.h
# dtkComposerNodeArrayScalar.h
# dtkComposerNodeArrayScalarExtractor.h
# dtkComposerNodeArrayScalarOperatorModifier.h
......@@ -126,7 +127,7 @@ set(${PROJECT_NAME}_HEADERS
)
set(${PROJECT_NAME}_SOURCES
# dtkComposer.cpp
dtkComposer.cpp
# dtkComposerCompass.cpp
# dtkComposerControls.cpp
# dtkComposerControlsDelegate.cpp
......@@ -148,6 +149,7 @@ set(${PROJECT_NAME}_SOURCES
# dtkComposerMachine.cpp
# dtkComposerMachineState.cpp
dtkComposerNode.cpp
dtkComposerNodeFactory.cpp
# dtkComposerNodeArrayScalar.cpp
# dtkComposerNodeArrayScalarExtractor.cpp
# dtkComposerNodeArrayScalarOperatorModifier.cpp
......@@ -225,7 +227,7 @@ set(${PROJECT_NAME}_SOURCES
# dtkComposerReader.cpp
# dtkComposerWriter.cpp
)
set(${PROJECT_NAME}_QRC dtkComposer.qrc)
## #################################################################
......
/* dtkComposer.cpp ---
/* dtkComposer.cpp ---
*
* Author: tkloczko
* Copyright (C) 2011 - Thibaud Kloczko, Inria.
* Created: Mon Jan 30 10:34:49 2012 (+0100)
* Version: $Id$
* Last-Updated: Wed Mar 20 14:42:14 2013 (+0100)
* By: Julien Wintz
* Update #: 428
* Author: Thibaud Kloczko
* Created: Tue Apr 9 12:49:06 2013 (+0200)
* Version:
* Last-Updated: Wed Apr 10 15:09:19 2013 (+0200)
* By: Thibaud Kloczko
* Update #: 37
*/
/* Commentary:
/* Change Log:
*
*/
/* Change log:
*
*/
#include <dtkConfig.h>
#include "dtkComposer.h"
#include "dtkComposer_p.h"
#include "dtkComposerCompass.h"
#include "dtkComposerEvaluator.h"
#include "dtkComposerFactory.h"
#include "dtkComposerGraph.h"
#include "dtkComposerMachine.h"
#include "dtkComposerNodeRemote.h"
#include "dtkComposerPath.h"
#include "dtkComposerReader.h"
#include "dtkComposerScene.h"
#include "dtkComposerSceneNodeComposite.h"
#include "dtkComposerSceneNodeControl.h"
#include "dtkComposerStack.h"
#include "dtkComposerView.h"
#include "dtkComposerWriter.h"
#include <dtkLog>
#include <QtConcurrent>
#include <QtCore>
#include <QtGui>
#include <QtNetwork>
// /////////////////////////////////////////////////////////////////
// dtkComposerPrivate
// /////////////////////////////////////////////////////////////////
void dtkComposerPrivate::download(const QUrl& url)
{
Q_UNUSED(url);
}
void dtkComposerPrivate::onRequestFinished(QNetworkReply *)
{
}
// /////////////////////////////////////////////////////////////////
// dtkComposer
// /////////////////////////////////////////////////////////////////
dtkComposer::dtkComposer(QWidget *parent) : QWidget(parent), d(new dtkComposerPrivate)
{
d->machine = new dtkComposerMachine;
d->factory = new dtkComposerFactory;
d->graph = new dtkComposerGraph;
d->stack = new dtkComposerStack;
d->scene = new dtkComposerScene;
d->evaluator = new dtkComposerEvaluator;
d->scene->setFactory(d->factory);
d->scene->setMachine(d->machine);
d->scene->setStack(d->stack);
d->scene->setGraph(d->graph);
d->view = new dtkComposerView(this);
d->view->setScene(d->scene);
d->path = new dtkComposerPath(this);
d->path->setScene(d->scene);
d->compass = new dtkComposerCompass;
d->compass->setScene(d->scene);
d->compass->setView(d->view);
d->evaluator->setGraph(d->graph);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(d->path);
layout->addWidget(d->view);
connect(d->scene, SIGNAL(modified(bool)), this, SIGNAL(modified(bool)));
}
dtkComposer::~dtkComposer(void)
{
delete d->machine;
delete d->factory;
delete d->graph;
delete d->stack;
delete d->evaluator;
delete d;
d = NULL;
}
void dtkComposer::setFactory(dtkComposerFactory *factory)
{
delete d->factory;
d->factory = factory;
#include "dtkComposerNodeFactory.h"
d->scene->setFactory(d->factory);
}
bool dtkComposer::open(const QUrl& url)
{
d->download(url);
bool status = false;
if(!d->tempName.isEmpty())
status = this->open(d->tempName);
return status;
}
bool dtkComposer::open(QString file)
namespace dtkComposer
{
if (!file.isEmpty()) {
namespace node
{
namespace _private {
dtkComposerNodeFactory factory;
}
dtkComposerReader reader;
reader.setFactory(d->factory);
reader.setScene(d->scene);
reader.setGraph(d->graph);
reader.read(file);
d->fileName = file;
dtkComposerNodeFactory& factory(void) {
return _private::factory;
}
}
return true;
}
bool dtkComposer::save(QString file, dtkComposerWriter::Type type)
{
return saveNode(d->scene->root(), file, type);
}
bool dtkComposer::saveNode(dtkComposerSceneNodeComposite *node, QString file, dtkComposerWriter::Type type)
{
QString fName = d->fileName;
if(!file.isEmpty())
fName = file;
dtkComposerWriter writer;
writer.setScene(d->scene);
writer.writeNode(node, fName, type);
const QFileInfo fi(fName);
d->fileName = fi.absoluteFilePath();
return true;
}
bool dtkComposer::insert(QString file)
{
if (!file.isEmpty()) {
dtkComposerReader reader;
reader.setFactory(d->factory);
reader.setScene(d->scene);
reader.setGraph(d->graph);
reader.read(file, true);
}
return true;
}
void dtkComposer::updateRemotes(dtkComposerSceneNodeComposite *composite)
{
#if defined(DTK_BUILD_DISTRIBUTED)
dtkComposerWriter writer;
writer.setScene(d->scene);
foreach(dtkComposerSceneNode *node, composite->nodes()) {
if (dtkComposerNodeRemote *remote = dynamic_cast<dtkComposerNodeRemote *>(node->wrapee()))
remote->setComposition(writer.toXML(dynamic_cast<dtkComposerSceneNodeComposite *>(node)));
else if (dtkComposerSceneNodeComposite *sub = dynamic_cast<dtkComposerSceneNodeComposite *>(node))
this->updateRemotes(sub);
else if (dtkComposerSceneNodeControl *ctrl = dynamic_cast<dtkComposerSceneNodeControl *>(node))
foreach(dtkComposerSceneNodeComposite *block, ctrl->blocks())
this->updateRemotes(block);
}
#else
Q_UNUSED(composite);
#endif
}
void dtkComposer::run(void)
{
this->updateRemotes(d->scene->root());
QtConcurrent::run(d->evaluator, &dtkComposerEvaluator::run, false);
d->graph->update();
}
void dtkComposer::step(void)
{
d->evaluator->step();
d->evaluator->logStack();
d->graph->update();
}
void dtkComposer::cont(void)
{
this->updateRemotes(d->scene->root());
QtConcurrent::run(d->evaluator, &dtkComposerEvaluator::cont, false);
d->graph->update();
}
void dtkComposer::next(void)
{
QtConcurrent::run(d->evaluator, &dtkComposerEvaluator::next, false);
d->graph->update();
}
void dtkComposer::stop(void)
{
d->evaluator->stop();
}
void dtkComposer::reset(void)
{
dtkComposerWriter writer;
writer.setScene(d->scene);
QString data = writer.toXML(d->scene->root(), false).toString();
dtkComposerReader reader;
reader.setFactory(d->factory);
reader.setScene(d->scene);
reader.setGraph(d->graph);
reader.readString(data);
d->evaluator->reset();
}
dtkComposerEvaluator *dtkComposer::evaluator(void)
{
return d->evaluator;
}
dtkComposerMachine *dtkComposer::machine(void)
{
return d->machine;
}
dtkComposerFactory *dtkComposer::factory(void)
{
return d->factory;
}
dtkComposerGraph *dtkComposer::graph(void)
{
return d->graph;
}
dtkComposerScene *dtkComposer::scene(void)
{
return d->scene;
}
dtkComposerStack *dtkComposer::stack(void)
{
return d->stack;
}
dtkComposerView *dtkComposer::view(void)
{
return d->view;
}
dtkComposerPath *dtkComposer::path(void)
{
return d->path;
}
dtkComposerCompass *dtkComposer::compass(void)
{
return d->compass;
}
/* dtkComposer.h ---
/* dtkComposer.h ---
*
* Author: tkloczko
* Copyright (C) 2011 - Thibaud Kloczko, Inria.
* Created: Mon Jan 30 10:34:34 2012 (+0100)
* Version: $Id$
* Last-Updated: Wed Mar 20 14:15:09 2013 (+0100)
* By: Julien Wintz
* Update #: 75
* Author: Thibaud Kloczko
* Created: Tue Apr 9 12:43:49 2013 (+0200)
* Version:
* Last-Updated: Wed Apr 10 15:02:48 2013 (+0200)
* By: Thibaud Kloczko
* Update #: 29
*/
/* Commentary:
/* Change Log:
*
*/
/* Change log:
*
*/
#ifndef DTKCOMPOSER_H
#define DTKCOMPOSER_H
#include "dtkComposerWriter.h"
#pragma once
#include <QtCore>
#include <QtGui>
#include <QtWidgets>
class dtkComposerNodeFactory;
class dtkComposerEvaluator;
class dtkComposerFactory;
class dtkComposerGraph;
class dtkComposerMachine;
class dtkComposerPrivate;
class dtkComposerScene;
class dtkComposerSceneNodeComposite;
class dtkComposerStack;
class dtkComposerView;
class dtkComposerCompass;
class dtkComposerPath;
class dtkComposer : public QWidget
namespace dtkComposer
{
Q_OBJECT
public:
dtkComposer(QWidget *parent = 0);
virtual ~dtkComposer(void);
public:
void setFactory(dtkComposerFactory *factory);
public slots:
virtual bool open(const QUrl& url);
virtual bool open(QString file);
virtual bool save(QString file = QString(), dtkComposerWriter::Type type = dtkComposerWriter::Ascii);
virtual bool saveNode(dtkComposerSceneNodeComposite *node, QString file = QString(), dtkComposerWriter::Type type = dtkComposerWriter::Ascii);
virtual bool insert(QString file);
public slots:
void run(void);
void step(void);
void cont(void);
void next(void);
void stop(void);
void reset(void);
signals:
void modified(bool);
public:
dtkComposerEvaluator *evaluator(void);
dtkComposerCompass *compass(void);
dtkComposerFactory *factory(void);
dtkComposerMachine *machine(void);
dtkComposerGraph *graph(void);
dtkComposerScene *scene(void);
dtkComposerStack *stack(void);
dtkComposerView *view(void);
dtkComposerPath *path(void);
public:
void updateRemotes(dtkComposerSceneNodeComposite * composite);
private:
dtkComposerPrivate *d;
};
namespace node {
dtkComposerNodeFactory& factory(void);
}
}
#endif
......@@ -12,10 +12,7 @@
*
*/
#ifndef DTKCOMPOSERFACTORY_H
#define DTKCOMPOSERFACTORY_H
#pragma once
#include <QtCore>
......@@ -63,4 +60,3 @@ private:
dtkComposerFactoryPrivate *d;
};
#endif
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - David Rey, Inria.
* Created: Tue Feb 14 14:24:23 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Apr 4 09:48:34 2013 (+0200)
* Last-Updated: Wed Apr 10 15:07:28 2013 (+0200)
* By: Thibaud Kloczko
* Update #: 57
* Update #: 93
*/
/* Commentary:
......@@ -19,17 +19,18 @@
#pragma once
#include <dtkCore>
#include <QtCore>
class dtkComposerNodePrivate;
class dtkComposerTransmitter;
// /////////////////////////////////////////////////////////////////
// dtkComposerNode declaration
// dtkComposerNode
// /////////////////////////////////////////////////////////////////
class dtkComposerNodePrivate;
class dtkComposerNode
class dtkComposerNode
{
public:
dtkComposerNode(void);
......@@ -69,4 +70,3 @@ public:
private:
dtkComposerNodePrivate *d;
};
/* dtkComposerNodeFactory.cpp ---
*
* Author: Thibaud Kloczko
* Created: Wed Apr 10 12:02:54 2013 (+0200)
* Version:
* Last-Updated: Wed Apr 10 15:11:47 2013 (+0200)
* By: Thibaud Kloczko
* Update #: 169
*/
/* Change Log:
*
*/
#include "dtkComposerNodeFactory.h"
#include "dtkComposerNodeBoolean.h"
#include "dtkComposerNodeBooleanOperator.h"
#include "dtkComposerNodeControlCase.h"
#include "dtkComposerNodeControlDoWhile.h"
#include "dtkComposerNodeControlFor.h"
#include "dtkComposerNodeControlForEach.h"
#include "dtkComposerNodeControlIf.h"
#include "dtkComposerNodeControlMap.h"
#include "dtkComposerNodeControlWhile.h"
#include "dtkComposerNodeInteger.h"
#include "dtkComposerNodeNumberOperator.h"
#include "dtkComposerNodeReal.h"
#include "dtkComposerNodeString.h"
#include "dtkComposerNodeStringOperator.h"
dtkComposerNodeFactory::dtkComposerNodeFactory(void) : dtkCorePluginFactory<dtkComposerNode>()
{
this->initNodeBoolean();
this->initNodeControl();
this->initNodeNumber();
this->initNodeString();
}
dtkComposerNodeFactory::~dtkComposerNodeFactory(void)
{
}
void dtkComposerNodeFactory::initNodeBoolean(void)
{
this->record("boolean", &dtkComposerNodeCreator<dtkComposerNodeBoolean>);
this->record("not", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorUnaryNot>);
this->record("and", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryAnd>);
this->record("or", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryOr>);
this->record("xor", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryXor>);
this->record("nand", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryNand>);
this->record("nor", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryNor>);
this->record("xnor", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryXnor>);
this->record("imp", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryImp>);
this->record("nimp", &dtkComposerNodeCreator<dtkComposerNodeBooleanOperatorBinaryNimp>);
}
void dtkComposerNodeFactory::initNodeControl(void)
{
this->record("case", &dtkComposerNodeCreator<dtkComposerNodeControlCase>);
this->record("if", &dtkComposerNodeCreator<dtkComposerNodeControlIf>);
this->record("dowhile", &dtkComposerNodeCreator<dtkComposerNodeControlDoWhile>);
this->record("for", &dtkComposerNodeCreator<dtkComposerNodeControlFor>);
this->record("foreach", &dtkComposerNodeCreator<dtkComposerNodeControlForEach>);
this->record("map", &dtkComposerNodeCreator<dtkComposerNodeControlMap>);
this->record("while", &dtkComposerNodeCreator<dtkComposerNodeControlWhile>);
}
void dtkComposerNodeFactory::initNodeNumber(void)
{
this->record("integer", &dtkComposerNodeCreator<dtkComposerNodeInteger>);
this->record("real", &dtkComposerNodeCreator<dtkComposerNodeReal>);
// -- Unary operators
this->record("abs", &dtkComposerNodeCreator<dtkComposerNodeNumberOperatorUnaryAbs>);
this->record("sqrt", &dtkComposerNodeCreator<dtkComposerNodeNumberOperatorUnarySqrt>);
this->record("square", &dtkComposerNodeCreator<dtkComposerNodeNumberOperatorUnarySquare>);
this->record("incr", &dtkComposerNodeCreator<dtkComposerNodeNumberOperatorUnaryIncr>);
this->record("decr", &dtkComposerNodeCreator<dtkComposerNodeNumberOperatorUnaryDecr>);
this->record("floor", &dtkComposerNodeCreator<dtkComposerNodeNumberOperatorUnaryFloor>);
this->record("ceil", &dtkComposerNodeCreator<dtkComposerNodeNumberOperatorUnaryCeil>);
<