Exemple #1
0
        public void EhView_AddNormalGroupStyle()
        {
            SelectableListNode selected = null;

            foreach (SelectableListNode node in _availableNormalStyles)
            {
                if (node.Selected)
                {
                    selected = node;
                    break;
                }
            }
            if (null != selected)
            {
                _availableNormalStyles.Remove(selected);

                IPlotGroupStyle s = (IPlotGroupStyle)Activator.CreateInstance((Type)selected.Item);
                _doc.Add(s);
                CheckableSelectableListNode node = new CheckableSelectableListNode(
                    Current.Gui.GetUserFriendlyClassName(s.GetType()),
                    s.GetType(), true, s.IsStepEnabled);
                if (s.CanHaveChilds())
                {
                    _currentNormalStyles.Insert(_currentStepItems, node);
                    _currentStepItems++;
                }
                else
                {
                    _currentNormalStyles.Add(node);
                }

                _view.InitializeAvailableNormalGroupStyles(_availableNormalStyles);
                _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles);
            }
        }
        public void EhView_MoveDownGroupStyle()
        {
            if (0 == _currentNoOfItemsThatCanHaveChilds || _currentNormalStyles[_currentNoOfItemsThatCanHaveChilds - 1].IsSelected)
            {
                return; // can not move down any more
            }
            for (int i = _currentNoOfItemsThatCanHaveChilds - 2; i >= 0; i--)
            {
                CheckableSelectableListNode selected = _currentNormalStyles[i];
                if (!selected.IsSelected)
                {
                    continue;
                }

                IPlotGroupStyle style     = _doc.GetPlotGroupStyle((Type)selected.Tag);
                Type            childtype = _doc.GetTypeOfChild(style.GetType());
                _doc.RemoveType(style.GetType()); // Removing the type so removing also the parent-child-relationship
                if (childtype == null)
                {
                    _doc.Add(style);
                }
                else
                {
                    _doc.Add(style, childtype); // Add the type, but the child type this time is the parent type
                }
                _currentNormalStyles.Exchange(i, i + 1);
            }
            // this requires the whole currentNormalStyle list to be updated
            UpdateCurrentNormalOrder();
            _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles);
        }
Exemple #3
0
        public void EhView_MoveUpGroupStyle()
        {
            if (0 == _currentStepItems || _currentNormalStyles[0].Selected)
            {
                return; // can not move up any more
            }
            for (int i = 1; i < _currentStepItems; i++)
            {
                CheckableSelectableListNode selected = _currentNormalStyles[i];
                if (!selected.Selected)
                {
                    continue;
                }

                IPlotGroupStyle style      = _doc.GetPlotGroupStyle((Type)selected.Item);
                Type            parenttype = _doc.GetParentTypeOf(style.GetType());
                _doc.RemoveType(style.GetType()); // Removing the type so removing also the parent-child-relationship
                if (parenttype == null)
                {
                    _doc.Add(style);
                }
                else
                {
                    _doc.Insert(style, parenttype); // Add the type, but parent type is this time the child type
                }
                _currentNormalStyles.Exchange(i, i - 1);
            }
            // this requires the whole currentNormalStyle list to be updated
            UpdateCurrentNormalOrder();
            _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles);
        }
        /// <summary>
        /// Inserts a group style by adding it. The child group style type is appended as child to this group type.
        /// In case the child type has a parent, then this will be the parent of the inserted group style.
        /// </summary>
        /// <param name="groupStyle"></param>
        /// <param name="childGroupStyleType"></param>
        public void Insert(IPlotGroupStyle groupStyle, System.Type childGroupStyleType)
        {
            if (groupStyle == null)
            {
                throw new ArgumentNullException("Try to add a null value to this group style collection");
            }

            if (_typeToInstance.ContainsKey(groupStyle.GetType()))
            {
                throw new ArgumentException(string.Format("The group style type <<{0}>> is already present in this group style collection", groupStyle.GetType()));
            }

            if (childGroupStyleType != null && !_typeToInstance.ContainsKey(childGroupStyleType))
            {
                throw new ArgumentException(string.Format("The child group style (of type: {0}) can not be found in this collection", childGroupStyleType));
            }

            _typeToInstance.Add(groupStyle.GetType(), groupStyle);
            GroupInfo groupInfo = new GroupInfo();

            groupInfo.ChildGroupType = childGroupStyleType;
            _typeToInfo.Add(groupStyle.GetType(), groupInfo);


            if (childGroupStyleType != null)
            {
                System.Type oldParentType = _typeToInfo[childGroupStyleType].ParentGroupType;
                _typeToInfo[childGroupStyleType].ParentGroupType = groupStyle.GetType();
                groupInfo.ParentGroupType = oldParentType;
                if (oldParentType != null)
                {
                    _typeToInfo[oldParentType].ChildGroupType = groupStyle.GetType();
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Adds a group style to this collection, as a child of another group style. If the parent group style doesn't allow childs, then the group style is added normally.
        /// </summary>
        /// <param name="groupStyle">Group style to add to this collection.</param>
        /// <param name="parentGroupStyleType">Type of the parent group style.</param>
        public void Add(IPlotGroupStyle groupStyle, System.Type parentGroupStyleType)
        {
            if (parentGroupStyleType != null)
            {
                if (!_typeToInstance.ContainsKey(parentGroupStyleType))
                {
                    throw new ArgumentException(string.Format("The parent group style (of type: {0}) can not be found in this collection", parentGroupStyleType));
                }
                var parentInstance = _typeToInstance[parentGroupStyleType];
                if (!parentInstance.CanCarryOver)
                {
                    Add(groupStyle);
                    EhSelfChanged(EventArgs.Empty);
                    return;
                }
            }

            if (groupStyle == null)
            {
                throw new ArgumentNullException("Try to add a null value to this group style collection");
            }

            if (_typeToInstance.ContainsKey(groupStyle.GetType()))
            {
                throw new ArgumentException(string.Format("The group style type <<{0}>> is already present in this group style collection", groupStyle.GetType()));
            }

            groupStyle.ParentObject = this;
            _typeToInstance.Add(groupStyle.GetType(), groupStyle);
            var groupInfo = new GroupInfo
            {
                ParentGroupType = parentGroupStyleType
            };

            _typeToInfo.Add(groupStyle.GetType(), groupInfo);

            if (parentGroupStyleType != null)
            {
                System.Type oldChildType = _typeToInfo[parentGroupStyleType].ChildGroupType;
                _typeToInfo[parentGroupStyleType].ChildGroupType = groupStyle.GetType();
                groupInfo.ChildGroupType = oldChildType;
                if (oldChildType != null)
                {
                    _typeToInfo[oldChildType].ParentGroupType = groupStyle.GetType();
                }
            }

            EhSelfChanged(EventArgs.Empty);
        }
        public void EhView_IndentGroupStyle()
        {
            // for all selected items: append it as child to the item upward
            int count = Math.Min(_currentNoOfItemsThatCanHaveChilds + 1, _currentNormalStyles.Count); // note: the first item that can step, but can not have childs, could also be indented, thats why 1+

            for (int i = 1; i < count; ++i)
            {
                CheckableSelectableListNode selected = _currentNormalStyles[i];
                if (!selected.IsSelected)
                {
                    continue;
                }

                if (null != _doc.GetParentTypeOf((Type)selected.Tag))
                {
                    continue; // only ident those items who dont have a parent
                }
                IPlotGroupStyle style = _doc.GetPlotGroupStyle((Type)selected.Tag);
                _doc.RemoveType(style.GetType());                       // Removing the type so removing also the parent-child-relationship
                _doc.Add(style, (Type)_currentNormalStyles[i - 1].Tag); // Add the type again, but this time without parents or childs
            }
            // this requires the whole currentNormalStyle list to be updated
            UpdateCurrentNormalOrder();
            UpdateCurrentNormalIndentation();
            _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles);
        }
        /// <summary>
        /// This updates the list, presuming that the number of items has not changed.
        /// </summary>
        private void UpdateCurrentNormalOrder()
        {
            // if possible, we try to maintain the order in the list in which the items
            // appear

            if (0 == _currentNoOfItemsThatCanHaveChilds)
            {
                return; // then there is nothing to do now
            }
            IPlotGroupStyle previousStyle = null;
            IPlotGroupStyle style         = null;

            for (int i = 0; i < _currentNoOfItemsThatCanHaveChilds; i++, previousStyle = style)
            {
                CheckableSelectableListNode node = _currentNormalStyles[i];
                style = _doc.GetPlotGroupStyle((Type)node.Tag);

                if (previousStyle != null)
                {
                    Type prevchildtype = _doc.GetTypeOfChild(previousStyle.GetType());
                    if (prevchildtype != null)
                    {
                        if (prevchildtype != style.GetType())
                        {
                            int pi = _currentNormalStyles.IndexOfObject(prevchildtype);
                            _currentNormalStyles.Exchange(i, pi);
                        }
                        continue;
                    }
                }

                Type parenttype = _doc.GetParentTypeOf(style.GetType());
                if (parenttype != null &&
                    (previousStyle == null || previousStyle.GetType() != parenttype))
                {
                    int pi = _currentNormalStyles.IndexOfObject(parenttype);
                    _currentNormalStyles.Exchange(i, pi);
                }
            }
            UpdateCurrentNormalIndentation();
        }
 /// <summary>
 /// Comparison of plot group styles. Primarily they are sorted by the flag <see cref="IPlotGroupStyle.CanCarryOver"/>, so that items that can not have childs appear
 /// later in the list. Secondly, the items that can step appear earlier in the list.  Thirdly, the items are sorted by their parent-child relationship, and finally, by their name.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 private int ComparePlotGroupStyles(IPlotGroupStyle x, IPlotGroupStyle y)
 {
     if (x.CanCarryOver != y.CanCarryOver)
     {
         return(x.CanCarryOver ? -1 : 1);
     }
     if (x.CanStep != y.CanStep)
     {
         return(x.CanStep ? -1 : 1);
     }
     else
     {
         return(string.Compare(Current.Gui.GetUserFriendlyClassName(x.GetType()), Current.Gui.GetUserFriendlyClassName(y.GetType())));
     }
 }
            public virtual void SDeserialize(PlotGroupStyleCollectionBase s, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                Type parentStyleType = null;
                int  count           = info.OpenArray();

                for (int i = 0; i < count; i++)
                {
                    IPlotGroupStyle style    = (IPlotGroupStyle)info.GetValue("Style", s);
                    bool            hasChild = info.GetBoolean("HasChild");
                    s.Add(style, parentStyleType);
                    parentStyleType = hasChild ? style.GetType() : null;
                }
                info.CloseArray(count);

                s._plotGroupStrictness = (PlotGroupStrictness)info.GetEnum("Strictness", typeof(PlotGroupStrictness));
            }
Exemple #10
0
        /// <summary>
        /// Looks first in externalGroups, then in localGroups for the type of PlotGroupStyle to apply.
        /// In contrast to <see cref="GetStyleToApply{T}(IPlotGroupStyleCollection, IPlotGroupStyleCollection)"/>, we are searching here only for an interface,
        /// and return the first plot group style found that implements that interface.
        /// If an instance with this interface found, this instance is returned. If found, the containig collection
        /// is informed that this group style will be applied now by calling OnBeforeApplication.
        /// </summary>
        /// <typeparam name="T">Type of the interface to look for.</typeparam>
        /// <param name="externalGroups">First collection to look for the group style.</param>
        /// <param name="localGroups">Second collection to look for the group style.</param>
        /// <returns>The instance of the plot group style that implements the interface (if found), or null otherwise.</returns>
        public static T GetFirstStyleToApplyImplementingInterface <T>(
            IPlotGroupStyleCollection externalGroups,
            IPlotGroupStyleCollection localGroups
            )
        {
            IPlotGroupStyle           grpStyle = null;
            IPlotGroupStyleCollection grpColl  = externalGroups;

            grpStyle = grpColl.FirstOrDefault(style => typeof(T).IsAssignableFrom(style.GetType()));
            if (null == grpStyle)
            {
                grpColl  = localGroups;
                grpStyle = grpColl.FirstOrDefault(style => typeof(T).IsAssignableFrom(style.GetType()));
            }

            if (null != grpStyle)
            {
                grpColl.OnBeforeApplication(grpStyle.GetType());
            }

            return((T)grpStyle);
        }
Exemple #11
0
        public void EhView_UnindentGroupStyle()
        {
            // make sure that all the selected items are not child of another item
            for (int i = _currentNormalStyles.Count - 1; i >= 0; i--)
            {
                CheckableSelectableListNode selected = _currentNormalStyles[i];
                if (!selected.Selected)
                {
                    continue;
                }

                if (null != _doc.GetParentTypeOf((Type)selected.Item))
                {
                    IPlotGroupStyle style = _doc.GetPlotGroupStyle((Type)selected.Item);
                    _doc.RemoveType(style.GetType()); // Removing the type so removing also the parent-child-relationship
                    _doc.Add(style);                  // Add the type again, but this time without parents or childs
                }
            }

            // this requires the whole currentNormalStyle list to be updated
            UpdateCurrentNormalOrder();
            _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles);
        }
Exemple #12
0
        public void EhView_IndentGroupStyle()
        {
            // for all selected items: append it as child to the item upward

            for (int i = 1; i < _currentStepItems; i++)
            {
                CheckableSelectableListNode selected = _currentNormalStyles[i];
                if (!selected.Selected)
                {
                    continue;
                }

                if (null != _doc.GetParentTypeOf((Type)selected.Item))
                {
                    continue; // only ident those items who dont have a parent
                }
                IPlotGroupStyle style = _doc.GetPlotGroupStyle((Type)selected.Item);
                _doc.RemoveType(style.GetType());                        // Removing the type so removing also the parent-child-relationship
                _doc.Add(style, (Type)_currentNormalStyles[i - 1].Item); // Add the type again, but this time without parents or childs
            }
            // this requires the whole currentNormalStyle list to be updated
            UpdateCurrentNormalOrder();
            _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles);
        }
		/// <summary>
		/// Inserts a group style by adding it. The child group style type is appended as child to this group type.
		/// In case the child type has already a parent, then this parent will be the parent of the inserted group style.
		/// </summary>
		/// <param name="groupStyle">Group style to add.</param>
		/// <param name="childGroupStyleType">Type of group style, which should be the child of the added group style.</param>
		public void Insert(IPlotGroupStyle groupStyle, System.Type childGroupStyleType)
		{
			if (groupStyle == null)
				throw new ArgumentNullException("Try to add a null value to this group style collection");

			if (_typeToInstance.ContainsKey(groupStyle.GetType()))
				throw new ArgumentException(string.Format("The group style type <<{0}>> is already present in this group style collection", groupStyle.GetType()));

			if (childGroupStyleType != null && !_typeToInstance.ContainsKey(childGroupStyleType))
				throw new ArgumentException(string.Format("The child group style (of type: {0}) can not be found in this collection", childGroupStyleType));

			groupStyle.ParentObject = this;
			_typeToInstance.Add(groupStyle.GetType(), groupStyle);
			GroupInfo groupInfo = new GroupInfo();
			groupInfo.ChildGroupType = childGroupStyleType;
			_typeToInfo.Add(groupStyle.GetType(), groupInfo);

			if (childGroupStyleType != null)
			{
				System.Type oldParentType = _typeToInfo[childGroupStyleType].ParentGroupType;
				_typeToInfo[childGroupStyleType].ParentGroupType = groupStyle.GetType();
				groupInfo.ParentGroupType = oldParentType;
				if (oldParentType != null)
					_typeToInfo[oldParentType].ChildGroupType = groupStyle.GetType();
			}

			EhSelfChanged(EventArgs.Empty);
		}
		/// <summary>
		/// Adds a group style to this collection, as a child of another group style. If the parent group style doesn't allow childs, then the group style is added normally.
		/// </summary>
		/// <param name="groupStyle">Group style to add to this collection.</param>
		/// <param name="parentGroupStyleType">Type of the parent group style.</param>
		public void Add(IPlotGroupStyle groupStyle, System.Type parentGroupStyleType)
		{
			if (parentGroupStyleType != null)
			{
				if (!_typeToInstance.ContainsKey(parentGroupStyleType))
					throw new ArgumentException(string.Format("The parent group style (of type: {0}) can not be found in this collection", parentGroupStyleType));
				var parentInstance = _typeToInstance[parentGroupStyleType];
				if (!parentInstance.CanCarryOver)
				{
					Add(groupStyle);
					EhSelfChanged(EventArgs.Empty);
					return;
				}
			}

			if (groupStyle == null)
				throw new ArgumentNullException("Try to add a null value to this group style collection");

			if (_typeToInstance.ContainsKey(groupStyle.GetType()))
				throw new ArgumentException(string.Format("The group style type <<{0}>> is already present in this group style collection", groupStyle.GetType()));

			groupStyle.ParentObject = this;
			_typeToInstance.Add(groupStyle.GetType(), groupStyle);
			GroupInfo groupInfo = new GroupInfo();
			groupInfo.ParentGroupType = parentGroupStyleType;
			_typeToInfo.Add(groupStyle.GetType(), groupInfo);

			if (parentGroupStyleType != null)
			{
				System.Type oldChildType = _typeToInfo[parentGroupStyleType].ChildGroupType;
				_typeToInfo[parentGroupStyleType].ChildGroupType = groupStyle.GetType();
				groupInfo.ChildGroupType = oldChildType;
				if (oldChildType != null)
					_typeToInfo[oldChildType].ParentGroupType = groupStyle.GetType();
			}

			EhSelfChanged(EventArgs.Empty);
		}
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                PlotItemCollection s = null != o ? (PlotItemCollection)o : new PlotItemCollection();

                int count = info.OpenArray();

                IGPlotItem[] plotItems = new IGPlotItem[count];
                for (int i = 0; i < count; i++)
                {
                    plotItems[i] = (IGPlotItem)info.GetValue("PlotItem", s);
                }
                info.CloseArray(count);


                count = info.OpenArray(); // PlotGroups
                PGTrans[] plotGroups = new PGTrans[count];
                for (int i = 0; i < count; i++)
                {
                    plotGroups[i].PlotGroup = (PlotGroupMemento)info.GetValue(s);
                }
                info.CloseArray(count);

                // now assemble the new tree based collection based on the both fields

                for (int pix = 0; pix < plotItems.Length; pix++)
                {
                    // look if this plotItem is member of some group
                    int foundidx = -1;
                    for (int grx = 0; grx < plotGroups.Length; grx++)
                    {
                        if (Array.IndexOf <int>(plotGroups[grx].PlotGroup._plotItemIndices, pix) >= 0)
                        {
                            foundidx = grx;
                            break;
                        }
                    }
                    if (foundidx < 0) // if not found in some group, add the item directly
                    {
                        s.Add(plotItems[pix]);
                    }
                    else
                    {
                        if (plotGroups[foundidx].PlotItemCollection == null)
                        {
                            PlotItemCollection newColl = new PlotItemCollection();
                            plotGroups[foundidx].PlotItemCollection = newColl;
                            s.Add(plotGroups[foundidx].PlotItemCollection);
                            // now set the properties of this new collection
                            bool            serial = !plotGroups[foundidx].PlotGroup._concurrently;
                            IPlotGroupStyle curr   = null;
                            IPlotGroupStyle prev   = null;
                            if (0 != (plotGroups[foundidx].PlotGroup._plotGroupStyle & Version0PlotGroupStyle.Color))
                            {
                                curr = new ColorGroupStyle();
                                newColl.GroupStyles.Add(curr);
                            }
                            if (0 != (plotGroups[foundidx].PlotGroup._plotGroupStyle & Version0PlotGroupStyle.Line))
                            {
                                prev = curr;
                                curr = new LineStyleGroupStyle();
                                newColl.GroupStyles.Add(curr, serial ? (prev == null?null:prev.GetType()) : null);
                            }
                            if (0 != (plotGroups[foundidx].PlotGroup._plotGroupStyle & Version0PlotGroupStyle.Symbol))
                            {
                                prev = curr;
                                curr = new SymbolShapeStyleGroupStyle();
                                newColl.GroupStyles.Add(curr, serial ? (prev == null ? null : prev.GetType()) : null);
                            }
                        }
                        // now add the item to this collection
                        plotGroups[foundidx].PlotItemCollection.Add(plotItems[pix]);
                    }
                }

                return(s);
            }