mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-05 16:51:35 +00:00
Initial implementation
This commit is contained in:
parent
a6dd971580
commit
b93490fbd2
@ -55,6 +55,8 @@ import { RectangleElementFactory } from './helpers/drawings-factory/rectangle-el
|
|||||||
import { LineElementFactory } from './helpers/drawings-factory/line-element-factory';
|
import { LineElementFactory } from './helpers/drawings-factory/line-element-factory';
|
||||||
import { TextEditorComponent } from './components/text-editor/text-editor.component';
|
import { TextEditorComponent } from './components/text-editor/text-editor.component';
|
||||||
import { DrawingAddingComponent } from './components/drawing-adding/drawing-adding.component';
|
import { DrawingAddingComponent } from './components/drawing-adding/drawing-adding.component';
|
||||||
|
import { MovingModeComponent } from './components/moving-mode/moving-mode.component';
|
||||||
|
import { MovingEventSource } from './events/moving-event-source';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [CommonModule, MatMenuModule, MatIconModule],
|
imports: [CommonModule, MatMenuModule, MatIconModule],
|
||||||
@ -67,7 +69,8 @@ import { DrawingAddingComponent } from './components/drawing-adding/drawing-addi
|
|||||||
...ANGULAR_MAP_DECLARATIONS,
|
...ANGULAR_MAP_DECLARATIONS,
|
||||||
SelectionControlComponent,
|
SelectionControlComponent,
|
||||||
SelectionSelectComponent,
|
SelectionSelectComponent,
|
||||||
DraggableSelectionComponent
|
DraggableSelectionComponent,
|
||||||
|
MovingModeComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
CssFixer,
|
CssFixer,
|
||||||
@ -87,6 +90,7 @@ import { DrawingAddingComponent } from './components/drawing-adding/drawing-addi
|
|||||||
DrawingsEventSource,
|
DrawingsEventSource,
|
||||||
NodesEventSource,
|
NodesEventSource,
|
||||||
LinksEventSource,
|
LinksEventSource,
|
||||||
|
MovingEventSource,
|
||||||
MapDrawingToSvgConverter,
|
MapDrawingToSvgConverter,
|
||||||
DrawingToMapDrawingConverter,
|
DrawingToMapDrawingConverter,
|
||||||
LabelToMapLabelConverter,
|
LabelToMapLabelConverter,
|
||||||
|
@ -8,3 +8,4 @@
|
|||||||
<app-selection-select></app-selection-select>
|
<app-selection-select></app-selection-select>
|
||||||
<app-text-editor #textEditor [svg]="svg"></app-text-editor>
|
<app-text-editor #textEditor [svg]="svg"></app-text-editor>
|
||||||
<app-draggable-selection [svg]="svg"></app-draggable-selection>
|
<app-draggable-selection [svg]="svg"></app-draggable-selection>
|
||||||
|
<app-moving-mode [svg]="svg"></app-moving-mode>
|
||||||
|
Before Width: | Height: | Size: 472 B After Width: | Height: | Size: 520 B |
@ -121,7 +121,7 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
|
|
||||||
this.subscriptions.push(
|
this.subscriptions.push(
|
||||||
this.toolsService.isMovingToolActivated.subscribe((value: boolean) => {
|
this.toolsService.isMovingToolActivated.subscribe((value: boolean) => {
|
||||||
this.movingToolWidget.setEnabled(value);
|
//this.movingToolWidget.setEnabled(value);
|
||||||
this.mapChangeDetectorRef.detectChanges();
|
this.mapChangeDetectorRef.detectChanges();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,105 @@
|
|||||||
|
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
|
||||||
|
import { Context } from '../../models/context';
|
||||||
|
import { MovingEventSource } from '../../events/moving-event-source';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { select } from 'd3-selection';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-moving-mode',
|
||||||
|
templateUrl: './moving-mode.component.html',
|
||||||
|
styleUrls: ['./moving-mode.component.scss']
|
||||||
|
})
|
||||||
|
export class MovingModeComponent implements OnInit, OnDestroy {
|
||||||
|
@Input('svg') svg: SVGSVGElement;
|
||||||
|
|
||||||
|
private scrollListener: Function;
|
||||||
|
private mouseupListener: Function;
|
||||||
|
private mousedownListener: Function;
|
||||||
|
private mousemoveListener: Function;
|
||||||
|
private movingModeState: Subscription;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private context: Context,
|
||||||
|
private movingEventSource: MovingEventSource
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.movingModeState = this.movingEventSource.movingModeState.subscribe((event: boolean) => {
|
||||||
|
event ? this.activate() : this.deactivate();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
activate() {
|
||||||
|
this.addMoveListener();
|
||||||
|
this.addZoomListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
addMoveListener() {
|
||||||
|
this.mousemoveListener = (event: MouseEvent) => {
|
||||||
|
const view = select(this.svg);
|
||||||
|
const canvas = view.selectAll<SVGGElement, Context>('g.canvas').data([this.context]);
|
||||||
|
const canvasEnter = canvas.enter().append<SVGGElement>('g').attr('class', 'canvas');
|
||||||
|
|
||||||
|
canvas.merge(canvasEnter).attr('transform', () => {
|
||||||
|
this.context.transformation.x = this.context.transformation.x + event.movementX;
|
||||||
|
this.context.transformation.y = this.context.transformation.y + event.movementY;
|
||||||
|
|
||||||
|
const xTrans = this.context.getZeroZeroTransformationPoint().x + this.context.transformation.x;
|
||||||
|
const yTrans = this.context.getZeroZeroTransformationPoint().y + this.context.transformation.y;
|
||||||
|
const kTrans = this.context.transformation.k;
|
||||||
|
|
||||||
|
return `translate(${xTrans}, ${yTrans}) scale(${kTrans})`;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
this.mousedownListener = (event: MouseEvent) => {
|
||||||
|
this.mouseupListener = (event: MouseEvent) => {
|
||||||
|
this.removelisteners();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.svg.addEventListener('mouseup', this.mouseupListener as EventListenerOrEventListenerObject);
|
||||||
|
this.svg.addEventListener('mousemove', this.mousemoveListener as EventListenerOrEventListenerObject);
|
||||||
|
};
|
||||||
|
this.svg.addEventListener('mousedown', this.mousedownListener as EventListenerOrEventListenerObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
addZoomListener() {
|
||||||
|
this.scrollListener = (event: WheelEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
let zoom = event.deltaY;
|
||||||
|
zoom = event.deltaMode === 0 ? zoom/100 : zoom/3;
|
||||||
|
|
||||||
|
const view = select(this.svg);
|
||||||
|
const canvas = view.selectAll<SVGGElement, Context>('g.canvas').data([this.context]);
|
||||||
|
const canvasEnter = canvas.enter().append<SVGGElement>('g').attr('class', 'canvas');
|
||||||
|
|
||||||
|
canvas.merge(canvasEnter).attr('transform', () => {
|
||||||
|
this.context.transformation.k = this.context.transformation.k - zoom/10;
|
||||||
|
|
||||||
|
const xTrans = this.context.getZeroZeroTransformationPoint().x + this.context.transformation.x;
|
||||||
|
const yTrans = this.context.getZeroZeroTransformationPoint().y + this.context.transformation.y;
|
||||||
|
const kTrans = this.context.transformation.k;
|
||||||
|
|
||||||
|
return `translate(${xTrans}, ${yTrans}) scale(${kTrans})`;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
document.addEventListener('wheel', this.scrollListener as EventListenerOrEventListenerObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
removelisteners() {
|
||||||
|
this.svg.removeEventListener('mouseup', this.mouseupListener as EventListenerOrEventListenerObject);
|
||||||
|
this.svg.removeEventListener('mousemove', this.mousemoveListener as EventListenerOrEventListenerObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
deactivate() {
|
||||||
|
this.svg.removeEventListener('mouseup', this.mouseupListener as EventListenerOrEventListenerObject);
|
||||||
|
this.svg.removeEventListener('mousedown', this.mousedownListener as EventListenerOrEventListenerObject);
|
||||||
|
this.svg.removeEventListener('mousemove', this.mousemoveListener as EventListenerOrEventListenerObject);
|
||||||
|
document.removeEventListener('wheel', this.scrollListener as EventListenerOrEventListenerObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.movingModeState.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
6
src/app/cartography/events/moving-event-source.ts
Normal file
6
src/app/cartography/events/moving-event-source.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Injectable, EventEmitter } from "@angular/core";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class MovingEventSource {
|
||||||
|
public movingModeState = new EventEmitter<boolean>();
|
||||||
|
}
|
@ -42,6 +42,7 @@ import { MapLabelToLabelConverter } from '../../cartography/converters/map/map-l
|
|||||||
import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProject.service';
|
import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProject.service';
|
||||||
import { MapLink } from '../../cartography/models/map/map-link';
|
import { MapLink } from '../../cartography/models/map/map-link';
|
||||||
import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter';
|
import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter';
|
||||||
|
import { MovingEventSource } from '../../cartography/events/moving-event-source';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -106,7 +107,8 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
private toolsService: ToolsService,
|
private toolsService: ToolsService,
|
||||||
private selectionManager: SelectionManager,
|
private selectionManager: SelectionManager,
|
||||||
private selectionTool: SelectionTool,
|
private selectionTool: SelectionTool,
|
||||||
private recentlyOpenedProjectService: RecentlyOpenedProjectService
|
private recentlyOpenedProjectService: RecentlyOpenedProjectService,
|
||||||
|
private movingEventSource: MovingEventSource
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -292,7 +294,9 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
public toggleMovingMode() {
|
public toggleMovingMode() {
|
||||||
this.tools.moving = !this.tools.moving;
|
this.tools.moving = !this.tools.moving;
|
||||||
this.toolsService.movingToolActivation(this.tools.moving);
|
this.movingEventSource.movingModeState.emit(this.tools.moving);
|
||||||
|
//this.toolsService.movingToolActivation(this.tools.moving);
|
||||||
|
|
||||||
if (!this.readonly) {
|
if (!this.readonly) {
|
||||||
this.tools.selection = !this.tools.moving;
|
this.tools.selection = !this.tools.moving;
|
||||||
this.toolsService.selectionToolActivation(this.tools.selection);
|
this.toolsService.selectionToolActivation(this.tools.selection);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user