Example #1
0
        public static RelationshipDefinition RelationshipDefinitionCreate(Domain OwnerEntity, IList <RelationshipDefinition> EditedList)
        {
            if (!ProductDirector.ValidateEditionPermission(AppExec.LIC_EDITION_FREE, "create Relationship Definitions"))
            {
                return(null);
            }

            var ItemsCount = OwnerEntity.ConceptDefinitions.Count + EditedList.Count;
            var MaxQuota   = AppExec.CurrentLicenseEdition.TechName.SelectCorresponding(LicensingConfig.IdeaDefinitionsCreationQuotas);

            if (!ProductDirector.ValidateEditionLimit(ItemsCount + 1, MaxQuota, "create", "Idea Definitions (Concept Defs. + Relationship Defs.)"))
            {
                return(null);
            }

            int    NewNumber = EditedList.Count + 1;
            string NewName   = "RelationshipDef" + NewNumber.ToString();
            var    Definitor = new RelationshipDefinition(OwnerEntity, Domain.GenericRelationshipDefinition,
                                                          NewName, NewName.TextToIdentifier(), Shapes.Ellipse);

            if (RelationshipDefinitionEdit(OwnerEntity, EditedList, Definitor))
            {
                return(Definitor);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Saves the Document into the underlying package, optionally with a new Uri.
        /// If the underlying package does not exists, then it is created with the supplied Uri.
        /// If the document is not already stored, then the Uri must be supplied.
        /// Returns an error message if problems were detected.
        /// </summary>
        /// <param name="DocumentLocation">New location for the Composition, Optional if the document is already stored.</param>
        /// <param name="UpdateLocation">Indicates to update the Composition location.</param>
        /// <param name="ResetExistenceStatus">Indicates to reset the existence status to Not-Modified.</param>
        /// <param name="RegisterAsRecentDoc">Indicates to register the document in the recent-documents list.</param>
        /// <returns>Possible problem error message.</returns>
        public string Store(Uri DocumentLocation = null, bool UpdateLocation = true, bool ResetExistenceStatus = true, bool RegisterAsRecentDoc = true)
        {
            var MaxQuota = AppExec.CurrentLicenseEdition.TechName.SelectCorresponding(LicensingConfig.IdeasCreationQuotas);

            if (!ProductDirector.ValidateEditionLimit(this.TargetComposition.DeclaredIdeas.Count(), MaxQuota, "save", "Ideas (Concepts + Relationships)"))
            {
                return("This product edition cannot save a Composition with more than " + MaxQuota.ToString() + " Ideas.");
            }

            MaxQuota = AppExec.CurrentLicenseEdition.TechName.SelectCorresponding(LicensingConfig.ComposabilityLevelsQuotas);

            var CompoLevels = this.TargetComposition.GetCompositeSubLevelsCount();

            if (!ProductDirector.ValidateEditionLimit(CompoLevels, MaxQuota, "save", "Composability Depth Levels"))
            {
                return("This product edition cannot save a Composition with more than " + MaxQuota.ToString() + " composability depth levels.");
            }

            if (DocumentLocation == null)
            {
                DocumentLocation = this.Location;
            }
            else
            if (UpdateLocation)
            {
                this.Location = DocumentLocation;
            }

            var Snapshot = (this.TargetComposition.ActiveView == null
                            ? null
                            : this.TargetComposition.ActiveView.ToVisualSnapshot(PART_SNAPSHOT_WIDTH, PART_SNAPSHOT_HEIGHT));

            var Result = StoreToLocation <ISphereModel>(this.TargetComposition, Composition.__ClassDefinitor.Name,
                                                        this.TargetComposition.Classification.ContentTypeCode, DocumentLocation,
                                                        CompositionDocumentUri, RegisterAsRecentDoc, false,
                                                        this.TargetComposition, Snapshot);

            if (Result.IsAbsent() && ResetExistenceStatus)
            {
                this.ExistenceStatus = EExistenceStatus.NotModified;
            }

            return(Result);
        }
Example #3
0
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------
        public static OperationResult <Relationship> CreateRelationship(Idea DestinationComposite, RelationshipDefinition Definitor, View TargetView,
                                                                        VisualRepresentation OriginRepresentation, Point OriginPosition,
                                                                        VisualRepresentation TargetRepresentation, Point TargetPosition,
                                                                        bool ExtendFromOriginRelationship = true, // (Shift not pressed) Applicable only when origin and target are both relationships. Else (Shift pressed) create Rel. from Target to Origin.
                                                                        bool ExtendExistingRelationship   = true) // (Right-Alt not pressed) Applicable only when origin is a not (simple and hiding-central-symbol) relationship. Else (Right-Alt pressed) created Rel. from Rel.
        {
            bool EditInPlace = false;

            General.ContractRequiresNotNull(DestinationComposite, Definitor, TargetView, OriginRepresentation);

            var MaxQuota = AppExec.CurrentLicenseEdition.TechName.SelectCorresponding(LicensingConfig.IdeasCreationQuotas);

            if (!ProductDirector.ValidateEditionLimit(DestinationComposite.OwnerComposition.DeclaredIdeas.Count() + 1, MaxQuota, "create", "Ideas (Concepts + Relationships)"))
            {
                return(OperationResult.Failure <Relationship>("This product edition cannot create more than " + MaxQuota + " Ideas."));
            }

            if (!ExtendFromOriginRelationship && (TargetRepresentation == null || !(TargetRepresentation.RepresentedIdea is Relationship)))
            {
                ExtendFromOriginRelationship = true;
            }

            var  PotentialOriginRelationship = OriginRepresentation.RepresentedIdea as Relationship;
            var  PotentialTargetRelationship = (TargetRepresentation == null ? (Relationship)null : TargetRepresentation.RepresentedIdea as Relationship);
            bool CreatingNewRelationship     = (/*?*/ !ExtendExistingRelationship || /*?*/ !((PotentialOriginRelationship != null && PotentialOriginRelationship.RelationshipDefinitor.Value == Definitor) ||
                                                                                             (PotentialTargetRelationship != null && PotentialTargetRelationship.RelationshipDefinitor.Value == Definitor)));
            bool?ExtensionFromOriginRelationship = (CreatingNewRelationship ? (bool?)null : (PotentialOriginRelationship != null && ExtendFromOriginRelationship));

            if (!CreatingNewRelationship && TargetRepresentation == null)
            {
                if (OriginRepresentation is RelationshipVisualRepresentation)
                {
                    return(OperationResult.Success(((RelationshipVisualRepresentation)OriginRepresentation).RepresentedRelationship, "Creating new Relationship."));
                }
                else
                {
                    return(OperationResult.Failure <Relationship>("There is no targeted Idea to relate."));
                }
            }

            if (DestinationComposite.IdeaDefinitor.CompositeContentDomain == null)
            {
                return(OperationResult.Failure <Relationship>("Destination Container doest not accept Composite-Content.", DestinationComposite));
            }

            if (DestinationComposite.CompositeContentDomain.GlobalId != Definitor.OwnerDomain.GlobalId)
            {
                return(OperationResult.Failure <Relationship>("The destination container only accepts content of the '" + DestinationComposite.CompositeContentDomain.Name + "' Domain."));
            }

            Relationship       WorkingRelationship = null;
            LinkRoleDefinition OriginLinkRoleDef   = null;
            RoleBasedLink      OriginLink          = null;

            DestinationComposite.EditEngine.StartCommandVariation("Create Relationship");

            if (CreatingNewRelationship)
            {
                if (TargetRepresentation != null)
                {
                    var CanLink = Definitor.CanLink(OriginRepresentation.RepresentedIdea.IdeaDefinitor, TargetRepresentation.RepresentedIdea.IdeaDefinitor);

                    if (!CanLink.Result)
                    {
                        DestinationComposite.EditEngine.DiscardCommandVariation();
                        return(OperationResult.Failure <Relationship>(CanLink.Message));
                    }
                }

                string NewName = Definitor.Name;

                var AppendNumToName = AppExec.GetConfiguration <bool>("IdeaEditing", "Relationship.OnCreationAppendDefNameAndNumber", true);
                if (AppendNumToName)
                {
                    NewName = NewName + " (Idea " + (DestinationComposite.CompositeIdeas.Count + 1).ToString() + ")";
                }

                WorkingRelationship = new Relationship(DestinationComposite.OwnerComposition, Definitor, NewName, NewName.TextToIdentifier());

                if (Definitor.IsVersionable)
                {
                    WorkingRelationship.Version = new VersionCard();
                }

                WorkingRelationship.AddToComposite(DestinationComposite);

                OriginLinkRoleDef = Definitor.GetLinkForRole(ERoleType.Origin);
                OriginLink        = new RoleBasedLink(WorkingRelationship, OriginRepresentation.RepresentedIdea, OriginLinkRoleDef, OriginLinkRoleDef.AllowedVariants[0]);
                WorkingRelationship.AddLink(OriginLink);

                PotentialOriginRelationship = WorkingRelationship;
                EditInPlace = true;
            }
            else
            {
                OperationResult <bool> CanLink = OperationResult.Success(true);

                if (ExtensionFromOriginRelationship.IsTrue())
                {
                    WorkingRelationship = PotentialOriginRelationship;
                }
                else
                {
                    WorkingRelationship = (PotentialTargetRelationship != null ? PotentialTargetRelationship : PotentialOriginRelationship);
                }

                if (TargetRepresentation != null)
                {
                    CanLink = EvaluateLinkability(Definitor, OriginRepresentation, TargetRepresentation,
                                                  PotentialOriginRelationship, PotentialTargetRelationship, WorkingRelationship);

                    if (!CanLink.Result)
                    {
                        DestinationComposite.EditEngine.DiscardCommandVariation();
                        return(OperationResult.Failure <Relationship>("Cannot create/extend Relationship. Cause: " + CanLink.Message));
                    }
                }
            }

            LinkRoleDefinition WorkingLinkRoleDef = null;
            RoleBasedLink      WorkingLink        = null;

            if (TargetRepresentation != null && (CreatingNewRelationship || (WorkingRelationship == PotentialOriginRelationship &&
                                                                             ExtensionFromOriginRelationship.IsTrue())))
            {
                WorkingLinkRoleDef = Definitor.GetLinkForRole(ERoleType.Target);
                if (WorkingRelationship.Links.Where(link => link.RoleDefinitor == WorkingLinkRoleDef &&
                                                    link.AssociatedIdea == TargetRepresentation.RepresentedIdea).Any())
                {
                    DestinationComposite.EditEngine.DiscardCommandVariation();
                    return(OperationResult.Failure <Relationship>("Cannot create Target Link. Cause: Already exists one of the same role-type associating the same Idea."));
                }

                WorkingLink = new RoleBasedLink(WorkingRelationship, TargetRepresentation.RepresentedIdea, WorkingLinkRoleDef, WorkingLinkRoleDef.AllowedVariants[0]);
                WorkingRelationship.AddLink(WorkingLink);
            }

            if (OriginRepresentation != null && !CreatingNewRelationship &&
                WorkingRelationship == PotentialTargetRelationship && !ExtensionFromOriginRelationship.IsTrue())
            {
                WorkingLinkRoleDef = Definitor.GetLinkForRole(ERoleType.Origin);
                if (WorkingRelationship.Links.Where(link => link.RoleDefinitor == WorkingLinkRoleDef &&
                                                    link.AssociatedIdea == OriginRepresentation.RepresentedIdea).Any())
                {
                    DestinationComposite.EditEngine.DiscardCommandVariation();
                    return(OperationResult.Failure <Relationship>("Cannot create Origin Link. Cause: Already exists one of the same role-type associating the same Idea."));
                }

                WorkingLink = new RoleBasedLink(WorkingRelationship, OriginRepresentation.RepresentedIdea, WorkingLinkRoleDef, WorkingLinkRoleDef.AllowedVariants[0]);
                WorkingRelationship.AddLink(WorkingLink);
            }

            RelationshipVisualRepresentation Representator = null;
            VisualSymbol CentralSymbol = null;

            if (TargetPosition != Display.NULL_POINT &&
                OriginPosition != Display.NULL_POINT)
            {
                VisualConnector OriginConnector = null;

                var InitialPosition    = OriginPosition;
                var EdgeOriginPosition = OriginPosition;
                var EdgeTargetPosition = TargetPosition;

                if (CreatingNewRelationship)
                {
                    // Force connect from Symbols' centers.
                    if (OriginRepresentation != null)
                    {
                        EdgeOriginPosition = OriginPosition.DetermineNearestIntersectingPoint(TargetPosition, TargetView.Presenter,
                                                                                              OriginRepresentation.MainSymbol.Graphic,
                                                                                              TargetView.VisualHitTestFilter);
                    }

                    if (TargetRepresentation == null)
                    {
                        InitialPosition = TargetPosition;
                    }
                    else
                    {
                        EdgeTargetPosition = TargetPosition.DetermineNearestIntersectingPoint(OriginPosition, TargetView.Presenter,
                                                                                              TargetRepresentation.MainSymbol.Graphic,
                                                                                              TargetView.VisualHitTestFilter);
                        InitialPosition = EdgeOriginPosition.DetermineCenterRespect(EdgeTargetPosition);
                    }

                    // Create representation
                    Representator = CreateRelationshipVisualRepresentation(WorkingRelationship, TargetView, InitialPosition);
                    CentralSymbol = Representator.MainSymbol;

                    // Notice that here the Origin connector is being drawn, so the Target plug is empty/none (because is connected to the Relationship Central/Main Symbol).
                    OriginConnector = new VisualConnector(Representator, OriginLink, OriginRepresentation.MainSymbol, CentralSymbol, OriginPosition, CentralSymbol.BaseCenter);
                }
                else
                {
                    if (WorkingRelationship == PotentialOriginRelationship)
                    {
                        Representator = (RelationshipVisualRepresentation)OriginRepresentation;
                    }
                    else
                    {
                        Representator = (RelationshipVisualRepresentation)TargetRepresentation;
                    }

                    CentralSymbol   = OriginRepresentation.MainSymbol;
                    InitialPosition = CentralSymbol.BaseCenter;
                }

                VisualConnector TargetConnector        = null;
                VisualConnector OriginAutoRefConnector = null;

                if (TargetRepresentation != null)
                {
                    TargetConnector = new VisualConnector(Representator, WorkingLink, CentralSymbol, TargetRepresentation.MainSymbol, InitialPosition, TargetPosition);

                    if (WorkingRelationship == PotentialOriginRelationship)
                    {
                        OriginAutoRefConnector = CentralSymbol.OriginConnections.FirstOrDefault(conn => conn.OriginSymbol == TargetRepresentation.MainSymbol);
                    }
                }

                if (CreatingNewRelationship)
                {
                    Representator.AddVisualPart(OriginConnector);
                }

                if (TargetConnector != null)
                {
                    Representator.AddVisualPart(TargetConnector);
                }

                if (OriginAutoRefConnector != null)
                {
                    Representator.BendAutoRefConnectors(OriginAutoRefConnector, TargetConnector);
                }

                Representator.Render();
            }

            DestinationComposite.UpdateVersion();
            DestinationComposite.EditEngine.CompleteCommandVariation();

            var InformedRelationship = WorkingRelationship;

            if (WorkingRelationship == PotentialTargetRelationship &&
                PotentialOriginRelationship != null)
            {
                InformedRelationship = PotentialOriginRelationship;
            }

            return(OperationResult.Success(InformedRelationship, null, null, CentralSymbol.OwnerRepresentation, EditInPlace));
        }