fiore@5: /* fiore@5: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool fiore@5: fiore@5: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) fiore@5: fiore@5: This program is free software: you can redistribute it and/or modify fiore@5: it under the terms of the GNU General Public License as published by fiore@5: the Free Software Foundation, either version 3 of the License, or fiore@5: (at your option) any later version. fiore@5: fiore@5: This program is distributed in the hope that it will be useful, fiore@5: but WITHOUT ANY WARRANTY; without even the implied warranty of fiore@5: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fiore@5: GNU General Public License for more details. fiore@5: fiore@5: You should have received a copy of the GNU General Public License fiore@5: along with this program. If not, see . fiore@5: */ fiore@5: #pragma once fiore@5: #include "CollectionsManager.h" fiore@5: #include fiore@5: #include fiore@5: fiore@5: #include fiore@5: #include fiore@5: #include fiore@5: #include fiore@5: fiore@5: #include fiore@5: #include fiore@5: #include fiore@5: fiore@5: fiore@5: fiore@5: class HapticManager fiore@5: { fiore@5: CollectionsManager *cm ; fiore@5: void (*executeCommand)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy); fiore@5: HAPI::AnyHapticsDevice *hd; fiore@5: /* The force effect in use. Contains 0 if there is no force effect in use. */ fiore@5: H3DUtil::AutoRef force_effect; fiore@5: /* the current set of haptic lines. It's used as argument when adding a constraint effect to the hapitc * fiore@5: * device and it's filled up with the edges of the current diagram through the collection manager */ fiore@5: vector< HAPI::Collision::LineSegment> line_set; fiore@5: vector point_set; fiore@5: map point_id_map; fiore@5: map line_id_map; fiore@5: /* in order not to utter continuosly the touched node/edge name, keep track of the node/edge that was * fiore@5: * last touched and avoid to utter its name unless the proxy touches another node/edge or goes far enough */ fiore@5: HAPI::Collision::Point* last_touched_point; fiore@5: HAPI::Collision::LineSegment* last_touched_line; fiore@5: HAPI::Vec3 proxy_pos; fiore@5: HAPI::HAPIInt32 pressed_button; fiore@5: fiore@5: enum {STICKY, LOOSE} magnetic_mode; fiore@5: bool magnetic_mode_changed; fiore@5: fiore@5: enum {START_DRAGGING, DRAGGING, RELEASED} pickup_mode; fiore@5: HAPI::Collision::Point *pickedup_point; fiore@5: HAPI::Collision::LineSegment *pickedup_line; fiore@5: HAPI::Vec3 pickup_line_pos; fiore@5: HAPI::Vec3 last_dragging_pos; fiore@5: fiore@5: int attract_to; fiore@5: enum {NO_ATTRACTION ,STOP_ATTRACTION, ACTIVE} attraction_mode; fiore@5: fiore@5: bool object_unselected; fiore@5: fiore@5: /* how bigger graphic coordinates are than haptic coordinates */ fiore@5: static const int GRAPHIC_SCALE; fiore@5: static const int SPRING_FORCE_FACTOR; fiore@5: static const int LINE_FORCE_FACTOR_LOOSE; fiore@5: static const int LINE_FORCE_FACTOR_STICKY; fiore@5: static const int POINT_FORCE_FACTOR; fiore@5: static const double POINT_COLLISION_THRESHOLD; fiore@5: static const double LINE_COLLISION_THRESHOLD; fiore@5: static const double DRAGGING_SOUND_THRESHOLD; fiore@5: fiore@5: /* commands sent to the java thread */ fiore@5: static const char MOVE_CMD; fiore@5: static const char PLAY_SOUND_CMD; fiore@5: static const char SPEAK_NAME_CMD; fiore@5: static const char PICKUP_CMD; fiore@5: static const char SPEAK_INFO_CMD; fiore@5: static const char SELECT_CMD; fiore@5: static const char UNSELECT_CMD; fiore@5: fiore@5: /* arguments for PLAY_SOUND_CMD */ fiore@5: static const int LOOSE_MODE_SOUND; fiore@5: static const int STICKY_MODE_SOUND; fiore@5: static const int DRAGGING_SOUND; fiore@5: fiore@5: static const HAPI::HAPIInt32 FRONT_BUTTON; fiore@5: static const HAPI::HAPIInt32 LEFT_BUTTON; fiore@5: static const HAPI::HAPIInt32 RIGHT_BUTTON; fiore@5: static const HAPI::HAPIInt32 REAR_BUTTON; fiore@5: static const HAPI::HAPIInt32 NO_BUTTON; fiore@5: public: fiore@5: HapticManager(CollectionsManager * cManager, void (*func)(const jchar cmd, const jint ID, const jdouble startx, const jdouble starty, const jdouble endx, const jdouble endy)); fiore@5: fiore@5: /* try and initialize the haptic device, return false if the initialization fails */ fiore@5: bool init(void); fiore@5: fiore@5: /* drawing routines (both graphically and haptically) */ fiore@5: void drawCursor(void); fiore@5: void drawDiagram(bool redrawHapticsScene,bool pickup, int attract_to); fiore@5: fiore@5: /* collisions routines: check if the proxy is touching a node or an edge */ fiore@5: bool checkNodeCollision(void); fiore@5: bool checkEdgeCollision(void); fiore@5: fiore@5: /* check if an unselection command must be issued. Commands cannot be issued in the drawDiagram * fiore@5: * as it might possibly result in a deadlock. Therefore in drawDiagram the inner flag variable * fiore@5: * object_unselected is set if necessary, and then when this method is called, the command is * fiore@5: * issued if the flad was set to true */ fiore@5: bool checkUnselection(void); fiore@5: fiore@5: /* check buttons routine */ fiore@5: bool checkButtons(void); fiore@5: fiore@5: /* routine that plays chain sound during motion if an object is being dragged */ fiore@5: bool checkMotion(); fiore@5: fiore@5: /* release the allocated resources */ fiore@5: void dispose(void); fiore@5: fiore@5: /* a null id value for Java nodes and edges. The id used for nodes and edges is * fiore@5: * the hashCode of the Java object, therefore a zero value will work for NO_ID */ fiore@5: static const int NO_ID; fiore@5: };