Example #1
0
        // ----------------------------------------------------------------------
        public bool IsPartOfConnection(iCS_EditorObject testedPort)
        {
            if (this == testedPort)
            {
                return(true);
            }
            var src = ProducerPort;

            if (src == null)
            {
                return(false);
            }
            return(src.IsPartOfConnection(testedPort));
        }
        // ----------------------------------------------------------------------
        public float ProposeViewportScalingFor(iCS_EditorObject node, float minScale, float maxScale)
        {
            var newScale = ProposeViewportScalingFor(node);

            if (newScale < minScale)
            {
                newScale = minScale;
            }
            if (newScale > maxScale)
            {
                newScale = maxScale;
            }
            return(newScale);
        }
        // ===================================================================
        // ENABLE PORTS
        // -------------------------------------------------------------------------
        /// Returns the list of all enable ports on the given node.
        ///
        /// @param node The node from which to extract the enable ports.
        /// @return The list of enable ports.
        ///
        public static iCS_EditorObject[] GetEnablePorts(iCS_EditorObject node)
        {
            var enables = new List <iCS_EditorObject>();

            node.ForEachChildPort(
                p => {
                if (p.IsEnablePort)
                {
                    enables.Add(p);
                }
            }
                );
            return(enables.ToArray());
        }
Example #4
0
        // -------------------------------------------------------------------------
        /// Returns the list of functions inside the given package.
        ///
        /// @param package The package to examine.
        /// @return The list of all functions nested inside the package.
        ///
        public static List <iCS_EditorObject> GetListOfFunctions(iCS_EditorObject package)
        {
            var childFunctions = new List <iCS_EditorObject>();

            package.ForEachChildRecursiveDepthFirst(
                c => {
                if (c.IsKindOfFunction)
                {
                    childFunctions.Add(c);
                }
            }
                );
            return(childFunctions);
        }
        // ----------------------------------------------------------------------
        private bool WasPresent(iCS_EditorObject obj)
        {
            if (obj == null)
            {
                return(false);
            }
            int id = obj.InstanceId;

            if (id < 0 || id >= myWasPresent.Length)
            {
                return(false);
            }
            return(myWasPresent[id]);
        }
        // ----------------------------------------------------------------------
        public static void DragAndDropSetPortValue(iCS_EditorObject port, UnityEngine.Object value)
        {
            var iStorage = port.IStorage;

            OpenTransaction(iStorage);
            try {
                port.Value = value;
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return;
            }
            CloseTransaction(iStorage, "Set port " + port.DisplayName);
        }
Example #7
0
        // ----------------------------------------------------------------------
        // This function will attempt to remove dupliacte ports on the same module.
        public void OptimizeDataConnection(iCS_EditorObject inPort, iCS_EditorObject outPort)
        {
            var provider = inPort.ProducerPort;

            if (provider == null)
            {
                return;
            }
            if (provider != outPort)
            {
                OptimizeDataConnection(provider, outPort);
            }
            OptimizeDataConnection(provider);
        }
        // ----------------------------------------------------------------------
        public void SmartFocusOn(iCS_EditorObject obj)
        {
            if (IStorage == null)
            {
                return;
            }
            var focusNode = obj;

            // Focus on port parent.
            if (obj.IsPort)
            {
                focusNode = obj.ParentNode;
            }
            // Move to higher parent if scale is too large.
            float scale = ProposeViewportScalingFor(focusNode, 0.75f, 1f);

            if (Math3D.IsSmallerOrEqual(scale, 0.75f))
            {
                CenterAndScaleOn(focusNode);
                return;
            }
            if (focusNode != IStorage.DisplayRoot)
            {
                var focusNodeParent = focusNode.ParentNode;
                if (focusNodeParent != null)
                {
                    var parentScale = ProposeViewportScalingFor(focusNodeParent, 0.80f, 1f);
                    while (parentScale > 0.80f)
                    {
                        scale           = parentScale;
                        focusNode       = focusNodeParent;
                        focusNodeParent = focusNode.ParentNode;
                        if (focusNode == IStorage.DisplayRoot || focusNodeParent == null)
                        {
                            break;
                        }
                        parentScale = ProposeViewportScalingFor(focusNodeParent, 0.80f, 1f);
                    }
                }
            }
            // Center on focus node
            if (focusNode == IStorage.DisplayRoot)
            {
                CenterAndScaleOnRoot();
            }
            else
            {
                CenterAtWithScale(focusNode.GlobalPosition, scale);
            }
        }
Example #9
0
        // ----------------------------------------------------------------------
        static Vector2 BindingDirectionFromTo(iCS_EditorObject port, iCS_EditorObject to, iCS_IStorage storage)
        {
            // Don't compute complex tangents if we don't have a proper parent.
            iCS_EditorObject portParent = port.ParentNode;

            if (port.IsFloating || to.IsFloating)
            {
                if (port.IsDataOrControlPort || !portParent.IsPositionOnEdge(port.AnimatedPosition, port.Edge))
                {
                    Vector2 fromPos = port.AnimatedPosition;
                    Vector2 toPos   = to.AnimatedPosition;
                    return(GetBestDirectionFrom((toPos - fromPos).normalized));
                }
            }

            if (port.IsOutTransitionPort && portParent.IsIconizedOnDisplay)
            {
                return(storage.GetTransitionPackageVector(portParent));
            }
            if (port.IsInTransitionPort && portParent.IsIconizedOnDisplay)
            {
                return(-storage.GetTransitionPackageVector(portParent));
            }
            Vector2 direction;

            if (port.IsOnLeftEdge)
            {
                direction = LeftDirection;
            }
            else if (port.IsOnRightEdge)
            {
                direction = RightDirection;
            }
            else if (port.IsOnTopEdge)
            {
                direction = UpDirection;
            }
            else
            {
                direction = DownDirection;
            }
            // Inverse direction for connection between nested nodes.
            iCS_EditorObject toParent = to.ParentNode;

            if (storage.IsChildOf(toParent, portParent) && !port.IsInStatePort)
            {
                direction = -direction;
            }
            return(direction);
        }
        public bool IsBelowInHierarchyTo(iCS_EditorObject node)
        {
            bool result = false;

            node.ForEachChildRecursiveDepthLast(
                c => {
                if (c == this)
                {
                    result = true;
                }
            }
                );
            return(result);
        }
Example #11
0
        // ----------------------------------------------------------------------
        public iCS_EditorObject PropertiesWizardFindFunction(iCS_EditorObject module, LibraryObject libraryObject)
        {
            iCS_EditorObject foundNode = null;

            module.ForEachChildNode(
                n => {
                if (n.DisplayName == libraryObject.nodeName)
                {
                    foundNode = n;
                }
            }
                );
            return(foundNode);
        }
Example #12
0
        // -------------------------------------------------------------------------
        public iCS_EditorObject[] CleanupEnablePorts(iCS_EditorObject node)
        {
            var enables = GetEnablePorts(node);

            if (enables == null || enables.Length == 0)
            {
                return(null);
            }
            for (int i = 0; i < enables.Length; ++i)
            {
                enables[i].PortIndex = (int)iCS_PortIndex.EnablesStart + i;
            }
            return(enables);
        }
 // ======================================================================
 // Transition helpers.
 // ----------------------------------------------------------------------
 public iCS_EditorObject GetFromStatePort(iCS_EditorObject transitionObject)
 {
     if (transitionObject == null)
     {
         return(null);
     }
     if (transitionObject.IsInStatePort)
     {
         iCS_EditorObject source = transitionObject.ProducerPort;
         if (source == null)
         {
             return(null);
         }
         if (source.IsOutStatePort)
         {
             return(source);
         }
         transitionObject = source.Parent;
     }
     if (transitionObject.IsTransitionPackage)
     {
         if (!UntilMatchingChildPort(transitionObject,
                                     child => {
             if (child.IsInTransitionPort)
             {
                 transitionObject = child;
                 return(true);
             }
             return(false);
         }
                                     ))
         {
             return(null);
         }
     }
     if (transitionObject.IsInTransitionPort)
     {
         iCS_EditorObject source = transitionObject.ProducerPort;
         if (source == null)
         {
             return(null);
         }
         transitionObject = source;
     }
     if (transitionObject.IsOutStatePort)
     {
         return(transitionObject);
     }
     return(null);
 }
        // ---------------------------------------------------------------------------------
        public void ShowElement(iCS_EditorObject eObj)
        {
            if (eObj == null)
            {
                return;
            }
            var parent = eObj.Parent;

            while (parent != null)
            {
                myTreeView.Unfold(parent);
                parent = parent.Parent;
            }
        }
Example #15
0
        public static LibraryMemberInfo getAssociatedHelpMemberInfo(iCS_EditorObject edObj)
        {
            if (edObj != null)
            {
                if (edObj.IsPort)
                {
                    // check for special types of ports.
                    // TODO: support these.
                    if (edObj.PortIndex == (int)PortIndex.Return && edObj.ParentNode.IsStaticField)
                    {
                        // return port will be same as parent node description.
                    }
                    else if (edObj.IsKindOfPackagePort && !edObj.IsInstanceNodePort && !edObj.IsProposedDataPort)
                    {
                        return(null);
                    }
                    else if (edObj.PortIndex >= (int)PortIndex.ParametersEnd)
                    {
                        return(null);
                    }

                    // Following port will contain the member info
                    if (edObj.IsProposedDataPort)
                    {
                        // contained in edObj
                    }
                    else if (edObj.IsInputPort)
                    {
                        var consumerPorts = edObj.SegmentEndConsumerPorts;
                        var aConsumer     = consumerPorts.Length != 0 ? consumerPorts[0] : edObj;
                        edObj = aConsumer.Parent;
                    }
                    else if (edObj.IsOutputPort)
                    {
                        edObj = edObj.SegmentProducerPort.Parent;
                    }
                }

                LibraryMemberInfo memberInfo = null;

                // Try and Get Member Info from GetAssociatedDescriptor
                if (edObj.IsKindOfFunction || edObj.IsEventHandler)
                {
                    memberInfo = edObj.GetLibraryObject() as LibraryMemberInfo;
                }

                return(memberInfo);
            }
            return(null);
        }
 // ----------------------------------------------------------------------
 public static void RunOnWillDestroyNode(iCS_EditorObject obj)
 {
     if (!obj.IsNode || OnWillDestroyNode == null)
     {
         return;
     }
     foreach (Action <iCS_EditorObject> handler in OnWillDestroyNode.GetInvocationList())
     {
         try {
             handler(obj);
         }
         catch (Exception) {}
     }
 }
        // ----------------------------------------------------------------------
        /// Returns the port with the given port index.
        ///
        /// @return The found port or _null_ otherwise.
        ///
        public iCS_EditorObject GetPortWithIndex(int portIndex)
        {
            iCS_EditorObject result = null;

            ForEachChildPort(
                p => {
                if (p.PortIndex == portIndex)
                {
                    result = p;
                }
            }
                );
            return(result);
        }
        // Hierarchy Queries ====================================================
        public bool IsParentOf(iCS_EditorObject obj)
        {
            if (obj == null)
            {
                return(false);
            }
            var parent = obj.Parent;

            if (parent == this)
            {
                return(true);
            }
            return(IsParentOf(parent));
        }
 public static void Case(iCS_EditorObject obj,
                         Func <iCS_EditorObject, bool> c1, Action <iCS_EditorObject> f1,
                         Func <iCS_EditorObject, bool> c2, Action <iCS_EditorObject> f2,
                         Func <iCS_EditorObject, bool> c3, Action <iCS_EditorObject> f3,
                         Func <iCS_EditorObject, bool> c4, Action <iCS_EditorObject> f4,
                         Func <iCS_EditorObject, bool> c5, Action <iCS_EditorObject> f5,
                         Func <iCS_EditorObject, bool> c6, Action <iCS_EditorObject> f6,
                         Func <iCS_EditorObject, bool> c7, Action <iCS_EditorObject> f7,
                         Func <iCS_EditorObject, bool> c8, Action <iCS_EditorObject> f8,
                         Func <iCS_EditorObject, bool> c9, Action <iCS_EditorObject> f9,
                         Action <iCS_EditorObject> defaultFnc = null)
 {
     Prelude.choice(obj, c1, f1, c2, f2, c3, f3, c4, f4, c5, f5, c6, f6, c7, f7, c8, f8, c9, f9, defaultFnc);
 }
 // ----------------------------------------------------------------------
 public static void RunOnPortCreated(iCS_EditorObject obj)
 {
     if (!obj.IsPort || OnPortCreated == null)
     {
         return;
     }
     foreach (Action <iCS_EditorObject> handler in OnPortCreated.GetInvocationList())
     {
         try {
             handler(obj);
         }
         catch (Exception) {}
     }
 }
 // ----------------------------------------------------------------------
 public iCS_EditorObject GetOutTransitionPort(iCS_EditorObject transitionObject)
 {
     if (transitionObject.IsInStatePort)
     {
         transitionObject = transitionObject.ProducerPort;
         if (transitionObject == null)
         {
             return(null);
         }
     }
     if (transitionObject.IsOutTransitionPort)
     {
         return(transitionObject);
     }
     if (transitionObject.IsOutStatePort)
     {
         transitionObject = FindAConnectedPort(transitionObject);
         if (transitionObject == null)
         {
             return(null);
         }
     }
     if (transitionObject.IsInTransitionPort)
     {
         transitionObject = transitionObject.ParentNode;
         if (transitionObject == null)
         {
             return(null);
         }
     }
     if (transitionObject.IsTransitionPackage)
     {
         UntilMatchingChildPort(transitionObject,
                                p => {
             if (p.IsOutTransitionPort)
             {
                 transitionObject = p;
                 return(true);
             }
             return(false);
         }
                                );
         if (transitionObject.IsOutTransitionPort)
         {
             return(transitionObject);
         }
     }
     return(null);
 }
Example #22
0
        // ----------------------------------------------------------------------
        iCS_EditorObject PropertiesWizardCreatePortIfNonExisting(iCS_EditorObject module, string portName, Type portType,
                                                                 VSObjectType objType, int portIdx = -1)
        {
            iCS_EditorObject port = PropertiesWizardGetPort(module, portName, objType, portIdx);

            if (port == null)
            {
                port = CreatePort(portName, module.InstanceId, portType, objType);
                if (portIdx != -1)
                {
                    port.PortIndex = portIdx;
                }
            }
            return(port);
        }
 // ----------------------------------------------------------------------
 void OnStatePackageMenu(iCS_EditorObject targetObject)
 {
     iCS_MenuContext[] menu = StartWithFocusMenu(targetObject);
     if (!targetObject.IsIconizedInLayout && !targetObject.IsFoldedInLayout)
     {
         // Base menu items
         int idx = GrowMenuBy(ref menu, 3);
         menu[idx]     = new iCS_MenuContext(PackageStr);
         menu[idx + 1] = new iCS_MenuContext(StateChartStr);
         menu[idx + 2] = new iCS_MenuContext(SeparatorStr);
     }
     AddShowInHierarchyMenuItem(ref menu);
     AddDeleteMenuItem(ref menu);
     ShowMenu(menu, targetObject, targetObject.IStorage);
 }
Example #24
0
        // ======================================================================
        // Creation
        // ----------------------------------------------------------------------
        public void MoveDynamicPortToLastIndex(iCS_EditorObject port)
        {
            // -- Display error for invalid use. --
            if (port.IsFixDataPort)
            {
                Debug.LogWarning("iCanScript: Internal error: Tryng to move port index of a fix port");
                return;
            }
            // -- Get next available parameter index. --
            iCS_EditorObject parent = port.ParentNode;

            port.PortIndex = GetNextDynamicOrProposedPortIndex(parent);
            // -- Reajust the port indexes. --
            GraphEditor.AdjustPortIndexes(parent);
        }
        // ----------------------------------------------------------------------
        // Creates the missing fix ports
        public bool BuildMissingPorts(iCS_EditorObject node, PortInfo[] neededPorts)
        {
            bool changed = false;

            foreach (var pi in neededPorts)
            {
                if (!DoesPortExist(node, pi.Name, pi.ValueType, pi.PortType))
                {
                    var port = CreatePort(pi.Name, node.InstanceId, pi.ValueType, pi.PortType);
                    port.Value = pi.InitialValue;
                    changed    = true;
                }
            }
            return(changed);
        }
        // =========================================================================
        // Utilities
        // -------------------------------------------------------------------------
        // Don't use this function directly !!!
        // Use ToggleMultiSelection or SelectedObject= value to add an object to the
        // selection list.
        void RemoveFromSelectedObjects(iCS_EditorObject obj)
        {
            int idx = mySelectedObjects.IndexOf(obj);

            if (idx == -1)
            {
                return;
            }
            mySelectedObjects.RemoveAt(idx);
            if (idx == 0)
            {
                SelectedObjectId = mySelectedObjects.Count == 0 ? -1 : mySelectedObjects[0].InstanceId;
            }
            obj.ForEachConnectedProducerTypeCast(n => RemoveFromSelectedObjects(n));
        }
        // ----------------------------------------------------------------------
        public int NbOfChildren(iCS_EditorObject parent, Func <iCS_EditorObject, bool> filter)
        {
            if (!IsValid(parent))
            {
                return(0);
            }
            int cnt = 0;

            ForEachChild(parent, c => { if (filter(c))
                                        {
                                            ++cnt;
                                        }
                         });
            return(cnt);
        }
 Prelude.Tree <iCS_EditorObject> BuildTreeNode(iCS_EditorObject nodeRoot, List <bool> filterFlags)
 {
     Prelude.Tree <iCS_EditorObject> tree = new Prelude.Tree <iCS_EditorObject>(nodeRoot);
     myIStorage.ForEachChild(nodeRoot,
                             c => {
         Prelude.Tree <iCS_EditorObject> newNode = BuildTreeNode(c, filterFlags);
         if (filterFlags[c.InstanceId])
         {
             tree.AddChild(newNode);
         }
     }
                             );
     tree.Sort(SortComparaison);
     return(tree);
 }
Example #29
0
 // -------------------------------------------------------------------------
 public static Texture2D GetDefaultNodeIconFor(iCS_EditorObject obj)
 {
     if (obj.IsEventHandler)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.Message));
     }
     else if (obj.IsInstanceNode)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.ObjectInstance));
     }
     else if (obj.IsKindOfPackage)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.Package));
     }
     else if (obj.IsConstructor)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.Builder));
     }
     else if (obj.IsKindOfFunction)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.Function));
     }
     else if (obj.IsStateChart)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.StateChart));
     }
     else if (obj.IsEntryState)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.EntryState));
     }
     else if (obj.IsState)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.State));
     }
     else if (obj.IsOnStateEntryPackage)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.OnStateEntry));
     }
     else if (obj.IsOnStateUpdatePackage)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.OnStateUpdate));
     }
     else if (obj.IsOnStateExitPackage)
     {
         return(GetDefaultNodeIconFor(DefaultNodeIcons.OnStateExit));
     }
     return(TextureCache.GetIcon(kDefaultIcon));
 }
        // ===================================================================
        // BUILDER
        // -------------------------------------------------------------------
        /// Creates a port editor window at the given screen position.
        ///
        /// @param screenPosition The screen position where the editor
        ///                       should be displayed.
        ///
        public static new EditorWindow Create(iCS_EditorObject port, Vector2 screenPosition)
        {
            if (port == null)
            {
                return(null);
            }
            var self = EventHandlerPortEditor.CreateInstance <EventHandlerPortEditor>();

            self.vsObject = port;
            Texture2D iCanScriptLogo = null;

            TextureCache.GetTexture(iCS_EditorStrings.TitleLogoIcon, out iCanScriptLogo);
            self.titleContent = new GUIContent("Event Handler Port Editor", iCanScriptLogo);
            self.ShowUtility();
            return(self);
        }