~tapaal-contributor/tapaal/sidepane-refactor-1886410

« back to all changes in this revision

Viewing changes to src/pipe/gui/graphicElements/ArcPath.java

merged in lp:~yrke/tapaal/cleanup-PNO-namingAndInterface refactoring animator and drawing and adding global net properties timed/game

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
import pipe.dataLayer.DataLayer;
16
16
import pipe.gui.Pipe;
17
 
import pipe.gui.Zoomer;
18
17
import pipe.gui.undo.AddArcPathPointEdit;
19
18
import dk.aau.cs.gui.undo.Command;
20
19
 
29
28
public class ArcPath implements Shape {
30
29
 
31
30
        private GeneralPath path = new GeneralPath();
32
 
        private List<ArcPathPoint> pathPoints = new ArrayList<ArcPathPoint>();
33
 
        private Arc myArc;
 
31
        private final List<ArcPathPoint> pathPoints = new ArrayList<ArcPathPoint>();
 
32
        private final Arc myArc;
34
33
        private boolean pointLock = false;
35
 
        private static Stroke proximityStroke = new BasicStroke(Pipe.ARC_PATH_PROXIMITY_WIDTH);
36
 
        private static Stroke stroke = new BasicStroke(Pipe.ARC_PATH_SELECTION_WIDTH);
 
34
        private static final Stroke proximityStroke = new BasicStroke(Pipe.ARC_PATH_PROXIMITY_WIDTH);
 
35
        private static final Stroke stroke = new BasicStroke(Pipe.ARC_PATH_SELECTION_WIDTH);
37
36
        private Shape shape, proximityShape;
38
37
        private int transitionAngle;
39
38
        private final static boolean showDebugCurvedControlPoints = false;
115
114
                //Calculate the arc mid-point for lable placement
116
115
                if (getEndIndex() < 2) {
117
116
                        midPoint.x = (((pathPoints.get(0)).getPoint().x + (pathPoints.get(1)).getPoint().x) * 0.5);
118
 
                        midPoint.y = (((pathPoints.get(0)).getPoint().y + (pathPoints
119
 
                                        .get(1)).getPoint().y) * 0.5);
 
117
                        midPoint.y = (((pathPoints.get(0)).getPoint().y + (pathPoints.get(1)).getPoint().y) * 0.5);
120
118
                } else {
121
119
                        double acc = 0;
122
120
                        double percent = 0;
134
132
 
135
133
                        ArcPathPoint previousPoint = pathPoints.get(c - 1);
136
134
                        midPoint.x = previousPoint.getPoint().x + ((currentPoint.getPoint().x - previousPoint.getPoint().x) * percent);
137
 
                        midPoint.y = previousPoint.getPoint().y
138
 
                                        + ((currentPoint.getPoint().y - previousPoint.getPoint().y) * percent);
 
135
                        midPoint.y = previousPoint.getPoint().y + ((currentPoint.getPoint().y - previousPoint.getPoint().y) * percent);
139
136
                }
140
137
 
141
138
                shape = stroke.createStrokedShape(this);
306
303
                } else if (source instanceof Transition && (pathPoints.get(1)).getPointType()) {
307
304
                        ArcPathPoint myPoint = pathPoints.get(1);
308
305
                        ArcPathPoint myLastPoint = pathPoints.get(0);
309
 
                        double distance = getMod(myPoint.getPoint(), myLastPoint.getPoint())
310
 
                                        / Pipe.ARC_CONTROL_POINT_CONSTANT;
311
 
                        myPoint.setControl1((myLastPoint.getPoint().x + Math
312
 
                                        .cos(anAngle)
313
 
                                        * distance), (myLastPoint.getPoint().y + Math
314
 
                                        .sin(anAngle)
315
 
                                        * distance));
 
306
                        double distance = getMod(myPoint.getPoint(), myLastPoint.getPoint()) / Pipe.ARC_CONTROL_POINT_CONSTANT;
 
307
                        myPoint.setControl1(
 
308
                            (myLastPoint.getPoint().x + Math.cos(anAngle) * distance),
 
309
                (myLastPoint.getPoint().y + Math.sin(anAngle) * distance)
 
310
            );
316
311
 
317
312
                        myPoint = pathPoints.get(getEndIndex());
318
313
                        myPoint.setControl2(getControlPoint(myPoint.getPoint(), myPoint.getControl1(), myPoint.getPoint(), myPoint.getControl1()));
319
314
                } else if (target != null && source instanceof Place && (pathPoints.get(getEndIndex())).getPointType()) {
320
315
                        ArcPathPoint myPoint = pathPoints.get(getEndIndex());
321
316
                        ArcPathPoint myLastPoint = pathPoints.get(getEndIndex() - 1);
322
 
            double distance = getMod(myPoint.getPoint(), myLastPoint.getPoint())
323
 
                                        / Pipe.ARC_CONTROL_POINT_CONSTANT;
324
 
                        myPoint.setControl2((myPoint.getPoint().x + Math
325
 
                                        .cos(anAngle)
326
 
                                        * distance), (myPoint.getPoint().y + Math
327
 
                                        .sin(anAngle)
328
 
                                        * distance));
 
317
            double distance = getMod(myPoint.getPoint(), myLastPoint.getPoint()) / Pipe.ARC_CONTROL_POINT_CONSTANT;
 
318
                        myPoint.setControl2(
 
319
                            (myPoint.getPoint().x + Math.cos(anAngle) * distance),
 
320
                (myPoint.getPoint().y + Math.sin(anAngle) * distance)
 
321
            );
329
322
 
330
323
                        myPoint = pathPoints.get(1);
331
324
                        myPoint.setControl1(getControlPoint(
334
327
            );
335
328
                }
336
329
        }
337
 
        
 
330
 
338
331
        public void addPoint(int index, double x, double y, boolean type) {
339
 
                pathPoints.add(index, new ArcPathPoint(x, y, type, this));
 
332
            var arcpath = new ArcPathPoint(x, y, type, this);
 
333
 
 
334
        if (myArc!=null) {
 
335
            arcpath.zoomUpdate(myArc.getZoom());
 
336
        }
 
337
                pathPoints.add(index, arcpath);
340
338
        }
341
339
 
342
340
        public void addPoint(double x, double y, boolean type) {
343
 
                pathPoints.add(new ArcPathPoint(x, y, type, this));
 
341
            var arcpath = new ArcPathPoint(x, y, type, this);
 
342
 
 
343
            //XXX: we set zoom here, it might be a prototype
 
344
        if (myArc!=null) {
 
345
            arcpath.zoomUpdate(myArc.getZoom());
 
346
        }
 
347
                pathPoints.add(arcpath);
344
348
        }
345
 
        
 
349
 
346
350
 
347
351
        public void addPoint() {
348
352
                pathPoints.add(new ArcPathPoint(this));
434
438
        public double getEndAngle() {
435
439
                if (getEndIndex() > 0) {
436
440
                        if (getArc().getTarget() instanceof Transition) {
437
 
                                return (pathPoints.get(getEndIndex())).getAngle(((pathPoints
438
 
                                                .get(getEndIndex()))).getControl2());
 
441
                                return (pathPoints.get(getEndIndex())).getAngle(((pathPoints.get(getEndIndex()))).getControl2());
439
442
                        } else {
440
 
                                return (pathPoints.get(getEndIndex())).getAngle(((pathPoints
441
 
                                                .get(getEndIndex()))).getControl1());
 
443
                                return (pathPoints.get(getEndIndex())).getAngle(((pathPoints.get(getEndIndex()))).getControl1());
442
444
                        }
443
445
                }
444
446
                return 0;
560
562
                        // Nadeem 21/06/2005
561
563
                        if (!model.getPNObjects().contains(pathPoint)) {
562
564
                                model.addPetriNetObject(pathPoint);
563
 
                                pathPoint.updatePointLocation();
564
565
                        }
565
566
                }
566
567
        }
611
612
                insertPoint(wantedpoint + 1, newPoint);
612
613
                createPath();
613
614
                myArc.updateArcPosition();
 
615
        showPoints();
614
616
 
615
617
                return new AddArcPathPointEdit(this.getArc(), newPoint, getArc().getGuiModel());
616
618
        }