123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- /* This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
- * Copyright 2011 by the AToMPM team and licensed under the LGPL
- * See COPYING.lesser and README.md in the root of this project for full details
- */
- __canvasBehaviourStatechart = {
- '__STATE_IDLE' : 0,
- '__STATE_CANVAS_SELECTING' : 1,
- '__STATE_SOMETHING_SELECTED' : 2,
- '__STATE_DRAGGING_SELECTION' : 3,
- '__STATE_DRAWING_EDGE' : 4,
- '__STATE_EDITING_CONNECTION_PATHS' : 5,
- '__STATE_DRAGGING_CONNECTION_PATH_CTRL_POINT': 6,
- '__currentState' : undefined,
- '__entryActions':{
- 1:
- function(event)
- {
- GUIUtils.disableDock();
- __initCanvasSelectionOverlay(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event));
- },
- 3:
- function(event)
- {
- GUIUtils.disableDock();
- GeometryUtils.initSelectionTransformationPreviewOverlay(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event));
- },
- 4:
- function(event)
- {
- GUIUtils.disableDock();
- ConnectionUtils.initConnectionPath(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event),event.target);
- },
- 6:
- function(event)
- {
- GUIUtils.disableDock();
- }
- },
- '__exitActions' :{
- 1:
- function(event)
- {
- GUIUtils.enableDock();
- },
- 3:
- function(event)
- {
- GUIUtils.enableDock();
- },
- 4:
- function(event)
- {
- GUIUtils.enableDock();
- },
- 6:
- function(event)
- {
- GUIUtils.enableDock();
- }
- },
- /* transition to specified state */
- '__T' :
- function(s,event)
- {
- if( this.__currentState in this.__exitActions )
- this.__exitActions[this.__currentState](event);
-
- this.__currentState = s;
-
- if( s in this.__entryActions )
- this.__entryActions[s](event);
- },
- /* initialise the statechart */
- 'init':
- function()
- {
- this.__currentState = this.__STATE_IDLE;
- },
- /* handle an event... only discarded events are allowed to propagate to parent
- HTML element
- name: internal name of the event
- event: the javascript event */
- 'handleUserEvent':
- function(name,event)
- {
- if( this.__currentState == this.__STATE_IDLE )
- {
- if( name == __EVENT_RIGHT_RELEASE_CANVAS )
- DataUtils.create(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event));
-
- else if( name == __EVENT_LEFT_PRESS_CANVAS )
- this.__T(this.__STATE_CANVAS_SELECTING,event);
-
- else if( name == __EVENT_MIDDLE_RELEASE_ICON )
- {
- __select( event.target );
- WindowManagement.openDialog(_ENTITY_EDITOR);
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
-
- else if( name == __EVENT_SHIFT_MIDDLE_RELEASE_ICON )
- WindowManagement.openDialog(__SVG_TEXT_EDITOR, event.target);
-
- else if( name == __EVENT_LEFT_RELEASE_ICON )
- {
- __select( event.target );
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
- else if( name == __EVENT_SHIFT_LEFT_RELEASE_ICON )
- {
- __select( event.target, true );
- WindowManagement.openDialog(_ENTITY_EDITOR);
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
-
- else if( name == __EVENT_CODED_SELECTION )
- {
- __select(event);
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
-
- else if( name == __EVENT_RIGHT_PRESS_ICON )
- this.__T(this.__STATE_DRAWING_EDGE,event);
-
- else if( name == __EVENT_SHIFT_WHEEL_ICON )
- {
- if( event.wheelDelta > 0 )
- __iconToFront(event.target);
- else
- __iconToBack(event.target);
- }
-
- else
- return;
-
- if( event && event.stopPropagation )
- {
- event.stopPropagation();
- event.preventDefault();
- }
- }
-
-
- else if( this.__currentState == this.__STATE_CANVAS_SELECTING )
- {
- if( name == __EVENT_MOUSE_MOVE ){
- __updateCanvasSelectionOverlay(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event));
- }
-
- else if( name == __EVENT_LEFT_RELEASE_CANVAS ||
- name == __EVENT_LEFT_RELEASE_ICON )
- {
- if( ! __selectSelection() )
- this.__T(this.__STATE_IDLE,event);
- else
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
-
- else
- return;
-
- if( event && event.stopPropagation )
- {
- event.stopPropagation();
- event.preventDefault();
- }
- }
- else if( this.__currentState == this.__STATE_SOMETHING_SELECTED )
- {
- if( name == __EVENT_KEYUP_DEL )
- {
- DataUtils.del();
- __select();
- this.__T(this.__STATE_IDLE,event);
- }
-
- else if( name == __EVENT_KEYUP_ESC ||
- name == __EVENT_LEFT_PRESS_CANVAS ||
- name == __EVENT_LEFT_PRESS_ICON ||
- name == __EVENT_CODED_CANVAS_EDIT ||
- name == __EVENT_MIDDLE_RELEASE_CANVAS ||
- name == __EVENT_MIDDLE_RELEASE_ICON ||
- name == __EVENT_SHIFT_MIDDLE_RELEASE_ICON ||
- name == __EVENT_RIGHT_RELEASE_CANVAS ||
- name == __EVENT_RIGHT_RELEASE_ICON )
- {
- __select();
- this.__T(this.__STATE_IDLE,event);
- }
-
- else if( name == __EVENT_LEFT_PRESS_SELECTION )
- {
- if( ! GeometryUtils.areTransformationsAllowed() )
- console.warn('the selection dragging mode can only be activated if '+
- 'all of the ends of selected edges are also selected, '+
- 'and if the geometry controls are inactive');
- else
- this.__T(this.__STATE_DRAGGING_SELECTION,event);
- }
-
- else if( name == __EVENT_KEYUP_CTRL )
- {
- if( ! GeometryUtils.areTransformationsAllowed() )
- console.warn('the geometry controls can only be activated if all '+
- 'of the ends of selected edges are also selected, and'+
- 'if the geometry controls aren\'t already active');
- else
- GeometryUtils.showGeometryControlsOverlay();
- }
-
- else if( name == __EVENT_KEYUP_ALT )
- {
- GeometryUtils.hideGeometryControlsOverlay();
- GeometryUtils.hideTransformationPreviewOverlay();
- }
-
- else if( name == __EVENT_KEYUP_SHIFT &&
- __selectionContainsType(__EDGETYPE) )
- {
- ConnectionUtils.showConnectionPathEditingOverlay();
- __select();
- this.__T(this.__STATE_EDITING_CONNECTION_PATHS);
- }
- else if( name == __EVENT_KEYUP_INS ||
- name == __EVENT_KEYUP_COMMAND )
- {
- WindowManagement.openDialog(_ENTITY_EDITOR);
- }
-
- else if( name == __EVENT_CODED_SELECTION )
- {
- __select(event);
- }
- else if( name == __EVENT_KEYUP_TAB )
- {
- if( ! GeometryUtils.areTransformationsAllowed() )
- console.warn('selection snapping is only enabled if all of '+
- 'the ends of selected edges are also selected, '+
- 'and if the geometry controls are inactive');
- else
- GeometryUtils.snapSelectionToGrid();
- }
-
- else
- return;
-
- if( event && event.stopPropagation )
- {
- event.stopPropagation();
- event.preventDefault();
- }
- }
-
-
- else if( this.__currentState == this.__STATE_DRAGGING_SELECTION )
- {
- if( name == __EVENT_MOUSE_MOVE )
- GeometryUtils.previewSelectionTranslation(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event));
-
- else if( name == __EVENT_KEYUP_ESC )
- {
- GeometryUtils.hideTransformationPreviewOverlay();
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
-
- else if( name == __EVENT_LEFT_RELEASE_CANVAS ||
- name == __EVENT_LEFT_RELEASE_SELECTION )
- {
- GeometryUtils.transformSelection(__SELECTION_DRAG);
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
- else if( name == __EVENT_LEFT_RELEASE_ICON )
- {
- DataUtils.getInsertConnectionType(
- event.target,
- undefined,
- function(connectionType)
- {
- if( connectionType )
- GeometryUtils.transformSelection(
- __SELECTION_DRAG,
- {'dropTarget':event.target,
- 'connectionType':connectionType});
- else
- {
- console.warn('no containment relationship was created');
- GeometryUtils.transformSelection(__SELECTION_DRAG);
- }
- });
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
-
- else
- return;
-
- if( event && event.stopPropagation )
- {
- event.stopPropagation();
- event.preventDefault();
- }
- }
-
-
- else if( this.__currentState == this.__STATE_DRAWING_EDGE )
- {
- if( name == __EVENT_MOUSE_MOVE ){
- ConnectionUtils.updateConnectionSegment(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event));
- }
- else if( name == __EVENT_KEYUP_ESC ||
- name == __EVENT_RIGHT_RELEASE_CANVAS )
- {
- ConnectionUtils.hideConnectionPath();
- this.__T(this.__STATE_IDLE,event);
- }
- else if( name == __EVENT_LEFT_RELEASE_CANVAS ||
- name == __EVENT_LEFT_RELEASE_ICON ||
- name == __EVENT_KEYUP_CTRL )
- ConnectionUtils.addConnectionSegment();
-
- else if( name == __EVENT_MIDDLE_RELEASE_CANVAS ||
- name == __EVENT_MIDDLE_RELEASE_ICON ||
- name == __EVENT_KEYUP_ALT )
- ConnectionUtils.deleteConnectionSegment();
-
- else if( name == __EVENT_KEYUP_TAB )
- ConnectionUtils.snapConnectionSegment();
-
- else if( name == __EVENT_RIGHT_RELEASE_ICON )
- {
- if( ConnectionUtils.getConnectionPath().getTotalLength() <= 5 )
- console.warn('to avoid accidental path creations, paths must '+
- 'measure at least 5px');
- else
- DataUtils.connect(event.target);
- this.__T(this.__STATE_IDLE,event);
- }
-
- else
- return;
-
- if( event && event.stopPropagation )
- {
- event.stopPropagation();
- event.preventDefault();
- }
- }
- else if( this.__currentState == this.__STATE_EDITING_CONNECTION_PATHS )
- {
- if( name == __EVENT_KEYUP_ESC ||
- name == __EVENT_LEFT_RELEASE_CANVAS ||
- name == __EVENT_LEFT_RELEASE_ICON ||
- name == __EVENT_CODED_CANVAS_EDIT )
- {
- ConnectionUtils.hideConnectionPathEditingOverlay();
- this.__T(this.__STATE_IDLE,event);
- }
-
- else if( name == __EVENT_LEFT_PRESS_CTRL_POINT )
- {
- ConnectionUtils.initControlPointTranslation(event.target);
- this.__T(this.__STATE_DRAGGING_CONNECTION_PATH_CTRL_POINT,event);
- }
-
- else if( name == __EVENT_MIDDLE_RELEASE_CTRL_POINT )
- ConnectionUtils.deleteControlPoint(event.target);
-
- else if( name == __EVENT_RIGHT_RELEASE_CTRL_POINT ) {
- ConnectionUtils.addControlPoint(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event), event.target);
- }
- else if( name == __EVENT_KEYUP_TAB )
- ConnectionUtils.snapControlPoint();
-
- else if( name == __EVENT_CODED_SELECTION )
- {
- ConnectionUtils.hideConnectionPathEditingOverlay();
- __select(event);
- this.__T(this.__STATE_SOMETHING_SELECTED,event);
- }
-
- else
- return;
- if( event && event.stopPropagation )
- {
- event.stopPropagation();
- event.preventDefault();
- }
- }
- else if( this.__currentState == this.__STATE_DRAGGING_CONNECTION_PATH_CTRL_POINT )
- {
- if( name == __EVENT_MOUSE_MOVE ) {
- ConnectionUtils.previewControlPointTranslation(GUIUtils.convertToCanvasX(event), GUIUtils.convertToCanvasY(event));
- }
- else if( name == __EVENT_LEFT_RELEASE_CTRL_POINT )
- {
- ConnectionUtils.updateConnectionPath();
- this.__T(this.__STATE_EDITING_CONNECTION_PATHS,event);
- }
-
- else
- return;
-
- if( event && event.stopPropagation )
- {
- event.stopPropagation();
- event.preventDefault();
- }
- }
- }
- };
|