Mercurial > hg > ccmieditor
diff native/PhantomOmni/CollectionsManager.h @ 3:9e67171477bc
PHANTOM Omni Heptic device release
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Wed, 25 Apr 2012 17:09:09 +0100 |
parents | |
children | d66dd5880081 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/native/PhantomOmni/CollectionsManager.h Wed Apr 25 17:09:09 2012 +0100 @@ -0,0 +1,140 @@ +#pragma once + +#include <jni.h> +#include "stdafx.h" +#include "utils.h" + + +/* this class uses the java haptic object lists to provide nodes * + * and edges to draw to the graphic and haptic managers */ +class CollectionsManager +{ +public: + struct NodeData { + jdouble x; + jdouble y; + jint hapticId; + jint diagramId; + + NodeData(){} + private : + NodeData(const NodeData& n){/* avoid mistakenly copy construction calls */} + }; + + struct EdgeData{ + jdouble *x; + jdouble *y; + bool **adjMatrix; + jint hapticId; + jint diagramId; + jint stipplePattern; + jsize nodeStart; + jdouble attractPoint[2]; + void setSize(unsigned int s){ + size = s; + if(s > previousSize){ + /* delete the old memory */ + delete [] x; + delete [] y; + for(unsigned int i=0; i<previousSize; i++) + delete[] adjMatrix[i]; + delete [] adjMatrix; + /* allocates a bigger one */ + try{ + x = new jdouble[size]; + y = new jdouble[size]; + adjMatrix = new bool* [size]; + for(unsigned int i=0; i<size; i++){ + adjMatrix[i] = new bool[size]; + for(unsigned int j=0; j<size; j++) + adjMatrix[i][j] = false; + } + }catch(std::bad_alloc){ + stopExecution("Could not allocate memory for the program.\nAborting..."); + } + previousSize = size; + } + } + + unsigned int getSize() const { + return size; + } + + EdgeData(unsigned int s) : size(s), previousSize(s){ + x = new jdouble[size]; + y = new jdouble[size]; + adjMatrix = new bool* [size]; + for(unsigned int i=0; i<size; i++){ + adjMatrix[i] = new bool[size]; + for(unsigned int j=0; j<size; j++) + adjMatrix[i][j] = false; + } + } + ~EdgeData(){ + delete [] x; + delete [] y; + for(unsigned int i=0; i<size; i++) + delete[] adjMatrix[i]; + delete [] adjMatrix; + } + private : + unsigned int size; + unsigned int previousSize; + EdgeData(const EdgeData& e){ /* avoid mistakenly copy construction */} + + }; +private: + JNIEnv *env; + jobject *haptics; + + jclass hapticClass; + jclass hapticNodeClass; + jclass hapticEdgeClass; + jclass listClass; + jclass bitsetClass; + jobject nodeList; + jobject edgeList; + jmethodID getMethodId; + jmethodID sizeMethodId; + jmethodID getBitMethodId; + jmethodID getNodeFromIDMethodId; + jmethodID getEdgeFromIDMethodId; + jfieldID xFieldId; + jfieldID yFieldId; + jfieldID nodeHapticIdFieldId; + jfieldID edgeHapticIdFieldId; + jfieldID nodeDiagramIdFieldId; + jfieldID edgeDiagramIdFieldId; + jfieldID nodeListfieldId; + jfieldID stipplePatternfieldId; + jfieldID edgeListfieldId; + jfieldID edgeSizefieldId; + jfieldID edgeXsFieldId; + jfieldID edgeYsFieldId; + jfieldID edgeAdjMatrixFieldId; + jfieldID attractPointXFieldId; + jfieldID attractPointYFieldId; + jfieldID edgeNodeStartFieldId; + + int screenHeight; + NodeData nd; + EdgeData ed; + + void fillupNodeData(struct NodeData & nd, jobject & currentNode); + void fillupEdgeData(struct EdgeData & ed, jobject & currentEdge); +public: + CollectionsManager(JNIEnv *environment, jobject *obj) : env(environment), haptics(obj), ed(2){} + virtual ~CollectionsManager(void){} + const jint getNodesNum(); + const jint getEdgesNum(); + struct NodeData & getNodeData(const int i); + struct EdgeData & getEdgeData(const int i); + struct NodeData & getNodeDataFromID(const jint id) throw(int); + struct EdgeData & getEdgeDataFromID(const jint id) throw(int); + bool isEdge(const jint id) const throw(int); + bool isNode(const jint id) const throw(int); + void init(void); + int getScreenHeight() const { return screenHeight;} + void setScreenHeight(const int sh) { screenHeight = sh; } + +};