Commit b9ce45fd authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Move PhysicalWorld as grouped property of NetworkDefinition

No more children in PhysicalWorld, put them in NetworkDefinition

Change PhysicalGroup to ObjectsGroup as it can be used anywhere

Adapt sample network to reflect API changes
parent e89b3e43
......@@ -50,6 +50,22 @@ void BasicObject::updateState (const QJsonObject & values) {
}
}
ObjectsGroup::ObjectsGroup (QObject * parent)
: BasicObject (ObjectFamily::GROUP, parent)
, m_subObjects (this)
{
Manager::instance ().registerObject (this);
}
ObjectsGroup::~ObjectsGroup (void) {
Manager::instance ().unregisterObject (this);
}
void ObjectsGroup::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
AbstractObjectListModel::AbstractObjectListModel (QObject * parent) : QAbstractListModel (parent) { }
AbstractObjectListModel::~AbstractObjectListModel (void) { }
......
......@@ -173,6 +173,18 @@ public:
}
};
class ObjectsGroup : public BasicObject {
Q_OBJECT
QML_DEFAULT_PROPERTY (subObjects)
QML_LIST_PROPERTY (QObject, subObjects)
public:
explicit ObjectsGroup (QObject * parent = Q_NULLPTR);
virtual ~ObjectsGroup (void);
void onComponentCompleted (void) Q_DECL_FINAL;
};
class AbstractObjectListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY (int count READ getCount NOTIFY countChanged)
......
......@@ -279,7 +279,7 @@ void Manager::deinit (void) {
m_physicalValues.clear ();
m_physicalBlocks.clear ();
m_physicalMarkers.clear ();
m_physicalGroups.clear ();
m_objectsGroups.clear ();
m_routines.clear ();
m_routinesOnTimer.clear ();
m_routinesOnEvent.clear ();
......@@ -954,9 +954,9 @@ void Manager::doInitObjects (void) {
marker->refreshAncestors ();
usePath = true;
}
else if (PhysicalGroup * group = basicObject->as<PhysicalGroup> ()) {
else if (ObjectsGroup * group = basicObject->as<ObjectsGroup> ()) {
dump ("GROUP", group);
m_physicalGroups.append (group);
m_objectsGroups.append (group);
usePath = true;
}
else if (PhysicalWorld * world = basicObject->as<PhysicalWorld> ()) {
......
......@@ -101,7 +101,7 @@ class Manager : public QObject {
QML_REFLIST_PROPERTY (PhysicalValue, physicalValues, 500)
QML_REFLIST_PROPERTY (PhysicalBlock, physicalBlocks, 10)
QML_REFLIST_PROPERTY (PhysicalMarker, physicalMarkers, 20)
QML_REFLIST_PROPERTY (PhysicalGroup, physicalGroups, 5)
QML_REFLIST_PROPERTY (ObjectsGroup, objectsGroups, 5)
QML_REFLIST_PROPERTY (CanOpen, canOpens, 20)
QML_REFLIST_PROPERTY (CanBus, canBuses, 5)
QML_REFLIST_PROPERTY (SerialBus, serialBuses, 5)
......
#include "NetworkDefinition.h"
#include "Manager.h"
#include "Physics.h"
NetworkDefinition::NetworkDefinition (QObject * parent)
......@@ -14,5 +15,12 @@ NetworkDefinition::NetworkDefinition (QObject * parent)
, m_hideActuatorsPanel (false)
, m_hideMessagesPanel (false)
, m_startTab (Tabs::NODES_IO)
, m_world (Q_NULLPTR)
{ }
{
m_world = new PhysicalWorld (this);
}
void NetworkDefinition::classBegin (void) { }
void NetworkDefinition::componentComplete (void) {
Manager::instance ().intializeObject (m_world);
}
......@@ -2,7 +2,7 @@
#define NETWORKDEFINITION_H
#include <QObject>
#include <QQuickItem>
#include <QQmlParserStatus>
#include "QQmlObjectListModel.h"
#include "QQmlVarPropertyHelpers.h"
......@@ -21,8 +21,9 @@ QML_ENUM_CLASS (Tabs,
PHYSIC_3D,
DASHBOARD)
class NetworkDefinition : public QObject {
class NetworkDefinition : public QObject, public QQmlParserStatus {
Q_OBJECT
Q_INTERFACES (QQmlParserStatus)
QML_DEFAULT_PROPERTY (subObjects)
QML_LIST_PROPERTY (QObject, subObjects)
QML_WRITABLE_CSTREF_PROPERTY (QString, uid)
......@@ -35,10 +36,13 @@ class NetworkDefinition : public QObject {
QML_WRITABLE_VAR_PROPERTY (bool, hideActuatorsPanel)
QML_WRITABLE_VAR_PROPERTY (bool, hideMessagesPanel)
QML_WRITABLE_VAR_PROPERTY (Tabs::Type, startTab)
QML_WRITABLE_PTR_PROPERTY (PhysicalWorld, world)
QML_CONSTANT_PTR_PROPERTY (PhysicalWorld, world)
public:
explicit NetworkDefinition (QObject * parent = Q_NULLPTR);
void classBegin (void) Q_DECL_FINAL;
void componentComplete (void) Q_DECL_FINAL;
};
#endif // NETWORKDEFINITION_H
......@@ -115,9 +115,6 @@ PhysicalPoint::PhysicalPoint (QObject * parent)
m_onLeftToRight->set_uid ("ON_LEFT_TO_RIGHT");
m_onBackToFront->set_uid ("ON_BACK_TO_FRONT");
m_onBottomToTop->set_uid ("ON_BOTTOM_TO_TOP");
m_onLeftToRight->onComponentCompleted ();
m_onBackToFront->onComponentCompleted ();
m_onBottomToTop->onComponentCompleted ();
Manager::instance ().registerObject (this);
}
......@@ -127,6 +124,9 @@ PhysicalPoint::~PhysicalPoint (void) {
void PhysicalPoint::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
m_onLeftToRight->onComponentCompleted ();
m_onBackToFront->onComponentCompleted ();
m_onBottomToTop->onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
......@@ -153,12 +153,6 @@ PhysicalSize::PhysicalSize (QObject * parent)
m_toTop->set_uid ("TO_TOP");
m_toBack->set_uid ("TO_BACK");
m_toFront->set_uid ("TO_FRONT");
m_toLeft->onComponentCompleted ();
m_toRight->onComponentCompleted ();
m_toBottom->onComponentCompleted ();
m_toTop->onComponentCompleted ();
m_toBack->onComponentCompleted ();
m_toFront->onComponentCompleted ();
Manager::instance ().registerObject (this);
}
......@@ -168,6 +162,12 @@ PhysicalSize::~PhysicalSize (void) {
void PhysicalSize::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
m_toLeft->onComponentCompleted ();
m_toRight->onComponentCompleted ();
m_toBottom->onComponentCompleted ();
m_toTop->onComponentCompleted ();
m_toBack->onComponentCompleted ();
m_toFront->onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
......@@ -197,9 +197,6 @@ PhysicalAngle::PhysicalAngle (QObject * parent)
m_yaw->set_uid ("YAW");
m_pitch->set_uid ("PITCH");
m_roll->set_uid ("ROLL");
m_yaw->onComponentCompleted ();
m_pitch->onComponentCompleted ();
m_roll->onComponentCompleted ();
Manager::instance ().registerObject (this);
}
......@@ -209,6 +206,9 @@ PhysicalAngle::~PhysicalAngle (void) {
void PhysicalAngle::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
m_yaw->onComponentCompleted ();
m_pitch->onComponentCompleted ();
m_roll->onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
......@@ -229,8 +229,6 @@ PhysicalMarker::PhysicalMarker (QObject * parent)
m_absolutePos = new PhysicalPoint (this);
m_relativePos->set_uid ("REL_POS");
m_absolutePos->set_uid ("ABS_POS");
m_relativePos->onComponentCompleted ();
m_absolutePos->onComponentCompleted ();
Manager::instance ().registerObject (this);
}
......@@ -238,6 +236,13 @@ PhysicalMarker::~PhysicalMarker (void) {
Manager::instance ().unregisterObject (this);
}
void PhysicalMarker::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
m_relativePos->onComponentCompleted ();
m_absolutePos->onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
void PhysicalMarker::refreshAncestors (void) {
ancestors.clear ();
PhysicalBlock * tmp = m_referenceBlock;
......@@ -254,11 +259,6 @@ void PhysicalMarker::refreshAncestors (void) {
}
}
void PhysicalMarker::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
PhysicalBlock::PhysicalBlock (QObject * parent)
: BasicObject (ObjectFamily::BLOCK, parent)
, m_visible (true)
......@@ -275,10 +275,6 @@ PhysicalBlock::PhysicalBlock (QObject * parent)
m_angle->set_uid ("ANGLE");
m_pivotPos->set_uid ("POS");
m_absoluteAngle->set_uid ("ABS_ANGLE");
m_size->onComponentCompleted ();
m_angle->onComponentCompleted ();
m_pivotPos->onComponentCompleted ();
m_absoluteAngle->onComponentCompleted ();
// vertex
connect (this, &PhysicalBlock::roundedAxisChanged, this, &PhysicalBlock::refreshVertexList);
connect (m_size->get_toLeft (), &PhysicalValue::valChanged, this, &PhysicalBlock::refreshVertexList);
......@@ -307,6 +303,10 @@ PhysicalBlock::~PhysicalBlock (void) {
void PhysicalBlock::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
m_size->onComponentCompleted ();
m_angle->onComponentCompleted ();
m_pivotPos->onComponentCompleted ();
m_absoluteAngle->onComponentCompleted ();
m_ready = true;
Manager::instance ().intializeObject (this);
}
......@@ -466,30 +466,12 @@ QJsonObject PhysicalBlock::exportState (void) const {
};
}
PhysicalGroup::PhysicalGroup (QObject * parent)
: BasicObject (ObjectFamily::GROUP, parent)
, m_subObjects (this)
{
Manager::instance ().registerObject (this);
}
PhysicalGroup::~PhysicalGroup (void) {
Manager::instance ().unregisterObject (this);
}
void PhysicalGroup::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
PhysicalWorld::PhysicalWorld (QObject * parent)
: BasicObject (ObjectFamily::WORLD, parent)
, m_subObjects (this)
, m_dirty (false)
{
m_bounds = new PhysicalSize (this);
m_bounds->set_uid ("BOUNDS");
m_bounds->onComponentCompleted ();
Manager::instance ().registerObject (this);
}
......@@ -499,6 +481,7 @@ PhysicalWorld::~PhysicalWorld (void) {
void PhysicalWorld::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
m_bounds->onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
......
......@@ -230,22 +230,8 @@ public:
void refreshAncestors (void);
};
class PhysicalGroup : public BasicObject {
Q_OBJECT
QML_DEFAULT_PROPERTY (subObjects)
QML_LIST_PROPERTY (QObject, subObjects)
public:
explicit PhysicalGroup (QObject * parent = Q_NULLPTR);
virtual ~PhysicalGroup (void);
void onComponentCompleted (void) Q_DECL_FINAL;
};
class PhysicalWorld : public BasicObject {
Q_OBJECT
QML_DEFAULT_PROPERTY (subObjects)
QML_LIST_PROPERTY (QObject, subObjects)
QML_CONSTANT_PTR_PROPERTY (PhysicalSize, bounds) // boundaries on 6 sides
public:
......
......@@ -135,6 +135,7 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) {
qmlRegisterUncreatableType<BasicObject> (uri, maj, min, "BasicObject", msg);
qmlRegisterUncreatableType<Memory> (uri, maj, min, "Memory", msg);
qmlRegisterUncreatableType<AbstractObjectListModel> (uri, maj, min, "ObjectRefListModel", msg);
qmlRegisterUncreatableType<PhysicalWorld> (uri, maj, min, "PhysicalWorld", msg);
#else
// should not be instanciated but due to QML engine bug, must be declared as "creatable" for properties
qmlRegisterType<HelpSection> (uri, maj, min, "HelpSection");
......@@ -159,6 +160,7 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) {
qmlRegisterType<BasicObject> (uri, maj, min, "BasicObject");
qmlRegisterType<Memory> (uri, maj, min, "Memory");
qmlRegisterType<AbstractObjectListModel> (uri, maj, min, "ObjectRefListModel");
qmlRegisterType<PhysicalWorld> (uri, maj, min, "PhysicalWorld");
#endif
// can be created in QML in UI
qmlRegisterType<RendererItem> (uri, maj, min, "RendererItem");
......@@ -193,14 +195,13 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) {
qmlRegisterType<CanOpen> (uri, maj, min, "CanOpen");
qmlRegisterType<NetworkDefinition> (uri, maj, min, "NetworkDefinition");
qmlRegisterType<Node> (uri, maj, min, "Node");
qmlRegisterType<ObjectsGroup> (uri, maj, min, "ObjectsGroup");
qmlRegisterType<PhysicalPoint> (uri, maj, min, "PhysicalPoint");
qmlRegisterType<PhysicalSize> (uri, maj, min, "PhysicalSize");
qmlRegisterType<PhysicalAngle> (uri, maj, min, "PhysicalAngle");
qmlRegisterType<PhysicalBlock> (uri, maj, min, "PhysicalBlock");
qmlRegisterType<PhysicalValue> (uri, maj, min, "PhysicalValue");
qmlRegisterType<PhysicalMarker> (uri, maj, min, "PhysicalMarker");
qmlRegisterType<PhysicalGroup> (uri, maj, min, "PhysicalGroup");
qmlRegisterType<PhysicalWorld> (uri, maj, min, "PhysicalWorld");
qmlRegisterType<RoutineOnCanFrame> (uri, maj, min, "RoutineOnCanFrame");
qmlRegisterType<RoutineOnSerialFrame> (uri, maj, min, "RoutineOnSerialFrame");
qmlRegisterType<RoutineOnEvent> (uri, maj, min, "RoutineOnEvent");
......
......@@ -21,7 +21,7 @@ ExpandableGroup {
}
ExtraAnchors.horizontalFill: parent;
property PhysicalGroup group : null;
property ObjectsGroup group : null;
signal needVisible (Item item);
signal needDetails (PhysicalValue phyVal);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment