annotate native/PhantomOmni/CollectionsManager.h @ 8:ea7885bd9bff tip

fixed bug : render solid line as dotted/dashed when moving the stylus from dotted/dashed to solid
author ccmi-guest
date Thu, 03 Jul 2014 16:12:20 +0100
parents d66dd5880081
children
rev   line source
fiore@3 1 #pragma once
fiore@3 2
fiore@3 3 #include <jni.h>
fiore@3 4 #include "stdafx.h"
fiore@3 5 #include "utils.h"
fiore@3 6
fiore@3 7
fiore@3 8 /* this class uses the java haptic object lists to provide nodes *
fiore@3 9 * and edges to draw to the graphic and haptic managers */
fiore@3 10 class CollectionsManager
fiore@3 11 {
fiore@3 12 public:
fiore@3 13 struct NodeData {
fiore@3 14 jdouble x;
fiore@3 15 jdouble y;
fiore@3 16 jint hapticId;
fiore@3 17 jint diagramId;
fiore@3 18
fiore@3 19 NodeData(){}
fiore@3 20 private :
fiore@3 21 NodeData(const NodeData& n){/* avoid mistakenly copy construction calls */}
fiore@3 22 };
fiore@3 23
fiore@3 24 struct EdgeData{
fiore@3 25 jdouble *x;
fiore@3 26 jdouble *y;
fiore@3 27 bool **adjMatrix;
fiore@3 28 jint hapticId;
fiore@3 29 jint diagramId;
fiore@3 30 jint stipplePattern;
fiore@3 31 jsize nodeStart;
fiore@3 32 jdouble attractPoint[2];
fiore@3 33 void setSize(unsigned int s){
fiore@3 34 size = s;
fiore@3 35 if(s > previousSize){
fiore@3 36 /* delete the old memory */
fiore@3 37 delete [] x;
fiore@3 38 delete [] y;
fiore@3 39 for(unsigned int i=0; i<previousSize; i++)
fiore@3 40 delete[] adjMatrix[i];
fiore@3 41 delete [] adjMatrix;
fiore@3 42 /* allocates a bigger one */
fiore@3 43 try{
fiore@3 44 x = new jdouble[size];
fiore@3 45 y = new jdouble[size];
fiore@3 46 adjMatrix = new bool* [size];
fiore@3 47 for(unsigned int i=0; i<size; i++){
fiore@3 48 adjMatrix[i] = new bool[size];
fiore@3 49 for(unsigned int j=0; j<size; j++)
fiore@3 50 adjMatrix[i][j] = false;
fiore@3 51 }
fiore@3 52 }catch(std::bad_alloc){
fiore@3 53 stopExecution("Could not allocate memory for the program.\nAborting...");
fiore@3 54 }
fiore@3 55 previousSize = size;
fiore@3 56 }
fiore@3 57 }
fiore@3 58
fiore@3 59 unsigned int getSize() const {
fiore@3 60 return size;
fiore@3 61 }
fiore@3 62
fiore@3 63 EdgeData(unsigned int s) : size(s), previousSize(s){
fiore@3 64 x = new jdouble[size];
fiore@3 65 y = new jdouble[size];
fiore@3 66 adjMatrix = new bool* [size];
fiore@3 67 for(unsigned int i=0; i<size; i++){
fiore@3 68 adjMatrix[i] = new bool[size];
fiore@3 69 for(unsigned int j=0; j<size; j++)
fiore@3 70 adjMatrix[i][j] = false;
fiore@3 71 }
fiore@3 72 }
fiore@3 73 ~EdgeData(){
fiore@3 74 delete [] x;
fiore@3 75 delete [] y;
fiore@3 76 for(unsigned int i=0; i<size; i++)
fiore@3 77 delete[] adjMatrix[i];
fiore@3 78 delete [] adjMatrix;
fiore@3 79 }
fiore@3 80 private :
fiore@3 81 unsigned int size;
fiore@3 82 unsigned int previousSize;
fiore@3 83 EdgeData(const EdgeData& e){ /* avoid mistakenly copy construction */}
fiore@3 84
fiore@3 85 };
fiore@3 86 private:
fiore@3 87 JNIEnv *env;
fiore@3 88 jobject *haptics;
fiore@3 89
fiore@3 90 jclass hapticClass;
fiore@3 91 jclass hapticNodeClass;
fiore@3 92 jclass hapticEdgeClass;
fiore@3 93 jclass listClass;
fiore@3 94 jclass bitsetClass;
fiore@3 95 jobject nodeList;
fiore@3 96 jobject edgeList;
fiore@3 97 jmethodID getMethodId;
fiore@3 98 jmethodID sizeMethodId;
fiore@3 99 jmethodID getBitMethodId;
fiore@3 100 jmethodID getNodeFromIDMethodId;
fiore@3 101 jmethodID getEdgeFromIDMethodId;
fiore@3 102 jfieldID xFieldId;
fiore@3 103 jfieldID yFieldId;
fiore@3 104 jfieldID nodeHapticIdFieldId;
fiore@3 105 jfieldID edgeHapticIdFieldId;
fiore@3 106 jfieldID nodeDiagramIdFieldId;
fiore@3 107 jfieldID edgeDiagramIdFieldId;
fiore@3 108 jfieldID nodeListfieldId;
fiore@3 109 jfieldID stipplePatternfieldId;
fiore@3 110 jfieldID edgeListfieldId;
fiore@3 111 jfieldID edgeSizefieldId;
fiore@3 112 jfieldID edgeXsFieldId;
fiore@3 113 jfieldID edgeYsFieldId;
fiore@3 114 jfieldID edgeAdjMatrixFieldId;
fiore@3 115 jfieldID attractPointXFieldId;
fiore@3 116 jfieldID attractPointYFieldId;
fiore@3 117 jfieldID edgeNodeStartFieldId;
fiore@3 118
fiore@3 119 int screenHeight;
fiore@3 120 NodeData nd;
fiore@3 121 EdgeData ed;
fiore@3 122
fiore@3 123 void fillupNodeData(struct NodeData & nd, jobject & currentNode);
fiore@3 124 void fillupEdgeData(struct EdgeData & ed, jobject & currentEdge);
fiore@3 125 public:
fiore@3 126 CollectionsManager(JNIEnv *environment, jobject *obj) : env(environment), haptics(obj), ed(2){}
fiore@3 127 virtual ~CollectionsManager(void){}
fiore@3 128 const jint getNodesNum();
fiore@3 129 const jint getEdgesNum();
fiore@3 130 struct NodeData & getNodeData(const int i);
fiore@3 131 struct EdgeData & getEdgeData(const int i);
fiore@3 132 struct NodeData & getNodeDataFromID(const jint id) throw(int);
fiore@3 133 struct EdgeData & getEdgeDataFromID(const jint id) throw(int);
fiore@3 134 bool isEdge(const jint id) const throw(int);
fiore@3 135 bool isNode(const jint id) const throw(int);
fiore@3 136 void init(void);
fiore@5 137 inline int getScreenHeight() const { return screenHeight;}
fiore@5 138 inline void setScreenHeight(const int sh) { screenHeight = sh; }
fiore@3 139
fiore@3 140 };