annotate native/Falcon/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@5 1 /*
fiore@5 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
fiore@5 3
fiore@5 4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
fiore@5 5
fiore@5 6 This program is free software: you can redistribute it and/or modify
fiore@5 7 it under the terms of the GNU General Public License as published by
fiore@5 8 the Free Software Foundation, either version 3 of the License, or
fiore@5 9 (at your option) any later version.
fiore@5 10
fiore@5 11 This program is distributed in the hope that it will be useful,
fiore@5 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
fiore@5 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fiore@5 14 GNU General Public License for more details.
fiore@5 15
fiore@5 16 You should have received a copy of the GNU General Public License
fiore@5 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
fiore@5 18 */
fiore@5 19
fiore@5 20 #pragma once
fiore@5 21 #include <jni.h>
fiore@5 22 #include <new>
fiore@5 23 #include <H3DUtil/Vec3d.h>
fiore@5 24
fiore@5 25 #include "utils.h"
fiore@5 26
fiore@5 27
fiore@5 28 /* this class uses the java haptic object lists to provide nodes *
fiore@5 29 * and edges to draw to the graphic and haptic managers */
fiore@5 30 class CollectionsManager {
fiore@5 31 public:
fiore@5 32 struct NodeData {
fiore@5 33 jdouble x;
fiore@5 34 jdouble y;
fiore@5 35 jint hapticId;
fiore@5 36 jint diagramId;
fiore@5 37
fiore@5 38 NodeData(){}
fiore@5 39 private :
fiore@5 40 NodeData(const NodeData& n){/* avoid mistakenly copy construction calls */}
fiore@5 41 };
fiore@5 42
fiore@5 43 struct EdgeData{
fiore@5 44 jdouble *x;
fiore@5 45 jdouble *y;
fiore@5 46 bool **adjMatrix;
fiore@5 47 jint hapticId;
fiore@5 48 jint diagramId;
fiore@5 49 jint stipplePattern;
fiore@5 50 jsize nodeStart;
fiore@5 51 jdouble attractPoint[2];
fiore@5 52 void setSize(unsigned int s){
fiore@5 53 size = s;
fiore@5 54 if(s > previousSize){
fiore@5 55 /* delete the old memory */
fiore@5 56 delete [] x;
fiore@5 57 delete [] y;
fiore@5 58 for(unsigned int i=0; i<previousSize; i++)
fiore@5 59 delete[] adjMatrix[i];
fiore@5 60 delete [] adjMatrix;
fiore@5 61 /* allocates a bigger one */
fiore@5 62 try{
fiore@5 63 x = new jdouble[size];
fiore@5 64 y = new jdouble[size];
fiore@5 65 adjMatrix = new bool* [size];
fiore@5 66 for(unsigned int i=0; i<size; i++){
fiore@5 67 adjMatrix[i] = new bool[size];
fiore@5 68 for(unsigned int j=0; j<size; j++)
fiore@5 69 adjMatrix[i][j] = false;
fiore@5 70 }
fiore@5 71 }catch(std::bad_alloc){
fiore@5 72 stopExecution("Could not allocate memory for the program.\nAborting...");
fiore@5 73 }
fiore@5 74 previousSize = size;
fiore@5 75 }
fiore@5 76 }
fiore@5 77
fiore@5 78 unsigned int getSize() const {
fiore@5 79 return size;
fiore@5 80 }
fiore@5 81
fiore@5 82 EdgeData(unsigned int s) : size(s), previousSize(s){
fiore@5 83 x = new jdouble[size];
fiore@5 84 y = new jdouble[size];
fiore@5 85 adjMatrix = new bool* [size];
fiore@5 86 for(unsigned int i=0; i<size; i++){
fiore@5 87 adjMatrix[i] = new bool[size];
fiore@5 88 for(unsigned int j=0; j<size; j++)
fiore@5 89 adjMatrix[i][j] = false;
fiore@5 90 }
fiore@5 91 }
fiore@5 92 ~EdgeData(){
fiore@5 93 delete [] x;
fiore@5 94 delete [] y;
fiore@5 95 for(unsigned int i=0; i<size; i++)
fiore@5 96 delete[] adjMatrix[i];
fiore@5 97 delete [] adjMatrix;
fiore@5 98 }
fiore@5 99 private :
fiore@5 100 unsigned int size;
fiore@5 101 unsigned int previousSize;
fiore@5 102 EdgeData(const EdgeData& e){ /* avoid mistakenly copy construction */}
fiore@5 103
fiore@5 104 };
fiore@5 105 private:
fiore@5 106 JNIEnv *env;
fiore@5 107 jobject *haptics;
fiore@5 108
fiore@5 109 jclass hapticClass;
fiore@5 110 jclass hapticNodeClass;
fiore@5 111 jclass hapticEdgeClass;
fiore@5 112 jclass listClass;
fiore@5 113 jclass bitsetClass;
fiore@5 114 jobject nodeList;
fiore@5 115 jobject edgeList;
fiore@5 116 jmethodID getMethodId;
fiore@5 117 jmethodID sizeMethodId;
fiore@5 118 jmethodID getBitMethodId;
fiore@5 119 jfieldID xFieldId;
fiore@5 120 jfieldID yFieldId;
fiore@5 121 jfieldID nodeHapticIdFieldId;
fiore@5 122 jfieldID edgeHapticIdFieldId;
fiore@5 123 jfieldID nodeDiagramIdFieldId;
fiore@5 124 jfieldID edgeDiagramIdFieldId;
fiore@5 125 jfieldID nodeListfieldId;
fiore@5 126 jfieldID stipplePatternfieldId;
fiore@5 127 jfieldID edgeListfieldId;
fiore@5 128 jfieldID edgeSizefieldId;
fiore@5 129 jfieldID edgeXsFieldId;
fiore@5 130 jfieldID edgeYsFieldId;
fiore@5 131 jfieldID edgeAdjMatrixFieldId;
fiore@5 132 jfieldID attractPointXFieldId;
fiore@5 133 jfieldID attractPointYFieldId;
fiore@5 134 jfieldID edgeNodeStartFieldId;
fiore@5 135
fiore@5 136
fiore@5 137 int screenHeight;
fiore@5 138 int screenWidth;
fiore@5 139 NodeData nd;
fiore@5 140 EdgeData ed;
fiore@5 141
fiore@5 142 void fillupNodeData(struct NodeData & nd, jobject & currentNode);
fiore@5 143 void fillupEdgeData(struct EdgeData & ed, jobject & currentEdge);
fiore@5 144 public:
fiore@5 145 CollectionsManager(JNIEnv *environment, jobject *obj) : env(environment), haptics(obj), ed(2){}
fiore@5 146 virtual ~CollectionsManager(void){}
fiore@5 147 const jint getNodesNum();
fiore@5 148 const jint getEdgesNum();
fiore@5 149 struct NodeData & getNodeData(const int i);
fiore@5 150 struct EdgeData & getEdgeData(const int i);
fiore@5 151 inline int getScreenHeight() const { return screenHeight;}
fiore@5 152 inline void setScreenHeight(const int sh) { screenHeight = sh; }
fiore@5 153 inline int getScreenWidth() const { return screenWidth;}
fiore@5 154 inline void setScreenWidth(const int sw) { screenWidth = sw; }
fiore@5 155 void init(void);
fiore@5 156 };