/** * ************************************************************************* * * Do the * relocation */ private DialogAndInProcessCmd stepRelocateSource() { // // Go and find if we intersect anything. // List<Intersection.AugmentedIntersection> augs = appState_.getGenomePresentation().intersectItem(x, y, rcxT_, true, false); Intersection.AugmentedIntersection ai = (new IntersectionChooser(true, rcxT_)).selectionRanker(augs); Intersection inter = ((ai == null) || (ai.intersect == null)) ? null : ai.intersect; // // If we don't intersect anything, we need to bag it. // if (inter == null) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } Object sub = inter.getSubID(); if (sub == null) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } String id = inter.getObjectID(); Node node = rcxT_.getGenome().getNode(id); if (node == null) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } if (!(sub instanceof Intersection.PadVal)) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } List<Intersection.PadVal> pads = inter.getPadCand(); if (LinkSupport.changeLinkSource(appState_, intersect, inter, pads, id, rcxT_)) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.ACCEPT, this)); } else { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } }
/** * ************************************************************************* * * Do the * relocation */ private DialogAndInProcessCmd stepRelocateModuleSource() { String currentOverlay = rcxT_.oso.getCurrentOverlay(); // // Go and find if we intersect anything. // Intersection intersected = appState_ .getGenomePresentation() .intersectANetModuleElement( x, y, rcxT_, GenomePresentation.NetModuleIntersect.NET_MODULE_LINK_PAD); // // If we don't intersect anything, or the correct thing, we need to bag it. // if (intersected == null) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } String id = intersected.getObjectID(); NetOverlayOwner owner = rcxT_.getGenomeSource().getOverlayOwnerFromGenomeKey(rcxT_.getGenomeID()); NetworkOverlay novr = owner.getNetworkOverlay(currentOverlay); NetModule nm = novr.getModule(id); if (nm == null) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } NetModuleFree.IntersectionExtraInfo ei = (NetModuleFree.IntersectionExtraInfo) intersected.getSubID(); if (ei == null) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } if (ei.type != NetModuleFree.IntersectionExtraInfo.IS_PAD) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } // New point: Point2D padPt = (Point2D) ei.intersectPt.clone(); UiUtil.forceToGrid(padPt, UiUtil.GRID_SIZE); Vector2D toSide = ei.padNorm.scaled(-1.0); String treeID = intersect.getObjectID(); NetModuleLinkageProperties nmlp = rcxT_ .getLayout() .getNetOverlayProperties(currentOverlay) .getNetModuleLinkagePropertiesFromTreeID(treeID); LinkSegmentID[] linkIDs = intersect.segmentIDsFromIntersect(); Set<String> throughSeg = nmlp.resolveLinkagesThroughSegment(linkIDs[0]); int totalLinks = nmlp.getLinkageList().size(); if (throughSeg.size() != totalLinks) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } String myLinkId = throughSeg.iterator().next(); NetModuleLinkage myLink = novr.getLinkage(myLinkId); if (!myLink.getSource().equals(id)) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } // // Pretty lax about links in and out of modules. Only restriction is that // link cannot end on the same pad as it starts (avoids zero-length links!) // Iterator<String> tsit = throughSeg.iterator(); while (tsit.hasNext()) { String linkID = tsit.next(); if (!novr.linkIsFeedback(linkID)) { continue; } Point2D targPt = nmlp.getTargetEnd(linkID, 0.0); if (padPt.equals(targPt)) { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } } // // Undo/Redo support // UndoSupport support = new UndoSupport(appState_, "undo.changeModuleLinkSource"); // // We reject unless the target we are intersecting matches the // link we are trying to relocate. // Layout.PropChange lpc = rcxT_.getLayout().changeNetModuleSource(currentOverlay, treeID, padPt, toSide, rcxT_); if (lpc != null) { PropChangeCmd mov = new PropChangeCmd(appState_, rcxT_, lpc); support.addEdit(mov); support.addEvent( new LayoutChangeEvent(rcxT_.getLayoutID(), LayoutChangeEvent.UNSPECIFIED_CHANGE)); support.finish(); return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.ACCEPT, this)); } else { return (new DialogAndInProcessCmd(ServerControlFlowHarness.ClickResult.REJECT, this)); } }