예제 #1
0
        /// <summary>
        /// Creates and returns a collection of local detail editing cards for the supplied Idea and Symbol.
        /// </summary>
        public static EditableList <DetailEditingCard> GenerateLocalDetailsFor(Idea SourceIdea, VisualSymbol SourceSymbol,
                                                                               IEnumerable <DetailEditingCard> GeneratedGlobalDetails)
        {
            General.ContractRequires(SourceSymbol == null || SourceSymbol.OwnerRepresentation.RepresentedIdea == SourceIdea);

            var GeneratedLocalDetailEdits = new EditableList <DetailEditingCard>("LocalDetailEdits", null);

            // Add the custom designated details (for this particular Idea), plus its possible custom formats.
            foreach (var Detail in SourceIdea.Details.Where(det => det.ContentDesignator.IsLocal))
            {
                var TargetEditCard = new DetailEditingCard(true, new Assignment <DetailDesignator>(Detail.Designation, true), Detail);
                GeneratedLocalDetailEdits.Add(TargetEditCard);

                // Set any possible custom format
                if (SourceSymbol != null && TargetEditCard != null &&
                    SourceIdea.DetailsCustomLooks.ContainsKey(TargetEditCard.Designator.Value))
                {
                    var FormattedDesignation = SourceIdea.DetailsCustomLooks[TargetEditCard.Designator.Value];
                    if (FormattedDesignation != null && FormattedDesignation.ContainsKey(SourceSymbol))
                    {
                        TargetEditCard.SetLook(FormattedDesignation[SourceSymbol]);
                    }
                }
            }

            // Finally, add custom formats of Local Internal/Property details (not related to an existent detail).
            // Notice that global-designators (those previously generated) are excluded.
            // IMPORTANT: Don't ask solely for Idea-Definitor's detail designators, because for a Converted Idea
            //            can exist globally-defined detail designators which remain declared by the previous Idea-Definition.
            var AssignedCustomLooks = SourceIdea.DetailsCustomLooks
                                      .Where(cuslook => cuslook.Key is LinkDetailDesignator &&
                                             !GeneratedLocalDetailEdits.Any(det => det.Designator.Value.IsEquivalent(cuslook.Key)) &&
                                             (GeneratedGlobalDetails != null &&
                                              !GeneratedGlobalDetails.Any(
                                                  det =>
            {
                if (!(det.Designator.Value is LinkDetailDesignator))
                {
                    return(det.Designator.Value.IsEqual(cuslook.Key));
                }

                var dsnlink = det.Designator.Value.GetFinalContent(SourceIdea) as Link;
                var clklink = cuslook.Key.GetFinalContent(SourceIdea) as Link;

                var result = dsnlink.Target.IsEqual(clklink.Target);
                return(result);
            }))
                                             /*- && !SourceIdea.IdeaDefinitor.DetailDesignators.Any(dsn => dsn.IsEquivalent(cuslook.Key))*/);

            foreach (var CustLook in AssignedCustomLooks)
            {
                // Notice that no detail is supplied because Internal-Detail is just a designator-to-property reference.
                GeneratedLocalDetailEdits.Add(new DetailEditingCard(true, new Assignment <DetailDesignator>(CustLook.Key, true), null));
            }

            return(GeneratedLocalDetailEdits);
        }
예제 #2
0
        /// <summary>
        /// Creates and returns a collection of global detail editing cards for the supplied Idea and Symbol.
        /// </summary>
        public static EditableList <DetailEditingCard> GenerateGlobalDetailsFor(Idea SourceIdea, VisualSymbol SourceSymbol)
        {
            General.ContractRequires(SourceSymbol == null || SourceSymbol.OwnerRepresentation.RepresentedIdea == SourceIdea);

            var GeneratedGlobalDetailEdits = new EditableList <DetailEditingCard>("GlobalDetailEdits", null);

            // First, populate considering the predefined designations of Global scope
            // IMPORTANT: This also concatenates non-local details (designations predefined in the previous Idea-Definition of a CONVERTED Source-Idea).
            var Designators = SourceIdea.IdeaDefinitor.DetailDesignators.Concat(
                SourceIdea.Details.Where(det => !det.AssignedDesignator.IsLocal).Select(det => det.Designation)).Distinct();

            foreach (var Designator in Designators)
            {
                var NewDetEdit = new DetailEditingCard(true, new Assignment <DetailDesignator>(Designator, false),
                                                       SourceIdea.Details.FirstOrDefault(det => det.Designation.IsEqual(Designator)));

                if (SourceSymbol != null && SourceIdea.DetailsCustomLooks.ContainsKey(Designator) &&
                    SourceIdea.DetailsCustomLooks[Designator].ContainsKey(SourceSymbol))
                {
                    NewDetEdit.SetLook(SourceIdea.DetailsCustomLooks[Designator][SourceSymbol]);
                }

                GeneratedGlobalDetailEdits.Add(NewDetEdit);
            }

            // Then, add the custom designated details (for this particular Idea)
            foreach (var Detail in SourceIdea.Details)
            {
                var MatchPredefDsnIndex = GeneratedGlobalDetailEdits.IndexOfMatch(PredefDsn => PredefDsn.Designator.Value.IsEqual(Detail.Designation));
            }

            // Plus, set possible custom formats.
            foreach (var Detail in SourceIdea.Details)
            {
                var MatchPredefDsnIndex = GeneratedGlobalDetailEdits.IndexOfMatch(PredefDsn => PredefDsn.Designator.Value.IsEqual(Detail.Designation));

                if (SourceSymbol != null && MatchPredefDsnIndex >= 0)
                {
                    var TargetEditCard = GeneratedGlobalDetailEdits[MatchPredefDsnIndex];

                    // Set any possible custom format
                    if (TargetEditCard != null && SourceIdea.DetailsCustomLooks.ContainsKey(TargetEditCard.Designator.Value))
                    {
                        var FormattedDesignation = SourceIdea.DetailsCustomLooks[TargetEditCard.Designator.Value];

                        if (FormattedDesignation != null && FormattedDesignation.ContainsKey(SourceSymbol))
                        {
                            TargetEditCard.SetLook(FormattedDesignation[SourceSymbol]);
                        }
                    }
                }
            }

            return(GeneratedGlobalDetailEdits);
        }