Example #1
0
        /// <summary>
        /// Sets the active item; used by UI components.
        /// The active is used as insersion point where paste and drag and drop operations
        /// insert new objects into the UI data.</summary>
        /// <param name="item">Active item</param>
        public void SetActiveItem(object item)
        {
            m_activeItem = null;
            DomNode node = Adapters.As <DomNode>(item);

            while (node != null)
            {
                if (node.Is <GameObjectFolder>() || node.Is <GameObjectGroup>())
                {
                    m_activeItem = node;
                    break;
                }
                node = node.Parent;
            }
        }
        public static GameObjectReference Create(DomNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (!node.Is <IGameObject>())
            {
                throw new ArgumentException(node.Type.Name + " is not derived from " +
                                            Schema.gameObjectType.Type.Name);
            }
            DomNode      rootNode = node.GetRoot();
            GameDocument gameDoc  = rootNode.As <GameDocument>();

            if (gameDoc == null)
            {
                throw new ArgumentException("nod must belong to a document.");
            }


            // create game object reference.
            DomNode             refNode = new DomNode(Schema.gameObjectReferenceType.Type);
            GameObjectReference gobRef  = refNode.As <GameObjectReference>();

            // Create Uri
            Uri ur = new Uri(gameDoc.Uri + "#" + node.GetId());

            refNode.SetAttribute(Schema.gameObjectReferenceType.refAttribute, ur);
            gobRef.m_target = node;
            return(gobRef);
        }
Example #3
0
        /// <summary>
        /// Gets whether the target can be demoted from reference instances to copy instances.
        /// Items can be demoted when the active context is CircuitEditingContext and
        /// all the items are selected references.</summary>
        /// <param name="items">Items to demote</param>
        /// <returns>True iff the target can be demoted</returns>
        public override bool CanDemoteToCopyInstance(IEnumerable <object> items)
        {
            var circuitEditingContext = ContextRegistry.GetActiveContext <CircuitEditingContext>();

            if (circuitEditingContext != null && items.Any())
            {
                DomNode parent = null;
                foreach (var item in items)
                {
                    bool validCandiate = circuitEditingContext.Selection.Contains(item) &&
                                         (item.Is <GroupInstance>() || item.Is <ModuleInstance>());
                    if (!validCandiate)
                    {
                        return(false);
                    }

                    var currentParent = item.Cast <DomNode>().Parent;
                    if (parent == null)
                    {
                        parent = currentParent;
                    }
                    else if (parent != currentParent) // items limit to same parent
                    {
                        return(false);
                    }
                }
                return(parent.Is <ICircuitContainer>());
            }
            return(false);
        }
Example #4
0
        private bool IsContained(DomNode element, DomNode container)
        {
            if (container.Is <Circuit>())
            {
                return(true);
            }

            if (m_moveElementBehavior == MoveElementBehavior.MoveConstrainToCursorContainment‎)
            {
                // since container is the drop target, the cursor must be over the container when CanMove() is called
                return(true);
            }
            else if (m_moveElementBehavior == MoveElementBehavior.MoveConstrainToContainerBounds)
            {
                AdaptableControl control = m_viewingContext.Cast <AdaptableControl>();

                var offset = GetRelativeOffset(element.Parent.Cast <ICircuitContainer>(), container.Cast <ICircuitContainer>());

                // get bound in local space
                var elemLocalBound      = GetLocalBound(control, element.Cast <Element>());
                var containerLocalBound = GetLocalBound(control, container.Cast <Element>());

                elemLocalBound.Offset(offset);

                containerLocalBound.Location = new PointF(0, GetTitleHeight(control));
                containerLocalBound.Height  -= GetLabelHeight(control);// exclude bottom label area

                elemLocalBound.Offset(GetSubContentOffset(control));

                return(containerLocalBound.Contains(elemLocalBound));
            }
            return(false);
        }
Example #5
0
 private void RemoveNode(DomNode node)
 {
     if (node.Is <Group>())
     {
         node.Cast <Group>().Changed -= GroupChanged;
     }
 }
Example #6
0
 private void AddNode(DomNode node)
 {
     if (node.Is <Group>())
     {
         node.Cast <Group>().Changed += GroupChanged;
     }
 }
Example #7
0
        /// <summary>
        /// Tests if the gameobjects can be grouped.
        /// The gameobjects can be grouped if there are more than one
        /// and they belong to the same level.</summary>
        public bool CanGroup(IEnumerable <IGameObject> gobs)
        {
            // can group if there are more than one gob and they all belong to same level.
            DomNode root1     = null;
            int     gobcount  = 0;
            bool    sameLevel = true;

            foreach (IGameObject gob in gobs)
            {
                DomNode root = gob.As <DomNode>().GetRoot();
                if (!root.Is <IGame>())
                {
                    sameLevel = false;
                    break;
                }
                if (root1 == null)
                {
                    root1 = root;
                }

                if (root1 != root)
                {
                    sameLevel = false;
                    break;
                }
                gobcount++;
            }

            return(sameLevel && gobcount > 1);
        }
Example #8
0
        /// <summary>
        /// Find first item in a hierarchy using a predicate
        /// </summary>
        /// <typeparam name="T">Type to convert to</typeparam>
        /// <param name="domRootNode">Root item to look in</param>
        /// <param name="predicate">Predicate to use</param>
        /// <returns>Found item or null if not found</returns>
        public static T FindFirstInWhere <T>(DomNode domRootNode, Predicate <T> predicate) where T : class
        {
            if (domRootNode == null)
            {
                return(null);
            }

            if (predicate == null)
            {
                return(null);
            }

            if (domRootNode.Is <T>())
            {
                var converted = domRootNode.As <T>();
                if (predicate(converted))
                {
                    return(converted);
                }
            }

            foreach (var domNode in domRootNode.Children)
            {
                var result = FindFirstInWhere(domNode, predicate);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Example #9
0
        private static bool IsCircuitItem(DomNode child, DomNode parent)
        {
            if (parent == null)
            {
                return(false);
            }

            while (parent != null &&
                   parent.Is <LayerFolder>())
            {
                parent = parent.Parent;
            }

            return
                (child.Is <Group>() || parent.Is <Circuit>() || parent.Is <Group>());
        }
Example #10
0
        public static GameObjectReference Create(DomNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (!node.Is <IGameObject>())
            {
                throw new ArgumentException(node.Type.Name + " is not derived from " +
                                            Schema.gameObjectType.Type.Name);
            }

            GameDocument gameDoc = node.GetRoot().As <GameDocument>();

            if (gameDoc == null)
            {
                throw new ArgumentException("node must belong to a document.");
            }

            // create game object reference.
            DomNode             refNode = new DomNode(Schema.gameObjectReferenceType.Type);
            GameObjectReference gobRef  = refNode.As <GameObjectReference>();

            gobRef.SetTarget(node);
            gobRef.UpdateUri();
            return(gobRef);
        }
        protected override void OnNodeSet()
        {
            base.OnNodeSet();

            // Only adapt to ICurve.
            if (!DomNode.Is <ICurve>())
            {
                throw new InvalidOperationException("This adapter can only attach to instance of type that implements ICurve");
            }

            DomNode.ChildInserting += (sender, e) =>
            {
                var cp = e.Child.As <IControlPoint>();
                if (cp != null)
                {
                    // check curve limit.
                    var curve = DomNode.Cast <ICurve>();
                    if (cp.X < curve.MinX ||
                        cp.X > curve.MaxX ||
                        cp.Y < curve.MinY ||
                        cp.Y > curve.MaxY)
                    {
                        throw new InvalidTransactionException("Cannot add control-point outside curve limits".Localize());
                    }
                }
            };

            DomNode.AttributeChanged += (sender, e) =>
            {
                try
                {
                    // prevent re-entry
                    if (m_validating)
                    {
                        return;
                    }
                    m_validating = true;

                    var pt    = e.DomNode.As <IControlPoint>();
                    var curve = pt == null ? null : pt.Parent;
                    if (curve != null)
                    {
                        // keep x and y within curve limits.
                        if (e.AttributeInfo.Equivalent(UISchema.controlPointType.xAttribute))
                        {
                            pt.X = MathUtil.Clamp((float)e.NewValue, curve.MinX, curve.MaxX);
                        }
                        else if (e.AttributeInfo.Equivalent(UISchema.controlPointType.yAttribute))
                        {
                            pt.Y = MathUtil.Clamp((float)e.NewValue, curve.MinY, curve.MaxY);
                        }
                    }
                }
                finally
                {
                    m_validating = false;
                }
            };
        }
Example #12
0
        /// <summary>
        /// Constructs descriptive name of circuit item. Debugging Helper method.</summary>
        /// <param name="domNode">DomNode of circuit item</param>
        /// <returns>Descriptive name of circuit item</returns>
        static public string GetDomNodeName(DomNode domNode)
        {
            string result = string.Empty;

            if (domNode.Is <Element>())
            {
                result = domNode.Cast <Element>().Name;
            }
            else if (domNode.Is <GroupPin>())
            {
                result = "Group Pin : " + domNode.Cast <GroupPin>().Name;
            }
            else if (domNode.Is <Wire>())
            {
                var connection = domNode.Cast <Wire>();
                int inputPinIndex, outputPinIndex;
                // during undo/redo, the pin index may temporarily out of range, need to check index before call OutputPin|InputPin
                if (connection.IsValid(out inputPinIndex, out outputPinIndex))
                {
                    result = "Edge from " + connection.OutputElement.Name + "[" + connection.OutputPin.Name + "]" +
                             " to " + connection.InputElement.Name + "[" + connection.InputPin.Name + "]";
                }
                else
                {
                    result = "Edge from " + connection.OutputElement.Name + "[" + outputPinIndex + "]" +
                             " to " + connection.InputElement.Name + "[" + inputPinIndex + "]";
                }
            }
            else if (domNode.Is <Circuit>())
            {
                var doc = domNode.As <IDocument>();
                if (doc != null && doc.Uri != null)
                {
                    result = "Circuit " + Path.GetFileNameWithoutExtension(doc.Uri.LocalPath);
                }
                else
                {
                    result = "Circuit " + domNode.GetId();
                }
            }
            if (result == string.Empty)
            {
                result = domNode.GetId() ?? domNode.ToString();
            }
            return(result);
        }
Example #13
0
        /// <summary>
        /// Gets item's display information</summary>
        /// <param name="item">Item being displayed</param>
        /// <param name="info">Item info, to fill out</param>
        public void GetInfo(object item, ItemInfo info)
        {
            DomNode node = item as DomNode;

            if (node != null)
            {
                if (node.Type == UISchema.UIRefType.Type)
                {
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefImage);
                    string   label    = string.Empty;
                    UIRef    uiRef    = node.As <UIRef>();
                    UIObject uiTarget = uiRef.UIObject;
                    if (uiTarget != null)
                    {
                        label = uiTarget.Name;
                    }

                    info.Label = "[" + label + "]";
                }
                else if (node.Is <Curve>())
                {
                    Curve cv = node.Cast <Curve>();
                    info.Label      = string.IsNullOrWhiteSpace(cv.DisplayName) ? cv.Name : cv.DisplayName;
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.CurveImage);
                }
                else
                {
                    NodeTypePaletteItem paletteItem = node.Type.GetTag <NodeTypePaletteItem>();
                    if (paletteItem != null)
                    {
                        info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName);
                    }

                    info.Label = node.GetId();
                }

                info.IsLeaf = !GetChildren(item).Any();
            }
            else
            {
                EmptyRef emptyRef = item as EmptyRef;
                if (emptyRef != null)
                {
                    info.Label      = "Ref";
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefEmptyImage);
                    info.IsLeaf     = true;
                }
            }

            if (string.IsNullOrEmpty(info.Label))
            {
                throw new ArgumentException("info.lable");
            }
        }
Example #14
0
 protected override void WriteChildElementsRecursive(DomNode node, XmlWriter writer)
 {
     // Filter out external template file references that should not be in-lined
     if (node.Is<TemplateFolder>())
     {
         var pathUri = node.GetAttribute(Schema.templateFolderType.referenceFileAttribute) as Uri;
         if (pathUri != null)
             return;
     }
     base.WriteChildElementsRecursive(node, writer);
 }
Example #15
0
 protected override void WriteChildElementsRecursive(DomNode node, XmlWriter writer)
 {
     // Filter out external template file references that should not be in-lined
     if (node.Is<TemplateFolder>())
     {
         var pathUri = node.GetAttribute(Schema.templateFolderType.referenceFileAttribute) as Uri;
         if (pathUri != null)
             return;
     }
     base.WriteChildElementsRecursive(node, writer);
 }
Example #16
0
        /// <summary>
        /// Gets the bounding rectangle of all circuit items in client coordinates</summary>
        /// <returns>Bounding rectangle of all circuit items in client coordinates</returns>
        public Rectangle GetBounds()
        {
            if (m_graph == null)
            {
                return(Rectangle.Empty);
            }
            IEnumerable <object> items = m_graph.Nodes;
            var annoDiagram            = m_graph.As <IAnnotatedDiagram>();

            if (annoDiagram != null)
            {
                items = items.Concat(annoDiagram.Annotations);
            }
            Rectangle bounds = GetBounds(items);


            if (DomNode.Is <Group>())
            {
                // include group pins y range
                var group = DomNode.Cast <Group>();

                int yMin = int.MaxValue;
                int yMax = int.MinValue;

                foreach (var pin in group.InputGroupPins.Concat(group.OutputGroupPins))
                {
                    var grpPin = pin.Cast <GroupPin>();
                    if (grpPin.Bounds.Y < yMin)
                    {
                        yMin = grpPin.Bounds.Y;
                    }
                    if (grpPin.Bounds.Y > yMax)
                    {
                        yMax = grpPin.Bounds.Y;
                    }
                }

                // transform y range to client space
                if (yMin != int.MaxValue && yMax != int.MinValue)
                {
                    var transformAdapter = m_control.Cast <ITransformAdapter>();
                    var minPt            = Matrix3x2F.TransformPoint(transformAdapter.Transform, new PointF(0, yMin));
                    var maxPt            = Matrix3x2F.TransformPoint(transformAdapter.Transform, new PointF(0, yMax));

                    yMin = (int)minPt.Y;
                    yMax = (int)maxPt.Y;
                    int width  = bounds.Width;
                    int height = yMax - yMin + 1;
                    bounds = Rectangle.Union(bounds, new Rectangle(bounds.X, yMin, width, height));
                }
            }
            return(bounds);
        }
Example #17
0
            private static void GatherNodeTypes(DomNode domNode, ICollection <SledProjectFilesFolderType> lstFolders)
            {
                if (domNode.Is <SledProjectFilesFolderType>())
                {
                    lstFolders.Add(domNode.As <SledProjectFilesFolderType>());
                }

                foreach (var child in domNode.Children)
                {
                    GatherNodeTypes(child, lstFolders);
                }
            }
Example #18
0
            private static void GatherNodeTypes(DomNode tree, IDictionary <Guid, SledProjectFilesFileType> dictNodes)
            {
                if (tree.Is <SledProjectFilesFileType>())
                {
                    var projFile = tree.As <SledProjectFilesFileType>();
                    if (!dictNodes.ContainsKey(projFile.Guid))
                    {
                        dictNodes.Add(projFile.Guid, projFile);
                    }
                }

                foreach (var child in tree.Children)
                {
                    GatherNodeTypes(child, dictNodes);
                }
            }
Example #19
0
        /// <summary>
        /// Recursively gather type T convertible objects from a specific
        /// root DomNode and its children
        /// </summary>
        /// <typeparam name="T">Type to convert to</typeparam>
        /// <param name="domRootNode">Root DomNode</param>
        /// <param name="lstObjects">List of objects</param>
        public static void GatherAllAs <T>(DomNode domRootNode, List <T> lstObjects) where T : class
        {
            if (domRootNode == null)
            {
                return;
            }

            if (domRootNode.Is <T>())
            {
                lstObjects.Add(domRootNode.As <T>());
            }

            foreach (var domNode in domRootNode.Children)
            {
                GatherAllAs(domNode, lstObjects);
            }
        }
Example #20
0
 private static bool IsLayerItem(DomNode node)
 {
     return node.Is<ILayer>() || node.Is<IReference<IGameObject>>();
 }
Example #21
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();
            control.SuspendLayout();
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();
            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale = new PointF(0.25f, 0.25f);
            transformAdapter.MaxScale = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);
            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();
            ((ILayoutConstraint)canvasAdapter).Enabled = false; //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();
            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

            var d2dRectangleDragSelector = new D2dRectangleDragSelector();
            var d2dRectangleDragRenderer = new D2dRectangleDragRenderer(d2dRectangleDragSelector);

            if (circuitNode.Is<Circuit>())
            {
                var circuitAdapter = new D2dGraphAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, transformAdapter);

                // The "AllFirst" policy will try to draw edges (wires) before nodes, as much as possible.
                //circuitAdapter.EdgeRenderPolicy = D2dGraphAdapter<Module, Connection, ICircuitPin>.DrawEdgePolicy.AllFirst;
                
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    d2dRectangleDragSelector, //Needs to be before annotationAdaptor, so that drag-and-selecting text works.
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor, //Needs to be before circuitAdapter so that comments appear under elements.
                    circuitAdapter,
                    circuitModuleEditAdapter, //lets user move circuit elements on canvas
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    d2dRectangleDragRenderer,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                    );
            }
            else if (circuitNode.Is<Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer,
                                                                                      transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = m_subGraphRenderer.GetPinOffset;

                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                  hoverAdapter,
                  scrollbarAdapter,
                  autoTranslateAdapter,
                  d2dRectangleDragSelector,
                  transformAdapter,
                  viewingAdapter,
                  canvasAdapter,
                  mouseTransformManipulator,
                  mouseWheelManipulator,
                  new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                  new D2dGridAdapter(),
                  annotationAdaptor,
                  circuitAdapter,
                  circuitModuleEditAdapter,
                  circuitConnectionEditAdapter,
                  new LabelEditAdapter(),
                  groupPinEditor,
                  d2dRectangleDragRenderer,
                  new SelectionAdapter(),
                  new DragDropAdapter(m_statusService),
                  new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                  );
            }
            else throw new NotImplementedException(
               "graph node type is not supported!");

            control.ResumeLayout();

            control.DoubleClick += control_DoubleClick;
            control.MouseDown += control_MouseDown;
            return control;
        }
Example #22
0
        private void ShowBreakpointConditionForm(DomNode domNode)
        {
            if (domNode == null)
                return;

            if (!domNode.Is<SledProjectFilesBreakpointType>())
                return;

            var bp =
                domNode.As<SledProjectFilesBreakpointType>();

            if (bp == null)
                return;

            ShowBreakpointConditionFormInternal(bp);
        }
Example #23
0
 bool IReference <DomNode> .CanReference(DomNode item)
 {
     return(item.Is <Element>());
 }
Example #24
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();
            control.SuspendLayout();             
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();
            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale = new PointF(0.25f, 0.25f);
            transformAdapter.MaxScale = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);
            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();
            ((ILayoutConstraint) canvasAdapter).Enabled = false; //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();
            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

            if (circuitNode.Is<Circuit>())
            {
                var circuitAdapter = new D2dGraphAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );
            }
            else if (circuitNode.Is<Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer,
                                                                                      transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = m_subGraphRenderer.GetPinOffset;
 
                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                  hoverAdapter,
                  scrollbarAdapter,
                  autoTranslateAdapter,
                  new RectangleDragSelector(),
                  transformAdapter,
                  viewingAdapter,
                  canvasAdapter,
                  mouseTransformManipulator,
                  mouseWheelManipulator,
                  new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                  new D2dGridAdapter(),
                  annotationAdaptor,
                  circuitAdapter,
                  circuitModuleEditAdapter,
                  circuitConnectionEditAdapter,
                  new LabelEditAdapter(),
                  groupPinEditor,
                  new SelectionAdapter(),
                  new DragDropAdapter(m_statusService),
                  new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                  );
            }
            else throw new NotImplementedException(
               "graph node type is not supported!");

            control.ResumeLayout();

            control.DoubleClick += new EventHandler(control_DoubleClick);
            control.MouseDown += new MouseEventHandler(control_MouseDown);
            return control;
        }
Example #25
0
 private static bool IsLayerItem(DomNode node)
 {
     return node.Is<LayerFolder>() || node.Is<ElementRef>() || node.Is<Element>();
 }
Example #26
0
 /// <summary>
 /// Returns true iff the reference can reference the specified target item</summary>
 /// <param name="item">Item to be referenced</param>
 /// <returns>True iff the reference can reference the specified target item</returns>
 /// <remarks>This method should never throw any exceptions</remarks>
 bool IReference <DomNode> .CanReference(DomNode item)
 {
     return(item.Is <Group>());
 }
Example #27
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();

            control.SuspendLayout();
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();

            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale       = true;
            transformAdapter.MinScale           = new PointF(0.25f, 0.25f);
            transformAdapter.MaxScale           = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);

            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();

            ((ILayoutConstraint)canvasAdapter).Enabled = false;  //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter      = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator     = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter          = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();

            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

            if (circuitNode.Is <Circuit>())
            {
                var circuitAdapter           = new D2dGraphAdapter <Module, Connection, ICircuitPin>(m_circuitRenderer, transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );
            }
            else if (circuitNode.Is <Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter <Module, Connection, ICircuitPin>(m_subGraphRenderer,
                                                                                              transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = m_subGraphRenderer.GetPinOffset;

                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    groupPinEditor,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );
            }
            else
            {
                throw new NotImplementedException(
                          "graph node type is not supported!");
            }

            control.ResumeLayout();

            control.DoubleClick += new EventHandler(control_DoubleClick);
            control.MouseDown   += new MouseEventHandler(control_MouseDown);
            return(control);
        }
Example #28
0
 private static bool IsFsmItem(DomNode child, DomNode parent)
 {
     return
         (parent != null && parent.Is <Fsm>());
 }
Example #29
0
 private static bool IsLayerItem(DomNode node)
 {
     return(node.Is <ILayer>() || node.Is <IReference <IGameObject> >());
 }
Example #30
0
        /// <summary>
        /// Inserts the specified child into the specified parent</summary>
        /// <param name="parent">Parent to insert into</param>
        /// <param name="child">Child to be inserted</param>
        /// <remarks>This method is used by copy-paste and drag-drop from various sources.
        /// When making any changes to this method, please test the following:
        /// - Copy/Paste, Cut/Paste
        /// - Drag-drop from {Palette|ResourceLister} to {ProjectLister|DesignView}
        /// Pay special attention to:
        /// - (GameObjects with) GameObjectReferences
        /// - (GameObjects with) ResourceReferences incl. Locators
        /// - GameObjectGroups (and hierarchies thereof)
        /// - GameObjectFolders (and hierarchies thereof)
        /// - Pasting the same objects more than once</remarks>
        public void Insert(object parent, object child)
        {
            if (!CanInsert(parent, child))
            {
                return;
            }

            var hierarchical = parent.AsAll <IHierarchical>();

            // Extract node list from IDataObject
            IEnumerable <object> items = Util.ConvertData(child, true);

            DomNode parentRoot = null;
            DomNode parentNode = parent.As <DomNode>();

            if (parentNode != null)
            {
                parentRoot = parentNode.GetRoot();
            }

            List <DomNode> copyList   = new List <DomNode>();
            List <object>  objectlist = new List <object>();

            foreach (object item in items)
            {
                if (item.Is <IGameObject>() || item.Is <IGameObjectFolder>())
                {
                    DomNode childNode = item.As <DomNode>();
                    DomNode childRoot = childNode.GetRoot();

                    if ((parentRoot != null && childRoot.Is <IGame>() && parentRoot != childRoot))
                    {
                        childNode.RemoveFromParent();
                        copyList.Add(childNode);
                        continue;
                    }
                }
                objectlist.Add(item);
            }

            if (copyList.Count > 0)
            {
                IEnumerable <DomNode> copies = DomNode.Copy(copyList);
                // remvoe lock
                foreach (DomNode copy in copies)
                {
                    this.SetLocked(copy, false);
                }
                objectlist.AddRange(copies);
            }

            foreach (object obj in objectlist)
            {
                DomNode node = obj.As <DomNode>();
                if (node != null)
                {
                    node.InitializeExtensions();
                }
            }

            List <DomNode> insertedNodes = new List <DomNode>();

            foreach (object obj in objectlist)
            {
                object insertedObj = null;

                bool inserted = false;
                foreach (var h in hierarchical)
                {
                    if (h.AddChild(obj))
                    {
                        inserted = true;
                        break;
                    }
                }

                if (inserted)
                {
                    insertedObj = obj;
                }
                else
                {
                    IResource res = obj as IResource;
                    var       gob = m_resourceConverterService.Convert(res);
                    foreach (var h in hierarchical)
                    {
                        if (h.AddChild(gob))
                        {
                            inserted = true;
                            break;
                        }
                    }
                    if (inserted)
                    {
                        insertedObj = gob;
                    }
                }
                DomNode insertNode = Adapters.As <DomNode>(insertedObj);
                if (insertNode != null)
                {
                    insertedNodes.Add(insertNode);
                }
            }

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(insertedNodes);
            List <object>         newSelection = new List <object>();

            foreach (DomNode rootNode in rootDomNodes)
            {
                AdaptablePath <object> path = Util.AdaptDomPath(rootNode);

                if (path.First.Is <IGame>() && (rootNode.Is <IGameObject>() || rootNode.Is <IGameObjectFolder>()))
                {
                    newSelection.Add(path);
                }
            }
            if (newSelection.Count > 0)
            {
                if (InTransaction)
                {
                    m_savedSelection = new List <object>(MasterContext.Selection);
                }

                MasterContext.SetRange(newSelection);
            }
        }
Example #31
0
 private static bool IsTemplateItem(DomNode child, DomNode parent)
 {
     return
         (child.Is <TemplateFolder>() ||
          (parent != null && parent.Is <TemplateFolder>()));
 }
Example #32
0
        /// <summary>
        /// Gets the bounding rectangle of all circuit items in client coordinates</summary>
        /// <returns>Bounding rectangle of all circuit items in client coordinates</returns>
        public Rectangle GetBounds()
        {
            var items = new List <object>();

            if (m_graphContainer != null)
            {
                items.AddRange(m_graphContainer.Elements.AsIEnumerable <object>());
                if (m_graphContainer.Annotations != null)
                {
                    items.AddRange(m_graphContainer.Annotations.AsIEnumerable <object>());
                }
            }
            else
            {
                if (m_graph != null)
                {
                    items.AddRange(m_graph.Nodes.AsIEnumerable <IGraphNode>().AsIEnumerable <object>());
                }
                //TODO: including Annotations
            }

            Rectangle bounds = GetBounds(items);

            if (DomNode.Is <Group>()) // the view is associated with a group editor
            {
                // include group pins y range
                var group = DomNode.Cast <Group>();

                int yMin = int.MaxValue;
                int yMax = int.MinValue;

                foreach (var pin in group.InputGroupPins)
                {
                    var grpPin = pin.Cast <GroupPin>();
                    if (grpPin.Bounds.Location.Y < yMin)
                    {
                        yMin = grpPin.Bounds.Location.Y;
                    }
                    if (grpPin.Bounds.Location.Y > yMax)
                    {
                        yMax = grpPin.Bounds.Location.Y;
                    }
                }

                foreach (var pin in group.OutputGroupPins)
                {
                    var grpPin = pin.Cast <GroupPin>();
                    if (grpPin.Bounds.Location.Y < yMin)
                    {
                        yMin = grpPin.Bounds.Location.Y;
                    }
                    if (grpPin.Bounds.Location.Y > yMax)
                    {
                        yMax = grpPin.Bounds.Location.Y;
                    }
                }

                // transform y range to client space
                if (yMin != int.MaxValue && yMax != int.MinValue)
                {
                    var transformAdapter = m_control.Cast <ITransformAdapter>();
                    var yRange           = D2dUtil.TransformVector(transformAdapter.Transform, new PointF(yMin, yMax));
                    yMin = (int)Math.Min(yRange.X, yRange.Y);
                    yMax = (int)Math.Max(yRange.X, yRange.Y);
                    int width  = bounds.Width;
                    int height = yMax - yMin + 1;
                    bounds = Rectangle.Union(bounds, new Rectangle(bounds.Location.X, yMin, width, height));
                }
            }
            return(bounds);
        }
Example #33
0
 private static bool IsPrototypeItem(DomNode child, DomNode parent)
 {
     return
         child.Is<PrototypeFolder>() ||
         (parent != null && parent.Is<PrototypeFolder>());
 }
Example #34
0
 private static bool IsLayerItem(DomNode node)
 {
     return(node.Is <LayerFolder>() || node.Is <ElementRef>() || node.Is <Element>());
 }
Example #35
0
 /// <summary>
 /// Returns true iff the template can reference the specified target item</summary>
 public override bool CanReference(DomNode item)
 {
     return(item.Is <Module>());
 }
            private static void GatherNodeTypes(DomNode domNode, ICollection<SledProjectFilesFolderType> lstFolders)
            {
                if (domNode.Is<SledProjectFilesFolderType>())
                    lstFolders.Add(domNode.As<SledProjectFilesFolderType>());

                foreach (var child in domNode.Children)
                {
                    GatherNodeTypes(child, lstFolders);
                }
            }
Example #37
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();

            control.SuspendLayout();
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();

            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale       = true;
            transformAdapter.MinScale           = new PointF(0.01f, 0.01f);
            transformAdapter.MaxScale           = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);

            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();

            ((ILayoutConstraint)canvasAdapter).Enabled = false; //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter      = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator     = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter          = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();

            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(Theme); // display annotations under diagram

            var d2dRectangleDragSelector = new D2dRectangleDragSelector();
            var d2dRectangleDragRenderer = new D2dRectangleDragRenderer(d2dRectangleDragSelector);
            var gridAdapter = new D2dGridAdapter();

            gridAdapter.ConstraintEnabled = SnapToGridEnabled;
            //gridAdapter.Enabled = false;
            //gridAdapter.Visible = true;
            if (circuitNode.Is <Circuit>())
            {
                var circuitAdapter = new D2dGraphAdapter <Module, Connection, ICircuitPin>(CircuitRenderer, transformAdapter);

                // The "AllFirst" policy will try to draw edges (wires) before nodes, as much as possible.
                //circuitAdapter.EdgeRenderPolicy = D2dGraphAdapter<Module, Connection, ICircuitPin>.DrawEdgePolicy.AllFirst;

                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    CircuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(CircuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    d2dRectangleDragSelector, //Needs to be before annotationAdaptor, so that drag-and-selecting text works.
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    gridAdapter,
                    annotationAdaptor,        //Needs to be before circuitAdapter so that comments appear under elements.
                    circuitAdapter,
                    circuitModuleEditAdapter, //lets user move circuit elements on canvas
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    d2dRectangleDragRenderer,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                    );
            }
            else if (circuitNode.Is <Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter <Module, Connection, ICircuitPin>(SubCircuitRenderer,
                                                                                              transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    SubCircuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(SubCircuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = SubCircuitRenderer.GetPinOffset;

                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    d2dRectangleDragSelector,
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    gridAdapter,
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    groupPinEditor,
                    d2dRectangleDragRenderer,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                    );
            }
            else
            {
                throw new NotImplementedException(
                          "graph node type is not supported!");
            }

            control.ResumeLayout();

            control.DoubleClick += control_DoubleClick;
            control.MouseDown   += control_MouseDown;
            return(control);
        }
Example #38
0
 private static bool IsTemplateItem(DomNode child, DomNode parent)
 {
     return
         child.Is<TemplateFolder>() ||
         (parent != null && parent.Is<TemplateFolder>());
 }
Example #39
0
 private static bool IsPrototypeItem(DomNode child, DomNode parent)
 {
     return
         (child.Is <PrototypeFolder>() ||
          (parent != null && parent.Is <PrototypeFolder>()));
 }
Example #40
0
 /// <summary>
 /// Returns true iff the template can reference the specified target item</summary>
 public override bool CanReference(DomNode item)
 {
     return item.Is<Module>();
 }